From bef613e656a36400577cde295b09267c80f3adce Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 9 Aug 2024 08:20:59 +0200 Subject: csd: track pointer when rendering and handling CSD button clicks * Render button as highlighted only when pointer is above them * Releasing the mouse button while *not* on the button does *not* activate the button When pressing, and holding, a mouse button, the compositor keeps sending motion events for the surface where the button was pressed, even if the mouse has moved outside it. We also don't get any surface leave/enter events. This meant that the button was rendered as highlighted, and a click registered, if the user pressed the mouse button while on the button, and then moved the cursor away from the button before releasing the button. This patch fixes it, by checking if the current cursor coordinates fall within the button surface. --- render.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 279e51bf..d9630983 100644 --- a/render.c +++ b/render.c @@ -2627,6 +2627,32 @@ render_csd_button_close(struct terminal *term, struct buffer *buf) pixman_image_unref(src); } +static bool +any_pointer_is_on_button(const struct terminal *term, enum csd_surface csd_surface) +{ + if (unlikely(tll_length(term->wl->seats) == 0)) + return false; + + tll_foreach(term->wl->seats, it) { + const struct seat *seat = &it->item; + + if (seat->mouse.x < 0) + continue; + if (seat->mouse.y < 0) + continue; + + struct csd_data info = get_csd_data(term, csd_surface); + if (seat->mouse.x > info.width) + continue; + + if (seat->mouse.y > info.height) + continue; + return true; + } + + return false; +} + static void render_csd_button(struct terminal *term, enum csd_surface surf_idx, const struct csd_data *info, struct buffer *buf) @@ -2650,21 +2676,24 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx, _color = term->conf->colors.table[4]; /* blue */ is_set = term->conf->csd.color.minimize_set; conf_color = &term->conf->csd.color.minimize; - is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE; + is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE && + any_pointer_is_on_button(term, CSD_SURF_MINIMIZE); break; case CSD_SURF_MAXIMIZE: _color = term->conf->colors.table[2]; /* green */ is_set = term->conf->csd.color.maximize_set; conf_color = &term->conf->csd.color.maximize; - is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE; + is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE && + any_pointer_is_on_button(term, CSD_SURF_MAXIMIZE); break; case CSD_SURF_CLOSE: _color = term->conf->colors.table[1]; /* red */ is_set = term->conf->csd.color.close_set; conf_color = &term->conf->csd.color.quit; - is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE; + is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE && + any_pointer_is_on_button(term, CSD_SURF_CLOSE); break; default: -- cgit v1.3