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 
17 class Q_DECL_HIDDEN EventQueue::Private
18 {
19 public:
20  wl_display *display = nullptr;
21  WaylandPointer<wl_event_queue, wl_event_queue_destroy> queue;
22 };
23 
24 EventQueue::EventQueue(QObject *parent)
25  : QObject(parent)
26  , d(new Private)
27 {
28 }
29 
30 EventQueue::~EventQueue()
31 {
32  release();
33 }
34 
35 void EventQueue::release()
36 {
37  d->queue.release();
38  d->display = nullptr;
39 }
40 
41 void EventQueue::destroy()
42 {
43  d->queue.destroy();
44  d->display = nullptr;
45 }
46 
47 bool EventQueue::isValid()
48 {
49  return d->queue.isValid();
50 }
51 
52 void EventQueue::setup(wl_display *display)
53 {
54  Q_ASSERT(display);
55  Q_ASSERT(!d->display);
56  Q_ASSERT(!d->queue);
57  d->display = display;
58  d->queue.setup(wl_display_create_queue(display));
59 }
60 
61 void EventQueue::setup(ConnectionThread *connection)
62 {
63  setup(connection->display());
64  connect(connection, &ConnectionThread::eventsRead, this, &EventQueue::dispatch, Qt::QueuedConnection);
65 }
66 
67 void EventQueue::dispatch()
68 {
69  if (!d->display || !d->queue) {
70  return;
71  }
72  wl_display_dispatch_queue_pending(d->display, d->queue);
73  wl_display_flush(d->display);
74 }
75 
76 void EventQueue::addProxy(wl_proxy *proxy)
77 {
78  Q_ASSERT(d->queue);
79  wl_proxy_set_queue(proxy, d->queue);
80 }
81 
82 EventQueue::operator wl_event_queue*() const
83 {
84  return d->queue;
85 }
86 
87 EventQueue::operator wl_event_queue*()
88 {
89  return d->queue;
90 }
91 
92 }
93 }
Creates and manages the connection to a Wayland server.
Display * display()
Definition: global.cpp:79
QueuedConnection
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
wl_display * display()
The display this ConnectionThread is connected to.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.