Changeset View
Changeset View
Standalone View
Standalone View
tests/pointerconstraintstest.qml
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2018 Roman Gilg <subdiff@gmail.com> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | import QtQuick 2.10 | ||||
21 | import QtQuick.Controls 2.0 | ||||
22 | import QtQuick.Layouts 1.1 | ||||
23 | | ||||
24 | ColumnLayout { | ||||
25 | /* for margins */ | ||||
26 | ColumnLayout { | ||||
27 | id: root | ||||
28 | focus: true | ||||
29 | | ||||
30 | Layout.margins: 20 | ||||
31 | | ||||
32 | function lock() { | ||||
33 | org_kde_kwin_tests_pointerconstraints_backend.lockRequest(lockPersChck.checked, root.activRect()); | ||||
34 | } | ||||
35 | function confine() { | ||||
36 | org_kde_kwin_tests_pointerconstraints_backend.confineRequest(confPersChck.checked, root.activRect()); | ||||
37 | } | ||||
38 | function unlock() { | ||||
39 | org_kde_kwin_tests_pointerconstraints_backend.unlockRequest(); | ||||
40 | } | ||||
41 | function unconfine() { | ||||
42 | org_kde_kwin_tests_pointerconstraints_backend.unconfineRequest(); | ||||
43 | } | ||||
44 | function hideAndConfine() { | ||||
45 | org_kde_kwin_tests_pointerconstraints_backend.hideAndConfineRequest(); | ||||
46 | } | ||||
47 | function undoHideAndConfine() { | ||||
48 | org_kde_kwin_tests_pointerconstraints_backend.undoHideRequest(); | ||||
49 | } | ||||
50 | | ||||
51 | property bool waylandNative: org_kde_kwin_tests_pointerconstraints_backend.mode === 0 | ||||
52 | | ||||
53 | Keys.onPressed: { | ||||
54 | if (event.key === Qt.Key_L) { | ||||
55 | root.lock(); | ||||
56 | event.accepted = true; | ||||
57 | } else if (event.key === Qt.Key_C) { | ||||
58 | root.confine(); | ||||
59 | event.accepted = true; | ||||
60 | } else if (event.key === Qt.Key_K) { | ||||
61 | root.unlock(); | ||||
62 | event.accepted = true; | ||||
63 | } else if (event.key === Qt.Key_X) { | ||||
64 | root.unconfine(); | ||||
65 | event.accepted = true; | ||||
66 | } else if (event.key === Qt.Key_H) { | ||||
67 | root.hideAndConfine(); | ||||
68 | event.accepted = true; | ||||
69 | } else if (event.key === Qt.Key_G) { | ||||
70 | root.undoHideAndConfine(); | ||||
71 | event.accepted = true; | ||||
72 | } | ||||
73 | } | ||||
74 | | ||||
75 | function activRect() { | ||||
76 | if (fullWindowChck.checked) { | ||||
77 | return Qt.rect(0, 0, -1, -1); | ||||
78 | } | ||||
79 | return activArea.rect(); | ||||
80 | } | ||||
81 | | ||||
82 | GridLayout { | ||||
83 | columns: 2 | ||||
84 | rowSpacing: 10 | ||||
85 | columnSpacing: 10 | ||||
86 | | ||||
87 | Button { | ||||
88 | id: lockButton | ||||
89 | text: "Lock pointer" | ||||
90 | onClicked: root.lock() | ||||
91 | } | ||||
92 | CheckBox { | ||||
93 | id: lockPersChck | ||||
94 | text: "Persistent lock" | ||||
95 | checked: root.waylandNative | ||||
96 | enabled: root.waylandNative | ||||
97 | } | ||||
98 | Button { | ||||
99 | id: confButton | ||||
100 | text: "Confine pointer" | ||||
101 | onClicked: root.confine() | ||||
102 | } | ||||
103 | CheckBox { | ||||
104 | id: confPersChck | ||||
105 | text: "Persistent confine" | ||||
106 | checked: root.waylandNative | ||||
107 | enabled: root.waylandNative | ||||
108 | } | ||||
109 | Button { | ||||
110 | id: hideConfButton | ||||
111 | text: "Hide and confine pointer" | ||||
112 | onClicked: root.hideAndConfine() | ||||
113 | visible: !root.waylandNative | ||||
114 | } | ||||
115 | CheckBox { | ||||
116 | id: confBeforeHideChck | ||||
117 | text: "Confine first, then hide" | ||||
118 | checked: false | ||||
119 | visible: !root.waylandNative | ||||
120 | } | ||||
121 | } | ||||
122 | | ||||
123 | CheckBox { | ||||
124 | id: restrAreaChck | ||||
125 | text: "Restrict input area (not yet implemented)" | ||||
126 | enabled: false | ||||
127 | } | ||||
128 | CheckBox { | ||||
129 | id: fullWindowChck | ||||
130 | text: "Full window area activates" | ||||
131 | checked: !root.waylandNative | ||||
132 | enabled: root.waylandNative | ||||
133 | } | ||||
134 | CheckBox { | ||||
135 | id: errorsChck | ||||
136 | text: "Allow critical errors" | ||||
137 | checked: false | ||||
138 | enabled: root.waylandNative | ||||
139 | onCheckedChanged: org_kde_kwin_tests_pointerconstraints_backend.errorsAllowed = checked; | ||||
140 | } | ||||
141 | | ||||
142 | Item { | ||||
143 | width: childrenRect.width | ||||
144 | height: childrenRect.height | ||||
145 | | ||||
146 | Rectangle { | ||||
147 | id: activArea | ||||
148 | | ||||
149 | width: 400 | ||||
150 | height: 200 | ||||
151 | | ||||
152 | enabled: root.waylandNative && !fullWindowChck.checked | ||||
153 | | ||||
154 | function rect() { | ||||
155 | var globalPt = mapToGlobal(x, y); | ||||
156 | return Qt.rect(globalPt.x, globalPt.y, width, height); | ||||
157 | } | ||||
158 | | ||||
159 | border.color: enabled ? "black" : "lightgrey" | ||||
160 | border.width: 2 | ||||
161 | | ||||
162 | Label { | ||||
163 | anchors.top: parent.top | ||||
164 | anchors.horizontalCenter: parent.horizontalCenter | ||||
165 | text: "Activation area" | ||||
166 | } | ||||
167 | } | ||||
168 | Button { | ||||
169 | id: unconfButton | ||||
170 | anchors.horizontalCenter: activArea.horizontalCenter | ||||
171 | anchors.verticalCenter: activArea.verticalCenter | ||||
172 | | ||||
173 | text: "Unconfine pointer" | ||||
174 | onClicked: root.unconfineRequest() | ||||
175 | } | ||||
176 | } | ||||
177 | | ||||
178 | Label { | ||||
179 | text: "Lock: L / Unlock: K" | ||||
180 | } | ||||
181 | Label { | ||||
182 | text: "Confine: C / Unconfine: X" | ||||
183 | } | ||||
184 | Label { | ||||
185 | text: "Hide cursor and confine pointer: H / undo hide: G" | ||||
186 | visible: !root.waylandNative | ||||
187 | } | ||||
188 | } | ||||
189 | | ||||
190 | } |