From bf58fc49fe6e607e1f0c99bfdf36e0a888e9c3fa Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 1 Dec 2023 09:25:48 -0500 Subject: [PATCH] bugfix: able to change direction on a single-child window --- src/window_tree.cpp | 31 +++++++++++++++++++++++++------ src/window_tree.h | 1 + 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/window_tree.cpp b/src/window_tree.cpp index cfb76f3..39cea9b 100644 --- a/src/window_tree.cpp +++ b/src/window_tree.cpp @@ -106,16 +106,35 @@ void WindowTree::resize(geom::Size new_size) void WindowTree::request_vertical() { - active_lane = active_lane->find_node_for_window(active_window); - active_lane->to_lane(); - active_lane->set_direction(NodeDirection::vertical); + handle_direction_request(NodeDirection::vertical); } void WindowTree::request_horizontal() { - active_lane = active_lane->find_node_for_window(active_window); - active_lane->to_lane(); - active_lane->set_direction(NodeDirection::horizontal); + handle_direction_request(NodeDirection::horizontal); +} + +void WindowTree::handle_direction_request(NodeDirection direction) +{ + auto window_lane = active_lane->find_node_for_window(active_window); + if (!window_lane->is_window()) + { + std::cerr << "WindowTree::handle_direction_request: must change direction of a window" << std::endl; + return; + } + + // Edge case: if we're an only child, we can just change the direction of the parent to achieve the same effect + if (window_lane->parent->get_sub_nodes().size() == 1) + { + active_lane = window_lane->parent; + } + else + { + active_lane = window_lane; + active_lane->to_lane(); + } + + active_lane->set_direction(direction); } void WindowTree::advise_focus_gained(miral::Window& window) diff --git a/src/window_tree.h b/src/window_tree.h index 99cf027..22426da 100644 --- a/src/window_tree.h +++ b/src/window_tree.h @@ -57,6 +57,7 @@ public: void advise_delete_window(miral::Window&); private: + void handle_direction_request(NodeDirection direction); std::shared_ptr root_lane; std::shared_ptr active_lane; miral::Window active_window;