From 158722b642dd1267e85f70c68f520b3a30a74877 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 7 Aug 2020 19:51:34 +0200 Subject: input: fix col/row calculation when cursor is in the top or left margin This fixes an issue where the col/row were incorrectly set to 0 instead of -1, when the mouse cursor was inside the grid margins. This resulted in e.g. the mouse cursor having the wrong shape, and foot incorrectly handling mouse events as if they were inside the grid. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 62aa0906..b9edbf1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ * Incorrect multi-column character spacer insertion when reflowing text. * Compilation errors in 32-bit builds. +* Mouse cursor style of top and left margins. ### Security -- cgit v1.3 From 721ca80abe13d47a232a41452780a3c1bb03b862 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 7 Aug 2020 19:55:02 +0200 Subject: input: motion: do selection update even if cursor is outside the grid Previously, the selection was only updated when the mouse cursor was inside the grid. This makes it difficult to e.g. do large selections fast, since you often end up moving the cursor outside the grid, or outside the terminal window even. Now, we update the selection regardless of *where* the cursor is. This is done by bounding the row/col we pass to 'selection_update()' to the grid, while still setting the seat's row/col to -1 when the cursor is outside the grid, to ensure the xcursor etc are set correctly. Care must also be taken to *not* pass any motion events to a mouse grabbing client, when the cursor is outside the grid. Closes #70. --- CHANGELOG.md | 2 ++ input.c | 29 ++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index b9edbf1b..d6408bf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,8 @@ text. * Compilation errors in 32-bit builds. * Mouse cursor style of top and left margins. +* Selection is now **updated** when the cursor moves outside the grid + (https://codeberg.org/dnkl/foot/issues/70). ### Security diff --git a/input.c b/input.c index 161af06b..cd23fd80 100644 --- a/input.c +++ b/input.c @@ -1204,8 +1204,6 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, break; case TERM_SURF_GRID: { - term_xcursor_update_for_seat(term, seat); - int col = x >= term->margins.left ? (x - term->margins.left) / term->cell_width : -1; int row = y >= term->margins.top ? (y - term->margins.top) / term->cell_height : -1; @@ -1215,22 +1213,35 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, seat->mouse.col = col >= 0 && col < term->cols ? col : -1; seat->mouse.row = row >= 0 && row < term->rows ? row : -1; - if (seat->mouse.col < 0 || seat->mouse.row < 0) - break; + term_xcursor_update_for_seat(term, seat); + + /* Update selection even if cursor is outside the grid, + * including outside the terminal bounds */ + int selection_col = max(0, min(col, term->cols - 1)); + int selection_row = max(0, min(row, term->rows - 1)); - bool update_selection = seat->mouse.button == BTN_LEFT || seat->mouse.button == BTN_RIGHT; + bool update_selection = + seat->mouse.button == BTN_LEFT || seat->mouse.button == BTN_RIGHT; bool update_selection_early = term->selection.end.row == -1; if (update_selection && update_selection_early) - selection_update(term, seat->mouse.col, seat->mouse.row); + selection_update(term, selection_col, selection_row); - if (old_col == seat->mouse.col && old_row == seat->mouse.row) + if (old_col == seat->mouse.col && old_row == seat->mouse.row) { + /* Cursor hasn't moved to a new cell since last motion event */ break; + } if (update_selection && !update_selection_early) - selection_update(term, seat->mouse.col, seat->mouse.row); + selection_update(term, selection_col, selection_row); + + if (!term_mouse_grabbed(term, seat) && + seat->mouse.col >= 0 && + seat->mouse.row >= 0) + { + assert(seat->mouse.col < term->cols); + assert(seat->mouse.row < term->rows); - if (!term_mouse_grabbed(term, seat)) { term_mouse_motion( term, seat->mouse.button, seat->mouse.row, seat->mouse.col, seat->kbd.shift, seat->kbd.alt, seat->kbd.ctrl); -- cgit v1.3 From 0a9aa2dd3202125cfd5b22faf626090c78a33bb9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 7 Aug 2020 20:08:30 +0200 Subject: changelog: 'of' -> 'in' --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index d6408bf2..48ae1331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ * Incorrect multi-column character spacer insertion when reflowing text. * Compilation errors in 32-bit builds. -* Mouse cursor style of top and left margins. +* Mouse cursor style in top and left margins. * Selection is now **updated** when the cursor moves outside the grid (https://codeberg.org/dnkl/foot/issues/70). -- cgit v1.3