KWayland

event_queue.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "event_queue.h"
7 #include "connection_thread.h"
8 #include "wayland_pointer_p.h"
9 
10 #include <wayland-client.h>
11 
12 namespace KWayland
13 {
14 namespace Client
15 {
16 class Q_DECL_HIDDEN EventQueue::Private
17 {
18 public:
19  wl_display *display = nullptr;
20  WaylandPointer<wl_event_queue, wl_event_queue_destroy> queue;
21 };
22 
23 EventQueue::EventQueue(QObject *parent)
24  : QObject(parent)
25  , d(new Private)
26 {
27 }
28 
29 EventQueue::~EventQueue()
30 {
31  release();
32 }
33 
35 {
36  d->queue.release();
37  d->display = nullptr;
38 }
39 
40 void EventQueue::destroy()
41 {
42  d->queue.destroy();
43  d->display = nullptr;
44 }
45 
46 bool EventQueue::isValid()
47 {
48  return d->queue.isValid();
49 }
50 
51 void EventQueue::setup(wl_display *display)
52 {
53  Q_ASSERT(display);
54  Q_ASSERT(!d->display);
55  Q_ASSERT(!d->queue);
56  d->display = display;
57  d->queue.setup(wl_display_create_queue(display));
58 }
59 
60 void EventQueue::setup(ConnectionThread *connection)
61 {
62  setup(connection->display());
63  connect(connection, &ConnectionThread::eventsRead, this, &EventQueue::dispatch, Qt::QueuedConnection);
64 }
65 
66 void EventQueue::dispatch()
67 {
68  if (!d->display || !d->queue) {
69  return;
70  }
71  wl_display_dispatch_queue_pending(d->display, d->queue);
72  wl_display_flush(d->display);
73 }
74 
75 void EventQueue::addProxy(wl_proxy *proxy)
76 {
77  Q_ASSERT(d->queue);
78  wl_proxy_set_queue(proxy, d->queue);
79 }
80 
81 EventQueue::operator wl_event_queue *() const
82 {
83  return d->queue;
84 }
85 
86 EventQueue::operator wl_event_queue *()
87 {
88  return d->queue;
89 }
90 
91 }
92 }
virtual void release(quint64 objid)
wl_display * display()
The display this ConnectionThread is connected to.
Creates and manages the connection to a Wayland server.
QueuedConnection
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.