mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
mouse: use discrete axis event if available
This improves the scroll experience with certain devices
This commit is contained in:
parent
bb3e33948f
commit
e88cf4c8c8
3 changed files with 39 additions and 25 deletions
59
input.c
59
input.c
|
|
@ -410,37 +410,54 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mouse_scroll(struct terminal *term, int amount)
|
||||
{
|
||||
int button = amount < 0 ? BTN_BACK : BTN_FORWARD;
|
||||
|
||||
void (*scrollback)(struct terminal *term, int rows)
|
||||
= amount < 0 ? &cmd_scrollback_up : &cmd_scrollback_down;
|
||||
|
||||
amount = abs(amount);
|
||||
|
||||
for (int i = 0; i < amount; i++)
|
||||
term_mouse_down(term, button, term->mouse.row, term->mouse.col,
|
||||
term->kbd.shift, term->kbd.alt, term->kbd.ctrl);
|
||||
|
||||
scrollback(term, amount);
|
||||
}
|
||||
|
||||
static void
|
||||
wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
|
||||
uint32_t time, uint32_t axis, wl_fixed_t value)
|
||||
{
|
||||
struct terminal *term = data;
|
||||
|
||||
/* TODO: generate button event for BTN_FORWARD/BTN_BACK? */
|
||||
|
||||
if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL)
|
||||
return;
|
||||
|
||||
int amount = wl_fixed_to_int(value);
|
||||
struct terminal *term = data;
|
||||
if (term->mouse.have_discrete)
|
||||
return;
|
||||
|
||||
if (amount < 0) {
|
||||
for (int i = 0; i < -amount; i++) {
|
||||
term_mouse_down(term, BTN_BACK, term->mouse.row, term->mouse.col,
|
||||
term->kbd.shift, term->kbd.alt, term->kbd.ctrl);
|
||||
}
|
||||
cmd_scrollback_up(term, -amount);
|
||||
} else {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
term_mouse_down(term, BTN_FORWARD, term->mouse.row, term->mouse.col,
|
||||
term->kbd.shift, term->kbd.alt, term->kbd.ctrl);
|
||||
}
|
||||
cmd_scrollback_down(term, amount);
|
||||
}
|
||||
mouse_scroll(term, wl_fixed_to_int(value));
|
||||
}
|
||||
|
||||
static void
|
||||
wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,
|
||||
uint32_t axis, int32_t discrete)
|
||||
{
|
||||
if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL)
|
||||
return;
|
||||
|
||||
struct terminal *term = data;
|
||||
term->mouse.have_discrete = true;
|
||||
mouse_scroll(term, discrete);
|
||||
}
|
||||
|
||||
static void
|
||||
wl_pointer_frame(void *data, struct wl_pointer *wl_pointer)
|
||||
{
|
||||
struct terminal *term = data;
|
||||
term->mouse.have_discrete = false;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -455,12 +472,6 @@ wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer,
|
|||
{
|
||||
}
|
||||
|
||||
static void
|
||||
wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer,
|
||||
uint32_t axis, int32_t discrete)
|
||||
{
|
||||
}
|
||||
|
||||
const struct wl_pointer_listener pointer_listener = {
|
||||
.enter = wl_pointer_enter,
|
||||
.leave = wl_pointer_leave,
|
||||
|
|
|
|||
2
main.c
2
main.c
|
|
@ -125,7 +125,7 @@ handle_global(void *data, struct wl_registry *registry,
|
|||
|
||||
else if (strcmp(interface, wl_seat_interface.name) == 0) {
|
||||
term->wl.seat = wl_registry_bind(
|
||||
term->wl.registry, name, &wl_seat_interface, 4);
|
||||
term->wl.registry, name, &wl_seat_interface, 5);
|
||||
wl_seat_add_listener(term->wl.seat, &seat_listener, term);
|
||||
wl_display_roundtrip(term->wl.display);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -288,6 +288,9 @@ struct terminal {
|
|||
|
||||
int last_button;
|
||||
struct timeval last_time;
|
||||
|
||||
/* We used a discrete axis event in the current pointer frame */
|
||||
bool have_discrete;
|
||||
} mouse;
|
||||
|
||||
struct coord cursor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue