Fix mouse click event using current mouse co-ords rather than the co-ords at the time of the click

This commit is contained in:
Kovid Goyal 2021-07-22 07:31:30 +05:30
parent 92f428b6d1
commit f61b8608de
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 5 deletions

View File

@ -424,6 +424,7 @@ typedef struct PendingClick {
int button, count, modifiers; int button, count, modifiers;
bool grabbed; bool grabbed;
monotonic_t at; monotonic_t at;
MousePosition mouse_pos;
} PendingClick; } PendingClick;
static void static void
@ -435,7 +436,10 @@ send_pending_click_to_window(Window *w, void *data) {
ClickQueue *q = &w->click_queues[pc->button]; ClickQueue *q = &w->click_queues[pc->button];
// only send click if no presses have happened since the release that triggered the click // 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) { 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); 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); PendingClick *pc = calloc(sizeof(PendingClick), 1);
if (pc) { if (pc) {
pc->window_id = w->id; pc->window_id = w->id;
pc->mouse_pos = w->mouse_pos;
pc->at = monotonic(); pc->at = monotonic();
pc->button = button; pc->button = button;
pc->count = count == 2 ? -3 : -2; pc->count = count == 2 ? -3 : -2;

View File

@ -101,6 +101,12 @@ typedef struct {
unsigned int length; unsigned int length;
} ClickQueue; } ClickQueue;
typedef struct MousePosition {
unsigned int cell_x, cell_y;
double x, y;
bool in_left_half_of_cell;
} MousePosition;
typedef struct { typedef struct {
id_type id; id_type id;
bool visible, cursor_visible_at_last_render; bool visible, cursor_visible_at_last_render;
@ -108,11 +114,7 @@ typedef struct {
CursorShape last_cursor_shape; CursorShape last_cursor_shape;
PyObject *title; PyObject *title;
ScreenRenderData render_data; ScreenRenderData render_data;
struct { MousePosition mouse_pos;
unsigned int cell_x, cell_y;
double x, y;
bool in_left_half_of_cell;
} mouse_pos;
struct { struct {
unsigned int left, top, right, bottom; unsigned int left, top, right, bottom;
} padding; } padding;