Skip to content

Commit 087cc7d

Browse files
committed
Drag lock and finger repositioning
1 parent 05c6863 commit 087cc7d

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

platforms/unix/vm-display-fbdev/sqUnixEvdevKeyMouse.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <getopt.h>
4747
#include <ctype.h>
4848
#include <signal.h>
49+
#include <time.h>
4950
#include <limits.h> /* PATH_MAX */
5051
#include <linux/input.h> /* /usr/include/linux/input.h */
5152
/* #include <X11/keysym.h> * /usr/include/X11/keysym.h */
@@ -134,9 +135,13 @@ struct ms
134135
int slots[NUM_SUPPORTED_SLOTS];
135136
int primary_tracking_id; /* -1 for none */
136137
int current_slot; /* -1 for none */
138+
139+
double tap_release_deadline;
140+
int tap_bit;
137141
};
138142

139143
#define TAP_START_TIMEOUT 0.18
144+
#define TAP_END_TIMEOUT 0.3
140145

141146
static struct ms mouseDev;
142147

@@ -260,13 +265,25 @@ static void printMouseState() {
260265
static void clearMouseButtons() { buttonState = 0 ; wheelDelta = 0; }
261266

262267
static void register_touch(int touch_count, double timestamp) {
263-
if (mouseDev.touching < touch_count) {
268+
if (mouseDev.tap_bit != 0) {
269+
mouseDev.touching = mouseDev.tap_bit;
270+
mouseDev.tap_release_deadline = 0;
271+
} else if (mouseDev.touching < touch_count) {
264272
mouseDev.touching = touch_count;
265273
}
266274
mouseDev.touch_change_time = timestamp;
267275
mouseDev.moved = 0;
268276
}
269277

278+
static double timestamp(void) {
279+
struct timespec ts;
280+
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
281+
perror("clock_gettime");
282+
abort();
283+
}
284+
return ts.tv_sec + ((double) ts.tv_nsec / 1000000000.0);
285+
}
286+
270287
static void updateMouseButtons(struct input_event* evt) {
271288
if (evt->type == EV_KEY) {
272289
double now = evt->input_event_sec + ((double) evt->input_event_usec / 1000000.0);
@@ -291,15 +308,19 @@ static void updateMouseButtons(struct input_event* evt) {
291308

292309
case BTN_TOUCH:
293310
if (mouseDev.touching > 0) {
294-
if ((now - mouseDev.touch_change_time) <= TAP_START_TIMEOUT) {
311+
if (mouseDev.tap_bit != 0) {
312+
// Release of a previous drag lock.
313+
mouseDev.tap_release_deadline = timestamp() + TAP_END_TIMEOUT;
314+
} else if ((now - mouseDev.touch_change_time) <= TAP_START_TIMEOUT) {
295315
// A tap.
296316
int bit = LeftMouseButtonBit;
297317
if (mouseDev.touching == 2) bit = 0;
298318
if (mouseDev.touching == 3) bit = RightMouseButtonBit;
299319
if (mouseDev.touching == 4) bit = MidMouseButtonBit;
300320
if (bit != 0) {
301321
enqueueMouseEvent(buttonState | bit, 0, 0);
302-
enqueueMouseEvent(buttonState & ~bit, 0, 0);
322+
mouseDev.tap_bit = bit;
323+
mouseDev.tap_release_deadline = timestamp() + TAP_END_TIMEOUT;
303324
}
304325
}
305326
}
@@ -646,6 +667,12 @@ static void processLibEvdevMouseEvents() {
646667
int i, read_size;
647668
int arrowCode, modifierBits; /* for Wheel delta sent as arrow keys */
648669

670+
if ((mouseDev.tap_release_deadline != 0) && (timestamp() >= mouseDev.tap_release_deadline)) {
671+
enqueueMouseEvent(buttonState & ~mouseDev.tap_bit, 0, 0);
672+
mouseDev.tap_bit = 0;
673+
mouseDev.tap_release_deadline = 0;
674+
}
675+
649676
read_size = read(mouseDev.fd, evt, sizeof(evt));
650677
if (read_size < (int) sizeof(struct input_event)) {
651678
return; /* asynch read */

0 commit comments

Comments
 (0)