mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-21 05:33:45 -04:00
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.
This commit is contained in:
parent
363a0de8b9
commit
d675cf8720
3 changed files with 39 additions and 17 deletions
|
|
@ -12,6 +12,15 @@
|
||||||
* [1.2.0](#1-2-0)
|
* [1.2.0](#1-2-0)
|
||||||
|
|
||||||
## 1.4.4
|
## 1.4.4
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Mouse cursor is now always a `left_ptr` when inside the margins, to
|
||||||
|
indicate it is not possible to start a selection.
|
||||||
|
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Crash when starting a selection inside the margins.
|
||||||
|
|
||||||
|
|
||||||
## 1.4.3
|
## 1.4.3
|
||||||
|
|
|
||||||
40
input.c
40
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;
|
int y = wl_fixed_to_int(surface_y) * term->scale;
|
||||||
|
|
||||||
switch ((term->active_surface = term_surface_kind(term, surface))) {
|
switch ((term->active_surface = term_surface_kind(term, surface))) {
|
||||||
case TERM_SURF_GRID:
|
case TERM_SURF_GRID: {
|
||||||
seat->mouse.col = x / term->cell_width;
|
int col = (x - term->margins.left) / term->cell_width;
|
||||||
seat->mouse.row = y / term->cell_height;
|
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);
|
term_xcursor_update(term);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TERM_SURF_SEARCH:
|
case TERM_SURF_SEARCH:
|
||||||
case TERM_SURF_TITLE:
|
case TERM_SURF_TITLE:
|
||||||
|
|
@ -1165,26 +1170,31 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TERM_SURF_GRID: {
|
case TERM_SURF_GRID: {
|
||||||
|
term_xcursor_update(term);
|
||||||
|
|
||||||
int col = (x - term->margins.left) / term->cell_width;
|
int col = (x - term->margins.left) / term->cell_width;
|
||||||
int row = (y - term->margins.top) / term->cell_height;
|
int row = (y - term->margins.top) / term->cell_height;
|
||||||
|
|
||||||
if (col < 0 || row < 0 || col >= term->cols || row >= term->rows)
|
int old_col = seat->mouse.col;
|
||||||
return;
|
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 || 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;
|
bool update_selection_early = term->selection.end.row == -1;
|
||||||
|
|
||||||
if (update_selection && update_selection_early)
|
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;
|
break;
|
||||||
|
|
||||||
seat->mouse.col = col;
|
|
||||||
seat->mouse.row = row;
|
|
||||||
|
|
||||||
if (update_selection && !update_selection_early)
|
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)) {
|
if (!term_mouse_grabbed(term, seat)) {
|
||||||
term_mouse_motion(
|
term_mouse_motion(
|
||||||
|
|
@ -1360,9 +1370,11 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
||||||
if (selection_enabled(term, seat)) {
|
if (selection_enabled(term, seat)) {
|
||||||
switch (seat->mouse.count) {
|
switch (seat->mouse.count) {
|
||||||
case 1:
|
case 1:
|
||||||
selection_start(
|
if (seat->mouse.col >= 0 && seat->mouse.row >= 0) {
|
||||||
term, seat->mouse.col, seat->mouse.row,
|
selection_start(
|
||||||
seat->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL);
|
term, seat->mouse.col, seat->mouse.row,
|
||||||
|
seat->kbd.ctrl ? SELECTION_BLOCK : SELECTION_NORMAL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,10 @@ bool
|
||||||
selection_enabled(const struct terminal *term, struct seat *seat)
|
selection_enabled(const struct terminal *term, struct seat *seat)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
term->mouse_tracking == MOUSE_NONE ||
|
seat->mouse.col >= 0 && seat->mouse.row >= 0 &&
|
||||||
term_mouse_grabbed(term, seat) ||
|
(term->mouse_tracking == MOUSE_NONE ||
|
||||||
term->is_searching;
|
term_mouse_grabbed(term, seat) ||
|
||||||
|
term->is_searching);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue