input: minor fixes and cleanups for scroll-factor

This commit is contained in:
Isaac Freund
2024-04-16 13:25:12 +02:00
parent 8a3018a311
commit df5cb5dfe8
5 changed files with 28 additions and 12 deletions

View File

@ -313,8 +313,16 @@ fn handleAxis(listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Point
cursor.seat.wlr_seat.pointerNotifyAxis(
event.time_msec,
event.orientation,
event.delta * device.scroll_factor,
@intFromFloat(@as(f32, @floatFromInt(event.delta_discrete)) * device.scroll_factor),
event.delta * device.config.scroll_factor,
@intFromFloat(math.clamp(
@round(@as(f32, @floatFromInt(event.delta_discrete)) * device.config.scroll_factor),
// It seems that clamping to exactly the bounds of an i32 is insufficient to make the
// @intFromFloat() call safe due to the max/min i32 not being exactly representable
// by an f32. Dividing by 2 is a low effort way to ensure the value is in bounds and
// allow users to set their scroll-factor to inf without crashing river.
math.minInt(i32) / 2,
math.maxInt(i32) / 2,
)),
event.source,
);
}