-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMtTranslate.hpp
168 lines (167 loc) · 4.23 KB
/
MtTranslate.hpp
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
/*
* This file is part of the Screentouch project. It is subject to the GPLv3
* license terms in the LICENSE file found in the top-level directory of this
* distribution and at
* https://github.com/jjackowski/screentouch/blob/master/LICENSE.
* No part of the Screentouch project, including this file, may be copied,
* modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*
* Copyright (C) 2018 Jeff Jackowski
*/
#include "EvdevOutput.hpp"
#include <chrono>
/**
* Multi-touch translator.
* @author Jeff Jackowski
*/
class MtTranslate {
/**
* Much less useful than anticipated, but may be more useful if the
* locations of each spot matter in a future operation.
*/
struct SlotState {
/**
* Tracking ID.
*/
int tid;
int x;
int y;
SlotState() : tid(-1) { }
};
typedef SlotState StateHist[2];
/**
* The touchscreen input device.
*/
EvdevShared evdev;
/**
* The user-input device to which the translated input events are output.
*/
EvdevOutput eo;
/**
* Data on each of the "slots", stateful contact points reported by
* multi-touch protocol B.
*/
std::vector<StateHist> slots;
typedef std::chrono::steady_clock::time_point timepoint;
typedef std::chrono::steady_clock::duration duration;
/**
* The time when some event occured that may need to be referenced later.
* For instance, if the user taps the screen, the time is used in case the
* user quickly touches the screen again for a drag operation.
*/
timepoint eventtime;
/**
* Index of the most current touch information in the StateHist arrays.
*/
int cur;
/**
* Index of the old touch information in the StateHist arrays.
*/
int old;
/**
* The currently updating slot from the multi-touch input, protocol B.
*/
int slot;
/**
* The number of slots in use, which is the number of contact points.
*/
int scnt;
/**
* The number of contacts that the operation is responding to. This may be
* different from @a scnt.
*/
int cntctCur;
/**
* The value of @a cntctCur at the end of synEvent() the last time the
* function ran.
*/
int cntctOld;
/**
* The location used for the cursor. It is the previous location for most
* of synEvent().
*/
int cursorX;
/**
* The location used for the cursor. It is the previous location for most
* of synEvent().
*/
int cursorY;
/**
* The set of mouse-like input operations that are implemented.
*/
enum Operation {
None,
ReleaseLeft,
ReleaseRight,
ReleaseMiddle,
DragLeft,
DragRight,
DragMiddle,
MoveCursor,
ScrollVert,
ScrollHoriz,
Scroll2D // 3-finger scroll; seems to not work with Firefox
};
/**
* The current mouse-like input operation.
*/
int curOp;
/**
* The minimum distance an initial contact must move before it is considered
* to have moved. Mitigates apparent noise in the location.
*/
int moveDist;
/**
* Responds to ABS_MT_SLOT input events.
*/
void slotEvent(std::int32_t val);
/**
* Responds to ABS_MT_TRACKING_ID input events.
*/
void trackEvent(std::int32_t val);
/**
* Responds to ABS_MT_POSITION_X input events.
*/
void xPosEvent(std::int32_t val);
/**
* Responds to ABS_MT_POSITION_Y input events.
*/
void yPosEvent(std::int32_t val);
/**
* Responds to SYN_REPORT input events.
*/
void synEvent();
/**
* Initialization function called by all constructors.
*/
void init();
/**
* A length of time between tap-like contacts of the screen used to
* implement different behavior when an operation requires mutlple contacts
* over time.
*/
static constexpr std::chrono::milliseconds tapTime =
std::chrono::milliseconds(192);
/**
* Logs to stdout what is going on for debugging.
*/
void logstate() const;
public:
/**
* Makes a new input translator using the given device for input.
*/
MtTranslate(const EvdevShared &ev, int movethres);
/**
* Makes a new input translator using the given device for input.
*/
MtTranslate(EvdevShared &&ev, int movethres);
// disconnect signal functions given to evdev
~MtTranslate();
/**
* Call to handle single-tap button presses. These occur after the tap
* when no other touch input is given. As a result, it cannot be in
* synEvent() because there will not be an event.
*/
void timeoutHandle();
};