0c5ca405cc
Summary: There are two types of constraints supported: 1. Pointer confinement 2. Pointer locking In the case of confinement the pointer is confined to a given region of the surface. This is comparable to general operation where the pointer is confined to the screen region. In the second case the pointer gets locked. That means it cannot move at all. No further position updates are provided, only relative motion events can go to the application. There is a hint about cursor position update on unlock which is not yet implemented in KWayland::Server, thus also not in this change. The implementation in KWin grants the requests for pointer constraints when the pointer enters the constrained region, either by pointer movement or by e.g. stacking order changes. There is no confirmation from user required to enter that mode. But we want to show an OSD when the pointer gets constrained, this is not yet implemented, though. Breaking an active constraint is relatively easy. E.g. changing the stacking order will break the constraint if another surface is under the cursor. Also (in case of confinement) moving the pointer to an overlapping window breaks the confinement. But as soon as one moves the pointer back to the window a constraint might get honoured again. To properly break there is a dedicated event filter. It listens for a long press of the Escape key. If hold for 3sec the pointer constraint is broken and not activated again till the pointer got moved out of the window. Afterward when moving in the pointer might activate again. The escape filter ensures that the key press is forwarded to the application if it's a short press or if another key gets pressed during the three seconds. If the three seconds way fires, the later escape release is not sent to the application. This basic interaction is also ensured through an added auto test. This change implements T4605. Test Plan: Added auto test and nested KWin Wayland with D3488 Reviewers: #kwin, #plasma_on_wayland Subscribers: plasma-devel, kwin Tags: #plasma_on_wayland, #kwin Differential Revision: https://phabricator.kde.org/D3506
187 lines
5.9 KiB
C++
187 lines
5.9 KiB
C++
/********************************************************************
|
|
KWin - the KDE window manager
|
|
This file is part of the KDE project.
|
|
|
|
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*********************************************************************/
|
|
#ifndef KWIN_WAYLAND_TEST_H
|
|
#define KWIN_WAYLAND_TEST_H
|
|
|
|
#include "../../main.h"
|
|
|
|
// Qt
|
|
#include <QtTest/QtTest>
|
|
|
|
namespace KWayland
|
|
{
|
|
namespace Client
|
|
{
|
|
class ConnectionThread;
|
|
class Compositor;
|
|
class PlasmaShell;
|
|
class PlasmaWindowManagement;
|
|
class PointerConstraints;
|
|
class Seat;
|
|
class ServerSideDecorationManager;
|
|
class Shell;
|
|
class ShellSurface;
|
|
class ShmPool;
|
|
class Surface;
|
|
class XdgShellSurface;
|
|
}
|
|
}
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
class AbstractClient;
|
|
class ShellClient;
|
|
|
|
class WaylandTestApplication : public Application
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
WaylandTestApplication(int &argc, char **argv);
|
|
virtual ~WaylandTestApplication();
|
|
|
|
protected:
|
|
void performStartup() override;
|
|
|
|
private:
|
|
void createBackend();
|
|
void createX11Connection();
|
|
void continueStartupWithScreens();
|
|
void continueStartupWithX();
|
|
void startXwaylandServer();
|
|
|
|
int m_xcbConnectionFd = -1;
|
|
QProcess *m_xwaylandProcess = nullptr;
|
|
QMetaObject::Connection m_xwaylandFailConnection;
|
|
};
|
|
|
|
namespace Test
|
|
{
|
|
|
|
enum class AdditionalWaylandInterface {
|
|
Seat = 1 << 0,
|
|
Decoration = 1 << 1,
|
|
PlasmaShell = 1 << 2,
|
|
WindowManagement = 1 << 3,
|
|
PointerConstraints = 1 << 4
|
|
};
|
|
Q_DECLARE_FLAGS(AdditionalWaylandInterfaces, AdditionalWaylandInterface)
|
|
/**
|
|
* Creates a Wayland Connection in a dedicated thread and creates various
|
|
* client side objects which can be used to create windows.
|
|
* @param socketName The name of the Wayland socket to connect to.
|
|
* @returns @c true if created successfully, @c false if there was an error
|
|
* @see destroyWaylandConnection
|
|
**/
|
|
bool setupWaylandConnection(const QString &socketName, AdditionalWaylandInterfaces flags = AdditionalWaylandInterfaces());
|
|
|
|
/**
|
|
* Destroys the Wayland Connection created with @link{setupWaylandConnection}.
|
|
* This can be called from cleanup in order to ensure that no Wayland Connection
|
|
* leaks into the next test method.
|
|
* @see setupWaylandConnection
|
|
*/
|
|
void destroyWaylandConnection();
|
|
|
|
KWayland::Client::ConnectionThread *waylandConnection();
|
|
KWayland::Client::Compositor *waylandCompositor();
|
|
KWayland::Client::Shell *waylandShell();
|
|
KWayland::Client::ShmPool *waylandShmPool();
|
|
KWayland::Client::Seat *waylandSeat();
|
|
KWayland::Client::ServerSideDecorationManager *waylandServerSideDecoration();
|
|
KWayland::Client::PlasmaShell *waylandPlasmaShell();
|
|
KWayland::Client::PlasmaWindowManagement *waylandWindowManagement();
|
|
KWayland::Client::PointerConstraints *waylandPointerConstraints();
|
|
|
|
bool waitForWaylandPointer();
|
|
bool waitForWaylandTouch();
|
|
bool waitForWaylandKeyboard();
|
|
|
|
void flushWaylandConnection();
|
|
|
|
KWayland::Client::Surface *createSurface(QObject *parent = nullptr);
|
|
enum class ShellSurfaceType {
|
|
WlShell,
|
|
XdgShellV5
|
|
};
|
|
QObject *createShellSurface(ShellSurfaceType type, KWayland::Client::Surface *surface, QObject *parent = nullptr);
|
|
KWayland::Client::ShellSurface *createShellSurface(KWayland::Client::Surface *surface, QObject *parent = nullptr);
|
|
KWayland::Client::XdgShellSurface *createXdgShellV5Surface(KWayland::Client::Surface *surface, QObject *parent = nullptr);
|
|
|
|
/**
|
|
* Creates a shared memory buffer of @p size in @p color and attaches it to the @p surface.
|
|
* The @p surface gets damaged and committed, thus it's rendered.
|
|
**/
|
|
void render(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format = QImage::Format_ARGB32);
|
|
|
|
/**
|
|
* Waits till a new ShellClient is shown and returns the created ShellClient.
|
|
* If no ShellClient gets shown during @p timeout @c null is returned.
|
|
**/
|
|
ShellClient *waitForWaylandWindowShown(int timeout = 5000);
|
|
|
|
/**
|
|
* Combination of @link{render} and @link{waitForWaylandWindowShown}.
|
|
**/
|
|
ShellClient *renderAndWaitForShown(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format = QImage::Format_ARGB32, int timeout = 5000);
|
|
|
|
/**
|
|
* Waits for the @p client to be destroyed.
|
|
**/
|
|
bool waitForWindowDestroyed(AbstractClient *client);
|
|
|
|
/**
|
|
* Locks the screen and waits till the screen is locked.
|
|
* @returns @c true if the screen could be locked, @c false otherwise
|
|
**/
|
|
bool lockScreen();
|
|
|
|
/**
|
|
* Unlocks the screen and waits till the screen is unlocked.
|
|
* @returns @c true if the screen could be unlocked, @c false otherwise
|
|
**/
|
|
bool unlockScreen();
|
|
}
|
|
|
|
}
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::Test::AdditionalWaylandInterfaces)
|
|
Q_DECLARE_METATYPE(KWin::Test::ShellSurfaceType)
|
|
|
|
#define WAYLANDTEST_MAIN_HELPER(TestObject, DPI) \
|
|
int main(int argc, char *argv[]) \
|
|
{ \
|
|
setenv("QT_QPA_PLATFORM", "wayland-org.kde.kwin.qpa", true); \
|
|
setenv("QT_QPA_PLATFORM_PLUGIN_PATH", KWINQPAPATH, true); \
|
|
setenv("KWIN_FORCE_OWN_QPA", "1", true); \
|
|
DPI; \
|
|
KWin::WaylandTestApplication app(argc, argv); \
|
|
app.setAttribute(Qt::AA_Use96Dpi, true); \
|
|
TestObject tc; \
|
|
return QTest::qExec(&tc, argc, argv); \
|
|
}
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
|
|
#define WAYLANDTEST_MAIN(TestObject) WAYLANDTEST_MAIN_HELPER(TestObject, QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling) )
|
|
#else
|
|
#define WAYLANDTEST_MAIN(TestObject) WAYLANDTEST_MAIN_HELPER(TestObject,)
|
|
#endif
|
|
|
|
#endif
|