Skip to content

Commit

Permalink
fix: touchpad relative motion
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Nov 20, 2023
1 parent a868419 commit 3224a1c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/cpp/touchpad_relative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ int SetupUinputDevice() {

void start() {
signed int last_absX, last_absY;
bool touch_down = false;
struct input_event event {}, ie {};
while(true) {
poll(poll_fds.data(), poll_fds.size(), -1);
Expand All @@ -70,7 +71,7 @@ void start() {
if (read(poll_fds[i].fd, &event, sizeof(event)) == sizeof(struct input_event)){
switch (event.code) {
case ABS_X:
if (event.value <= 1) break;
if (!touch_down || event.value <= 1) break;
ie.type = EV_REL;
ie.code = REL_X;
ie.value = event.value - last_absX;
Expand All @@ -79,7 +80,7 @@ void start() {
break;

case ABS_Y:
if (event.value <= 1) break;
if (!touch_down || event.value <= 1) break;
ie.type = EV_REL;
ie.code = REL_Y;
ie.value = event.value - last_absY;
Expand All @@ -92,6 +93,11 @@ void start() {
case BTN_MIDDLE:
write(uinput_fds[i], &event, sizeof(event));
break;

case BTN_TOUCH:
touch_down = event.value == 1;
if (touch_down) printf("x %d\n", event.value);
break;
}
ie = input_event{0, 0, EV_SYN, SYN_REPORT, 0};
write(uinput_fds[i], &ie, sizeof(ie));
Expand Down

0 comments on commit 3224a1c

Please sign in to comment.