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

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

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
Loading