aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-30 16:11:00 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-30 16:11:00 +0000
commitfbeb1e96103681b6a3fac49443e64ed13ae28737 (patch)
tree9678d7f14ddc3bd542e7e84e1441748307bbf366 /terminal.c
parentterm: add term_mouse_grabbed() (diff)
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.
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c25
1 files changed, 19 insertions, 6 deletions
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);