mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05: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
|
||||
mouse_scroll(struct seat *seat, int amount)
|
||||
{
|
||||
|
|
@ -1620,48 +1634,33 @@ mouse_scroll(struct seat *seat, int amount)
|
|||
assert(term != NULL);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
if ((button == BTN_BACK || button == BTN_FORWARD) &&
|
||||
term->grid == &term->alt && term->alt_scrolling &&
|
||||
term->mouse_tracking == MOUSE_NONE)
|
||||
{
|
||||
/*
|
||||
* alternateScroll/faux scrolling - translate mouse
|
||||
* "back"/"forward" to up/down keys
|
||||
*/
|
||||
|
||||
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);
|
||||
if (term->mouse_tracking == MOUSE_NONE) {
|
||||
if (term->grid == &term->alt) {
|
||||
if (term->alt_scrolling)
|
||||
alternate_scroll(seat, amount, button);
|
||||
} else {
|
||||
if (button == BTN_BACK)
|
||||
cmd_scrollback_up(term, amount);
|
||||
else
|
||||
cmd_scrollback_down(term, amount);
|
||||
}
|
||||
} else {
|
||||
if (!term_mouse_grabbed(term, seat) &&
|
||||
seat->mouse.col >= 0 && seat->mouse.row >= 0)
|
||||
{
|
||||
assert(seat->mouse.col < term->cols);
|
||||
assert(seat->mouse.row < term->rows);
|
||||
} else if (!term_mouse_grabbed(term, seat) &&
|
||||
seat->mouse.col >= 0 && seat->mouse.row >= 0)
|
||||
{
|
||||
assert(seat->mouse.col < term->cols);
|
||||
assert(seat->mouse.row < term->rows);
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
term_mouse_down(
|
||||
term, button, seat->mouse.row, seat->mouse.col,
|
||||
seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl);
|
||||
}
|
||||
|
||||
term_mouse_up(
|
||||
for (int i = 0; i < amount; i++) {
|
||||
term_mouse_down(
|
||||
term, button, seat->mouse.row, seat->mouse.col,
|
||||
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