Skip to content

Commit

Permalink
bugfix: properly constraining apps with minimum size
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Jan 7, 2024
1 parent 5a6517e commit a98ef25
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 34 deletions.
15 changes: 13 additions & 2 deletions src/miracle_window_management_policy.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define MIR_LOG_COMPONENT "miracle"

#include "miracle_window_management_policy.h"
#include "window_helpers.h"

#include <mir_toolkit/events/enums.h>
#include <miral/toolkit_event.h>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
46 changes: 20 additions & 26 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,36 +519,12 @@ bool Node::minimize(std::shared_ptr<Node>& 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)
Expand All @@ -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<geom::Rectangle>());
else
info.clip_area(get_visible_area());
return;
}

for (auto node : sub_nodes)
{
node->constrain();
}
}
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Node : public std::enable_shared_from_this<Node>
int get_gap_x() { return gap_x; }
int get_gap_y() { return gap_y; }
std::vector<std::shared_ptr<Node>> const& get_sub_nodes() { return sub_nodes; }
void constrain();

private:
std::shared_ptr<Node> parent;
Expand Down
28 changes: 22 additions & 6 deletions src/window_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>::max()};
new_spec.min_height() = geom::Height{0};
new_spec.max_height() = geom::Height{std::numeric_limits<int>::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<int>::max()};
new_spec.min_height() = geom::Height{0};
new_spec.max_height() = geom::Height{std::numeric_limits<int>::max()};
return new_spec;
}

Expand Down Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/window_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a98ef25

Please sign in to comment.