diff --git a/src/node.cpp b/src/node.cpp index 1c4ffe4..5feb48e 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -1,3 +1,5 @@ +#include "window_metadata.h" +#include #define MIR_LOG_COMPONENT "node" #include "node.h" @@ -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) @@ -217,12 +216,12 @@ geom::Rectangle Node::create_new_node_position(int index) } } -void Node::add_window(miral::Window& new_window) +std::shared_ptr 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(WindowType::tiled, new_window); @@ -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() @@ -611,4 +611,4 @@ void Node::constrain() { node->constrain(); } -} \ No newline at end of file +} diff --git a/src/node.h b/src/node.h index bbd809d..d5f1509 100644 --- a/src/node.h +++ b/src/node.h @@ -54,7 +54,7 @@ class Node : public std::enable_shared_from_this geom::Rectangle create_new_node_position(int index = -1); /// Append the node to the lane - void add_window(miral::Window&); + std::shared_ptr add_window(miral::Window&); /// Updates the node's logical area (including gaps) void set_logical_area(geom::Rectangle const& target_rect); diff --git a/src/tiling_window_management_policy.cpp b/src/tiling_window_management_policy.cpp index 49a6084..87bd0e4 100644 --- a/src/tiling_window_management_policy.cpp +++ b/src/tiling_window_management_policy.cpp @@ -1,3 +1,5 @@ +#include "miral/window_specification.h" +#include "window_metadata.h" #define MIR_LOG_COMPONENT "miracle" #include "tiling_window_management_policy.h" @@ -278,18 +280,35 @@ void TilingWindowManagementPolicy::advise_new_window(miral::WindowInfo const& wi return; } + std::shared_ptr 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(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(); } diff --git a/src/tree.cpp b/src/tree.cpp index ff91f3d..20e3b45 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -1,3 +1,4 @@ +#include "window_metadata.h" #define MIR_LOG_COMPONENT "window_tree" #include "tree.h" @@ -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 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() @@ -848,4 +842,4 @@ bool Tree::is_empty() empty = false; }); return empty; -} \ No newline at end of file +} diff --git a/src/tree.h b/src/tree.h index 06a2551..c0dbdb4 100644 --- a/src/tree.h +++ b/src/tree.h @@ -2,6 +2,7 @@ #define WINDOW_TREE_H #include "node.h" +#include "window_metadata.h" #include #include #include @@ -18,7 +19,7 @@ namespace miracle class Screen; class MiracleConfig; - + enum class Direction { up, @@ -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 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();