From 28410f1b998d1b298941530355d1e6bb37f269a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 11 Aug 2020 10:42:23 +0200 Subject: [PATCH] input: mouse-bindings: check selection is enabled/possible and that pointer is on grid We shouldn't start or modify a selection if selection isn't possible (i.e. client application is grabbing the mouse, and user isn't holding Shift). We also shouldn't start or modify a selection if the pointer is outside the grid (updating an ongoing selection on motion events is an exception to this). --- input.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/input.c b/input.c index 518a690b..e1e061ed 100644 --- a/input.c +++ b/input.c @@ -254,13 +254,23 @@ execute_binding(struct seat *seat, struct terminal *term, break; } - case BIND_ACTION_SELECT_BEGIN: - selection_start(term, seat->mouse.col, seat->mouse.row, SELECTION_NORMAL); + case BIND_ACTION_SELECT_BEGIN: { + bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + if (selection_enabled(term, seat) && cursor_is_on_grid) { + selection_start( + term, seat->mouse.col, seat->mouse.row, SELECTION_NORMAL); + } break; + } - case BIND_ACTION_SELECT_BEGIN_BLOCK: - selection_start(term, seat->mouse.col, seat->mouse.row, SELECTION_BLOCK); + case BIND_ACTION_SELECT_BEGIN_BLOCK: { + bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + if (selection_enabled(term, seat) && cursor_is_on_grid) { + selection_start( + term, seat->mouse.col, seat->mouse.row, SELECTION_BLOCK); + } break; + } case BIND_ACTION_SELECT_EXTEND: { bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; @@ -271,20 +281,30 @@ execute_binding(struct seat *seat, struct terminal *term, break; } - case BIND_ACTION_SELECT_WORD: - selection_mark_word( - seat, term, seat->mouse.col, seat->mouse.row, false, serial); + case BIND_ACTION_SELECT_WORD: { + bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + if (selection_enabled(term, seat) && cursor_is_on_grid) { + selection_mark_word( + seat, term, seat->mouse.col, seat->mouse.row, false, serial); + } break; + } - case BIND_ACTION_SELECT_WORD_WS: - selection_mark_word( - seat, term, seat->mouse.col, seat->mouse.row, true, serial); + case BIND_ACTION_SELECT_WORD_WS: { + bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + if (selection_enabled(term, seat) && cursor_is_on_grid) { + selection_mark_word( + seat, term, seat->mouse.col, seat->mouse.row, true, serial); + } break; + } - case BIND_ACTION_SELECT_ROW: - selection_mark_row(seat, term, seat->mouse.row, serial); + case BIND_ACTION_SELECT_ROW: { + bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + if (selection_enabled(term, seat) && cursor_is_on_grid) + selection_mark_row(seat, term, seat->mouse.row, serial); break; - + } case BIND_ACTION_COUNT: assert(false);