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.
This commit is contained in:
Daniel Eklöf 2019-11-30 17:11:00 +01:00
parent 2208f4304b
commit fbeb1e9610
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 26 additions and 20 deletions

12
input.c
View file

@ -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);
}

View file

@ -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);

View file

@ -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);