commit c8a64305fd746ab1b33367d3ffcc9fa054221717
parent 9889b14511e95b29855aa265c19e57e9cd86cd1b
Author: David Eklov <david.eklov@gmail.com>
Date: Tue, 5 Jul 2016 01:21:56 -0500
Enable windows to register to get notified of pointer button events
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/include/client/window.h b/include/client/window.h
@@ -9,6 +9,8 @@
#include "list.h"
#include "client/registry.h"
+struct window;
+
struct buffer {
struct wl_buffer *buffer;
cairo_surface_t *surface;
@@ -25,6 +27,13 @@ struct cursor {
struct wl_poitner *pointer;
};
+struct pointer_input {
+ wl_fixed_t last_x;
+ wl_fixed_t last_y;
+
+ void (*notify)(struct window *window, wl_fixed_t x, wl_fixed_t y, uint32_t button);
+};
+
struct window {
struct registry *registry;
struct buffer buffers[2];
@@ -36,6 +45,7 @@ struct window {
uint32_t width, height;
char *font;
cairo_t *cairo;
+ struct pointer_input pointer_input;
};
struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface);
diff --git a/wayland/window.c b/wayland/window.c
@@ -30,10 +30,20 @@ static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) {
+ struct window *window = data;
+
+ window->pointer_input.last_x = sx_w;
+ window->pointer_input.last_y = sy_w;
}
static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
uint32_t time, uint32_t button, uint32_t state_w) {
+ struct window *window = data;
+ struct pointer_input *input = &window->pointer_input;
+
+ if (window->pointer_input.notify) {
+ window->pointer_input.notify(window, input->last_x, input->last_y, button);
+ }
}
static void pointer_handle_axis(void *data, struct wl_pointer *pointer,