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;
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());

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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());

View file

@ -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();

View file

@ -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());

View file

@ -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();

View file

@ -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();

View file

@ -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());

View file

@ -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());

View file

@ -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();

View file

@ -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());

View file

@ -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();

View file

@ -64,7 +64,7 @@ void TestAppmenu::init()
qRegisterMetaType<AppMenuInterface::InterfaceAddress>();
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());

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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();

View file

@ -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());

View file

@ -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());

View file

@ -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();

View file

@ -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();

View file

@ -95,7 +95,7 @@ void TestWindowManagement::init()
qRegisterMetaType<KWaylandServer::PlasmaWindowManagementInterface::ShowingDesktopState>("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());

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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();

View file

@ -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());

View file

@ -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> 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"));
}

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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();

View file

@ -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());

View file

@ -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();

View file

@ -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());

View file

@ -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());

View file

@ -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());

View file

@ -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<OutputInterface*> outputs;
QList<OutputDeviceInterface*> outputdevices;
QVector<SeatInterface*> seats;
QVector<ClientConnection*> 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)

View file

@ -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*);