input: bindings: calculate 'cursor_is_on_grid' once only

This commit is contained in:
Daniel Eklöf 2020-08-11 10:53:21 +02:00
parent 2764a8394a
commit bb9228dd21
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

26
input.c
View file

@ -81,6 +81,8 @@ execute_binding(struct seat *seat, struct terminal *term,
enum bind_action_normal action, char *const *pipe_argv, enum bind_action_normal action, char *const *pipe_argv,
uint32_t serial) uint32_t serial)
{ {
const bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0;
switch (action) { switch (action) {
case BIND_ACTION_NONE: case BIND_ACTION_NONE:
break; break;
@ -254,57 +256,45 @@ execute_binding(struct seat *seat, struct terminal *term,
break; break;
} }
case BIND_ACTION_SELECT_BEGIN: { 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) { if (selection_enabled(term, seat) && cursor_is_on_grid) {
selection_start( selection_start(
term, seat->mouse.col, seat->mouse.row, SELECTION_NORMAL); term, seat->mouse.col, seat->mouse.row, SELECTION_NORMAL);
} }
break; break;
}
case BIND_ACTION_SELECT_BEGIN_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) { if (selection_enabled(term, seat) && cursor_is_on_grid) {
selection_start( selection_start(
term, seat->mouse.col, seat->mouse.row, SELECTION_BLOCK); term, seat->mouse.col, seat->mouse.row, SELECTION_BLOCK);
} }
break; break;
}
case BIND_ACTION_SELECT_EXTEND: { case BIND_ACTION_SELECT_EXTEND:
bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0;
if (selection_enabled(term, seat) && cursor_is_on_grid) { if (selection_enabled(term, seat) && cursor_is_on_grid) {
selection_extend( selection_extend(
seat, term, seat->mouse.col, seat->mouse.row, serial); seat, term, seat->mouse.col, seat->mouse.row, serial);
} }
break; break;
}
case BIND_ACTION_SELECT_WORD: { 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) { if (selection_enabled(term, seat) && cursor_is_on_grid) {
selection_mark_word( selection_mark_word(
seat, term, seat->mouse.col, seat->mouse.row, false, serial); seat, term, seat->mouse.col, seat->mouse.row, false, serial);
} }
break; break;
}
case BIND_ACTION_SELECT_WORD_WS: { 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) { if (selection_enabled(term, seat) && cursor_is_on_grid) {
selection_mark_word( selection_mark_word(
seat, term, seat->mouse.col, seat->mouse.row, true, serial); seat, term, seat->mouse.col, seat->mouse.row, true, serial);
} }
break; break;
}
case BIND_ACTION_SELECT_ROW: { 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) if (selection_enabled(term, seat) && cursor_is_on_grid)
selection_mark_row(seat, term, seat->mouse.row, serial); selection_mark_row(seat, term, seat->mouse.row, serial);
break; break;
}
case BIND_ACTION_COUNT: case BIND_ACTION_COUNT:
assert(false); assert(false);