From c1f35731e0a98344b605d5b07caa77c2f00e3791 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 12:31:13 +0200 Subject: input: margins are not selectable * Fix col/row calculation in pointer-enter event; we did not take the margins into account. * seat->mouse.col,row are now set to -1 if the cursor is inside the margins. That is, col/row are only ever valid when the mouse is actually over the grid, and not in the margins. * Use regular 'left-ptr' mouse cursor when mouse is inside the margins, to not make the user think he/she can start a selection. Besides making things clearer, this also fixes a crash that occurred if you started a selection in e.g. the right margin. --- input.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 442cd322..4dd8cf39 100644 --- a/input.c +++ b/input.c @@ -1023,11 +1023,16 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, int y = wl_fixed_to_int(surface_y) * term->scale; switch ((term->active_surface = term_surface_kind(term, surface))) { - case TERM_SURF_GRID: - seat->mouse.col = x / term->cell_width; - seat->mouse.row = y / term->cell_height; + case TERM_SURF_GRID: { + int col = (x - term->margins.left) / term->cell_width; + int row = (y - term->margins.top) / term->cell_height; + + seat->mouse.col = col >= 0 && col < term->cols ? col : -1; + seat->mouse.row = row >= 0 && row < term->rows ? row : -1; + term_xcursor_update(term); break; + } case TERM_SURF_SEARCH: case TERM_SURF_TITLE: @@ -1165,26 +1170,31 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, break; case TERM_SURF_GRID: { + term_xcursor_update(term); + int col = (x - term->margins.left) / term->cell_width; int row = (y - term->margins.top) / term->cell_height; - if (col < 0 || row < 0 || col >= term->cols || row >= term->rows) - return; + int old_col = seat->mouse.col; + int old_row = seat->mouse.row; + + 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; bool update_selection = seat->mouse.button == BTN_LEFT; bool update_selection_early = term->selection.end.row == -1; if (update_selection && update_selection_early) - selection_update(term, col, row); + selection_update(term, seat->mouse.col, seat->mouse.row); - if (col == seat->mouse.col && row == seat->mouse.row) + if (old_col == seat->mouse.col && old_row == seat->mouse.row) break; - seat->mouse.col = col; - seat->mouse.row = row; - if (update_selection && !update_selection_early) - selection_update(term, col, row); + selection_update(term, seat->mouse.col, seat->mouse.row); if (!term_mouse_grabbed(term, seat)) { term_mouse_motion( @@ -1360,9 +1370,11 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, if (selection_enabled(term, seat)) { switch (seat->mouse.count) { case 1: - selection_start( - term, seat->mouse.col, seat->mouse.row, - seat->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); + if (seat->mouse.col >= 0 && seat->mouse.row >= 0) { + selection_start( + term, seat->mouse.col, seat->mouse.row, + seat->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL); + } break; case 2: -- cgit v1.3 From 1a65b161dc03bb1ab42913866a111be16abc7e42 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 12:37:35 +0200 Subject: input: handle the scrollback indicator surface in pointer events --- input.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 4dd8cf39..fbf6b517 100644 --- a/input.c +++ b/input.c @@ -1035,6 +1035,7 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, } case TERM_SURF_SEARCH: + case TERM_SURF_SCROLLBACK_INDICATOR: case TERM_SURF_TITLE: render_xcursor_set(seat, term, XCURSOR_LEFT_PTR); break; @@ -1112,6 +1113,7 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_NONE: case TERM_SURF_GRID: case TERM_SURF_SEARCH: + case TERM_SURF_SCROLLBACK_INDICATOR: case TERM_SURF_TITLE: case TERM_SURF_BORDER_LEFT: case TERM_SURF_BORDER_RIGHT: @@ -1146,6 +1148,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, switch (term->active_surface) { case TERM_SURF_NONE: case TERM_SURF_SEARCH: + case TERM_SURF_SCROLLBACK_INDICATOR: case TERM_SURF_BUTTON_MINIMIZE: case TERM_SURF_BUTTON_MAXIMIZE: case TERM_SURF_BUTTON_CLOSE: @@ -1357,6 +1360,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, break; case TERM_SURF_SEARCH: + case TERM_SURF_SCROLLBACK_INDICATOR: break; case TERM_SURF_GRID: { -- cgit v1.3 From 7127a0a6c393ee888a7b640c5481e191e0744519 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 27 Jul 2020 16:44:41 +0200 Subject: selection: extending a selection is now interactive That is, a selection extension can be resized just like an ordinary extension. --- CHANGELOG.md | 4 +++- input.c | 2 +- selection.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'input.c') diff --git a/CHANGELOG.md b/CHANGELOG.md index 764e8f46..53c2462a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,13 +37,15 @@ outside it. * Scrollback search to focus match, that requires a viewport change, roughly in the center of the screen. +* Extending a selection with the right mouse button now works while + dragging the mouse. ### Deprecated ### Removed ### Fixed -* Crash in scrollback search +* Crash in scrollback search. * Crash when a **pipe-visible** or **pipe-scrollback** command contained an unclosed quote (https://codeberg.org/dnkl/foot/issues/49). diff --git a/input.c b/input.c index 442cd322..c7f4b073 100644 --- a/input.c +++ b/input.c @@ -1171,7 +1171,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, if (col < 0 || row < 0 || col >= term->cols || row >= term->rows) return; - bool update_selection = seat->mouse.button == BTN_LEFT; + 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) diff --git a/selection.c b/selection.c index d5add464..354f6f53 100644 --- a/selection.c +++ b/selection.c @@ -372,8 +372,8 @@ selection_extend_normal(struct terminal *term, int col, int row, uint32_t serial if (row < start->row || (row == start->row && col < start->col)) { /* Extend selection to start *before* current start */ - new_start = (struct coord){col, row}; - new_end = *end; + new_start = *end; + new_end = (struct coord){col, row}; } else if (row > end->row || (row == end->row && col > end->col)) { @@ -391,8 +391,8 @@ selection_extend_normal(struct terminal *term, int col, int row, uint32_t serial abs(linear - (end->row * term->cols + end->col))) { /* Move start point */ - new_start = (struct coord){col, row}; - new_end = *end; + new_start = *end; + new_end = (struct coord){col, row}; } else { @@ -440,13 +440,13 @@ selection_extend_block(struct terminal *term, int col, int row, uint32_t serial) /* Move one of the top corners */ if (abs(col - top_left.col) < abs(col - top_right.col)) { - new_start = (struct coord){col, row}; - new_end = bottom_right; + new_start = bottom_right; + new_end = (struct coord){col, row}; } else { - new_start = (struct coord){col, row}; - new_end = bottom_left; + new_start = bottom_left; + new_end = (struct coord){col, row}; } } -- cgit v1.3