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).
This commit is contained in:
Daniel Eklöf 2020-08-11 10:42:23 +02:00
parent 24ee6d836b
commit 28410f1b99
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

46
input.c
View file

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