exposable: add ‘btn’ argument to on_mouse()

This commit is contained in:
Daniel Eklöf 2021-06-21 21:00:07 +02:00
parent 8f7ef7c20b
commit dd724d1bc2
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
11 changed files with 69 additions and 38 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}