diff --git a/bar/backend.h b/bar/backend.h index f2681a8..d365da6 100644 --- a/bar/backend.h +++ b/bar/backend.h @@ -10,7 +10,7 @@ struct backend { void (*loop)(struct bar *bar, void (*expose)(const struct bar *bar), void (*on_mouse)(struct bar *bar, enum mouse_event event, - int x, int y)); + enum mouse_button btn, int x, int y)); void (*commit)(const struct bar *bar); void (*refresh)(const struct bar *bar); void (*set_cursor)(struct bar *bar, const char *cursor); diff --git a/bar/bar.c b/bar/bar.c index 0e51608..b7557fd 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -151,7 +151,8 @@ set_cursor(struct bar *bar, const char *cursor) } static void -on_mouse(struct bar *_bar, enum mouse_event event, int x, int y) +on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, + int x, int y) { struct private *bar = _bar->private; @@ -173,7 +174,7 @@ on_mouse(struct bar *_bar, enum mouse_event event, int x, int y) mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { if (e->on_mouse != NULL) - e->on_mouse(e, _bar, event, x - mx, y); + e->on_mouse(e, _bar, event, btn, x - mx, y); return; } @@ -187,7 +188,7 @@ on_mouse(struct bar *_bar, enum mouse_event event, int x, int y) mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { if (e->on_mouse != NULL) - e->on_mouse(e, _bar, event, x - mx, y); + e->on_mouse(e, _bar, event, btn, x - mx, y); return; } @@ -205,7 +206,7 @@ on_mouse(struct bar *_bar, enum mouse_event event, int x, int y) mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { if (e->on_mouse != NULL) - e->on_mouse(e, _bar, event, x - mx, y); + e->on_mouse(e, _bar, event, btn, x - mx, y); return; } diff --git a/bar/wayland.c b/bar/wayland.c index 1a72577..05a12a9 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -113,7 +114,8 @@ struct wayland_backend { struct buffer *pending_buffer; /* Finished, but not yet rendered */ void (*bar_expose)(const struct bar *bar); - void (*bar_on_mouse)(struct bar *bar, enum mouse_event event, int x, int y); + void (*bar_on_mouse)(struct bar *bar, enum mouse_event event, + enum mouse_button btn, int x, int y); }; static void @@ -262,7 +264,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, backend->active_seat = seat; backend->bar_on_mouse( - backend->bar, ON_MOUSE_MOTION, seat->pointer.x, seat->pointer.y); + backend->bar, ON_MOUSE_MOTION, MOUSE_BTN_NONE, + seat->pointer.x, seat->pointer.y); } static void @@ -276,8 +279,19 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, struct wayland_backend *backend = seat->backend; backend->active_seat = seat; + + enum mouse_button btn; + + switch (button) { + case BTN_LEFT: btn = MOUSE_BTN_LEFT; break; + case BTN_MIDDLE: btn = MOUSE_BTN_MIDDLE; break; + case BTN_RIGHT: btn = MOUSE_BTN_RIGHT; break; + default: + return; + } + backend->bar_on_mouse( - backend->bar, ON_MOUSE_CLICK, seat->pointer.x, seat->pointer.y); + backend->bar, ON_MOUSE_CLICK, btn, seat->pointer.x, seat->pointer.y); } static void @@ -1011,7 +1025,8 @@ cleanup(struct bar *_bar) static void loop(struct bar *_bar, void (*expose)(const struct bar *bar), - void (*on_mouse)(struct bar *bar, enum mouse_event event, int x, int y)) + void (*on_mouse)(struct bar *bar, enum mouse_event event, + enum mouse_button btn, int x, int y)) { struct private *bar = _bar->private; struct wayland_backend *backend = bar->backend.data; diff --git a/bar/xcb.c b/bar/xcb.c index 99b787d..6229bc5 100644 --- a/bar/xcb.c +++ b/bar/xcb.c @@ -312,7 +312,8 @@ cleanup(struct bar *_bar) static void loop(struct bar *_bar, void (*expose)(const struct bar *bar), - void (*on_mouse)(struct bar *bar, enum mouse_event event, int x, int y)) + void (*on_mouse)(struct bar *bar, enum mouse_event event, + enum mouse_button btn, int x, int y)) { struct private *bar = _bar->private; struct xcb_backend *backend = bar->backend.data; @@ -357,7 +358,7 @@ loop(struct bar *_bar, case XCB_MOTION_NOTIFY: { const xcb_motion_notify_event_t *evt = (void *)e; - on_mouse(_bar, ON_MOUSE_MOTION, evt->event_x, evt->event_y); + on_mouse(_bar, ON_MOUSE_MOTION, MOUSE_BTN_NONE, evt->event_x, evt->event_y); break; } @@ -366,7 +367,13 @@ loop(struct bar *_bar, case XCB_BUTTON_RELEASE: { const xcb_button_release_event_t *evt = (void *)e; - on_mouse(_bar, ON_MOUSE_CLICK, evt->event_x, evt->event_y); + + switch (evt->detail) { + case 1: case 2: case 3: + on_mouse(_bar, ON_MOUSE_CLICK, + evt->detail, evt->event_x, evt->event_y); + break; + } break; } diff --git a/particle.c b/particle.c index ffe330f..2ce4800 100644 --- a/particle.c +++ b/particle.c @@ -141,10 +141,11 @@ err: void exposable_default_on_mouse(struct exposable *exposable, struct bar *bar, - enum mouse_event event, int x, int y) + enum mouse_event event, enum mouse_button btn, + int x, int y) { - LOG_DBG("on_mouse: exposable=%p, event=%s, x=%d, y=%d (on-click=%s)", - exposable, event == ON_MOUSE_MOTION ? "motion" : "click", x, y, + LOG_DBG("on_mouse: exposable=%p, event=%s, btn=%d, x=%d, y=%d (on-click=%s)", + exposable, event == ON_MOUSE_MOTION ? "motion" : "click", btn, x, y, exposable->on_click); /* If we have a handler, change cursor to a hand */ diff --git a/particle.h b/particle.h index e89b9c4..1fc582a 100644 --- a/particle.h +++ b/particle.h @@ -29,6 +29,13 @@ enum mouse_event { ON_MOUSE_CLICK, }; +enum mouse_button { + MOUSE_BTN_NONE, + MOUSE_BTN_LEFT, + MOUSE_BTN_MIDDLE, + MOUSE_BTN_RIGHT, +}; + struct exposable { const struct particle *particle; void *private; @@ -42,7 +49,7 @@ struct exposable { int x, int y, int height); void (*on_mouse)(struct exposable *exposable, struct bar *bar, - enum mouse_event event, int x, int y); + enum mouse_event event, enum mouse_button btn, int x, int y); }; struct particle *particle_common_new( @@ -59,7 +66,7 @@ void exposable_render_deco( void exposable_default_on_mouse( struct exposable *exposable, struct bar *bar, - enum mouse_event event, int x, int y); + enum mouse_event event, enum mouse_button btn, int x, int y); /* List of attributes *all* particles implement */ #define PARTICLE_COMMON_ATTRS \ diff --git a/particles/dynlist.c b/particles/dynlist.c index c04d610..00bb41f 100644 --- a/particles/dynlist.c +++ b/particles/dynlist.c @@ -67,13 +67,13 @@ dynlist_expose(const struct exposable *exposable, pixman_image_t *pix, int x, in static void on_mouse(struct exposable *exposable, struct bar *bar, - enum mouse_event event, int x, int y) + enum mouse_event event, enum mouse_button btn, int x, int y) { //const struct particle *p = exposable->particle; const struct private *e = exposable->private; if (exposable->on_click != NULL) { - exposable_default_on_mouse(exposable, bar, event, x, y); + exposable_default_on_mouse(exposable, bar, event, btn, x, y); return; } @@ -82,7 +82,7 @@ on_mouse(struct exposable *exposable, struct bar *bar, if (x >= px && x < px + e->exposables[i]->width) { if (e->exposables[i]->on_mouse != NULL) { e->exposables[i]->on_mouse( - e->exposables[i], bar, event, x - px, y); + e->exposables[i], bar, event, btn, x - px, y); } return; } @@ -91,7 +91,7 @@ on_mouse(struct exposable *exposable, struct bar *bar, } LOG_DBG("on_mouse missed all sub-particles"); - exposable_default_on_mouse(exposable, bar, event, x, y); + exposable_default_on_mouse(exposable, bar, event, btn, x, y); } struct exposable * diff --git a/particles/list.c b/particles/list.c index 6f51152..f9e61f6 100644 --- a/particles/list.c +++ b/particles/list.c @@ -75,14 +75,14 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int static void on_mouse(struct exposable *exposable, struct bar *bar, - enum mouse_event event, int x, int y) + enum mouse_event event, enum mouse_button btn, 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); + exposable_default_on_mouse(exposable, bar, event, btn, x, y); return; } @@ -91,7 +91,7 @@ on_mouse(struct exposable *exposable, struct bar *bar, if (x >= px && x < px + e->exposables[i]->width) { if (e->exposables[i]->on_mouse != NULL) { e->exposables[i]->on_mouse( - e->exposables[i], bar, event, x - px, y); + e->exposables[i], bar, event, btn, x - px, y); } return; } @@ -100,7 +100,7 @@ on_mouse(struct exposable *exposable, struct bar *bar, } /* We're between sub-particles (or in the left/right margin) */ - exposable_default_on_mouse(exposable, bar, event, x, y); + exposable_default_on_mouse(exposable, bar, event, btn, x, y); } static struct exposable * diff --git a/particles/map.c b/particles/map.c index 57bb0fb..cc26f77 100644 --- a/particles/map.c +++ b/particles/map.c @@ -61,26 +61,26 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int static void on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, - int x, int y) + enum mouse_button btn, 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); + exposable_default_on_mouse(exposable, bar, event, btn, 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); + e->exposable->on_mouse(e->exposable, bar, event, btn, x - px, y); return; } /* In the left- or right margin */ - exposable_default_on_mouse(exposable, bar, event, x, y); + exposable_default_on_mouse(exposable, bar, event, btn, x, y); } static struct exposable * diff --git a/particles/progress-bar.c b/particles/progress-bar.c index ad5c4cd..62a58b9 100644 --- a/particles/progress-bar.c +++ b/particles/progress-bar.c @@ -85,10 +85,10 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int static void on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, - int x, int y) + enum mouse_button btn, int x, int y) { if (exposable->on_click == NULL) { - exposable_default_on_mouse(exposable, bar, event, x, y); + exposable_default_on_mouse(exposable, bar, event, btn, x, y); return; } @@ -120,7 +120,7 @@ on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, /* Mouse is over the start-marker */ struct exposable *start = e->exposables[0]; if (start->on_mouse != NULL) - start->on_mouse(start, bar, event, x - p->left_margin, y); + start->on_mouse(start, bar, event, btn, x - p->left_margin, y); } else { /* Mouse if over left margin */ bar->set_cursor(bar, "left_ptr"); @@ -139,7 +139,7 @@ on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, /* Mouse is over the end-marker */ struct exposable *end = e->exposables[e->count - 1]; if (end->on_mouse != NULL) - end->on_mouse(end, bar, event, x - x_offset - clickable_width, y); + end->on_mouse(end, bar, event, btn, x - x_offset - clickable_width, y); } else { /* Mouse is over the right margin */ bar->set_cursor(bar, "left_ptr"); @@ -165,7 +165,7 @@ on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, } /* Call default implementation, which will execute our handler */ - exposable_default_on_mouse(exposable, bar, event, x, y); + exposable_default_on_mouse(exposable, bar, event, btn, x, y); if (event == ON_MOUSE_CLICK) { /* Reset handler string */ diff --git a/particles/ramp.c b/particles/ramp.c index 9a7f06e..8087217 100644 --- a/particles/ramp.c +++ b/particles/ramp.c @@ -57,26 +57,26 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int static void on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event, - int x, int y) + enum mouse_button btn, 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); + exposable_default_on_mouse(exposable, bar, event, btn, 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); + e->exposable->on_mouse(e->exposable, bar, event, btn, x - px, y); return; } /* In the left- or right margin */ - exposable_default_on_mouse(exposable, bar, event, x, y); + exposable_default_on_mouse(exposable, bar, event, btn, x, y); } static void