Skip to content

Commit

Permalink
feature: abandoning any resize that would result in a too-small window
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Dec 28, 2023
1 parent 23ef5cb commit abcb130
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/miracle_window_management_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ auto MiracleWindowManagementPolicy::place_new_window(

void MiracleWindowManagementPolicy::advise_new_window(const miral::WindowInfo &window_info)
{

if (is_tileable(window_info))
{
miral::WindowSpecification mods;
constrain_window(mods, window_info);
window_manager_tools.modify_window(window_info.window(), mods);
}
}

void MiracleWindowManagementPolicy::handle_window_ready(miral::WindowInfo &window_info)
Expand Down Expand Up @@ -317,7 +322,7 @@ void set_if_needed(mir::optional_value<ValueType>& pending, ValueType const& cur
}


void MiracleWindowManagementPolicy::constrain_window(miral::WindowSpecification& mods, miral::WindowInfo& window_info)
void MiracleWindowManagementPolicy::constrain_window(miral::WindowSpecification& mods, miral::WindowInfo const& window_info)
{
set_if_needed(mods.min_width(), window_info.min_width(), geom::Width{0});
set_if_needed(mods.min_height(), window_info.min_height(), geom::Height{0});
Expand Down
2 changes: 1 addition & 1 deletion src/miracle_window_management_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MiracleWindowManagementPolicy : public miral::WindowManagementPolicy
miral::ExternalClientLauncher const external_client_launcher;
miral::InternalClientLauncher const internal_client_launcher;

void constrain_window(miral::WindowSpecification&, miral::WindowInfo&);
void constrain_window(miral::WindowSpecification&, miral::WindowInfo const&);
};
}

Expand Down
29 changes: 25 additions & 4 deletions src/window_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@ void WindowTree::resize_node_in_direction(
return;
}

constexpr int MIN_SIZE = 50;
bool is_negative = direction == Direction::left || direction == Direction::up;
auto resize_amount = is_negative ? -amount : amount;
auto nodes = parent->get_sub_nodes();
std::vector<geom::Rectangle> pending_node_resizes;
if (is_vertical)
{
int height_for_others = floor(-resize_amount / static_cast<float>(nodes.size() - 1));
Expand All @@ -395,10 +397,17 @@ void WindowTree::resize_node_in_direction(

if (i != 0)
{
auto prev_rect = nodes[i - 1]->get_logical_area();
auto prev_rect = pending_node_resizes[i - 1];
other_rect.top_left.y = geom::Y{prev_rect.top_left.y.as_int() + prev_rect.size.height.as_int()};
}
other_node->set_rectangle(other_rect);

if (other_rect.size.height.as_int() <= MIN_SIZE)
{
std::cerr << "Unable to resize a rectangle that would cause another to be negative\n";
return;
}

pending_node_resizes.push_back(other_rect);
}
}
else
Expand All @@ -415,12 +424,24 @@ void WindowTree::resize_node_in_direction(

if (i != 0)
{
auto prev_rect = nodes[i - 1]->get_logical_area();
auto prev_rect = pending_node_resizes[i - 1];
other_rect.top_left.x = geom::X{prev_rect.top_left.x.as_int() + prev_rect.size.width.as_int()};
}
other_node->set_rectangle(other_rect);

if (other_rect.size.width.as_int() <= MIN_SIZE)
{
std::cerr << "Unable to resize a rectangle that would cause another to be negative\n";
return;
}

pending_node_resizes.push_back(other_rect);
}
}

for (size_t i = 0; i < nodes.size(); i++)
{
nodes[i]->set_rectangle(pending_node_resizes[i]);
}
}

void WindowTree::advise_application_zone_create(miral::Zone const& application_zone)
Expand Down

0 comments on commit abcb130

Please sign in to comment.