diff --git a/autotests/client/test_xdg_foreign.cpp b/autotests/client/test_xdg_foreign.cpp index 4fdee0d..f4eb29b 100644 --- a/autotests/client/test_xdg_foreign.cpp +++ b/autotests/client/test_xdg_foreign.cpp @@ -1,401 +1,401 @@ /******************************************************************** Copyright 2014 Martin Gräßlin Copyright 2017 Marco Martin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ // Qt #include // KWin #include "../../src/client/compositor.h" #include "../../src/client/connection_thread.h" #include "../../src/client/event_queue.h" #include "../../src/client/region.h" #include "../../src/client/registry.h" #include "../../src/client/surface.h" -#include "../../src/client/xdgforeign_v1.h" +#include "../../src/client/xdgforeign.h" #include "../../src/server/display.h" #include "../../src/server/compositor_interface.h" #include "../../src/server/surface_interface.h" #include "../../src/server/xdgforeign_interface.h" using namespace KWayland::Client; class TestForeign : public QObject { Q_OBJECT public: explicit TestForeign(QObject *parent = nullptr); private Q_SLOTS: void init(); void cleanup(); void testExport(); void testDeleteImported(); void testDeleteChildSurface(); void testDeleteParentSurface(); void testDeleteExported(); void testExportTwoTimes(); void testImportTwoTimes(); private: void doExport(); KWayland::Server::Display *m_display; KWayland::Server::CompositorInterface *m_compositorInterface; KWayland::Server::XdgForeignUnstableInterface *m_foreignInterface; KWayland::Client::ConnectionThread *m_connection; KWayland::Client::Compositor *m_compositor; KWayland::Client::EventQueue *m_queue; - KWayland::Client::XdgExporterUnstableV1 *m_exporter; - KWayland::Client::XdgImporterUnstableV1 *m_importer; + KWayland::Client::XdgExporterUnstable *m_exporter; + KWayland::Client::XdgImporterUnstable *m_importer; QPointer m_exportedSurface; QPointer m_exportedSurfaceInterface; - QPointer m_exported; - QPointer m_imported; + QPointer m_exported; + QPointer m_imported; QPointer m_childSurface; QPointer m_childSurfaceInterface; QThread *m_thread; }; static const QString s_socketName = QStringLiteral("kwayland-test-xdg-foreign-0"); TestForeign::TestForeign(QObject *parent) : QObject(parent) , m_display(nullptr) , m_compositorInterface(nullptr) , m_connection(nullptr) , m_compositor(nullptr) , m_queue(nullptr) , m_exporter(nullptr) , m_importer(nullptr) , m_thread(nullptr) { } void TestForeign::init() { using namespace KWayland::Server; delete m_display; m_display = new Display(this); m_display->setSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); qRegisterMetaType("KWayland::Server::SurfaceInterface"); // setup connection m_connection = new KWayland::Client::ConnectionThread; QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); QVERIFY(connectedSpy.isValid()); m_connection->setSocketName(s_socketName); m_thread = new QThread(this); m_connection->moveToThread(m_thread); m_thread->start(); m_connection->initConnection(); QVERIFY(connectedSpy.wait()); m_queue = new KWayland::Client::EventQueue(this); QVERIFY(!m_queue->isValid()); m_queue->setup(m_connection); QVERIFY(m_queue->isValid()); Registry registry; QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); QVERIFY(compositorSpy.isValid()); QSignalSpy exporterSpy(®istry, &Registry::exporterUnstableV1Announced); QVERIFY(exporterSpy.isValid()); QSignalSpy importerSpy(®istry, &Registry::importerUnstableV1Announced); QVERIFY(importerSpy.isValid()); QVERIFY(!registry.eventQueue()); registry.setEventQueue(m_queue); QCOMPARE(registry.eventQueue(), m_queue); registry.create(m_connection->display()); QVERIFY(registry.isValid()); registry.setup(); m_compositorInterface = m_display->createCompositor(m_display); m_compositorInterface->create(); QVERIFY(m_compositorInterface->isValid()); QVERIFY(compositorSpy.wait()); m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); m_foreignInterface = m_display->createXdgForeignUnstableInterface(m_display); m_foreignInterface->create(); QVERIFY(m_foreignInterface->isValid()); QVERIFY(exporterSpy.wait()); //Both importer and exporter should have been triggered by now QCOMPARE(exporterSpy.count(), 1); QCOMPARE(importerSpy.count(), 1); - m_exporter = registry.createXdgExporterUnstableV1(exporterSpy.first().first().value(), exporterSpy.first().last().value(), this); - m_importer = registry.createXdgImporterUnstableV1(importerSpy.first().first().value(), importerSpy.first().last().value(), this); + m_exporter = registry.createXdgExporterUnstable(exporterSpy.first().first().value(), exporterSpy.first().last().value(), this); + m_importer = registry.createXdgImporterUnstable(importerSpy.first().first().value(), importerSpy.first().last().value(), this); } void TestForeign::cleanup() { #define CLEANUP(variable) \ if (variable) { \ delete variable; \ variable = nullptr; \ } //some tests delete it beforehand if (m_exportedSurfaceInterface) { QSignalSpy exportedSurfaceDestroyedSpy(m_exportedSurfaceInterface.data(), &QObject::destroyed); QVERIFY(exportedSurfaceDestroyedSpy.isValid()); CLEANUP(m_exportedSurface) exportedSurfaceDestroyedSpy.wait(); } if (m_childSurfaceInterface) { QSignalSpy childSurfaceDestroyedSpy(m_childSurfaceInterface.data(), &QObject::destroyed); QVERIFY(childSurfaceDestroyedSpy.isValid()); CLEANUP(m_childSurface) childSurfaceDestroyedSpy.wait(); } CLEANUP(m_compositor) CLEANUP(m_exporter) CLEANUP(m_importer) CLEANUP(m_queue) if (m_connection) { m_connection->deleteLater(); m_connection = nullptr; } if (m_thread) { m_thread->quit(); m_thread->wait(); delete m_thread; m_thread = nullptr; } CLEANUP(m_compositorInterface) CLEANUP(m_foreignInterface) CLEANUP(m_display) #undef CLEANUP } void TestForeign::doExport() { QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); m_exportedSurface = m_compositor->createSurface(); QVERIFY(serverSurfaceCreated.wait()); m_exportedSurfaceInterface = serverSurfaceCreated.first().first().value(); //Export a window m_exported = m_exporter->exportSurface(m_exportedSurface, this); QVERIFY(m_exported->handle().isEmpty()); - QSignalSpy doneSpy(m_exported.data(), &XdgExportedUnstableV1::done); + QSignalSpy doneSpy(m_exported.data(), &XdgExportedUnstable::done); QVERIFY(doneSpy.wait()); QVERIFY(!m_exported->handle().isEmpty()); QSignalSpy transientSpy(m_foreignInterface, &KWayland::Server::XdgForeignUnstableInterface::transientChanged); QVERIFY(transientSpy.isValid()); //Import the just exported window m_imported = m_importer->import(m_exported->handle(), this); QVERIFY(m_imported->isValid()); QSignalSpy childSurfaceInterfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); m_childSurface = m_compositor->createSurface(); QVERIFY(childSurfaceInterfaceCreated.wait()); m_childSurfaceInterface = childSurfaceInterfaceCreated.first().first().value(); m_childSurface->commit(Surface::CommitFlag::None); m_imported->setParentOf(m_childSurface); QVERIFY(transientSpy.wait()); QCOMPARE(transientSpy.first().first().value(), m_childSurfaceInterface.data()); QCOMPARE(transientSpy.first().at(1).value(), m_exportedSurfaceInterface.data()); //transientFor api QCOMPARE(m_foreignInterface->transientFor(m_childSurfaceInterface), m_exportedSurfaceInterface.data()); } void TestForeign::testExport() { doExport(); } void TestForeign::testDeleteImported() { doExport(); QSignalSpy transientSpy(m_foreignInterface, &KWayland::Server::XdgForeignUnstableInterface::transientChanged); QVERIFY(transientSpy.isValid()); m_imported->deleteLater(); m_imported = nullptr; QVERIFY(transientSpy.wait()); QCOMPARE(transientSpy.first().first().value(), m_childSurfaceInterface.data()); QCOMPARE(transientSpy.first().at(1).value(), nullptr); QCOMPARE(m_foreignInterface->transientFor(m_childSurfaceInterface), nullptr); } void TestForeign::testDeleteChildSurface() { doExport(); QSignalSpy transientSpy(m_foreignInterface, &KWayland::Server::XdgForeignUnstableInterface::transientChanged); QVERIFY(transientSpy.isValid()); m_childSurface->deleteLater(); QVERIFY(transientSpy.wait()); //when the client surface dies, the server one will eventually die too QSignalSpy surfaceDestroyedSpy(m_childSurfaceInterface, SIGNAL(destroyed())); QVERIFY(surfaceDestroyedSpy.wait()); QCOMPARE(transientSpy.first().at(0).value(), nullptr); QCOMPARE(transientSpy.first().at(1).value(), m_exportedSurfaceInterface.data()); } void TestForeign::testDeleteParentSurface() { doExport(); QSignalSpy transientSpy(m_foreignInterface, &KWayland::Server::XdgForeignUnstableInterface::transientChanged); QVERIFY(transientSpy.isValid()); m_exportedSurface->deleteLater(); QSignalSpy exportedSurfaceDestroyedSpy(m_exportedSurfaceInterface.data(), &QObject::destroyed); QVERIFY(exportedSurfaceDestroyedSpy.isValid()); exportedSurfaceDestroyedSpy.wait(); QVERIFY(transientSpy.wait()); QCOMPARE(transientSpy.first().first().value(), m_childSurfaceInterface.data()); QCOMPARE(transientSpy.first().at(1).value(), nullptr); QCOMPARE(m_foreignInterface->transientFor(m_childSurfaceInterface), nullptr); } void TestForeign::testDeleteExported() { doExport(); QSignalSpy transientSpy(m_foreignInterface, &KWayland::Server::XdgForeignUnstableInterface::transientChanged); - QSignalSpy destroyedSpy(m_imported.data(), &KWayland::Client::XdgImportedUnstableV1::importedDestroyed); + QSignalSpy destroyedSpy(m_imported.data(), &KWayland::Client::XdgImportedUnstable::importedDestroyed); QVERIFY(transientSpy.isValid()); m_exported->deleteLater(); m_exported = nullptr; QVERIFY(transientSpy.wait()); QVERIFY(destroyedSpy.wait()); QCOMPARE(transientSpy.first().first().value(), m_childSurfaceInterface.data()); QCOMPARE(transientSpy.first().at(1).value(), nullptr); QCOMPARE(m_foreignInterface->transientFor(m_childSurfaceInterface), nullptr); QVERIFY(!m_imported->isValid()); } void TestForeign::testExportTwoTimes() { doExport(); //Export second window - KWayland::Client::XdgExportedUnstableV1 *exported2 = m_exporter->exportSurface(m_exportedSurface, this); + KWayland::Client::XdgExportedUnstable *exported2 = m_exporter->exportSurface(m_exportedSurface, this); QVERIFY(exported2->handle().isEmpty()); - QSignalSpy doneSpy(exported2, &XdgExportedUnstableV1::done); + QSignalSpy doneSpy(exported2, &XdgExportedUnstable::done); QVERIFY(doneSpy.wait()); QVERIFY(!exported2->handle().isEmpty()); QSignalSpy transientSpy(m_foreignInterface, &KWayland::Server::XdgForeignUnstableInterface::transientChanged); QVERIFY(transientSpy.isValid()); //Import the just exported window - KWayland::Client::XdgImportedUnstableV1 *imported2 = m_importer->import(exported2->handle(), this); + KWayland::Client::XdgImportedUnstable *imported2 = m_importer->import(exported2->handle(), this); QVERIFY(imported2->isValid()); //create a second child surface QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); KWayland::Client::Surface *childSurface2 = m_compositor->createSurface(); QVERIFY(serverSurfaceCreated.wait()); KWayland::Server::SurfaceInterface *childSurface2Interface = serverSurfaceCreated.first().first().value(); imported2->setParentOf(childSurface2); QVERIFY(transientSpy.wait()); QCOMPARE(transientSpy.first().first().value(), childSurface2Interface); QCOMPARE(transientSpy.first().at(1).value(), m_exportedSurfaceInterface.data()); //transientFor api //check the old relationship is still here QCOMPARE(m_foreignInterface->transientFor(m_childSurfaceInterface), m_exportedSurfaceInterface.data()); //check the new relationship QCOMPARE(m_foreignInterface->transientFor(childSurface2Interface), m_exportedSurfaceInterface.data()); } void TestForeign::testImportTwoTimes() { doExport(); QSignalSpy transientSpy(m_foreignInterface, &KWayland::Server::XdgForeignUnstableInterface::transientChanged); QVERIFY(transientSpy.isValid()); //Import another time the exported window - KWayland::Client::XdgImportedUnstableV1 *imported2 = m_importer->import(m_exported->handle(), this); + KWayland::Client::XdgImportedUnstable *imported2 = m_importer->import(m_exported->handle(), this); QVERIFY(imported2->isValid()); //create a second child surface QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); QVERIFY(serverSurfaceCreated.isValid()); KWayland::Client::Surface *childSurface2 = m_compositor->createSurface(); QVERIFY(serverSurfaceCreated.wait()); KWayland::Server::SurfaceInterface *childSurface2Interface = serverSurfaceCreated.first().first().value(); imported2->setParentOf(childSurface2); QVERIFY(transientSpy.wait()); QCOMPARE(transientSpy.first().first().value(), childSurface2Interface); QCOMPARE(transientSpy.first().at(1).value(), m_exportedSurfaceInterface.data()); //transientFor api //check the old relationship is still here QCOMPARE(m_foreignInterface->transientFor(m_childSurfaceInterface), m_exportedSurfaceInterface.data()); //check the new relationship QCOMPARE(m_foreignInterface->transientFor(childSurface2Interface), m_exportedSurfaceInterface.data()); } QTEST_GUILESS_MAIN(TestForeign) #include "test_xdg_foreign.moc" diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index b715d0f..6614cf8 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -1,227 +1,228 @@ remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) remove_definitions(-DQT_NO_CAST_FROM_ASCII) remove_definitions(-DQT_NO_CAST_TO_ASCII) # needed to access QPA include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) set(CLIENT_LIB_SRCS buffer.cpp blur.cpp compositor.cpp connection_thread.cpp contrast.cpp slide.cpp event_queue.cpp datadevice.cpp datadevicemanager.cpp dataoffer.cpp datasource.cpp dpms.cpp fakeinput.cpp fullscreen_shell.cpp idle.cpp keyboard.cpp outputconfiguration.cpp outputmanagement.cpp outputdevice.cpp logging.cpp output.cpp pointer.cpp pointerconstraints.cpp pointergestures.cpp plasmashell.cpp plasmawindowmanagement.cpp plasmawindowmodel.cpp region.cpp registry.cpp relativepointer.cpp seat.cpp server_decoration.cpp shadow.cpp shell.cpp shm_pool.cpp subcompositor.cpp subsurface.cpp surface.cpp touch.cpp textinput.cpp textinput_v0.cpp textinput_v2.cpp xdgshell.cpp xdgshell_v5.cpp xdgforeign_v1.cpp + xdgforeign.cpp ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/fullscreen-shell.xml BASENAME fullscreen-shell ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/output-management.xml BASENAME output-management ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/outputdevice.xml BASENAME org_kde_kwin_outputdevice ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/plasma-shell.xml BASENAME plasma-shell ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/plasma-window-management.xml BASENAME plasma-window-management ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/idle.xml BASENAME idle ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/fake-input.xml BASENAME fake-input ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/shadow.xml BASENAME shadow ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/blur.xml BASENAME blur ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/contrast.xml BASENAME contrast ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/slide.xml BASENAME slide ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/dpms.xml BASENAME dpms ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/server-decoration.xml BASENAME server-decoration ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/text-input.xml BASENAME text-input-v0 ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/text-input-unstable-v2.xml BASENAME text-input-v2 ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/xdg-shell-unstable-v5.xml BASENAME xdg-shell-v5 ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/relative-pointer-unstable-v1.xml BASENAME relativepointer-unstable-v1 ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/pointer-gestures-unstable-v1.xml BASENAME pointer-gestures-unstable-v1 ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/pointer-constraints-unstable-v1.xml BASENAME pointer-constraints-unstable-v1 ) ecm_add_wayland_client_protocol(CLIENT_LIB_SRCS PROTOCOL ${KWayland_SOURCE_DIR}/src/client/protocols/xdg-foreign-unstable-v1.xml BASENAME xdg-foreign-unstable-v1 ) add_library(KF5WaylandClient ${CLIENT_LIB_SRCS}) generate_export_header(KF5WaylandClient BASE_NAME KWaylandClient EXPORT_FILE_NAME KWayland/Client/kwaylandclient_export.h ) add_library(KF5::WaylandClient ALIAS KF5WaylandClient) target_include_directories(KF5WaylandClient INTERFACE "$") target_link_libraries(KF5WaylandClient PUBLIC Qt5::Gui PRIVATE Wayland::Client Qt5::Concurrent ) set_target_properties(KF5WaylandClient PROPERTIES VERSION ${KWAYLAND_VERSION_STRING} SOVERSION ${KWAYLAND_SOVERSION} EXPORT_NAME WaylandClient ) install(TARGETS KF5WaylandClient EXPORT KF5WaylandTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) set(CLIENT_LIB_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/KWayland/Client/kwaylandclient_export.h blur.h buffer.h compositor.h connection_thread.h contrast.h event_queue.h datadevice.h datadevicemanager.h dataoffer.h datasource.h dpms.h fakeinput.h fullscreen_shell.h idle.h keyboard.h outputconfiguration.h outputmanagement.h outputdevice.h output.h pointer.h pointerconstraints.h plasmashell.h plasmawindowmanagement.h plasmawindowmodel.h pointergestures.h region.h registry.h relativepointer.h seat.h server_decoration.h shadow.h shell.h shm_pool.h slide.h subcompositor.h subsurface.h surface.h touch.h textinput.h xdgshell.h xdgforeign_v1.h ) install(FILES ${CLIENT_LIB_HEADERS} DESTINATION ${KF5_INCLUDE_INSTALL_DIR}/KWayland/Client COMPONENT Devel ) # make available to ecm_add_qch in parent folder set(KWaylandClient_APIDOX_SRCS ${CLIENT_LIB_HEADERS} PARENT_SCOPE) include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME KWaylandClient LIB_NAME KF5WaylandClient DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/client/registry.cpp b/src/client/registry.cpp index 2767f78..f02c163 100644 --- a/src/client/registry.cpp +++ b/src/client/registry.cpp @@ -1,763 +1,773 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #include "registry.h" #include "compositor.h" #include "connection_thread.h" #include "datadevicemanager.h" #include "dpms.h" #include "event_queue.h" #include "fakeinput.h" #include "fullscreen_shell.h" #include "idle.h" #include "logging_p.h" #include "outputconfiguration.h" #include "outputmanagement.h" #include "outputdevice.h" #include "output.h" #include "plasmashell.h" #include "plasmawindowmanagement.h" #include "pointerconstraints.h" #include "pointergestures.h" #include "seat.h" #include "shadow.h" #include "blur.h" #include "contrast.h" #include "relativepointer.h" #include "server_decoration.h" #include "slide.h" #include "shell.h" #include "shm_pool.h" #include "subcompositor.h" #include "textinput_p.h" #include "xdgshell.h" #include "xdgshell_p.h" #include "wayland_pointer_p.h" #include "xdgforeign_v1.h" // Qt #include // wayland #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /***** * How to add another interface: * * define a new enum value in Registry::Interface * * define the bind method * * define the create method * * define the Announced signal * * define the Removed signal * * add a block to s_interfaces * * add the BIND macro for the new bind * * add the CREATE macro for the new create * * extend registry unit test to verify that it works ****/ namespace KWayland { namespace Client { namespace { struct SuppertedInterfaceData { quint32 maxVersion; QByteArray name; const wl_interface *interface; void (Registry::*announcedSignal)(quint32, quint32); void (Registry::*removedSignal)(quint32); }; static const QMap s_interfaces = { {Registry::Interface::Compositor, { 3, QByteArrayLiteral("wl_compositor"), &wl_compositor_interface, &Registry::compositorAnnounced, &Registry::compositorRemoved }}, {Registry::Interface::DataDeviceManager, { 2, QByteArrayLiteral("wl_data_device_manager"), &wl_data_device_manager_interface, &Registry::dataDeviceManagerAnnounced, &Registry::dataDeviceManagerRemoved }}, {Registry::Interface::Output, { 2, QByteArrayLiteral("wl_output"), &wl_output_interface, &Registry::outputAnnounced, &Registry::outputRemoved }}, {Registry::Interface::Shm, { 1, QByteArrayLiteral("wl_shm"), &wl_shm_interface, &Registry::shmAnnounced, &Registry::shmRemoved }}, {Registry::Interface::Seat, { 4, QByteArrayLiteral("wl_seat"), &wl_seat_interface, &Registry::seatAnnounced, &Registry::seatRemoved }}, {Registry::Interface::Shell, { 1, QByteArrayLiteral("wl_shell"), &wl_shell_interface, &Registry::shellAnnounced, &Registry::shellRemoved }}, {Registry::Interface::SubCompositor, { 1, QByteArrayLiteral("wl_subcompositor"), &wl_subcompositor_interface, &Registry::subCompositorAnnounced, &Registry::subCompositorRemoved }}, {Registry::Interface::PlasmaShell, { 4, QByteArrayLiteral("org_kde_plasma_shell"), &org_kde_plasma_shell_interface, &Registry::plasmaShellAnnounced, &Registry::plasmaShellRemoved }}, {Registry::Interface::PlasmaWindowManagement, { 7, QByteArrayLiteral("org_kde_plasma_window_management"), &org_kde_plasma_window_management_interface, &Registry::plasmaWindowManagementAnnounced, &Registry::plasmaWindowManagementRemoved }}, {Registry::Interface::Idle, { 1, QByteArrayLiteral("org_kde_kwin_idle"), &org_kde_kwin_idle_interface, &Registry::idleAnnounced, &Registry::idleRemoved }}, {Registry::Interface::FakeInput, { 2, QByteArrayLiteral("org_kde_kwin_fake_input"), &org_kde_kwin_fake_input_interface, &Registry::fakeInputAnnounced, &Registry::fakeInputRemoved }}, {Registry::Interface::OutputManagement, { 1, QByteArrayLiteral("org_kde_kwin_outputmanagement"), &org_kde_kwin_outputmanagement_interface, &Registry::outputManagementAnnounced, &Registry::outputManagementRemoved }}, {Registry::Interface::OutputDevice, { 1, QByteArrayLiteral("org_kde_kwin_outputdevice"), &org_kde_kwin_outputdevice_interface, &Registry::outputDeviceAnnounced, &Registry::outputDeviceRemoved }}, {Registry::Interface::Shadow, { 2, QByteArrayLiteral("org_kde_kwin_shadow_manager"), &org_kde_kwin_shadow_manager_interface, &Registry::shadowAnnounced, &Registry::shadowRemoved }}, {Registry::Interface::Blur, { 1, QByteArrayLiteral("org_kde_kwin_blur_manager"), &org_kde_kwin_blur_manager_interface, &Registry::blurAnnounced, &Registry::blurRemoved }}, {Registry::Interface::Contrast, { 1, QByteArrayLiteral("org_kde_kwin_contrast_manager"), &org_kde_kwin_contrast_manager_interface, &Registry::contrastAnnounced, &Registry::contrastRemoved }}, {Registry::Interface::Slide, { 1, QByteArrayLiteral("org_kde_kwin_slide_manager"), &org_kde_kwin_slide_manager_interface, &Registry::slideAnnounced, &Registry::slideRemoved }}, {Registry::Interface::FullscreenShell, { 1, QByteArrayLiteral("_wl_fullscreen_shell"), &_wl_fullscreen_shell_interface, &Registry::fullscreenShellAnnounced, &Registry::fullscreenShellRemoved }}, {Registry::Interface::Dpms, { 1, QByteArrayLiteral("org_kde_kwin_dpms_manager"), &org_kde_kwin_dpms_manager_interface, &Registry::dpmsAnnounced, &Registry::dpmsRemoved }}, {Registry::Interface::ServerSideDecorationManager, { 1, QByteArrayLiteral("org_kde_kwin_server_decoration_manager"), &org_kde_kwin_server_decoration_manager_interface, &Registry::serverSideDecorationManagerAnnounced, &Registry::serverSideDecorationManagerRemoved }}, {Registry::Interface::TextInputManagerUnstableV0, { 1, QByteArrayLiteral("wl_text_input_manager"), &wl_text_input_manager_interface, &Registry::textInputManagerUnstableV0Announced, &Registry::textInputManagerUnstableV0Removed }}, {Registry::Interface::TextInputManagerUnstableV2, { 1, QByteArrayLiteral("zwp_text_input_manager_v2"), &zwp_text_input_manager_v2_interface, &Registry::textInputManagerUnstableV2Announced, &Registry::textInputManagerUnstableV2Removed }}, {Registry::Interface::XdgShellUnstableV5, { 1, QByteArrayLiteral("xdg_shell"), &xdg_shell_interface, &Registry::xdgShellUnstableV5Announced, &Registry::xdgShellUnstableV5Removed }}, {Registry::Interface::RelativePointerManagerUnstableV1, { 1, QByteArrayLiteral("zwp_relative_pointer_manager_v1"), &zwp_relative_pointer_manager_v1_interface, &Registry::relativePointerManagerUnstableV1Announced, &Registry::relativePointerManagerUnstableV1Removed }}, {Registry::Interface::PointerGesturesUnstableV1, { 1, QByteArrayLiteral("zwp_pointer_gestures_v1"), &zwp_pointer_gestures_v1_interface, &Registry::pointerGesturesUnstableV1Announced, &Registry::pointerGesturesUnstableV1Removed }}, {Registry::Interface::PointerConstraintsUnstableV1, { 1, QByteArrayLiteral("zwp_pointer_constraints_v1"), &zwp_pointer_constraints_v1_interface, &Registry::pointerConstraintsUnstableV1Announced, &Registry::pointerConstraintsUnstableV1Removed }}, {Registry::Interface::XdgExporterUnstableV1, { 1, QByteArrayLiteral("zxdg_exporter_v1"), &zxdg_exporter_v1_interface, &Registry::exporterUnstableV1Announced, &Registry::exporterUnstableV1Removed }}, {Registry::Interface::XdgImporterUnstableV1, { 1, QByteArrayLiteral("zxdg_importer_v1"), &zxdg_importer_v1_interface, &Registry::importerUnstableV1Announced, &Registry::importerUnstableV1Removed }} }; static quint32 maxVersion(const Registry::Interface &interface) { auto it = s_interfaces.find(interface); if (it != s_interfaces.end()) { return it.value().maxVersion; } return 0; } } class Registry::Private { public: Private(Registry *q); void setup(); bool hasInterface(Interface interface) const; AnnouncedInterface interface(Interface interface) const; QVector interfaces(Interface interface) const; Interface interfaceForName(quint32 name) const; template T *bind(Interface interface, uint32_t name, uint32_t version) const; template T *create(quint32 name, quint32 version, QObject *parent, WL *(Registry::*bindMethod)(uint32_t, uint32_t) const); WaylandPointer registry; static const struct wl_callback_listener s_callbackListener; WaylandPointer callback; EventQueue *queue = nullptr; private: void handleAnnounce(uint32_t name, const char *interface, uint32_t version); void handleRemove(uint32_t name); void handleGlobalSync(); static void globalAnnounce(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version); static void globalRemove(void *data, struct wl_registry *registry, uint32_t name); static void globalSync(void *data, struct wl_callback *callback, uint32_t serial); Registry *q; struct InterfaceData { Interface interface; uint32_t name; uint32_t version; }; QList m_interfaces; static const struct wl_registry_listener s_registryListener; }; Registry::Private::Private(Registry *q) : q(q) { } void Registry::Private::setup() { wl_registry_add_listener(registry, &s_registryListener, this); wl_callback_add_listener(callback, &s_callbackListener, this); } Registry::Registry(QObject *parent) : QObject(parent) , d(new Private(this)) { } Registry::~Registry() { release(); } void Registry::release() { d->registry.release(); d->callback.release(); } void Registry::destroy() { emit registryDestroyed(); d->registry.destroy(); d->callback.destroy(); } void Registry::create(wl_display *display) { Q_ASSERT(display); Q_ASSERT(!isValid()); d->registry.setup(wl_display_get_registry(display)); d->callback.setup(wl_display_sync(display)); if (d->queue) { d->queue->addProxy(d->registry); d->queue->addProxy(d->callback); } } void Registry::create(ConnectionThread *connection) { create(connection->display()); connect(connection, &ConnectionThread::connectionDied, this, &Registry::destroy); } void Registry::setup() { Q_ASSERT(isValid()); d->setup(); } void Registry::setEventQueue(EventQueue *queue) { d->queue = queue; if (!queue) { return; } if (d->registry) { d->queue->addProxy(d->registry); } if (d->callback) { d->queue->addProxy(d->callback); } } EventQueue *Registry::eventQueue() { return d->queue; } #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct wl_registry_listener Registry::Private::s_registryListener = { globalAnnounce, globalRemove }; const struct wl_callback_listener Registry::Private::s_callbackListener = { globalSync }; #endif void Registry::Private::globalAnnounce(void *data, wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { auto r = reinterpret_cast(data); Q_ASSERT(registry == r->registry); r->handleAnnounce(name, interface, version); } void Registry::Private::globalRemove(void *data, wl_registry *registry, uint32_t name) { auto r = reinterpret_cast(data); Q_ASSERT(registry == r->registry); r->handleRemove(name); } void Registry::Private::globalSync(void* data, wl_callback* callback, uint32_t serial) { Q_UNUSED(serial) auto r = reinterpret_cast(data); Q_ASSERT(r->callback == callback); r->handleGlobalSync(); r->callback.destroy(); } void Registry::Private::handleGlobalSync() { emit q->interfacesAnnounced(); } namespace { static Registry::Interface nameToInterface(const char *interface) { for (auto it = s_interfaces.begin(); it != s_interfaces.end(); ++it) { if (qstrcmp(interface, it.value().name) == 0) { return it.key(); } } return Registry::Interface::Unknown; } } void Registry::Private::handleAnnounce(uint32_t name, const char *interface, uint32_t version) { Interface i = nameToInterface(interface); emit q->interfaceAnnounced(QByteArray(interface), name, version); if (i == Interface::Unknown) { qCDebug(KWAYLAND_CLIENT) << "Unknown interface announced: " << interface << "/" << name << "/" << version; return; } qCDebug(KWAYLAND_CLIENT) << "Wayland Interface: " << interface << "/" << name << "/" << version; m_interfaces.append({i, name, version}); auto it = s_interfaces.constFind(i); if (it != s_interfaces.end()) { emit (q->*it.value().announcedSignal)(name, version); } } void Registry::Private::handleRemove(uint32_t name) { auto it = std::find_if(m_interfaces.begin(), m_interfaces.end(), [name](const InterfaceData &data) { return data.name == name; } ); if (it != m_interfaces.end()) { InterfaceData data = *(it); m_interfaces.erase(it); auto sit = s_interfaces.find(data.interface); if (sit != s_interfaces.end()) { emit (q->*sit.value().removedSignal)(data.name); } } emit q->interfaceRemoved(name); } bool Registry::Private::hasInterface(Registry::Interface interface) const { auto it = std::find_if(m_interfaces.begin(), m_interfaces.end(), [interface](const InterfaceData &data) { return data.interface == interface; } ); return it != m_interfaces.end(); } QVector Registry::Private::interfaces(Interface interface) const { QVector retVal; for (auto it = m_interfaces.constBegin(); it != m_interfaces.constEnd(); ++it) { const auto &data = *it; if (data.interface == interface) { retVal << AnnouncedInterface{data.name, data.version}; } } return retVal; } Registry::AnnouncedInterface Registry::Private::interface(Interface interface) const { const auto all = interfaces(interface); if (!all.isEmpty()) { return all.last(); } return AnnouncedInterface{0, 0}; } Registry::Interface Registry::Private::interfaceForName(quint32 name) const { auto it = std::find_if(m_interfaces.constBegin(), m_interfaces.constEnd(), [name] (const InterfaceData &data) { return data.name == name; }); if (it == m_interfaces.constEnd()) { return Interface::Unknown; } return (*it).interface; } bool Registry::hasInterface(Registry::Interface interface) const { return d->hasInterface(interface); } QVector Registry::interfaces(Interface interface) const { return d->interfaces(interface); } Registry::AnnouncedInterface Registry::interface(Interface interface) const { return d->interface(interface); } #define BIND2(__NAME__, __INAME__, __WL__) \ __WL__ *Registry::bind##__NAME__(uint32_t name, uint32_t version) const \ { \ return d->bind<__WL__>(Interface::__INAME__, name, qMin(maxVersion(Interface::__INAME__), version)); \ } #define BIND(__NAME__, __WL__) BIND2(__NAME__, __NAME__, __WL__) BIND(Compositor, wl_compositor) BIND(Output, wl_output) BIND(Seat, wl_seat) BIND(Shell, wl_shell) BIND(Shm, wl_shm) BIND(SubCompositor, wl_subcompositor) BIND(FullscreenShell, _wl_fullscreen_shell) BIND(DataDeviceManager, wl_data_device_manager) BIND(PlasmaShell, org_kde_plasma_shell) BIND(PlasmaWindowManagement, org_kde_plasma_window_management) BIND(Idle, org_kde_kwin_idle) BIND(FakeInput, org_kde_kwin_fake_input) BIND(OutputManagement, org_kde_kwin_outputmanagement) BIND(OutputDevice, org_kde_kwin_outputdevice) BIND(ServerSideDecorationManager, org_kde_kwin_server_decoration_manager) BIND(TextInputManagerUnstableV0, wl_text_input_manager) BIND(TextInputManagerUnstableV2, zwp_text_input_manager_v2) BIND(XdgShellUnstableV5, xdg_shell) BIND(RelativePointerManagerUnstableV1, zwp_relative_pointer_manager_v1) BIND(PointerGesturesUnstableV1, zwp_pointer_gestures_v1) BIND(PointerConstraintsUnstableV1, zwp_pointer_constraints_v1) BIND(XdgExporterUnstableV1, zxdg_exporter_v1) BIND(XdgImporterUnstableV1, zxdg_importer_v1) BIND2(ShadowManager, Shadow, org_kde_kwin_shadow_manager) BIND2(BlurManager, Blur, org_kde_kwin_blur_manager) BIND2(ContrastManager, Contrast, org_kde_kwin_contrast_manager) BIND2(SlideManager, Slide, org_kde_kwin_slide_manager) BIND2(DpmsManager, Dpms, org_kde_kwin_dpms_manager) #undef BIND #undef BIND2 template T *Registry::Private::create(quint32 name, quint32 version, QObject *parent, WL *(Registry::*bindMethod)(uint32_t, uint32_t) const) { T *t = new T(parent); t->setEventQueue(queue); t->setup((q->*bindMethod)(name, version)); QObject::connect(q, &Registry::interfaceRemoved, t, [t, name] (quint32 removed) { if (name == removed) { emit t->removed(); } } ); QObject::connect(q, &Registry::registryDestroyed, t, &T::destroy); return t; } #define CREATE2(__NAME__, __BINDNAME__) \ __NAME__ *Registry::create##__NAME__(quint32 name, quint32 version, QObject *parent) \ { \ return d->create<__NAME__>(name, version, parent, &Registry::bind##__BINDNAME__); \ } #define CREATE(__NAME__) CREATE2(__NAME__, __NAME__) CREATE(Compositor) CREATE(Seat) CREATE(Shell) CREATE(SubCompositor) CREATE(FullscreenShell) CREATE(Output) CREATE(DataDeviceManager) CREATE(PlasmaShell) CREATE(PlasmaWindowManagement) CREATE(Idle) CREATE(FakeInput) CREATE(OutputManagement) CREATE(OutputDevice) CREATE(ShadowManager) CREATE(BlurManager) CREATE(ContrastManager) CREATE(SlideManager) CREATE(DpmsManager) CREATE(ServerSideDecorationManager) -CREATE(XdgExporterUnstableV1) -CREATE(XdgImporterUnstableV1) CREATE2(ShmPool, Shm) #undef CREATE #undef CREATE2 +XdgExporterUnstable *Registry::createXdgExporterUnstable(quint32 name, quint32 version, QObject *parent) +{ + //only V1 supported for now + return d->create(name, version, parent, &Registry::bindXdgExporterUnstableV1); +} + +XdgImporterUnstable *Registry::createXdgImporterUnstable(quint32 name, quint32 version, QObject *parent) +{ + //only V1 supported for now + return d->create(name, version, parent, &Registry::bindXdgImporterUnstableV1); +} + TextInputManager *Registry::createTextInputManager(quint32 name, quint32 version, QObject *parent) { switch (d->interfaceForName(name)) { case Interface::TextInputManagerUnstableV0: return d->create(name, version, parent, &Registry::bindTextInputManagerUnstableV0); case Interface::TextInputManagerUnstableV2: return d->create(name, version, parent, &Registry::bindTextInputManagerUnstableV2); default: return nullptr; } } XdgShell *Registry::createXdgShell(quint32 name, quint32 version, QObject *parent) { switch (d->interfaceForName(name)) { case Interface::XdgShellUnstableV5: return d->create(name, version, parent, &Registry::bindXdgShellUnstableV5); default: return nullptr; } } RelativePointerManager *Registry::createRelativePointerManager(quint32 name, quint32 version, QObject *parent) { switch (d->interfaceForName(name)) { case Interface::RelativePointerManagerUnstableV1: return d->create(name, version, parent, &Registry::bindRelativePointerManagerUnstableV1); default: return nullptr; } } PointerGestures *Registry::createPointerGestures(quint32 name, quint32 version, QObject *parent) { switch (d->interfaceForName(name)) { case Interface::PointerGesturesUnstableV1: return d->create(name, version, parent, &Registry::bindPointerGesturesUnstableV1); default: return nullptr; } } PointerConstraints *Registry::createPointerConstraints(quint32 name, quint32 version, QObject *parent) { switch (d->interfaceForName(name)) { case Interface::PointerConstraintsUnstableV1: return d->create(name, version, parent, &Registry::bindPointerConstraintsUnstableV1); default: return nullptr; } } namespace { static const wl_interface *wlInterface(Registry::Interface interface) { auto it = s_interfaces.find(interface); if (it != s_interfaces.end()) { return it.value().interface; } return nullptr; } } template T *Registry::Private::bind(Registry::Interface interface, uint32_t name, uint32_t version) const { auto it = std::find_if(m_interfaces.begin(), m_interfaces.end(), [=](const InterfaceData &data) { return data.interface == interface && data.name == name && data.version >= version; }); if (it == m_interfaces.end()) { qCDebug(KWAYLAND_CLIENT) << "Don't have interface " << int(interface) << "with name " << name << "and minimum version" << version; return nullptr; } auto t = reinterpret_cast(wl_registry_bind(registry, name, wlInterface(interface), version)); if (queue) { queue->addProxy(t); } return t; } bool Registry::isValid() const { return d->registry.isValid(); } wl_registry *Registry::registry() { return d->registry; } Registry::operator wl_registry*() const { return d->registry; } Registry::operator wl_registry*() { return d->registry; } } } diff --git a/src/client/registry.h b/src/client/registry.h index e141482..4ad8bad 100644 --- a/src/client/registry.h +++ b/src/client/registry.h @@ -1,1335 +1,1337 @@ /******************************************************************** Copyright 2014 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . *********************************************************************/ #ifndef WAYLAND_REGISTRY_H #define WAYLAND_REGISTRY_H #include #include #include struct wl_compositor; struct wl_data_device_manager; struct wl_display; struct wl_output; struct wl_registry; struct wl_seat; struct wl_shell; struct wl_shm; struct wl_subcompositor; struct wl_text_input_manager; struct zwp_text_input_manager_v2; struct _wl_fullscreen_shell; struct org_kde_kwin_outputmanagement; struct org_kde_kwin_outputdevice; struct org_kde_kwin_fake_input; struct org_kde_kwin_idle; struct org_kde_kwin_dpms_manager; struct org_kde_kwin_shadow_manager; struct org_kde_kwin_blur_manager; struct org_kde_kwin_contrast_manager; struct org_kde_kwin_slide_manager; struct org_kde_plasma_shell; struct org_kde_plasma_window_management; struct org_kde_kwin_server_decoration_manager; struct xdg_shell; struct zwp_relative_pointer_manager_v1; struct zwp_pointer_gestures_v1; struct zwp_pointer_constraints_v1; struct zxdg_exporter_v1; struct zxdg_importer_v1; namespace KWayland { namespace Client { class Compositor; class ConnectionThread; class DataDeviceManager; class DpmsManager; class EventQueue; class FakeInput; class FullscreenShell; class OutputManagement; class OutputDevice; class Idle; class Output; class PlasmaShell; class PlasmaWindowManagement; class PointerConstraints; class PointerGestures; class Seat; class ShadowManager; class BlurManager; class ContrastManager; class SlideManager; class Shell; class ShmPool; class ServerSideDecorationManager; class SubCompositor; class TextInputManager; class TextInputManagerUnstableV0; class TextInputManagerUnstableV2; class XdgShell; class RelativePointerManager; class XdgExporterUnstableV1; class XdgImporterUnstableV1; +class XdgExporterUnstable; +class XdgImporterUnstable; /** * @short Wrapper for the wl_registry interface. * * The purpose of this class is to manage the wl_registry interface. * This class supports some well-known interfaces and can create a * wrapper class for those. * * The main purpose is to emit signals whenever a new interface is * added or an existing interface is removed. For the well known interfaces * dedicated signals are emitted allowing a user to connect directly to the * signal announcing the interface it is interested in. * * To create and setup the Registry one needs to call create with either a * wl_display from an existing Wayland connection or a ConnectionThread instance: * * @code * ConnectionThread *connection; // existing connection * Registry registry; * registry.create(connection); * registry.setup(); * @endcode * * The interfaces are announced in an asynchronous way by the Wayland server. * To initiate the announcing of the interfaces one needs to call setup. **/ class KWAYLANDCLIENT_EXPORT Registry : public QObject { Q_OBJECT public: /** * The well-known interfaces this Registry supports. * For each of the enum values the Registry is able to create a Wrapper * object. **/ enum class Interface { Unknown, ///< Refers to an Unknown interface Compositor, ///< Refers to the wl_compositor interface Shell, ///< Refers to the wl_shell interface Seat, ///< Refers to the wl_seat interface Shm, ///< Refers to the wl_shm interface Output, ///< Refers to the wl_output interface FullscreenShell, ///< Refers to the _wl_fullscreen_shell interface SubCompositor, ///< Refers to the wl_subcompositor interface; DataDeviceManager, ///< Refers to the wl_data_device_manager interface PlasmaShell, ///< Refers to org_kde_plasma_shell interface PlasmaWindowManagement, ///< Refers to org_kde_plasma_window_management interface Idle, ///< Refers to org_kde_kwin_idle_interface interface FakeInput, ///< Refers to org_kde_kwin_fake_input interface Shadow, ///< Refers to org_kde_kwin_shadow_manager interface Blur, ///< refers to org_kde_kwin_blur_manager interface Contrast, ///< refers to org_kde_kwin_contrast_manager interface Slide, ///< refers to org_kde_kwin_slide_manager Dpms, ///< Refers to org_kde_kwin_dpms_manager interface OutputManagement, ///< Refers to the wl_data_device_manager interface OutputDevice, ///< Refers to the org_kde_kwin_outputdevice interface ServerSideDecorationManager, ///< Refers to org_kde_kwin_server_decoration_manager TextInputManagerUnstableV0, ///< Refers to wl_text_input_manager, @since 5.23 TextInputManagerUnstableV2, ///< Refers to zwp_text_input_manager_v2, @since 5.23 XdgShellUnstableV5, ///< Refers to xdg_shell (unstable version 5), @since 5.25 RelativePointerManagerUnstableV1, ///< Refers to zwp_relative_pointer_manager_v1, @since 5.28 PointerGesturesUnstableV1, ///< Refers to zwp_pointer_gestures_v1, @since 5.29 PointerConstraintsUnstableV1, ///< Refers to zwp_pointer_constraints_v1, @since 5.29 XdgExporterUnstableV1, ///< refers to zxdg_exporter_v1, @since 5.38 XdgImporterUnstableV1 ///< refers to zxdg_importer_v1, @since 5.38 }; explicit Registry(QObject *parent = nullptr); virtual ~Registry(); /** * Releases the wl_registry interface. * After the interface has been released the Registry instance is no * longer valid and can be setup with another wl_registry interface. **/ void release(); /** * Destroys the data held by this Registry. * This method is supposed to be used when the connection to the Wayland * server goes away. If the connection is not valid anymore, it's not * possible to call release anymore as that calls into the Wayland * connection and the call would fail. This method cleans up the data, so * that the instance can be deleted or set up to a new wl_registry interface * once there is a new connection available. * * It is suggested to connect this method to ConnectionThread::connectionDied: * @code * connect(connection, &ConnectionThread::connectionDied, registry, &Registry::destroy); * @endcode * * @see release **/ void destroy(); /** * Gets the registry from the @p display. **/ void create(wl_display *display); /** * Gets the registry from the @p connection. **/ void create(ConnectionThread *connection); /** * Finalizes the setup of the Registry. * After calling this method the interfaces will be announced in an asynchronous way. * The Registry must have been created when calling this method. * @see create **/ void setup(); /** * Sets the @p queue to use for this Registry. * * The EventQueue should be set before the Registry gets setup. * The EventQueue gets automatically added to all interfaces created by * this Registry. So that all objects are in teh same EventQueue. * * @param queue The event queue to use for this Registry. **/ void setEventQueue(EventQueue *queue); /** * @returns The EventQueue used by this Registry **/ EventQueue *eventQueue(); /** * @returns @c true if managing a wl_registry. **/ bool isValid() const; /** * @returns @c true if the Registry has an @p interface. **/ bool hasInterface(Interface interface) const; /** * Representation of one announced interface. **/ struct AnnouncedInterface { /** * The name of the announced interface. **/ quint32 name; /** * The maximum supported version of the announced interface. **/ quint32 version; }; /** * Provides name and version for the @p interface. * * The first value of the returned pair is the "name", the second value is the "version". * If the @p interface has not been announced, both values are set to 0. * If there @p interface has been announced multiple times, the last announced is returned. * In case one is interested in all announced interfaces, one should prefer @link interfaces(Interface) @endlink. * * The returned information can be passed into the bind or create methods. * * @param interface The well-known interface for which the name and version should be retrieved * @returns name and version of the given interface * @since 5.5 **/ AnnouncedInterface interface(Interface interface) const; /** * Provides all pairs of name and version for the well-known @p interface. * * If the @p interface has not been announced, an empty vector is returned. * * The returned information can be passed into the bind or create methods. * * @param interface The well-known interface for which the name and version should be retrieved * @returns All pairs of name and version of the given interface * @since 5.5 **/ QVector interfaces(Interface interface) const; /** * @name Low-level bind methods for global interfaces. **/ ///@{ /** * Binds the wl_compositor with @p name and @p version. * If the @p name does not exist or is not for the compositor interface, * @c null will be returned. * * Prefer using createCompositor instead. * @see createCompositor **/ wl_compositor *bindCompositor(uint32_t name, uint32_t version) const; /** * Binds the wl_shell with @p name and @p version. * If the @p name does not exist or is not for the shell interface, * @c null will be returned. * * Prefer using createShell instead. * @see createShell **/ wl_shell *bindShell(uint32_t name, uint32_t version) const; /** * Binds the wl_seat with @p name and @p version. * If the @p name does not exist or is not for the seat interface, * @c null will be returned. * * Prefer using createSeat instead. * @see createSeat **/ wl_seat *bindSeat(uint32_t name, uint32_t version) const; /** * Binds the wl_shm with @p name and @p version. * If the @p name does not exist or is not for the shm interface, * @c null will be returned. * * Prefer using createShmPool instead. * @see createShmPool **/ wl_shm *bindShm(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_outputmanagement with @p name and @p version. * If the @p name does not exist or is not for the outputmanagement interface, * @c null will be returned. * * Prefer using createOutputManagement instead. * @see createOutputManagement **/ org_kde_kwin_outputmanagement *bindOutputManagement(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_outputdevice with @p name and @p version. * If the @p name does not exist or is not for the outputdevice interface, * @c null will be returned. * * Prefer using createOutputDevice instead. * @see createOutputDevice **/ wl_output *bindOutput(uint32_t name, uint32_t version) const; /** * Binds the wl_subcompositor with @p name and @p version. * If the @p name does not exist or is not for the subcompositor interface, * @c null will be returned. * * Prefer using createSubCompositor instead. * @see createSubCompositor **/ wl_subcompositor *bindSubCompositor(uint32_t name, uint32_t version) const; /** * Binds the wl_output with @p name and @p version. * If the @p name does not exist or is not for the output interface, * @c null will be returned. * * Prefer using createOutput instead. * @see createOutput * @since 5.5 **/ org_kde_kwin_outputdevice *bindOutputDevice(uint32_t name, uint32_t version) const; /** * Binds the _wl_fullscreen_shell with @p name and @p version. * If the @p name does not exist or is not for the fullscreen shell interface, * @c null will be returned. * * Prefer using createFullscreenShell instead. * @see createFullscreenShell **/ _wl_fullscreen_shell *bindFullscreenShell(uint32_t name, uint32_t version) const; /** * Binds the wl_data_device_manager with @p name and @p version. * If the @p name does not exist or is not for the data device manager interface, * @c null will be returned. * * Prefer using createDataDeviceManager instead. * @see createDataDeviceManager **/ wl_data_device_manager *bindDataDeviceManager(uint32_t name, uint32_t version) const; /** * Binds the org_kde_plasma_shell with @p name and @p version. * If the @p name does not exist or is not for the Plasma shell interface, * @c null will be returned. * * Prefer using createPlasmaShell instead. * @see createPlasmaShell * @since 5.4 **/ org_kde_plasma_shell *bindPlasmaShell(uint32_t name, uint32_t version) const; /** * Binds the org_kde_plasma_window_management with @p name and @p version. * If the @p name does not exist or is not for the Plasma window management interface, * @c null will be returned. * * Prefer using createPlasmaWindowManagement instead. * @see createPlasmaWindowManagement * @since 5.4 **/ org_kde_plasma_window_management *bindPlasmaWindowManagement(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_idle with @p name and @p version. * If the @p name does not exist or is not for the idle interface, * @c null will be returned. * * Prefer using createIdle instead. * @see createIdle * @since 5.4 **/ org_kde_kwin_idle *bindIdle(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_fake_input with @p name and @p version. * If the @p name does not exist or is not for the fake input interface, * @c null will be returned. * * Prefer using createFakeInput instead. * @see createFakeInput * @since 5.4 **/ org_kde_kwin_fake_input *bindFakeInput(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_shadow_manager with @p name and @p version. * If the @p name does not exist or is not for the shadow manager interface, * @c null will be returned. * * Prefer using createShadowManager instead. * @see createShadowManager * @since 5.4 **/ org_kde_kwin_shadow_manager *bindShadowManager(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_blur_manager with @p name and @p version. * If the @p name does not exist or is not for the blur manager interface, * @c null will be returned. * * Prefer using createBlurManager instead. * @see createBlurManager * @since 5.5 **/ org_kde_kwin_blur_manager *bindBlurManager(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_contrast_manager with @p name and @p version. * If the @p name does not exist or is not for the contrast manager interface, * @c null will be returned. * * Prefer using createContrastManager instead. * @see createContrastManager * @since 5.5 **/ org_kde_kwin_contrast_manager *bindContrastManager(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_slide_manager with @p name and @p version. * If the @p name does not exist or is not for the slide manager interface, * @c null will be returned. * * Prefer using createSlideManager instead. * @see createSlideManager * @since 5.5 **/ org_kde_kwin_slide_manager * bindSlideManager(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_dpms_manager with @p name and @p version. * If the @p name does not exist or is not for the dpms manager interface, * @c null will be returned. * * Prefer using createDpmsManager instead. * @see createDpmsManager * @since 5.5 **/ org_kde_kwin_dpms_manager *bindDpmsManager(uint32_t name, uint32_t version) const; /** * Binds the org_kde_kwin_server_decoration_manager with @p name and @p version. * If the @p name does not exist or is not for the server side decoration manager interface, * @c null will be returned. * * Prefer using createServerSideDecorationManager instead. * @see createServerSideDecorationManager * @since 5.6 **/ org_kde_kwin_server_decoration_manager *bindServerSideDecorationManager(uint32_t name, uint32_t version) const; /** * Binds the wl_text_input_manager with @p name and @p version. * If the @p name does not exist or is not for the text input interface in unstable version 0, * @c null will be returned. * * Prefer using createTextInputManager instead. * @see createTextInputManager * @since 5.23 **/ wl_text_input_manager *bindTextInputManagerUnstableV0(uint32_t name, uint32_t version) const; /** * Binds the zwp_text_input_manager_v2 with @p name and @p version. * If the @p name does not exist or is not for the text input interface in unstable version 2, * @c null will be returned. * * Prefer using createTextInputManager instead. * @see createTextInputManager * @since 5.23 **/ zwp_text_input_manager_v2 *bindTextInputManagerUnstableV2(uint32_t name, uint32_t version) const; /** * Binds the xdg_shell (unstable version 5) with @p name and @p version. * If the @p name does not exist or is not for the xdg shell interface in unstable version 5, * @c null will be returned. * * Prefer using createXdgShell instead. * @see createXdgShell * @since 5.25 **/ xdg_shell *bindXdgShellUnstableV5(uint32_t name, uint32_t version) const; /** * Binds the zwp_relative_pointer_manager_v1 with @p name and @p version. * If the @p name does not exist or is not for the relative pointer interface in unstable version 1, * @c null will be returned. * * Prefer using createRelativePointerManager instead. * @see createRelativePointerManager * @since 5.28 **/ zwp_relative_pointer_manager_v1 *bindRelativePointerManagerUnstableV1(uint32_t name, uint32_t version) const; /** * Binds the zwp_pointer_gestures_v1 with @p name and @p version. * If the @p name does not exist or is not for the pointer gestures interface in unstable version 1, * @c null will be returned. * * Prefer using createPointerGestures instead. * @see createPointerGestures * @since 5.29 **/ zwp_pointer_gestures_v1 *bindPointerGesturesUnstableV1(uint32_t name, uint32_t version) const; /** * Binds the zwp_pointer_constraints_v1 with @p name and @p version. * If the @p name does not exist or is not for the pointer constraints interface in unstable version 1, * @c null will be returned. * * Prefer using createPointerConstraints instead. * @see createPointerConstraints * @since 5.29 **/ zwp_pointer_constraints_v1 *bindPointerConstraintsUnstableV1(uint32_t name, uint32_t version) const; zxdg_exporter_v1 *bindXdgExporterUnstableV1(uint32_t name, uint32_t version) const; zxdg_importer_v1 *bindXdgImporterUnstableV1(uint32_t name, uint32_t version) const; ///@} /** * @name Convenient factory methods for global objects. **/ ///@{ /** * Creates a Compositor and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the wl_compositor interface, * the returned Compositor will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the wl_compositor interface to bind * @param version The version or the wl_compositor interface to use * @param parent The parent for Compositor * * @returns The created Compositor. **/ Compositor *createCompositor(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a Seat and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the wl_seat interface, * the returned Seat will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the wl_seat interface to bind * @param version The version or the wl_seat interface to use * @param parent The parent for Seat * * @returns The created Seat. **/ Shell *createShell(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a Compositor and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the wl_compositor interface, * the returned Compositor will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the wl_compositor interface to bind * @param version The version or the wl_compositor interface to use * @param parent The parent for Compositor * * @returns The created Compositor. **/ Seat *createSeat(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a ShmPool and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the wl_shm interface, * the returned ShmPool will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the wl_shm interface to bind * @param version The version or the wl_shm interface to use * @param parent The parent for ShmPool * * @returns The created ShmPool. **/ ShmPool *createShmPool(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a SubCompositor and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the wl_subcompositor interface, * the returned SubCompositor will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the wl_subcompositor interface to bind * @param version The version or the wl_subcompositor interface to use * @param parent The parent for SubCompositor * * @returns The created SubCompositor. **/ SubCompositor *createSubCompositor(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates an Output and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the wl_output interface, * the returned Output will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the wl_output interface to bind * @param version The version or the wl_output interface to use * @param parent The parent for Output * * @returns The created Output. **/ Output *createOutput(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates an KWinOutputManagement and sets it up to manage the interface identified * by @p name and @p version. * * Note: in case @p name is invalid or isn't for the wl_output interface, * the returned KWinConnectors will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_outputmanagement interface to bind * @param version The version or the org_kde_kwin_outputmanagement interface to use * @param parent The parent for KWinOutputManagement * * @returns The created KWinOutputManagement. * @since 5.5 **/ OutputManagement *createOutputManagement(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates an OutputDevice and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_kwin_outputdevice interface, * the returned OutputDevice will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_outputdevice interface to bind * @param version The version or the org_kde_kwin_outputdevice interface to use * @param parent The parent for OutputDevice * * @returns The created Output. * @since 5.5 **/ OutputDevice *createOutputDevice(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a FullscreenShell and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the _wl_fullscreen_shell interface, * the returned FullscreenShell will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the _wl_fullscreen_shell interface to bind * @param version The version or the _wl_fullscreen_shell interface to use * @param parent The parent for FullscreenShell * * @returns The created FullscreenShell. * @since 5.5 **/ FullscreenShell *createFullscreenShell(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a DataDeviceManager and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the wl_data_device_manager interface, * the returned DataDeviceManager will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the wl_data_device_manager interface to bind * @param version The version or the wl_data_device_manager interface to use * @param parent The parent for DataDeviceManager * * @returns The created DataDeviceManager. **/ DataDeviceManager *createDataDeviceManager(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a PlasmaShell and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_plasma_shell interface, * the returned PlasmaShell will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_plasma_shell interface to bind * @param version The version or the org_kde_plasma_shell interface to use * @param parent The parent for PlasmaShell * * @returns The created PlasmaShell. * @since 5.4 **/ PlasmaShell *createPlasmaShell(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a PlasmaWindowManagement and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_plasma_window_management interface, * the returned PlasmaWindowManagement will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_plasma_window_management interface to bind * @param version The version or the org_kde_plasma_window_management interface to use * @param parent The parent for PlasmaWindowManagement * * @returns The created PlasmaWindowManagement. * @since 5.4 **/ PlasmaWindowManagement *createPlasmaWindowManagement(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates an Idle and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_kwin_idle interface, * the returned Idle will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_idle interface to bind * @param version The version or the org_kde_kwin_idle interface to use * @param parent The parent for Idle * * @returns The created Idle. * @since 5.4 **/ Idle *createIdle(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a FakeInput and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_kwin_fake_input interface, * the returned FakeInput will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_fake_input interface to bind * @param version The version or the org_kde_kwin_fake_input interface to use * @param parent The parent for FakeInput * * @returns The created FakeInput. * @since 5.4 **/ FakeInput *createFakeInput(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a ShadowManager and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_kwin_shadow_manager interface, * the returned ShadowManager will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_shadow_manager interface to bind * @param version The version or the org_kde_kwin_shadow_manager interface to use * @param parent The parent for ShadowManager * * @returns The created ShadowManager. * @since 5.4 **/ ShadowManager *createShadowManager(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a BlurManager and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_kwin_blur_manager interface, * the returned BlurManager will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_blur_manager interface to bind * @param version The version or the org_kde_kwin_blur_manager interface to use * @param parent The parent for BlurManager * * @returns The created BlurManager. * @since 5.5 **/ BlurManager *createBlurManager(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a ContrastManager and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_kwin_contrast_manager interface, * the returned ContrastManager will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_contrast_manager interface to bind * @param version The version or the org_kde_kwin_contrast_manager interface to use * @param parent The parent for ContrastManager * * @returns The created ContrastManager. * @since 5.5 **/ ContrastManager *createContrastManager(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a SlideManager and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_kwin_slide_manager interface, * the returned SlideManager will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_slide_manager interface to bind * @param version The version or the org_kde_kwin_slide_manager interface to use * @param parent The parent for SlideManager * * @returns The created SlideManager. * @since 5.5 **/ SlideManager *createSlideManager(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a DpmsManager and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_kwin_dpms_manager interface, * the returned DpmsManager will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_dpms_manager interface to bind * @param version The version or the org_kde_kwin_dpms_manager interface to use * @param parent The parent for DpmsManager * * @returns The created DpmsManager. * @since 5.5 **/ DpmsManager *createDpmsManager(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a ServerSideDecorationManager and sets it up to manage the interface identified by * @p name and @p version. * * Note: in case @p name is invalid or isn't for the org_kde_kwin_server_decoration_manager interface, * the returned ServerSideDecorationManager will not be valid. Therefore it's recommended to call * isValid on the created instance. * * @param name The name of the org_kde_kwin_server_decoration_manager interface to bind * @param version The version or the org_kde_kwin_server_decoration_manager interface to use * @param parent The parent for ServerSideDecorationManager * * @returns The created ServerSideDecorationManager. * @since 5.6 **/ ServerSideDecorationManager *createServerSideDecorationManager(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a TextInputManager and sets it up to manage the interface identified by * @p name and @p version. * * This factory method supports the following interfaces: * @li wl_text_input_manager * @li zwp_text_input_manager_v2 * * If @p name is for one of the supported interfaces the corresponding manager will be created, * otherwise @c null will be returned. * * @param name The name of the interface to bind * @param version The version of the interface to use * @param parent The parent for the TextInputManager * * @returns The created TextInputManager * @since 5.23 **/ TextInputManager *createTextInputManager(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates an XdgShell and sets it up to manage the interface identified by * @p name and @p version. * * This factory method supports the following interfaces: * @li xdg_shell (Unstable version 5) * * If @p name is for one of the supported interfaces the corresponding shell will be created, * otherwise @c null will be returned. * * @param name The name of the interface to bind * @param version The version of the interface to use * @param parent The parent for the XdgShell * * @returns The created XdgShell * @since 5.25 **/ XdgShell *createXdgShell(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a RelativePointerManager and sets it up to manage the interface identified by * @p name and @p version. * * This factory method supports the following interfaces: * @li zwp_relative_pointer_manager_v1 * * If @p name is for one of the supported interfaces the corresponding manager will be created, * otherwise @c null will be returned. * * @param name The name of the interface to bind * @param version The version of the interface to use * @param parent The parent for the RelativePointerManager * * @returns The created RelativePointerManager * @since 5.28 **/ RelativePointerManager *createRelativePointerManager(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a PointerGestures and sets it up to manage the interface identified by * @p name and @p version. * * This factory method supports the following interfaces: * @li zwp_pointer_gestures_v1 * * If @p name is for one of the supported interfaces the corresponding manager will be created, * otherwise @c null will be returned. * * @param name The name of the interface to bind * @param version The version of the interface to use * @param parent The parent for the PointerGestures * * @returns The created PointerGestures * @since 5.29 **/ PointerGestures *createPointerGestures(quint32 name, quint32 version, QObject *parent = nullptr); /** * Creates a PointerConstraints and sets it up to manage the interface identified by * @p name and @p version. * * This factory method supports the following interfaces: * @li zwp_pointer_constraints_v1 * * If @p name is for one of the supported interfaces the corresponding manager will be created, * otherwise @c null will be returned. * * @param name The name of the interface to bind * @param version The version of the interface to use * @param parent The parent for the PointerConstraints * * @returns The created PointerConstraints * @since 5.29 **/ PointerConstraints *createPointerConstraints(quint32 name, quint32 version, QObject *parent = nullptr); - XdgExporterUnstableV1 *createXdgExporterUnstableV1(quint32 name, quint32 version, QObject *parent = nullptr); - XdgImporterUnstableV1 *createXdgImporterUnstableV1(quint32 name, quint32 version, QObject *parent = nullptr); + XdgExporterUnstable *createXdgExporterUnstable(quint32 name, quint32 version, QObject *parent = nullptr); + XdgImporterUnstable *createXdgImporterUnstable(quint32 name, quint32 version, QObject *parent = nullptr); ///@} /** * cast operator to the low-level Wayland @c wl_registry **/ operator wl_registry*(); /** * cast operator to the low-level Wayland @c wl_registry **/ operator wl_registry*() const; /** * @returns access to the low-level Wayland @c wl_registry **/ wl_registry *registry(); Q_SIGNALS: /** * @name Interface announced signals. **/ ///@{ /** * Emitted whenever a wl_compositor interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface **/ void compositorAnnounced(quint32 name, quint32 version); /** * Emitted whenever a wl_shell interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface **/ void shellAnnounced(quint32 name, quint32 version); /** * Emitted whenever a wl_seat interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface **/ void seatAnnounced(quint32 name, quint32 version); /** * Emitted whenever a wl_shm interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface **/ void shmAnnounced(quint32 name, quint32 version); /** * Emitted whenever a wl_subcompositor interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface **/ void subCompositorAnnounced(quint32 name, quint32 version); /** * Emitted whenever a wl_output interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface **/ void outputAnnounced(quint32 name, quint32 version); /** * Emitted whenever a _wl_fullscreen_shell interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface **/ void fullscreenShellAnnounced(quint32 name, quint32 version); /** * Emitted whenever a wl_data_device_manager interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface **/ void dataDeviceManagerAnnounced(quint32 name, quint32 version); void outputManagementAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_kwin_outputdevice interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.5 **/ void outputDeviceAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_plasma_shell interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.4 **/ void plasmaShellAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_plasma_window_management interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.4 **/ void plasmaWindowManagementAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_kwin_idle interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.4 **/ void idleAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_kwin_fake_input interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.4 **/ void fakeInputAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_kwin_shadow_manager interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.4 **/ void shadowAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_kwin_blur_manager interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.5 **/ void blurAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_kwin_contrast_manager interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.5 **/ void contrastAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_kwin_slide_manager interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.5 **/ void slideAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_kwin_dpms_manager interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.5 **/ void dpmsAnnounced(quint32 name, quint32 version); /** * Emitted whenever a org_kde_kwin_server_decoration_manager interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.6 **/ void serverSideDecorationManagerAnnounced(quint32 name, quint32 version); /** * Emitted whenever a wl_text_input_manager interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.23 **/ void textInputManagerUnstableV0Announced(quint32 name, quint32 version); /** * Emitted whenever a zwp_text_input_manager_v2 interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.23 **/ void textInputManagerUnstableV2Announced(quint32 name, quint32 version); /** * Emitted whenever a xdg_shell (unstable version 5) interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.25 **/ void xdgShellUnstableV5Announced(quint32 name, quint32 version); /** * Emitted whenever a zwp_relative_pointer_manager_v1 interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.28 **/ void relativePointerManagerUnstableV1Announced(quint32 name, quint32 version); /** * Emitted whenever a zwp_pointer_gestures_v1 interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.29 **/ void pointerGesturesUnstableV1Announced(quint32 name, quint32 version); /** * Emitted whenever a zwp_pointer_constraints_v1 interface gets announced. * @param name The name for the announced interface * @param version The maximum supported version of the announced interface * @since 5.29 **/ void pointerConstraintsUnstableV1Announced(quint32 name, quint32 version); void exporterUnstableV1Announced(quint32 name, quint32 version); void importerUnstableV1Announced(quint32 name, quint32 version); ///@} /** * @name Interface removed signals. **/ ///@{ /** * Emitted whenever a wl_compositor interface gets removed. * @param name The name for the removed interface **/ void compositorRemoved(quint32 name); /** * Emitted whenever a wl_shell interface gets removed. * @param name The name for the removed interface **/ void shellRemoved(quint32 name); /** * Emitted whenever a wl_seat interface gets removed. * @param name The name for the removed interface **/ void seatRemoved(quint32 name); /** * Emitted whenever a wl_shm interface gets removed. * @param name The name for the removed interface **/ void shmRemoved(quint32 name); /** * Emitted whenever a wl_subcompositor interface gets removed. * @param name The name for the removed interface **/ void subCompositorRemoved(quint32 name); /** * Emitted whenever a wl_output interface gets removed. * @param name The name for the removed interface **/ void outputRemoved(quint32 name); /** * Emitted whenever a _wl_fullscreen_shell interface gets removed. * @param name The name for the removed interface **/ void fullscreenShellRemoved(quint32 name); /** * Emitted whenever a wl_data_device_manager interface gets removed. * @param name The name for the removed interface **/ void dataDeviceManagerRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_outputmanagement interface gets removed. * @param name The name for the removed interface * @since 5.5 **/ void outputManagementRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_outputdevice interface gets removed. * @param name The name for the removed interface * @since 5.5 **/ void outputDeviceRemoved(quint32 name); /** * Emitted whenever a org_kde_plasma_shell interface gets removed. * @param name The name for the removed interface * @since 5.4 **/ void plasmaShellRemoved(quint32 name); /** * Emitted whenever a org_kde_plasma_window_management interface gets removed. * @param name The name for the removed interface * @since 5.4 **/ void plasmaWindowManagementRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_idle interface gets removed. * @param name The name for the removed interface * @since 5.4 **/ void idleRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_fake_input interface gets removed. * @param name The name for the removed interface * @since 5.4 **/ void fakeInputRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_shadow_manager interface gets removed. * @param name The name for the removed interface * @since 5.4 **/ void shadowRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_blur_manager interface gets removed. * @param name The name for the removed interface * @since 5.5 **/ void blurRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_contrast_manager interface gets removed. * @param name The name for the removed interface * @since 5.5 **/ void contrastRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_slide_manager interface gets removed. * @param name The name for the removed interface * @since 5.5 **/ void slideRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_dpms_manager interface gets removed. * @param name The name for the removed interface * @since 5.5 **/ void dpmsRemoved(quint32 name); /** * Emitted whenever a org_kde_kwin_server_decoration_manager interface gets removed. * @param name The name for the removed interface * @since 5.6 **/ void serverSideDecorationManagerRemoved(quint32 name); /** * Emitted whenever a wl_text_input_manager interface gets removed. * @param name The name for the removed interface * @since 5.23 **/ void textInputManagerUnstableV0Removed(quint32 name); /** * Emitted whenever a zwp_text_input_manager_v2 interface gets removed. * @param name The name for the removed interface * @since 5.23 **/ void textInputManagerUnstableV2Removed(quint32 name); /** * Emitted whenever an xdg_shell (unstable version 5) interface gets removed. * @param name The name for the removed interface * @since 5.25 **/ void xdgShellUnstableV5Removed(quint32 name); /** * Emitted whenever a zwp_relative_pointer_manager_v1 interface gets removed. * @param name The name for the removed interface * @since 5.28 **/ void relativePointerManagerUnstableV1Removed(quint32 name); /** * Emitted whenever a zwp_pointer_gestures_v1 interface gets removed. * @param name The name for the removed interface * @since 5.29 **/ void pointerGesturesUnstableV1Removed(quint32 name); /** * Emitted whenever a zwp_pointer_constraints_v1 interface gets removed. * @param name The name for the removed interface * @since 5.29 **/ void pointerConstraintsUnstableV1Removed(quint32 name); void exporterUnstableV1Removed(quint32 name); void importerUnstableV1Removed(quint32 name); ///@} /** * Generic announced signal which gets emitted whenever an interface gets * announced. * * This signal is emitted before the dedicated signals are handled. If one * wants to know about one of the well-known interfaces use the dedicated * signals instead. Especially the bind methods might fail before the dedicated * signals are emitted. * * @param interface The interface (e.g. wl_compositor) which is announced * @param name The name for the announced interface * @param version The maximum supported version of the announced interface **/ void interfaceAnnounced(QByteArray interface, quint32 name, quint32 version); /** * Generic removal signal which gets emitted whenever an interface gets removed. * * This signal is emitted after the dedicated signals are handled. * * @param name The name for the removed interface **/ void interfaceRemoved(quint32 name); /** * Emitted when the Wayland display is done flushing the initial interface * callbacks, announcing wl_display properties. This can be used to compress * events. Note that this signal is emitted only after announcing interfaces, * such as outputs, but not after receiving callbacks of interface properties, * such as the output's geometry, modes, etc.. * This signal is emitted from the wl_display_sync callback. **/ void interfacesAnnounced(); Q_SIGNALS: /* * Emitted when the registry has been destroyed rather than released */ void registryDestroyed(); private: class Private; QScopedPointer d; }; } } #endif diff --git a/src/client/xdgforeign.cpp b/src/client/xdgforeign.cpp new file mode 100644 index 0000000..274d0fa --- /dev/null +++ b/src/client/xdgforeign.cpp @@ -0,0 +1,271 @@ +/**************************************************************************** +Copyright 2017 Marco Martin + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) version 3, or any +later version accepted by the membership of KDE e.V. (or its +successor approved by the membership of KDE e.V.), which shall +act as a proxy defined in Section 6 of version 3 of the license. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library. If not, see . +****************************************************************************/ +#include "xdgforeign.h" +#include "xdgforeign_p.h" +#include "event_queue.h" +#include "wayland_pointer_p.h" + +#include + +#include + +namespace KWayland +{ +namespace Client +{ + +XdgExporterUnstable::Private::Private() +{ +} + +XdgExporterUnstable::Private::~Private() +{ +} + +XdgExporterUnstable::XdgExporterUnstable(Private *p, QObject *parent) + : QObject(parent) + , d(p) +{ +} + +XdgExporterUnstable::~XdgExporterUnstable() +{ + release(); +} + +void XdgExporterUnstable::setup(zxdg_exporter_v1 *exporter) +{ + d->setupV1(exporter); +} + +void XdgExporterUnstable::release() +{ + d->release(); +} + +void XdgExporterUnstable::destroy() +{ + d->destroy(); +} + +XdgExporterUnstable::operator zxdg_exporter_v1*() { + return d->exporterV1(); +} + +XdgExporterUnstable::operator zxdg_exporter_v1*() const { + return d->exporterV1(); +} + +bool XdgExporterUnstable::isValid() const +{ + return d->isValid(); +} + +void XdgExporterUnstable::setEventQueue(EventQueue *queue) +{ + d->queue = queue; +} + +EventQueue *XdgExporterUnstable::eventQueue() +{ + return d->queue; +} + +XdgExportedUnstable *XdgExporterUnstable::exportSurface(Surface *surface, QObject *parent) +{ + return d->exportTopLevelV1(surface, parent); +} + + + +XdgImporterUnstable::Private::Private() +{ +} + +XdgImporterUnstable::Private::~Private() +{ +} + +XdgImporterUnstable::XdgImporterUnstable(Private *p, QObject *parent) + : QObject(parent) + , d(p) +{ +} + +XdgImporterUnstable::~XdgImporterUnstable() +{ + release(); +} + +void XdgImporterUnstable::setup(zxdg_importer_v1 *importer) +{ + d->setupV1(importer); +} + +void XdgImporterUnstable::release() +{ + d->release(); +} + +void XdgImporterUnstable::destroy() +{ + d->destroy(); +} + +XdgImporterUnstable::operator zxdg_importer_v1*() { + return d->importerV1(); +} + +XdgImporterUnstable::operator zxdg_importer_v1*() const { + return d->importerV1(); +} + +bool XdgImporterUnstable::isValid() const +{ + return d->isValid(); +} + +void XdgImporterUnstable::setEventQueue(EventQueue *queue) +{ + d->queue = queue; +} + +EventQueue *XdgImporterUnstable::eventQueue() +{ + return d->queue; +} + +XdgImportedUnstable *XdgImporterUnstable::import(const QString & handle, QObject *parent) +{ + Q_ASSERT(isValid()); + return d->importTopLevelV1(handle, parent); +} + +XdgExportedUnstable::XdgExportedUnstable(Private *p, QObject *parent) + : QObject(parent) + , d(p) +{ +} + +XdgExportedUnstable::Private::Private(XdgExportedUnstable *q) + : q(q) +{ +} + +XdgExportedUnstable::Private::~Private() +{ +} + +XdgExportedUnstable::~XdgExportedUnstable() +{ + release(); +} + +void XdgExportedUnstable::setup(zxdg_exported_v1 *exported) +{ + d->setupV1(exported); +} + +void XdgExportedUnstable::release() +{ + d->release(); +} + +void XdgExportedUnstable::destroy() +{ + d->destroy(); +} + +QString XdgExportedUnstable::handle() const +{ + return d->handle; +} + +XdgExportedUnstable::operator zxdg_exported_v1*() { + return d->exportedV1(); +} + +XdgExportedUnstable::operator zxdg_exported_v1*() const { + return d->exportedV1(); +} + +bool XdgExportedUnstable::isValid() const +{ + return d->isValid(); +} + +XdgImportedUnstable::Private::Private(XdgImportedUnstable *q) + : q(q) +{ +} + +XdgImportedUnstable::Private::~Private() +{ +} + +XdgImportedUnstable::XdgImportedUnstable(Private *p, QObject *parent) + : QObject(parent) + , d(p) +{ +} + +XdgImportedUnstable::~XdgImportedUnstable() +{ + release(); +} + +void XdgImportedUnstable::setup(zxdg_imported_v1 *imported) +{ + d->setupV1(imported); +} + +void XdgImportedUnstable::release() +{ + d->release(); +} + +void XdgImportedUnstable::destroy() +{ + d->destroy(); +} + +XdgImportedUnstable::operator zxdg_imported_v1*() { + return d->importedV1(); +} + +XdgImportedUnstable::operator zxdg_imported_v1*() const { + return d->importedV1(); +} + +bool XdgImportedUnstable::isValid() const +{ + return d->isValid(); +} + +void XdgImportedUnstable::setParentOf(Surface *surface) +{ + Q_ASSERT(isValid()); + d->setParentOf(surface); +} + + +} +} + diff --git a/src/client/xdgforeign_v1.h b/src/client/xdgforeign.h similarity index 86% copy from src/client/xdgforeign_v1.h copy to src/client/xdgforeign.h index eda1699..fbd0d8b 100644 --- a/src/client/xdgforeign_v1.h +++ b/src/client/xdgforeign.h @@ -1,362 +1,350 @@ /**************************************************************************** Copyright 2017 Marco Martin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . ****************************************************************************/ -#ifndef KWAYLAND_CLIENT_XDGFOREIGN_V1_H -#define KWAYLAND_CLIENT_XDGFOREIGN_V1_H +#ifndef KWAYLAND_CLIENT_XDGFOREIGN_H +#define KWAYLAND_CLIENT_XDGFOREIGN_H #include "surface.h" #include #include struct zxdg_exporter_v1; struct zxdg_importer_v1; struct zxdg_exported_v1; struct zxdg_imported_v1; namespace KWayland { namespace Client { class EventQueue; class Surface; -class XdgExportedUnstableV1; -class XdgImportedUnstableV1; +class XdgExportedUnstable; +class XdgImportedUnstable; /** * @short Wrapper for the zxdg_exporter_v1 interface. * * This class provides a convenient wrapper for the zxdg_exporter_v1 interface. * * To use this class one needs to interact with the Registry. There are two * possible ways to create the interface: * @code * *c = registry->create(name, version); * @endcode * * This creates the and sets it up directly. As an alternative this * can also be done in a more low level way: * @code * *c = new ; * c->setup(registry->bind(name, version)); * @endcode * * The can be used as a drop-in replacement for any zxdg_exporter_v1 * pointer as it provides matching cast operators. * * @see Registry **/ -class KWAYLANDCLIENT_EXPORT XdgExporterUnstableV1 : public QObject +class KWAYLANDCLIENT_EXPORT XdgExporterUnstable : public QObject { Q_OBJECT public: - /** - * Creates a new . - * Note: after constructing the it is not yet valid and one needs - * to call setup. In order to get a ready to use prefer using - * Registry::create. - **/ - explicit XdgExporterUnstableV1(QObject *parent = nullptr); - virtual ~XdgExporterUnstableV1(); + virtual ~XdgExporterUnstable(); /** * Setup this to manage the @p . * When using Registry::create there is no need to call this * method. **/ void setup(zxdg_exporter_v1 *); /** * @returns @c true if managing a zxdg_exporter_v1. **/ bool isValid() const; /** * Releases the zxdg_exporter_v1 interface. * After the interface has been released the instance is no * longer valid and can be setup with another zxdg_exporter_v1 interface. **/ void release(); /** * Destroys the data held by this . * This method is supposed to be used when the connection to the Wayland * server goes away. If the connection is not valid anymore, it's not * possible to call release anymore as that calls into the Wayland * connection and the call would fail. This method cleans up the data, so * that the instance can be deleted or set up to a new zxdg_exporter_v1 interface * once there is a new connection available. * * It is suggested to connect this method to ConnectionThread::connectionDied: * @code * connect(connection, &ConnectionThread::connectionDied, , &::destroy); * @endcode * * @see release **/ void destroy(); /** * Sets the @p queue to use for creating objects with this . **/ void setEventQueue(EventQueue *queue); /** * @returns The event queue to use for creating objects with this . **/ EventQueue *eventQueue(); - XdgExportedUnstableV1 *exportSurface(Surface *surface, QObject *parent = nullptr); + XdgExportedUnstable *exportSurface(Surface *surface, QObject *parent = nullptr); operator zxdg_exporter_v1*(); operator zxdg_exporter_v1*() const; Q_SIGNALS: /** * The corresponding global for this interface on the Registry got removed. * * This signal gets only emitted if the got created by * Registry::create **/ void removed(); -private: +protected: class Private; + explicit XdgExporterUnstable(Private *p, QObject *parent = nullptr); QScopedPointer d; }; /** * @short Wrapper for the zxdg_importer_v1 interface. * * This class provides a convenient wrapper for the zxdg_importer_v1 interface. * * To use this class one needs to interact with the Registry. There are two * possible ways to create the interface: * @code * *c = registry->create(name, version); * @endcode * * This creates the and sets it up directly. As an alternative this * can also be done in a more low level way: * @code * *c = new ; * c->setup(registry->bind(name, version)); * @endcode * * The can be used as a drop-in replacement for any zxdg_importer_v1 * pointer as it provides matching cast operators. * * @see Registry **/ -class KWAYLANDCLIENT_EXPORT XdgImporterUnstableV1 : public QObject +class KWAYLANDCLIENT_EXPORT XdgImporterUnstable : public QObject { Q_OBJECT public: - /** - * Creates a new . - * Note: after constructing the it is not yet valid and one needs - * to call setup. In order to get a ready to use prefer using - * Registry::create. - **/ - explicit XdgImporterUnstableV1(QObject *parent = nullptr); - virtual ~XdgImporterUnstableV1(); + virtual ~XdgImporterUnstable(); /** * Setup this to manage the @p . * When using Registry::create there is no need to call this * method. **/ void setup(zxdg_importer_v1 *); /** * @returns @c true if managing a zxdg_importer_v1. **/ bool isValid() const; /** * Releases the zxdg_importer_v1 interface. * After the interface has been released the instance is no * longer valid and can be setup with another zxdg_importer_v1 interface. **/ void release(); /** * Destroys the data held by this . * This method is supposed to be used when the connection to the Wayland * server goes away. If the connection is not valid anymore, it's not * possible to call release anymore as that calls into the Wayland * connection and the call would fail. This method cleans up the data, so * that the instance can be deleted or set up to a new zxdg_importer_v1 interface * once there is a new connection available. * * It is suggested to connect this method to ConnectionThread::connectionDied: * @code * connect(connection, &ConnectionThread::connectionDied, , &::destroy); * @endcode * * @see release **/ void destroy(); /** * Sets the @p queue to use for creating objects with this . **/ void setEventQueue(EventQueue *queue); /** * @returns The event queue to use for creating objects with this . **/ EventQueue *eventQueue(); - XdgImportedUnstableV1 *import(const QString & handle, QObject *parent = nullptr); + XdgImportedUnstable *import(const QString & handle, QObject *parent = nullptr); operator zxdg_importer_v1*(); operator zxdg_importer_v1*() const; Q_SIGNALS: /** * The corresponding global for this interface on the Registry got removed. * * This signal gets only emitted if the got created by * Registry::create **/ void removed(); -private: +protected: class Private; + explicit XdgImporterUnstable(Private *p, QObject *parent = nullptr); QScopedPointer d; }; -class KWAYLANDCLIENT_EXPORT XdgExportedUnstableV1 : public QObject +class KWAYLANDCLIENT_EXPORT XdgExportedUnstable : public QObject { Q_OBJECT public: - virtual ~XdgExportedUnstableV1(); + virtual ~XdgExportedUnstable(); /** * Setup this to manage the @p . * When using ::create there is no need to call this * method. **/ void setup(zxdg_exported_v1 *); /** * @returns @c true if managing a zxdg_exported_v1. **/ bool isValid() const; /** * Releases the zxdg_exported_v1 interface. * After the interface has been released the instance is no * longer valid and can be setup with another zxdg_exported_v1 interface. **/ void release(); /** * Destroys the data held by this . * This method is supposed to be used when the connection to the Wayland * server goes away. If the connection is not valid anymore, it's not * possible to call release anymore as that calls into the Wayland * connection and the call would fail. This method cleans up the data, so * that the instance can be deleted or set up to a new zxdg_exported_v1 interface * once there is a new connection available. * * It is suggested to connect this method to ConnectionThread::connectionDied: * @code * connect(connection, &ConnectionThread::connectionDied, , &::destroy); * @endcode * * @see release **/ void destroy(); QString handle() const; operator zxdg_exported_v1*(); operator zxdg_exported_v1*() const; Q_SIGNALS: /** * Emitted when the exported window is fully initialized. * the handle will be valid at this point **/ void done(); -private: - friend class XdgExporterUnstableV1; - explicit XdgExportedUnstableV1(QObject *parent = nullptr); +protected: + friend class XdgExporterUnstable; class Private; + explicit XdgExportedUnstable(Private *p, QObject *parent = nullptr); QScopedPointer d; }; -class KWAYLANDCLIENT_EXPORT XdgImportedUnstableV1 : public QObject +class KWAYLANDCLIENT_EXPORT XdgImportedUnstable : public QObject { Q_OBJECT public: - virtual ~XdgImportedUnstableV1(); + virtual ~XdgImportedUnstable(); /** * Setup this to manage the @p . * When using ::create there is no need to call this * method. **/ void setup(zxdg_imported_v1 *); /** * @returns @c true if managing a zxdg_imported_v1. **/ bool isValid() const; /** * Releases the zxdg_imported_v1 interface. * After the interface has been released the instance is no * longer valid and can be setup with another zxdg_imported_v1 interface. **/ void release(); /** * Destroys the data held by this . * This method is supposed to be used when the connection to the Wayland * server goes away. If the connection is not valid anymore, it's not * possible to call release anymore as that calls into the Wayland * connection and the call would fail. This method cleans up the data, so * that the instance can be deleted or set up to a new zxdg_imported_v1 interface * once there is a new connection available. * * It is suggested to connect this method to ConnectionThread::connectionDied: * @code * connect(connection, &ConnectionThread::connectionDied, , &::destroy); * @endcode * * @see release **/ void destroy(); void setParentOf(Surface *surface); operator zxdg_imported_v1*(); operator zxdg_imported_v1*() const; Q_SIGNALS: /** * Emitted when the imported surface is not valid anymore, * for instance because it's no longer exported on the other end */ void importedDestroyed(); -private: - friend class XdgImporterUnstableV1; - explicit XdgImportedUnstableV1(QObject *parent = nullptr); +protected: + friend class XdgImporterUnstable; class Private; + explicit XdgImportedUnstable(Private *p, QObject *parent = nullptr); QScopedPointer d; }; } } #endif diff --git a/src/client/xdgforeign_p.h b/src/client/xdgforeign_p.h new file mode 100644 index 0000000..3e667fd --- /dev/null +++ b/src/client/xdgforeign_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +Copyright 2017 Marco Martin + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) version 3, or any +later version accepted by the membership of KDE e.V. (or its +successor approved by the membership of KDE e.V.), which shall +act as a proxy defined in Section 6 of version 3 of the license. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library. If not, see . +****************************************************************************/ +#ifndef KWAYLAND_CLIENT_XDGFOREIGN_P_H +#define KWAYLAND_CLIENT_XDGFOREIGN_P_H + +#include "xdgforeign.h" +#include + +namespace KWayland +{ +namespace Client +{ + +class XdgExportedUnstableV1; +class XdgImportedUnstableV1; + +class Q_DECL_HIDDEN XdgExporterUnstable::Private +{ +public: + Private(); + virtual ~Private(); + + virtual XdgExportedUnstable *exportTopLevelV1(Surface *surface, QObject *parent) = 0; + + virtual void setupV1(zxdg_exporter_v1 *arg) = 0; + virtual zxdg_exporter_v1 *exporterV1() = 0; + + virtual void release() = 0; + virtual void destroy() = 0; + virtual bool isValid() = 0; + + EventQueue *queue = nullptr; +}; + +class Q_DECL_HIDDEN XdgImporterUnstable::Private +{ +public: + Private(); + virtual ~Private(); + + virtual XdgImportedUnstable *importTopLevelV1(const QString & handle, QObject *parent) = 0; + + virtual void setupV1(zxdg_importer_v1 *arg) = 0; + virtual zxdg_importer_v1 *importerV1() = 0; + + virtual void release() = 0; + virtual void destroy() = 0; + virtual bool isValid() = 0; + + EventQueue *queue = nullptr; +}; + + +class Q_DECL_HIDDEN XdgExportedUnstable::Private +{ +public: + Private(XdgExportedUnstable *q); + virtual ~Private(); + + virtual void setupV1(zxdg_exported_v1 *) = 0; + virtual zxdg_exported_v1 *exportedV1() = 0; + + virtual void release() = 0; + virtual void destroy() = 0; + virtual bool isValid() = 0; + + QString handle; + +protected: + XdgExportedUnstable *q; + +}; + + +class Q_DECL_HIDDEN XdgImportedUnstable::Private +{ +public: + Private(XdgImportedUnstable *q); + virtual ~Private(); + + virtual void setupV1(zxdg_imported_v1 *) = 0; + virtual zxdg_imported_v1 *importedV1() = 0; + + virtual void setParentOf(Surface *surface) = 0; + virtual void release() = 0; + virtual void destroy() = 0; + virtual bool isValid() = 0; + +protected: + XdgImportedUnstable *q; +}; + +} +} + +#endif diff --git a/src/client/xdgforeign_v1.cpp b/src/client/xdgforeign_v1.cpp index f8d3de3..a51a293 100644 --- a/src/client/xdgforeign_v1.cpp +++ b/src/client/xdgforeign_v1.cpp @@ -1,369 +1,337 @@ /**************************************************************************** Copyright 2017 Marco Martin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . ****************************************************************************/ #include "xdgforeign_v1.h" +#include "xdgforeign_p.h" #include "event_queue.h" #include "wayland_pointer_p.h" #include #include namespace KWayland { namespace Client { -class Q_DECL_HIDDEN XdgExporterUnstableV1::Private +class Q_DECL_HIDDEN XdgExporterUnstableV1::Private : public XdgExporterUnstable::Private { public: - Private() = default; + Private(); - void setup(zxdg_exporter_v1 *arg); + XdgExportedUnstable *exportTopLevelV1(Surface *surface, QObject *parent) override; + void setupV1(zxdg_exporter_v1 *arg) override; + zxdg_exporter_v1 *exporterV1() override; + + void release() override; + void destroy() override; + bool isValid() override; WaylandPointer exporter; - EventQueue *queue = nullptr; }; -XdgExporterUnstableV1::XdgExporterUnstableV1(QObject *parent) - : QObject(parent) - , d(new Private) -{ -} +XdgExporterUnstableV1::Private::Private() + : XdgExporterUnstable::Private() +{} -void XdgExporterUnstableV1::Private::setup(zxdg_exporter_v1 *arg) +zxdg_exporter_v1 *XdgExporterUnstableV1::Private::exporterV1() { - Q_ASSERT(arg); - Q_ASSERT(!exporter); - exporter.setup(arg); + return exporter; } -XdgExporterUnstableV1::~XdgExporterUnstableV1() +void XdgExporterUnstableV1::Private::release() { + exporter.release(); } -void XdgExporterUnstableV1::setup(zxdg_exporter_v1 *exporter) +void XdgExporterUnstableV1::Private::destroy() { - d->setup(exporter); + exporter.destroy(); } -void XdgExporterUnstableV1::release() +bool XdgExporterUnstableV1::Private::isValid() { - d->exporter.release(); + return exporter.isValid(); } -void XdgExporterUnstableV1::destroy() +XdgExportedUnstable *XdgExporterUnstableV1::Private::exportTopLevelV1(Surface *surface, QObject *parent) { - d->exporter.destroy(); -} - -XdgExporterUnstableV1::operator zxdg_exporter_v1*() { - return d->exporter; -} - -XdgExporterUnstableV1::operator zxdg_exporter_v1*() const { - return d->exporter; + Q_ASSERT(isValid()); + auto p = new XdgExportedUnstableV1(parent); + auto w = zxdg_exporter_v1_export_toplevel(exporter, *surface); + if (queue) { + queue->addProxy(w); + } + p->setup(w); + return p; } -bool XdgExporterUnstableV1::isValid() const -{ - return d->exporter.isValid(); -} -void XdgExporterUnstableV1::setEventQueue(EventQueue *queue) +XdgExporterUnstableV1::XdgExporterUnstableV1(QObject *parent) + : XdgExporterUnstable(new Private, parent) { - d->queue = queue; } -EventQueue *XdgExporterUnstableV1::eventQueue() +void XdgExporterUnstableV1::Private::setupV1(zxdg_exporter_v1 *arg) { - return d->queue; + Q_ASSERT(arg); + Q_ASSERT(!exporter); + exporter.setup(arg); } -XdgExportedUnstableV1 *XdgExporterUnstableV1::exportSurface(Surface *surface, QObject *parent) +XdgExporterUnstableV1::~XdgExporterUnstableV1() { - Q_ASSERT(isValid()); - auto p = new XdgExportedUnstableV1(parent); - auto w = zxdg_exporter_v1_export_toplevel(d->exporter, *surface); - if (d->queue) { - d->queue->addProxy(w); - } - p->setup(w); - return p; } -class Q_DECL_HIDDEN XdgImporterUnstableV1::Private +class Q_DECL_HIDDEN XdgImporterUnstableV1::Private : public XdgImporterUnstable::Private { public: - Private() = default; + Private(); + + XdgImportedUnstable *importTopLevelV1(const QString & handle, QObject *parent) override; + void setupV1(zxdg_importer_v1 *arg) override; + zxdg_importer_v1 *importerV1() override; - void setup(zxdg_importer_v1 *arg); + void release() override; + void destroy() override; + bool isValid() override; WaylandPointer importer; EventQueue *queue = nullptr; }; -XdgImporterUnstableV1::XdgImporterUnstableV1(QObject *parent) - : QObject(parent) - , d(new Private) -{ -} +XdgImporterUnstableV1::Private::Private() + : XdgImporterUnstable::Private() +{} -void XdgImporterUnstableV1::Private::setup(zxdg_importer_v1 *arg) +zxdg_importer_v1 *XdgImporterUnstableV1::Private::importerV1() { - Q_ASSERT(arg); - Q_ASSERT(!importer); - importer.setup(arg); + return importer; } -XdgImporterUnstableV1::~XdgImporterUnstableV1() +void XdgImporterUnstableV1::Private::release() { + importer.release(); } -void XdgImporterUnstableV1::setup(zxdg_importer_v1 *importer) +void XdgImporterUnstableV1::Private::destroy() { - d->setup(importer); + importer.destroy(); } -void XdgImporterUnstableV1::release() +bool XdgImporterUnstableV1::Private::isValid() { - d->importer.release(); + return importer.isValid(); } -void XdgImporterUnstableV1::destroy() +XdgImportedUnstable *XdgImporterUnstableV1::Private::importTopLevelV1(const QString & handle, QObject *parent) { - d->importer.destroy(); -} - -XdgImporterUnstableV1::operator zxdg_importer_v1*() { - return d->importer; + Q_ASSERT(isValid()); + auto p = new XdgImportedUnstableV1(parent); + auto w = zxdg_importer_v1_import_toplevel(importer, handle.toUtf8()); + if (queue) { + queue->addProxy(w); + } + p->setup(w); + return p; } -XdgImporterUnstableV1::operator zxdg_importer_v1*() const { - return d->importer; -} -bool XdgImporterUnstableV1::isValid() const +XdgImporterUnstableV1::XdgImporterUnstableV1(QObject *parent) + : XdgImporterUnstable(new Private, parent) { - return d->importer.isValid(); } -void XdgImporterUnstableV1::setEventQueue(EventQueue *queue) +void XdgImporterUnstableV1::Private::setupV1(zxdg_importer_v1 *arg) { - d->queue = queue; + Q_ASSERT(arg); + Q_ASSERT(!importer); + importer.setup(arg); } -EventQueue *XdgImporterUnstableV1::eventQueue() +XdgImporterUnstableV1::~XdgImporterUnstableV1() { - return d->queue; } -XdgImportedUnstableV1 *XdgImporterUnstableV1::import(const QString & handle, QObject *parent) -{ - Q_ASSERT(isValid()); - auto p = new XdgImportedUnstableV1(parent); - auto w = zxdg_importer_v1_import_toplevel(d->importer, handle.toUtf8()); - if (d->queue) { - d->queue->addProxy(w); - } - p->setup(w); - return p; -} -class Q_DECL_HIDDEN XdgExportedUnstableV1::Private +class Q_DECL_HIDDEN XdgExportedUnstableV1::Private : public XdgExportedUnstable::Private { public: Private(XdgExportedUnstableV1 *q); - void setup(zxdg_exported_v1 *arg); + void setupV1(zxdg_exported_v1 *arg) override; + zxdg_exported_v1 *exportedV1() override; - WaylandPointer exported; - - QString handle; + void release() override; + void destroy() override; + bool isValid() override; -private: - XdgExportedUnstableV1 *q; + WaylandPointer exported; private: static void handleCallback(void *data, zxdg_exported_v1 *zxdg_exported_v1, const char * handle); static const zxdg_exported_v1_listener s_listener; }; +zxdg_exported_v1 *XdgExportedUnstableV1::Private::exportedV1() +{ + return exported; +} + +void XdgExportedUnstableV1::Private::release() +{ + exported.release(); +} + +void XdgExportedUnstableV1::Private::destroy() +{ + exported.destroy(); +} + +bool XdgExportedUnstableV1::Private::isValid() +{ + return exported.isValid(); +} + + const zxdg_exported_v1_listener XdgExportedUnstableV1::Private::s_listener = { handleCallback }; void XdgExportedUnstableV1::Private::handleCallback(void *data, zxdg_exported_v1 *zxdg_exported_v1, const char * handle) { auto p = reinterpret_cast(data); Q_ASSERT(p->exported == zxdg_exported_v1); p->handle = handle; emit p->q->done(); } XdgExportedUnstableV1::XdgExportedUnstableV1(QObject *parent) - : QObject(parent) - , d(new Private(this)) + : XdgExportedUnstable(new Private(this), parent) { } -void XdgExportedUnstableV1::Private::setup(zxdg_exported_v1 *arg) +void XdgExportedUnstableV1::Private::setupV1(zxdg_exported_v1 *arg) { Q_ASSERT(arg); Q_ASSERT(!exported); exported.setup(arg); zxdg_exported_v1_add_listener(exported, &s_listener, this); } XdgExportedUnstableV1::Private::Private(XdgExportedUnstableV1 *q) - : q(q) + : XdgExportedUnstable::Private::Private(q) { } XdgExportedUnstableV1::~XdgExportedUnstableV1() { } -void XdgExportedUnstableV1::setup(zxdg_exported_v1 *exported) +class Q_DECL_HIDDEN XdgImportedUnstableV1::Private : public XdgImportedUnstable::Private { - d->setup(exported); -} +public: + Private(XdgImportedUnstableV1 *q); -void XdgExportedUnstableV1::release() -{ - d->exported.release(); -} + void setupV1(zxdg_imported_v1 *arg) override; + zxdg_imported_v1 *importedV1() override; + + void setParentOf(Surface *surface) override; + void release() override; + void destroy() override; + bool isValid() override; + + WaylandPointer imported; -void XdgExportedUnstableV1::destroy() +private: + static void destroyedCallback(void *data, zxdg_imported_v1 *zxdg_imported_v1); + + static const zxdg_imported_v1_listener s_listener; +}; + +XdgImportedUnstableV1::Private::Private(XdgImportedUnstableV1 *q) + : XdgImportedUnstable::Private::Private(q) { - d->exported.destroy(); } -QString XdgExportedUnstableV1::handle() const +zxdg_imported_v1 *XdgImportedUnstableV1::Private::importedV1() { - return d->handle; + return imported; } -XdgExportedUnstableV1::operator zxdg_exported_v1*() { - return d->exported; +void XdgImportedUnstableV1::Private::release() +{ + imported.release(); } -XdgExportedUnstableV1::operator zxdg_exported_v1*() const { - return d->exported; +void XdgImportedUnstableV1::Private::destroy() +{ + imported.destroy(); } -bool XdgExportedUnstableV1::isValid() const +bool XdgImportedUnstableV1::Private::isValid() { - return d->exported.isValid(); + return imported.isValid(); } -class Q_DECL_HIDDEN XdgImportedUnstableV1::Private +void XdgImportedUnstableV1::Private::setParentOf(Surface *surface) { -public: - Private(XdgImportedUnstableV1 *q); - - void setup(zxdg_imported_v1 *arg); - - WaylandPointer imported; - -private: - XdgImportedUnstableV1 *q; - -private: - static void destroyedCallback(void *data, zxdg_imported_v1 *zxdg_imported_v1); - - static const zxdg_imported_v1_listener s_listener; -}; + Q_ASSERT(isValid()); + zxdg_imported_v1_set_parent_of(imported, *surface); +} const zxdg_imported_v1_listener XdgImportedUnstableV1::Private::s_listener = { destroyedCallback }; void XdgImportedUnstableV1::Private::destroyedCallback(void *data, zxdg_imported_v1 *zxdg_imported_v1) { auto p = reinterpret_cast(data); Q_ASSERT(p->imported == zxdg_imported_v1); - // TODO: implement + p->q->release(); emit p->q->importedDestroyed(); } -XdgImportedUnstableV1::Private::Private(XdgImportedUnstableV1 *q) - : q(q) -{ -} + XdgImportedUnstableV1::XdgImportedUnstableV1(QObject *parent) - : QObject(parent) - , d(new Private(this)) + : XdgImportedUnstable(new Private(this), parent) { } -void XdgImportedUnstableV1::Private::setup(zxdg_imported_v1 *arg) +void XdgImportedUnstableV1::Private::setupV1(zxdg_imported_v1 *arg) { Q_ASSERT(arg); Q_ASSERT(!imported); imported.setup(arg); zxdg_imported_v1_add_listener(imported, &s_listener, this); } XdgImportedUnstableV1::~XdgImportedUnstableV1() { } -void XdgImportedUnstableV1::setup(zxdg_imported_v1 *imported) -{ - d->setup(imported); -} - -void XdgImportedUnstableV1::release() -{ - d->imported.release(); -} - -void XdgImportedUnstableV1::destroy() -{ - d->imported.destroy(); -} - -XdgImportedUnstableV1::operator zxdg_imported_v1*() { - return d->imported; -} - -XdgImportedUnstableV1::operator zxdg_imported_v1*() const { - return d->imported; -} - -bool XdgImportedUnstableV1::isValid() const -{ - return d->imported.isValid(); -} - -void XdgImportedUnstableV1::setParentOf(Surface *surface) -{ - Q_ASSERT(isValid()); - zxdg_imported_v1_set_parent_of(d->imported, *surface); -} - } } diff --git a/src/client/xdgforeign_v1.h b/src/client/xdgforeign_v1.h index eda1699..02f5afe 100644 --- a/src/client/xdgforeign_v1.h +++ b/src/client/xdgforeign_v1.h @@ -1,362 +1,153 @@ /**************************************************************************** Copyright 2017 Marco Martin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . ****************************************************************************/ #ifndef KWAYLAND_CLIENT_XDGFOREIGN_V1_H #define KWAYLAND_CLIENT_XDGFOREIGN_V1_H +#include "xdgforeign.h" #include "surface.h" #include #include struct zxdg_exporter_v1; struct zxdg_importer_v1; struct zxdg_exported_v1; struct zxdg_imported_v1; namespace KWayland { namespace Client { class EventQueue; class Surface; class XdgExportedUnstableV1; class XdgImportedUnstableV1; /** * @short Wrapper for the zxdg_exporter_v1 interface. * * This class provides a convenient wrapper for the zxdg_exporter_v1 interface. * * To use this class one needs to interact with the Registry. There are two * possible ways to create the interface: * @code * *c = registry->create(name, version); * @endcode * * This creates the and sets it up directly. As an alternative this * can also be done in a more low level way: * @code * *c = new ; * c->setup(registry->bind(name, version)); * @endcode * * The can be used as a drop-in replacement for any zxdg_exporter_v1 * pointer as it provides matching cast operators. * * @see Registry **/ -class KWAYLANDCLIENT_EXPORT XdgExporterUnstableV1 : public QObject +class KWAYLANDCLIENT_EXPORT XdgExporterUnstableV1 : public XdgExporterUnstable { Q_OBJECT public: /** * Creates a new . * Note: after constructing the it is not yet valid and one needs * to call setup. In order to get a ready to use prefer using * Registry::create. **/ explicit XdgExporterUnstableV1(QObject *parent = nullptr); virtual ~XdgExporterUnstableV1(); - /** - * Setup this to manage the @p . - * When using Registry::create there is no need to call this - * method. - **/ - void setup(zxdg_exporter_v1 *); - /** - * @returns @c true if managing a zxdg_exporter_v1. - **/ - bool isValid() const; - /** - * Releases the zxdg_exporter_v1 interface. - * After the interface has been released the instance is no - * longer valid and can be setup with another zxdg_exporter_v1 interface. - **/ - void release(); - /** - * Destroys the data held by this . - * This method is supposed to be used when the connection to the Wayland - * server goes away. If the connection is not valid anymore, it's not - * possible to call release anymore as that calls into the Wayland - * connection and the call would fail. This method cleans up the data, so - * that the instance can be deleted or set up to a new zxdg_exporter_v1 interface - * once there is a new connection available. - * - * It is suggested to connect this method to ConnectionThread::connectionDied: - * @code - * connect(connection, &ConnectionThread::connectionDied, , &::destroy); - * @endcode - * - * @see release - **/ - void destroy(); - - /** - * Sets the @p queue to use for creating objects with this . - **/ - void setEventQueue(EventQueue *queue); - /** - * @returns The event queue to use for creating objects with this . - **/ - EventQueue *eventQueue(); - - XdgExportedUnstableV1 *exportSurface(Surface *surface, QObject *parent = nullptr); - - operator zxdg_exporter_v1*(); - operator zxdg_exporter_v1*() const; - -Q_SIGNALS: - /** - * The corresponding global for this interface on the Registry got removed. - * - * This signal gets only emitted if the got created by - * Registry::create - **/ - void removed(); - private: class Private; - QScopedPointer d; }; /** * @short Wrapper for the zxdg_importer_v1 interface. * * This class provides a convenient wrapper for the zxdg_importer_v1 interface. * * To use this class one needs to interact with the Registry. There are two * possible ways to create the interface: * @code * *c = registry->create(name, version); * @endcode * * This creates the and sets it up directly. As an alternative this * can also be done in a more low level way: * @code * *c = new ; * c->setup(registry->bind(name, version)); * @endcode * * The can be used as a drop-in replacement for any zxdg_importer_v1 * pointer as it provides matching cast operators. * * @see Registry **/ -class KWAYLANDCLIENT_EXPORT XdgImporterUnstableV1 : public QObject +class KWAYLANDCLIENT_EXPORT XdgImporterUnstableV1 : public XdgImporterUnstable { Q_OBJECT public: /** * Creates a new . * Note: after constructing the it is not yet valid and one needs * to call setup. In order to get a ready to use prefer using * Registry::create. **/ explicit XdgImporterUnstableV1(QObject *parent = nullptr); virtual ~XdgImporterUnstableV1(); - /** - * Setup this to manage the @p . - * When using Registry::create there is no need to call this - * method. - **/ - void setup(zxdg_importer_v1 *); - /** - * @returns @c true if managing a zxdg_importer_v1. - **/ - bool isValid() const; - /** - * Releases the zxdg_importer_v1 interface. - * After the interface has been released the instance is no - * longer valid and can be setup with another zxdg_importer_v1 interface. - **/ - void release(); - /** - * Destroys the data held by this . - * This method is supposed to be used when the connection to the Wayland - * server goes away. If the connection is not valid anymore, it's not - * possible to call release anymore as that calls into the Wayland - * connection and the call would fail. This method cleans up the data, so - * that the instance can be deleted or set up to a new zxdg_importer_v1 interface - * once there is a new connection available. - * - * It is suggested to connect this method to ConnectionThread::connectionDied: - * @code - * connect(connection, &ConnectionThread::connectionDied, , &::destroy); - * @endcode - * - * @see release - **/ - void destroy(); - - /** - * Sets the @p queue to use for creating objects with this . - **/ - void setEventQueue(EventQueue *queue); - /** - * @returns The event queue to use for creating objects with this . - **/ - EventQueue *eventQueue(); - - XdgImportedUnstableV1 *import(const QString & handle, QObject *parent = nullptr); - - operator zxdg_importer_v1*(); - operator zxdg_importer_v1*() const; - -Q_SIGNALS: - /** - * The corresponding global for this interface on the Registry got removed. - * - * This signal gets only emitted if the got created by - * Registry::create - **/ - void removed(); - private: class Private; - QScopedPointer d; }; -class KWAYLANDCLIENT_EXPORT XdgExportedUnstableV1 : public QObject +class KWAYLANDCLIENT_EXPORT XdgExportedUnstableV1 : public XdgExportedUnstable { Q_OBJECT public: virtual ~XdgExportedUnstableV1(); - /** - * Setup this to manage the @p . - * When using ::create there is no need to call this - * method. - **/ - void setup(zxdg_exported_v1 *); - /** - * @returns @c true if managing a zxdg_exported_v1. - **/ - bool isValid() const; - /** - * Releases the zxdg_exported_v1 interface. - * After the interface has been released the instance is no - * longer valid and can be setup with another zxdg_exported_v1 interface. - **/ - void release(); - /** - * Destroys the data held by this . - * This method is supposed to be used when the connection to the Wayland - * server goes away. If the connection is not valid anymore, it's not - * possible to call release anymore as that calls into the Wayland - * connection and the call would fail. This method cleans up the data, so - * that the instance can be deleted or set up to a new zxdg_exported_v1 interface - * once there is a new connection available. - * - * It is suggested to connect this method to ConnectionThread::connectionDied: - * @code - * connect(connection, &ConnectionThread::connectionDied, , &::destroy); - * @endcode - * - * @see release - **/ - void destroy(); - - QString handle() const; - - operator zxdg_exported_v1*(); - operator zxdg_exported_v1*() const; - -Q_SIGNALS: - /** - * Emitted when the exported window is fully initialized. - * the handle will be valid at this point - **/ - void done(); - private: friend class XdgExporterUnstableV1; explicit XdgExportedUnstableV1(QObject *parent = nullptr); class Private; - QScopedPointer d; }; -class KWAYLANDCLIENT_EXPORT XdgImportedUnstableV1 : public QObject +class KWAYLANDCLIENT_EXPORT XdgImportedUnstableV1 : public XdgImportedUnstable { Q_OBJECT public: virtual ~XdgImportedUnstableV1(); - /** - * Setup this to manage the @p . - * When using ::create there is no need to call this - * method. - **/ - void setup(zxdg_imported_v1 *); - /** - * @returns @c true if managing a zxdg_imported_v1. - **/ - bool isValid() const; - /** - * Releases the zxdg_imported_v1 interface. - * After the interface has been released the instance is no - * longer valid and can be setup with another zxdg_imported_v1 interface. - **/ - void release(); - /** - * Destroys the data held by this . - * This method is supposed to be used when the connection to the Wayland - * server goes away. If the connection is not valid anymore, it's not - * possible to call release anymore as that calls into the Wayland - * connection and the call would fail. This method cleans up the data, so - * that the instance can be deleted or set up to a new zxdg_imported_v1 interface - * once there is a new connection available. - * - * It is suggested to connect this method to ConnectionThread::connectionDied: - * @code - * connect(connection, &ConnectionThread::connectionDied, , &::destroy); - * @endcode - * - * @see release - **/ - void destroy(); - - void setParentOf(Surface *surface); - - operator zxdg_imported_v1*(); - operator zxdg_imported_v1*() const; - -Q_SIGNALS: - /** - * Emitted when the imported surface is not valid anymore, - * for instance because it's no longer exported on the other end - */ - void importedDestroyed(); - private: friend class XdgImporterUnstableV1; explicit XdgImportedUnstableV1(QObject *parent = nullptr); class Private; - QScopedPointer d; }; } } #endif diff --git a/src/server/xdgforeign_v1_interface.cpp b/src/server/xdgforeign_v1_interface.cpp index 4ebf273..5eac549 100644 --- a/src/server/xdgforeign_v1_interface.cpp +++ b/src/server/xdgforeign_v1_interface.cpp @@ -1,458 +1,459 @@ /**************************************************************************** Copyright 2017 Marco Martin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . ****************************************************************************/ #include "xdgforeign_interface.h" #include "xdgforeign_v1_interface_p.h" #include "display.h" #include "global_p.h" #include "resource_p.h" #include "surface_interface_p.h" #include "wayland-xdg-foreign-unstable-v1-server-protocol.h" #include #include namespace KWayland { namespace Server { class Q_DECL_HIDDEN XdgExporterUnstableV1Interface::Private : public Global::Private { public: Private(XdgExporterUnstableV1Interface *q, Display *d, XdgForeignUnstableInterface *foreignInterface); XdgForeignUnstableInterface *foreignInterface; QHash exportedSurfaces; private: void bind(wl_client *client, uint32_t version, uint32_t id) override; static void unbind(wl_resource *resource); static Private *cast(wl_resource *r) { return reinterpret_cast(wl_resource_get_user_data(r)); } static void destroyCallback(wl_client *client, wl_resource *resource); static void exportCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface); XdgExporterUnstableV1Interface *q; static const struct zxdg_exporter_v1_interface s_interface; static const quint32 s_version; }; const quint32 XdgExporterUnstableV1Interface::Private::s_version = 1; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct zxdg_exporter_v1_interface XdgExporterUnstableV1Interface::Private::s_interface = { destroyCallback, exportCallback }; #endif XdgExporterUnstableV1Interface::XdgExporterUnstableV1Interface(Display *display, XdgForeignUnstableInterface *parent) : Global(new Private(this, display, parent), parent) { } XdgExporterUnstableV1Interface::~XdgExporterUnstableV1Interface() {} XdgExporterUnstableV1Interface::Private *XdgExporterUnstableV1Interface::d_func() const { return reinterpret_cast(d.data()); } XdgExportedUnstableV1Interface *XdgExporterUnstableV1Interface::exportedSurface(const QString &handle) { Q_D(); auto it = d->exportedSurfaces.constFind(handle); if (it != d->exportedSurfaces.constEnd()) { return it.value(); } return nullptr; } void XdgExporterUnstableV1Interface::Private::destroyCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) } void XdgExporterUnstableV1Interface::Private::exportCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface) { auto s = cast(resource); QPointer e = new XdgExportedUnstableV1Interface(s->q, surface); e->create(s->display->getConnection(client), wl_resource_get_version(resource), id); if (!e->resource()) { wl_resource_post_no_memory(resource); delete e; return; } const QString handle = QUuid::createUuid().toString(); //a surface not exported anymore connect(e.data(), &XdgExportedUnstableV1Interface::unbound, s->q, [s, handle]() { s->exportedSurfaces.remove(handle); emit s->q->surfaceUnexported(handle); }); //if the surface dies before this, this dies too connect(SurfaceInterface::get(surface), &Resource::unbound, s->q, [s, e, handle]() { if (e) { e->deleteLater(); } s->exportedSurfaces.remove(handle); emit s->q->surfaceUnexported(handle); }); s->exportedSurfaces[handle] = e; zxdg_exported_v1_send_handle(e->resource(), handle.toUtf8().constData()); emit s->q->surfaceExported(handle, e); } XdgExporterUnstableV1Interface::Private::Private(XdgExporterUnstableV1Interface *q, Display *d,XdgForeignUnstableInterface *foreignInterface) : Global::Private(d, &zxdg_exporter_v1_interface, s_version) , foreignInterface(foreignInterface) , q(q) { } void XdgExporterUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *resource = c->createResource(&zxdg_exporter_v1_interface, qMin(version, s_version), id); if (!resource) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(resource, &s_interface, this, unbind); // TODO: should we track? } void XdgExporterUnstableV1Interface::Private::unbind(wl_resource *resource) { Q_UNUSED(resource) // TODO: implement? } class Q_DECL_HIDDEN XdgImporterUnstableV1Interface::Private : public Global::Private { public: Private(XdgImporterUnstableV1Interface *q, Display *d, XdgForeignUnstableInterface *foreignInterface); XdgForeignUnstableInterface *foreignInterface; QHash importedSurfaces; //child->parent hash QHash parents; //parent->child hash QHash children; private: void bind(wl_client *client, uint32_t version, uint32_t id) override; static void unbind(wl_resource *resource); static Private *cast(wl_resource *r) { return reinterpret_cast(wl_resource_get_user_data(r)); } static void destroyCallback(wl_client *client, wl_resource *resource); static void importCallback(wl_client *client, wl_resource *resource, uint32_t id, const char * handle); XdgImporterUnstableV1Interface *q; static const struct zxdg_importer_v1_interface s_interface; static const quint32 s_version; }; const quint32 XdgImporterUnstableV1Interface::Private::s_version = 1; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct zxdg_importer_v1_interface XdgImporterUnstableV1Interface::Private::s_interface = { destroyCallback, importCallback }; #endif XdgImporterUnstableV1Interface::XdgImporterUnstableV1Interface(Display *display, XdgForeignUnstableInterface *parent) : Global(new Private(this, display, parent), parent) { } XdgImporterUnstableV1Interface::~XdgImporterUnstableV1Interface() -{} +{ +} XdgImportedUnstableV1Interface *XdgImporterUnstableV1Interface::importedSurface(const QString &handle) { Q_D(); auto it = d->importedSurfaces.constFind(handle); if (it != d->importedSurfaces.constEnd()) { return it.value(); } return nullptr; } SurfaceInterface *XdgImporterUnstableV1Interface::transientFor(SurfaceInterface *surface) { Q_D(); auto it = d->parents.constFind(surface); if (it == d->parents.constEnd()) { return nullptr; } return SurfaceInterface::get((*it)->parentResource()); } XdgImporterUnstableV1Interface::Private *XdgImporterUnstableV1Interface::d_func() const { return reinterpret_cast(d.data()); } void XdgImporterUnstableV1Interface::Private::destroyCallback(wl_client *client, wl_resource *resource) { Q_UNUSED(client) } void XdgImporterUnstableV1Interface::Private::importCallback(wl_client *client, wl_resource *resource, uint32_t id, const char * handle) { auto s = cast(resource); Q_ASSERT(s->foreignInterface); XdgExportedUnstableV1Interface *exp = s->foreignInterface->d->exporter->exportedSurface(QString::fromUtf8(handle)); if (!exp) { zxdg_imported_v1_send_destroyed(resource); return; } wl_resource *surface = exp->parentResource(); if (!surface) { zxdg_imported_v1_send_destroyed(resource); return; } QPointer imp = new XdgImportedUnstableV1Interface(s->q, surface); imp->create(s->display->getConnection(client), wl_resource_get_version(resource), id); //surface no longer exported connect(exp, &XdgExportedUnstableV1Interface::unbound, s->q, [s, imp, handle]() { //imp valid when the exported is deleted before the imported if (imp) { zxdg_imported_v1_send_destroyed(imp->resource()); imp->deleteLater(); } s->importedSurfaces.remove(QString::fromUtf8(handle)); emit s->q->surfaceUnimported(QString::fromUtf8(handle)); }); connect(imp.data(), &XdgImportedUnstableV1Interface::childChanged, s->q, [s, imp](SurfaceInterface *child) { //remove any previous association auto it = s->children.find(imp); if (it != s->children.end()) { s->parents.remove(*it); s->children.erase(it); } s->parents[child] = imp; s->children[imp] = child; SurfaceInterface *parent = SurfaceInterface::get(imp->parentResource()); emit s->q->transientChanged(child, parent); //child surface destroyed connect(child, &Resource::unbound, s->q, [s, child]() { auto it = s->parents.find(child); if (it != s->parents.end()) { s->children.remove(*it); s->parents.erase(it); emit s->q->transientChanged(nullptr, SurfaceInterface::get((*it)->parentResource())); } }); }); //surface no longer imported connect(imp.data(), &XdgImportedUnstableV1Interface::unbound, s->q, [s, handle, imp]() { s->importedSurfaces.remove(QString::fromUtf8(handle)); emit s->q->surfaceUnimported(QString::fromUtf8(handle)); auto it = s->children.find(imp); if (it != s->children.end()) { s->parents.remove(*it); s->children.erase(it); emit s->q->transientChanged(*it, nullptr); } }); if (!imp->resource()) { wl_resource_post_no_memory(resource); delete imp; return; } s->importedSurfaces[QString::fromUtf8(handle)] = imp; emit s->q->surfaceImported(QString::fromUtf8(handle), imp); } XdgImporterUnstableV1Interface::Private::Private(XdgImporterUnstableV1Interface *q, Display *d, XdgForeignUnstableInterface *foreignInterface) : Global::Private(d, &zxdg_importer_v1_interface, s_version) , foreignInterface(foreignInterface) , q(q) { } void XdgImporterUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id) { auto c = display->getConnection(client); wl_resource *resource = c->createResource(&zxdg_importer_v1_interface, qMin(version, s_version), id); if (!resource) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(resource, &s_interface, this, unbind); // TODO: should we track? } void XdgImporterUnstableV1Interface::Private::unbind(wl_resource *resource) { Q_UNUSED(resource) // TODO: implement? } class Q_DECL_HIDDEN XdgExportedUnstableV1Interface::Private : public Resource::Private { public: Private(XdgExportedUnstableV1Interface *q, XdgExporterUnstableV1Interface *c, wl_resource *parentResource); ~Private(); private: XdgExportedUnstableV1Interface *q_func() { return reinterpret_cast(q); } static const struct zxdg_exported_v1_interface s_interface; }; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct zxdg_exported_v1_interface XdgExportedUnstableV1Interface::Private::s_interface = { resourceDestroyedCallback }; #endif XdgExportedUnstableV1Interface::XdgExportedUnstableV1Interface(XdgExporterUnstableV1Interface *parent, wl_resource *parentResource) : Resource(new Private(this, parent, parentResource)) { } XdgExportedUnstableV1Interface::~XdgExportedUnstableV1Interface() {} XdgExportedUnstableV1Interface::Private *XdgExportedUnstableV1Interface::d_func() const { return reinterpret_cast(d.data()); } XdgExportedUnstableV1Interface::Private::Private(XdgExportedUnstableV1Interface *q, XdgExporterUnstableV1Interface *c, wl_resource *parentResource) : Resource::Private(q, c, parentResource, &zxdg_exported_v1_interface, &s_interface) { } XdgExportedUnstableV1Interface::Private::~Private() {} class Q_DECL_HIDDEN XdgImportedUnstableV1Interface::Private : public Resource::Private { public: Private(XdgImportedUnstableV1Interface *q, XdgImporterUnstableV1Interface *c, wl_resource *parentResource); ~Private(); QPointer parentOf; private: static void setParentOfCallback(wl_client *client, wl_resource *resource, wl_resource * surface); XdgImportedUnstableV1Interface *q_func() { return reinterpret_cast(q); } static const struct zxdg_imported_v1_interface s_interface; }; #ifndef DOXYGEN_SHOULD_SKIP_THIS const struct zxdg_imported_v1_interface XdgImportedUnstableV1Interface::Private::s_interface = { resourceDestroyedCallback, setParentOfCallback }; #endif XdgImportedUnstableV1Interface::XdgImportedUnstableV1Interface(XdgImporterUnstableV1Interface *parent, wl_resource *parentResource) : Resource(new Private(this, parent, parentResource)) { } XdgImportedUnstableV1Interface::~XdgImportedUnstableV1Interface() {} XdgImportedUnstableV1Interface::Private *XdgImportedUnstableV1Interface::d_func() const { return reinterpret_cast(d.data()); } SurfaceInterface *XdgImportedUnstableV1Interface::child() const { Q_D(); return d->parentOf.data(); } void XdgImportedUnstableV1Interface::Private::setParentOfCallback(wl_client *client, wl_resource *resource, wl_resource * surface) { auto s = cast(resource); SurfaceInterface *surf = SurfaceInterface::get(surface); if (!surf) { return; } s->parentOf = surf; emit s->q_func()->childChanged(surf); } XdgImportedUnstableV1Interface::Private::Private(XdgImportedUnstableV1Interface *q, XdgImporterUnstableV1Interface *c, wl_resource *parentResource) : Resource::Private(q, c, parentResource, &zxdg_imported_v1_interface, &s_interface) { } XdgImportedUnstableV1Interface::Private::~Private() {} } }