2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
|
2020-08-02 22:10:35 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2018-06-09 13:19:50 +00:00
|
|
|
#ifndef POINTERCONSTRAINTSTEST_H
|
|
|
|
#define POINTERCONSTRAINTSTEST_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QQuickView>
|
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
namespace KWayland
|
|
|
|
{
|
|
|
|
namespace Client
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
|
|
|
|
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:
|
2022-03-23 10:13:38 +00:00
|
|
|
Backend(QObject *parent = nullptr)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
2018-06-09 13:19:50 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(int mode READ mode CONSTANT)
|
2018-07-18 07:06:56 +00:00
|
|
|
Q_PROPERTY(bool lockHint MEMBER m_lockHint NOTIFY lockHintChanged)
|
2018-06-09 13:19:50 +00:00
|
|
|
Q_PROPERTY(bool errorsAllowed READ errorsAllowed WRITE setErrorsAllowed NOTIFY errorsAllowedChanged)
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
virtual void init(QQuickView *view)
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
m_view = view;
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
int mode() const
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
return (int)m_mode;
|
|
|
|
}
|
2018-07-18 07:06:56 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
bool lockHint() const
|
|
|
|
{
|
2018-07-18 07:06:56 +00:00
|
|
|
return m_lockHint;
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
bool errorsAllowed() const
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
return m_errorsAllowed;
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
void setErrorsAllowed(bool set)
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
if (m_errorsAllowed == set) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_errorsAllowed = set;
|
|
|
|
Q_EMIT errorsAllowedChanged();
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
Q_INVOKABLE virtual void lockRequest(bool persistent = true, QRect region = QRect())
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
Q_INVOKABLE virtual void unlockRequest()
|
|
|
|
{
|
|
|
|
}
|
2018-06-09 13:19:50 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
Q_INVOKABLE virtual void confineRequest(bool persistent = true, QRect region = QRect())
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
Q_INVOKABLE virtual void unconfineRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Q_INVOKABLE virtual void hideAndConfineRequest(bool confineBeforeHide = false)
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
Q_INVOKABLE virtual void undoHideRequest()
|
|
|
|
{
|
|
|
|
}
|
2018-06-09 13:19:50 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void confineChanged(bool confined);
|
|
|
|
void lockChanged(bool locked);
|
2018-07-18 07:06:56 +00:00
|
|
|
void lockHintChanged();
|
2018-06-09 13:19:50 +00:00
|
|
|
void errorsAllowedChanged();
|
2018-07-18 07:06:56 +00:00
|
|
|
void forceSurfaceCommit();
|
2018-06-09 13:19:50 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
enum class Mode {
|
|
|
|
Wayland = 0,
|
|
|
|
X = 1
|
|
|
|
};
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
QQuickView *view() const
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
return m_view;
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
void setMode(Mode set)
|
|
|
|
{
|
2018-06-09 13:19:50 +00:00
|
|
|
m_mode = set;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QQuickView *m_view;
|
|
|
|
Mode m_mode;
|
2018-07-18 07:06:56 +00:00
|
|
|
|
|
|
|
bool m_lockHint = true;
|
2018-06-09 13:19:50 +00:00
|
|
|
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
|