From f61b8608ded9f81fac276e048e8c0a043ba917db Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 22 Jul 2021 07:31:30 +0530 Subject: [PATCH] Fix mouse click event using current mouse co-ords rather than the co-ords at the time of the click --- kitty/mouse.c | 5 +++++ kitty/state.h | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/kitty/mouse.c b/kitty/mouse.c index 0d08940c8..d72f4ec5f 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -424,6 +424,7 @@ typedef struct PendingClick { int button, count, modifiers; bool grabbed; monotonic_t at; + MousePosition mouse_pos; } PendingClick; static void @@ -435,7 +436,10 @@ send_pending_click_to_window(Window *w, void *data) { ClickQueue *q = &w->click_queues[pc->button]; // only send click if no presses have happened since the release that triggered the click if (q->length && q->clicks[q->length - 1].at <= pc->at) { + MousePosition current_pos = w->mouse_pos; + w->mouse_pos = pc->mouse_pos; dispatch_mouse_event(w, pc->button, pc->count, pc->modifiers, pc->grabbed); + w->mouse_pos = current_pos; } } @@ -447,6 +451,7 @@ dispatch_possible_click(Window *w, int button, int modifiers) { PendingClick *pc = calloc(sizeof(PendingClick), 1); if (pc) { pc->window_id = w->id; + pc->mouse_pos = w->mouse_pos; pc->at = monotonic(); pc->button = button; pc->count = count == 2 ? -3 : -2; diff --git a/kitty/state.h b/kitty/state.h index 5573af99a..189b2ebf4 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -101,6 +101,12 @@ typedef struct { unsigned int length; } ClickQueue; +typedef struct MousePosition { + unsigned int cell_x, cell_y; + double x, y; + bool in_left_half_of_cell; +} MousePosition; + typedef struct { id_type id; bool visible, cursor_visible_at_last_render; @@ -108,11 +114,7 @@ typedef struct { CursorShape last_cursor_shape; PyObject *title; ScreenRenderData render_data; - struct { - unsigned int cell_x, cell_y; - double x, y; - bool in_left_half_of_cell; - } mouse_pos; + MousePosition mouse_pos; struct { unsigned int left, top, right, bottom; } padding;