Skip to content

Commit

Permalink
(#373) workspaces select the application zone as their area during co…
Browse files Browse the repository at this point in the history
…nstruction
  • Loading branch information
mattkae committed Feb 6, 2025
1 parent 33a7877 commit 913411b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
19 changes: 12 additions & 7 deletions src/workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ std::shared_ptr<Container> foreach_node_internal(

return nullptr;
}

geom::Rectangle get_output_area(OutputInterface const* output)
{
auto const& zones = output->get_app_zones();
if (!zones.empty())
return zones[0].extents();

return output->get_area();
}
}

Workspace::Workspace(
Expand All @@ -110,7 +119,7 @@ Workspace::Workspace(
state { state },
config { config },
root(std::make_shared<ParentContainer>(
state, window_controller, config, output->get_area(), this, nullptr, true))
state, window_controller, config, get_output_area(output), this, nullptr, true))
{
config_handle = config->register_listener([this](auto const&)
{
Expand All @@ -131,12 +140,8 @@ void Workspace::set_area(mir::geometry::Rectangle const& area)

void Workspace::recalculate_area()
{
for (auto const& zone : output->get_app_zones())
{
root->set_logical_area(zone.extents());
root->commit_changes();
break;
}
root->set_logical_area(get_output_area(output));
root->commit_changes();
}

AllocationHint Workspace::allocate_position(
Expand Down
48 changes: 42 additions & 6 deletions tests/test_workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ namespace
const float OUTPUT_WIDTH = 1280;
const float OUTPUT_HEIGHT = 720;

const geom::Rectangle TREE_BOUNDS {
const geom::Rectangle OUTPUT_SIZE {
geom::Point(0, 0),
geom::Size(OUTPUT_WIDTH, OUTPUT_HEIGHT)
};

const geom::Rectangle OTHER_TREE_BOUNDS {
const geom::Rectangle OTHER_OUTPUT_SIZE {
geom::Point(OUTPUT_WIDTH, OUTPUT_HEIGHT),
geom::Size(OUTPUT_WIDTH, OUTPUT_HEIGHT)
};

std::vector<std::shared_ptr<WorkspaceInterface>> empty_workspaces;
std::vector<miral::Zone> empty_app_zones;

std::unique_ptr<test::MockOutput> create_output(geom::Rectangle const& bounds)
{
Expand All @@ -55,6 +56,8 @@ std::unique_ptr<test::MockOutput> create_output(geom::Rectangle const& bounds)
.WillByDefault(testing::ReturnRef(bounds));
ON_CALL(*output, get_workspaces())
.WillByDefault(testing::ReturnRef(empty_workspaces));
ON_CALL(*output, get_app_zones())
.WillByDefault(testing::ReturnRef(empty_app_zones));
return output;
}
}
Expand All @@ -64,7 +67,7 @@ class WorkspaceTest : public testing::Test
public:
WorkspaceTest() :
state(std::make_shared<CompositorState>()),
output(create_output(TREE_BOUNDS)),
output(create_output(OUTPUT_SIZE)),
window_controller(std::make_shared<StubWindowController>(pairs)),
workspace(
output.get(),
Expand Down Expand Up @@ -216,7 +219,7 @@ TEST_F(WorkspaceTest, can_move_container_to_different_parent)

TEST_F(WorkspaceTest, can_move_container_to_container_in_other_tree)
{
auto other_output = create_output(OTHER_TREE_BOUNDS);
auto other_output = create_output(OTHER_OUTPUT_SIZE);
Workspace other(
other_output.get(),
1,
Expand All @@ -238,7 +241,7 @@ TEST_F(WorkspaceTest, can_move_container_to_container_in_other_tree)

TEST_F(WorkspaceTest, can_move_container_to_tree)
{
auto other_output = create_output(OTHER_TREE_BOUNDS);
auto other_output = create_output(OTHER_OUTPUT_SIZE);
Workspace other(
other_output.get(),
1,
Expand All @@ -252,7 +255,7 @@ TEST_F(WorkspaceTest, can_move_container_to_tree)
ASSERT_EQ(leaf1->get_workspace(), &workspace);
ASSERT_TRUE(other.add_to_root(*leaf1));
ASSERT_EQ(leaf1->get_workspace(), &other);
ASSERT_EQ(leaf1->get_logical_area(), OTHER_TREE_BOUNDS);
ASSERT_EQ(leaf1->get_logical_area(), OTHER_OUTPUT_SIZE);
}

TEST_F(WorkspaceTest, dragged_windows_do_not_change_their_position_when_a_new_window_is_added)
Expand All @@ -275,3 +278,36 @@ TEST_F(WorkspaceTest, dragged_windows_are_unconstrained)
leaf1->drag_stop();
ASSERT_EQ(window_controller->get_window_data(leaf1).clip, leaf1->get_visible_area());
}

TEST_F(WorkspaceTest, workspace_bounds_are_initialized_to_output_size_when_no_app_zones_are_present)
{
// Assert that the first tree (w/o app zones) is equal to the output size.
ASSERT_EQ(workspace.get_root()->get_logical_area(), OUTPUT_SIZE);
}

TEST_F(WorkspaceTest, workspace_bounds_are_initialized_to_first_zone_size_when_app_zones_are_present)
{
auto output = std::make_unique<testing::NiceMock<test::MockOutput>>();
ON_CALL(*output, get_area())
.WillByDefault(testing::ReturnRef(OTHER_OUTPUT_SIZE));
ON_CALL(*output, get_workspaces())
.WillByDefault(testing::ReturnRef(empty_workspaces));

mir::geometry::Rectangle const zone_bounds(
mir::geometry::Point(100, 100),
mir::geometry::Size(500, 500));
std::vector<miral::Zone> zones = { miral::Zone(zone_bounds) };
ON_CALL(*output, get_app_zones())
.WillByDefault(testing::ReturnRef(zones));
Workspace other(
output.get(),
1,
1,
"1",
std::make_shared<test::StubConfiguration>(),
window_controller,
state);

// Assert that the first tree (w/o app zones) is equal to the output size.
ASSERT_EQ(other.get_root()->get_logical_area(), zone_bounds);
}

0 comments on commit 913411b

Please sign in to comment.