From ea9376b4d708b72565ff39a5d633d7532c265811 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Tue, 19 Dec 2023 10:23:34 -0500 Subject: [PATCH] bugfix: translating other outputs when we resize an output --- src/miracle_window_management_policy.cpp | 2 +- src/node.cpp | 11 +++++++++++ src/node.h | 1 + src/window_tree.cpp | 11 ++++++++--- src/window_tree.h | 2 +- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/miracle_window_management_policy.cpp b/src/miracle_window_management_policy.cpp index fbb6b29..e3a1512 100644 --- a/src/miracle_window_management_policy.cpp +++ b/src/miracle_window_management_policy.cpp @@ -188,7 +188,7 @@ void MiracleWindowManagementPolicy::advise_output_update(miral::Output const& up { if (pair->output.is_same_output(original)) { - pair->tree.resize_display(updated.extents().size); + pair->tree.set_output_area(updated.extents()); break; } } diff --git a/src/node.cpp b/src/node.cpp index 86894e2..2111b78 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -372,5 +372,16 @@ void Node::scale_area(double x_scale, double y_scale) node->scale_area(x_scale, y_scale); } + redistribute_size(); +} + +void Node::translate_by(int x, int y) +{ + area.top_left.x = geom::X{area.top_left.x.as_int() + x}; + area.top_left.y = geom::Y{area.top_left.y.as_int() + y}; + for (auto node : sub_nodes) + { + node->translate_by(x, y); + } redistribute_size(); } \ No newline at end of file diff --git a/src/node.h b/src/node.h index de79112..1eaeef9 100644 --- a/src/node.h +++ b/src/node.h @@ -91,6 +91,7 @@ public: std::shared_ptr find_nth_window_child(int i); void scale_area(double x_scale, double y_scale); + void translate_by(int x, int y); private: miral::Window window; diff --git a/src/window_tree.cpp b/src/window_tree.cpp index 7a44699..f493e2e 100644 --- a/src/window_tree.cpp +++ b/src/window_tree.cpp @@ -83,14 +83,19 @@ bool WindowTree::try_select_next(miracle::Direction direction) return true; } -void WindowTree::resize_display(geom::Size new_size) +void WindowTree::set_output_area(geom::Rectangle new_area) { - double x_scale = static_cast(new_size.width.as_int()) / static_cast(area.size.width.as_int()); - double y_scale = static_cast(new_size.height.as_int()) / static_cast(area.size.height.as_int()); + double x_scale = static_cast(new_area.size.width.as_int()) / static_cast(area.size.width.as_int()); + double y_scale = static_cast(new_area.size.height.as_int()) / static_cast(area.size.height.as_int()); root_lane->scale_area(x_scale, y_scale); area.size = geom::Size{ geom::Width{ceil(area.size.width.as_int() * x_scale)}, geom::Height {ceil(area.size.height.as_int() * y_scale)}}; + + int position_diff_x = new_area.top_left.x.as_int() - area.top_left.x.as_int(); + int position_diff_y = new_area.top_left.y.as_int() - area.top_left.y.as_int(); + root_lane->translate_by(position_diff_x, position_diff_y); + area.top_left = new_area.top_left; } bool WindowTree::point_is_in_output(int x, int y) diff --git a/src/window_tree.h b/src/window_tree.h index b7cd492..e9eda2f 100644 --- a/src/window_tree.h +++ b/src/window_tree.h @@ -81,7 +81,7 @@ public: void advise_delete_window(miral::Window&); /// Called when the physical display is resized. - void resize_display(geom::Size new_size); + void set_output_area(geom::Rectangle new_area); bool point_is_in_output(int x, int y);