labwc: right click emulation on Raspberry Pi touch display
Recently, I updated the Raspberry Pi OS on my Home Assistant RPI to the latest release. To my frustration, the switch from wayfire to labwc broke touchscreen support. While I didn’t necessarily need proper touch gestures, right-click emulation was a must.
After tinkering with rc.xml for a while, I was on the verge of giving up and reverting back to wayfire. However, aside from this issue, labwc was quite good overall. I was particularly sold on the out of box virtual keyboard support.
Long story short, I decided to take a look at the sources to see if I could hack something together fast. I haven’t yet had time to properly understand the code behind input management to turn this into proper upstream PR, but it works for now.
diff -ruN /tmp/labwc-0.8.2/src/input/cursor.c labwc-0.8.2/src/input/cursor.c
--- /tmp/labwc-0.8.2/src/input/cursor.c 2024-12-13 22:14:37.000000000 +0300
+++ labwc-0.8.2/src/input/cursor.c 2025-01-10 15:26:44.552519361 +0300
@@ -1260,6 +1260,21 @@
wlr_seat_pointer_notify_button(seat->seat, time_msec, button, state);
}
cursor_finish_button_release(seat, button);
+
+ if (time_msec - press_msec > 1000) { // emulate right click on long (1sec) press
+ notify = cursor_process_button_press(seat, BTN_RIGHT, time_msec);
+ if (notify) {
+ wlr_seat_pointer_notify_button(seat->seat, time_msec, BTN_RIGHT, 1);
+ }
+
+ notify = cursor_process_button_release(seat, BTN_RIGHT, time_msec);
+ if (notify) {
+ wlr_seat_pointer_notify_button(seat->seat, time_msec, BTN_RIGHT, 0);
+ }
+ cursor_finish_button_release(seat, BTN_RIGHT);
+
+ }
+
break;
}
wlr_seat_pointer_notify_frame(seat->seat);