forked from external/yambar
exposable: add ‘btn’ argument to on_mouse()
This commit is contained in:
parent
8f7ef7c20b
commit
dd724d1bc2
11 changed files with 69 additions and 38 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <sys/mman.h>
|
||||
#include <linux/memfd.h>
|
||||
#include <linux/input-event-codes.h>
|
||||
|
||||
#include <pixman.h>
|
||||
#include <wayland-client.h>
|
||||
|
@ -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;
|
||||
|
|
13
bar/xcb.c
13
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
11
particle.h
11
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 \
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue