feature: when a WindowTree is removed, then we add its contents to any other tree that we can find

This commit is contained in:
Matthew Kosarek 2024-01-21 16:53:42 -05:00
parent 96eefa2ea9
commit 057ecddd5c
4 changed files with 39 additions and 1 deletions

View File

@ -273,7 +273,10 @@ void MiracleWindowManagementPolicy::advise_output_delete(miral::Output const& ou
if (tree_list.empty())
active_tree = nullptr;
else
{
active_tree = tree_list[0];
active_tree->tree.add_tree(it->tree);
}
}
break;
}

View File

@ -89,7 +89,7 @@ public:
bool is_window() const { return state == NodeState::window; }
bool is_lane() const { return state == NodeState::lane; }
NodeLayoutDirection get_direction() const { return direction; }
miral::Window const& get_window() const { return window; }
miral::Window& get_window() { return window; }
std::shared_ptr<Node> get_parent() const { return parent; }
std::vector<std::shared_ptr<Node>> const& get_sub_nodes() const { return sub_nodes; }

View File

@ -619,4 +619,35 @@ bool WindowTree::constrain(miral::WindowInfo &window_info)
node->get_parent()->constrain();
return true;
}
void WindowTree::add_tree(WindowTree& other_tree)
{
other_tree.foreach_node([&](auto node)
{
if (node->is_window())
{
auto new_node_position = root_lane->create_new_node_position();
node->set_logical_area(new_node_position);
root_lane->add_window(node->get_window());
}
});
}
namespace
{
void foreach_node_internal(std::function<void(std::shared_ptr<Node>)> f, std::shared_ptr<Node> parent)
{
f(parent);
if (parent->is_window())
return;
for (auto node : parent->get_sub_nodes())
foreach_node_internal(f, node);
}
}
void WindowTree::foreach_node(std::function<void(std::shared_ptr<Node>)> f)
{
foreach_node_internal(f, root_lane);
}

View File

@ -94,6 +94,10 @@ public:
/// Constrains the window to its tile if it is in this tree.
bool constrain(miral::WindowInfo& window_info);
void add_tree(WindowTree&);
void foreach_node(std::function<void(std::shared_ptr<Node>)>);
private:
miral::WindowManagerTools tools;
WindowTreeOptions options;