2024-07-03 23:49:17 +03:00
|
|
|
/**
|
|
|
|
Copyright (C) 2024 Matthew Kosarek
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**/
|
|
|
|
|
2024-07-14 21:12:54 +03:00
|
|
|
#include "compositor_state.h"
|
2024-07-03 23:49:17 +03:00
|
|
|
#include "leaf_container.h"
|
|
|
|
#include "stub_configuration.h"
|
2024-07-14 21:12:54 +03:00
|
|
|
#include "stub_session.h"
|
|
|
|
#include "stub_surface.h"
|
2024-07-14 23:42:20 +03:00
|
|
|
#include "tiling_window_tree.h"
|
|
|
|
#include "window_controller.h"
|
2024-07-03 23:49:17 +03:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <miral/window_management_options.h>
|
|
|
|
|
|
|
|
using namespace miracle;
|
|
|
|
|
2024-08-18 16:52:59 +03:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
geom::Rectangle r {
|
|
|
|
geom::Point(0, 0),
|
|
|
|
geom::Size(1280, 720)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-07-03 23:49:17 +03:00
|
|
|
class SimpleTilingWindowTreeInterface : public TilingWindowTreeInterface
|
|
|
|
{
|
|
|
|
public:
|
2024-07-14 23:42:20 +03:00
|
|
|
std::vector<miral::Zone> const& get_zones() override
|
2024-07-03 23:49:17 +03:00
|
|
|
{
|
|
|
|
return zones;
|
|
|
|
}
|
|
|
|
|
2024-08-02 16:50:03 +03:00
|
|
|
Workspace* get_workspace() const override
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-07-03 23:49:17 +03:00
|
|
|
private:
|
2024-07-14 23:42:20 +03:00
|
|
|
std::vector<miral::Zone> zones = { r };
|
2024-07-03 23:49:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class StubWindowController : public miracle::WindowController
|
|
|
|
{
|
|
|
|
public:
|
2024-08-02 16:50:03 +03:00
|
|
|
StubWindowController(std::vector<std::pair<miral::Window, std::shared_ptr<Container>>>& pairs) :
|
2024-07-14 23:42:20 +03:00
|
|
|
pairs { pairs }
|
|
|
|
{
|
|
|
|
}
|
2024-07-03 23:49:17 +03:00
|
|
|
bool is_fullscreen(miral::Window const&) override
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2024-07-14 23:42:20 +03:00
|
|
|
void set_rectangle(miral::Window const&, geom::Rectangle const&, geom::Rectangle const&) override { }
|
2024-07-03 23:49:17 +03:00
|
|
|
MirWindowState get_state(miral::Window const&) override
|
|
|
|
{
|
|
|
|
return mir_window_state_restored;
|
|
|
|
}
|
|
|
|
|
2024-07-14 23:42:20 +03:00
|
|
|
void change_state(miral::Window const&, MirWindowState state) override { }
|
|
|
|
void clip(miral::Window const&, geom::Rectangle const&) override { }
|
|
|
|
void noclip(miral::Window const&) override { }
|
|
|
|
void select_active_window(miral::Window const&) override { }
|
2024-08-02 16:50:03 +03:00
|
|
|
std::shared_ptr<Container> get_container(miral::Window const& window) override
|
2024-07-03 23:49:17 +03:00
|
|
|
{
|
|
|
|
for (auto const& p : pairs)
|
|
|
|
{
|
|
|
|
if (p.first == window)
|
|
|
|
return p.second;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-07-14 23:42:20 +03:00
|
|
|
void raise(miral::Window const&) override { }
|
|
|
|
void send_to_back(miral::Window const&) override { }
|
|
|
|
void open(miral::Window const&) override { }
|
|
|
|
void close(miral::Window const&) override { }
|
2024-08-02 16:50:03 +03:00
|
|
|
void on_animation(miracle::AnimationStepResult const& result, std::shared_ptr<Container> const&) override { }
|
2024-07-14 23:42:20 +03:00
|
|
|
void set_user_data(miral::Window const&, std::shared_ptr<void> const&) override { }
|
|
|
|
void modify(miral::Window const&, miral::WindowSpecification const&) override { }
|
|
|
|
miral::WindowInfo& info_for(miral::Window const&) override { }
|
2024-07-03 23:49:17 +03:00
|
|
|
|
|
|
|
private:
|
2024-08-02 16:50:03 +03:00
|
|
|
std::vector<std::pair<miral::Window, std::shared_ptr<Container>>>& pairs;
|
2024-07-03 23:49:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class TilingWindowTreeTest : public testing::Test
|
|
|
|
{
|
|
|
|
public:
|
2024-07-14 23:42:20 +03:00
|
|
|
TilingWindowTreeTest() :
|
|
|
|
tree(
|
2024-07-03 23:49:17 +03:00
|
|
|
std::make_unique<SimpleTilingWindowTreeInterface>(),
|
|
|
|
window_controller,
|
2024-07-14 21:12:54 +03:00
|
|
|
state,
|
2024-08-18 16:52:59 +03:00
|
|
|
std::make_shared<test::StubConfiguration>(),
|
|
|
|
r)
|
2024-07-03 23:49:17 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<LeafContainer> create_leaf()
|
|
|
|
{
|
|
|
|
miral::WindowSpecification spec;
|
2024-07-18 23:12:11 +03:00
|
|
|
spec = tree.place_new_window(spec, nullptr);
|
2024-07-03 23:49:17 +03:00
|
|
|
|
2024-07-14 21:12:54 +03:00
|
|
|
auto session = std::make_shared<test::StubSession>();
|
|
|
|
sessions.push_back(session);
|
|
|
|
auto surface = std::make_shared<test::StubSurface>();
|
|
|
|
surfaces.push_back(surface);
|
2024-07-14 23:42:20 +03:00
|
|
|
|
2024-07-14 21:12:54 +03:00
|
|
|
miral::Window window(session, surface);
|
2024-07-03 23:49:17 +03:00
|
|
|
miral::WindowInfo info(window, spec);
|
|
|
|
|
2024-07-18 23:12:11 +03:00
|
|
|
auto leaf = tree.confirm_window(info, nullptr);
|
2024-08-02 16:50:03 +03:00
|
|
|
pairs.push_back({ window, leaf });
|
2024-07-14 21:12:54 +03:00
|
|
|
|
2024-08-03 23:34:45 +03:00
|
|
|
state.active = leaf;
|
2024-08-02 16:50:03 +03:00
|
|
|
tree.advise_focus_gained(*leaf);
|
2024-07-03 23:49:17 +03:00
|
|
|
return leaf;
|
|
|
|
}
|
|
|
|
|
2024-07-14 21:12:54 +03:00
|
|
|
CompositorState state;
|
|
|
|
std::vector<std::shared_ptr<test::StubSession>> sessions;
|
|
|
|
std::vector<std::shared_ptr<test::StubSurface>> surfaces;
|
2024-08-02 16:50:03 +03:00
|
|
|
std::vector<std::pair<miral::Window, std::shared_ptr<Container>>> pairs;
|
2024-07-14 23:42:20 +03:00
|
|
|
StubWindowController window_controller { pairs };
|
2024-07-03 23:49:17 +03:00
|
|
|
TilingWindowTree tree;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(TilingWindowTreeTest, can_add_single_window_without_border_and_gaps)
|
|
|
|
{
|
|
|
|
auto leaf = create_leaf();
|
|
|
|
ASSERT_EQ(leaf->get_logical_area().size, geom::Size(1280, 720));
|
|
|
|
ASSERT_EQ(leaf->get_logical_area().top_left, geom::Point(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TilingWindowTreeTest, can_add_two_windows_horizontally_without_border_and_gaps)
|
|
|
|
{
|
|
|
|
auto leaf1 = create_leaf();
|
|
|
|
auto leaf2 = create_leaf();
|
|
|
|
|
|
|
|
ASSERT_EQ(leaf1->get_logical_area().size, geom::Size(1280 / 2.f, 720));
|
|
|
|
ASSERT_EQ(leaf1->get_logical_area().top_left, geom::Point(0, 0));
|
|
|
|
|
|
|
|
ASSERT_EQ(leaf2->get_logical_area().size, geom::Size(1280 / 2.f, 720));
|
|
|
|
ASSERT_EQ(leaf2->get_logical_area().top_left, geom::Point(1280 / 2.f, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TilingWindowTreeTest, can_add_two_windows_vertically_without_border_and_gaps)
|
|
|
|
{
|
|
|
|
auto leaf1 = create_leaf();
|
|
|
|
|
2024-08-02 16:50:03 +03:00
|
|
|
tree.request_vertical_layout(*leaf1);
|
2024-07-03 23:49:17 +03:00
|
|
|
|
|
|
|
auto leaf2 = create_leaf();
|
|
|
|
ASSERT_EQ(leaf1->get_logical_area().size, geom::Size(1280, 720 / 2.f));
|
|
|
|
ASSERT_EQ(leaf1->get_logical_area().top_left, geom::Point(0, 0));
|
|
|
|
|
|
|
|
ASSERT_EQ(leaf2->get_logical_area().size, geom::Size(1280, 720 / 2.f));
|
2024-07-14 23:42:20 +03:00
|
|
|
ASSERT_EQ(leaf2->get_logical_area().top_left, geom::Point(0, 720 / 2.f));
|
2024-07-03 23:49:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TilingWindowTreeTest, can_add_three_windows_horizontally_without_border_and_gaps)
|
|
|
|
{
|
|
|
|
auto leaf1 = create_leaf();
|
|
|
|
auto leaf2 = create_leaf();
|
|
|
|
auto leaf3 = create_leaf();
|
|
|
|
|
|
|
|
ASSERT_EQ(leaf1->get_logical_area().size, geom::Size(ceilf(1280 / 3.f), 720));
|
|
|
|
ASSERT_EQ(leaf1->get_logical_area().top_left, geom::Point(0, 0));
|
|
|
|
|
|
|
|
ASSERT_EQ(leaf2->get_logical_area().size, geom::Size(ceilf(1280 / 3.f), 720));
|
|
|
|
ASSERT_EQ(leaf2->get_logical_area().top_left, geom::Point(ceilf(1280 / 3.f), 0));
|
|
|
|
|
|
|
|
ASSERT_EQ(leaf3->get_logical_area().size, geom::Size(floorf(1280 / 3.f), 720));
|
|
|
|
ASSERT_EQ(leaf3->get_logical_area().top_left, geom::Point(floorf(1280 * (2.f / 3.f)) - 1, 0));
|
|
|
|
}
|