aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/protocols/Tablet.hpp
blob: 8c99bee00b44d6f289de9b84e8ba84e9513f81d0 (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
233
234
235
236
237
#pragma once

#include <memory>
#include <vector>
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "tablet-v2.hpp"
#include "../helpers/math/Math.hpp"
#include <aquamarine/input/Input.hpp>

class CTablet;
class CTabletTool;
class CTabletPad;
class CEventLoopTimer;
class CTabletSeat;
class CWLSurfaceResource;

class CTabletPadStripV2Resource {
  public:
    CTabletPadStripV2Resource(SP<CZwpTabletPadStripV2> resource_, uint32_t id);

    bool     good();

    uint32_t id = 0;

  private:
    SP<CZwpTabletPadStripV2> resource;

    friend class CTabletSeat;
    friend class CTabletPadGroupV2Resource;
    friend class CTabletV2Protocol;
};

class CTabletPadRingV2Resource {
  public:
    CTabletPadRingV2Resource(SP<CZwpTabletPadRingV2> resource_, uint32_t id);

    bool     good();

    uint32_t id = 0;

  private:
    SP<CZwpTabletPadRingV2> resource;

    friend class CTabletSeat;
    friend class CTabletPadGroupV2Resource;
    friend class CTabletV2Protocol;
};

class CTabletPadGroupV2Resource {
  public:
    CTabletPadGroupV2Resource(SP<CZwpTabletPadGroupV2> resource_, size_t idx);

    bool                                       good();
    void                                       sendData(SP<CTabletPad> pad, SP<Aquamarine::ITabletPad::STabletPadGroup> group);

    std::vector<WP<CTabletPadRingV2Resource>>  rings;
    std::vector<WP<CTabletPadStripV2Resource>> strips;

    size_t                                     idx = 0;

  private:
    SP<CZwpTabletPadGroupV2> resource;

    friend class CTabletSeat;
    friend class CTabletPadV2Resource;
    friend class CTabletV2Protocol;
};

class CTabletPadV2Resource {
  public:
    CTabletPadV2Resource(SP<CZwpTabletPadV2> resource_, SP<CTabletPad> pad_, SP<CTabletSeat> seat_);

    bool                                       good();
    void                                       sendData();

    std::vector<WP<CTabletPadGroupV2Resource>> groups;

    WP<CTabletPad>                             pad;
    WP<CTabletSeat>                            seat;

    bool                                       inert = false; // removed was sent

  private:
    SP<CZwpTabletPadV2> resource;

    void                createGroup(SP<Aquamarine::ITabletPad::STabletPadGroup> group, size_t idx);

    friend class CTabletSeat;
    friend class CTabletV2Protocol;
};

class CTabletV2Resource {
  public:
    CTabletV2Resource(SP<CZwpTabletV2> resource_, SP<CTablet> tablet_, SP<CTabletSeat> seat_);

    bool            good();
    void            sendData();

    WP<CTablet>     tablet;
    WP<CTabletSeat> seat;

    bool            inert = false; // removed was sent

  private:
    SP<CZwpTabletV2> resource;

    friend class CTabletSeat;
    friend class CTabletV2Protocol;
};

class CTabletToolV2Resource {
  public:
    CTabletToolV2Resource(SP<CZwpTabletToolV2> resource_, SP<CTabletTool> tool_, SP<CTabletSeat> seat_);

    bool                   good();
    void                   sendData();
    void                   queueFrame();
    void                   sendFrame();

    bool                   current = false;
    WP<CWLSurfaceResource> lastSurf;

    WP<CTabletTool>        tool;
    WP<CTabletSeat>        seat;

    bool                   frameQueued = false;
    bool                   inert       = false; // removed was sent

  private:
    SP<CZwpTabletToolV2> resource;

    friend class CTabletSeat;
    friend class CTabletV2Protocol;
};

class CTabletSeat {
  public:
    CTabletSeat(SP<CZwpTabletSeatV2> resource_);

    bool                                   good();
    void                                   sendData();

    std::vector<WP<CTabletToolV2Resource>> tools;
    std::vector<WP<CTabletPadV2Resource>>  pads;
    std::vector<WP<CTabletV2Resource>>     tablets;

    void                                   sendTool(SP<CTabletTool> tool);
    void                                   sendPad(SP<CTabletPad> pad);
    void                                   sendTablet(SP<CTablet> tablet);

  private:
    SP<CZwpTabletSeatV2> resource;
    WP<CTabletSeat>      self;

    friend class CTabletV2Protocol;
};

class CTabletV2Protocol : public IWaylandProtocol {
  public:
    CTabletV2Protocol(const wl_interface* iface, const int& ver, const std::string& name);

    virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);

    void         registerDevice(SP<CTablet> tablet);
    void         registerDevice(SP<CTabletTool> tool);
    void         registerDevice(SP<CTabletPad> pad);

    void         unregisterDevice(SP<CTablet> tablet);
    void         unregisterDevice(SP<CTabletTool> tool);
    void         unregisterDevice(SP<CTabletPad> pad);

    void         recheckRegisteredDevices();

    // Tablet tool events
    void pressure(SP<CTabletTool> tool, double value);
    void distance(SP<CTabletTool> tool, double value);
    void rotation(SP<CTabletTool> tool, double value);
    void slider(SP<CTabletTool> tool, double value);
    void wheel(SP<CTabletTool> tool, double value);
    void tilt(SP<CTabletTool> tool, const Vector2D& value);
    void up(SP<CTabletTool> tool);
    void down(SP<CTabletTool> tool);
    void proximityIn(SP<CTabletTool> tool, SP<CTablet> tablet, SP<CWLSurfaceResource> surf);
    void proximityOut(SP<CTabletTool> tool);
    void buttonTool(SP<CTabletTool> tool, uint32_t button, uint32_t state);
    void motion(SP<CTabletTool> tool, const Vector2D& value);

    // Tablet pad events
    void mode(SP<CTabletPad> pad, uint32_t group, uint32_t mode, uint32_t timeMs);
    void buttonPad(SP<CTabletPad> pad, uint32_t button, uint32_t timeMs, uint32_t state);
    void strip(SP<CTabletPad> pad, uint32_t strip, double position, bool finger, uint32_t timeMs);
    void ring(SP<CTabletPad> pad, uint32_t ring, double position, bool finger, uint32_t timeMs);

  private:
    void onManagerResourceDestroy(wl_resource* res);
    void destroyResource(CTabletSeat* resource);
    void destroyResource(CTabletToolV2Resource* resource);
    void destroyResource(CTabletV2Resource* resource);
    void destroyResource(CTabletPadV2Resource* resource);
    void destroyResource(CTabletPadGroupV2Resource* resource);
    void destroyResource(CTabletPadRingV2Resource* resource);
    void destroyResource(CTabletPadStripV2Resource* resource);
    void onGetSeat(CZwpTabletManagerV2* pMgr, uint32_t id, wl_resource* seat);

    //
    std::vector<UP<CZwpTabletManagerV2>>       m_vManagers;
    std::vector<SP<CTabletSeat>>               m_vSeats;
    std::vector<SP<CTabletToolV2Resource>>     m_vTools;
    std::vector<SP<CTabletV2Resource>>         m_vTablets;
    std::vector<SP<CTabletPadV2Resource>>      m_vPads;
    std::vector<SP<CTabletPadGroupV2Resource>> m_vGroups;
    std::vector<SP<CTabletPadRingV2Resource>>  m_vRings;
    std::vector<SP<CTabletPadStripV2Resource>> m_vStrips;

    // registered
    std::vector<WP<CTablet>>     tablets;
    std::vector<WP<CTabletTool>> tools;
    std::vector<WP<CTabletPad>>  pads;

    // FIXME: rings and strips are broken, I don't understand how this shit works.
    // It's 2am.
    SP<CTabletPadRingV2Resource>  ringForID(SP<CTabletPad> pad, uint32_t id);
    SP<CTabletPadStripV2Resource> stripForID(SP<CTabletPad> pad, uint32_t id);

    friend class CTabletSeat;
    friend class CTabletToolV2Resource;
    friend class CTabletV2Resource;
    friend class CTabletPadV2Resource;
    friend class CTabletPadGroupV2Resource;
    friend class CTabletPadRingV2Resource;
    friend class CTabletPadStripV2Resource;
};

namespace PROTO {
    inline UP<CTabletV2Protocol> tablet;
};