Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 497d0773 authored by Roman Gilg's avatar Roman Gilg

[tests] Add pointer constraints test

Summary:
Provides a testing application for pointer locking and pointer confining in
a Wayland session.

The application can be started with QT_QPA_PLATFORM variable set to wayland
or xcb to test constraining in native mode as well as through Xwayland.

Several modes and properties can be selected to test various forms of locking
and confining.

{F5899580}

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: davidedmundson, zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D13439
parent 7550d2a0
......@@ -35,6 +35,10 @@ target_link_libraries(libinputtest Qt5::Core Qt5::DBus Libinput::Libinput ${UDEV
add_executable(x11shadowreader x11shadowreader.cpp)
target_link_libraries(x11shadowreader XCB::XCB Qt5::Widgets Qt5::X11Extras KF5::ConfigCore KF5::WindowSystem)
add_executable(pointerconstraints pointerconstraintstest.cpp)
add_definitions(-DDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(pointerconstraints XCB::XCB Qt5::Gui Qt5::Quick KF5::WaylandClient)
add_executable(pointergestures pointergesturestest.cpp)
add_definitions(-DDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(pointergestures Qt5::Gui Qt5::Quick KF5::WaylandClient)
......
This diff is collapsed.
/********************************************************************
Copyright 2018 Roman Gilg <subdiff@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#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 errorsAllowed READ errorsAllowed WRITE setErrorsAllowed NOTIFY errorsAllowedChanged)
virtual void init(QQuickView *view) {
m_view = view;
}
int mode() const {
return (int)m_mode;
}
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_UNUSED(persistent);
Q_UNUSED(region);
}
Q_INVOKABLE virtual void unlockRequest() {}
Q_INVOKABLE virtual void confineRequest(bool persistent = true, QRect region = QRect()) {
Q_UNUSED(persistent);
Q_UNUSED(region);
}
Q_INVOKABLE virtual void unconfineRequest() {}
Q_INVOKABLE virtual void hideAndConfineRequest(bool confineBeforeHide = false) {
Q_UNUSED(confineBeforeHide);
}
Q_INVOKABLE virtual void undoHideRequest() {}
Q_SIGNALS:
void confineChanged(bool confined);
void lockChanged(bool locked);
void errorsAllowedChanged();
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_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
/********************************************************************
Copyright 2018 Roman Gilg <subdiff@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
import QtQuick 2.10
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
ColumnLayout {
/* for margins */
ColumnLayout {
id: root
focus: true
Layout.margins: 20
function lock() {
org_kde_kwin_tests_pointerconstraints_backend.lockRequest(lockPersChck.checked, root.activRect());
}
function confine() {
org_kde_kwin_tests_pointerconstraints_backend.confineRequest(confPersChck.checked, root.activRect());
}
function unlock() {
org_kde_kwin_tests_pointerconstraints_backend.unlockRequest();
}
function unconfine() {
org_kde_kwin_tests_pointerconstraints_backend.unconfineRequest();
}
function hideAndConfine() {
org_kde_kwin_tests_pointerconstraints_backend.hideAndConfineRequest();
}
function undoHideAndConfine() {
org_kde_kwin_tests_pointerconstraints_backend.undoHideRequest();
}
property bool waylandNative: org_kde_kwin_tests_pointerconstraints_backend.mode === 0
Keys.onPressed: {
if (event.key === Qt.Key_L) {
root.lock();
event.accepted = true;
} else if (event.key === Qt.Key_C) {
root.confine();
event.accepted = true;
} else if (event.key === Qt.Key_K) {
root.unlock();
event.accepted = true;
} else if (event.key === Qt.Key_X) {
root.unconfine();
event.accepted = true;
} else if (event.key === Qt.Key_H) {
root.hideAndConfine();
event.accepted = true;
} else if (event.key === Qt.Key_G) {
root.undoHideAndConfine();
event.accepted = true;
}
}
function activRect() {
if (fullWindowChck.checked) {
return Qt.rect(0, 0, -1, -1);
}
return activArea.rect();
}
GridLayout {
columns: 2
rowSpacing: 10
columnSpacing: 10
Button {
id: lockButton
text: "Lock pointer"
onClicked: root.lock()
}
CheckBox {
id: lockPersChck
text: "Persistent lock"
checked: root.waylandNative
enabled: root.waylandNative
}
Button {
id: confButton
text: "Confine pointer"
onClicked: root.confine()
}
CheckBox {
id: confPersChck
text: "Persistent confine"
checked: root.waylandNative
enabled: root.waylandNative
}
Button {
id: hideConfButton
text: "Hide and confine pointer"
onClicked: root.hideAndConfine()
visible: !root.waylandNative
}
CheckBox {
id: confBeforeHideChck
text: "Confine first, then hide"
checked: false
visible: !root.waylandNative
}
}
CheckBox {
id: restrAreaChck
text: "Restrict input area (not yet implemented)"
enabled: false
}
CheckBox {
id: fullWindowChck
text: "Full window area activates"
checked: !root.waylandNative
enabled: root.waylandNative
}
CheckBox {
id: errorsChck
text: "Allow critical errors"
checked: false
enabled: root.waylandNative
onCheckedChanged: org_kde_kwin_tests_pointerconstraints_backend.errorsAllowed = checked;
}
Item {
width: childrenRect.width
height: childrenRect.height
Rectangle {
id: activArea
width: 400
height: 200
enabled: root.waylandNative && !fullWindowChck.checked
function rect() {
var globalPt = mapToGlobal(x, y);
return Qt.rect(globalPt.x, globalPt.y, width, height);
}
border.color: enabled ? "black" : "lightgrey"
border.width: 2
Label {
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
text: "Activation area"
}
}
Button {
id: unconfButton
anchors.horizontalCenter: activArea.horizontalCenter
anchors.verticalCenter: activArea.verticalCenter
text: "Unconfine pointer"
onClicked: root.unconfineRequest()
}
}
Label {
text: "Lock: L / Unlock: K"
}
Label {
text: "Confine: C / Unconfine: X"
}
Label {
text: "Hide cursor and confine pointer: H / undo hide: G"
visible: !root.waylandNative
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment