From bb9228dd21785c8621d9b413c3e630b5f47bbce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 11 Aug 2020 10:53:21 +0200 Subject: [PATCH] input: bindings: calculate 'cursor_is_on_grid' once only --- input.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/input.c b/input.c index d7ae76f3..cb4c84cf 100644 --- a/input.c +++ b/input.c @@ -81,6 +81,8 @@ execute_binding(struct seat *seat, struct terminal *term, enum bind_action_normal action, char *const *pipe_argv, uint32_t serial) { + const bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + switch (action) { case BIND_ACTION_NONE: break; @@ -254,57 +256,45 @@ execute_binding(struct seat *seat, struct terminal *term, break; } - case BIND_ACTION_SELECT_BEGIN: { - bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + case BIND_ACTION_SELECT_BEGIN: 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: { - bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + case BIND_ACTION_SELECT_BEGIN_BLOCK: 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; + case BIND_ACTION_SELECT_EXTEND: if (selection_enabled(term, seat) && cursor_is_on_grid) { selection_extend( seat, term, seat->mouse.col, seat->mouse.row, serial); } break; - } - case BIND_ACTION_SELECT_WORD: { - bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + case BIND_ACTION_SELECT_WORD: 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: { - bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + case BIND_ACTION_SELECT_WORD_WS: 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: { - bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; + case BIND_ACTION_SELECT_ROW: 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);