mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-23 12:35:41 +02:00
bar/wayland: call on_mouse() directly from listeners
This commit is contained in:
parent
85a1940e47
commit
29b57bcc48
1 changed files with 30 additions and 40 deletions
|
@ -54,6 +54,8 @@ struct monitor {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wayland_backend {
|
struct wayland_backend {
|
||||||
|
struct bar *bar;
|
||||||
|
|
||||||
struct wl_display *display;
|
struct wl_display *display;
|
||||||
struct wl_registry *registry;
|
struct wl_registry *registry;
|
||||||
struct wl_compositor *compositor;
|
struct wl_compositor *compositor;
|
||||||
|
@ -92,6 +94,9 @@ struct wayland_backend {
|
||||||
tll(struct buffer) buffers; /* List of SHM buffers */
|
tll(struct buffer) buffers; /* List of SHM buffers */
|
||||||
struct buffer *next_buffer; /* Bar is rendering to this one */
|
struct buffer *next_buffer; /* Bar is rendering to this one */
|
||||||
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_on_mouse)(struct bar *bar, enum mouse_event event, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
@ -154,13 +159,12 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
|
||||||
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
|
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
|
||||||
{
|
{
|
||||||
struct wayland_backend *backend = data;
|
struct wayland_backend *backend = data;
|
||||||
//printf("MOTION: %dx%d\n", wl_fixed_to_int(surface_x), wl_fixed_to_int(surface_y));
|
|
||||||
backend->pointer.x = wl_fixed_to_int(surface_x);
|
backend->pointer.x = wl_fixed_to_int(surface_x);
|
||||||
backend->pointer.y = wl_fixed_to_int(surface_y);
|
backend->pointer.y = wl_fixed_to_int(surface_y);
|
||||||
|
|
||||||
write(backend->pipe_fds[1], &(uint8_t){3}, sizeof(uint8_t));
|
backend->bar_on_mouse(
|
||||||
write(backend->pipe_fds[1], &backend->pointer.x, sizeof(backend->pointer.x));
|
backend->bar, ON_MOUSE_MOTION, backend->pointer.x, backend->pointer.y);
|
||||||
write(backend->pipe_fds[1], &backend->pointer.y, sizeof(backend->pointer.y));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -171,11 +175,8 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct wayland_backend *backend = data;
|
struct wayland_backend *backend = data;
|
||||||
//printf("BUTTON: %dx%d\n", backend->pointer.x, backend->pointer.y);
|
backend->bar_on_mouse(
|
||||||
|
backend->bar, ON_MOUSE_CLICK, backend->pointer.x, backend->pointer.y);
|
||||||
write(backend->pipe_fds[1], &(uint8_t){2}, sizeof(uint8_t));
|
|
||||||
write(backend->pipe_fds[1], &backend->pointer.x, sizeof(backend->pointer.x));
|
|
||||||
write(backend->pipe_fds[1], &backend->pointer.y, sizeof(backend->pointer.y));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -481,6 +482,8 @@ setup(struct bar *_bar)
|
||||||
struct private *bar = _bar->private;
|
struct private *bar = _bar->private;
|
||||||
struct wayland_backend *backend = bar->backend.data;
|
struct wayland_backend *backend = bar->backend.data;
|
||||||
|
|
||||||
|
backend->bar = _bar;
|
||||||
|
|
||||||
backend->display = wl_display_connect(NULL);
|
backend->display = wl_display_connect(NULL);
|
||||||
assert(backend->display != NULL);
|
assert(backend->display != NULL);
|
||||||
|
|
||||||
|
@ -622,6 +625,9 @@ loop(struct bar *_bar,
|
||||||
struct private *bar = _bar->private;
|
struct private *bar = _bar->private;
|
||||||
struct wayland_backend *backend = bar->backend.data;
|
struct wayland_backend *backend = bar->backend.data;
|
||||||
|
|
||||||
|
backend->bar_expose = expose;
|
||||||
|
backend->bar_on_mouse = on_mouse;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
while (wl_display_prepare_read(backend->display) != 0){
|
while (wl_display_prepare_read(backend->display) != 0){
|
||||||
//printf("initial wayland event\n");
|
//printf("initial wayland event\n");
|
||||||
|
@ -660,9 +666,8 @@ loop(struct bar *_bar,
|
||||||
//wl_display_cancel_read(backend->display);
|
//wl_display_cancel_read(backend->display);
|
||||||
read(backend->pipe_fds[0], &command, sizeof(command));
|
read(backend->pipe_fds[0], &command, sizeof(command));
|
||||||
|
|
||||||
if (command == 1) {
|
|
||||||
//printf("refresh\n");
|
|
||||||
assert(command == 1);
|
assert(command == 1);
|
||||||
|
//printf("refresh\n");
|
||||||
expose(_bar);
|
expose(_bar);
|
||||||
#if 0
|
#if 0
|
||||||
while (wl_display_prepare_read(backend->display) != 0) {
|
while (wl_display_prepare_read(backend->display) != 0) {
|
||||||
|
@ -673,23 +678,7 @@ loop(struct bar *_bar,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == 2) {
|
if (fds[1].revents & POLLIN) {
|
||||||
//printf("mouse\n");
|
|
||||||
int x, y;
|
|
||||||
read(backend->pipe_fds[0], &x, sizeof(x));
|
|
||||||
read(backend->pipe_fds[0], &y, sizeof(y));
|
|
||||||
on_mouse(_bar, ON_MOUSE_CLICK, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command == 3) {
|
|
||||||
int x, y;
|
|
||||||
read(backend->pipe_fds[0], &x, sizeof(x));
|
|
||||||
read(backend->pipe_fds[0], &y, sizeof(y));
|
|
||||||
on_mouse(_bar, ON_MOUSE_MOTION, x, y);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
//printf("wayland events\n");
|
//printf("wayland events\n");
|
||||||
wl_display_read_events(backend->display);
|
wl_display_read_events(backend->display);
|
||||||
|
@ -698,6 +687,7 @@ loop(struct bar *_bar,
|
||||||
//printf("wayland events\n");
|
//printf("wayland events\n");
|
||||||
wl_display_dispatch(backend->display);
|
wl_display_dispatch(backend->display);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void frame_callback(
|
static void frame_callback(
|
||||||
|
|
Loading…
Add table
Reference in a new issue