summaryrefslogtreecommitdiff
path: root/src/devices/Tablet.hpp
blob: 1805f3ba011ea0a70a48b2ae259827b2df16b929 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#pragma once

#include "IHID.hpp"
#include "../helpers/WLListener.hpp"
#include "../macros.hpp"
#include "../helpers/Vector2D.hpp"
#include "../helpers/Box.hpp"

struct wlr_tablet;
struct wlr_tablet_tool;
struct wlr_tablet_pad;

class CTabletTool;
class CTabletPad;
class CWLSurfaceResource;

/*
    A tablet device
    Tablets don't have an interface for now,
    if there will be a need it's trivial to do.
*/
class CTablet : public IHID {
  public:
    static SP<CTablet> create(wlr_tablet* tablet);
    static SP<CTablet> fromWlr(wlr_tablet* tablet);
    ~CTablet();

    virtual uint32_t getCapabilities();
    virtual eHIDType getType();
    wlr_tablet*      wlr();

    enum eTabletToolAxes {
        HID_TABLET_TOOL_AXIS_X        = (1 << 0),
        HID_TABLET_TOOL_AXIS_Y        = (1 << 1),
        HID_TABLET_TOOL_AXIS_TILT_X   = (1 << 2),
        HID_TABLET_TOOL_AXIS_TILT_Y   = (1 << 3),
        HID_TABLET_TOOL_AXIS_DISTANCE = (1 << 4),
        HID_TABLET_TOOL_AXIS_PRESSURE = (1 << 5),
        HID_TABLET_TOOL_AXIS_ROTATION = (1 << 6),
        HID_TABLET_TOOL_AXIS_SLIDER   = (1 << 7),
        HID_TABLET_TOOL_AXIS_WHEEL    = (1 << 8),
    };

    struct SAxisEvent {
        wlr_tablet_tool* tool;
        SP<CTablet>      tablet;

        uint32_t         timeMs      = 0;
        uint32_t         updatedAxes = 0; // eTabletToolAxes
        Vector2D         axis;
        Vector2D         axisDelta;
        Vector2D         tilt;
        double           pressure   = 0;
        double           distance   = 0;
        double           rotation   = 0;
        double           slider     = 0;
        double           wheelDelta = 0;
    };

    struct SProximityEvent {
        wlr_tablet_tool* tool;
        SP<CTablet>      tablet;

        uint32_t         timeMs = 0;
        Vector2D         proximity;
        bool             in = false;
    };

    struct STipEvent {
        wlr_tablet_tool* tool;
        SP<CTablet>      tablet;

        uint32_t         timeMs = 0;
        Vector2D         tip;
        bool             in = false;
    };

    struct SButtonEvent {
        wlr_tablet_tool* tool;
        SP<CTablet>      tablet;

        uint32_t         timeMs = 0;
        uint32_t         button;
        bool             down = false;
    };

    struct {
        CSignal axis;
        CSignal proximity;
        CSignal tip;
        CSignal button;
    } tabletEvents;

    WP<CTablet> self;

    bool        relativeInput = false;
    std::string hlName        = "";
    std::string boundOutput   = "";
    CBox        activeArea;
    CBox        boundBox; // output-local

  private:
    CTablet(wlr_tablet* tablet);

    void        disconnectCallbacks();

    wlr_tablet* tablet = nullptr;

    DYNLISTENER(destroy);
    DYNLISTENER(axis);
    DYNLISTENER(proximity);
    DYNLISTENER(tip);
    DYNLISTENER(button);
};

class CTabletPad : public IHID {
  public:
    static SP<CTabletPad> create(wlr_tablet_pad* pad);
    ~CTabletPad();

    virtual uint32_t getCapabilities();
    virtual eHIDType getType();
    wlr_tablet_pad*  wlr();

    struct SButtonEvent {
        uint32_t timeMs = 0;
        uint32_t button = 0;
        bool     down   = false;
        uint32_t mode   = 0;
        uint32_t group  = 0;
    };

    struct SRingEvent {
        uint32_t timeMs   = 0;
        bool     finger   = false;
        uint32_t ring     = 0;
        double   position = 0;
        uint32_t mode     = 0;
    };

    struct SStripEvent {
        uint32_t timeMs   = 0;
        bool     finger   = false;
        uint32_t strip    = 0;
        double   position = 0;
        uint32_t mode     = 0;
    };

    struct {
        CSignal button;
        CSignal ring;
        CSignal strip;
        CSignal attach;
    } padEvents;

    WP<CTabletPad>  self;
    WP<CTabletTool> parent;

    std::string     hlName;

  private:
    CTabletPad(wlr_tablet_pad* pad);

    void            disconnectCallbacks();

    wlr_tablet_pad* pad = nullptr;

    DYNLISTENER(destroy);
    DYNLISTENER(ring);
    DYNLISTENER(strip);
    DYNLISTENER(button);
    DYNLISTENER(attach);
};

class CTabletTool : public IHID {
  public:
    static SP<CTabletTool> create(wlr_tablet_tool* tool);
    static SP<CTabletTool> fromWlr(wlr_tablet_tool* tool);
    ~CTabletTool();

    enum eTabletToolType {
        HID_TABLET_TOOL_TYPE_PEN = 1,
        HID_TABLET_TOOL_TYPE_ERASER,
        HID_TABLET_TOOL_TYPE_BRUSH,
        HID_TABLET_TOOL_TYPE_PENCIL,
        HID_TABLET_TOOL_TYPE_AIRBRUSH,
        HID_TABLET_TOOL_TYPE_MOUSE,
        HID_TABLET_TOOL_TYPE_LENS,
        HID_TABLET_TOOL_TYPE_TOTEM,
    };

    enum eTabletToolCapabilities {
        HID_TABLET_TOOL_CAPABILITY_TILT     = (1 << 0),
        HID_TABLET_TOOL_CAPABILITY_PRESSURE = (1 << 1),
        HID_TABLET_TOOL_CAPABILITY_DISTANCE = (1 << 2),
        HID_TABLET_TOOL_CAPABILITY_ROTATION = (1 << 3),
        HID_TABLET_TOOL_CAPABILITY_SLIDER   = (1 << 4),
        HID_TABLET_TOOL_CAPABILITY_WHEEL    = (1 << 5),
    };

    virtual uint32_t       getCapabilities();
    wlr_tablet_tool*       wlr();
    virtual eHIDType       getType();
    SP<CWLSurfaceResource> getSurface();
    void                   setSurface(SP<CWLSurfaceResource>);

    WP<CTabletTool>        self;
    Vector2D               tilt;
    bool                   active           = false; // true if in proximity
    uint32_t               toolCapabilities = 0;

    bool                   isDown = false;
    std::vector<uint32_t>  buttonsDown;
    Vector2D               absolutePos; // last known absolute position.

    std::string            hlName;

  private:
    CTabletTool(wlr_tablet_tool* tool);

    void                   disconnectCallbacks();

    WP<CWLSurfaceResource> pSurface;

    wlr_tablet_tool*       tool = nullptr;

    DYNLISTENER(destroy);

    struct {
        CHyprSignalListener destroySurface;
    } listeners;
};