From c0ce131f1a4195585cc89f58ab65cfd7658ca0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 19 Nov 2021 15:04:51 +0100 Subject: [PATCH] input: Update mouse x/y coordinates on wl_pointer_enter Otherwise if you don't receive motion event before e.g. button pressed, the coordinates will be incorrect. This happens when e.g. you get alt-tabbed so that the mouse cursor ends up on top of the terminal window, but the mouse never actually moved. --- input.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/input.c b/input.c index 5f864a8d..35baf3d4 100644 --- a/input.c +++ b/input.c @@ -1405,11 +1405,18 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, struct wl_window *win = wl_surface_get_user_data(surface); struct terminal *term = win->term; + int x = wl_fixed_to_int(surface_x) * term->scale; + int y = wl_fixed_to_int(surface_y) * term->scale; + seat->pointer.serial = serial; seat->pointer.hidden = false; + seat->mouse.x = x; + seat->mouse.y = y; - LOG_DBG("pointer-enter: pointer=%p, serial=%u, surface = %p, new-moused = %p", - (void *)wl_pointer, serial, (void *)surface, (void *)term); + LOG_DBG("pointer-enter: pointer=%p, serial=%u, surface = %p, new-moused = %p, " + "x=%d, y=%d", + (void *)wl_pointer, serial, (void *)surface, (void *)term, + x, y); xassert(tll_length(seat->mouse.buttons) == 0); @@ -1418,9 +1425,6 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, seat->mouse_focus = term; - int x = wl_fixed_to_int(surface_x) * term->scale; - int y = wl_fixed_to_int(surface_y) * term->scale; - switch ((term->active_surface = term_surface_kind(term, surface))) { case TERM_SURF_GRID: { /*