diff --git a/autotests/client/drm_lease_v1.cpp b/autotests/client/drm_lease_v1.cpp index 4ff8116d..f67b7db1 100644 --- a/autotests/client/drm_lease_v1.cpp +++ b/autotests/client/drm_lease_v1.cpp @@ -78,6 +78,8 @@ void drm_lease_v1_test::init() server.display->start(); QVERIFY(server.display->running()); + server.globals.output_manager + = std::make_unique(*server.display); server.display->createShm(); server.globals.drm_lease_device_v1 = std::make_unique(server.display.get()); @@ -209,7 +211,7 @@ void drm_lease_v1_test::test_connectors() std::vector> server_outputs; auto add_output = [&server_outputs, this] { server_outputs.emplace_back( - std::make_unique(server.display.get())); + std::make_unique(*server.globals.output_manager)); }; add_output(); @@ -289,7 +291,7 @@ void drm_lease_v1_test::test_lease() std::vector> server_outputs; auto add_output = [&server_outputs, this] { server_outputs.emplace_back( - std::make_unique(server.display.get())); + std::make_unique(*server.globals.output_manager)); }; add_output(); diff --git a/autotests/client/layer_shell.cpp b/autotests/client/layer_shell.cpp index b3cf6d65..1fdefea1 100644 --- a/autotests/client/layer_shell.cpp +++ b/autotests/client/layer_shell.cpp @@ -48,8 +48,8 @@ private Q_SLOTS: private: struct { std::unique_ptr display; - Wrapland::Server::globals globals; std::unique_ptr output; + Wrapland::Server::globals globals; } server; QThread* m_thread{nullptr}; @@ -73,6 +73,8 @@ void layer_shell_test::init() server.display->start(); QVERIFY(server.display->running()); + server.globals.output_manager + = std::make_unique(*server.display); server.display->createShm(); server.globals.compositor = std::make_unique(server.display.get()); @@ -80,7 +82,7 @@ void layer_shell_test::init() = std::make_unique(server.display.get()); server.globals.xdg_shell = std::make_unique(server.display.get()); - server.output = std::make_unique(server.display.get()); + server.output = std::make_unique(*server.globals.output_manager); server.output->set_enabled(true); server.output->done(); diff --git a/autotests/client/output.cpp b/autotests/client/output.cpp index eae681b3..8bdfcc37 100644 --- a/autotests/client/output.cpp +++ b/autotests/client/output.cpp @@ -27,6 +27,7 @@ License along with this library. If not, see . #include "../../server/display.h" #include "../../server/dpms.h" +#include "../../server/output_manager.h" #include @@ -62,6 +63,7 @@ private Q_SLOTS: struct { std::unique_ptr display; std::unique_ptr output; + std::unique_ptr output_manager; } server; Clt::ConnectionThread* m_connection; @@ -85,8 +87,9 @@ void TestOutput::init() server.display->start(); QVERIFY(server.display->running()); + server.output_manager = std::make_unique(*server.display); Srv::output_metadata meta{.name = "HDMI-A", .make = "Foocorp", .model = "Barmodel"}; - server.output = std::make_unique(meta, server.display.get()); + server.output = std::make_unique(meta, *server.output_manager); QCOMPARE(server.output->mode_size(), QSize()); QCOMPARE(server.output->refresh_rate(), 60000); diff --git a/autotests/client/output_device.cpp b/autotests/client/output_device.cpp index 1a64ae59..95eb2773 100644 --- a/autotests/client/output_device.cpp +++ b/autotests/client/output_device.cpp @@ -26,6 +26,7 @@ License along with this library. If not, see . #include "../../server/display.h" #include "../../server/output.h" +#include "../../server/output_manager.h" #include @@ -58,6 +59,7 @@ private Q_SLOTS: struct { std::unique_ptr display; std::unique_ptr output; + std::unique_ptr output_manager; } server; std::string m_name = "HDMI-A"; @@ -84,6 +86,8 @@ TestOutputDevice::TestOutputDevice(QObject* parent) void TestOutputDevice::init() { server.display = std::make_unique(); + server.output_manager = std::make_unique(*server.display); + server.display->set_socket_name(std::string(socket_name)); server.display->start(); QVERIFY(server.display->running()); @@ -93,7 +97,7 @@ void TestOutputDevice::init() .model = m_model, .serial_number = m_serialNumber, .physical_size = {200, 100}}; - server.output = std::make_unique(meta, server.display.get()); + server.output = std::make_unique(meta, *server.output_manager); Srv::output_mode m0; m0.id = 0; diff --git a/autotests/client/output_management.cpp b/autotests/client/output_management.cpp index ac60a1a7..1113716d 100644 --- a/autotests/client/output_management.cpp +++ b/autotests/client/output_management.cpp @@ -72,8 +72,8 @@ private Q_SLOTS: struct { std::unique_ptr display; - Wrapland::Server::globals globals; std::unique_ptr output; + Wrapland::Server::globals globals; } server; Clt::Registry* m_registry = nullptr; @@ -113,9 +113,11 @@ void TestOutputManagement::init() server.display->start(); QVERIFY(server.display->running()); + server.globals.output_manager + = std::make_unique(*server.display); server.globals.compositor = std::make_unique(server.display.get()); - server.output = std::make_unique(server.display.get()); + server.output = std::make_unique(*server.globals.output_manager); Srv::output_mode m0; m0.id = 0; @@ -147,7 +149,7 @@ void TestOutputManagement::init() server.output->set_enabled(true); server.output->done(); - server.globals.output_management_v1 + server.globals.output_manager->management_v1 = std::make_unique(server.display.get()); // setup connection @@ -292,10 +294,10 @@ void TestOutputManagement::testBasicMemoryManagement() { createConfig(); - QSignalSpy serverApplySpy(server.globals.output_management_v1.get(), + QSignalSpy serverApplySpy(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested); Srv::OutputConfigurationV1* configurationInterface = nullptr; - connect(server.globals.output_management_v1.get(), + connect(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested, [=, &configurationInterface](Srv::OutputConfigurationV1* c) { configurationInterface = c; @@ -319,7 +321,7 @@ void TestOutputManagement::testRemoval() QSignalSpy outputManagementRemovedSpy(m_registry, &Clt::Registry::outputManagementV1Removed); QVERIFY(outputManagementRemovedSpy.isValid()); - server.globals.output_management_v1.reset(); + server.globals.output_manager->management_v1.reset(); QVERIFY(outputManagementRemovedSpy.wait(200)); QCOMPARE(outputManagementRemovedSpy.first().first(), m_announcedSpy->first().first()); QVERIFY(!m_registry->hasInterface(Clt::Registry::Interface::OutputManagementV1)); @@ -332,7 +334,7 @@ void TestOutputManagement::testApplied() QVERIFY(m_outputConfiguration->isValid()); QSignalSpy appliedSpy(m_outputConfiguration, &Clt::OutputConfigurationV1::applied); - connect(server.globals.output_management_v1.get(), + connect(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested, [=](Srv::OutputConfigurationV1* configurationInterface) { configurationInterface->setApplied(); @@ -348,7 +350,7 @@ void TestOutputManagement::testFailed() QVERIFY(m_outputConfiguration->isValid()); QSignalSpy failedSpy(m_outputConfiguration, &Clt::OutputConfigurationV1::failed); - connect(server.globals.output_management_v1.get(), + connect(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested, [=](Srv::OutputConfigurationV1* configurationInterface) { configurationInterface->setFailed(); @@ -391,13 +393,13 @@ void TestOutputManagement::testMultipleSettings() QSignalSpy outputChangedSpy(output, &Clt::OutputDeviceV1::changed); Srv::OutputConfigurationV1* configurationInterface; - connect(server.globals.output_management_v1.get(), + connect(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested, [=, &configurationInterface](Srv::OutputConfigurationV1* c) { applyPendingChanges(c); configurationInterface = c; }); - QSignalSpy serverApplySpy(server.globals.output_management_v1.get(), + QSignalSpy serverApplySpy(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested); QVERIFY(serverApplySpy.isValid()); @@ -443,7 +445,7 @@ void TestOutputManagement::testConfigFailed() QVERIFY(config->isValid()); QVERIFY(output->isValid()); - QSignalSpy serverApplySpy(server.globals.output_management_v1.get(), + QSignalSpy serverApplySpy(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested); QVERIFY(serverApplySpy.isValid()); QSignalSpy outputChangedSpy(output, &Clt::OutputDeviceV1::changed); @@ -459,7 +461,7 @@ void TestOutputManagement::testConfigFailed() config->apply(); - connect(server.globals.output_management_v1.get(), + connect(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested, [=](Srv::OutputConfigurationV1* c) { c->setFailed(); }); @@ -483,7 +485,7 @@ void TestOutputManagement::testExampleConfig() // config->setGeometry(output, QRectF(QPoint(-1, -1), output->geometry().size())); QSignalSpy configAppliedSpy(config, &Clt::OutputConfigurationV1::applied); - connect(server.globals.output_management_v1.get(), + connect(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested, [=](Srv::OutputConfigurationV1* c) { c->setApplied(); }); config->apply(); @@ -503,7 +505,7 @@ void TestOutputManagement::testScale() config->apply(); QSignalSpy configAppliedSpy(config, &OutputConfiguration::applied); - connect(server.globals.output_management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested, [=](Srv::OutputConfigurationV1 *c) { + connect(server.globals.output_manager->management_v1.get(), &Srv::OutputManagementV1::configurationChangeRequested, [=](Srv::OutputConfigurationV1 *c) { applyPendingChanges(c); c->setApplied(); }); diff --git a/autotests/client/plasma_window_management.cpp b/autotests/client/plasma_window_management.cpp index 798ef164..543454f1 100644 --- a/autotests/client/plasma_window_management.cpp +++ b/autotests/client/plasma_window_management.cpp @@ -173,6 +173,8 @@ void TestWindowManagement::init() QVERIFY(m_registry->isValid()); m_registry->setup(); + server.globals.output_manager + = std::make_unique(*server.display); server.globals.compositor = std::make_unique(server.display.get()); QVERIFY(compositorSpy.wait()); @@ -859,7 +861,7 @@ void TestWindowManagement::testSendToOutput() QSignalSpy outputAnnouncedSpy(m_registry, &Wrapland::Client::Registry::outputAnnounced); QVERIFY(outputAnnouncedSpy.isValid()); - auto srv_output = std::make_unique(server.display.get()); + auto srv_output = std::make_unique(*server.globals.output_manager); srv_output->set_enabled(true); srv_output->done(); diff --git a/autotests/client/presentation_time.cpp b/autotests/client/presentation_time.cpp index c8965aff..34ed865c 100644 --- a/autotests/client/presentation_time.cpp +++ b/autotests/client/presentation_time.cpp @@ -54,8 +54,8 @@ private Q_SLOTS: private: struct { std::unique_ptr display; - Wrapland::Server::globals globals; std::unique_ptr output; + Wrapland::Server::globals globals; } server; Client::ConnectionThread* m_connection; @@ -89,12 +89,14 @@ void TestPresentationTime::init() server.display->createShm(); + server.globals.output_manager + = std::make_unique(*server.display); server.globals.compositor = std::make_unique(server.display.get()); server.globals.presentation_manager = std::make_unique(server.display.get()); - server.output = std::make_unique(server.display.get()); + server.output = std::make_unique(*server.globals.output_manager); server.output->set_enabled(true); server.output->done(); diff --git a/autotests/client/registry.cpp b/autotests/client/registry.cpp index ac928d58..0c2b8911 100644 --- a/autotests/client/registry.cpp +++ b/autotests/client/registry.cpp @@ -166,11 +166,12 @@ void TestWaylandRegistry::init() server.display->start(); server.display->createShm(); - + server.globals.output_manager + = std::make_unique(*server.display); server.globals.compositor = std::make_unique(server.display.get()); server.globals.outputs.emplace_back( - std::make_unique(server.display.get())); + std::make_unique(*server.globals.output_manager)); server.globals.seats.emplace_back( std::make_unique(server.display.get())); server.globals.subcompositor @@ -181,8 +182,8 @@ void TestWaylandRegistry::init() = std::make_unique(server.display.get()); server.globals.drm_lease_device_v1 = std::make_unique(server.display.get()); - server.globals.output_management_v1 - = std::make_unique(server.display.get()); + server.globals.output_manager->create_management_v1(); + server.globals.output_manager->create_xdg_manager(); server.globals.blur_manager = std::make_unique(server.display.get()); server.globals.contrast_manager @@ -229,6 +230,7 @@ void TestWaylandRegistry::init() void TestWaylandRegistry::cleanup() { + server = {}; } void TestWaylandRegistry::testCreate() @@ -728,7 +730,7 @@ void TestWaylandRegistry::testRemoval() QSignalSpy outputManagementRemovedSpy(®istry, SIGNAL(outputManagementV1Removed(quint32))); QVERIFY(outputManagementRemovedSpy.isValid()); - server.globals.output_management_v1.reset(); + server.globals.output_manager->management_v1.reset(); QVERIFY(outputManagementRemovedSpy.wait()); QCOMPARE(outputManagementRemovedSpy.first().first(), outputManagementAnnouncedSpy.first().first()); @@ -1030,7 +1032,7 @@ void TestWaylandRegistry::testAnnounceMultiple() QSignalSpy outputAnnouncedSpy(®istry, &Registry::outputAnnounced); QVERIFY(outputAnnouncedSpy.isValid()); - auto output1 = std::make_unique(server.display.get()); + auto output1 = std::make_unique(*server.globals.output_manager); output1->set_enabled(true); output1->done(); QVERIFY(outputAnnouncedSpy.wait()); @@ -1044,7 +1046,7 @@ void TestWaylandRegistry::testAnnounceMultiple() QCOMPARE(registry.interface(Registry::Interface::Output).version, outputAnnouncedSpy.first().last().value()); - auto output2 = std::make_unique(server.display.get()); + auto output2 = std::make_unique(*server.globals.output_manager); output2->set_enabled(true); output2->done(); QVERIFY(outputAnnouncedSpy.wait()); @@ -1111,7 +1113,7 @@ void TestWaylandRegistry::testAnnounceMultipleOutputDeviceV1s() QSignalSpy outputDeviceAnnouncedSpy(®istry, &Registry::outputDeviceV1Announced); QVERIFY(outputDeviceAnnouncedSpy.isValid()); - auto device1 = std::make_unique(server.display.get()); + auto device1 = std::make_unique(*server.globals.output_manager); QVERIFY(outputDeviceAnnouncedSpy.wait()); QCOMPARE(registry.interfaces(Registry::Interface::OutputDeviceV1).count(), 2); @@ -1124,7 +1126,7 @@ void TestWaylandRegistry::testAnnounceMultipleOutputDeviceV1s() QCOMPARE(registry.interface(Registry::Interface::OutputDeviceV1).version, outputDeviceAnnouncedSpy.first().last().value()); - auto device2 = std::make_unique(server.display.get()); + auto device2 = std::make_unique(*server.globals.output_manager); QVERIFY(outputDeviceAnnouncedSpy.wait()); QCOMPARE(registry.interfaces(Registry::Interface::OutputDeviceV1).count(), 3); QCOMPARE(registry.interfaces(Registry::Interface::OutputDeviceV1).last().name, diff --git a/autotests/client/surface.cpp b/autotests/client/surface.cpp index 38f62674..b70020c6 100644 --- a/autotests/client/surface.cpp +++ b/autotests/client/surface.cpp @@ -103,6 +103,8 @@ void TestSurface::init() server.display->start(); QVERIFY(server.display->running()); + server.globals.output_manager + = std::make_unique(*server.display); server.display->createShm(); server.globals.compositor = std::make_unique(server.display.get()); @@ -1125,7 +1127,7 @@ void TestSurface::testOutput() QSignalSpy outputAnnouncedSpy(®istry, &Wrapland::Client::Registry::outputAnnounced); QVERIFY(outputAnnouncedSpy.isValid()); - auto serverOutput = new Wrapland::Server::output(server.display.get()); + auto serverOutput = new Wrapland::Server::output(*server.globals.output_manager); serverOutput->set_enabled(true); serverOutput->done(); diff --git a/autotests/client/wlr_output_management.cpp b/autotests/client/wlr_output_management.cpp index 065ae59a..c1d2bde9 100644 --- a/autotests/client/wlr_output_management.cpp +++ b/autotests/client/wlr_output_management.cpp @@ -89,7 +89,9 @@ void TestWlrOutputManagement::init() server.display->start(); QVERIFY(server.display->running()); - server.output = std::make_unique(server.display.get()); + server.globals.output_manager + = std::make_unique(*server.display); + server.output = std::make_unique(*server.globals.output_manager); Srv::output_mode m0; m0.id = 0; @@ -119,8 +121,7 @@ void TestWlrOutputManagement::init() server.output->set_mode(1); server.output->set_geometry(QRectF(QPointF(0, 1920), QSizeF(1024, 768))); - server.globals.output_management_v1 - = std::make_unique(server.display.get()); + server.globals.output_manager->create_management_v1(); // setup connection m_connection = new Clt::ConnectionThread; diff --git a/autotests/client/xdg_output.cpp b/autotests/client/xdg_output.cpp index b0a7977a..adf05c0f 100644 --- a/autotests/client/xdg_output.cpp +++ b/autotests/client/xdg_output.cpp @@ -46,8 +46,8 @@ private Q_SLOTS: private: struct { std::unique_ptr display; - Wrapland::Server::globals globals; std::unique_ptr output; + Wrapland::Server::globals globals; } server; std::string m_name = "HDMI-A"; @@ -76,11 +76,13 @@ void TestXdgOutput::init() server.display->start(); QVERIFY(server.display->running()); - server.globals.xdg_output_manager - = std::make_unique(server.display.get()); + server.globals.output_manager + = std::make_unique(*server.display); + server.globals.output_manager->create_xdg_manager(); Wrapland::Server::output_metadata meta{.name = m_name, .make = m_make, .model = m_model}; - server.output = std::make_unique(meta, server.display.get()); + server.output + = std::make_unique(meta, *server.globals.output_manager); server.output->add_mode(Wrapland::Server::output_mode{QSize(1920, 1080), 60000, true, 1}); server.output->set_mode(1); server.output->set_enabled(true); diff --git a/autotests/client/xdg_shell.cpp b/autotests/client/xdg_shell.cpp index d337b292..ea3bb129 100644 --- a/autotests/client/xdg_shell.cpp +++ b/autotests/client/xdg_shell.cpp @@ -137,18 +137,20 @@ void XdgShellTest::init() QVERIFY(server.display->running()); server.display->createShm(); + server.globals.output_manager + = std::make_unique(*server.display); server.globals.compositor = std::make_unique(server.display.get()); server.globals.xdg_shell = std::make_unique(server.display.get()); server.globals.outputs.push_back( - std::make_unique(server.display.get())); + std::make_unique(*server.globals.output_manager)); server.globals.outputs.back()->add_mode(Server::output_mode{QSize(1024, 768)}); server.globals.outputs.back()->set_enabled(true); server.globals.outputs.back()->done(); server.globals.outputs.push_back( - std::make_unique(server.display.get())); + std::make_unique(*server.globals.output_manager)); server.globals.outputs.back()->add_mode(Server::output_mode{QSize(1024, 768)}); server.globals.outputs.back()->set_enabled(true); server.globals.outputs.back()->done(); diff --git a/autotests/server/display.cpp b/autotests/server/display.cpp index 97638bfc..fcd33115 100644 --- a/autotests/server/display.cpp +++ b/autotests/server/display.cpp @@ -23,6 +23,7 @@ License along with this library. If not, see . #include "../../server/display.h" #include "../../server/output.h" #include "../../server/output_management_v1.h" +#include "../../server/output_manager.h" #include "../../server/wl_output.h" #include @@ -89,30 +90,31 @@ void TestServerDisplay::testAddRemoveOutput() display.set_socket_name(std::string("kwin-wayland-server-display-test-output-0")); display.start(); - auto output1 = std::make_unique(&display); + auto output_manager = Wrapland::Server::output_manager(display); + auto output1 = std::make_unique(output_manager); output1->set_enabled(true); output1->done(); - QCOMPARE(display.globals.outputs.size(), 1); - QCOMPARE(display.globals.outputs[0]->wayland_output(), output1->wayland_output()); + QCOMPARE(output_manager.outputs.size(), 1); + QCOMPARE(output_manager.outputs[0]->wayland_output(), output1->wayland_output()); // create a second output - auto output2 = std::make_unique(&display); + auto output2 = std::make_unique(output_manager); output2->set_enabled(true); output2->done(); - QCOMPARE(display.globals.outputs.size(), 2); - QCOMPARE(display.globals.outputs[0]->wayland_output(), output1->wayland_output()); - QCOMPARE(display.globals.outputs[1]->wayland_output(), output2->wayland_output()); + QCOMPARE(output_manager.outputs.size(), 2); + QCOMPARE(output_manager.outputs[0]->wayland_output(), output1->wayland_output()); + QCOMPARE(output_manager.outputs[1]->wayland_output(), output2->wayland_output()); // remove the first output output1.reset(); - QCOMPARE(display.globals.outputs.size(), 1); - QCOMPARE(display.globals.outputs[0]->wayland_output(), output2->wayland_output()); + QCOMPARE(output_manager.outputs.size(), 1); + QCOMPARE(output_manager.outputs[0]->wayland_output(), output2->wayland_output()); // and delete the second output2.reset(); - QVERIFY(display.globals.outputs.empty()); + QVERIFY(output_manager.outputs.empty()); } void TestServerDisplay::testClientConnection() diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 2acf2c51..94d4e49a 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -31,6 +31,7 @@ set(SERVER_LIB_SRCS output_configuration_v1.cpp output_device_v1.cpp output_management_v1.cpp + output_manager.cpp plasma_activation_feedback.cpp plasma_shell.cpp plasma_virtual_desktop.cpp @@ -407,6 +408,7 @@ set(SERVER_LIB_HEADERS output_configuration_v1.h output_device_v1.h output_management_v1.h + output_manager.h plasma_activation_feedback.h plasma_shell.h plasma_virtual_desktop.h diff --git a/server/display.h b/server/display.h index 49ffcb32..a589ee01 100644 --- a/server/display.h +++ b/server/display.h @@ -137,8 +137,7 @@ class WRAPLANDSERVER_EXPORT Display : public QObject Server::SlideManager* slide_manager{nullptr}; Server::ContrastManager* contrast_manager{nullptr}; - /// Graphical outputs and their management - std::vector outputs; + /// Graphical output management Server::XdgOutputManager* xdg_output_manager{nullptr}; Server::DpmsManager* dpms_manager{nullptr}; Server::OutputManagementV1* output_management_v1{nullptr}; diff --git a/server/output.cpp b/server/output.cpp index e6708437..dcac83ff 100644 --- a/server/output.cpp +++ b/server/output.cpp @@ -21,6 +21,7 @@ License along with this library. If not, see . #include "display.h" #include "output_device_v1_p.h" +#include "output_manager.h" #include "utils.h" #include "wl_output_p.h" #include "xdg_output_p.h" @@ -35,9 +36,9 @@ License along with this library. If not, see . namespace Wrapland::Server { -output::Private::Private(output_metadata metadata, Display* display, output* q_ptr) - : display_handle(display) - , device{new OutputDeviceV1(q_ptr, display)} +output::Private::Private(output_metadata metadata, output_manager& manager, output* q_ptr) + : manager{manager} + , device{new OutputDeviceV1(q_ptr, &manager.display)} , q_ptr{q_ptr} { if (metadata.description.empty()) { @@ -46,29 +47,26 @@ output::Private::Private(output_metadata metadata, Display* display, output* q_p pending.meta = std::move(metadata); published.meta = pending.meta; - display->globals.outputs.push_back(q_ptr); - QObject::connect(display, &Display::destroyed, q_ptr, [this] { + manager.outputs.push_back(q_ptr); + QObject::connect(&manager.display, &Display::destroyed, q_ptr, [this] { device.reset(); xdg_output.reset(); wayland_output.reset(); - display_handle = nullptr; }); } output::Private::~Private() { - if (display_handle) { - remove_all(display_handle->globals.outputs, q_ptr); - } + remove_all(manager.outputs, q_ptr); } void output::Private::done() { if (published.enabled != pending.enabled) { if (pending.enabled) { - wayland_output.reset(new WlOutput(q_ptr, display_handle)); - if (display_handle->globals.xdg_output_manager) { - xdg_output.reset(new XdgOutput(q_ptr, display_handle)); + wayland_output.reset(new WlOutput(q_ptr, &manager.display)); + if (manager.xdg_manager) { + xdg_output.reset(new XdgOutput(q_ptr, &manager.display)); } } else { wayland_output.reset(); @@ -166,13 +164,13 @@ bool output_mode::operator!=(output_mode const& mode) const return !(*this == mode); } -output::output(Display* display) - : output(output_metadata(), display) +output::output(output_manager& manager) + : output(output_metadata(), manager) { } -output::output(output_metadata metadata, Display* display) - : d_ptr(new Private(std::move(metadata), display, this)) +output::output(output_metadata metadata, output_manager& manager) + : d_ptr(new Private(std::move(metadata), manager, this)) { } diff --git a/server/output.h b/server/output.h index 241cb948..78d37916 100644 --- a/server/output.h +++ b/server/output.h @@ -31,8 +31,8 @@ License along with this library. If not, see . namespace Wrapland::Server { -class Display; class OutputDeviceV1; +class output_manager; class WlOutput; class XdgOutput; @@ -110,8 +110,8 @@ class WRAPLANDSERVER_EXPORT output : public QObject { Q_OBJECT public: - explicit output(Display* display); - output(output_metadata metadata, Display* display); + explicit output(output_manager& manager); + output(output_metadata metadata, output_manager& manager); ~output() override; output_metadata const& get_metadata() const; diff --git a/server/output_manager.cpp b/server/output_manager.cpp new file mode 100644 index 00000000..3f1436fb --- /dev/null +++ b/server/output_manager.cpp @@ -0,0 +1,40 @@ +/* + SPDX-FileCopyrightText: 2023 Roman Glig + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only +*/ +#include "output_manager.h" + +#include "display.h" +#include "output.h" +#include "output_management_v1.h" +#include "xdg_output.h" + +namespace Wrapland::Server +{ + +output_manager::output_manager(Display& display) + : display{display} +{ +} + +output_manager::~output_manager() +{ + assert(outputs.empty()); +} + +XdgOutputManager& output_manager::create_xdg_manager() +{ + assert(!xdg_manager); + xdg_manager = std::make_unique(&display); + return *xdg_manager; +} + +OutputManagementV1& output_manager::create_management_v1() +{ + assert(!management_v1); + management_v1 = std::make_unique(&display); + return *management_v1; +} + +} diff --git a/server/output_manager.h b/server/output_manager.h new file mode 100644 index 00000000..fcff9a25 --- /dev/null +++ b/server/output_manager.h @@ -0,0 +1,37 @@ +/* + SPDX-FileCopyrightText: 2023 Roman Glig + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only +*/ +#pragma once + +#include + +#include +#include + +namespace Wrapland::Server +{ + +class output; +class Display; +class OutputManagementV1; +class XdgOutputManager; + +class WRAPLANDSERVER_EXPORT output_manager +{ +public: + explicit output_manager(Display& display); + virtual ~output_manager(); + + XdgOutputManager& create_xdg_manager(); + OutputManagementV1& create_management_v1(); + + Display& display; + std::vector outputs; + + std::unique_ptr xdg_manager; + std::unique_ptr management_v1; +}; + +} diff --git a/server/output_p.h b/server/output_p.h index edbc958a..71207451 100644 --- a/server/output_p.h +++ b/server/output_p.h @@ -35,7 +35,7 @@ class Display; class output::Private { public: - Private(output_metadata metadata, Display* display, output* q_ptr); + Private(output_metadata metadata, output_manager& manager, output* q_ptr); ~Private(); void update_client_scale(); @@ -49,7 +49,7 @@ class output::Private static int32_t get_mode_flags(output_mode const& mode, output_state const& state); static int32_t to_transform(output_transform transform); - Display* display_handle; + output_manager& manager; int connector_id{0}; std::vector modes; diff --git a/tests/globals.h b/tests/globals.h index 5af9d739..67f540bc 100644 --- a/tests/globals.h +++ b/tests/globals.h @@ -23,6 +23,7 @@ #include "../../server/layer_shell_v1.h" #include "../../server/linux_dmabuf_v1.h" #include "../../server/output_management_v1.h" +#include "../../server/output_manager.h" #include "../../server/plasma_activation_feedback.h" #include "../../server/plasma_shell.h" #include "../../server/plasma_virtual_desktop.h" @@ -76,9 +77,8 @@ struct globals { /// Graphical outputs and their management std::vector> outputs; - std::unique_ptr xdg_output_manager; + std::unique_ptr output_manager; std::unique_ptr dpms_manager; - std::unique_ptr output_management_v1; /// Basic input std::vector> seats; diff --git a/tests/renderingservertest.cpp b/tests/renderingservertest.cpp index 1503b199..02d5fa8f 100644 --- a/tests/renderingservertest.cpp +++ b/tests/renderingservertest.cpp @@ -22,6 +22,7 @@ License along with this library. If not, see . #include "../server/data_device_manager.h" #include "../server/display.h" #include "../server/keyboard_pool.h" +#include "../server/output_manager.h" #include "../server/pointer_pool.h" #include "../server/seat.h" #include "../server/surface.h" @@ -266,13 +267,14 @@ int main(int argc, char** argv) Display display; display.start(); + auto output_manager = Wrapland::Server::output_manager(display); auto data_device_manager = std::make_unique(&display); auto compositor = std::make_unique(&display); auto shell = std::make_unique(&display); display.createShm(); Wrapland::Server::output_metadata meta{.physical_size = {269, 202}}; - auto output = std::make_unique(meta, &display); + auto output = std::make_unique(meta, output_manager); const QSize windowSize(1024, 768); output->add_mode(output_mode{windowSize}); diff --git a/tests/waylandservertest.cpp b/tests/waylandservertest.cpp index f22a1e07..1edc2f30 100644 --- a/tests/waylandservertest.cpp +++ b/tests/waylandservertest.cpp @@ -20,6 +20,7 @@ License along with this library. If not, see . #include "../server/compositor.h" #include "../server/display.h" #include "../server/output.h" +#include "../server/output_manager.h" #include "../server/seat.h" #include "../server/xdg_shell.h" @@ -87,11 +88,12 @@ int main(int argc, char** argv) display.start(); display.createShm(); + auto output_manager = Wrapland::Server::output_manager(display); auto compositor = std::make_unique(&display); auto xdg_shell = std::make_unique(&display); Wrapland::Server::output_metadata meta{.physical_size = {10, 10}}; - auto output = std::make_unique(meta, &display); + auto output = std::make_unique(meta, output_manager); output->add_mode(Wrapland::Server::output_mode{QSize(1024, 768)}); // starts XWayland by forking and opening a pipe