Skip to content
Myr

fixup: Refine touchscreen support.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- reverse scroll direction - tap-to-select - smoother scrolling.

authored by Mark Stosberg · committed by markstos · parent 0e9c79b · Browse files · 2 files+73 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+73 added−15 removed

  • other:+73 added−15 removed

2 files+73 added−15 removed

modified:wayland.c+67 added-13 removed
1 unmodified line
23#include <ctype.h>4#include <errno.h>5#include <locale.h>6#include <math.h>7#include <poll.h>8#include <stdlib.h>9#include <string.h>10#include <unistd.h>
1180 unmodified lines
1191 wl_fixed_t x, wl_fixed_t y)1192{1193 struct seat *seat = data;11941194 /* Only track one touch at a time for scrolling */1195 /* Only track one touch at a time */1196 if (seat->touch.active_touch.scrolling)1197 return;11981199 seat->touch.active_touch.id = id;1200 seat->touch.active_touch.start_x = wl_fixed_to_double(x);1201 seat->touch.active_touch.start_y = wl_fixed_to_double(y);1202 seat->touch.active_touch.current_x = wl_fixed_to_double(x);1203 seat->touch.active_touch.current_y = wl_fixed_to_double(y);1204 seat->touch.active_touch.last_y = wl_fixed_to_double(y);1205 seat->touch.active_touch.scrolling = true;1206 seat->touch.active_touch.is_tap = true;1207 seat->touch.active_touch.start_time = time;1208 seat->touch.active_touch.accumulated_scroll = 0.0;1209 seat->touch.serial = serial;1210}12111212static void1213wl_touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial,1214 uint32_t time, int32_t id)1215{1216 struct seat *seat = data;1217 struct wayland *wayl = seat->wayl;12181219 if (seat->touch.active_touch.id == id) {1220 /* Check if this was a tap (no significant movement and quick) */1221 if (seat->touch.active_touch.is_tap) {1222 double dx = seat->touch.active_touch.current_x - seat->touch.active_touch.start_x;1223 double dy = seat->touch.active_touch.current_y - seat->touch.active_touch.start_y;1224 double distance = sqrt(dx * dx + dy * dy);1225 uint32_t duration = time - seat->touch.active_touch.start_time;12261227 /* Tap threshold: less than 10 pixels movement and under 500ms */1228 if (distance < 10.0 && duration < 500) {1229 /* Convert touch coordinates to match selection */1230 int touch_y = (int)seat->touch.active_touch.start_y;1231 size_t tapped_row = render_get_row_num(wayl->render, touch_y, wayl->matches);12321233 /* If user tapped on a valid row, select and execute it */1234 if (matches_idx_select(wayl->matches, tapped_row)) {1235 execute_selected(seat, false, -1);1236 } else {1237 /* Tapped on empty area or input field - focus input */1238 wayl_refresh(wayl);1239 }1240 }1241 }12421243 seat->touch.active_touch.scrolling = false;1244 seat->touch.active_touch.id = -1;1245 }1246}
6 unmodified lines
12531254 if (!seat->touch.active_touch.scrolling || seat->touch.active_touch.id != id)1255 return;12561257 double new_x = wl_fixed_to_double(x);1258 double new_y = wl_fixed_to_double(y);1227 double delta_y = seat->touch.active_touch.current_y - new_y;12591260 /* Update current position */1261 seat->touch.active_touch.current_x = new_x;1262 seat->touch.active_touch.current_y = new_y;12631264 /* Check if movement is too large to be a tap */1265 double dx = new_x - seat->touch.active_touch.start_x;1266 double dy = new_y - seat->touch.active_touch.start_y;1267 double distance = sqrt(dx * dx + dy * dy);12681269 if (distance > 10.0) {1270 seat->touch.active_touch.is_tap = false;1271 }12721273 /* Calculate accumulated scroll from last position */1274 double delta_y = new_y - seat->touch.active_touch.last_y;1275 seat->touch.active_touch.accumulated_scroll += delta_y;12761277 /* Reversed scrolling: positive delta_y (finger moving down) scrolls up in the list */1278 /* Threshold for scrolling - roughly equivalent to one line */1230 const double scroll_threshold = 20.0;1279 const double scroll_threshold = 15.0;12801232 if (delta_y > scroll_threshold) {1233 /* Scrolling up - select previous item */1234 matches_selected_prev(seat->wayl->matches, true);1235 wayl_refresh(seat->wayl);1236 seat->touch.active_touch.current_y = new_y;1237 } else if (delta_y < -scroll_threshold) {1238 /* Scrolling down - select next item */1239 matches_selected_next(seat->wayl->matches, true);1240 wayl_refresh(seat->wayl);1241 seat->touch.active_touch.current_y = new_y;1281 if (seat->touch.active_touch.accumulated_scroll > scroll_threshold) {1282 /* Finger moving down - select previous item (scroll up in list) */1283 if (matches_selected_prev(seat->wayl->matches, true)) {1284 wayl_refresh(seat->wayl);1285 }1286 seat->touch.active_touch.accumulated_scroll = 0.0;1287 } else if (seat->touch.active_touch.accumulated_scroll < -scroll_threshold) {1288 /* Finger moving up - select next item (scroll down in list) */1289 if (matches_selected_next(seat->wayl->matches, true)) {1290 wayl_refresh(seat->wayl);1291 }1292 seat->touch.active_touch.accumulated_scroll = 0.0;1293 }12941295 /* Update last position for next delta calculation */1296 seat->touch.active_touch.last_y = new_y;1297}12981299static void1300wl_touch_frame(void *data, struct wl_touch *wl_touch)
1679 unmodified lines
modified:wayland.h+6 added-2 removed
61 unmodified lines
62 struct {63 uint32_t serial;64 struct {65 int id;66 double start_y;67 double current_y;66 double start_x, start_y;67 double current_x, current_y;68 double last_y;69 bool scrolling;70 bool is_tap;71 uint32_t start_time;72 double accumulated_scroll;73 } active_touch;74 } touch;7576 struct wl_data_device *data_device;
32 unmodified lines