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.
This commit is contained in:
Daniel Eklöf 2020-08-11 09:55:33 +02:00
parent 1dd142aeab
commit 20f0334e13
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
6 changed files with 68 additions and 38 deletions

61
input.c
View file

@ -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(