2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2020-11-03 18:44:32 +00:00
|
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2020-03-15 15:19:28 +00:00
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
#pragma once
|
2016-11-08 13:17:15 +00:00
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
#include <KWaylandServer/kwaylandserver_export.h>
|
2016-11-08 13:17:15 +00:00
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
#include <QObject>
|
2016-11-08 13:17:15 +00:00
|
|
|
#include <QRegion>
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
struct wl_resource;
|
|
|
|
|
2020-04-29 14:56:38 +00:00
|
|
|
namespace KWaylandServer
|
2016-11-08 13:17:15 +00:00
|
|
|
{
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
class ConfinedPointerV1InterfacePrivate;
|
2016-11-08 13:17:15 +00:00
|
|
|
class Display;
|
2020-11-03 18:44:32 +00:00
|
|
|
class LockedPointerV1InterfacePrivate;
|
|
|
|
class PointerConstraintsV1InterfacePrivate;
|
2016-11-08 13:17:15 +00:00
|
|
|
class SurfaceInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manager object to create pointer constraints.
|
|
|
|
*
|
2020-11-03 18:44:32 +00:00
|
|
|
* To create this manager use {@link Display::createPointerConstraintsV1}
|
2016-11-08 13:17:15 +00:00
|
|
|
*
|
2020-11-03 18:44:32 +00:00
|
|
|
* @see ConfinedPointerV1Interface
|
|
|
|
* @see LockedPointerV1Interface
|
|
|
|
*/
|
|
|
|
class KWAYLANDSERVER_EXPORT PointerConstraintsV1Interface : public QObject
|
2016-11-08 13:17:15 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
public:
|
|
|
|
explicit PointerConstraintsV1Interface(Display *display, QObject *parent = nullptr);
|
|
|
|
~PointerConstraintsV1Interface() override;
|
2016-11-08 13:17:15 +00:00
|
|
|
|
|
|
|
private:
|
2020-11-03 18:44:32 +00:00
|
|
|
QScopedPointer<PointerConstraintsV1InterfacePrivate> d;
|
2016-11-08 13:17:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2020-11-03 18:44:32 +00:00
|
|
|
* The LockedPointerV1Interface lets the client request to disable movements of
|
2016-11-08 13:17:15 +00:00
|
|
|
* the virtual pointer (i.e. the cursor), effectively locking the pointer
|
|
|
|
* to a position.
|
|
|
|
*
|
|
|
|
* It is up to the compositor whether the lock gets activated.
|
2020-11-03 18:44:32 +00:00
|
|
|
* To activate it needs to use {@link LockedPointerV1Interface::setLocked}.
|
2016-11-08 13:17:15 +00:00
|
|
|
* The compositor needs to ensure that the SurfaceInterface has pointer focus
|
2020-11-03 18:44:32 +00:00
|
|
|
* and that the pointer is inside the {@link LockedPointerV1Interface::region} when
|
2016-11-08 13:17:15 +00:00
|
|
|
* it activates the lock.
|
|
|
|
*
|
2021-05-13 09:33:08 +00:00
|
|
|
* While the lock is active the PointerInterface does no longer Q_EMIT pointer motion
|
2016-11-08 13:17:15 +00:00
|
|
|
* events, but still emits relative pointer motion events.
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
|
|
|
class KWAYLANDSERVER_EXPORT LockedPointerV1Interface : public QObject
|
2016-11-08 13:17:15 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
public:
|
|
|
|
~LockedPointerV1Interface() override;
|
2016-11-08 13:17:15 +00:00
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
enum class LifeTime : uint {
|
|
|
|
OneShot = 1,
|
2021-04-29 09:45:00 +00:00
|
|
|
Persistent = 2,
|
2016-11-08 13:17:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LifeTime lifeTime() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The intersection of this region and the input region of the SurfaceInterface is used
|
|
|
|
* to determine where the pointer must be in order for the lock to activate.
|
|
|
|
* It is up to the compositor whether to warp the pointer or require some kind of
|
|
|
|
* user interaction for the lock to activate.
|
|
|
|
*
|
|
|
|
* If the region is empty the SurfaceInterface input region is used.
|
|
|
|
*
|
|
|
|
* @see regionChanged
|
|
|
|
* @see SurfaceInterface::input
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
QRegion region() const;
|
|
|
|
|
2018-07-23 08:49:08 +00:00
|
|
|
/**
|
|
|
|
* Indicates where the mouse cursor should be positioned after it has been unlocked again.
|
|
|
|
* The compositor can warp the cursor at this moment to the position. For that it
|
2021-05-13 09:33:08 +00:00
|
|
|
* will not Q_EMIT any relative motion events. The hint is relative to the top-left
|
2018-07-23 08:49:08 +00:00
|
|
|
* corner of the surface the lock was applied to. Only non-negative x and y values
|
|
|
|
* are allowed. Otherwise the hint is invalid and should be ignored by the compositor.
|
|
|
|
*
|
|
|
|
* In case the client never set the hint, an invalid one will be returned.
|
|
|
|
*
|
|
|
|
* This function should be called when the compositor decides to break the lock or the
|
|
|
|
* client unbinds the resource. To set the position in this case the compositor should
|
|
|
|
* call this function when the aboutToBeUnbound signal has been emitted.
|
|
|
|
*
|
|
|
|
* @see cursorPositionHintChanged
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2018-07-23 08:49:08 +00:00
|
|
|
QPointF cursorPositionHint() const;
|
|
|
|
|
2016-11-08 13:17:15 +00:00
|
|
|
/**
|
|
|
|
* Whether the Compositor set this pointer lock to be active.
|
|
|
|
* @see setLocked
|
|
|
|
* @see lockedChanged
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
bool isLocked() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activates or deactivates the lock.
|
|
|
|
*
|
|
|
|
* A pointer lock can only be activated if the SurfaceInterface
|
2020-11-03 18:44:32 +00:00
|
|
|
* this LockedPointerV1Interface was created for has pointer focus
|
2017-05-26 00:57:20 +00:00
|
|
|
* and the pointer is inside the {@link region}.
|
2016-11-08 13:17:15 +00:00
|
|
|
*
|
2018-07-23 08:49:08 +00:00
|
|
|
* Unlocking resets the cursor position hint.
|
|
|
|
*
|
2016-11-08 13:17:15 +00:00
|
|
|
* @param locked Whether the lock should be active
|
|
|
|
* @see isLocked
|
|
|
|
* @see lockedChanged
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
void setLocked(bool locked);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2020-11-03 18:44:32 +00:00
|
|
|
/**
|
|
|
|
* This is signal is emitted when the locked pointer is about to be destroyed.
|
|
|
|
*/
|
|
|
|
void aboutToBeDestroyed();
|
|
|
|
|
2016-11-08 13:17:15 +00:00
|
|
|
/**
|
|
|
|
* Emitted whenever the region changes.
|
|
|
|
* This happens when the parent SurfaceInterface gets committed
|
|
|
|
* @see region
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
void regionChanged();
|
|
|
|
|
2018-07-23 08:49:08 +00:00
|
|
|
/**
|
|
|
|
* Emitted whenever the cursor position hint changes.
|
|
|
|
* This happens when the parent SurfaceInterface gets committed
|
|
|
|
* @see cursorPositionHint
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2018-07-23 08:49:08 +00:00
|
|
|
void cursorPositionHintChanged();
|
|
|
|
|
2016-11-08 13:17:15 +00:00
|
|
|
/**
|
2017-05-26 00:57:20 +00:00
|
|
|
* Emitted whenever the {@link isLocked} state changes.
|
2016-11-08 13:17:15 +00:00
|
|
|
* @see isLocked
|
|
|
|
* @see setLocked
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
void lockedChanged();
|
|
|
|
|
|
|
|
private:
|
2020-11-03 18:44:32 +00:00
|
|
|
LockedPointerV1Interface(LifeTime lifeTime, const QRegion ®ion, ::wl_resource *resource);
|
|
|
|
QScopedPointer<LockedPointerV1InterfacePrivate> d;
|
|
|
|
friend class LockedPointerV1InterfacePrivate;
|
|
|
|
friend class PointerConstraintsV1InterfacePrivate;
|
2016-11-08 13:17:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2020-11-03 18:44:32 +00:00
|
|
|
* The ConfinedPointerV1Interface gets installed on a SurfaceInterface.
|
2016-11-08 13:17:15 +00:00
|
|
|
* The confinement indicates that the SurfaceInterface wants to confine the
|
|
|
|
* pointer to a region of the SurfaceInterface.
|
|
|
|
*
|
|
|
|
* It is up to the compositor whether the confinement gets activated.
|
2020-11-03 18:44:32 +00:00
|
|
|
* To activate it needs to use {@link ConfinedPointerV1Interface::setConfined}.
|
2016-11-08 13:17:15 +00:00
|
|
|
* The compositor needs to ensure that the SurfaceInterface has pointer focus
|
2020-11-03 18:44:32 +00:00
|
|
|
* and that the pointer is inside the {@link ConfinedPointerV1Interface::region} when
|
2016-11-08 13:17:15 +00:00
|
|
|
* it activates the confinement.
|
|
|
|
*
|
2020-11-03 18:44:32 +00:00
|
|
|
* From client side the confinement gets deactivated by destroying the ConfinedPointerV1Interface.
|
2016-11-08 13:17:15 +00:00
|
|
|
* From compositor side the confinement can be deactivated by setting
|
2020-11-03 18:44:32 +00:00
|
|
|
* {@link ConfinedPointerV1Interface::setConfined} to @c false.
|
|
|
|
*/
|
|
|
|
class KWAYLANDSERVER_EXPORT ConfinedPointerV1Interface : public QObject
|
2016-11-08 13:17:15 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
public:
|
|
|
|
~ConfinedPointerV1Interface() override;
|
2016-11-08 13:17:15 +00:00
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
enum class LifeTime : uint {
|
|
|
|
OneShot = 1,
|
2021-04-29 09:45:00 +00:00
|
|
|
Persistent = 2,
|
2016-11-08 13:17:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LifeTime lifeTime() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The intersection of this region and the input region of the SurfaceInterface is used
|
|
|
|
* to determine where the pointer must be in order for the confinement to activate.
|
|
|
|
* It is up to the compositor whether to warp the pointer or require some kind of
|
|
|
|
* user interaction for the confinement to activate.
|
|
|
|
*
|
|
|
|
* If the region is empty the SurfaceInterface input region is used.
|
|
|
|
*
|
|
|
|
* @see regionChanged
|
|
|
|
* @see SurfaceInterface::input
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
QRegion region() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the Compositor set this pointer confinement to be active.
|
|
|
|
* @see setConfined
|
|
|
|
* @see confinedChanged
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
bool isConfined() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activates or deactivates the confinement.
|
|
|
|
*
|
|
|
|
* A pointer confinement can only be activated if the SurfaceInterface
|
2020-11-03 18:44:32 +00:00
|
|
|
* this ConfinedPointerV1Interface was created for has pointer focus
|
2017-05-26 00:57:20 +00:00
|
|
|
* and the pointer is inside the {@link region}.
|
2016-11-08 13:17:15 +00:00
|
|
|
*
|
|
|
|
* @param confined Whether the confinement should be active
|
|
|
|
* @see isConfined
|
|
|
|
* @see confinedChanged
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
void setConfined(bool confined);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* Emitted whenever the region changes.
|
|
|
|
* This happens when the parent SurfaceInterface gets committed
|
|
|
|
* @see region
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
void regionChanged();
|
|
|
|
|
|
|
|
/**
|
2017-05-26 00:57:20 +00:00
|
|
|
* Emitted whenever the {@link isConfined} state changes.
|
2016-11-08 13:17:15 +00:00
|
|
|
* @see isConfined
|
|
|
|
* @see setConfined
|
2020-11-03 18:44:32 +00:00
|
|
|
*/
|
2016-11-08 13:17:15 +00:00
|
|
|
void confinedChanged();
|
|
|
|
|
|
|
|
private:
|
2020-11-03 18:44:32 +00:00
|
|
|
ConfinedPointerV1Interface(LifeTime lifeTime, const QRegion ®ion, ::wl_resource *resource);
|
|
|
|
QScopedPointer<ConfinedPointerV1InterfacePrivate> d;
|
|
|
|
friend class ConfinedPointerV1InterfacePrivate;
|
|
|
|
friend class PointerConstraintsV1InterfacePrivate;
|
2016-11-08 13:17:15 +00:00
|
|
|
};
|
|
|
|
|
2020-11-03 18:44:32 +00:00
|
|
|
} // namespace KWaylandServer
|