Skip to content

Commit

Permalink
refactor: preparation for floating
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Feb 29, 2024
1 parent 0e480c7 commit 053a051
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/node.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "window_metadata.h"
#include <memory>
#define MIR_LOG_COMPONENT "node"

#include "node.h"
Expand Down Expand Up @@ -37,9 +39,6 @@ Node::Node(
config{config},
tree{tree}
{
miral::WindowSpecification spec;
spec.userdata() = metadata;
tools.modify_window(metadata->get_window(), spec);
}

geom::Rectangle Node::get_logical_area_internal(geom::Rectangle const& rectangle)
Expand Down Expand Up @@ -217,12 +216,12 @@ geom::Rectangle Node::create_new_node_position(int index)
}
}

void Node::add_window(miral::Window& new_window)
std::shared_ptr<WindowMetadata> Node::add_window(miral::Window& new_window)
{
if (pending_index < 0)
{
mir::fatal_error("Unable to add the window to the scene. Was create_new_node_position called?");
return;
return nullptr;
}

auto node_metadata = std::make_shared<WindowMetadata>(WindowType::tiled, new_window);
Expand All @@ -237,6 +236,7 @@ void Node::add_window(miral::Window& new_window)

sub_nodes.insert(sub_nodes.begin() + pending_index, node);
pending_index = -1;
return node_metadata;
}

void Node::_refit_node_to_area()
Expand Down Expand Up @@ -611,4 +611,4 @@ void Node::constrain()
{
node->constrain();
}
}
}
2 changes: 1 addition & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Node : public std::enable_shared_from_this<Node>
geom::Rectangle create_new_node_position(int index = -1);

/// Append the node to the lane
void add_window(miral::Window&);
std::shared_ptr<WindowMetadata> add_window(miral::Window&);

/// Updates the node's logical area (including gaps)
void set_logical_area(geom::Rectangle const& target_rect);
Expand Down
21 changes: 20 additions & 1 deletion src/tiling_window_management_policy.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "miral/window_specification.h"
#include "window_metadata.h"
#define MIR_LOG_COMPONENT "miracle"

#include "tiling_window_management_policy.h"
Expand Down Expand Up @@ -278,18 +280,35 @@ void TilingWindowManagementPolicy::advise_new_window(miral::WindowInfo const& wi
return;
}

std::shared_ptr<WindowMetadata> metadata = nullptr;
switch (pending_type)
{
case WindowType::tiled:
shared_output->get_active_tree().advise_new_window(window_info);
metadata = shared_output->get_active_tree().advise_new_window(window_info);
break;
case WindowType::other:
if (window_info.state() == MirWindowState::mir_window_state_attached)
{
window_manager_tools.select_active_window(window_info.window());
}
metadata = std::make_shared<WindowMetadata>(WindowType::other, window_info.window());
break;
default:
mir::log_error("Unsupported window type: %d", (int)pending_type);
break;
}

if (metadata)
{
miral::WindowSpecification spec;
spec.userdata() = metadata;
window_manager_tools.modify_window(window_info.window(), spec);
}
else
{
mir::log_error("Window failed to set metadata");
}

pending_type = WindowType::none;
pending_output.reset();
}
Expand Down
18 changes: 6 additions & 12 deletions src/tree.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "window_metadata.h"
#define MIR_LOG_COMPONENT "window_tree"

#include "tree.h"
Expand Down Expand Up @@ -57,23 +58,16 @@ miral::WindowSpecification Tree::allocate_position(const miral::WindowSpecificat
return new_spec;
}

void Tree::advise_new_window(miral::WindowInfo const& window_info)
std::shared_ptr<WindowMetadata> Tree::advise_new_window(miral::WindowInfo const& window_info)
{
if (!window_helpers::is_tileable(window_info))
{
if (window_info.state() == MirWindowState::mir_window_state_attached)
{
tools.select_active_window(window_info.window());
}
return;
}

_get_active_lane()->add_window(window_info.window());
auto metadata = _get_active_lane()->add_window(window_info.window());
if (window_helpers::is_window_fullscreen(window_info.state()))
{
tools.select_active_window(window_info.window());
advise_fullscreen_window(window_info);
}

return metadata;
}

void Tree::toggle_resize_mode()
Expand Down Expand Up @@ -848,4 +842,4 @@ bool Tree::is_empty()
empty = false;
});
return empty;
}
}
5 changes: 3 additions & 2 deletions src/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define WINDOW_TREE_H

#include "node.h"
#include "window_metadata.h"
#include <memory>
#include <vector>
#include <miral/window.h>
Expand All @@ -18,7 +19,7 @@ namespace miracle

class Screen;
class MiracleConfig;

enum class Direction
{
up,
Expand All @@ -37,7 +38,7 @@ class Tree
/// position is the position WITH GAPS.
miral::WindowSpecification allocate_position(const miral::WindowSpecification &requested_specification);

void advise_new_window(miral::WindowInfo const&);
std::shared_ptr<WindowMetadata> advise_new_window(miral::WindowInfo const&);

/// Places us into resize mode. Other operations are prohibited while we are in resize mode.
void toggle_resize_mode();
Expand Down

0 comments on commit 053a051

Please sign in to comment.