@@ -43,6 +43,15 @@ class TouchDevice {
43
43
// The daemon configuration.
44
44
core::Config m_config;
45
45
46
+ // Information about the device that the daemon is reading from.
47
+ core::DeviceInfo m_info;
48
+
49
+ // How far a contact can be outside of the touch area and still get registered.
50
+ f64 m_overshoot = 0 ;
51
+
52
+ // Whether all inputs will be lifted once a palm is registered.
53
+ bool m_disable_on_palm = false ;
54
+
46
55
// The indices of the contacts in the current frame.
47
56
std::set<usize> m_current {};
48
57
@@ -59,18 +68,41 @@ class TouchDevice {
59
68
bool m_enabled = true ;
60
69
61
70
public:
62
- TouchDevice (const core::Config &config, const core::DeviceInfo &info) : m_config {config}
71
+ TouchDevice (const core::Config &config, const core::DeviceInfo &info)
72
+ : m_config {config},
73
+ m_info {info}
63
74
{
64
- m_uinput->set_name (" Touchscreen" );
75
+ if (info.is_touchscreen ())
76
+ m_uinput->set_name (" Touchscreen" );
77
+ else
78
+ m_uinput->set_name (" Touchpad" );
79
+
65
80
m_uinput->set_vendor (info.vendor );
66
81
m_uinput->set_product (info.product );
67
82
68
83
m_uinput->set_evbit (EV_ABS);
69
84
m_uinput->set_evbit (EV_KEY);
70
85
71
- m_uinput->set_propbit (INPUT_PROP_DIRECT);
72
86
m_uinput->set_keybit (BTN_TOUCH);
73
87
88
+ if (info.is_touchpad ()) {
89
+ m_uinput->set_keybit (BTN_TOOL_FINGER);
90
+ m_uinput->set_keybit (BTN_TOOL_DOUBLETAP);
91
+ m_uinput->set_keybit (BTN_TOOL_TRIPLETAP);
92
+ m_uinput->set_keybit (BTN_TOOL_QUADTAP);
93
+ m_uinput->set_keybit (BTN_TOOL_QUINTTAP);
94
+
95
+ m_uinput->set_propbit (INPUT_PROP_POINTER);
96
+
97
+ m_overshoot = config.touchpad_overshoot ;
98
+ m_disable_on_palm = config.touchpad_disable_on_palm ;
99
+ } else {
100
+ m_uinput->set_propbit (INPUT_PROP_DIRECT);
101
+
102
+ m_overshoot = config.touchscreen_overshoot ;
103
+ m_disable_on_palm = config.touchscreen_disable_on_palm ;
104
+ }
105
+
74
106
const f64 diag = std::hypot (config.width , config.height );
75
107
76
108
// Resolution for X / Y is expected to be units/mm.
@@ -98,7 +130,7 @@ class TouchDevice {
98
130
*/
99
131
void update (const std::vector<contacts::Contact<f64>> &contacts)
100
132
{
101
- // If the touchscreen is disabled ignore all inputs.
133
+ // If the touch device is disabled ignore all inputs.
102
134
if (!m_enabled)
103
135
return ;
104
136
@@ -114,7 +146,7 @@ class TouchDevice {
114
146
}
115
147
116
148
/* !
117
- * Disables the touchscreen and lifts all contacts.
149
+ * Disables the touch device and lifts all contacts.
118
150
*/
119
151
void disable ()
120
152
{
@@ -130,25 +162,25 @@ class TouchDevice {
130
162
}
131
163
132
164
/* !
133
- * Enables the touchscreen .
165
+ * Enables the touch device .
134
166
*/
135
167
void enable ()
136
168
{
137
169
m_enabled = true ;
138
170
}
139
171
140
172
/* !
141
- * Whether the touchscreen is disabled or enabled.
173
+ * Whether the touch device is disabled or enabled.
142
174
*
143
- * @return true if the touchscreen is enabled.
175
+ * @return true if the touch device is enabled.
144
176
*/
145
177
[[nodiscard]] bool enabled () const
146
178
{
147
179
return m_enabled;
148
180
}
149
181
150
182
/* !
151
- * Whether the touchscreen is currently active.
183
+ * Whether the touch device is currently active.
152
184
*
153
185
* @return true if there are any active inputs.
154
186
*/
@@ -189,14 +221,14 @@ class TouchDevice {
189
221
}
190
222
191
223
/* !
192
- * Checks if the touchscreen should be disabled because of a palm on the screen .
224
+ * Checks if the touch device should be disabled because of a palm.
193
225
*
194
226
* @param[in] contacts All currently active contacts.
195
227
* @return true if all contacts should be lifted.
196
228
*/
197
229
[[nodiscard]] bool is_blocked (const std::vector<contacts::Contact<f64>> &contacts) const
198
230
{
199
- if (!m_config. touchscreen_disable_on_palm )
231
+ if (!m_disable_on_palm )
200
232
return false ;
201
233
202
234
return std::any_of (contacts.cbegin (), contacts.cend (), [&](const auto &c) {
@@ -213,8 +245,8 @@ class TouchDevice {
213
245
{
214
246
bool reset_singletouch = true ;
215
247
216
- const f64 ox = m_config. touchscreen_overshoot / m_config.width ;
217
- const f64 oy = m_config. touchscreen_overshoot / m_config.height ;
248
+ const f64 ox = m_overshoot / m_config.width ;
249
+ const f64 oy = m_overshoot / m_config.height ;
218
250
219
251
for (const contacts::Contact<f64> &contact : contacts) {
220
252
// Ignore contacts without an index
@@ -366,6 +398,14 @@ class TouchDevice {
366
398
void lift_singletouch () const
367
399
{
368
400
m_uinput->emit (EV_KEY, BTN_TOUCH, 0 );
401
+
402
+ if (m_info.is_touchpad ()) {
403
+ m_uinput->emit (EV_KEY, BTN_TOOL_FINGER, 0 );
404
+ m_uinput->emit (EV_KEY, BTN_TOOL_DOUBLETAP, 0 );
405
+ m_uinput->emit (EV_KEY, BTN_TOOL_TRIPLETAP, 0 );
406
+ m_uinput->emit (EV_KEY, BTN_TOOL_QUADTAP, 0 );
407
+ m_uinput->emit (EV_KEY, BTN_TOOL_QUINTTAP, 0 );
408
+ }
369
409
}
370
410
371
411
/* !
@@ -384,6 +424,15 @@ class TouchDevice {
384
424
const i32 y = casts::to<i32>(std::round (mean.y () * MAX_Y));
385
425
386
426
m_uinput->emit (EV_KEY, BTN_TOUCH, 1 );
427
+
428
+ if (m_info.is_touchpad ()) {
429
+ m_uinput->emit (EV_KEY, BTN_TOOL_FINGER, m_current.size () == 1 ? 1 : 0 );
430
+ m_uinput->emit (EV_KEY, BTN_TOOL_DOUBLETAP, m_current.size () == 2 ? 1 : 0 );
431
+ m_uinput->emit (EV_KEY, BTN_TOOL_TRIPLETAP, m_current.size () == 3 ? 1 : 0 );
432
+ m_uinput->emit (EV_KEY, BTN_TOOL_QUADTAP, m_current.size () == 4 ? 1 : 0 );
433
+ m_uinput->emit (EV_KEY, BTN_TOOL_QUINTTAP, m_current.size () >= 5 ? 1 : 0 );
434
+ }
435
+
387
436
m_uinput->emit (EV_ABS, ABS_X, x);
388
437
m_uinput->emit (EV_ABS, ABS_Y, y);
389
438
}
0 commit comments