feature: resizing the display resizes the windows in it

This commit is contained in:
Matthew Kosarek 2023-12-19 09:44:29 -05:00
parent a1eb6f7347
commit e3add8c55e
4 changed files with 22 additions and 4 deletions

View File

@ -159,7 +159,7 @@ void MiracleWindowManagementPolicy::advise_output_create(miral::Output const& ou
void MiracleWindowManagementPolicy::advise_output_update(miral::Output const& updated, miral::Output const& original)
{
for (auto pair : tree_list)
for (auto& pair : tree_list)
{
if (pair.output.is_same_output(original))
{

View File

@ -360,4 +360,17 @@ std::shared_ptr<Node> Node::find_nth_window_child(int i)
// The lane is correct, so let's get the first window in that lane.
return sub_nodes[i]->find_nth_window_child(0);
}
void Node::scale_area(double x_scale, double y_scale)
{
area.size.width = geom::Width{ceil(x_scale * area.size.width.as_int())};
area.size.height = geom::Height {ceil(y_scale * area.size.height.as_int())};
for (auto node : sub_nodes)
{
node->scale_area(x_scale, y_scale);
}
redistribute_size();
}

View File

@ -90,6 +90,8 @@ public:
std::shared_ptr<Node> to_lane();
std::shared_ptr<Node> find_nth_window_child(int i);
void scale_area(double x_scale, double y_scale);
private:
miral::Window window;
std::vector<std::shared_ptr<Node>> sub_nodes;

View File

@ -85,9 +85,12 @@ bool WindowTree::try_select_next(miracle::Direction direction)
void WindowTree::resize_display(geom::Size new_size)
{
size = new_size;
root_lane->redistribute_size();
// TODO: Resize all windows
double x_scale = static_cast<double>(new_size.width.as_int()) / static_cast<double>(size.width.as_int());
double y_scale = static_cast<double>(new_size.height.as_int()) / static_cast<double>(size.height.as_int());
root_lane->scale_area(x_scale, y_scale);
size = geom::Size{
geom::Width{ceil(size.width.as_int() * x_scale)},
geom::Height {ceil(size.height.as_int() * y_scale)}};
}
bool WindowTree::try_move_active_window(miracle::Direction direction)