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.
This commit is contained in:
Daniel Eklöf 2020-08-07 19:51:34 +02:00
parent f952d5a305
commit 158722b642
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 9 additions and 4 deletions

View file

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

12
input.c
View file

@ -1048,8 +1048,12 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
switch ((term->active_surface = term_surface_kind(term, surface))) {
case TERM_SURF_GRID: {
int col = (x - term->margins.left) / term->cell_width;
int row = (y - term->margins.top) / term->cell_height;
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;
seat->mouse.col = col >= 0 && col < term->cols ? col : -1;
seat->mouse.row = row >= 0 && row < term->rows ? row : -1;
@ -1202,8 +1206,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
case TERM_SURF_GRID: {
term_xcursor_update_for_seat(term, seat);
int col = (x - term->margins.left) / term->cell_width;
int row = (y - term->margins.top) / term->cell_height;
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;
int old_col = seat->mouse.col;
int old_row = seat->mouse.row;