1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> |
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 | |
34 | void EventQueue::release() |
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(pointer: wl_display_create_queue(display)); |
58 | } |
59 | |
60 | void EventQueue::setup(ConnectionThread *connection) |
61 | { |
62 | setup(connection->display()); |
63 | connect(sender: connection, signal: &ConnectionThread::eventsRead, context: this, slot: &EventQueue::dispatch, type: Qt::QueuedConnection); |
64 | } |
65 | |
66 | void EventQueue::dispatch() |
67 | { |
68 | if (!d->display || !d->queue) { |
69 | return; |
70 | } |
71 | wl_display_dispatch_queue_pending(display: d->display, queue: d->queue); |
72 | wl_display_flush(display: d->display); |
73 | } |
74 | |
75 | void EventQueue::addProxy(wl_proxy *proxy) |
76 | { |
77 | Q_ASSERT(d->queue); |
78 | wl_proxy_set_queue(proxy, queue: 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 | } |
93 | |
94 | #include "moc_event_queue.cpp" |
95 |