25
25
#include < QAbstractEventDispatcher>
26
26
#include < QSocketNotifier>
27
27
#include < QMutex>
28
- #include < QDebug >
28
+ #include < QLoggingCategory >
29
29
#include < QProcess>
30
30
#include < QLocalServer>
31
31
#include < QLocalSocket>
38
38
QW_USE_NAMESPACE
39
39
WAYLIB_SERVER_BEGIN_NAMESPACE
40
40
41
+ Q_LOGGING_CATEGORY (qLcWlrServer, " waylib.server.core" )
42
+
41
43
static bool globalFilter(const wl_client *client,
42
44
const wl_global *global,
43
45
void *data) {
@@ -102,20 +104,20 @@ void WServerPrivate::init()
102
104
}
103
105
104
106
loop = wl_display_get_event_loop (display->handle ());
105
- int fd = wl_event_loop_get_fd (loop);
106
-
107
- auto processWaylandEvents = [this ] {
108
- int ret = wl_event_loop_dispatch (loop, 0 );
109
- if (ret)
110
- fprintf (stderr, " wl_event_loop_dispatch error: %d\n " , ret);
111
- wl_display_flush_clients (display->handle ());
112
- };
107
+ const int fd = wl_event_loop_get_fd (loop);
108
+ if (fd == -1 ) {
109
+ qCFatal (qLcWlrServer) << " Did not get the file descriptor for the event loop" ;
110
+ }
113
111
114
112
sockNot.reset (new QSocketNotifier (fd, QSocketNotifier::Read));
115
- QObject::connect (sockNot.get (), &QSocketNotifier::activated, q, processWaylandEvents);
113
+ QObject::connect (sockNot.get (), &QSocketNotifier::activated, q, [this ] {
114
+ dispatchEvents ();
115
+ });
116
116
117
- QAbstractEventDispatcher *dispatcher = QThread::currentThread ()->eventDispatcher ();
118
- QObject::connect (dispatcher, &QAbstractEventDispatcher::aboutToBlock, q, processWaylandEvents);
117
+ QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher ();
118
+ QObject::connect (dispatcher, &QAbstractEventDispatcher::aboutToBlock, q, [this ] {
119
+ flush ();
120
+ });
119
121
120
122
for (auto socket : std::as_const (sockets))
121
123
initSocket (socket);
@@ -142,6 +144,18 @@ void WServerPrivate::stop()
142
144
QThread::currentThread ()->eventDispatcher ()->disconnect (q);
143
145
}
144
146
147
+ void WServerPrivate::dispatchEvents ()
148
+ {
149
+ int ret = wl_event_loop_dispatch (loop, 0 );
150
+ if (ret)
151
+ qCCritical (qLcWlrServer, " wl_event_loop_dispatch error: %d\n " , ret);
152
+ }
153
+
154
+ void WServerPrivate::flush ()
155
+ {
156
+ wl_display_flush_clients (display->handle ());
157
+ }
158
+
145
159
void WServerPrivate::initSocket (WSocket *socketServer)
146
160
{
147
161
bool ok = socketServer->listen (display->handle ());
0 commit comments