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.
This commit is contained in:
Vlad Zahorodnii 2020-10-19 16:52:56 +01:00
parent e12bfaa53c
commit 1247a53eba
48 changed files with 161 additions and 203 deletions

View file

@ -53,7 +53,7 @@ void TestCompositor::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -67,7 +67,7 @@ void TestDataDevice::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -49,7 +49,7 @@ void TestDataSource::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -67,7 +67,7 @@ void TestDragAndDrop::init()
using namespace KWayland::Client; using namespace KWayland::Client;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -50,7 +50,7 @@ void ErrorTest::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -57,7 +57,7 @@ void FakeInputTest::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -49,7 +49,7 @@ void IdleTest::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -77,7 +77,7 @@ void TestVirtualDesktop::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -96,7 +96,7 @@ void PlasmaWindowModelTest::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -60,7 +60,7 @@ void TestPlasmaShell::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -63,7 +63,7 @@ void TestPointerConstraints::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -63,7 +63,7 @@ void SelectionTest::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -58,7 +58,7 @@ void TestServerSideDecoration::init()
using namespace KWayland::Client; using namespace KWayland::Client;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -61,7 +61,7 @@ void TestServerSideDecorationPalette::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -52,7 +52,7 @@ void ShadowTest::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -60,7 +60,7 @@ void TestShmPool::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -71,7 +71,7 @@ void TextInputTest::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -64,7 +64,7 @@ void TestAppmenu::init()
qRegisterMetaType<AppMenuInterface::InterfaceAddress>(); qRegisterMetaType<AppMenuInterface::InterfaceAddress>();
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -61,7 +61,7 @@ void TestBlur::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -64,7 +64,7 @@ void TestContrast::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -77,7 +77,7 @@ void TestFilter::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new TestDisplay(this); m_display = new TestDisplay(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -66,7 +66,7 @@ void TestWaylandOutput::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -78,7 +78,7 @@ void TestWaylandOutputDevice::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -91,7 +91,7 @@ void TestWaylandOutputManagement::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -59,7 +59,7 @@ void TestRegion::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -123,7 +123,7 @@ void TestWaylandSeat::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -61,7 +61,7 @@ void TestSlide::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -52,7 +52,7 @@ void TestSubCompositor::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -84,7 +84,7 @@ void TestSubSurface::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -83,7 +83,7 @@ void TestWaylandSurface::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -95,7 +95,7 @@ void TestWindowManagement::init()
qRegisterMetaType<KWaylandServer::PlasmaWindowManagementInterface::ShowingDesktopState>("ShowingDesktopState"); qRegisterMetaType<KWaylandServer::PlasmaWindowManagementInterface::ShowingDesktopState>("ShowingDesktopState");
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -63,7 +63,7 @@ void TestXdgDecoration::init()
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -82,7 +82,7 @@ void TestForeign::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -54,7 +54,7 @@ void TestXdgOutput::init()
using namespace KWaylandServer; using namespace KWaylandServer;
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -89,7 +89,7 @@ void XdgShellTest::init()
{ {
delete m_display; delete m_display;
m_display = new Display(this); m_display = new Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());
m_display->createShm(); m_display->createShm();

View file

@ -158,8 +158,8 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-datacontrol-tes
void DataControlInterfaceTest::init() void DataControlInterfaceTest::init()
{ {
m_display = new Display; m_display = new Display();
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -35,17 +35,16 @@ private Q_SLOTS:
void TestWaylandServerDisplay::testSocketName() void TestWaylandServerDisplay::testSocketName()
{ {
Display display; Display display;
QSignalSpy changedSpy(&display, SIGNAL(socketNameChanged(QString))); QSignalSpy changedSpy(&display, &Display::socketNamesChanged);
QVERIFY(changedSpy.isValid()); QVERIFY(changedSpy.isValid());
QCOMPARE(display.socketName(), QStringLiteral("wayland-0")); QCOMPARE(display.socketNames(), QStringList());
const QString testSName = QStringLiteral("fooBar"); const QString testSName = QStringLiteral("fooBar");
display.setSocketName(testSName); display.addSocketName(testSName);
QCOMPARE(display.socketName(), testSName); QCOMPARE(display.socketNames(), QStringList { testSName });
QCOMPARE(changedSpy.count(), 1); QCOMPARE(changedSpy.count(), 1);
QCOMPARE(changedSpy.first().first().toString(), testSName);
// changing to same name again should not emit signal // changing to same name again should not emit signal
display.setSocketName(testSName); display.addSocketName(testSName);
QCOMPARE(changedSpy.count(), 1); QCOMPARE(changedSpy.count(), 1);
} }
@ -59,7 +58,7 @@ void TestWaylandServerDisplay::testStartStop()
QScopedPointer<Display> display(new Display); QScopedPointer<Display> display(new Display);
QSignalSpy runningSpy(display.data(), SIGNAL(runningChanged(bool))); QSignalSpy runningSpy(display.data(), SIGNAL(runningChanged(bool)));
QVERIFY(runningSpy.isValid()); QVERIFY(runningSpy.isValid());
display->setSocketName(testSocketName); display->addSocketName(testSocketName);
QVERIFY(!display->isRunning()); QVERIFY(!display->isRunning());
display->start(); display->start();
// QVERIFY(runningSpy.wait()); // QVERIFY(runningSpy.wait());
@ -75,7 +74,7 @@ void TestWaylandServerDisplay::testStartStop()
void TestWaylandServerDisplay::testAddRemoveOutput() void TestWaylandServerDisplay::testAddRemoveOutput()
{ {
Display display; Display display;
display.setSocketName(QStringLiteral("kwin-wayland-server-display-test-output-0")); display.addSocketName(QStringLiteral("kwin-wayland-server-display-test-output-0"));
display.start(); display.start();
OutputInterface *output = display.createOutput(); OutputInterface *output = display.createOutput();
@ -98,7 +97,7 @@ void TestWaylandServerDisplay::testAddRemoveOutput()
void TestWaylandServerDisplay::testClientConnection() void TestWaylandServerDisplay::testClientConnection()
{ {
Display display; Display display;
display.setSocketName(QStringLiteral("kwin-wayland-server-display-test-client-connection")); display.addSocketName(QStringLiteral("kwin-wayland-server-display-test-client-connection"));
display.start(); display.start();
QSignalSpy connectedSpy(&display, SIGNAL(clientConnected(KWaylandServer::ClientConnection*))); QSignalSpy connectedSpy(&display, SIGNAL(clientConnected(KWaylandServer::ClientConnection*)));
QVERIFY(connectedSpy.isValid()); QVERIFY(connectedSpy.isValid());
@ -174,7 +173,7 @@ void TestWaylandServerDisplay::testClientConnection()
void TestWaylandServerDisplay::testConnectNoSocket() void TestWaylandServerDisplay::testConnectNoSocket()
{ {
Display display; Display display;
display.start(Display::StartMode::ConnectClientsOnly); display.start();
QVERIFY(display.isRunning()); QVERIFY(display.isRunning());
// let's try connecting a client // let's try connecting a client
@ -191,7 +190,7 @@ void TestWaylandServerDisplay::testConnectNoSocket()
void TestWaylandServerDisplay::testOutputManagement() void TestWaylandServerDisplay::testOutputManagement()
{ {
Display display; Display display;
display.setSocketName("kwayland-test-0"); display.addSocketName("kwayland-test-0");
display.start(); display.start();
auto kwin = display.createOutputManagement(this); auto kwin = display.createOutputManagement(this);
kwin->create(); kwin->create();
@ -205,20 +204,20 @@ void TestWaylandServerDisplay::testAutoSocketName()
QVERIFY(qputenv("XDG_RUNTIME_DIR", runtimeDir.path().toUtf8())); QVERIFY(qputenv("XDG_RUNTIME_DIR", runtimeDir.path().toUtf8()));
Display display0; Display display0;
display0.setAutomaticSocketNaming(true); QSignalSpy socketNameChangedSpy0(&display0, &Display::socketNamesChanged);
QSignalSpy socketNameChangedSpy0(&display0, SIGNAL(socketNameChanged(QString))); QVERIFY(socketNameChangedSpy0.isValid());
QVERIFY(display0.addSocketName());
display0.start(); display0.start();
QVERIFY(display0.isRunning()); QVERIFY(display0.isRunning());
QCOMPARE(socketNameChangedSpy0.count(), 0); QCOMPARE(socketNameChangedSpy0.count(), 1);
QCOMPARE(display0.socketName(), QStringLiteral("wayland-0"));
Display display1; Display display1;
display1.setAutomaticSocketNaming(true); QSignalSpy socketNameChangedSpy1(&display1, &Display::socketNamesChanged);
QSignalSpy socketNameChangedSpy1(&display1, SIGNAL(socketNameChanged(QString))); QVERIFY(socketNameChangedSpy1.isValid());
QVERIFY(display1.addSocketName());
display1.start(); display1.start();
QVERIFY(display1.isRunning()); QVERIFY(display1.isRunning());
QCOMPARE(socketNameChangedSpy1.count(), 1); QCOMPARE(socketNameChangedSpy1.count(), 1);
QCOMPARE(display1.socketName(), QStringLiteral("wayland-1"));
} }

View file

@ -172,7 +172,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-inputmet
void TestInputMethodInterface::initTestCase() void TestInputMethodInterface::initTestCase()
{ {
m_display.setSocketName(s_socketName); m_display.addSocketName(s_socketName);
m_display.start(); m_display.start();
QVERIFY(m_display.isRunning()); QVERIFY(m_display.isRunning());

View file

@ -95,7 +95,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-keyboard
void TestKeyboardShortcutsInhibitorInterface::initTestCase() void TestKeyboardShortcutsInhibitorInterface::initTestCase()
{ {
m_display.setSocketName(s_socketName); m_display.addSocketName(s_socketName);
m_display.start(); m_display.start();
QVERIFY(m_display.isRunning()); QVERIFY(m_display.isRunning());

View file

@ -102,7 +102,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-layer-sh
void TestLayerShellV1Interface::initTestCase() void TestLayerShellV1Interface::initTestCase()
{ {
m_display.setSocketName(s_socketName); m_display.addSocketName(s_socketName);
m_display.start(); m_display.start();
QVERIFY(m_display.isRunning()); QVERIFY(m_display.isRunning());

View file

@ -31,10 +31,8 @@ void NoXdgRuntimeDirTest::testCreate()
Display display; Display display;
QSignalSpy runningSpy(&display, &Display::runningChanged); QSignalSpy runningSpy(&display, &Display::runningChanged);
QVERIFY(runningSpy.isValid()); QVERIFY(runningSpy.isValid());
display.setSocketName(testSocketName); QVERIFY(!display.addSocketName(testSocketName));
QVERIFY(!display.isRunning());
display.start(); display.start();
QVERIFY(!display.isRunning());
// call into dispatchEvents should not crash // call into dispatchEvents should not crash
display.dispatchEvents(); display.dispatchEvents();

View file

@ -93,7 +93,7 @@ void TestScreencastV1Interface::initTestCase()
{ {
delete m_display; delete m_display;
m_display = new KWaylandServer::Display(this); m_display = new KWaylandServer::Display(this);
m_display->setSocketName(s_socketName); m_display->addSocketName(s_socketName);
m_display->start(); m_display->start();
QVERIFY(m_display->isRunning()); QVERIFY(m_display->isRunning());

View file

@ -30,7 +30,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-seat-tes
void TestWaylandServerSeat::testCapabilities() void TestWaylandServerSeat::testCapabilities()
{ {
Display display; Display display;
display.setSocketName(s_socketName); display.addSocketName(s_socketName);
display.start(); display.start();
SeatInterface *seat = display.createSeat(); SeatInterface *seat = display.createSeat();
QVERIFY(!seat->hasKeyboard()); QVERIFY(!seat->hasKeyboard());
@ -80,7 +80,7 @@ void TestWaylandServerSeat::testCapabilities()
void TestWaylandServerSeat::testName() void TestWaylandServerSeat::testName()
{ {
Display display; Display display;
display.setSocketName(s_socketName); display.addSocketName(s_socketName);
display.start(); display.start();
SeatInterface *seat = display.createSeat(); SeatInterface *seat = display.createSeat();
QCOMPARE(seat->name(), QString()); QCOMPARE(seat->name(), QString());
@ -99,7 +99,7 @@ void TestWaylandServerSeat::testName()
void TestWaylandServerSeat::testPointerButton() void TestWaylandServerSeat::testPointerButton()
{ {
Display display; Display display;
display.setSocketName(s_socketName); display.addSocketName(s_socketName);
display.start(); display.start();
SeatInterface *seat = display.createSeat(); SeatInterface *seat = display.createSeat();
PointerInterface *pointer = seat->focusedPointer(); PointerInterface *pointer = seat->focusedPointer();
@ -129,7 +129,7 @@ void TestWaylandServerSeat::testPointerButton()
void TestWaylandServerSeat::testPointerPos() void TestWaylandServerSeat::testPointerPos()
{ {
Display display; Display display;
display.setSocketName(s_socketName); display.addSocketName(s_socketName);
display.start(); display.start();
SeatInterface *seat = display.createSeat(); SeatInterface *seat = display.createSeat();
QSignalSpy seatPosSpy(seat, SIGNAL(pointerPosChanged(QPointF))); QSignalSpy seatPosSpy(seat, SIGNAL(pointerPosChanged(QPointF)));
@ -157,7 +157,7 @@ void TestWaylandServerSeat::testPointerPos()
void TestWaylandServerSeat::testRepeatInfo() void TestWaylandServerSeat::testRepeatInfo()
{ {
Display display; Display display;
display.setSocketName(s_socketName); display.addSocketName(s_socketName);
display.start(); display.start();
SeatInterface *seat = display.createSeat(); SeatInterface *seat = display.createSeat();
seat->setHasKeyboard(true); seat->setHasKeyboard(true);
@ -175,7 +175,7 @@ void TestWaylandServerSeat::testRepeatInfo()
void TestWaylandServerSeat::testMultiple() void TestWaylandServerSeat::testMultiple()
{ {
Display display; Display display;
display.setSocketName(s_socketName); display.addSocketName(s_socketName);
display.start(); display.start();
QVERIFY(display.seats().isEmpty()); QVERIFY(display.seats().isEmpty());
SeatInterface *seat1 = display.createSeat(); SeatInterface *seat1 = display.createSeat();

View file

@ -137,7 +137,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-tablet-t
void TestTabletInterface::initTestCase() void TestTabletInterface::initTestCase()
{ {
m_display.setSocketName(s_socketName); m_display.addSocketName(s_socketName);
m_display.start(); m_display.start();
QVERIFY(m_display.isRunning()); QVERIFY(m_display.isRunning());

View file

@ -115,7 +115,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-text-inp
void TestTextInputV3Interface::initTestCase() void TestTextInputV3Interface::initTestCase()
{ {
m_display.setSocketName(s_socketName); m_display.addSocketName(s_socketName);
m_display.start(); m_display.start();
QVERIFY(m_display.isRunning()); QVERIFY(m_display.isRunning());

View file

@ -58,7 +58,7 @@ static const QString s_socketName = QStringLiteral("kwin-wayland-server-viewport
void TestViewporterInterface::initTestCase() void TestViewporterInterface::initTestCase()
{ {
m_display.setSocketName(s_socketName); m_display.addSocketName(s_socketName);
m_display.start(); m_display.start();
QVERIFY(m_display.isRunning()); QVERIFY(m_display.isRunning());

View file

@ -66,20 +66,18 @@ class Display::Private
{ {
public: public:
Private(Display *q); 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_display *display = nullptr;
wl_event_loop *loop = nullptr; wl_event_loop *loop = nullptr;
QString socketName = QStringLiteral("wayland-0");
bool running = false; bool running = false;
bool automaticSocketNaming = false;
QList<OutputInterface*> outputs; QList<OutputInterface*> outputs;
QList<OutputDeviceInterface*> outputdevices; QList<OutputDeviceInterface*> outputdevices;
QVector<SeatInterface*> seats; QVector<SeatInterface*> seats;
QVector<ClientConnection*> clients; QVector<ClientConnection*> clients;
QStringList socketNames;
EGLDisplay eglDisplay = EGL_NO_DISPLAY; EGLDisplay eglDisplay = EGL_NO_DISPLAY;
private: private:
@ -91,20 +89,10 @@ Display::Private::Private(Display *q)
{ {
} }
void Display::Private::installSocketNotifier() void Display::Private::registerSocketName(const QString &socketName)
{ {
if (!QThread::currentThread()) { socketNames.append(socketName);
return; emit q->socketNamesChanged();
}
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);
} }
Display::Display(QObject *parent) Display::Display(QObject *parent)
@ -112,6 +100,7 @@ Display::Display(QObject *parent)
, d(new Private(this)) , d(new Private(this))
{ {
d->display = wl_display_create(); d->display = wl_display_create();
d->loop = wl_display_get_event_loop(d->display);
} }
Display::~Display() Display::~Display()
@ -120,96 +109,73 @@ Display::~Display()
wl_display_destroy(d->display); wl_display_destroy(d->display);
} }
void Display::Private::flush() bool Display::addSocketFileDescriptor(int fileDescriptor)
{ {
if (!display || !loop) { if (wl_display_add_socket_fd(d->display, fileDescriptor)) {
return; 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) { if (name.isEmpty()) {
return; const char *socket = wl_display_add_socket_auto(d->display);
if (!socket) {
qCWarning(KWAYLAND_SERVER, "Failed to find a free display socket");
return false;
} }
if (wl_event_loop_dispatch(loop, 0) != 0) { 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);
}
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"; 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); wl_display_flush_clients(d->display);
}
}
void Display::Private::setRunning(bool r)
{
Q_ASSERT(running != r);
running = r;
emit q->runningChanged(running);
} }
OutputInterface *Display::createOutput(QObject *parent) OutputInterface *Display::createOutput(QObject *parent)

View file

@ -87,54 +87,47 @@ class LayerShellV1Interface;
class KWAYLANDSERVER_EXPORT Display : public QObject class KWAYLANDSERVER_EXPORT Display : public QObject
{ {
Q_OBJECT 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) Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged)
public: public:
explicit Display(QObject *parent = nullptr); explicit Display(QObject *parent = nullptr);
virtual ~Display(); virtual ~Display();
/** /**
* Sets the basename of the socket to @p name. If @p name is empty, it will use * Adds a socket with the given @p fileDescriptor to the Wayland display. This function
* wl_display_add_socket_auto to get a free socket with a filename "wayland-%d". * returns @c true if the socket has been added successfully; otherwise returns @c false.
**/ *
void setSocketName(const QString &name); * The compositor can call this function even after the display has been started.
QString socketName() const; *
* @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 * Returns the list of socket names that the display listens for client connections.
* 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. QStringList socketNames() const;
* @since 5.55
**/
void setAutomaticSocketNaming(bool automaticSocketNaming);
bool automaticSocketNaming() const;
quint32 serial(); quint32 serial();
quint32 nextSerial(); 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 * Start accepting client connections. If the display has started successfully, this
* function returns @c true; otherwise @c false is returned. * function returns @c true; otherwise @c false is returned.
*/ */
bool start(StartMode mode = StartMode::ConnectToSocket); bool start();
/** void dispatchEvents();
* 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);
/** /**
* Create a client for the given file descriptor. * Create a client for the given file descriptor.
@ -374,9 +367,11 @@ public:
**/ **/
void *eglDisplay() const; void *eglDisplay() const;
private Q_SLOTS:
void flush();
Q_SIGNALS: Q_SIGNALS:
void socketNameChanged(const QString&); void socketNamesChanged();
void automaticSocketNamingChanged(bool);
void runningChanged(bool); void runningChanged(bool);
void clientConnected(KWaylandServer::ClientConnection*); void clientConnected(KWaylandServer::ClientConnection*);
void clientDisconnected(KWaylandServer::ClientConnection*); void clientDisconnected(KWaylandServer::ClientConnection*);