Skip to content
Myr

✨ 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

2 files+126 added−0 removed

modified:wayland.c+115 added
286 unmodified lines
287 wl_surface_destroy(seat->pointer.surface);288 if (seat->wl_pointer != NULL)289 wl_pointer_release(seat->wl_pointer);290291 if (seat->wl_touch != NULL)292 wl_touch_release(seat->wl_touch);293294 if (seat->wl_seat != NULL)295 wl_seat_release(seat->wl_seat);296297 free(seat->clipboard.text);
886 unmodified lines
1184 .axis_discrete = wl_pointer_axis_discrete,1185};11861187static void1188wl_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;11931194 /* Only track one touch at a time for scrolling */1195 if (seat->touch.active_touch.scrolling)1196 return;11971198 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}12041205static void1206wl_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;12101211 if (seat->touch.active_touch.id == id) {1212 seat->touch.active_touch.scrolling = false;1213 seat->touch.active_touch.id = -1;1214 }1215}12161217static void1218wl_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;12221223 if (!seat->touch.active_touch.scrolling || seat->touch.active_touch.id != id)1224 return;12251226 double new_y = wl_fixed_to_double(y);1227 double delta_y = seat->touch.active_touch.current_y - new_y;12281229 /* Threshold for scrolling - roughly equivalent to one line */1230 const double scroll_threshold = 20.0;12311232 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}12441245static void1246wl_touch_frame(void *data, struct wl_touch *wl_touch)1247{1248 /* Touch frame events group related touch events */1249}12501251static void1252wl_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}12581259static void1260wl_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}12651266static void1267wl_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}12721273static 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};12821283static void1284seat_handle_capabilities(void *data, struct wl_seat *wl_seat,1285 enum wl_seat_capability caps)1286{1287 struct seat *seat = data;
55 unmodified lines
1343 seat->pointer.theme = NULL;1344 seat->pointer.cursor = NULL;1345 }1346 }13471348 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);13521353 /* 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}13641365static void1366seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name)
1559 unmodified lines
modified:wayland.h+11 added
56 unmodified lines
57 struct wl_cursor *cursor;58 float scale;59 } pointer;6061 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;7172 struct wl_data_device *data_device;73 struct zwp_primary_selection_device_v1 *primary_selection_device;7475 bool is_pasting;
29 unmodified lines