From 0b8e6cccc8dccc1f8166da41a5f985158d303ac2 Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 22 Jun 2017 15:41:59 +0200 Subject: [PATCH 1/7] Add wayland input listener skeletons --- backend/wayland/wl_seat.c | 102 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 3 deletions(-) diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 5e6583ba..b4a1b862 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -11,12 +11,109 @@ #include #include "backend/wayland.h" -static void wlr_wl_device_destroy(struct wlr_input_device_state *state) { +static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, + wl_fixed_t surface_y) { + +} + +static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, struct wl_surface *surface) { + +} + +static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, + uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { + +} + +static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { + +} + +static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, + uint32_t time, uint32_t axis, wl_fixed_t value) { + +} + +static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { + +} + +static void pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer, + uint32_t axis_source) { + +} + +static void pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer, + uint32_t time, uint32_t axis) { + +} + +static void pointer_handle_axis_discrete(void *data, struct wl_pointer *wl_pointer, + uint32_t axis, int32_t discrete) { + +} + +static const struct wl_pointer_listener pointer_listener = { + .enter = pointer_handle_enter, + .leave = pointer_handle_leave, + .motion = pointer_handle_motion, + .button = pointer_handle_button, + .axis = pointer_handle_axis, + .frame = pointer_handle_frame, + .axis_source = pointer_handle_axis_source, + .axis_stop = pointer_handle_axis_stop, + .axis_discrete = pointer_handle_axis_discrete +}; + +static void keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard, + uint32_t format, int32_t fd, uint32_t size) { + +} + +static void keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard, + uint32_t serial, struct wl_surface *surface, struct wl_array *keys) { + +} + +static void keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard, + uint32_t serial, struct wl_surface *surface) { + +} + +static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, + uint32_t serial, uint32_t time, uint32_t key, uint32_t state) { + +} + +static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard, + uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, + uint32_t mods_locked, uint32_t group) { + +} + +static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard, + int32_t rate, int32_t delay) { + +} + +static struct wl_keyboard_listener keyboard_listener = { + .keymap = keyboard_handle_keymap, + .enter = keyboard_handle_enter, + .leave = keyboard_handle_leave, + .key = keyboard_handle_key, + .modifiers = keyboard_handle_modifiers, + .repeat_info = keyboard_handle_repeat_info +}; + +static void input_device_destroy(struct wlr_input_device_state *state) { free(state); } static struct wlr_input_device_impl input_device_impl = { - .destroy = wlr_wl_device_destroy + .destroy = input_device_destroy }; static struct wlr_input_device *allocate_device(struct wlr_backend_state *state, @@ -49,7 +146,6 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, struct wlr_backend_state *state = data; assert(state->seat == wl_seat); - // TODO: add listeners and receive input if ((caps & WL_SEAT_CAPABILITY_POINTER)) { wlr_log(L_DEBUG, "seat %p offered pointer", wl_seat); struct wl_pointer *wl_pointer = wl_seat_get_pointer(wl_seat); From c1520077b6dab32dee359bdfe03dddc5e391f9a5 Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 22 Jun 2017 16:53:48 +0200 Subject: [PATCH 2/7] Implement wayland backend input events --- backend/wayland/backend.c | 11 ++--- backend/wayland/wl_seat.c | 100 +++++++++++++++++++++++++++++--------- include/backend/wayland.h | 5 ++ 3 files changed, 87 insertions(+), 29 deletions(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index a58c8691..a6029500 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -63,7 +63,7 @@ static bool wlr_wl_backend_init(struct wlr_backend_state* state) { state->remote_display_src = wl_event_loop_add_fd(loop, fd, events, dispatch_events, state); wl_event_source_check(state->remote_display_src); - + return true; } @@ -76,14 +76,14 @@ static void wlr_wl_backend_destroy(struct wlr_backend_state *state) { wlr_output_destroy(state->outputs->items[i]); } - for (size_t i = 0; state->devices && i < state->devices->length; ++i) { + for (size_t i = 0; i < state->devices->length; ++i) { wlr_input_device_destroy(state->devices->items[i]); } list_free(state->devices); + list_free(state->outputs); wlr_egl_free(&state->egl); - free(state->outputs); if (state->seat) wl_seat_destroy(state->seat); if (state->shm) wl_shm_destroy(state->shm); if (state->shell) wl_shell_destroy(state->shell); @@ -133,9 +133,8 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { error: if (state) { - free(state->outputs); - free(state->devices); - free(state->devices); + list_free(state->devices); + list_free(state->outputs); } free(state); free(backend); diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index b4a1b862..2538d4b2 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -8,13 +8,18 @@ #include #include #include +#include #include #include "backend/wayland.h" static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) { - + struct wlr_input_device *dev = data; + assert(dev && dev->pointer && dev->pointer->state); + struct wlr_pointer_state *state = dev->pointer->state; + state->surface_x = wl_fixed_to_double(surface_x); + state->surface_y = wl_fixed_to_double(surface_y); } static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, @@ -24,17 +29,46 @@ static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { + struct wlr_input_device *dev = data; + assert(dev && dev->pointer && dev->pointer->state); + struct wlr_pointer_state *state = dev->pointer->state; + struct wlr_event_pointer_motion wlr_event; + wlr_event.time_sec = time / 1000; + wlr_event.time_usec = time * 1000; + wlr_event.delta_x = wl_fixed_to_double(surface_x) - state->surface_x; + wlr_event.delta_y = wl_fixed_to_double(surface_y) - state->surface_y; + wl_signal_emit(&dev->pointer->events.motion, &wlr_event); + + state->surface_x = surface_x; + state->surface_y = surface_y; } static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { + struct wlr_input_device *dev = data; + assert(dev && dev->pointer); + struct wlr_event_pointer_button wlr_event; + wlr_event.button = button; + wlr_event.state = state; + wlr_event.time_sec = time / 1000; + wlr_event.time_usec = time * 1000; + wl_signal_emit(&dev->pointer->events.button, &wlr_event); } static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value) { + struct wlr_input_device *dev = data; + assert(dev && dev->pointer); + struct wlr_event_pointer_axis wlr_event; + wlr_event.delta = value; + wlr_event.orientation = axis; + wlr_event.time_sec = time / 1000; + wlr_event.time_usec = time * 1000; + wlr_event.source = WLR_AXIS_SOURCE_CONTINUOUS; // TODO + wl_signal_emit(&dev->pointer->events.axis, &wlr_event); } static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { @@ -85,7 +119,15 @@ static void keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard, static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) { + struct wlr_input_device *dev = data; + assert(dev && dev->keyboard); + struct wlr_event_keyboard_key wlr_event; + wlr_event.keycode = key; + wlr_event.state = state; + wlr_event.time_sec = time / 1000; + wlr_event.time_usec = time * 1000; + wl_signal_emit(&dev->keyboard->events.key, &wlr_event); } static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard, @@ -109,6 +151,8 @@ static struct wl_keyboard_listener keyboard_listener = { }; static void input_device_destroy(struct wlr_input_device_state *state) { + if (state->resource) + wl_proxy_destroy(state->resource); free(state); } @@ -116,11 +160,18 @@ static struct wlr_input_device_impl input_device_impl = { .destroy = input_device_destroy }; +static void pointer_destroy(struct wlr_pointer_state *state) { + free(state); +} + +static struct wlr_pointer_impl pointer_impl = { + .destroy = pointer_destroy +}; + static struct wlr_input_device *allocate_device(struct wlr_backend_state *state, enum wlr_input_device_type type) { - struct wlr_input_device_state *devstate = - calloc(1, sizeof(struct wlr_input_device_state)); - if(!devstate) { + struct wlr_input_device_state *devstate; + if (!(devstate = calloc(1, sizeof(struct wlr_input_device_state)))) { wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); return NULL; } @@ -128,11 +179,11 @@ static struct wlr_input_device *allocate_device(struct wlr_backend_state *state, // TODO: any way to retrieve those information? int vendor = 0; int product = 0; - const char *name = "unknown;wayland"; + const char *name = "wayland"; struct wlr_input_device *wlr_device = wlr_input_device_create( type, &input_device_impl, devstate, name, vendor, product); - if(!wlr_device) { + if (!wlr_device) { free(devstate); return NULL; } @@ -147,38 +198,41 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, assert(state->seat == wl_seat); if ((caps & WL_SEAT_CAPABILITY_POINTER)) { - wlr_log(L_DEBUG, "seat %p offered pointer", wl_seat); - struct wl_pointer *wl_pointer = wl_seat_get_pointer(wl_seat); - - struct wlr_input_device *wlr_device = allocate_device(state, - WLR_INPUT_DEVICE_POINTER); - if(!wlr_device) { - wl_pointer_destroy(wl_pointer); - wlr_log(L_ERROR, "Unable to allocate wl_pointer device"); + wlr_log(L_DEBUG, "seat %p offered pointer", (void*) wl_seat); + struct wlr_pointer_state *pointer_state; + if (!(pointer_state = calloc(1, sizeof(struct wlr_pointer_state)))) { + wlr_log(L_ERROR, "Unable to allocate wlr_pointer_state"); return; } - wlr_device->pointer = wlr_pointer_create(NULL, NULL); - list_add(state->devices, wlr_device); + struct wlr_input_device *wlr_device; + if (!(wlr_device = allocate_device(state, WLR_INPUT_DEVICE_POINTER))) { + free(pointer_state); + wlr_log(L_ERROR, "Unable to allocate wlr_device for pointer"); + return; + } + + struct wl_pointer *wl_pointer = wl_seat_get_pointer(wl_seat); + wl_pointer_add_listener(wl_pointer, &pointer_listener, wlr_device); + wlr_device->pointer = wlr_pointer_create(&pointer_impl, pointer_state); + wlr_device->state->resource = wl_pointer; wl_signal_emit(&state->backend->events.input_add, wlr_device); } if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) { - wlr_log(L_DEBUG, "seat %p offered keyboard", wl_seat); - struct wl_keyboard *wl_keyboard = wl_seat_get_keyboard(wl_seat); + wlr_log(L_DEBUG, "seat %p offered keyboard", (void*) wl_seat); struct wlr_input_device *wlr_device = allocate_device(state, WLR_INPUT_DEVICE_KEYBOARD); - if(!wlr_device) { - wl_keyboard_release(wl_keyboard); + if (!wlr_device) { wlr_log(L_ERROR, "Unable to allocate wl_pointer device"); return; } + struct wl_keyboard *wl_keyboard = wl_seat_get_keyboard(wl_seat); + wl_keyboard_add_listener(wl_keyboard, &keyboard_listener, wlr_device); wlr_device->keyboard = wlr_keyboard_create(NULL, NULL); - list_add(state->devices, wlr_device); + wlr_device->state->resource = wl_keyboard; wl_signal_emit(&state->backend->events.input_add, wlr_device); } - - // TODO: touch } static void seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) { diff --git a/include/backend/wayland.h b/include/backend/wayland.h index bf65ec50..8138101c 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -43,6 +43,11 @@ struct wlr_input_device_state { void *resource; }; +struct wlr_pointer_state { + double surface_x; + double surface_y; +}; + void wlr_wl_registry_poll(struct wlr_backend_state *backend); extern const struct wl_seat_listener seat_listener; From d26a9ba968472cb5c78d9ea0aea3d8f5ff02fbf5 Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 22 Jun 2017 17:12:09 +0200 Subject: [PATCH 3/7] Fix pointer motion coords --- backend/wayland/wl_seat.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 2538d4b2..f4d3cd52 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -33,15 +33,21 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, assert(dev && dev->pointer && dev->pointer->state); struct wlr_pointer_state *state = dev->pointer->state; + double x = wl_fixed_to_double(surface_x); + double y = wl_fixed_to_double(surface_y); + + if (x == state->surface_x && y == state->surface_y) + return; + struct wlr_event_pointer_motion wlr_event; wlr_event.time_sec = time / 1000; wlr_event.time_usec = time * 1000; - wlr_event.delta_x = wl_fixed_to_double(surface_x) - state->surface_x; - wlr_event.delta_y = wl_fixed_to_double(surface_y) - state->surface_y; + wlr_event.delta_x = x - state->surface_x; + wlr_event.delta_y = y - state->surface_y; wl_signal_emit(&dev->pointer->events.motion, &wlr_event); - state->surface_x = surface_x; - state->surface_y = surface_y; + state->surface_x = x; + state->surface_y = y; } static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, From 272030652a73fd54472726e3ccd693402868fd35 Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 22 Jun 2017 17:54:51 +0200 Subject: [PATCH 4/7] Implement absolute motion events for wayland --- backend/wayland/backend.c | 13 ++++++++++++- backend/wayland/wl_seat.c | 39 ++++++++++++++++++++++----------------- include/backend/wayland.h | 7 ++++--- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index a6029500..ef480c18 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -63,7 +63,7 @@ static bool wlr_wl_backend_init(struct wlr_backend_state* state) { state->remote_display_src = wl_event_loop_add_fd(loop, fd, events, dispatch_events, state); wl_event_source_check(state->remote_display_src); - + return true; } @@ -102,6 +102,17 @@ bool wlr_backend_is_wl(struct wlr_backend *b) { return b->impl == &backend_impl; } +struct wlr_output *wlr_wl_output_for_surface(struct wlr_backend_state *backend, + struct wl_surface *surface) { + for (size_t i = 0; i < backend->outputs->length; ++i) { + struct wlr_output *output = backend->outputs->items[i]; + if(output->state->surface == surface) + return output; + } + + return NULL; +} + struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { wlr_log(L_INFO, "Creating wayland backend"); diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index f4d3cd52..6d3b8b05 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -17,9 +17,15 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, wl_fixed_t surface_y) { struct wlr_input_device *dev = data; assert(dev && dev->pointer && dev->pointer->state); - struct wlr_pointer_state *state = dev->pointer->state; - state->surface_x = wl_fixed_to_double(surface_x); - state->surface_y = wl_fixed_to_double(surface_y); + struct wlr_output* output = wlr_wl_output_for_surface(dev->state->backend, + surface); + + if (!output) { + wlr_log(L_ERROR, "pointer entered invalid surface"); + return; + } + + dev->pointer->state->current_output = output; } static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, @@ -32,22 +38,20 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, struct wlr_input_device *dev = data; assert(dev && dev->pointer && dev->pointer->state); struct wlr_pointer_state *state = dev->pointer->state; + assert(state->current_output); - double x = wl_fixed_to_double(surface_x); - double y = wl_fixed_to_double(surface_y); + int width, height; + wl_egl_window_get_attached_size(state->current_output->state->egl_window, + &width, &height); - if (x == state->surface_x && y == state->surface_y) - return; - - struct wlr_event_pointer_motion wlr_event; + struct wlr_event_pointer_motion_absolute wlr_event; wlr_event.time_sec = time / 1000; wlr_event.time_usec = time * 1000; - wlr_event.delta_x = x - state->surface_x; - wlr_event.delta_y = y - state->surface_y; - wl_signal_emit(&dev->pointer->events.motion, &wlr_event); - - state->surface_x = x; - state->surface_y = y; + wlr_event.width_mm = width; + wlr_event.height_mm = height; + wlr_event.x_mm = wl_fixed_to_double(surface_x); + wlr_event.y_mm = wl_fixed_to_double(surface_y); + wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event); } static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, @@ -73,7 +77,7 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, wlr_event.orientation = axis; wlr_event.time_sec = time / 1000; wlr_event.time_usec = time * 1000; - wlr_event.source = WLR_AXIS_SOURCE_CONTINUOUS; // TODO + wlr_event.source = WLR_AXIS_SOURCE_CONTINUOUS; wl_signal_emit(&dev->pointer->events.axis, &wlr_event); } @@ -182,7 +186,8 @@ static struct wlr_input_device *allocate_device(struct wlr_backend_state *state, return NULL; } - // TODO: any way to retrieve those information? + devstate->backend = state; + int vendor = 0; int product = 0; const char *name = "wayland"; diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 8138101c..df817598 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -39,16 +39,17 @@ struct wlr_output_state { }; struct wlr_input_device_state { - enum wlr_input_device_type type; + struct wlr_backend_state* backend; void *resource; }; struct wlr_pointer_state { - double surface_x; - double surface_y; + struct wlr_output *current_output; }; void wlr_wl_registry_poll(struct wlr_backend_state *backend); +struct wlr_output *wlr_wl_output_for_surface(struct wlr_backend_state *backend, + struct wl_surface *surface); extern const struct wl_seat_listener seat_listener; From dbde1f734075d47cdada320f056a4e3f7f528755 Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 22 Jun 2017 17:58:53 +0200 Subject: [PATCH 5/7] Store wayland backend axis source --- backend/wayland/wl_seat.c | 6 ++++-- include/backend/wayland.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 6d3b8b05..aedc4a00 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -77,7 +77,7 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, wlr_event.orientation = axis; wlr_event.time_sec = time / 1000; wlr_event.time_usec = time * 1000; - wlr_event.source = WLR_AXIS_SOURCE_CONTINUOUS; + wlr_event.source = dev->pointer->state->axis_source; wl_signal_emit(&dev->pointer->events.axis, &wlr_event); } @@ -87,7 +87,9 @@ static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { static void pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source) { - + struct wlr_input_device *dev = data; + assert(dev && dev->pointer && dev->pointer->state); + dev->pointer->state->axis_source = axis_source; } static void pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer, diff --git a/include/backend/wayland.h b/include/backend/wayland.h index df817598..792bad37 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -44,6 +44,7 @@ struct wlr_input_device_state { }; struct wlr_pointer_state { + enum wlr_axis_source axis_source; struct wlr_output *current_output; }; From 4ca872c91477f272d829b7fe5488eee36472448a Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 22 Jun 2017 18:04:13 +0200 Subject: [PATCH 6/7] Improve wayland backend pointer error logging --- backend/wayland/wl_seat.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index aedc4a00..ab3de74d 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -30,7 +30,9 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface) { - + struct wlr_input_device *dev = data; + assert(dev && dev->pointer && dev->pointer->state); + dev->pointer->state->current_output = NULL; } static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, @@ -38,7 +40,11 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, struct wlr_input_device *dev = data; assert(dev && dev->pointer && dev->pointer->state); struct wlr_pointer_state *state = dev->pointer->state; - assert(state->current_output); + + if(!state->current_output) { + wlr_log(L_ERROR, "pointer motion event without current output"); + return; + } int width, height; wl_egl_window_get_attached_size(state->current_output->state->egl_window, From a9547af35833ba06b7446bcba800d7d6a764508c Mon Sep 17 00:00:00 2001 From: nyorain Date: Thu, 22 Jun 2017 18:21:28 +0200 Subject: [PATCH 7/7] Fix pointer example for wayland backend --- example/pointer.c | 8 ++++++++ example/shared.c | 13 ++++++++++++- example/shared.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/example/pointer.c b/example/pointer.c index 9a2f33d7..035af240 100644 --- a/example/pointer.c +++ b/example/pointer.c @@ -54,6 +54,13 @@ static void handle_pointer_motion(struct pointer_state *pstate, state->cur_y += d_y; } +static void handle_pointer_motion_absolute(struct pointer_state *pstate, + double x, double y) { + struct sample_state *state = pstate->compositor->data; + state->cur_x = x; + state->cur_y = y; +} + static void handle_pointer_button(struct pointer_state *pstate, uint32_t button, enum wlr_button_state state) { struct sample_state *sample = pstate->compositor->data; @@ -109,6 +116,7 @@ int main(int argc, char *argv[]) { compositor.output_add_cb = handle_output_add; compositor.output_frame_cb = handle_output_frame; compositor.pointer_motion_cb = handle_pointer_motion; + compositor.pointer_motion_absolute_cb = handle_pointer_motion_absolute; compositor.pointer_button_cb = handle_pointer_button; compositor.pointer_axis_cb = handle_pointer_axis; compositor_init(&compositor); diff --git a/example/shared.c b/example/shared.c index c4ec4ffe..fbb6c559 100644 --- a/example/shared.c +++ b/example/shared.c @@ -105,6 +105,15 @@ static void pointer_motion_notify(struct wl_listener *listener, void *data) { } } +static void pointer_motion_absolute_notify(struct wl_listener *listener, void *data) { + struct wlr_event_pointer_motion_absolute *event = data; + struct pointer_state *pstate = wl_container_of(listener, pstate, motion_absolute); + if (pstate->compositor->pointer_motion_absolute_cb) { + pstate->compositor->pointer_motion_absolute_cb(pstate, + event->x_mm, event->y_mm); + } +} + static void pointer_button_notify(struct wl_listener *listener, void *data) { struct wlr_event_pointer_button *event = data; struct pointer_state *pstate = wl_container_of(listener, pstate, button); @@ -132,9 +141,11 @@ static void pointer_add(struct wlr_input_device *device, struct compositor_state wl_list_init(&pstate->button.link); wl_list_init(&pstate->axis.link); pstate->motion.notify = pointer_motion_notify; + pstate->motion_absolute.notify = pointer_motion_absolute_notify; pstate->button.notify = pointer_button_notify; pstate->axis.notify = pointer_axis_notify; wl_signal_add(&device->pointer->events.motion, &pstate->motion); + wl_signal_add(&device->pointer->events.motion_absolute, &pstate->motion_absolute); wl_signal_add(&device->pointer->events.button, &pstate->button); wl_signal_add(&device->pointer->events.axis, &pstate->axis); wl_list_insert(&state->pointers, &pstate->link); @@ -308,7 +319,7 @@ static void pointer_remove(struct wlr_input_device *device, struct compositor_st } wl_list_remove(&pstate->link); wl_list_remove(&pstate->motion.link); - //wl_list_remove(&pstate->motion_absolute.link); + wl_list_remove(&pstate->motion_absolute.link); wl_list_remove(&pstate->button.link); wl_list_remove(&pstate->axis.link); } diff --git a/example/shared.h b/example/shared.h index c95df9cc..37f52dcc 100644 --- a/example/shared.h +++ b/example/shared.h @@ -83,6 +83,8 @@ struct compositor_state { enum wlr_key_state key_state); void (*pointer_motion_cb)(struct pointer_state *s, double d_x, double d_y); + void (*pointer_motion_absolute_cb)(struct pointer_state *s, + double x, double y); void (*pointer_button_cb)(struct pointer_state *s, uint32_t button, enum wlr_button_state state); void (*pointer_axis_cb)(struct pointer_state *s,