File: pointerlocker.h

package info (click to toggle)
kdeconnect 25.04.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,584 kB
  • sloc: cpp: 22,922; xml: 520; python: 92; sh: 25; makefile: 5
file content (73 lines) | stat: -rw-r--r-- 1,827 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
    SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/

#ifndef POINTERLOCKER_H
#define POINTERLOCKER_H

#include <QObject>
#include <QWindow>

class AbstractPointerLocker : public QObject
{
    Q_OBJECT
    Q_PROPERTY(bool isSupported READ isSupported NOTIFY supportedChanged)
    Q_PROPERTY(bool isLocked READ isLocked WRITE setLocked NOTIFY lockedChanged)
    Q_PROPERTY(bool isLockEffective READ isLockEffective NOTIFY lockEffectiveChanged)
    Q_PROPERTY(QWindow *window READ window WRITE setWindow NOTIFY windowChanged)
public:
    AbstractPointerLocker(QObject *parent = nullptr)
        : QObject(parent)
    {
    }

    virtual void setLocked(bool locked) = 0;
    virtual bool isLocked() const = 0;
    virtual bool isLockEffective() const = 0;
    virtual bool isSupported() const = 0;

    virtual void setWindow(QWindow *window);
    QWindow *window() const
    {
        return m_window;
    }

Q_SIGNALS:
    void supportedChanged(bool isSupported);
    void lockedChanged(bool isLocked);
    void lockEffectiveChanged(bool isLockEffective);
    void windowChanged();
    void pointerMoved(const QPointF &delta);

protected:
    QWindow *m_window = nullptr;
};

class PointerLockerQt : public AbstractPointerLocker
{
    Q_OBJECT
public:
    PointerLockerQt(QObject *parent = nullptr);
    ~PointerLockerQt() override;

    void setLocked(bool locked) override;
    bool isLocked() const override;
    bool isSupported() const override
    {
        return true;
    }
    bool isLockEffective() const override
    {
        return isLocked();
    }

private:
    bool eventFilter(QObject *watched, QEvent *event) override;

    QPoint m_originalPosition;
    bool m_isLocked = false;
};

#endif