From fbeb1e96103681b6a3fac49443e64ed13ae28737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 30 Nov 2019 17:11:00 +0100 Subject: [PATCH] term: mouse reporting functions no longer take modifier state The mouse reporting functions are called from input when we receive Wayland mouse events. We used to pass the current keyboard modifier (shift, alt, ctrl, etc) to the terminal functions. This however is wrong, since we may receive Wayland mouse events without having keyboard focus. When we don't have keyboard focus, the modifier state doesn't apply to us. Remove the modifier arguments from the terminal mouse reporting functions. These functions now read this state directly instead, but only when the terminal instance in question has keyboard focus. --- input.c | 12 ++++-------- terminal.c | 25 +++++++++++++++++++------ terminal.h | 9 +++------ 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/input.c b/input.c index f51d2152..84a2f2e3 100644 --- a/input.c +++ b/input.c @@ -521,8 +521,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, selection_update(term, col, row); term_mouse_motion( - term, wayl->mouse.button, wayl->mouse.row, wayl->mouse.col, - wayl->kbd.shift, wayl->kbd.alt, wayl->kbd.ctrl); + term, wayl->mouse.button, wayl->mouse.row, wayl->mouse.col); } static void @@ -594,8 +593,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, wayl->mouse.button = button; /* For motion events */ wayl->mouse.last_button = button; wayl->mouse.last_time = now; - term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col, - wayl->kbd.shift, wayl->kbd.alt, wayl->kbd.ctrl); + term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col); break; } @@ -606,8 +604,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, selection_finalize(term, serial); wayl->mouse.button = 0; /* For motion events */ - term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col, - wayl->kbd.shift, wayl->kbd.alt, wayl->kbd.ctrl); + term_mouse_up(term, button, wayl->mouse.row, wayl->mouse.col); break; } } @@ -648,8 +645,7 @@ mouse_scroll(struct wayland *wayl, int amount) keyboard_key(wayl, NULL, wayl->input_serial, 0, key - 8, XKB_KEY_UP); } else { for (int i = 0; i < amount; i++) - term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col, - wayl->kbd.shift, wayl->kbd.alt, wayl->kbd.ctrl); + term_mouse_down(term, button, wayl->mouse.row, wayl->mouse.col); scrollback(term, amount); } diff --git a/terminal.c b/terminal.c index a1641063..c49c34df 100644 --- a/terminal.c +++ b/terminal.c @@ -1322,8 +1322,7 @@ term_mouse_grabbed(const struct terminal *term) } void -term_mouse_down(struct terminal *term, int button, int row, int col, - bool shift, bool alt, bool ctrl) +term_mouse_down(struct terminal *term, int button, int row, int col) { if (term_mouse_grabbed(term)) return; @@ -1337,6 +1336,12 @@ term_mouse_down(struct terminal *term, int button, int row, int col, if (encoded == -1) return; + + bool has_focus = term->wl->focused == term; + bool shift = has_focus ? term->wl->kbd.shift : false; + bool alt = has_focus ? term->wl->kbd.alt : false; + bool ctrl = has_focus ? term->wl->kbd.ctrl : false; + encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0); switch (term->mouse_tracking) { @@ -1357,8 +1362,7 @@ term_mouse_down(struct terminal *term, int button, int row, int col, } void -term_mouse_up(struct terminal *term, int button, int row, int col, - bool shift, bool alt, bool ctrl) +term_mouse_up(struct terminal *term, int button, int row, int col) { if (term_mouse_grabbed(term)) return; @@ -1377,6 +1381,11 @@ term_mouse_up(struct terminal *term, int button, int row, int col, if (encoded == -1) return; + bool has_focus = term->wl->focused == term; + bool shift = has_focus ? term->wl->kbd.shift : false; + bool alt = has_focus ? term->wl->kbd.alt : false; + bool ctrl = has_focus ? term->wl->kbd.ctrl : false; + encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0); switch (term->mouse_tracking) { @@ -1397,8 +1406,7 @@ term_mouse_up(struct terminal *term, int button, int row, int col, } void -term_mouse_motion(struct terminal *term, int button, int row, int col, - bool shift, bool alt, bool ctrl) +term_mouse_motion(struct terminal *term, int button, int row, int col) { if (term_mouse_grabbed(term)) return; @@ -1417,6 +1425,11 @@ term_mouse_motion(struct terminal *term, int button, int row, int col, } else encoded = 3; /* "released" */ + bool has_focus = term->wl->focused == term; + bool shift = has_focus ? term->wl->kbd.shift : false; + bool alt = has_focus ? term->wl->kbd.alt : false; + bool ctrl = has_focus ? term->wl->kbd.ctrl : false; + encoded += 32; /* Motion event */ encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0); diff --git a/terminal.h b/terminal.h index eefc2065..bec33790 100644 --- a/terminal.h +++ b/terminal.h @@ -360,12 +360,9 @@ void term_restore_cursor(struct terminal *term); void term_focus_in(struct terminal *term); void term_focus_out(struct terminal *term); -void term_mouse_down(struct terminal *term, int button, int row, int col, - bool shift, bool alt, bool ctrl); -void term_mouse_up(struct terminal *term, int button, int row, int col, - bool shift, bool alt, bool ctrl); -void term_mouse_motion(struct terminal *term, int button, int row, int col, - bool shift, bool alt, bool ctrl); +void term_mouse_down(struct terminal *term, int button, int row, int col); +void term_mouse_up(struct terminal *term, int button, int row, int col); +void term_mouse_motion(struct terminal *term, int button, int row, int col); bool term_mouse_grabbed(const struct terminal *term); void term_xcursor_update(struct terminal *term);