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. --- input.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 645fa4b3..161af06b 100644 --- a/input.c +++ b/input.c @@ -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; -- cgit v1.3