mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
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 (*loop)(struct bar *bar,
|
||||||
void (*expose)(const struct bar *bar),
|
void (*expose)(const struct bar *bar),
|
||||||
void (*on_mouse)(struct bar *bar, enum mouse_event event,
|
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 (*commit)(const struct bar *bar);
|
||||||
void (*refresh)(const struct bar *bar);
|
void (*refresh)(const struct bar *bar);
|
||||||
void (*set_cursor)(struct bar *bar, const char *cursor);
|
void (*set_cursor)(struct bar *bar, const char *cursor);
|
||||||
|
|
|
@ -151,7 +151,8 @@ set_cursor(struct bar *bar, const char *cursor)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
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;
|
mx += bar->left_spacing;
|
||||||
if (x >= mx && x < mx + e->width) {
|
if (x >= mx && x < mx + e->width) {
|
||||||
if (e->on_mouse != NULL)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +188,7 @@ on_mouse(struct bar *_bar, enum mouse_event event, int x, int y)
|
||||||
mx += bar->left_spacing;
|
mx += bar->left_spacing;
|
||||||
if (x >= mx && x < mx + e->width) {
|
if (x >= mx && x < mx + e->width) {
|
||||||
if (e->on_mouse != NULL)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +206,7 @@ on_mouse(struct bar *_bar, enum mouse_event event, int x, int y)
|
||||||
mx += bar->left_spacing;
|
mx += bar->left_spacing;
|
||||||
if (x >= mx && x < mx + e->width) {
|
if (x >= mx && x < mx + e->width) {
|
||||||
if (e->on_mouse != NULL)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <linux/memfd.h>
|
#include <linux/memfd.h>
|
||||||
|
#include <linux/input-event-codes.h>
|
||||||
|
|
||||||
#include <pixman.h>
|
#include <pixman.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
@ -113,7 +114,8 @@ struct wayland_backend {
|
||||||
struct buffer *pending_buffer; /* Finished, but not yet rendered */
|
struct buffer *pending_buffer; /* Finished, but not yet rendered */
|
||||||
|
|
||||||
void (*bar_expose)(const struct bar *bar);
|
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
|
static void
|
||||||
|
@ -262,7 +264,8 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
|
||||||
|
|
||||||
backend->active_seat = seat;
|
backend->active_seat = seat;
|
||||||
backend->bar_on_mouse(
|
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
|
static void
|
||||||
|
@ -276,8 +279,19 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
||||||
struct wayland_backend *backend = seat->backend;
|
struct wayland_backend *backend = seat->backend;
|
||||||
|
|
||||||
backend->active_seat = seat;
|
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(
|
||||||
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
|
static void
|
||||||
|
@ -1011,7 +1025,8 @@ cleanup(struct bar *_bar)
|
||||||
static void
|
static void
|
||||||
loop(struct bar *_bar,
|
loop(struct bar *_bar,
|
||||||
void (*expose)(const 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 private *bar = _bar->private;
|
||||||
struct wayland_backend *backend = bar->backend.data;
|
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
|
static void
|
||||||
loop(struct bar *_bar,
|
loop(struct bar *_bar,
|
||||||
void (*expose)(const 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 private *bar = _bar->private;
|
||||||
struct xcb_backend *backend = bar->backend.data;
|
struct xcb_backend *backend = bar->backend.data;
|
||||||
|
@ -357,7 +358,7 @@ loop(struct bar *_bar,
|
||||||
|
|
||||||
case XCB_MOTION_NOTIFY: {
|
case XCB_MOTION_NOTIFY: {
|
||||||
const xcb_motion_notify_event_t *evt = (void *)e;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +367,13 @@ loop(struct bar *_bar,
|
||||||
|
|
||||||
case XCB_BUTTON_RELEASE: {
|
case XCB_BUTTON_RELEASE: {
|
||||||
const xcb_button_release_event_t *evt = (void *)e;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,10 +141,11 @@ err:
|
||||||
|
|
||||||
void
|
void
|
||||||
exposable_default_on_mouse(struct exposable *exposable, struct bar *bar,
|
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)",
|
LOG_DBG("on_mouse: exposable=%p, event=%s, btn=%d, x=%d, y=%d (on-click=%s)",
|
||||||
exposable, event == ON_MOUSE_MOTION ? "motion" : "click", x, y,
|
exposable, event == ON_MOUSE_MOTION ? "motion" : "click", btn, x, y,
|
||||||
exposable->on_click);
|
exposable->on_click);
|
||||||
|
|
||||||
/* If we have a handler, change cursor to a hand */
|
/* 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,
|
ON_MOUSE_CLICK,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum mouse_button {
|
||||||
|
MOUSE_BTN_NONE,
|
||||||
|
MOUSE_BTN_LEFT,
|
||||||
|
MOUSE_BTN_MIDDLE,
|
||||||
|
MOUSE_BTN_RIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
struct exposable {
|
struct exposable {
|
||||||
const struct particle *particle;
|
const struct particle *particle;
|
||||||
void *private;
|
void *private;
|
||||||
|
@ -42,7 +49,7 @@ struct exposable {
|
||||||
int x, int y, int height);
|
int x, int y, int height);
|
||||||
|
|
||||||
void (*on_mouse)(struct exposable *exposable, struct bar *bar,
|
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(
|
struct particle *particle_common_new(
|
||||||
|
@ -59,7 +66,7 @@ void exposable_render_deco(
|
||||||
|
|
||||||
void exposable_default_on_mouse(
|
void exposable_default_on_mouse(
|
||||||
struct exposable *exposable, struct bar *bar,
|
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 */
|
/* List of attributes *all* particles implement */
|
||||||
#define PARTICLE_COMMON_ATTRS \
|
#define PARTICLE_COMMON_ATTRS \
|
||||||
|
|
|
@ -67,13 +67,13 @@ dynlist_expose(const struct exposable *exposable, pixman_image_t *pix, int x, in
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_mouse(struct exposable *exposable, struct bar *bar,
|
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 particle *p = exposable->particle;
|
||||||
const struct private *e = exposable->private;
|
const struct private *e = exposable->private;
|
||||||
|
|
||||||
if (exposable->on_click != NULL) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ on_mouse(struct exposable *exposable, struct bar *bar,
|
||||||
if (x >= px && x < px + e->exposables[i]->width) {
|
if (x >= px && x < px + e->exposables[i]->width) {
|
||||||
if (e->exposables[i]->on_mouse != NULL) {
|
if (e->exposables[i]->on_mouse != NULL) {
|
||||||
e->exposables[i]->on_mouse(
|
e->exposables[i]->on_mouse(
|
||||||
e->exposables[i], bar, event, x - px, y);
|
e->exposables[i], bar, event, btn, x - px, y);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ on_mouse(struct exposable *exposable, struct bar *bar,
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DBG("on_mouse missed all sub-particles");
|
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 *
|
struct exposable *
|
||||||
|
|
|
@ -75,14 +75,14 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_mouse(struct exposable *exposable, struct bar *bar,
|
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 particle *p = exposable->particle;
|
||||||
const struct eprivate *e = exposable->private;
|
const struct eprivate *e = exposable->private;
|
||||||
|
|
||||||
if (exposable->on_click != NULL) {
|
if (exposable->on_click != NULL) {
|
||||||
/* We have our own handler */
|
/* 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ on_mouse(struct exposable *exposable, struct bar *bar,
|
||||||
if (x >= px && x < px + e->exposables[i]->width) {
|
if (x >= px && x < px + e->exposables[i]->width) {
|
||||||
if (e->exposables[i]->on_mouse != NULL) {
|
if (e->exposables[i]->on_mouse != NULL) {
|
||||||
e->exposables[i]->on_mouse(
|
e->exposables[i]->on_mouse(
|
||||||
e->exposables[i], bar, event, x - px, y);
|
e->exposables[i], bar, event, btn, x - px, y);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ on_mouse(struct exposable *exposable, struct bar *bar,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We're between sub-particles (or in the left/right margin) */
|
/* 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 *
|
static struct exposable *
|
||||||
|
|
|
@ -61,26 +61,26 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
|
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 particle *p = exposable->particle;
|
||||||
const struct eprivate *e = exposable->private;
|
const struct eprivate *e = exposable->private;
|
||||||
|
|
||||||
if (exposable->on_click != NULL) {
|
if (exposable->on_click != NULL) {
|
||||||
/* We have our own handler */
|
/* 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int px = p->left_margin;
|
int px = p->left_margin;
|
||||||
if (x >= px && x < px + e->exposable->width) {
|
if (x >= px && x < px + e->exposable->width) {
|
||||||
if (e->exposable->on_mouse != NULL)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In the left- or right margin */
|
/* 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 *
|
static struct exposable *
|
||||||
|
|
|
@ -85,10 +85,10 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
|
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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
|
||||||
/* Mouse is over the start-marker */
|
/* Mouse is over the start-marker */
|
||||||
struct exposable *start = e->exposables[0];
|
struct exposable *start = e->exposables[0];
|
||||||
if (start->on_mouse != NULL)
|
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 {
|
} else {
|
||||||
/* Mouse if over left margin */
|
/* Mouse if over left margin */
|
||||||
bar->set_cursor(bar, "left_ptr");
|
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 */
|
/* Mouse is over the end-marker */
|
||||||
struct exposable *end = e->exposables[e->count - 1];
|
struct exposable *end = e->exposables[e->count - 1];
|
||||||
if (end->on_mouse != NULL)
|
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 {
|
} else {
|
||||||
/* Mouse is over the right margin */
|
/* Mouse is over the right margin */
|
||||||
bar->set_cursor(bar, "left_ptr");
|
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 */
|
/* 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) {
|
if (event == ON_MOUSE_CLICK) {
|
||||||
/* Reset handler string */
|
/* Reset handler string */
|
||||||
|
|
|
@ -57,26 +57,26 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_mouse(struct exposable *exposable, struct bar *bar, enum mouse_event event,
|
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 particle *p = exposable->particle;
|
||||||
const struct eprivate *e = exposable->private;
|
const struct eprivate *e = exposable->private;
|
||||||
|
|
||||||
if (exposable->on_click != NULL) {
|
if (exposable->on_click != NULL) {
|
||||||
/* We have our own handler */
|
/* 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int px = p->left_margin;
|
int px = p->left_margin;
|
||||||
if (x >= px && x < px + e->exposable->width) {
|
if (x >= px && x < px + e->exposable->width) {
|
||||||
if (e->exposable->on_mouse != NULL)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In the left- or right margin */
|
/* 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
|
static void
|
||||||
|
|
Loading…
Add table
Reference in a new issue