Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/server/kernel/private/wserver_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ class Q_DECL_HIDDEN WServerPrivate : public WObjectPrivate
{
public:
WServerPrivate(WServer *qq);
~WServerPrivate();
~WServerPrivate() override;

void init();
void stop();

void dispatchEvents();
void flush();

void initSocket(WSocket *socketServer);

W_DECLARE_PUBLIC(WServer)
Expand Down
38 changes: 26 additions & 12 deletions src/server/kernel/wserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QAbstractEventDispatcher>
#include <QSocketNotifier>
#include <QMutex>
#include <QDebug>
#include <QLoggingCategory>
#include <QProcess>
#include <QLocalServer>
#include <QLocalSocket>
Expand All @@ -38,6 +38,8 @@
QW_USE_NAMESPACE
WAYLIB_SERVER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(qLcWlrServer, "waylib.server.core")

static bool globalFilter(const wl_client *client,
const wl_global *global,
void *data) {
Expand Down Expand Up @@ -102,20 +104,20 @@ void WServerPrivate::init()
}

loop = wl_display_get_event_loop(display->handle());
int fd = wl_event_loop_get_fd(loop);

auto processWaylandEvents = [this] {
int ret = wl_event_loop_dispatch(loop, 0);
if (ret)
fprintf(stderr, "wl_event_loop_dispatch error: %d\n", ret);
wl_display_flush_clients(display->handle());
};
const int fd = wl_event_loop_get_fd(loop);
if (fd == -1) {
qCFatal(qLcWlrServer) << "Did not get the file descriptor for the event loop";
}

sockNot.reset(new QSocketNotifier(fd, QSocketNotifier::Read));
QObject::connect(sockNot.get(), &QSocketNotifier::activated, q, processWaylandEvents);
QObject::connect(sockNot.get(), &QSocketNotifier::activated, q, [this] {
dispatchEvents();
});

QAbstractEventDispatcher *dispatcher = QThread::currentThread()->eventDispatcher();
QObject::connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, q, processWaylandEvents);
QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher();
QObject::connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, q, [this] {
flush();
});

for (auto socket : std::as_const(sockets))
initSocket(socket);
Expand All @@ -142,6 +144,18 @@ void WServerPrivate::stop()
QThread::currentThread()->eventDispatcher()->disconnect(q);
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent event dispatcher retrieval in the stop() method. The init() method was changed to use QCoreApplication::eventDispatcher() (line 117), but stop() still uses QThread::currentThread()->eventDispatcher(). These should be consistent to avoid potential issues if the event dispatcher changes or if the server is accessed from different threads.

Suggested change
QThread::currentThread()->eventDispatcher()->disconnect(q);
QCoreApplication::eventDispatcher()->disconnect(q);

Copilot uses AI. Check for mistakes.
}

void WServerPrivate::dispatchEvents()
{
int ret = wl_event_loop_dispatch(loop, 0);
if (ret)
qCCritical(qLcWlrServer, "wl_event_loop_dispatch error: %d\n", ret);
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message includes a trailing newline character which is unnecessary. Qt's logging macros automatically add newlines. This is inconsistent with other qCCritical and qCFatal usage in the codebase (see line 109 and other files like wforeigntoplevelv1.cpp line 72, wcursorimage.cpp line 666) which don't include the trailing newline.

Suggested change
qCCritical(qLcWlrServer, "wl_event_loop_dispatch error: %d\n", ret);
qCCritical(qLcWlrServer, "wl_event_loop_dispatch error: %d", ret);

Copilot uses AI. Check for mistakes.
}

void WServerPrivate::flush()
{
wl_display_flush_clients(display->handle());
}

void WServerPrivate::initSocket(WSocket *socketServer)
{
bool ok = socketServer->listen(display->handle());
Expand Down
6 changes: 2 additions & 4 deletions src/server/kernel/wsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <sys/un.h>
#include <signal.h>

struct wl_event_source;

WAYLIB_SERVER_BEGIN_NAMESPACE

#define LOCK_SUFFIX ".lock"
Expand Down Expand Up @@ -656,8 +654,8 @@ WClient *WSocket::addClient(wl_client *client)
{
W_D(WSocket);

WClient *wclient = nullptr;
if ((wclient = WClient::get(client))) {
WClient *wclient = WClient::get(client);
if (wclient) {
if (wclient->socket() != this)
return nullptr;
if (d->clients.contains(wclient))
Expand Down