Warning, /plasma/kwin/tests/pointerconstraintstest.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 import QtQuick
0007 import QtQuick.Controls
0008 import QtQuick.Layouts
0009 
0010 ColumnLayout {
0011 /* for margins */
0012 ColumnLayout {
0013     id: root
0014     focus: true
0015 
0016     Layout.margins: 20
0017 
0018     function lock() {
0019         org_kde_kwin_tests_pointerconstraints_backend.lockRequest(lockPersChck.checked, root.activRect());
0020     }
0021     function confine() {
0022         org_kde_kwin_tests_pointerconstraints_backend.confineRequest(confPersChck.checked, root.activRect());
0023     }
0024     function unlock() {
0025         org_kde_kwin_tests_pointerconstraints_backend.unlockRequest();
0026     }
0027     function unconfine() {
0028         org_kde_kwin_tests_pointerconstraints_backend.unconfineRequest();
0029     }
0030     function hideAndConfine() {
0031         org_kde_kwin_tests_pointerconstraints_backend.hideAndConfineRequest();
0032     }
0033     function undoHideAndConfine() {
0034         org_kde_kwin_tests_pointerconstraints_backend.undoHideRequest();
0035     }
0036 
0037     property bool waylandNative: org_kde_kwin_tests_pointerconstraints_backend.mode === 0
0038 
0039     Keys.onPressed: {
0040         if (event.key === Qt.Key_L) {
0041             root.lock();
0042             event.accepted = true;
0043         } else if (event.key === Qt.Key_C) {
0044             root.confine();
0045             event.accepted = true;
0046         } else if (event.key === Qt.Key_K) {
0047             root.unlock();
0048             event.accepted = true;
0049         } else if (event.key === Qt.Key_X) {
0050             root.unconfine();
0051             event.accepted = true;
0052         } else if (event.key === Qt.Key_H) {
0053             root.hideAndConfine();
0054             event.accepted = true;
0055         } else if (event.key === Qt.Key_G) {
0056             root.undoHideAndConfine();
0057             event.accepted = true;
0058         }
0059     }
0060 
0061     function activRect() {
0062         if (fullWindowChck.checked) {
0063             return Qt.rect(0, 0, -1, -1);
0064         }
0065         return activArea.rect();
0066     }
0067 
0068     Connections {
0069         target: org_kde_kwin_tests_pointerconstraints_backend
0070         function onForceSurfaceCommit() {
0071             forceCommitRect.visible = true
0072         }
0073     }
0074 
0075     Rectangle {
0076         id: forceCommitRect
0077         width: 10
0078         height: 10
0079         color: "red"
0080         visible: false
0081 
0082         Timer {
0083             interval: 500
0084             running: forceCommitRect.visible
0085             repeat: false
0086             onTriggered: forceCommitRect.visible = false;
0087         }
0088     }
0089 
0090     GridLayout {
0091         columns: 2
0092         rowSpacing: 10
0093         columnSpacing: 10
0094 
0095         Button {
0096             id: lockButton
0097             text: "Lock pointer"
0098             onClicked: root.lock()
0099         }
0100         CheckBox {
0101             id: lockPersChck
0102             text: "Persistent lock"
0103             checked: root.waylandNative
0104             enabled: root.waylandNative
0105         }
0106         Button {
0107             id: confButton
0108             text: "Confine pointer"
0109             onClicked: root.confine()
0110         }
0111         CheckBox {
0112             id: confPersChck
0113             text: "Persistent confine"
0114             checked: root.waylandNative
0115             enabled: root.waylandNative
0116         }
0117         Button {
0118             id: hideConfButton
0119             text: "Hide and confine pointer"
0120             onClicked: root.hideAndConfine()
0121             visible: !root.waylandNative
0122         }
0123         CheckBox {
0124             id: confBeforeHideChck
0125             text: "Confine first, then hide"
0126             checked: false
0127             visible: !root.waylandNative
0128         }
0129     }
0130 
0131     CheckBox {
0132         id: lockHintChck
0133         text: "Send position hint on lock"
0134         checked: root.waylandNative
0135         enabled: root.waylandNative
0136         onCheckedChanged: org_kde_kwin_tests_pointerconstraints_backend.lockHint = checked;
0137     }
0138     CheckBox {
0139         id: restrAreaChck
0140         text: "Restrict input area (not yet implemented)"
0141         enabled: false
0142     }
0143     CheckBox {
0144         id: fullWindowChck
0145         text: "Full window area activates"
0146         checked: !root.waylandNative
0147         enabled: root.waylandNative
0148     }
0149     CheckBox {
0150         id: errorsChck
0151         text: "Allow critical errors"
0152         checked: false
0153         enabled: root.waylandNative
0154         onCheckedChanged: org_kde_kwin_tests_pointerconstraints_backend.errorsAllowed = checked;
0155     }
0156 
0157     Item {
0158         width: childrenRect.width
0159         height: childrenRect.height
0160 
0161         Rectangle {
0162             id: activArea
0163 
0164             width: 400
0165             height: 200
0166 
0167             enabled: root.waylandNative && !fullWindowChck.checked
0168 
0169             function rect() {
0170                 const scenePosition = mapToItem(null, x, y);
0171                 return Qt.rect(scenePosition.x, scenePosition.y, width, height);
0172             }
0173 
0174             border.color: enabled ? "black" : "lightgrey"
0175             border.width: 2
0176 
0177             Label {
0178                 anchors.top: parent.top
0179                 anchors.horizontalCenter: parent.horizontalCenter
0180                 text: "Activation area"
0181             }
0182         }
0183         Button {
0184             id: unconfButton
0185             anchors.horizontalCenter: activArea.horizontalCenter
0186             anchors.verticalCenter: activArea.verticalCenter
0187 
0188             text: "Unconfine pointer"
0189             onClicked: root.unconfine()
0190         }
0191     }
0192 
0193     Label {
0194         text: "Lock: L / Unlock: K"
0195     }
0196     Label {
0197         text: "Confine: C / Unconfine: X"
0198     }
0199     Label {
0200         text: "Hide cursor and confine pointer: H / undo hide: G"
0201         visible: !root.waylandNative
0202     }
0203 }
0204 
0205 }