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. --- selection.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'selection.c') diff --git a/selection.c b/selection.c index a078a698..3eadf2ea 100644 --- a/selection.c +++ b/selection.c @@ -237,6 +237,7 @@ selection_start(struct terminal *term, int col, int row, term->selection.kind = kind; term->selection.start = (struct coord){col, term->grid->view + row}; term->selection.end = (struct coord){-1, -1}; + term->selection.ongoing = true; } static bool @@ -566,6 +567,11 @@ selection_finalize(struct seat *seat, struct terminal *term, uint32_t serial) if (term->selection.start.row < 0 || term->selection.end.row < 0) return; + if (!term->selection.ongoing) + return; + + term->selection.ongoing = false; + assert(term->selection.start.row != -1); assert(term->selection.end.row != -1); @@ -600,6 +606,7 @@ selection_cancel(struct terminal *term) term->selection.start = (struct coord){-1, -1}; term->selection.end = (struct coord){-1, -1}; term->selection.direction = SELECTION_UNDIR; + term->selection.ongoing = false; } void -- cgit v1.3 From cddeaa2c1c648682e5d966d173f1663bee1d95a9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 10:14:38 +0200 Subject: selection: update: don't update if there's no ongoing selection --- selection.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 3eadf2ea..d0ed7bae 100644 --- a/selection.c +++ b/selection.c @@ -311,6 +311,9 @@ selection_update(struct terminal *term, int col, int row) if (term->selection.start.row < 0) return; + if (!term->selection.ongoing) + return; + LOG_DBG("selection updated: start = %d,%d, end = %d,%d -> %d, %d", term->selection.start.row, term->selection.start.col, term->selection.end.row, term->selection.end.col, -- cgit v1.3 From 9517c6443c0a0a9c8abf350e388c0be505c03de7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 10:15:01 +0200 Subject: selection: finalize: clear ongoing selection Check for ongoing selection, and *clear* it before bailing out due to the selection not having an end-point. This fixes an issue where a selection was kept as ongoing, even though the button had been released. Typically triggered by clicking without moving the mouse; this started a new selection, then (tried to) finalize it, but failed since the selection didn't have an end-point. --- selection.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index d0ed7bae..43ef2938 100644 --- a/selection.c +++ b/selection.c @@ -567,14 +567,14 @@ selection_extend(struct seat *seat, struct terminal *term, void selection_finalize(struct seat *seat, struct terminal *term, uint32_t serial) { - if (term->selection.start.row < 0 || term->selection.end.row < 0) - return; - if (!term->selection.ongoing) return; term->selection.ongoing = false; + if (term->selection.start.row < 0 || term->selection.end.row < 0) + return; + assert(term->selection.start.row != -1); assert(term->selection.end.row != -1); -- cgit v1.3 From f14b49068ac404879495b42343a6ab2e78b0609f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 11 Aug 2020 10:16:52 +0200 Subject: selection: extend: set ongoing to true --- selection.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 43ef2938..0f1731e6 100644 --- a/selection.c +++ b/selection.c @@ -536,6 +536,8 @@ selection_extend(struct seat *seat, struct terminal *term, return; } + term->selection.ongoing = true; + row += term->grid->view; if ((row == term->selection.start.row && col == term->selection.start.col) || -- cgit v1.3