aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-09-15 16:56:22 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-09-15 16:57:00 +0000
commit04c1bab7b0d24028403667d9081ca0081c947ebd (patch)
tree3811ed15d479b0f3a7b2280af0eb83cebb922d18
parentinput: don’t use stale keycodes for arrow-up/down (diff)
input: mouse_scroll(): refactor
-rw-r--r--input.c71
1 files changed, 35 insertions, 36 deletions
diff --git a/input.c b/input.c
index e8c49d5d..cfa99574 100644
--- a/input.c
+++ b/input.c
@@ -1614,54 +1614,53 @@ 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)
{
struct terminal *term = seat->mouse_focus;
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);
-
- 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 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);
- 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);
}
}