From 012162837d25b79c4f8e54f5cc49e2588e9343ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 23 Sep 2019 18:39:03 +0200 Subject: [PATCH] particle/progress-bar: expand and replace on-click handler on click events only No need to do it in motion events. --- particles/progress-bar.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/particles/progress-bar.c b/particles/progress-bar.c index 06e53b2..5c16802 100644 --- a/particles/progress-bar.c +++ b/particles/progress-bar.c @@ -147,25 +147,31 @@ on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, return; } - long where = clickable_width > 0 - ? 100 * (x - x_offset) / clickable_width - : 0; - - struct tag_set tags = { - .tags = (struct tag *[]){tag_new_int(NULL, "where", where)}, - .count = 1, - }; - + /* Remember the original handler, so that we can restore it */ char *original = exposable->on_click; - exposable->on_click = tags_expand_template(exposable->on_click, &tags); - tag_set_destroy(&tags); + + if (event == ON_MOUSE_CLICK) { + long where = clickable_width > 0 + ? 100 * (x - x_offset) / clickable_width + : 0; + + struct tag_set tags = { + .tags = (struct tag *[]){tag_new_int(NULL, "where", where)}, + .count = 1, + }; + + exposable->on_click = tags_expand_template(exposable->on_click, &tags); + tag_set_destroy(&tags); + } /* Call default implementation, which will execute our handler */ exposable_default_on_mouse(exposable, bar, event, x, y); - /* Reset handler string */ - free(exposable->on_click); - exposable->on_click = original; + if (event == ON_MOUSE_CLICK) { + /* Reset handler string */ + free(exposable->on_click); + exposable->on_click = original; + } } static struct exposable *