diff --git a/src/miracle_window_management_policy.cpp b/src/miracle_window_management_policy.cpp index 27229fc7..3a13c283 100644 --- a/src/miracle_window_management_policy.cpp +++ b/src/miracle_window_management_policy.cpp @@ -1,6 +1,7 @@ #define MIR_LOG_COMPONENT "miracle" #include "miracle_window_management_policy.h" +#include "window_helpers.h" #include #include @@ -84,7 +85,7 @@ bool MiracleWindowManagementPolicy::handle_keyboard_event(MirKeyboardEvent const auto const scan_code = miral::toolkit::mir_keyboard_event_scan_code(event); auto const modifiers = miral::toolkit::mir_keyboard_event_modifiers(event) & MODIFIER_MASK; - if (action == MirKeyboardAction::mir_keyboard_action_down && (modifiers & mir_input_event_modifier_alt)) + if (action == MirKeyboardAction::mir_keyboard_action_down && (modifiers & mir_input_event_modifier_meta)) { if (scan_code == KEY_ENTER) { @@ -212,7 +213,10 @@ void MiracleWindowManagementPolicy::handle_window_ready(miral::WindowInfo &windo for (auto tree : tree_list) { if (tree->tree.handle_window_ready(window_info)) + { + tree->tree.constrain(window_info); break; + } } } @@ -304,6 +308,7 @@ void MiracleWindowManagementPolicy::handle_modify_window( miral::WindowInfo &window_info, const miral::WindowSpecification &modifications) { + auto new_mods = modifications; if (modifications.state().is_set()) { if (modifications.state().value() == mir_window_state_fullscreen || modifications.state().value() == mir_window_state_maximized) @@ -322,7 +327,13 @@ void MiracleWindowManagementPolicy::handle_modify_window( } } - window_manager_tools.modify_window(window_info.window(), modifications); + window_manager_tools.modify_window(window_info.window(), new_mods); + + for (auto tree :tree_list) + { + if (tree->tree.constrain(window_info)) + break; + } } void MiracleWindowManagementPolicy::handle_raise_window(miral::WindowInfo &window_info) diff --git a/src/node.cpp b/src/node.cpp index 9235fffe..83afc541 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -519,36 +519,12 @@ bool Node::minimize(std::shared_ptr& node) int Node::get_min_width() { - if (is_window()) - { - miral::WindowInfo& info = tools.info_for(window); - return info.min_width().as_int(); - } - - int min_width = 50; - for (auto node : sub_nodes) - { - min_width = std::max(node->get_min_width(), min_width); - } - - return min_width; + return 50; } int Node::get_min_height() { - if (is_window()) - { - miral::WindowInfo& info = tools.info_for(window); - return info.min_height().as_int(); - } - - int min_height = 50; - for (auto node : sub_nodes) - { - min_height = std::max(node->get_min_height(), min_height); - } - - return min_height; + return 50; } void Node::_set_window_rectangle(geom::Rectangle area) @@ -562,4 +538,22 @@ void Node::_set_window_rectangle(geom::Rectangle area) child.move_to(visible_rect.top_left); child.resize(visible_rect.size); } +} + +void Node::constrain() +{ + if (is_window()) + { + auto& info = tools.info_for(window); + if (window_helpers::is_window_fullscreen(info.state())) + info.clip_area(mir::optional_value()); + else + info.clip_area(get_visible_area()); + return; + } + + for (auto node : sub_nodes) + { + node->constrain(); + } } \ No newline at end of file diff --git a/src/node.h b/src/node.h index 07b37d68..4582bb39 100644 --- a/src/node.h +++ b/src/node.h @@ -89,6 +89,7 @@ class Node : public std::enable_shared_from_this int get_gap_x() { return gap_x; } int get_gap_y() { return gap_y; } std::vector> const& get_sub_nodes() { return sub_nodes; } + void constrain(); private: std::shared_ptr parent; diff --git a/src/window_tree.cpp b/src/window_tree.cpp index 7c6d0758..810b8ab9 100644 --- a/src/window_tree.cpp +++ b/src/window_tree.cpp @@ -34,19 +34,19 @@ WindowTree::WindowTree( miral::WindowSpecification WindowTree::allocate_position(const miral::WindowSpecification &requested_specification) { + miral::WindowSpecification new_spec = requested_specification; + new_spec.min_width() = geom::Width{0}; + new_spec.max_width() = geom::Width{std::numeric_limits::max()}; + new_spec.min_height() = geom::Height{0}; + new_spec.max_height() = geom::Height{std::numeric_limits::max()}; if (requested_specification.state().is_set() && window_helpers::is_window_fullscreen(requested_specification.state().value())) { - return requested_specification; + return new_spec; } - miral::WindowSpecification new_spec = requested_specification; auto rect = get_active_lane()->new_node_position(); new_spec.size() = rect.size; new_spec.top_left() = rect.top_left; - new_spec.min_width() = geom::Width{0}; - new_spec.max_width() = geom::Width{std::numeric_limits::max()}; - new_spec.min_height() = geom::Height{0}; - new_spec.max_height() = geom::Height{std::numeric_limits::max()}; return new_spec; } @@ -609,5 +609,21 @@ bool WindowTree::confirm_placement_on_display( break; } + return true; +} + +bool WindowTree::constrain(miral::WindowInfo &window_info) +{ + auto node = root_lane->find_node_for_window(window_info.window()); + if (!node) + return false; + + if (!node->get_parent()) + { + std::cerr << "Unable to constrain node without parent\n"; + return true; + } + + node->get_parent()->constrain(); return true; } \ No newline at end of file diff --git a/src/window_tree.h b/src/window_tree.h index 2d737cec..5abac4fa 100644 --- a/src/window_tree.h +++ b/src/window_tree.h @@ -93,6 +93,9 @@ class WindowTree MirWindowState new_state, mir::geometry::Rectangle &new_placement); + /// Constrains the window to its tile if it is in this tree. + bool constrain(miral::WindowInfo& window_info); + private: miral::WindowManagerTools tools; WindowTreeOptions options;