From 1247a53eba2fc4d52c9adf3593e5900a97ef610f Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 19 Oct 2020 16:52:56 +0100 Subject: [PATCH] Allow accepting client connections on multiple sockets libwayland-server allows the wl_display accept client connections on more than one socket. We currently don't listen on multiple sockets, but it would be nice if Display supported such operation mode. --- .../autotests/client/test_compositor.cpp | 2 +- .../autotests/client/test_datadevice.cpp | 2 +- .../autotests/client/test_datasource.cpp | 2 +- .../autotests/client/test_drag_drop.cpp | 2 +- src/wayland/autotests/client/test_error.cpp | 2 +- .../autotests/client/test_fake_input.cpp | 2 +- src/wayland/autotests/client/test_idle.cpp | 2 +- .../client/test_plasma_virtual_desktop.cpp | 2 +- .../client/test_plasma_window_model.cpp | 2 +- .../autotests/client/test_plasmashell.cpp | 2 +- .../client/test_pointer_constraints.cpp | 2 +- .../autotests/client/test_selection.cpp | 2 +- .../client/test_server_side_decoration.cpp | 2 +- .../test_server_side_decoration_palette.cpp | 2 +- src/wayland/autotests/client/test_shadow.cpp | 2 +- .../autotests/client/test_shm_pool.cpp | 2 +- .../autotests/client/test_text_input_v2.cpp | 2 +- .../autotests/client/test_wayland_appmenu.cpp | 2 +- .../autotests/client/test_wayland_blur.cpp | 2 +- .../client/test_wayland_contrast.cpp | 2 +- .../autotests/client/test_wayland_filter.cpp | 2 +- .../autotests/client/test_wayland_output.cpp | 2 +- .../client/test_wayland_outputdevice.cpp | 2 +- .../client/test_wayland_outputmanagement.cpp | 2 +- .../autotests/client/test_wayland_region.cpp | 2 +- .../autotests/client/test_wayland_seat.cpp | 2 +- .../autotests/client/test_wayland_slide.cpp | 2 +- .../client/test_wayland_subcompositor.cpp | 2 +- .../client/test_wayland_subsurface.cpp | 2 +- .../autotests/client/test_wayland_surface.cpp | 2 +- .../client/test_wayland_windowmanagement.cpp | 2 +- .../autotests/client/test_xdg_decoration.cpp | 2 +- .../autotests/client/test_xdg_foreign.cpp | 2 +- .../autotests/client/test_xdg_output.cpp | 2 +- .../autotests/client/test_xdg_shell.cpp | 2 +- .../server/test_datacontrol_interface.cpp | 4 +- src/wayland/autotests/server/test_display.cpp | 35 ++-- .../server/test_inputmethod_interface.cpp | 2 +- ...keyboard_shortcuts_inhibitor_interface.cpp | 2 +- .../server/test_layershellv1_interface.cpp | 2 +- .../server/test_no_xdg_runtime_dir.cpp | 4 +- .../autotests/server/test_screencast.cpp | 2 +- src/wayland/autotests/server/test_seat.cpp | 12 +- .../server/test_tablet_interface.cpp | 2 +- .../server/test_textinputv3_interface.cpp | 2 +- .../server/test_viewporter_interface.cpp | 2 +- src/wayland/display.cpp | 162 +++++++----------- src/wayland/display.h | 63 ++++--- 48 files changed, 161 insertions(+), 203 deletions(-) diff --git a/src/wayland/autotests/client/test_compositor.cpp b/src/wayland/autotests/client/test_compositor.cpp index 4ba1e44a30..ce83972ef3 100644 --- a/src/wayland/autotests/client/test_compositor.cpp +++ b/src/wayland/autotests/client/test_compositor.cpp @@ -53,7 +53,7 @@ void TestCompositor::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_datadevice.cpp b/src/wayland/autotests/client/test_datadevice.cpp index f3f09922ad..50c4ac133a 100644 --- a/src/wayland/autotests/client/test_datadevice.cpp +++ b/src/wayland/autotests/client/test_datadevice.cpp @@ -67,7 +67,7 @@ void TestDataDevice::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_datasource.cpp b/src/wayland/autotests/client/test_datasource.cpp index fde3f2d272..7b58ec3466 100644 --- a/src/wayland/autotests/client/test_datasource.cpp +++ b/src/wayland/autotests/client/test_datasource.cpp @@ -49,7 +49,7 @@ void TestDataSource::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_drag_drop.cpp b/src/wayland/autotests/client/test_drag_drop.cpp index ef509f9a5e..b627d9d4b0 100644 --- a/src/wayland/autotests/client/test_drag_drop.cpp +++ b/src/wayland/autotests/client/test_drag_drop.cpp @@ -67,7 +67,7 @@ void TestDragAndDrop::init() using namespace KWayland::Client; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_error.cpp b/src/wayland/autotests/client/test_error.cpp index 6b769fde2f..7482017406 100644 --- a/src/wayland/autotests/client/test_error.cpp +++ b/src/wayland/autotests/client/test_error.cpp @@ -50,7 +50,7 @@ void ErrorTest::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_fake_input.cpp b/src/wayland/autotests/client/test_fake_input.cpp index 89993bc13d..a624851fe1 100644 --- a/src/wayland/autotests/client/test_fake_input.cpp +++ b/src/wayland/autotests/client/test_fake_input.cpp @@ -57,7 +57,7 @@ void FakeInputTest::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_idle.cpp b/src/wayland/autotests/client/test_idle.cpp index ae373faac9..41b11c60b1 100644 --- a/src/wayland/autotests/client/test_idle.cpp +++ b/src/wayland/autotests/client/test_idle.cpp @@ -49,7 +49,7 @@ void IdleTest::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_plasma_virtual_desktop.cpp b/src/wayland/autotests/client/test_plasma_virtual_desktop.cpp index 5f583b3112..442028b0dc 100644 --- a/src/wayland/autotests/client/test_plasma_virtual_desktop.cpp +++ b/src/wayland/autotests/client/test_plasma_virtual_desktop.cpp @@ -77,7 +77,7 @@ void TestVirtualDesktop::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_plasma_window_model.cpp b/src/wayland/autotests/client/test_plasma_window_model.cpp index e8bfb8f3c0..8e361e96ab 100644 --- a/src/wayland/autotests/client/test_plasma_window_model.cpp +++ b/src/wayland/autotests/client/test_plasma_window_model.cpp @@ -96,7 +96,7 @@ void PlasmaWindowModelTest::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_plasmashell.cpp b/src/wayland/autotests/client/test_plasmashell.cpp index af2dab559b..4fbc26eb32 100644 --- a/src/wayland/autotests/client/test_plasmashell.cpp +++ b/src/wayland/autotests/client/test_plasmashell.cpp @@ -60,7 +60,7 @@ void TestPlasmaShell::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_pointer_constraints.cpp b/src/wayland/autotests/client/test_pointer_constraints.cpp index f6bca1b462..8d44fd07b5 100644 --- a/src/wayland/autotests/client/test_pointer_constraints.cpp +++ b/src/wayland/autotests/client/test_pointer_constraints.cpp @@ -63,7 +63,7 @@ void TestPointerConstraints::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_selection.cpp b/src/wayland/autotests/client/test_selection.cpp index 347023b3e6..d87fbade12 100644 --- a/src/wayland/autotests/client/test_selection.cpp +++ b/src/wayland/autotests/client/test_selection.cpp @@ -63,7 +63,7 @@ void SelectionTest::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_server_side_decoration.cpp b/src/wayland/autotests/client/test_server_side_decoration.cpp index 84175605f0..eaab93172d 100644 --- a/src/wayland/autotests/client/test_server_side_decoration.cpp +++ b/src/wayland/autotests/client/test_server_side_decoration.cpp @@ -58,7 +58,7 @@ void TestServerSideDecoration::init() using namespace KWayland::Client; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_server_side_decoration_palette.cpp b/src/wayland/autotests/client/test_server_side_decoration_palette.cpp index 1c2231ce20..18694475fb 100644 --- a/src/wayland/autotests/client/test_server_side_decoration_palette.cpp +++ b/src/wayland/autotests/client/test_server_side_decoration_palette.cpp @@ -61,7 +61,7 @@ void TestServerSideDecorationPalette::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_shadow.cpp b/src/wayland/autotests/client/test_shadow.cpp index 79b32b7af9..46e695d977 100644 --- a/src/wayland/autotests/client/test_shadow.cpp +++ b/src/wayland/autotests/client/test_shadow.cpp @@ -52,7 +52,7 @@ void ShadowTest::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_shm_pool.cpp b/src/wayland/autotests/client/test_shm_pool.cpp index 003c67bc4e..b1e9594246 100644 --- a/src/wayland/autotests/client/test_shm_pool.cpp +++ b/src/wayland/autotests/client/test_shm_pool.cpp @@ -60,7 +60,7 @@ void TestShmPool::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_text_input_v2.cpp b/src/wayland/autotests/client/test_text_input_v2.cpp index e58c50c1aa..462a42a6e8 100644 --- a/src/wayland/autotests/client/test_text_input_v2.cpp +++ b/src/wayland/autotests/client/test_text_input_v2.cpp @@ -71,7 +71,7 @@ void TextInputTest::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_wayland_appmenu.cpp b/src/wayland/autotests/client/test_wayland_appmenu.cpp index c17797f2df..e1292f8d30 100644 --- a/src/wayland/autotests/client/test_wayland_appmenu.cpp +++ b/src/wayland/autotests/client/test_wayland_appmenu.cpp @@ -64,7 +64,7 @@ void TestAppmenu::init() qRegisterMetaType(); delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_blur.cpp b/src/wayland/autotests/client/test_wayland_blur.cpp index 6c92efc506..dc5308bf42 100644 --- a/src/wayland/autotests/client/test_wayland_blur.cpp +++ b/src/wayland/autotests/client/test_wayland_blur.cpp @@ -61,7 +61,7 @@ void TestBlur::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_contrast.cpp b/src/wayland/autotests/client/test_wayland_contrast.cpp index 1d5b08f3fd..4c51b83197 100644 --- a/src/wayland/autotests/client/test_wayland_contrast.cpp +++ b/src/wayland/autotests/client/test_wayland_contrast.cpp @@ -64,7 +64,7 @@ void TestContrast::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_filter.cpp b/src/wayland/autotests/client/test_wayland_filter.cpp index 97f5fe108e..89f179d585 100644 --- a/src/wayland/autotests/client/test_wayland_filter.cpp +++ b/src/wayland/autotests/client/test_wayland_filter.cpp @@ -77,7 +77,7 @@ void TestFilter::init() using namespace KWaylandServer; delete m_display; m_display = new TestDisplay(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_output.cpp b/src/wayland/autotests/client/test_wayland_output.cpp index ece8c733d4..66ec67c6ed 100644 --- a/src/wayland/autotests/client/test_wayland_output.cpp +++ b/src/wayland/autotests/client/test_wayland_output.cpp @@ -66,7 +66,7 @@ void TestWaylandOutput::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_outputdevice.cpp b/src/wayland/autotests/client/test_wayland_outputdevice.cpp index ec92c08e1a..7766ad5cb7 100644 --- a/src/wayland/autotests/client/test_wayland_outputdevice.cpp +++ b/src/wayland/autotests/client/test_wayland_outputdevice.cpp @@ -78,7 +78,7 @@ void TestWaylandOutputDevice::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_outputmanagement.cpp b/src/wayland/autotests/client/test_wayland_outputmanagement.cpp index 97a4da8837..cca854e406 100644 --- a/src/wayland/autotests/client/test_wayland_outputmanagement.cpp +++ b/src/wayland/autotests/client/test_wayland_outputmanagement.cpp @@ -91,7 +91,7 @@ void TestWaylandOutputManagement::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_region.cpp b/src/wayland/autotests/client/test_wayland_region.cpp index b500de5550..973165ac4d 100644 --- a/src/wayland/autotests/client/test_wayland_region.cpp +++ b/src/wayland/autotests/client/test_wayland_region.cpp @@ -59,7 +59,7 @@ void TestRegion::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_seat.cpp b/src/wayland/autotests/client/test_wayland_seat.cpp index 5ffd1c38f9..d569d0e186 100644 --- a/src/wayland/autotests/client/test_wayland_seat.cpp +++ b/src/wayland/autotests/client/test_wayland_seat.cpp @@ -123,7 +123,7 @@ void TestWaylandSeat::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_wayland_slide.cpp b/src/wayland/autotests/client/test_wayland_slide.cpp index a41266c01d..50a8223658 100644 --- a/src/wayland/autotests/client/test_wayland_slide.cpp +++ b/src/wayland/autotests/client/test_wayland_slide.cpp @@ -61,7 +61,7 @@ void TestSlide::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_subcompositor.cpp b/src/wayland/autotests/client/test_wayland_subcompositor.cpp index 4195d00927..12b86a6d6d 100644 --- a/src/wayland/autotests/client/test_wayland_subcompositor.cpp +++ b/src/wayland/autotests/client/test_wayland_subcompositor.cpp @@ -52,7 +52,7 @@ void TestSubCompositor::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_wayland_subsurface.cpp b/src/wayland/autotests/client/test_wayland_subsurface.cpp index d61e491b5f..28e95de2a6 100644 --- a/src/wayland/autotests/client/test_wayland_subsurface.cpp +++ b/src/wayland/autotests/client/test_wayland_subsurface.cpp @@ -84,7 +84,7 @@ void TestSubSurface::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_wayland_surface.cpp b/src/wayland/autotests/client/test_wayland_surface.cpp index 225c9dfc1d..7e331f8f9f 100644 --- a/src/wayland/autotests/client/test_wayland_surface.cpp +++ b/src/wayland/autotests/client/test_wayland_surface.cpp @@ -83,7 +83,7 @@ void TestWaylandSurface::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/client/test_wayland_windowmanagement.cpp b/src/wayland/autotests/client/test_wayland_windowmanagement.cpp index 348d58f4c8..8b3731cc71 100644 --- a/src/wayland/autotests/client/test_wayland_windowmanagement.cpp +++ b/src/wayland/autotests/client/test_wayland_windowmanagement.cpp @@ -95,7 +95,7 @@ void TestWindowManagement::init() qRegisterMetaType("ShowingDesktopState"); delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_xdg_decoration.cpp b/src/wayland/autotests/client/test_xdg_decoration.cpp index 5de1ccbeac..a00c31c7ba 100644 --- a/src/wayland/autotests/client/test_xdg_decoration.cpp +++ b/src/wayland/autotests/client/test_xdg_decoration.cpp @@ -63,7 +63,7 @@ void TestXdgDecoration::init() delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_xdg_foreign.cpp b/src/wayland/autotests/client/test_xdg_foreign.cpp index 0ddc4582a2..7ad42a1707 100644 --- a/src/wayland/autotests/client/test_xdg_foreign.cpp +++ b/src/wayland/autotests/client/test_xdg_foreign.cpp @@ -82,7 +82,7 @@ void TestForeign::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_xdg_output.cpp b/src/wayland/autotests/client/test_xdg_output.cpp index 095459014f..3008b02e21 100644 --- a/src/wayland/autotests/client/test_xdg_output.cpp +++ b/src/wayland/autotests/client/test_xdg_output.cpp @@ -54,7 +54,7 @@ void TestXdgOutput::init() using namespace KWaylandServer; delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/client/test_xdg_shell.cpp b/src/wayland/autotests/client/test_xdg_shell.cpp index f3a9887af4..db88d2e69a 100644 --- a/src/wayland/autotests/client/test_xdg_shell.cpp +++ b/src/wayland/autotests/client/test_xdg_shell.cpp @@ -89,7 +89,7 @@ void XdgShellTest::init() { delete m_display; m_display = new Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); m_display->createShm(); diff --git a/src/wayland/autotests/server/test_datacontrol_interface.cpp b/src/wayland/autotests/server/test_datacontrol_interface.cpp index a001d0aa6f..9670d8d753 100644 --- a/src/wayland/autotests/server/test_datacontrol_interface.cpp +++ b/src/wayland/autotests/server/test_datacontrol_interface.cpp @@ -158,8 +158,8 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-datacontrol-tes void DataControlInterfaceTest::init() { - m_display = new Display; - m_display->setSocketName(s_socketName); + m_display = new Display(); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/server/test_display.cpp b/src/wayland/autotests/server/test_display.cpp index 970e8f413e..945de6a092 100644 --- a/src/wayland/autotests/server/test_display.cpp +++ b/src/wayland/autotests/server/test_display.cpp @@ -35,17 +35,16 @@ private Q_SLOTS: void TestWaylandServerDisplay::testSocketName() { Display display; - QSignalSpy changedSpy(&display, SIGNAL(socketNameChanged(QString))); + QSignalSpy changedSpy(&display, &Display::socketNamesChanged); QVERIFY(changedSpy.isValid()); - QCOMPARE(display.socketName(), QStringLiteral("wayland-0")); + QCOMPARE(display.socketNames(), QStringList()); const QString testSName = QStringLiteral("fooBar"); - display.setSocketName(testSName); - QCOMPARE(display.socketName(), testSName); + display.addSocketName(testSName); + QCOMPARE(display.socketNames(), QStringList { testSName }); QCOMPARE(changedSpy.count(), 1); - QCOMPARE(changedSpy.first().first().toString(), testSName); // changing to same name again should not emit signal - display.setSocketName(testSName); + display.addSocketName(testSName); QCOMPARE(changedSpy.count(), 1); } @@ -59,7 +58,7 @@ void TestWaylandServerDisplay::testStartStop() QScopedPointer display(new Display); QSignalSpy runningSpy(display.data(), SIGNAL(runningChanged(bool))); QVERIFY(runningSpy.isValid()); - display->setSocketName(testSocketName); + display->addSocketName(testSocketName); QVERIFY(!display->isRunning()); display->start(); // QVERIFY(runningSpy.wait()); @@ -75,7 +74,7 @@ void TestWaylandServerDisplay::testStartStop() void TestWaylandServerDisplay::testAddRemoveOutput() { Display display; - display.setSocketName(QStringLiteral("kwin-wayland-server-display-test-output-0")); + display.addSocketName(QStringLiteral("kwin-wayland-server-display-test-output-0")); display.start(); OutputInterface *output = display.createOutput(); @@ -98,7 +97,7 @@ void TestWaylandServerDisplay::testAddRemoveOutput() void TestWaylandServerDisplay::testClientConnection() { Display display; - display.setSocketName(QStringLiteral("kwin-wayland-server-display-test-client-connection")); + display.addSocketName(QStringLiteral("kwin-wayland-server-display-test-client-connection")); display.start(); QSignalSpy connectedSpy(&display, SIGNAL(clientConnected(KWaylandServer::ClientConnection*))); QVERIFY(connectedSpy.isValid()); @@ -174,7 +173,7 @@ void TestWaylandServerDisplay::testClientConnection() void TestWaylandServerDisplay::testConnectNoSocket() { Display display; - display.start(Display::StartMode::ConnectClientsOnly); + display.start(); QVERIFY(display.isRunning()); // let's try connecting a client @@ -191,7 +190,7 @@ void TestWaylandServerDisplay::testConnectNoSocket() void TestWaylandServerDisplay::testOutputManagement() { Display display; - display.setSocketName("kwayland-test-0"); + display.addSocketName("kwayland-test-0"); display.start(); auto kwin = display.createOutputManagement(this); kwin->create(); @@ -205,20 +204,20 @@ void TestWaylandServerDisplay::testAutoSocketName() QVERIFY(qputenv("XDG_RUNTIME_DIR", runtimeDir.path().toUtf8())); Display display0; - display0.setAutomaticSocketNaming(true); - QSignalSpy socketNameChangedSpy0(&display0, SIGNAL(socketNameChanged(QString))); + QSignalSpy socketNameChangedSpy0(&display0, &Display::socketNamesChanged); + QVERIFY(socketNameChangedSpy0.isValid()); + QVERIFY(display0.addSocketName()); display0.start(); QVERIFY(display0.isRunning()); - QCOMPARE(socketNameChangedSpy0.count(), 0); - QCOMPARE(display0.socketName(), QStringLiteral("wayland-0")); + QCOMPARE(socketNameChangedSpy0.count(), 1); Display display1; - display1.setAutomaticSocketNaming(true); - QSignalSpy socketNameChangedSpy1(&display1, SIGNAL(socketNameChanged(QString))); + QSignalSpy socketNameChangedSpy1(&display1, &Display::socketNamesChanged); + QVERIFY(socketNameChangedSpy1.isValid()); + QVERIFY(display1.addSocketName()); display1.start(); QVERIFY(display1.isRunning()); QCOMPARE(socketNameChangedSpy1.count(), 1); - QCOMPARE(display1.socketName(), QStringLiteral("wayland-1")); } diff --git a/src/wayland/autotests/server/test_inputmethod_interface.cpp b/src/wayland/autotests/server/test_inputmethod_interface.cpp index af19606b55..051ce820f9 100644 --- a/src/wayland/autotests/server/test_inputmethod_interface.cpp +++ b/src/wayland/autotests/server/test_inputmethod_interface.cpp @@ -172,7 +172,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-inputmet void TestInputMethodInterface::initTestCase() { - m_display.setSocketName(s_socketName); + m_display.addSocketName(s_socketName); m_display.start(); QVERIFY(m_display.isRunning()); diff --git a/src/wayland/autotests/server/test_keyboard_shortcuts_inhibitor_interface.cpp b/src/wayland/autotests/server/test_keyboard_shortcuts_inhibitor_interface.cpp index 292633ff44..5d422bf8dd 100644 --- a/src/wayland/autotests/server/test_keyboard_shortcuts_inhibitor_interface.cpp +++ b/src/wayland/autotests/server/test_keyboard_shortcuts_inhibitor_interface.cpp @@ -95,7 +95,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-keyboard void TestKeyboardShortcutsInhibitorInterface::initTestCase() { - m_display.setSocketName(s_socketName); + m_display.addSocketName(s_socketName); m_display.start(); QVERIFY(m_display.isRunning()); diff --git a/src/wayland/autotests/server/test_layershellv1_interface.cpp b/src/wayland/autotests/server/test_layershellv1_interface.cpp index a5097b7c30..60abfca017 100644 --- a/src/wayland/autotests/server/test_layershellv1_interface.cpp +++ b/src/wayland/autotests/server/test_layershellv1_interface.cpp @@ -102,7 +102,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-layer-sh void TestLayerShellV1Interface::initTestCase() { - m_display.setSocketName(s_socketName); + m_display.addSocketName(s_socketName); m_display.start(); QVERIFY(m_display.isRunning()); diff --git a/src/wayland/autotests/server/test_no_xdg_runtime_dir.cpp b/src/wayland/autotests/server/test_no_xdg_runtime_dir.cpp index 1592c4a8a8..ee0f44be81 100644 --- a/src/wayland/autotests/server/test_no_xdg_runtime_dir.cpp +++ b/src/wayland/autotests/server/test_no_xdg_runtime_dir.cpp @@ -31,10 +31,8 @@ void NoXdgRuntimeDirTest::testCreate() Display display; QSignalSpy runningSpy(&display, &Display::runningChanged); QVERIFY(runningSpy.isValid()); - display.setSocketName(testSocketName); - QVERIFY(!display.isRunning()); + QVERIFY(!display.addSocketName(testSocketName)); display.start(); - QVERIFY(!display.isRunning()); // call into dispatchEvents should not crash display.dispatchEvents(); diff --git a/src/wayland/autotests/server/test_screencast.cpp b/src/wayland/autotests/server/test_screencast.cpp index 0291118962..07f0246fd6 100644 --- a/src/wayland/autotests/server/test_screencast.cpp +++ b/src/wayland/autotests/server/test_screencast.cpp @@ -93,7 +93,7 @@ void TestScreencastV1Interface::initTestCase() { delete m_display; m_display = new KWaylandServer::Display(this); - m_display->setSocketName(s_socketName); + m_display->addSocketName(s_socketName); m_display->start(); QVERIFY(m_display->isRunning()); diff --git a/src/wayland/autotests/server/test_seat.cpp b/src/wayland/autotests/server/test_seat.cpp index bb70cceb4a..032db4bdd4 100644 --- a/src/wayland/autotests/server/test_seat.cpp +++ b/src/wayland/autotests/server/test_seat.cpp @@ -30,7 +30,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-seat-tes void TestWaylandServerSeat::testCapabilities() { Display display; - display.setSocketName(s_socketName); + display.addSocketName(s_socketName); display.start(); SeatInterface *seat = display.createSeat(); QVERIFY(!seat->hasKeyboard()); @@ -80,7 +80,7 @@ void TestWaylandServerSeat::testCapabilities() void TestWaylandServerSeat::testName() { Display display; - display.setSocketName(s_socketName); + display.addSocketName(s_socketName); display.start(); SeatInterface *seat = display.createSeat(); QCOMPARE(seat->name(), QString()); @@ -99,7 +99,7 @@ void TestWaylandServerSeat::testName() void TestWaylandServerSeat::testPointerButton() { Display display; - display.setSocketName(s_socketName); + display.addSocketName(s_socketName); display.start(); SeatInterface *seat = display.createSeat(); PointerInterface *pointer = seat->focusedPointer(); @@ -129,7 +129,7 @@ void TestWaylandServerSeat::testPointerButton() void TestWaylandServerSeat::testPointerPos() { Display display; - display.setSocketName(s_socketName); + display.addSocketName(s_socketName); display.start(); SeatInterface *seat = display.createSeat(); QSignalSpy seatPosSpy(seat, SIGNAL(pointerPosChanged(QPointF))); @@ -157,7 +157,7 @@ void TestWaylandServerSeat::testPointerPos() void TestWaylandServerSeat::testRepeatInfo() { Display display; - display.setSocketName(s_socketName); + display.addSocketName(s_socketName); display.start(); SeatInterface *seat = display.createSeat(); seat->setHasKeyboard(true); @@ -175,7 +175,7 @@ void TestWaylandServerSeat::testRepeatInfo() void TestWaylandServerSeat::testMultiple() { Display display; - display.setSocketName(s_socketName); + display.addSocketName(s_socketName); display.start(); QVERIFY(display.seats().isEmpty()); SeatInterface *seat1 = display.createSeat(); diff --git a/src/wayland/autotests/server/test_tablet_interface.cpp b/src/wayland/autotests/server/test_tablet_interface.cpp index 2b7c69f4fd..274674edbe 100644 --- a/src/wayland/autotests/server/test_tablet_interface.cpp +++ b/src/wayland/autotests/server/test_tablet_interface.cpp @@ -137,7 +137,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-tablet-t void TestTabletInterface::initTestCase() { - m_display.setSocketName(s_socketName); + m_display.addSocketName(s_socketName); m_display.start(); QVERIFY(m_display.isRunning()); diff --git a/src/wayland/autotests/server/test_textinputv3_interface.cpp b/src/wayland/autotests/server/test_textinputv3_interface.cpp index 2e547f5344..2ec89f07f4 100644 --- a/src/wayland/autotests/server/test_textinputv3_interface.cpp +++ b/src/wayland/autotests/server/test_textinputv3_interface.cpp @@ -115,7 +115,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-text-inp void TestTextInputV3Interface::initTestCase() { - m_display.setSocketName(s_socketName); + m_display.addSocketName(s_socketName); m_display.start(); QVERIFY(m_display.isRunning()); diff --git a/src/wayland/autotests/server/test_viewporter_interface.cpp b/src/wayland/autotests/server/test_viewporter_interface.cpp index 8cc7d45e4d..9f5fe24393 100644 --- a/src/wayland/autotests/server/test_viewporter_interface.cpp +++ b/src/wayland/autotests/server/test_viewporter_interface.cpp @@ -58,7 +58,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-viewport void TestViewporterInterface::initTestCase() { - m_display.setSocketName(s_socketName); + m_display.addSocketName(s_socketName); m_display.start(); QVERIFY(m_display.isRunning()); diff --git a/src/wayland/display.cpp b/src/wayland/display.cpp index 6ed9b2d363..7bf6e4b70e 100644 --- a/src/wayland/display.cpp +++ b/src/wayland/display.cpp @@ -66,20 +66,18 @@ class Display::Private { public: Private(Display *q); - void flush(); - void dispatch(); - void setRunning(bool running); - void installSocketNotifier(); + void registerSocketName(const QString &socketName); + + QSocketNotifier *socketNotifier = nullptr; wl_display *display = nullptr; wl_event_loop *loop = nullptr; - QString socketName = QStringLiteral("wayland-0"); bool running = false; - bool automaticSocketNaming = false; QList outputs; QList outputdevices; QVector seats; QVector clients; + QStringList socketNames; EGLDisplay eglDisplay = EGL_NO_DISPLAY; private: @@ -91,20 +89,10 @@ Display::Private::Private(Display *q) { } -void Display::Private::installSocketNotifier() +void Display::Private::registerSocketName(const QString &socketName) { - if (!QThread::currentThread()) { - return; - } - int fd = wl_event_loop_get_fd(loop); - if (fd == -1) { - qCWarning(KWAYLAND_SERVER) << "Did not get the file descriptor for the event loop"; - return; - } - QSocketNotifier *m_notifier = new QSocketNotifier(fd, QSocketNotifier::Read, q); - QObject::connect(m_notifier, &QSocketNotifier::activated, q, [this] { dispatch(); } ); - QObject::connect(QThread::currentThread()->eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, q, [this] { flush(); }); - setRunning(true); + socketNames.append(socketName); + emit q->socketNamesChanged(); } Display::Display(QObject *parent) @@ -112,6 +100,7 @@ Display::Display(QObject *parent) , d(new Private(this)) { d->display = wl_display_create(); + d->loop = wl_display_get_event_loop(d->display); } Display::~Display() @@ -120,96 +109,73 @@ Display::~Display() wl_display_destroy(d->display); } -void Display::Private::flush() +bool Display::addSocketFileDescriptor(int fileDescriptor) { - if (!display || !loop) { - return; + if (wl_display_add_socket_fd(d->display, fileDescriptor)) { + qCWarning(KWAYLAND_SERVER, "Failed to add %d fd to display", fileDescriptor); + return false; } - wl_display_flush_clients(display); + return true; } -void Display::Private::dispatch() +bool Display::addSocketName(const QString &name) { - if (!display || !loop) { - return; + if (name.isEmpty()) { + const char *socket = wl_display_add_socket_auto(d->display); + if (!socket) { + qCWarning(KWAYLAND_SERVER, "Failed to find a free display socket"); + return false; + } + d->registerSocketName(QString::fromUtf8(socket)); + } else { + if (wl_display_add_socket(d->display, qPrintable(name))) { + qCWarning(KWAYLAND_SERVER, "Failed to add %s socket to display", qPrintable(name)); + return false; + } + d->registerSocketName(name); } - if (wl_event_loop_dispatch(loop, 0) != 0) { + return true; +} + +QStringList Display::socketNames() const +{ + return d->socketNames; +} + +bool Display::start() +{ + if (d->running) { + return true; + } + + const int fileDescriptor = wl_event_loop_get_fd(d->loop); + if (fileDescriptor == -1) { + qCWarning(KWAYLAND_SERVER) << "Did not get the file descriptor for the event loop"; + return false; + } + + d->socketNotifier = new QSocketNotifier(fileDescriptor, QSocketNotifier::Read, this); + connect(d->socketNotifier, &QSocketNotifier::activated, this, &Display::dispatchEvents); + + QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher(); + connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, this, &Display::flush); + + d->running = true; + emit runningChanged(true); + + return true; +} + +void Display::dispatchEvents() +{ + if (wl_event_loop_dispatch(d->loop, 0) != 0) { qCWarning(KWAYLAND_SERVER) << "Error on dispatching Wayland event loop"; } } -void Display::setSocketName(const QString &name) +void Display::flush() { - if (d->socketName == name) { - return; - } - d->socketName = name; - emit socketNameChanged(d->socketName); -} - -QString Display::socketName() const -{ - return d->socketName; -} - -void Display::setAutomaticSocketNaming(bool automaticSocketNaming) -{ - if (d->automaticSocketNaming == automaticSocketNaming) { - return; - } - d->automaticSocketNaming = automaticSocketNaming; - emit automaticSocketNamingChanged(automaticSocketNaming); -} - -bool Display::automaticSocketNaming() const -{ - return d->automaticSocketNaming; -} - -bool Display::start(StartMode mode) -{ - Q_ASSERT(!d->running); - if (mode == StartMode::ConnectToSocket) { - if (d->automaticSocketNaming) { - const char *socket = wl_display_add_socket_auto(d->display); - if (socket == nullptr) { - qCWarning(KWAYLAND_SERVER) << "Failed to create Wayland socket"; - return false; - } - - const QString newEffectiveSocketName = QString::fromUtf8(socket); - if (d->socketName != newEffectiveSocketName) { - d->socketName = newEffectiveSocketName; - emit socketNameChanged(d->socketName); - } - } else if (wl_display_add_socket(d->display, qPrintable(d->socketName)) != 0) { - qCWarning(KWAYLAND_SERVER) << "Failed to create Wayland socket"; - return false; - } - } - - d->loop = wl_display_get_event_loop(d->display); - d->installSocketNotifier(); - - return d->running; -} - -void Display::dispatchEvents(int msecTimeout) -{ - Q_ASSERT(d->display); - if (d->running) { - d->dispatch(); - } else if (d->loop) { - wl_event_loop_dispatch(d->loop, msecTimeout); - wl_display_flush_clients(d->display); - } -} - -void Display::Private::setRunning(bool r) -{ - Q_ASSERT(running != r); - running = r; - emit q->runningChanged(running); + wl_display_flush_clients(d->display); } OutputInterface *Display::createOutput(QObject *parent) diff --git a/src/wayland/display.h b/src/wayland/display.h index 5284950555..52d9a717c6 100644 --- a/src/wayland/display.h +++ b/src/wayland/display.h @@ -87,54 +87,47 @@ class LayerShellV1Interface; class KWAYLANDSERVER_EXPORT Display : public QObject { Q_OBJECT - Q_PROPERTY(QString socketName READ socketName WRITE setSocketName NOTIFY socketNameChanged) - Q_PROPERTY(bool automaticSocketNaming READ automaticSocketNaming WRITE setAutomaticSocketNaming NOTIFY automaticSocketNamingChanged) Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged) public: explicit Display(QObject *parent = nullptr); virtual ~Display(); /** - * Sets the basename of the socket to @p name. If @p name is empty, it will use - * wl_display_add_socket_auto to get a free socket with a filename "wayland-%d". - **/ - void setSocketName(const QString &name); - QString socketName() const; + * Adds a socket with the given @p fileDescriptor to the Wayland display. This function + * returns @c true if the socket has been added successfully; otherwise returns @c false. + * + * The compositor can call this function even after the display has been started. + * + * @see start() + */ + bool addSocketFileDescriptor(int fileDescriptor); + /** + * Adds a UNIX socket with the specified @p name to the Wayland display. This function + * returns @c true if the socket has been added successfully; otherwise returns @c false. + * + * If the specified socket name @p name is empty, the display will pick a free socket with + * a filename "wayland-%d". + * + * The compositor can call this function even after the display has been started. + * + * @see start() + */ + bool addSocketName(const QString &name = QString()); /** - * If automaticSocketNaming is true, the manually set socketName is ignored - * and it will use wl_display_add_socket_auto on start to get a free socket with - * a filename "wayland-%d" instead. The effective socket is written into socketName. - * @since 5.55 - **/ - void setAutomaticSocketNaming(bool automaticSocketNaming); - bool automaticSocketNaming() const; + * Returns the list of socket names that the display listens for client connections. + */ + QStringList socketNames() const; quint32 serial(); quint32 nextSerial(); - /** - * How to setup the server connection. - * @li ConnectToSocket: the server will open the socket identified by the socket name - * @li ConnectClientsOnly: only connections through createClient are possible - **/ - enum class StartMode { - ConnectToSocket, - ConnectClientsOnly - }; /** * Start accepting client connections. If the display has started successfully, this * function returns @c true; otherwise @c false is returned. */ - bool start(StartMode mode = StartMode::ConnectToSocket); - /** - * Dispatches pending events in a blocking way. May only be used if the Display is - * created and started before the QCoreApplication is created. Once the QCoreApplication - * is created and the event loop is started this method delegates to the normal dispatch - * handling. - * @see startLoop - **/ - void dispatchEvents(int msecTimeout = -1); + bool start(); + void dispatchEvents(); /** * Create a client for the given file descriptor. @@ -374,9 +367,11 @@ public: **/ void *eglDisplay() const; +private Q_SLOTS: + void flush(); + Q_SIGNALS: - void socketNameChanged(const QString&); - void automaticSocketNamingChanged(bool); + void socketNamesChanged(); void runningChanged(bool); void clientConnected(KWaylandServer::ClientConnection*); void clientDisconnected(KWaylandServer::ClientConnection*);