File: pointerconstraintstest.h

package info (click to toggle)
kwin 4%3A6.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 53,376 kB
  • sloc: cpp: 240,899; javascript: 2,225; xml: 2,096; ansic: 775; sh: 37; python: 15; makefile: 8
file content (179 lines) | stat: -rw-r--r-- 3,895 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
    SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef POINTERCONSTRAINTSTEST_H
#define POINTERCONSTRAINTSTEST_H

#include <QObject>
#include <QQuickView>

#include <xcb/xcb.h>

namespace KWayland
{
namespace Client
{

class ConnectionThread;
class Registry;
class Compositor;
class Seat;
class Pointer;
class PointerConstraints;
class LockedPointer;
class ConfinedPointer;

}
}

class MainWindow;

class Backend : public QObject
{
    Q_OBJECT
public:
    Backend(QObject *parent = nullptr)
        : QObject(parent)
    {
    }

    Q_PROPERTY(int mode READ mode CONSTANT)
    Q_PROPERTY(bool lockHint MEMBER m_lockHint NOTIFY lockHintChanged)
    Q_PROPERTY(bool errorsAllowed READ errorsAllowed WRITE setErrorsAllowed NOTIFY errorsAllowedChanged)

    virtual void init(QQuickView *view)
    {
        m_view = view;
    }
    int mode() const
    {
        return (int)m_mode;
    }

    bool lockHint() const
    {
        return m_lockHint;
    }
    bool errorsAllowed() const
    {
        return m_errorsAllowed;
    }
    void setErrorsAllowed(bool set)
    {
        if (m_errorsAllowed == set) {
            return;
        }
        m_errorsAllowed = set;
        Q_EMIT errorsAllowedChanged();
    }

    Q_INVOKABLE virtual void lockRequest(bool persistent = true, QRect region = QRect())
    {
    }
    Q_INVOKABLE virtual void unlockRequest()
    {
    }

    Q_INVOKABLE virtual void confineRequest(bool persistent = true, QRect region = QRect())
    {
    }
    Q_INVOKABLE virtual void unconfineRequest()
    {
    }
    Q_INVOKABLE virtual void hideAndConfineRequest(bool confineBeforeHide = false)
    {
    }
    Q_INVOKABLE virtual void undoHideRequest()
    {
    }

Q_SIGNALS:
    void confineChanged(bool confined);
    void lockChanged(bool locked);
    void lockHintChanged();
    void errorsAllowedChanged();
    void forceSurfaceCommit();

protected:
    enum class Mode {
        Wayland = 0,
        X = 1
    };

    QQuickView *view() const
    {
        return m_view;
    }
    void setMode(Mode set)
    {
        m_mode = set;
    }

private:
    QQuickView *m_view;
    Mode m_mode;

    bool m_lockHint = true;
    bool m_errorsAllowed = false;
};

class WaylandBackend : public Backend
{
    Q_OBJECT
public:
    WaylandBackend(QObject *parent = nullptr);

    void init(QQuickView *view) override;

    void lockRequest(bool persistent, QRect region) override;
    void unlockRequest() override;

    void confineRequest(bool persistent, QRect region) override;
    void unconfineRequest() override;

private:
    void setupRegistry(KWayland::Client::Registry *registry);

    bool isLocked();
    bool isConfined();

    void cleanupLock();
    void cleanupConfine();

    KWayland::Client::ConnectionThread *m_connectionThreadObject;
    KWayland::Client::Compositor *m_compositor = nullptr;
    KWayland::Client::Seat *m_seat = nullptr;
    KWayland::Client::Pointer *m_pointer = nullptr;
    KWayland::Client::PointerConstraints *m_pointerConstraints = nullptr;

    KWayland::Client::LockedPointer *m_lockedPointer = nullptr;
    bool m_lockedPointerPersistent = false;
    KWayland::Client::ConfinedPointer *m_confinedPointer = nullptr;
    bool m_confinedPointerPersistent = false;
};

class XBackend : public Backend
{
    Q_OBJECT
public:
    XBackend(QObject *parent = nullptr);

    void init(QQuickView *view) override;

    void lockRequest(bool persistent, QRect region) override;
    void unlockRequest() override;

    void confineRequest(bool persistent, QRect region) override;
    void unconfineRequest() override;

    void hideAndConfineRequest(bool confineBeforeHide) override;
    void undoHideRequest() override;

private:
    bool tryConfine(int &error);
    xcb_connection_t *m_xcbConn = nullptr;
};

#endif