aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-08-09 06:20:59 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-08-09 06:20:59 +0000
commitbef613e656a36400577cde295b09267c80f3adce (patch)
tree245025554197e8df66524eb0e327eb0e4d4ac204 /render.c
parentinput: CSD buttons are now triggered when releasing the mouse button (diff)
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.
Diffstat (limited to 'render.c')
-rw-r--r--render.c35
1 files changed, 32 insertions, 3 deletions
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: