From 20f0334e1314508683651b0e5c59fd637d1d13f5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 09:55:33 +0200 Subject: config: add mouse specific bind actions This extends the "normal" bind action enum with mouse specific actions. When parsing key bindings, we only check up to the last valid keyboard binding, while mouse bindings support *both* key actions and mouse actions. The new actions are: * select-begin: starts an interactive selection * select-extend: interactively extend an existing selection * select-word: select word under cursor * select-word-whitespace: select word under cursor, where the only word separating characters are whitespace characters. The old hard-coded selection "bindings" have been converted to instead use these actions, via default bindings added to the configuration. --- input.c | 61 +++++++++++++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 34 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index b7c5031a..9e260e69 100644 --- a/input.c +++ b/input.c @@ -254,6 +254,31 @@ execute_binding(struct seat *seat, struct terminal *term, break; } + case BIND_ACTION_SELECT_BEGIN: + selection_start( + term, seat->mouse.col, seat->mouse.row, + seat->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); + break; + + case BIND_ACTION_SELECT_WORD: + 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); + break; + + 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) { + selection_extend( + seat, term, seat->mouse.col, seat->mouse.row, serial); + } + break; + } + case BIND_ACTION_COUNT: assert(false); break; @@ -1442,38 +1467,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, switch (state) { case WL_POINTER_BUTTON_STATE_PRESSED: { - if (button == BTN_LEFT && seat->mouse.count <= 3 && mods == 0) { - selection_cancel(term); - - if (selection_enabled(term, seat) && cursor_is_on_grid) { - switch (seat->mouse.count) { - case 1: - selection_start( - term, seat->mouse.col, seat->mouse.row, - seat->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); - break; - - case 2: - selection_mark_word( - seat, term, seat->mouse.col, seat->mouse.row, - seat->kbd.ctrl, serial); - break; - - case 3: - selection_mark_row(seat, term, seat->mouse.row, serial); - break; - } - } - } - - else if (button == BTN_RIGHT && seat->mouse.count == 1 && mods == 0) { - if (selection_enabled(term, seat) && cursor_is_on_grid) { - selection_extend( - seat, term, seat->mouse.col, seat->mouse.row, serial); - } - } - - else if (seat->wl_keyboard != NULL) { + if (seat->wl_keyboard != NULL) { /* Seat has keyboard - use mouse bindings *with* modifiers */ tll_foreach(seat->mouse.bindings, it) { const struct mouse_binding *binding = &it->item; @@ -1533,8 +1527,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } case WL_POINTER_BUTTON_STATE_RELEASED: - if (button == BTN_LEFT && term->selection.end.col != -1) - selection_finalize(seat, term, serial); + selection_finalize(seat, term, serial); if (!term_mouse_grabbed(term, seat) && cursor_is_on_grid) { term_mouse_up( -- cgit v1.3 From 4d2bc54fa216dfda98c4b228b9576dcad471858c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 10:17:19 +0200 Subject: config: mouse bindings: add select-begin-block and select-row --- config.c | 8 ++++++-- doc/footrc.5.scd | 10 +++++++++- footrc | 4 +++- input.c | 33 +++++++++++++++++++-------------- wayland.h | 4 +++- 5 files changed, 40 insertions(+), 19 deletions(-) (limited to 'input.c') diff --git a/config.c b/config.c index 69883b68..d46b5f8e 100644 --- a/config.c +++ b/config.c @@ -72,9 +72,11 @@ static const char *const binding_action_map[] = { /* Mouse-specific actions */ [BIND_ACTION_SELECT_BEGIN] = "select-begin", + [BIND_ACTION_SELECT_BEGIN_BLOCK] = "select-begin-block", + [BIND_ACTION_SELECT_EXTEND] = "select-extend", [BIND_ACTION_SELECT_WORD] = "select-word", [BIND_ACTION_SELECT_WORD_WS] = "select-word-whitespace", - [BIND_ACTION_SELECT_EXTEND] = "select-extend", + [BIND_ACTION_SELECT_ROW] = "select-row", }; static_assert(ALEN(binding_action_map) == BIND_ACTION_COUNT, @@ -1534,9 +1536,11 @@ add_default_mouse_bindings(struct config *conf) add_binding(BIND_ACTION_PRIMARY_PASTE, none, BTN_MIDDLE, 1); add_binding(BIND_ACTION_SELECT_BEGIN, none, BTN_LEFT, 1); + add_binding(BIND_ACTION_SELECT_BEGIN_BLOCK, ctrl, BTN_LEFT, 1); + add_binding(BIND_ACTION_SELECT_EXTEND, none, BTN_RIGHT, 1); add_binding(BIND_ACTION_SELECT_WORD, none, BTN_LEFT, 2); add_binding(BIND_ACTION_SELECT_WORD_WS, ctrl, BTN_LEFT, 2); - add_binding(BIND_ACTION_SELECT_EXTEND, none, BTN_RIGHT, 1); + add_binding(BIND_ACTION_SELECT_ROW, none, BTN_LEFT, 3); #undef add_binding } diff --git a/doc/footrc.5.scd b/doc/footrc.5.scd index 4476daa1..a5792671 100644 --- a/doc/footrc.5.scd +++ b/doc/footrc.5.scd @@ -388,7 +388,12 @@ All actions listed under *key-bindings* can be user here as well. *select-begin* Begin an interactive selection. The selection is finalized, and copied to the _primary selection_, when the button is - released..Default: _BTN\_LEFT_. + released. Default: _BTN\_LEFT_. + +*select-begin-block* + Begin an interactive block selection. The selection is finalized, + and copied to the _primary selection_, when the button is + released. Default: _Control+BTN\_LEFT_. *select-extend* Interactively extend an existing selection. The selection is @@ -403,6 +408,9 @@ All actions listed under *key-bindings* can be user here as well. Select the _word_ (separated by spaces _only_) under the pointer. Default: Control+_BTN\_LEFT-2_. +*select-row* + Select the whole row under the pointer. Default: _BTN\_LEFT-3_. + *primary-paste* Pastes from the _primary selection_. Default: _BTN\_MIDDLE_. diff --git a/footrc b/footrc index 062b9177..a76c71e9 100644 --- a/footrc +++ b/footrc @@ -94,6 +94,8 @@ [mouse-bindings] # primary-paste=BTN_MIDDLE # select-begin=BTN_LEFT +# select-begin-block=Control=BTN_LEFT +# select-extend=BTN_RIGHT # select-word=BTN_LEFT-2 # select-word-whitespace=Control+BTN_LEFT-2 -# select-extend=BTN_RIGHT +# select-row=BTN_LEFT-3 diff --git a/input.c b/input.c index 9e260e69..518a690b 100644 --- a/input.c +++ b/input.c @@ -255,11 +255,22 @@ execute_binding(struct seat *seat, struct terminal *term, } case BIND_ACTION_SELECT_BEGIN: - selection_start( - term, seat->mouse.col, seat->mouse.row, - seat->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); + 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); + break; + + 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) { + selection_extend( + seat, term, seat->mouse.col, seat->mouse.row, serial); + } + break; + } + case BIND_ACTION_SELECT_WORD: selection_mark_word( seat, term, seat->mouse.col, seat->mouse.row, false, serial); @@ -270,14 +281,10 @@ execute_binding(struct seat *seat, struct terminal *term, seat, term, seat->mouse.col, seat->mouse.row, true, serial); break; - 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) { - selection_extend( - seat, term, seat->mouse.col, seat->mouse.row, serial); - } + case BIND_ACTION_SELECT_ROW: + selection_mark_row(seat, term, seat->mouse.row, serial); break; - } + case BIND_ACTION_COUNT: assert(false); @@ -1279,10 +1286,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; /* Update selection */ - if (seat->mouse.button == BTN_LEFT || seat->mouse.button == BTN_RIGHT) { - if (cursor_is_on_new_cell || term->selection.end.row < 0) - selection_update(term, selection_col, selection_row); - } + if (cursor_is_on_new_cell || term->selection.end.row < 0) + selection_update(term, selection_col, selection_row); /* Send mouse event to client application */ if (!term_mouse_grabbed(term, seat) && diff --git a/wayland.h b/wayland.h index b7528a7f..85cc1ca7 100644 --- a/wayland.h +++ b/wayland.h @@ -47,9 +47,11 @@ enum bind_action_normal { /* Mouse specific actions - i.e. they require a mouse coordinate */ BIND_ACTION_SELECT_BEGIN, + BIND_ACTION_SELECT_BEGIN_BLOCK, + BIND_ACTION_SELECT_EXTEND, BIND_ACTION_SELECT_WORD, BIND_ACTION_SELECT_WORD_WS, - BIND_ACTION_SELECT_EXTEND, + BIND_ACTION_SELECT_ROW, BIND_ACTION_COUNT, }; -- cgit v1.3 From 28410f1b998d1b298941530355d1e6bb37f269a0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 10:42:23 +0200 Subject: 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(-) (limited to 'input.c') 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); -- cgit v1.3 From 364412bfaa09b282389a988432cbe1aa2ad30bd8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 10:45:01 +0200 Subject: input: mouse-bindings: ignore Shift Shift is used to enable selection when the client application is grabbing the mouse. As such, mouse bindings *never* have Shift as a modifier, but should still trigger when Shift is being pressed. --- input.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index e1e061ed..d7ae76f3 100644 --- a/input.c +++ b/input.c @@ -1487,13 +1487,19 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; - xkb_mod_mask_t mods = xkb_state_serialize_mods( - seat->kbd.xkb_state, XKB_STATE_MODS_DEPRESSED); - switch (state) { case WL_POINTER_BUTTON_STATE_PRESSED: { if (seat->wl_keyboard != NULL) { /* Seat has keyboard - use mouse bindings *with* modifiers */ + + xkb_mod_mask_t mods = xkb_state_serialize_mods( + seat->kbd.xkb_state, XKB_STATE_MODS_DEPRESSED); + + /* Ignore Shift when matching modifiers, since it is + * used to enable selection in mouse grabbing client + * applications */ + mods &= ~(1 << seat->kbd.mod_shift); + tll_foreach(seat->mouse.bindings, it) { const struct mouse_binding *binding = &it->item; -- cgit v1.3 From bb9228dd21785c8621d9b413c3e630b5f47bbce4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 10:53:21 +0200 Subject: input: bindings: calculate 'cursor_is_on_grid' once only --- input.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'input.c') 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); -- cgit v1.3 From d29c4aed8a424b67eb0be4dbb7f8d964357cdfaa Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 16:36:42 +0200 Subject: input: mouse motion: don't update selection while scrollback searching When we are doing a scrollback search, the selection *is* ongoing. We still don't want to update the selection when the mouse moves. --- input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index cb4c84cf..3cd6830d 100644 --- a/input.c +++ b/input.c @@ -1296,8 +1296,10 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, bool cursor_is_on_grid = seat->mouse.col >= 0 && seat->mouse.row >= 0; /* Update selection */ - if (cursor_is_on_new_cell || term->selection.end.row < 0) - selection_update(term, selection_col, selection_row); + if (!term->is_searching) { + if (cursor_is_on_new_cell || term->selection.end.row < 0) + selection_update(term, selection_col, selection_row); + } /* Send mouse event to client application */ if (!term_mouse_grabbed(term, seat) && -- cgit v1.3