KWin
Loading...
Searching...
No Matches
pointerconstraintstest.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#ifndef POINTERCONSTRAINTSTEST_H
7#define POINTERCONSTRAINTSTEST_H
8
9#include <QObject>
10#include <QQuickView>
11
12#include <xcb/xcb.h>
13
14namespace KWayland
15{
16namespace Client
17{
18
19class ConnectionThread;
20class Registry;
21class Compositor;
22class Seat;
23class Pointer;
25class LockedPointer;
26class ConfinedPointer;
27
28}
29}
30
31class MainWindow;
32
33class Backend : public QObject
34{
35 Q_OBJECT
36public:
37 Backend(QObject *parent = nullptr)
38 : QObject(parent)
39 {
40 }
41
42 Q_PROPERTY(int mode READ mode CONSTANT)
43 Q_PROPERTY(bool lockHint MEMBER m_lockHint NOTIFY lockHintChanged)
45
46 virtual void init(QQuickView *view)
47 {
48 m_view = view;
49 }
50 int mode() const
51 {
52 return (int)m_mode;
53 }
54
55 bool lockHint() const
56 {
57 return m_lockHint;
58 }
59 bool errorsAllowed() const
60 {
61 return m_errorsAllowed;
62 }
63 void setErrorsAllowed(bool set)
64 {
65 if (m_errorsAllowed == set) {
66 return;
67 }
68 m_errorsAllowed = set;
69 Q_EMIT errorsAllowedChanged();
70 }
71
72 Q_INVOKABLE virtual void lockRequest(bool persistent = true, QRect region = QRect())
73 {
74 }
75 Q_INVOKABLE virtual void unlockRequest()
76 {
77 }
78
79 Q_INVOKABLE virtual void confineRequest(bool persistent = true, QRect region = QRect())
80 {
81 }
82 Q_INVOKABLE virtual void unconfineRequest()
83 {
84 }
85 Q_INVOKABLE virtual void hideAndConfineRequest(bool confineBeforeHide = false)
86 {
87 }
88 Q_INVOKABLE virtual void undoHideRequest()
89 {
90 }
91
92Q_SIGNALS:
93 void confineChanged(bool confined);
94 void lockChanged(bool locked);
98
99protected:
100 enum class Mode {
101 Wayland = 0,
102 X = 1
103 };
104
105 QQuickView *view() const
106 {
107 return m_view;
108 }
109 void setMode(Mode set)
110 {
111 m_mode = set;
112 }
113
114private:
115 QQuickView *m_view;
116 Mode m_mode;
117
118 bool m_lockHint = true;
119 bool m_errorsAllowed = false;
120};
121
123{
124 Q_OBJECT
125public:
126 WaylandBackend(QObject *parent = nullptr);
127
128 void init(QQuickView *view) override;
129
130 void lockRequest(bool persistent, QRect region) override;
131 void unlockRequest() override;
132
133 void confineRequest(bool persistent, QRect region) override;
134 void unconfineRequest() override;
135
136private:
137 void setupRegistry(KWayland::Client::Registry *registry);
138
139 bool isLocked();
140 bool isConfined();
141
142 void cleanupLock();
143 void cleanupConfine();
144
145 KWayland::Client::ConnectionThread *m_connectionThreadObject;
146 KWayland::Client::Compositor *m_compositor = nullptr;
147 KWayland::Client::Seat *m_seat = nullptr;
148 KWayland::Client::Pointer *m_pointer = nullptr;
149 KWayland::Client::PointerConstraints *m_pointerConstraints = nullptr;
150
151 KWayland::Client::LockedPointer *m_lockedPointer = nullptr;
152 bool m_lockedPointerPersistent = false;
153 KWayland::Client::ConfinedPointer *m_confinedPointer = nullptr;
154 bool m_confinedPointerPersistent = false;
155};
156
157class XBackend : public Backend
158{
159 Q_OBJECT
160public:
161 XBackend(QObject *parent = nullptr);
162
163 void init(QQuickView *view) override;
164
165 void lockRequest(bool persistent, QRect region) override;
166 void unlockRequest() override;
167
168 void confineRequest(bool persistent, QRect region) override;
169 void unconfineRequest() override;
170
171 void hideAndConfineRequest(bool confineBeforeHide) override;
172 void undoHideRequest() override;
173
174private:
175 bool tryConfine(int &error);
176 xcb_connection_t *m_xcbConn = nullptr;
177};
178
179#endif
bool lockHint() const
QQuickView * view() const
bool errorsAllowed() const
virtual Q_INVOKABLE void unconfineRequest()
void lockChanged(bool locked)
virtual Q_INVOKABLE void hideAndConfineRequest(bool confineBeforeHide=false)
void errorsAllowedChanged()
Backend(QObject *parent=nullptr)
void forceSurfaceCommit()
virtual Q_INVOKABLE void confineRequest(bool persistent=true, QRect region=QRect())
void lockHintChanged()
virtual void init(QQuickView *view)
void setErrorsAllowed(bool set)
virtual Q_INVOKABLE void unlockRequest()
void confineChanged(bool confined)
void setMode(Mode set)
int mode() const
virtual Q_INVOKABLE void lockRequest(bool persistent=true, QRect region=QRect())
virtual Q_INVOKABLE void undoHideRequest()
The Client class encapsulates a window decoration frame.
void confineRequest(bool persistent, QRect region) override
void init(QQuickView *view) override
void unlockRequest() override
WaylandBackend(QObject *parent=nullptr)
void unconfineRequest() override
void lockRequest(bool persistent, QRect region) override
void undoHideRequest() override
void unlockRequest() override
void confineRequest(bool persistent, QRect region) override
void init(QQuickView *view) override
void unconfineRequest() override
XBackend(QObject *parent=nullptr)
void hideAndConfineRequest(bool confineBeforeHide) override
void lockRequest(bool persistent, QRect region) override