From 2208f4304b799dbaaf52629d8ef3ce5629f16184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 30 Nov 2019 17:06:15 +0100 Subject: [PATCH] term: add term_mouse_grabbed() When this returns true, it means we have keyboard focus and are grabbing the mouse (for e.g. selections), regardless of whether the client has enabled mouse tracking or not. --- selection.c | 13 +------------ terminal.c | 33 +++++++++++++++------------------ terminal.h | 1 + 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/selection.c b/selection.c index 8aa97e13..b77dc64a 100644 --- a/selection.c +++ b/selection.c @@ -21,23 +21,12 @@ #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) -static bool -selection_forced(const struct terminal *term) -{ - const struct wayland *wayl = term->wl; - return wayl->focused == term && - wayl->kbd.shift && - !wayl->kbd.alt && - !wayl->kbd.ctrl && - !wayl->kbd.meta; -} - bool selection_enabled(const struct terminal *term) { return term->mouse_tracking == MOUSE_NONE || - selection_forced(term) || + term_mouse_grabbed(term) || term->is_searching; } diff --git a/terminal.c b/terminal.c index 6177f56c..a1641063 100644 --- a/terminal.c +++ b/terminal.c @@ -1309,17 +1309,24 @@ report_mouse_motion(struct terminal *term, int encoded_button, int row, int col) report_mouse_click(term, encoded_button, row, col, false); } +bool +term_mouse_grabbed(const struct terminal *term) +{ + /* + * Mouse is grabbed by us, regardless of whether mouse tracking has been enabled or not. + */ + return + term->wl->focused == term && + term->wl->kbd.shift && + !term->wl->kbd.alt && !term->wl->kbd.ctrl && !term->wl->kbd.meta; +} + void term_mouse_down(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->wl->focused == term && - term->wl->kbd.shift && - !term->wl->kbd.alt && !term->wl->kbd.ctrl && !term->wl->kbd.meta) - { - /* "raw" mouse mode */ + if (term_mouse_grabbed(term)) return; - } /* Map libevent button event code to X button number */ int xbutton = linux_mouse_button_to_x(button); @@ -1353,13 +1360,8 @@ void term_mouse_up(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->wl->focused == term && - term->wl->kbd.shift && - !term->wl->kbd.alt && !term->wl->kbd.ctrl && !term->wl->kbd.meta) - { - /* "raw" mouse mode */ + if (term_mouse_grabbed(term)) return; - } /* Map libevent button event code to X button number */ int xbutton = linux_mouse_button_to_x(button); @@ -1398,13 +1400,8 @@ void term_mouse_motion(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->wl->focused == term && - term->wl->kbd.shift && - !term->wl->kbd.alt && !term->wl->kbd.ctrl && !term->wl->kbd.meta) - { - /* "raw" mouse mode */ + if (term_mouse_grabbed(term)) return; - } int encoded = 0; diff --git a/terminal.h b/terminal.h index a7fb2b06..eefc2065 100644 --- a/terminal.h +++ b/terminal.h @@ -366,6 +366,7 @@ 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); +bool term_mouse_grabbed(const struct terminal *term); void term_xcursor_update(struct terminal *term); void term_set_window_title(struct terminal *term, const char *title);