From e4fab9a20bf5e2cfb5681a8a378ff756e06dfe76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 29 Dec 2018 21:17:08 +0100 Subject: [PATCH] particle/map: fix on_mouse() regression Now that we have a wrapper exposable, we need to implement on_mouse(). In it, we need to check if we have our own on-click handler, or else, check if mouse is inside the sub-exposable, or in the left- or right margin. --- particles/map.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/particles/map.c b/particles/map.c index 242a7b8..c32b189 100644 --- a/particles/map.c +++ b/particles/map.c @@ -48,6 +48,30 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height) e->exposable, cr, x + exposable->particle->left_margin, y, height); } +static void +on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, + int x, int y) +{ + const struct particle *p = exposable->particle; + const struct eprivate *e = exposable->private; + + if (exposable->on_click != NULL) { + /* We have our own handler */ + exposable_default_on_mouse(exposable, bar, event, x, y); + return; + } + + int px = p->left_margin; + if (x >= px && x < px + e->exposable->width) { + if (e->exposable->on_mouse != NULL) + e->exposable->on_mouse(e->exposable, bar, event, x - px, y); + return; + } + + /* In the left- or right margin */ + exposable_default_on_mouse(exposable, bar, event, x, y); +} + static struct exposable * instantiate(const struct particle *particle, const struct tag_set *tags) { @@ -86,6 +110,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags) exposable->destroy = &exposable_destroy; exposable->begin_expose = &begin_expose; exposable->expose = &expose; + exposable->on_mouse = &on_mouse; free(on_click); return exposable;