✨ New Feature: Touchscreen scrolling
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Mark Stosberg · committed by markstos · parent 3e7c9a2 · Browse files · 2 files·+126 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Fixes: #435
Diff stats
2 files+126 added−0 removed
- other:+126 added−0 removed
Provenance
- Commit
0e9c79b- Tree
e2a6cd7- Author
Mark Stosberg <mark@stosberg.com>- Committer
markstos <markstos@noreply.codeberg.org>- Parent
3e7c9a2
2 files changed+126 added−0 removed
modified:wayland.c+115 added
286 unmodified lines287 wl_surface_destroy(seat->pointer.surface);288 if (seat->wl_pointer != NULL)289 wl_pointer_release(seat->wl_pointer);290 291+ if (seat->wl_touch != NULL)292+ wl_touch_release(seat->wl_touch);293+294 if (seat->wl_seat != NULL)295 wl_seat_release(seat->wl_seat);296 297 free(seat->clipboard.text);886 unmodified lines1184 .axis_discrete = wl_pointer_axis_discrete,1185 };1186 1187 static void1188+wl_touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial,1189+ uint32_t time, struct wl_surface *surface, int32_t id,1190+ wl_fixed_t x, wl_fixed_t y)1191+{1192+ struct seat *seat = data;1193+1194+ /* Only track one touch at a time for scrolling */1195+ if (seat->touch.active_touch.scrolling)1196+ return;1197+1198+ seat->touch.active_touch.id = id;1199+ seat->touch.active_touch.start_y = wl_fixed_to_double(y);1200+ seat->touch.active_touch.current_y = wl_fixed_to_double(y);1201+ seat->touch.active_touch.scrolling = true;1202+ seat->touch.serial = serial;1203+}1204+1205+static void1206+wl_touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial,1207+ uint32_t time, int32_t id)1208+{1209+ struct seat *seat = data;1210+1211+ if (seat->touch.active_touch.id == id) {1212+ seat->touch.active_touch.scrolling = false;1213+ seat->touch.active_touch.id = -1;1214+ }1215+}1216+1217+static void1218+wl_touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time,1219+ int32_t id, wl_fixed_t x, wl_fixed_t y)1220+{1221+ struct seat *seat = data;1222+1223+ if (!seat->touch.active_touch.scrolling || seat->touch.active_touch.id != id)1224+ return;1225+1226+ double new_y = wl_fixed_to_double(y);1227+ double delta_y = seat->touch.active_touch.current_y - new_y;1228+1229+ /* Threshold for scrolling - roughly equivalent to one line */1230+ const double scroll_threshold = 20.0;1231+1232+ 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;1242+ }1243+}1244+1245+static void1246+wl_touch_frame(void *data, struct wl_touch *wl_touch)1247+{1248+ /* Touch frame events group related touch events */1249+}1250+1251+static void1252+wl_touch_cancel(void *data, struct wl_touch *wl_touch)1253+{1254+ struct seat *seat = data;1255+ seat->touch.active_touch.scrolling = false;1256+ seat->touch.active_touch.id = -1;1257+}1258+1259+static void1260+wl_touch_shape(void *data, struct wl_touch *wl_touch, int32_t id,1261+ wl_fixed_t major, wl_fixed_t minor)1262+{1263+ /* Touch shape events - not needed for scrolling */1264+}1265+1266+static void1267+wl_touch_orientation(void *data, struct wl_touch *wl_touch, int32_t id,1268+ wl_fixed_t orientation)1269+{1270+ /* Touch orientation events - not needed for scrolling */1271+}1272+1273+static const struct wl_touch_listener touch_listener = {1274+ .down = wl_touch_down,1275+ .up = wl_touch_up,1276+ .motion = wl_touch_motion,1277+ .frame = wl_touch_frame,1278+ .cancel = wl_touch_cancel,1279+ .shape = wl_touch_shape,1280+ .orientation = wl_touch_orientation,1281+};1282+1283+static void1284 seat_handle_capabilities(void *data, struct wl_seat *wl_seat,1285 enum wl_seat_capability caps)1286 {1287 struct seat *seat = data;55 unmodified lines1343 seat->pointer.theme = NULL;1344 seat->pointer.cursor = NULL;1345 }1346 }1347+1348+ if (caps & WL_SEAT_CAPABILITY_TOUCH) {1349+ if (seat->wl_touch == NULL) {1350+ seat->wl_touch = wl_seat_get_touch(wl_seat);1351+ wl_touch_add_listener(seat->wl_touch, &touch_listener, seat);1352+1353+ /* Initialize touch state */1354+ seat->touch.active_touch.id = -1;1355+ seat->touch.active_touch.scrolling = false;1356+ }1357+ } else {1358+ if (seat->wl_touch != NULL) {1359+ wl_touch_release(seat->wl_touch);1360+ seat->wl_touch = NULL;1361+ }1362+ }1363 }1364 1365 static void1366 seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name)1559 unmodified linesmodified:wayland.h+11 added
56 unmodified lines57 struct wl_cursor *cursor;58 float scale;59 } pointer;60 61+ struct wl_touch *wl_touch;62+ struct {63+ uint32_t serial;64+ struct {65+ int id;66+ double start_y;67+ double current_y;68+ bool scrolling;69+ } active_touch;70+ } touch;71+72 struct wl_data_device *data_device;73 struct zwp_primary_selection_device_v1 *primary_selection_device;74 75 bool is_pasting;29 unmodified lines