mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-08 08:20:59 -04:00
input: mouse_scroll(): refactor
This commit is contained in:
parent
cb41db8596
commit
04c1bab7b0
1 changed files with 35 additions and 36 deletions
71
input.c
71
input.c
|
|
@ -1613,6 +1613,20 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
alternate_scroll(struct seat *seat, int amount, int button)
|
||||||
|
{
|
||||||
|
if (seat->wl_keyboard == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xkb_keycode_t key = button == BTN_BACK
|
||||||
|
? seat->kbd.key_arrow_up : seat->kbd.key_arrow_down;
|
||||||
|
|
||||||
|
for (int i = 0; i < amount; i++)
|
||||||
|
keyboard_key(seat, NULL, seat->kbd.serial, 0, key - 8, XKB_KEY_DOWN);
|
||||||
|
keyboard_key(seat, NULL, seat->kbd.serial, 0, key - 8, XKB_KEY_UP);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mouse_scroll(struct seat *seat, int amount)
|
mouse_scroll(struct seat *seat, int amount)
|
||||||
{
|
{
|
||||||
|
|
@ -1620,48 +1634,33 @@ mouse_scroll(struct seat *seat, int amount)
|
||||||
assert(term != NULL);
|
assert(term != NULL);
|
||||||
|
|
||||||
int button = amount < 0 ? BTN_BACK : BTN_FORWARD;
|
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);
|
amount = abs(amount);
|
||||||
|
|
||||||
|
if (term->mouse_tracking == MOUSE_NONE) {
|
||||||
if ((button == BTN_BACK || button == BTN_FORWARD) &&
|
if (term->grid == &term->alt) {
|
||||||
term->grid == &term->alt && term->alt_scrolling &&
|
if (term->alt_scrolling)
|
||||||
term->mouse_tracking == MOUSE_NONE)
|
alternate_scroll(seat, amount, button);
|
||||||
{
|
} else {
|
||||||
/*
|
if (button == BTN_BACK)
|
||||||
* alternateScroll/faux scrolling - translate mouse
|
cmd_scrollback_up(term, amount);
|
||||||
* "back"/"forward" to up/down keys
|
else
|
||||||
*/
|
cmd_scrollback_down(term, amount);
|
||||||
|
|
||||||
if (seat->wl_keyboard != NULL) {
|
|
||||||
xkb_keycode_t key = button == BTN_BACK
|
|
||||||
? seat->kbd.key_arrow_up : seat->kbd.key_arrow_down;
|
|
||||||
|
|
||||||
for (int i = 0; i < amount; i++)
|
|
||||||
keyboard_key(seat, NULL, seat->kbd.serial, 0, key - 8, XKB_KEY_DOWN);
|
|
||||||
keyboard_key(seat, NULL, seat->kbd.serial, 0, key - 8, XKB_KEY_UP);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!term_mouse_grabbed(term, seat) &&
|
||||||
if (!term_mouse_grabbed(term, seat) &&
|
seat->mouse.col >= 0 && seat->mouse.row >= 0)
|
||||||
seat->mouse.col >= 0 && seat->mouse.row >= 0)
|
{
|
||||||
{
|
assert(seat->mouse.col < term->cols);
|
||||||
assert(seat->mouse.col < term->cols);
|
assert(seat->mouse.row < term->rows);
|
||||||
assert(seat->mouse.row < term->rows);
|
|
||||||
|
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
term_mouse_down(
|
term_mouse_down(
|
||||||
term, button, seat->mouse.row, seat->mouse.col,
|
|
||||||
seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
term_mouse_up(
|
|
||||||
term, button, seat->mouse.row, seat->mouse.col,
|
term, button, seat->mouse.row, seat->mouse.col,
|
||||||
seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl);
|
seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl);
|
||||||
} else
|
}
|
||||||
scrollback(term, amount);
|
|
||||||
|
term_mouse_up(
|
||||||
|
term, button, seat->mouse.row, seat->mouse.col,
|
||||||
|
seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue