From e3add8c55e96691e77abb9236168d0850c71e97d Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Tue, 19 Dec 2023 09:44:29 -0500 Subject: [PATCH] feature: resizing the display resizes the windows in it --- src/miracle_window_management_policy.cpp | 2 +- src/node.cpp | 13 +++++++++++++ src/node.h | 2 ++ src/window_tree.cpp | 9 ++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/miracle_window_management_policy.cpp b/src/miracle_window_management_policy.cpp index afed033..975cfcd 100644 --- a/src/miracle_window_management_policy.cpp +++ b/src/miracle_window_management_policy.cpp @@ -159,7 +159,7 @@ void MiracleWindowManagementPolicy::advise_output_create(miral::Output const& ou void MiracleWindowManagementPolicy::advise_output_update(miral::Output const& updated, miral::Output const& original) { - for (auto pair : tree_list) + for (auto& pair : tree_list) { if (pair.output.is_same_output(original)) { diff --git a/src/node.cpp b/src/node.cpp index a68a70a..86894e2 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -360,4 +360,17 @@ std::shared_ptr Node::find_nth_window_child(int i) // The lane is correct, so let's get the first window in that lane. return sub_nodes[i]->find_nth_window_child(0); +} + +void Node::scale_area(double x_scale, double y_scale) +{ + area.size.width = geom::Width{ceil(x_scale * area.size.width.as_int())}; + area.size.height = geom::Height {ceil(y_scale * area.size.height.as_int())}; + + for (auto node : sub_nodes) + { + node->scale_area(x_scale, y_scale); + } + + redistribute_size(); } \ No newline at end of file diff --git a/src/node.h b/src/node.h index 6b63dcd..de79112 100644 --- a/src/node.h +++ b/src/node.h @@ -90,6 +90,8 @@ public: std::shared_ptr to_lane(); std::shared_ptr find_nth_window_child(int i); + void scale_area(double x_scale, double y_scale); + private: miral::Window window; std::vector> sub_nodes; diff --git a/src/window_tree.cpp b/src/window_tree.cpp index 36ee72d..758adfc 100644 --- a/src/window_tree.cpp +++ b/src/window_tree.cpp @@ -85,9 +85,12 @@ bool WindowTree::try_select_next(miracle::Direction direction) void WindowTree::resize_display(geom::Size new_size) { - size = new_size; - root_lane->redistribute_size(); - // TODO: Resize all windows + double x_scale = static_cast(new_size.width.as_int()) / static_cast(size.width.as_int()); + double y_scale = static_cast(new_size.height.as_int()) / static_cast(size.height.as_int()); + root_lane->scale_area(x_scale, y_scale); + size = geom::Size{ + geom::Width{ceil(size.width.as_int() * x_scale)}, + geom::Height {ceil(size.height.as_int() * y_scale)}}; } bool WindowTree::try_move_active_window(miracle::Direction direction)