Skip to content
Myr

wayland: improve scrolling with mouse wheel and touchpad

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

* Prefer "discrete" events, if available (mouse wheel with distinct scroll lengths/"clicks"). * Ignore horizontal scroll events * Don't scroll one entry on each scroll event; accumulate the scroll amount until we reach the threshold. * Threshold currently set to "20", because that's what each discrete scroll event corresponds to with my mouse, and because it "feels" right when scrolling. * Immediately reset the accumulated scroll amount when the scroll direction is reversed. Closes #673§

authored by Daniel Eklöf · committed by Daniel Eklöf · parent a813b9e · Browse files · 3 files+66 added−9 removed
This commit

State

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

Diff stats

3 files+66 added−9 removed

  • other:+66 added−9 removed

3 files+66 added−9 removed

modified:CHANGELOG.md+2 added
48 unmodified lines
49* `--with-nth` and `--accept-nth` crashing if a column is empty50 (e.g. `\tsecond column`, or `first\t\tthird`) ([#658][658])51* Regression: `--accept-nth=0` and `--with-nth=0` not being treated as52 if not specified at all ([#670][670]).53* Improved scrolling with mouse wheel and touchpad ([#673][673]).5455[658]: https://codeberg.org/dnkl/fuzzel/issues/65856[670]: https://codeberg.org/dnkl/fuzzel/issues/67057[673]: https://codeberg.org/dnkl/fuzzel/issues/673585960### Security61### Contributors
1048 unmodified lines
modified:wayland.c+61 added-9 removed
1219 unmodified lines
1220 uint32_t time, uint32_t axis, wl_fixed_t value)1221{1222 struct seat *seat = data;1223 struct wayland *wayl = seat->wayl;1224 if (!wayl->enable_mouse) return;1225 bool refresh = false;12241227 if (value < 0) {1228 refresh = matches_selected_prev(wayl->matches, true);1229 } else if (value > 0) {1230 refresh = matches_selected_next(wayl->matches, true);1231 }1225 if (!wayl->enable_mouse)1226 return;12271233 if (refresh) {1234 select_hovered_match(seat, true);1228 if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL)1229 return;12301231 const double amount = wl_fixed_to_double(value);12321233 if (signbit(seat->pointer.accumulated_scroll) != signbit(amount)) {1234 /* Reversed direction, reset accumulated */1235 seat->pointer.accumulated_scroll = 0.;1236 }12371238 seat->pointer.accumulated_scroll += amount;1239}12401241static void1242wl_pointer_frame(void *data, struct wl_pointer *wl_pointer)1243{1244 const double threshold = 20;12451246 struct seat *seat = data;1247 struct wayland *wayl = seat->wayl;12481249 if (seat->pointer.discrete_used) {1250 seat->pointer.discrete_used = false;1251 return;1252 }12531254 if (!wayl->enable_mouse)1255 return;12561257 bool refresh = false;12581259 while (fabs(seat->pointer.accumulated_scroll) > threshold) {1260 if (seat->pointer.accumulated_scroll > 0.) {1261 seat->pointer.accumulated_scroll -= threshold;1262 refresh = matches_selected_next(wayl->matches, true);1263 } else {1264 seat->pointer.accumulated_scroll += threshold;1265 refresh = matches_selected_prev(wayl->matches, true);1266 }1267 }12681269 if (refresh)1270 select_hovered_match(seat, true);1271}12721273static void1274wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer,
10 unmodified lines
1285static void1286wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,1287 uint32_t axis, int32_t discrete)1288{1289 struct seat *seat = data;1290 struct wayland *wayl = seat->wayl;12911292 if (!wayl->enable_mouse)1293 return;12941295 if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL)1296 return;12971298 seat->pointer.discrete_used = true;12991300 bool refresh = false;1301 if (discrete > 0) {1302 for (int i = 0; i < discrete; i++)1303 refresh = matches_selected_next(wayl->matches, true);1304 } else {1305 for (int i = 0; i < -discrete; i++)1306 refresh = matches_selected_prev(wayl->matches, true);1307 }13081309 if (refresh)1310 select_hovered_match(seat, true);1311}13121313static const struct wl_pointer_listener pointer_listener = {1314 .enter = wl_pointer_enter,
1807 unmodified lines
modified:wayland.h+3 added
54 unmodified lines
55 struct wp_viewport *viewport;56 struct wl_cursor_theme *theme;57 struct wl_cursor *cursor;58 float scale;5960 bool discrete_used;61 double accumulated_scroll;62 } pointer;6364 struct wl_touch *wl_touch;65 struct {
48 unmodified lines