From 3a3d1b661714a7d37b8a4450fe0c3dec50027622 Mon Sep 17 00:00:00 2001 From: random human Date: Fri, 28 Sep 2018 04:43:52 +0530 Subject: [PATCH 01/19] relative_pointer: create skeleton and build Add protocol, header and type files to build. Create skeleton structs, creator and destroyer, and define implementations. --- include/rootston/desktop.h | 2 + include/wlr/types/wlr_relative_pointer_v1.h | 45 +++++++ protocol/meson.build | 2 + rootston/desktop.c | 2 + types/meson.build | 1 + types/wlr_relative_pointer_v1.c | 126 ++++++++++++++++++++ 6 files changed, 178 insertions(+) create mode 100644 include/wlr/types/wlr_relative_pointer_v1.h create mode 100644 types/wlr_relative_pointer_v1.c diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index b1fcaca0..56d2a129 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,7 @@ struct roots_desktop { struct wlr_pointer_constraints_v1 *pointer_constraints; struct wlr_presentation *presentation; struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager_v1; + struct wlr_relative_pointer_manager_v1 *relative_pointer_manager; struct wl_listener new_output; struct wl_listener layout_change; diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h new file mode 100644 index 00000000..815dcaca --- /dev/null +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -0,0 +1,45 @@ +/* + * This an unstable interface of wlroots. No guarantees are made regarding the + * future consistency of this API. + */ +#ifndef WLR_USE_UNSTABLE +#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" +#endif + +#ifndef WLR_TYPES_WLR_RELATIVE_POINTER_V1_H +#define WLR_TYPES_WLR_RELATIVE_POINTER_V1_H + +#include + + +/* This protocol specifies a set of interfaces used for making clients able to + * receive relative pointer events not obstructed by barriers (such as the + * monitor edge or other pointer barriers). + */ + +struct wlr_relative_pointer_manager_v1 { + struct wl_list resources; + struct wl_global *global; + + struct { + struct wl_signal destroy; + struct wl_signal get_relative_pointer; + } requests; + + void *data; +}; + +struct wlr_relative_pointer_v1 { + struct wl_resource *resource; + + struct { + struct wl_signal destroy; + } destroy; + + void *data; +}; + +struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display); +void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager); + +#endif diff --git a/protocol/meson.build b/protocol/meson.build index 58f57046..6d5acf37 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -20,6 +20,7 @@ protocols = [ [wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'], [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], [wl_protocol_dir, 'unstable/pointer-constraints/pointer-constraints-unstable-v1.xml'], + [wl_protocol_dir, 'unstable/relative-pointer/relative-pointer-unstable-v1.xml'], 'gamma-control.xml', 'gtk-primary-selection.xml', 'idle.xml', @@ -42,6 +43,7 @@ client_protocols = [ [wl_protocol_dir, 'unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'], [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], [wl_protocol_dir, 'unstable/pointer-constraints/pointer-constraints-unstable-v1.xml'], + [wl_protocol_dir, 'unstable/relative-pointer/relative-pointer-unstable-v1.xml'], 'idle.xml', 'input-method-unstable-v2.xml', 'screenshooter.xml', diff --git a/rootston/desktop.c b/rootston/desktop.c index 48e2635c..e4affe3b 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -1081,6 +1081,8 @@ struct roots_desktop *desktop_create(struct roots_server *server, wlr_presentation_create(server->wl_display, server->backend); desktop->foreign_toplevel_manager_v1 = wlr_foreign_toplevel_manager_v1_create(server->wl_display); + desktop->relative_pointer_manager = + wlr_relative_pointer_v1_create(server->wl_display); return desktop; } diff --git a/types/meson.build b/types/meson.build index 1813b144..982f607d 100644 --- a/types/meson.build +++ b/types/meson.build @@ -51,6 +51,7 @@ lib_wlr_types = static_library( 'wlr_primary_selection.c', 'wlr_region.c', 'wlr_screencopy_v1.c', + 'wlr_relative_pointer_v1.c', 'wlr_screenshooter.c', 'wlr_server_decoration.c', 'wlr_surface.c', diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c new file mode 100644 index 00000000..54bd41a7 --- /dev/null +++ b/types/wlr_relative_pointer_v1.c @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include "wayland-util.h" +#include "wayland-server.h" +#include "relative-pointer-unstable-v1-protocol.h" + +static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager_v1_impl; +static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl; + + +/* Callback functions + */ + +static void relative_pointer_manager_v1_handle_destroy(struct wl_client *client, + struct wl_resource *resource) +{ + wlr_log(WLR_DEBUG, "relative_pointer_manager_v1_handle_destroy called"); +} + + +static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_client *client, + struct wl_resource *resource, uint32_t id, struct wl_resource *pointer) +{ + wlr_log(WLR_DEBUG, "relative_pointer_manager_v1_handle_get_relative_pointer called"); +} + + +static void relative_pointer_v1_handle_destroy(struct wl_client *client, + struct wl_resource *resource) +{ + wlr_log(WLR_DEBUG, "relative_pointer_v1_handle_destroy called"); +} + + +static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resource *resource) +{ + wl_list_remove(wl_resource_get_link(resource)); + wlr_log(WLR_DEBUG, "relative_pointer_manager_v1_handle_resource_destroy called"); +} + + +static void relative_pointer_manager_bind(struct wl_client *wl_client, void *data, + uint32_t version, uint32_t id) +{ + struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = data; + + struct wl_resource *wl_resource = wl_resource_create(wl_client, + &zwp_relative_pointer_manager_v1_interface, version, id); + + if (wl_resource == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + + wl_list_insert(&relative_pointer_manager->resources, wl_resource_get_link(wl_resource)); + + wl_resource_set_implementation(wl_resource, &relative_pointer_manager_v1_impl, + relative_pointer_manager, relative_pointer_manager_v1_handle_resource_destroy); + + wlr_log(WLR_DEBUG, "relative_pointer_manager bound"); +} + + +/* Implementations + */ + +static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager_v1_impl = { + .destroy = relative_pointer_manager_v1_handle_destroy, + .get_relative_pointer = relative_pointer_manager_v1_handle_get_relative_pointer, +}; + + +static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl = { + .destroy = relative_pointer_v1_handle_destroy, +}; + + +/* Public functions + */ + +struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display) +{ + struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = + calloc(1, sizeof(struct wlr_relative_pointer_manager_v1)); + + if (relative_pointer_manager == NULL) { + return NULL; + } + + wl_list_init(&relative_pointer_manager->resources); + + wl_signal_init(&relative_pointer_manager->requests.destroy); + wl_signal_init(&relative_pointer_manager->requests.get_relative_pointer); + + relative_pointer_manager->global = wl_global_create(display, + &zwp_relative_pointer_manager_v1_interface, 1, + relative_pointer_manager, relative_pointer_manager_bind); + + if (relative_pointer_manager->global == NULL) { + free(relative_pointer_manager); + return NULL; + } + + wlr_log(WLR_DEBUG, "relative_pointer_v1 manager created"); + + return relative_pointer_manager; +} + + +void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager) +{ + if (relative_pointer_manager == NULL) { + return; + } + + struct wl_resource *resource; + struct wl_resource *tmp_resource; + wl_resource_for_each_safe(resource, tmp_resource, &relative_pointer_manager->resources) { + wl_resource_destroy(resource); + } + + wl_global_destroy(relative_pointer_manager->global); + free(relative_pointer_manager); +} From ba5b1676dfb0041c88e4966a6c32dee5a5a6513a Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 1 Oct 2018 03:54:21 +0530 Subject: [PATCH 02/19] relative_pointer: implement protocol requests Flesh out the details of the structs, signals, callback functions, and so on. weston-resizer silently works at this point (no events sent). --- include/wlr/types/wlr_relative_pointer_v1.h | 30 ++++++- include/wlr/types/wlr_seat.h | 1 + types/seat/wlr_seat.c | 4 + types/wlr_relative_pointer_v1.c | 99 +++++++++++++++++---- 4 files changed, 113 insertions(+), 21 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index 815dcaca..94ae053b 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -17,24 +17,48 @@ * monitor edge or other pointer barriers). */ + +/* A global interface used for getting the relative pointer object for a given + * pointer. + * + * Signals: + * - destroy -> struct wlr_relative_pointer_manager_v1 *manager + * :: the manager was destroyed + * - new_relative_pointer -> struct wlr_relative_pointer_v1 *relative_pointer + * :: a new relative_pointer was created + */ + struct wlr_relative_pointer_manager_v1 { struct wl_list resources; struct wl_global *global; struct { struct wl_signal destroy; - struct wl_signal get_relative_pointer; - } requests; + struct wl_signal new_relative_pointer; + } events; void *data; }; + +/* A wp_relative_pointer object is an extension to the wl_pointer interface + * used for emitting relative pointer events. It shares the same focus as + * wl_pointer objects of the same seat and will only emit events when it has + * focus. + * + * Signals: + * - destroy -> struct wlr_relative_pointer_v1 *relative_pointer + * :: the relative_pointer was destroyed + */ + struct wlr_relative_pointer_v1 { + struct wl_client *client; struct wl_resource *resource; + struct wl_pointer *pointer; struct { struct wl_signal destroy; - } destroy; + } events; void *data; }; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 942a3420..9fc1ba95 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -27,6 +27,7 @@ struct wlr_seat_client { // lists of wl_resource struct wl_list resources; struct wl_list pointers; + struct wl_list relative_pointers; struct wl_list keyboards; struct wl_list touches; struct wl_list data_devices; diff --git a/types/seat/wlr_seat.c b/types/seat/wlr_seat.c index 8b1d67fd..698a906a 100644 --- a/types/seat/wlr_seat.c +++ b/types/seat/wlr_seat.c @@ -79,6 +79,9 @@ static void seat_client_handle_resource_destroy( wl_resource_for_each_safe(resource, tmp, &client->pointers) { wl_resource_destroy(resource); } + wl_resource_for_each_safe(resource, tmp, &client->relative_pointers) { + wl_resource_destroy(resource); + } wl_resource_for_each_safe(resource, tmp, &client->keyboards) { wl_resource_destroy(resource); } @@ -131,6 +134,7 @@ static void seat_handle_bind(struct wl_client *client, void *_wlr_seat, seat_client->seat = wlr_seat; wl_list_init(&seat_client->resources); wl_list_init(&seat_client->pointers); + wl_list_init(&seat_client->relative_pointers); wl_list_init(&seat_client->keyboards); wl_list_init(&seat_client->touches); wl_list_init(&seat_client->data_devices); diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index 54bd41a7..b32bbc79 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -1,7 +1,10 @@ #include +#include +#include #include #include #include +#include #include "wayland-util.h" #include "wayland-server.h" #include "relative-pointer-unstable-v1-protocol.h" @@ -13,53 +16,109 @@ static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl; /* Callback functions */ +static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resource *resource) +{ + wl_list_remove(wl_resource_get_link(resource)); +} + + +static void relative_pointer_v1_handle_resource_destroy(struct wl_resource *resource) +{ + wl_list_remove(wl_resource_get_link(resource)); + + struct wlr_relative_pointer_v1 *relative_pointer = wl_resource_get_user_data(resource); + free(relative_pointer); +} + + static void relative_pointer_manager_v1_handle_destroy(struct wl_client *client, struct wl_resource *resource) { - wlr_log(WLR_DEBUG, "relative_pointer_manager_v1_handle_destroy called"); + wl_resource_destroy(resource); + + wlr_log(WLR_DEBUG, "relative_pointer_v1 manager unbound from client 0x%" PRIXPTR, + (uintptr_t) client); } static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *pointer) { - wlr_log(WLR_DEBUG, "relative_pointer_manager_v1_handle_get_relative_pointer called"); + struct wlr_seat_client *seat_client = + wlr_seat_client_from_pointer_resource(pointer); + assert(seat_client->client == client); + + struct wlr_relative_pointer_v1 *relative_pointer = + calloc(1, sizeof(struct wlr_relative_pointer_v1)); + if (relative_pointer == NULL) { + wl_client_post_no_memory(client); + return; + } + + struct wl_resource *relative_pointer_resource = wl_resource_create(client, + &zwp_relative_pointer_v1_interface, wl_resource_get_version(resource), id); + if (relative_pointer_resource == NULL) { + free(relative_pointer); + wl_client_post_no_memory(client); + return; + } + + relative_pointer->client = client; + relative_pointer->resource = relative_pointer_resource; + relative_pointer->pointer = (struct wl_pointer *) pointer; + + wl_signal_init(&relative_pointer->events.destroy); + + wl_list_insert(&seat_client->relative_pointers, + wl_resource_get_link(relative_pointer_resource)); + + wl_resource_set_implementation(relative_pointer_resource, &relative_pointer_v1_impl, + relative_pointer, relative_pointer_v1_handle_resource_destroy); + + struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = + wl_resource_get_user_data(resource); + wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer, + relative_pointer); + + wlr_log(WLR_DEBUG, + "relative_pointer_v1 0x%" PRIXPTR " created for client 0x%" PRIXPTR, + (uintptr_t) relative_pointer, (uintptr_t) client); } static void relative_pointer_v1_handle_destroy(struct wl_client *client, struct wl_resource *resource) { - wlr_log(WLR_DEBUG, "relative_pointer_v1_handle_destroy called"); -} + struct wlr_relative_pointer_v1 *relative_pointer = + wl_resource_get_user_data(resource); + wlr_log(WLR_DEBUG, + "relative_pointer_v1 0x%" PRIXPTR " released by client 0x%" PRIXPTR, + (uintptr_t) relative_pointer, (uintptr_t) client); - -static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resource *resource) -{ - wl_list_remove(wl_resource_get_link(resource)); - wlr_log(WLR_DEBUG, "relative_pointer_manager_v1_handle_resource_destroy called"); + wl_resource_destroy(resource); } -static void relative_pointer_manager_bind(struct wl_client *wl_client, void *data, +static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = data; - struct wl_resource *wl_resource = wl_resource_create(wl_client, + struct wl_resource *manager_resource = wl_resource_create(wl_client, &zwp_relative_pointer_manager_v1_interface, version, id); - if (wl_resource == NULL) { + if (manager_resource == NULL) { wl_client_post_no_memory(wl_client); return; } - wl_list_insert(&relative_pointer_manager->resources, wl_resource_get_link(wl_resource)); + wl_list_insert(&relative_pointer_manager->resources, wl_resource_get_link(manager_resource)); - wl_resource_set_implementation(wl_resource, &relative_pointer_manager_v1_impl, + wl_resource_set_implementation(manager_resource, &relative_pointer_manager_v1_impl, relative_pointer_manager, relative_pointer_manager_v1_handle_resource_destroy); - wlr_log(WLR_DEBUG, "relative_pointer_manager bound"); + wlr_log(WLR_DEBUG, "relative_pointer_v1 manager bound to client 0x%" PRIXPTR, + (uintptr_t) wl_client); } @@ -91,12 +150,12 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl wl_list_init(&relative_pointer_manager->resources); - wl_signal_init(&relative_pointer_manager->requests.destroy); - wl_signal_init(&relative_pointer_manager->requests.get_relative_pointer); + wl_signal_init(&relative_pointer_manager->events.destroy); + wl_signal_init(&relative_pointer_manager->events.new_relative_pointer); relative_pointer_manager->global = wl_global_create(display, &zwp_relative_pointer_manager_v1_interface, 1, - relative_pointer_manager, relative_pointer_manager_bind); + relative_pointer_manager, relative_pointer_manager_v1_bind); if (relative_pointer_manager->global == NULL) { free(relative_pointer_manager); @@ -115,6 +174,8 @@ void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *rel return; } + wlr_signal_emit_safe(&relative_pointer_manager->events.destroy, relative_pointer_manager); + struct wl_resource *resource; struct wl_resource *tmp_resource; wl_resource_for_each_safe(resource, tmp_resource, &relative_pointer_manager->resources) { @@ -123,4 +184,6 @@ void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *rel wl_global_destroy(relative_pointer_manager->global); free(relative_pointer_manager); + + wlr_log(WLR_DEBUG, "relative_pointer_v1 manager destroyed"); } From d0203446751f2b8b4e80ecf54b6ff831096c3302 Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 1 Oct 2018 06:21:32 +0530 Subject: [PATCH 03/19] relative_pointer: implement protocol events Implement zwp_relative_pointer_v1.relative_motion event, along with some glue code in wlr_seat_pointer and rootston. --- include/wlr/types/wlr_relative_pointer_v1.h | 4 ++++ include/wlr/types/wlr_seat.h | 12 ++++++++++++ rootston/cursor.c | 8 ++++++++ types/seat/wlr_seat_pointer.c | 15 +++++++++++++++ types/wlr_relative_pointer_v1.c | 13 +++++++++++++ 5 files changed, 52 insertions(+) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index 94ae053b..c74766b9 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -66,4 +66,8 @@ struct wlr_relative_pointer_v1 { struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display); void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager); +void wlr_relative_pointer_v1_send_relative_motion(struct wl_resource *resource, + uint64_t time, double dx, double dy, double dx_unaccel, double + dy_unaccel); + #endif diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 9fc1ba95..54e04e24 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -314,6 +314,18 @@ void wlr_seat_pointer_clear_focus(struct wlr_seat *wlr_seat); void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time, double sx, double sy); +/** Send relative motion events to the surface with pointer focus. Coordinates + * for the motion event are relative to current pointer location, both + * accelerated and unaccelerated. Compositors should use + * `wlr_seat_pointer_notify_relative_motion()` to send relative motion events + * to respect relative pointer requests by clients. + * + * Note that the timestamp is 64 bit, split into high 32 bits and low 32 bits. + */ +void wlr_seat_pointer_notify_relative_motion(struct wlr_seat *wlr_seat, + uint64_t time, double dx, double dy, double dx_unaccel, + double dy_unaccel); + /** * Send a button event to the surface with pointer focus. Coordinates for the * button event are surface-local. Returns the serial. Compositors should use diff --git a/rootston/cursor.c b/rootston/cursor.c index b9ded30e..b03b934e 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -310,6 +310,9 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor, double dx = event->delta_x; double dy = event->delta_y; + wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, (uint64_t) + event->time_msec, dx, dy, dx, dy); + if (cursor->active_constraint) { struct roots_view *view = cursor->pointer_view->view; assert(view); @@ -349,6 +352,11 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, event->x, event->y, &lx, &ly); + double dx = lx - cursor->cursor->x; + double dy = ly - cursor->cursor->y; + wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, (uint64_t) + event->time_msec, dx, dy, dx, dy); + if (cursor->pointer_view) { struct roots_view *view = cursor->pointer_view->view; diff --git a/types/seat/wlr_seat_pointer.c b/types/seat/wlr_seat_pointer.c index 594a5b81..12c4fab5 100644 --- a/types/seat/wlr_seat_pointer.c +++ b/types/seat/wlr_seat_pointer.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "types/wlr_seat.h" #include "util/signal.h" @@ -304,6 +305,20 @@ void wlr_seat_pointer_notify_motion(struct wlr_seat *wlr_seat, uint32_t time, grab->interface->motion(grab, time, sx, sy); } +void wlr_seat_pointer_notify_relative_motion(struct wlr_seat *wlr_seat, + uint64_t time, double dx, double dy, double dx_unaccel, double dy_unaccel) { + struct wlr_seat_client *client = wlr_seat->pointer_state.focused_client; + if (client == NULL) { + return; + } + + struct wl_resource *resource; + wl_resource_for_each(resource, &client->relative_pointers) { + wlr_relative_pointer_v1_send_relative_motion(resource, time, dx, dy, + dx_unaccel, dy_unaccel); + } +} + uint32_t wlr_seat_pointer_notify_button(struct wlr_seat *wlr_seat, uint32_t time, uint32_t button, uint32_t state) { clock_gettime(CLOCK_MONOTONIC, &wlr_seat->last_event); diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index b32bbc79..c8ec8190 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -187,3 +187,16 @@ void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *rel wlr_log(WLR_DEBUG, "relative_pointer_v1 manager destroyed"); } + + +void wlr_relative_pointer_v1_send_relative_motion(struct wl_resource *resource, + uint64_t time, double dx, double dy, double dx_unaccel, double + dy_unaccel) +{ + assert(wl_resource_instance_of(resource, &zwp_relative_pointer_v1_interface, + &relative_pointer_v1_impl)); + zwp_relative_pointer_v1_send_relative_motion(resource, + (uint32_t) (time >> 32), (uint32_t) time, wl_fixed_from_double(dx), + wl_fixed_from_double(dy), wl_fixed_from_double(dx_unaccel), + wl_fixed_from_double(dy_unaccel)); +} From 6fa1777f94b2743747d00433c98a2251e0ef12ee Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 1 Oct 2018 20:33:21 +0530 Subject: [PATCH 04/19] relative_pointer: code formatting fixes --- include/wlr/types/wlr_relative_pointer_v1.h | 12 ++-- include/wlr/types/wlr_seat.h | 7 ++- rootston/cursor.c | 8 +-- types/seat/wlr_seat_pointer.c | 3 +- types/wlr_relative_pointer_v1.c | 62 +++++++++------------ 5 files changed, 44 insertions(+), 48 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index c74766b9..b2eb7241 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -12,13 +12,15 @@ #include -/* This protocol specifies a set of interfaces used for making clients able to +/** + * This protocol specifies a set of interfaces used for making clients able to * receive relative pointer events not obstructed by barriers (such as the * monitor edge or other pointer barriers). */ -/* A global interface used for getting the relative pointer object for a given +/** + * A global interface used for getting the relative pointer object for a given * pointer. * * Signals: @@ -41,7 +43,8 @@ struct wlr_relative_pointer_manager_v1 { }; -/* A wp_relative_pointer object is an extension to the wl_pointer interface +/** + * A wp_relative_pointer object is an extension to the wl_pointer interface * used for emitting relative pointer events. It shares the same focus as * wl_pointer objects of the same seat and will only emit events when it has * focus. @@ -67,7 +70,6 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager); void wlr_relative_pointer_v1_send_relative_motion(struct wl_resource *resource, - uint64_t time, double dx, double dy, double dx_unaccel, double - dy_unaccel); + uint64_t time, double dx, double dy, double dx_unaccel, double dy_unaccel); #endif diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 54e04e24..4c0edcd8 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -314,7 +314,8 @@ void wlr_seat_pointer_clear_focus(struct wlr_seat *wlr_seat); void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time, double sx, double sy); -/** Send relative motion events to the surface with pointer focus. Coordinates +/** + * Send relative motion events to the surface with pointer focus. Coordinates * for the motion event are relative to current pointer location, both * accelerated and unaccelerated. Compositors should use * `wlr_seat_pointer_notify_relative_motion()` to send relative motion events @@ -323,8 +324,8 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time, * Note that the timestamp is 64 bit, split into high 32 bits and low 32 bits. */ void wlr_seat_pointer_notify_relative_motion(struct wlr_seat *wlr_seat, - uint64_t time, double dx, double dy, double dx_unaccel, - double dy_unaccel); + uint64_t time, double dx, double dy, + double dx_unaccel, double dy_unaccel); /** * Send a button event to the surface with pointer focus. Coordinates for the diff --git a/rootston/cursor.c b/rootston/cursor.c index b03b934e..45d7b40e 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -310,8 +310,8 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor, double dx = event->delta_x; double dy = event->delta_y; - wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, (uint64_t) - event->time_msec, dx, dy, dx, dy); + wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, + (uint64_t)event->time_msec, dx, dy, dx, dy); if (cursor->active_constraint) { struct roots_view *view = cursor->pointer_view->view; @@ -354,8 +354,8 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, double dx = lx - cursor->cursor->x; double dy = ly - cursor->cursor->y; - wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, (uint64_t) - event->time_msec, dx, dy, dx, dy); + wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, + (uint64_t)event->time_msec, dx, dy, dx, dy); if (cursor->pointer_view) { struct roots_view *view = cursor->pointer_view->view; diff --git a/types/seat/wlr_seat_pointer.c b/types/seat/wlr_seat_pointer.c index 12c4fab5..3c7e98e9 100644 --- a/types/seat/wlr_seat_pointer.c +++ b/types/seat/wlr_seat_pointer.c @@ -306,7 +306,8 @@ void wlr_seat_pointer_notify_motion(struct wlr_seat *wlr_seat, uint32_t time, } void wlr_seat_pointer_notify_relative_motion(struct wlr_seat *wlr_seat, - uint64_t time, double dx, double dy, double dx_unaccel, double dy_unaccel) { + uint64_t time, double dx, double dy, + double dx_unaccel, double dy_unaccel) { struct wlr_seat_client *client = wlr_seat->pointer_state.focused_client; if (client == NULL) { return; diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index c8ec8190..93d96fa4 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -13,17 +13,16 @@ static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_m static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl; -/* Callback functions +/** + * Callback functions */ -static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resource *resource) -{ +static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resource *resource) { wl_list_remove(wl_resource_get_link(resource)); } -static void relative_pointer_v1_handle_resource_destroy(struct wl_resource *resource) -{ +static void relative_pointer_v1_handle_resource_destroy(struct wl_resource *resource) { wl_list_remove(wl_resource_get_link(resource)); struct wlr_relative_pointer_v1 *relative_pointer = wl_resource_get_user_data(resource); @@ -32,18 +31,16 @@ static void relative_pointer_v1_handle_resource_destroy(struct wl_resource *reso static void relative_pointer_manager_v1_handle_destroy(struct wl_client *client, - struct wl_resource *resource) -{ + struct wl_resource *resource) { wl_resource_destroy(resource); - wlr_log(WLR_DEBUG, "relative_pointer_v1 manager unbound from client 0x%" PRIXPTR, - (uintptr_t) client); + wlr_log(WLR_DEBUG, "relative_pointer_v1 manager unbound from client %p", + client); } static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_client *client, - struct wl_resource *resource, uint32_t id, struct wl_resource *pointer) -{ + struct wl_resource *resource, uint32_t id, struct wl_resource *pointer) { struct wlr_seat_client *seat_client = wlr_seat_client_from_pointer_resource(pointer); assert(seat_client->client == client); @@ -80,28 +77,24 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer, relative_pointer); - wlr_log(WLR_DEBUG, - "relative_pointer_v1 0x%" PRIXPTR " created for client 0x%" PRIXPTR, - (uintptr_t) relative_pointer, (uintptr_t) client); + wlr_log(WLR_DEBUG, "relative_pointer_v1 %p created for client %p", + relative_pointer, client); } static void relative_pointer_v1_handle_destroy(struct wl_client *client, - struct wl_resource *resource) -{ + struct wl_resource *resource) { struct wlr_relative_pointer_v1 *relative_pointer = wl_resource_get_user_data(resource); - wlr_log(WLR_DEBUG, - "relative_pointer_v1 0x%" PRIXPTR " released by client 0x%" PRIXPTR, - (uintptr_t) relative_pointer, (uintptr_t) client); + wlr_log(WLR_DEBUG, "relative_pointer_v1 %p released by client %p", + relative_pointer, client); wl_resource_destroy(resource); } static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void *data, - uint32_t version, uint32_t id) -{ + uint32_t version, uint32_t id) { struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = data; struct wl_resource *manager_resource = wl_resource_create(wl_client, @@ -117,12 +110,13 @@ static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void * wl_resource_set_implementation(manager_resource, &relative_pointer_manager_v1_impl, relative_pointer_manager, relative_pointer_manager_v1_handle_resource_destroy); - wlr_log(WLR_DEBUG, "relative_pointer_v1 manager bound to client 0x%" PRIXPTR, - (uintptr_t) wl_client); + wlr_log(WLR_DEBUG, "relative_pointer_v1 manager bound to client %p", + wl_client); } -/* Implementations +/** + * Implementations */ static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager_v1_impl = { @@ -136,11 +130,11 @@ static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl = }; -/* Public functions +/** + * Public functions */ -struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display) -{ +struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display) { struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = calloc(1, sizeof(struct wlr_relative_pointer_manager_v1)); @@ -168,8 +162,7 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl } -void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager) -{ +void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager) { if (relative_pointer_manager == NULL) { return; } @@ -190,13 +183,12 @@ void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *rel void wlr_relative_pointer_v1_send_relative_motion(struct wl_resource *resource, - uint64_t time, double dx, double dy, double dx_unaccel, double - dy_unaccel) -{ + uint64_t time, double dx, double dy, + double dx_unaccel, double dy_unaccel) { assert(wl_resource_instance_of(resource, &zwp_relative_pointer_v1_interface, &relative_pointer_v1_impl)); zwp_relative_pointer_v1_send_relative_motion(resource, - (uint32_t) (time >> 32), (uint32_t) time, wl_fixed_from_double(dx), - wl_fixed_from_double(dy), wl_fixed_from_double(dx_unaccel), - wl_fixed_from_double(dy_unaccel)); + (uint32_t)(time >> 32), (uint32_t)time, + wl_fixed_from_double(dx), wl_fixed_from_double(dy), + wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel)); } From fb44ce9fa8aadc1fee59b13f5780b493ed0a425f Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 1 Oct 2018 21:49:26 +0530 Subject: [PATCH 05/19] relative_pointer: send frame event to pointer for Xwayland --- include/wlr/types/wlr_relative_pointer_v1.h | 2 +- types/seat/wlr_seat_pointer.c | 11 +++++++++-- types/wlr_relative_pointer_v1.c | 6 ++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index b2eb7241..22441bb6 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -69,7 +69,7 @@ struct wlr_relative_pointer_v1 { struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display); void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager); -void wlr_relative_pointer_v1_send_relative_motion(struct wl_resource *resource, +void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time, double dx, double dy, double dx_unaccel, double dy_unaccel); #endif diff --git a/types/seat/wlr_seat_pointer.c b/types/seat/wlr_seat_pointer.c index 3c7e98e9..2515fddc 100644 --- a/types/seat/wlr_seat_pointer.c +++ b/types/seat/wlr_seat_pointer.c @@ -315,8 +315,15 @@ void wlr_seat_pointer_notify_relative_motion(struct wlr_seat *wlr_seat, struct wl_resource *resource; wl_resource_for_each(resource, &client->relative_pointers) { - wlr_relative_pointer_v1_send_relative_motion(resource, time, dx, dy, - dx_unaccel, dy_unaccel); + struct wlr_relative_pointer_v1 *relative_pointer = + wl_resource_get_user_data(resource); + if (relative_pointer == NULL) { + continue; + } + + wlr_relative_pointer_v1_send_relative_motion(relative_pointer, time, + dx, dy, dx_unaccel, dy_unaccel); + pointer_send_frame((struct wl_resource *) relative_pointer->pointer); } } diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index 93d96fa4..c5c4650f 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -182,12 +182,10 @@ void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *rel } -void wlr_relative_pointer_v1_send_relative_motion(struct wl_resource *resource, +void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time, double dx, double dy, double dx_unaccel, double dy_unaccel) { - assert(wl_resource_instance_of(resource, &zwp_relative_pointer_v1_interface, - &relative_pointer_v1_impl)); - zwp_relative_pointer_v1_send_relative_motion(resource, + zwp_relative_pointer_v1_send_relative_motion(relative_pointer->resource, (uint32_t)(time >> 32), (uint32_t)time, wl_fixed_from_double(dx), wl_fixed_from_double(dy), wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel)); From 42ffa413fb6695c144557bf37effc1ce3d46fb5b Mon Sep 17 00:00:00 2001 From: random human Date: Wed, 3 Oct 2018 10:46:24 +0530 Subject: [PATCH 06/19] relative_pointer: add relative-pointer example On left mouse button click, locks the cursor and renders relative motion events. --- examples/meson.build | 4 + examples/relative-pointer-unstable-v1.c | 493 ++++++++++++++++++++++++ 2 files changed, 497 insertions(+) create mode 100644 examples/relative-pointer-unstable-v1.c diff --git a/examples/meson.build b/examples/meson.build index 589a7326..0811d1a2 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -81,6 +81,10 @@ examples = { 'src': 'pointer-constraints.c', 'dep': [wayland_client, wlr_protos, wlroots], }, + 'relative-pointer': { + 'src': 'relative-pointer-unstable-v1.c', + 'dep': [wayland_client, wlr_protos, wlroots], + }, 'dmabuf-capture': { 'src': 'dmabuf-capture.c', 'dep': [ diff --git a/examples/relative-pointer-unstable-v1.c b/examples/relative-pointer-unstable-v1.c new file mode 100644 index 00000000..ce671f99 --- /dev/null +++ b/examples/relative-pointer-unstable-v1.c @@ -0,0 +1,493 @@ +#include +#include +#include +#include +#include +#include +#include +#include "pointer-constraints-unstable-v1-client-protocol.h" +#include "relative-pointer-unstable-v1-client-protocol.h" +#include "xdg-shell-client-protocol.h" + + +/** + * structs storing global state + * + * These are passed around as user data in the wayland globals. + */ + +struct egl_info { + struct wlr_egl *egl; + struct wl_egl_window *egl_window; + struct wlr_egl_surface *egl_surface; + uint32_t width; + uint32_t height; + struct wl_surface *surface; + struct wl_callback *frame_callback; +}; + +struct window { + struct egl_info *egl_info; + struct wl_pointer *pointer; + struct zwp_locked_pointer_v1 *locked_pointer; + struct zwp_relative_pointer_v1 *relative_pointer; + int32_t pointer_x, pointer_y; + uint32_t last_draw; +}; + + +/** + * surface handling and helpers + * + * draw_cursor and draw_relative_cursor draw a small 5px by 5px box around the + * cursor and relative motion coordinates respectively. draw_background colors + * the background black. + * + * The functions are somewhat duplicated, but it doesn't really matter. + */ + +static void surface_callback_handle_done(void *data, + struct wl_callback *callback, uint32_t time) { + wl_callback_destroy(callback); + struct egl_info *e = data; + e->frame_callback = NULL; +} + +static struct wl_callback_listener surface_callback_listener = { + .done = surface_callback_handle_done, +}; + +static void draw_init(struct egl_info *e) { + eglMakeCurrent(e->egl->display, e->egl_surface, + e->egl_surface, e->egl->context); + glViewport(0, 0, e->width, e->height); +} + +static void draw_cursor(struct egl_info *e, int32_t x, int32_t y) { + glEnable(GL_SCISSOR_TEST); + glScissor(x, e->height - y, 5, 5); + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); /* white */ + glClear(GL_COLOR_BUFFER_BIT); + glDisable(GL_SCISSOR_TEST); +} + +static void draw_relative_cursor(struct egl_info *e, int32_t x, int32_t y) { + glEnable(GL_SCISSOR_TEST); + glScissor(x, e->height - y, 5, 5); + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); /* red */ + glClear(GL_COLOR_BUFFER_BIT); + glDisable(GL_SCISSOR_TEST); +} + +static void draw_background(struct egl_info *e) { + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); /* black */ + glClear(GL_COLOR_BUFFER_BIT); +} + +static void draw_end(struct egl_info *e) { + e->frame_callback = wl_surface_frame(e->surface); + wl_callback_add_listener(e->frame_callback, &surface_callback_listener, e); + + eglSwapBuffers(e->egl->display, e->egl_surface); +} + + +/** + * registry and globals handling + */ + +static struct wl_compositor *compositor = NULL; +static struct wl_seat *seat = NULL; +static struct xdg_wm_base *wm_base = NULL; +static struct zwp_pointer_constraints_v1 *pointer_constraints = NULL; +static struct zwp_relative_pointer_manager_v1 *relative_pointer_manager = NULL; + +static void registry_handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) { + if (strcmp(interface, wl_compositor_interface.name) == 0) { + compositor = wl_registry_bind(registry, name, + &wl_compositor_interface, version); + } else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { + wm_base = wl_registry_bind(registry, name, + &xdg_wm_base_interface, version); + } else if (strcmp(interface, wl_seat_interface.name) == 0) { + seat = wl_registry_bind(registry, name, + &wl_seat_interface, version); + } else if (strcmp(interface, zwp_pointer_constraints_v1_interface.name) == 0) { + pointer_constraints = wl_registry_bind(registry, name, + &zwp_pointer_constraints_v1_interface, version); + } else if (strcmp(interface, zwp_relative_pointer_manager_v1_interface.name) == 0) { + relative_pointer_manager = wl_registry_bind(registry, name, + &zwp_relative_pointer_manager_v1_interface, version); + } +} + +static void registry_handle_global_remove(void *data, struct wl_registry *registry, + uint32_t time) { + /* This space intentionally left blank */ +} + +static const struct wl_registry_listener registry_listener = { + .global = registry_handle_global, + .global_remove = registry_handle_global_remove, +}; + + +/** + * xdg_surface handling + */ + +static void xdg_surface_handle_configure(void *data, + struct xdg_surface *xdg_surface, uint32_t serial) { + struct egl_info *e = data; + xdg_surface_ack_configure(xdg_surface, serial); + wl_egl_window_resize(e->egl_window, e->width, e->height, 0, 0); + draw_init(e); + draw_background(e); + draw_end(e); +} + +static const struct xdg_surface_listener xdg_surface_listener = { + .configure = xdg_surface_handle_configure, +}; + + +/** + * xdg_toplevel handling + */ + +static void xdg_toplevel_handle_configure(void *data, + struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, + struct wl_array *states) { + struct egl_info *e = data; + // TODO: Why do we get 0,0 on initialization here? (in rootston) + if (width == 0 && height == 0) { + return; + } + e->width = width; + e->height = height; +} + +static void xdg_toplevel_handle_close(void *data, + struct xdg_toplevel *xdg_toplevel) { + struct egl_info *e = data; + wlr_egl_finish(e->egl); + exit(EXIT_SUCCESS); +} + +static const struct xdg_toplevel_listener xdg_toplevel_listener = { + .configure = xdg_toplevel_handle_configure, + .close = xdg_toplevel_handle_close, +}; + + +/** + * zwp_locked_pointer handling + * + * Pointer unlocks need to be handled properly since the relative pointer needs + * to be released as well. Unlocks happen when the focus is changed, for + * example. + */ + +static void locked_pointer_handle_locked(void *data, + struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1) { + /* This space intentionally left blank */ +} + +static void locked_pointer_handle_unlocked(void *data, + struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1) { + struct window *w = data; + /* The locked pointer doesn't need to be destroyed since it was oneshot */ + w->locked_pointer = NULL; + if (w->relative_pointer) { + /* Destroy the relative pointer */ + zwp_relative_pointer_v1_destroy(w->relative_pointer); + w->relative_pointer = NULL; + } + draw_init(w->egl_info); + draw_background(w->egl_info); + draw_end(w->egl_info); +} + +static const struct zwp_locked_pointer_v1_listener locked_pointer_listener = { + .locked = locked_pointer_handle_locked, + .unlocked = locked_pointer_handle_unlocked, +}; + + +/** + * zwp_relative_pointer handling + * + * Handling relative_motion events is the meat of the code. The handler simply + * tries to indicate what the deltas look like. + */ + +static void relative_pointer_handle_relative_motion(void *data, + struct zwp_relative_pointer_v1 *zwp_relative_pointer_v1, + uint32_t utime_hi, uint32_t utime_lo, + wl_fixed_t dx, wl_fixed_t dy, + wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel) { + struct window *w = data; + + /** + * This renders the last location of the pointer (before it as locked), as + * well as what the position would have been after the given relative + * motion. Note that, if the device sends absolute motion events, the + * cursor location after relative motion is always identical to the actual + * cursor position. + */ + uint64_t utime = (((uint64_t) utime_hi << 32) + utime_lo) / 1000; + if (utime - w->last_draw > 30 && w->egl_info->frame_callback == NULL) { + w->last_draw = utime; + + struct egl_info *e = w->egl_info; + draw_init(e); + draw_background(e); + draw_cursor(e, w->pointer_x, w->pointer_y); + draw_relative_cursor(e, w->pointer_x + wl_fixed_to_int(dx), + w->pointer_y + wl_fixed_to_int(dy)); + draw_end(e); + } +} + +static const struct zwp_relative_pointer_v1_listener relative_pointer_listener = { + .relative_motion = relative_pointer_handle_relative_motion, +}; + + +/** + * wl_pointer handling + * + * The client toggles between locking the pointer and receiving relative motion + * events, and releasing the locked pointer and falling back to normal motion + * events, on a mouse button one (left mouse button) click. + * + * It additionally removes the cursor image, and indicates the pointer location + * via a small white box. + */ + +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 *w = data; + struct egl_info *e = w->egl_info; + + if (button == BTN_LEFT && state_w == WL_POINTER_BUTTON_STATE_PRESSED) { + if (w->locked_pointer == NULL && w->relative_pointer == NULL) { + /* Get a locked pointer and add listener */ + w->locked_pointer = zwp_pointer_constraints_v1_lock_pointer( + pointer_constraints, w->egl_info->surface, w->pointer, NULL, + ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT); + zwp_locked_pointer_v1_add_listener(w->locked_pointer, + &locked_pointer_listener, w); + + /* Get relative pointer and add listener */ + w->relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer( + relative_pointer_manager, w->pointer); + zwp_relative_pointer_v1_add_listener(w->relative_pointer, + &relative_pointer_listener, w); + + /* Commit the surface and render */ + wl_surface_commit(e->surface); + + draw_init(e); + draw_background(e); + draw_cursor(e, w->pointer_x, w->pointer_y); + draw_end(e); + } else if (w->locked_pointer && w->relative_pointer) { + /* Destroy the locked pointer */ + zwp_locked_pointer_v1_destroy(w->locked_pointer); + w->locked_pointer = NULL; + + /* Destroy the relative pointer */ + zwp_relative_pointer_v1_destroy(w->relative_pointer); + w->relative_pointer = NULL; + + /* Render */ + draw_init(e); + draw_background(e); + draw_cursor(e, w->pointer_x, w->pointer_y); + draw_end(e); + } else { + fprintf(stderr, "Unknown state!\n"); + exit(EXIT_FAILURE); + } + } +} + +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 window *w = data; + wl_pointer_set_cursor(w->pointer, serial, NULL, 0, 0); +} + +static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, struct wl_surface *surface) { + /* This space intentionally left blank */ +} + +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 window *w = data; + struct egl_info *e = w->egl_info; + w->pointer_x = wl_fixed_to_int(surface_x); + w->pointer_y = wl_fixed_to_int(surface_y); + if (time - w->last_draw > 30 && e->frame_callback == NULL) { + w->last_draw = time; + draw_init(e); + draw_background(e); + draw_cursor(e, w->pointer_x, w->pointer_y); + draw_end(e); + } +} + +static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, + uint32_t time, uint32_t axis, wl_fixed_t value) { + /* This space intentionally left blank */ +} + +static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { + /* This space intentionally left blank */ +} + +static void pointer_handle_axis_source(void *data, + struct wl_pointer *wl_pointer, uint32_t axis_source) { + /* This space intentionally left blank */ +} + +static void pointer_handle_axis_stop(void *data, + struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis) { + /* This space intentionally left blank */ +} + +static void pointer_handle_axis_discrete(void *data, + struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete) { + /* This space intentionally left blank */ +} + +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, +}; + + +/** + * relative-pointer: + * + * This client servers as an example for the relative-pointer-v1 protocol, and + * to some extent the pointer-constraints protocol as well (the locked_pointer + * interface). + * + * The intended behavior is the following. In the default state, the client + * shows a black background, and renders the pointer location as a small white + * box. No cursor is shown. In the locked state, the pointer is locked and the + * client only listens for relative motion events, which are rendered relative + * to the last unlocked pointer location by a small red box. Clicking with the + * left mouse button toggles the state. + * + * Most of the code is standard. The interesting stuff happens in "wl_pointer + * handling" (toggling states), and "zwp_relative_pointer handling" (rendering + * relative motion events). + */ + +int main(int argc, char **argv) { + + /* Connect to the display */ + + struct wl_display *display = wl_display_connect(NULL); + if (display == NULL) { + fprintf(stderr, "Could not connect to a Wayland display\n"); + return EXIT_FAILURE; + } + + /* Get the registry and set listeners */ + + struct wl_registry *registry = wl_display_get_registry(display); + wl_registry_add_listener(registry, ®istry_listener, NULL); + wl_display_dispatch(display); + wl_display_roundtrip(display); + + /* Check that all the global interfaces were captured */ + + if (compositor == NULL) { + fprintf(stderr, "wl_compositor not available\n"); + return EXIT_FAILURE; + } + if (seat == NULL) { + fprintf(stderr, "wl_seat not available\n"); + return EXIT_FAILURE; + } + if (wm_base == NULL) { + fprintf(stderr, "xdg_wm_base not available\n"); + return EXIT_FAILURE; + } + if (pointer_constraints == NULL) { + fprintf(stderr, "zwp_pointer_constraints_v1 not available\n"); + return EXIT_FAILURE; + } + if (relative_pointer_manager == NULL) { + fprintf(stderr, "zwp_relative_pointer_manager_v1 not available\n"); + return EXIT_FAILURE; + } + + /* Initialize EGL context */ + + struct egl_info *e = calloc(1, sizeof(struct egl_info)); + e->egl = calloc(1, sizeof(struct wlr_egl)); + e->width = e->height = 512; + + wlr_egl_init(e->egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, + WL_SHM_FORMAT_ARGB8888); + + /* Create the surface and xdg_toplevels, and set listeners */ + + struct wl_surface *surface = wl_compositor_create_surface(compositor); + struct xdg_surface *xdg_surface = + xdg_wm_base_get_xdg_surface(wm_base, surface); + struct xdg_toplevel *xdg_toplevel = xdg_surface_get_toplevel(xdg_surface); + + xdg_surface_add_listener(xdg_surface, &xdg_surface_listener, e); + xdg_toplevel_add_listener(xdg_toplevel, &xdg_toplevel_listener, e); + + /* Create the egl window and surface */ + + wl_surface_commit(surface); + + e->egl_window = wl_egl_window_create(surface, e->width, e->height); + e->egl_surface = wlr_egl_create_surface(e->egl, e->egl_window); + e->surface = surface; + + wl_display_roundtrip(display); + + /* Setup global state and render */ + + struct window *w = calloc(1, sizeof(struct window)); + w->egl_info = e; + + draw_init(e); + draw_background(e); + draw_end(e); + + /* Setup the pointer */ + + struct wl_pointer *pointer = wl_seat_get_pointer(seat); + wl_pointer_add_listener(pointer, &pointer_listener, w); + + w->pointer = pointer; + + /* Run display */ + + while (wl_display_dispatch(display) != -1) { + /* This space intentionally left blank */ + } + + return EXIT_SUCCESS; +} From 68137dca3f0b20c5610a30e4c3820984b387dda5 Mon Sep 17 00:00:00 2001 From: random human Date: Thu, 4 Oct 2018 00:43:35 +0530 Subject: [PATCH 07/19] relative_pointer: implementation and code fixes In particular, modified public creator and destructor function names, added a display destroy listener, safely extract user data from resources, send correct time (in usecs) in rootston, etc. --- include/wlr/types/wlr_relative_pointer_v1.h | 32 ++++---- include/wlr/types/wlr_seat.h | 2 +- rootston/cursor.c | 4 +- rootston/desktop.c | 2 +- types/seat/wlr_seat.c | 4 +- types/seat/wlr_seat_pointer.c | 6 +- types/wlr_relative_pointer_v1.c | 91 +++++++++++++++------ 7 files changed, 92 insertions(+), 49 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index 22441bb6..50106b4b 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -22,12 +22,6 @@ /** * A global interface used for getting the relative pointer object for a given * pointer. - * - * Signals: - * - destroy -> struct wlr_relative_pointer_manager_v1 *manager - * :: the manager was destroyed - * - new_relative_pointer -> struct wlr_relative_pointer_v1 *relative_pointer - * :: a new relative_pointer was created */ struct wlr_relative_pointer_manager_v1 { @@ -36,9 +30,15 @@ struct wlr_relative_pointer_manager_v1 { struct { struct wl_signal destroy; + /** + * returns struct wlr_relative_pointer_v1 *relative_pointer + * called when a new relative_pointer is successfully created + */ struct wl_signal new_relative_pointer; } events; + struct wl_listener display_destroy_listener; + void *data; }; @@ -48,16 +48,12 @@ struct wlr_relative_pointer_manager_v1 { * used for emitting relative pointer events. It shares the same focus as * wl_pointer objects of the same seat and will only emit events when it has * focus. - * - * Signals: - * - destroy -> struct wlr_relative_pointer_v1 *relative_pointer - * :: the relative_pointer was destroyed */ struct wlr_relative_pointer_v1 { struct wl_client *client; struct wl_resource *resource; - struct wl_pointer *pointer; + struct wl_resource *pointer; struct { struct wl_signal destroy; @@ -66,10 +62,16 @@ struct wlr_relative_pointer_v1 { void *data; }; -struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display); -void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager); +struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_manager_v1_create( + struct wl_display *display); +void wlr_relative_pointer_manager_v1_destroy( + struct wlr_relative_pointer_manager_v1 *relative_pointer_manager); + +void wlr_relative_pointer_v1_send_relative_motion( + struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time, + double dx, double dy, double dx_unaccel, double dy_unaccel); -void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1 *relative_pointer, - uint64_t time, double dx, double dy, double dx_unaccel, double dy_unaccel); +struct wlr_relative_pointer_v1 *wlr_relative_pointer_v1_from_resource( + struct wl_resource *resource); #endif diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 4c0edcd8..9865ecdd 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -27,7 +27,7 @@ struct wlr_seat_client { // lists of wl_resource struct wl_list resources; struct wl_list pointers; - struct wl_list relative_pointers; + struct wl_list relative_pointers_v1; struct wl_list keyboards; struct wl_list touches; struct wl_list data_devices; diff --git a/rootston/cursor.c b/rootston/cursor.c index 45d7b40e..4c5fdb36 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -311,7 +311,7 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor, double dy = event->delta_y; wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, - (uint64_t)event->time_msec, dx, dy, dx, dy); + (uint64_t)event->time_msec * 1000, dx, dy, dx, dy); if (cursor->active_constraint) { struct roots_view *view = cursor->pointer_view->view; @@ -355,7 +355,7 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, double dx = lx - cursor->cursor->x; double dy = ly - cursor->cursor->y; wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, - (uint64_t)event->time_msec, dx, dy, dx, dy); + (uint64_t)event->time_msec * 1000, dx, dy, dx, dy); if (cursor->pointer_view) { struct roots_view *view = cursor->pointer_view->view; diff --git a/rootston/desktop.c b/rootston/desktop.c index e4affe3b..77a52571 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -1082,7 +1082,7 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->foreign_toplevel_manager_v1 = wlr_foreign_toplevel_manager_v1_create(server->wl_display); desktop->relative_pointer_manager = - wlr_relative_pointer_v1_create(server->wl_display); + wlr_relative_pointer_manager_v1_create(server->wl_display); return desktop; } diff --git a/types/seat/wlr_seat.c b/types/seat/wlr_seat.c index 698a906a..688bfc94 100644 --- a/types/seat/wlr_seat.c +++ b/types/seat/wlr_seat.c @@ -79,7 +79,7 @@ static void seat_client_handle_resource_destroy( wl_resource_for_each_safe(resource, tmp, &client->pointers) { wl_resource_destroy(resource); } - wl_resource_for_each_safe(resource, tmp, &client->relative_pointers) { + wl_resource_for_each_safe(resource, tmp, &client->relative_pointers_v1) { wl_resource_destroy(resource); } wl_resource_for_each_safe(resource, tmp, &client->keyboards) { @@ -134,7 +134,7 @@ static void seat_handle_bind(struct wl_client *client, void *_wlr_seat, seat_client->seat = wlr_seat; wl_list_init(&seat_client->resources); wl_list_init(&seat_client->pointers); - wl_list_init(&seat_client->relative_pointers); + wl_list_init(&seat_client->relative_pointers_v1); wl_list_init(&seat_client->keyboards); wl_list_init(&seat_client->touches); wl_list_init(&seat_client->data_devices); diff --git a/types/seat/wlr_seat_pointer.c b/types/seat/wlr_seat_pointer.c index 2515fddc..8e5fa4db 100644 --- a/types/seat/wlr_seat_pointer.c +++ b/types/seat/wlr_seat_pointer.c @@ -314,16 +314,16 @@ void wlr_seat_pointer_notify_relative_motion(struct wlr_seat *wlr_seat, } struct wl_resource *resource; - wl_resource_for_each(resource, &client->relative_pointers) { + wl_resource_for_each(resource, &client->relative_pointers_v1) { struct wlr_relative_pointer_v1 *relative_pointer = - wl_resource_get_user_data(resource); + wlr_relative_pointer_v1_from_resource(resource); if (relative_pointer == NULL) { continue; } wlr_relative_pointer_v1_send_relative_motion(relative_pointer, time, dx, dy, dx_unaccel, dy_unaccel); - pointer_send_frame((struct wl_resource *) relative_pointer->pointer); + pointer_send_frame(relative_pointer->pointer); } } diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index c5c4650f..fb126f1e 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -9,27 +9,64 @@ #include "wayland-server.h" #include "relative-pointer-unstable-v1-protocol.h" +#define RELATIVE_POINTER_MANAGER_VERSION 1 + static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager_v1_impl; static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl; /** - * Callback functions + * helper functions */ -static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resource *resource) { - wl_list_remove(wl_resource_get_link(resource)); +struct wlr_relative_pointer_v1 *relative_pointer_from_resource(struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwp_relative_pointer_v1_interface, + &relative_pointer_v1_impl)); + return wl_resource_get_user_data(resource); } +static struct wlr_relative_pointer_manager_v1 *relative_pointer_manager_from_resource(struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwp_relative_pointer_manager_v1_interface, + &relative_pointer_manager_v1_impl)); + return wl_resource_get_user_data(resource); +} + + +/** + * relative_pointer handler functions + */ + static void relative_pointer_v1_handle_resource_destroy(struct wl_resource *resource) { - wl_list_remove(wl_resource_get_link(resource)); + struct wlr_relative_pointer_v1 *relative_pointer = + relative_pointer_from_resource(resource); + wlr_signal_emit_safe(&relative_pointer->events.destroy, relative_pointer); - struct wlr_relative_pointer_v1 *relative_pointer = wl_resource_get_user_data(resource); + wl_list_remove(wl_resource_get_link(resource)); free(relative_pointer); } +static void relative_pointer_v1_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + struct wlr_relative_pointer_v1 *relative_pointer = + relative_pointer_from_resource(resource); + wlr_log(WLR_DEBUG, "relative_pointer_v1 %p released by client %p", + relative_pointer, client); + + wl_resource_destroy(resource); +} + + +/** + * relative_pointer_manager handler functions + */ + +static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resource *resource) { + wl_list_remove(wl_resource_get_link(resource)); +} + + static void relative_pointer_manager_v1_handle_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); @@ -62,18 +99,18 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl relative_pointer->client = client; relative_pointer->resource = relative_pointer_resource; - relative_pointer->pointer = (struct wl_pointer *) pointer; + relative_pointer->pointer = pointer; wl_signal_init(&relative_pointer->events.destroy); - wl_list_insert(&seat_client->relative_pointers, + wl_list_insert(&seat_client->relative_pointers_v1, wl_resource_get_link(relative_pointer_resource)); wl_resource_set_implementation(relative_pointer_resource, &relative_pointer_v1_impl, relative_pointer, relative_pointer_v1_handle_resource_destroy); struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = - wl_resource_get_user_data(resource); + relative_pointer_manager_from_resource(resource); wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer, relative_pointer); @@ -82,17 +119,6 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl } -static void relative_pointer_v1_handle_destroy(struct wl_client *client, - struct wl_resource *resource) { - struct wlr_relative_pointer_v1 *relative_pointer = - wl_resource_get_user_data(resource); - wlr_log(WLR_DEBUG, "relative_pointer_v1 %p released by client %p", - relative_pointer, client); - - wl_resource_destroy(resource); -} - - static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = data; @@ -114,6 +140,12 @@ static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void * wl_client); } +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = + wl_container_of(listener, relative_pointer_manager, display_destroy_listener); + wlr_relative_pointer_manager_v1_destroy(relative_pointer_manager); +} + /** * Implementations @@ -134,7 +166,7 @@ static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl = * Public functions */ -struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display) { +struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_manager_v1_create(struct wl_display *display) { struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = calloc(1, sizeof(struct wlr_relative_pointer_manager_v1)); @@ -144,11 +176,8 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl wl_list_init(&relative_pointer_manager->resources); - wl_signal_init(&relative_pointer_manager->events.destroy); - wl_signal_init(&relative_pointer_manager->events.new_relative_pointer); - relative_pointer_manager->global = wl_global_create(display, - &zwp_relative_pointer_manager_v1_interface, 1, + &zwp_relative_pointer_manager_v1_interface, RELATIVE_POINTER_MANAGER_VERSION, relative_pointer_manager, relative_pointer_manager_v1_bind); if (relative_pointer_manager->global == NULL) { @@ -156,18 +185,25 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl return NULL; } + wl_signal_init(&relative_pointer_manager->events.destroy); + wl_signal_init(&relative_pointer_manager->events.new_relative_pointer); + + relative_pointer_manager->display_destroy_listener.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &relative_pointer_manager->display_destroy_listener); + wlr_log(WLR_DEBUG, "relative_pointer_v1 manager created"); return relative_pointer_manager; } -void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager) { +void wlr_relative_pointer_manager_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager) { if (relative_pointer_manager == NULL) { return; } wlr_signal_emit_safe(&relative_pointer_manager->events.destroy, relative_pointer_manager); + wl_list_remove(&relative_pointer_manager->display_destroy_listener.link); struct wl_resource *resource; struct wl_resource *tmp_resource; @@ -190,3 +226,8 @@ void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1 wl_fixed_from_double(dx), wl_fixed_from_double(dy), wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel)); } + + +struct wlr_relative_pointer_v1 *wlr_relative_pointer_v1_from_resource(struct wl_resource *resource) { + return relative_pointer_from_resource(resource); +} From a2964a640bbcbe4e8e9c0f9ad0b7913227e9a3a0 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Sun, 9 Dec 2018 19:59:00 -0600 Subject: [PATCH 08/19] Add wlr_relative_pointer_v1.h to meson.build --- include/wlr/types/meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/include/wlr/types/meson.build b/include/wlr/types/meson.build index 752c0dea..dfb55ec9 100644 --- a/include/wlr/types/meson.build +++ b/include/wlr/types/meson.build @@ -27,6 +27,7 @@ install_headers( 'wlr_presentation_time.h', 'wlr_primary_selection.h', 'wlr_region.h', + 'wlr_relative_pointer_v1.h', 'wlr_screencopy_v1.h', 'wlr_screenshooter.h', 'wlr_seat.h', From f4cf3c08865e39e88061c96e823b2893a68a433f Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Thu, 13 Dec 2018 02:19:55 -0600 Subject: [PATCH 09/19] Remove wl_client from wlr_relative_pointer_v1 --- include/wlr/types/wlr_relative_pointer_v1.h | 1 - types/wlr_relative_pointer_v1.c | 1 - 2 files changed, 2 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index 50106b4b..24b20003 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -51,7 +51,6 @@ struct wlr_relative_pointer_manager_v1 { */ struct wlr_relative_pointer_v1 { - struct wl_client *client; struct wl_resource *resource; struct wl_resource *pointer; diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index fb126f1e..ed01b433 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -97,7 +97,6 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl return; } - relative_pointer->client = client; relative_pointer->resource = relative_pointer_resource; relative_pointer->pointer = pointer; From 09bdbf24f4fc44cfbb9bd6079a1d7cd08edaefdb Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Thu, 13 Dec 2018 23:41:21 -0600 Subject: [PATCH 10/19] Removed relative pointers from wlr_seat --- include/wlr/types/wlr_relative_pointer_v1.h | 5 +++- include/wlr/types/wlr_seat.h | 1 - rootston/cursor.c | 32 +++++++++++++++++++-- types/seat/wlr_seat.c | 4 --- types/seat/wlr_seat_pointer.c | 22 -------------- types/wlr_relative_pointer_v1.c | 9 ++++-- 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index 24b20003..1fd6e610 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -25,8 +25,9 @@ */ struct wlr_relative_pointer_manager_v1 { - struct wl_list resources; struct wl_global *global; + struct wl_list resources; + struct wl_list relative_pointers; struct { struct wl_signal destroy; @@ -52,7 +53,9 @@ struct wlr_relative_pointer_manager_v1 { struct wlr_relative_pointer_v1 { struct wl_resource *resource; + struct wlr_seat *seat; struct wl_resource *pointer; + struct wl_list link; // wlr_relative_pointer_manager_v1::relative_pointers struct { struct wl_signal destroy; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 9865ecdd..48c48d73 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -27,7 +27,6 @@ struct wlr_seat_client { // lists of wl_resource struct wl_list resources; struct wl_list pointers; - struct wl_list relative_pointers_v1; struct wl_list keyboards; struct wl_list touches; struct wl_list data_devices; diff --git a/rootston/cursor.c b/rootston/cursor.c index 4c5fdb36..87f35435 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -305,12 +305,39 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, } } +static void notify_relative_motion(struct roots_seat *seat, uint64_t time_msec, + double dx, double dy, double dx_unaccel, double dy_unaccel) { + + struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = + seat->input->server->desktop->relative_pointer_manager; + + struct wlr_seat_client *client = seat->seat->pointer_state.focused_client; + if (client == NULL) { + return; + } + + struct wl_resource *resource; + wl_resource_for_each(resource, &relative_pointer_manager->relative_pointers) { + + struct wlr_relative_pointer_v1 *pointer = + wlr_relative_pointer_v1_from_resource(resource); + if (pointer == NULL) { + continue; + } + + wlr_relative_pointer_v1_send_relative_motion(pointer, time_msec, + dx, dy, dx_unaccel, dy_unaccel); + wl_pointer_send_frame(pointer->pointer); + } + +} + void roots_cursor_handle_motion(struct roots_cursor *cursor, struct wlr_event_pointer_motion *event) { double dx = event->delta_x; double dy = event->delta_y; - wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, + notify_relative_motion(cursor->seat, (uint64_t)event->time_msec * 1000, dx, dy, dx, dy); if (cursor->active_constraint) { @@ -354,7 +381,8 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, double dx = lx - cursor->cursor->x; double dy = ly - cursor->cursor->y; - wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, + + notify_relative_motion(cursor->seat, (uint64_t)event->time_msec * 1000, dx, dy, dx, dy); if (cursor->pointer_view) { diff --git a/types/seat/wlr_seat.c b/types/seat/wlr_seat.c index 688bfc94..8b1d67fd 100644 --- a/types/seat/wlr_seat.c +++ b/types/seat/wlr_seat.c @@ -79,9 +79,6 @@ static void seat_client_handle_resource_destroy( wl_resource_for_each_safe(resource, tmp, &client->pointers) { wl_resource_destroy(resource); } - wl_resource_for_each_safe(resource, tmp, &client->relative_pointers_v1) { - wl_resource_destroy(resource); - } wl_resource_for_each_safe(resource, tmp, &client->keyboards) { wl_resource_destroy(resource); } @@ -134,7 +131,6 @@ static void seat_handle_bind(struct wl_client *client, void *_wlr_seat, seat_client->seat = wlr_seat; wl_list_init(&seat_client->resources); wl_list_init(&seat_client->pointers); - wl_list_init(&seat_client->relative_pointers_v1); wl_list_init(&seat_client->keyboards); wl_list_init(&seat_client->touches); wl_list_init(&seat_client->data_devices); diff --git a/types/seat/wlr_seat_pointer.c b/types/seat/wlr_seat_pointer.c index 8e5fa4db..936ac0dc 100644 --- a/types/seat/wlr_seat_pointer.c +++ b/types/seat/wlr_seat_pointer.c @@ -305,28 +305,6 @@ void wlr_seat_pointer_notify_motion(struct wlr_seat *wlr_seat, uint32_t time, grab->interface->motion(grab, time, sx, sy); } -void wlr_seat_pointer_notify_relative_motion(struct wlr_seat *wlr_seat, - uint64_t time, double dx, double dy, - double dx_unaccel, double dy_unaccel) { - struct wlr_seat_client *client = wlr_seat->pointer_state.focused_client; - if (client == NULL) { - return; - } - - struct wl_resource *resource; - wl_resource_for_each(resource, &client->relative_pointers_v1) { - struct wlr_relative_pointer_v1 *relative_pointer = - wlr_relative_pointer_v1_from_resource(resource); - if (relative_pointer == NULL) { - continue; - } - - wlr_relative_pointer_v1_send_relative_motion(relative_pointer, time, - dx, dy, dx_unaccel, dy_unaccel); - pointer_send_frame(relative_pointer->pointer); - } -} - uint32_t wlr_seat_pointer_notify_button(struct wlr_seat *wlr_seat, uint32_t time, uint32_t button, uint32_t state) { clock_gettime(CLOCK_MONOTONIC, &wlr_seat->last_event); diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index ed01b433..ef937829 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -98,18 +98,20 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl } relative_pointer->resource = relative_pointer_resource; + relative_pointer->seat = seat_client->seat; relative_pointer->pointer = pointer; wl_signal_init(&relative_pointer->events.destroy); - wl_list_insert(&seat_client->relative_pointers_v1, - wl_resource_get_link(relative_pointer_resource)); - wl_resource_set_implementation(relative_pointer_resource, &relative_pointer_v1_impl, relative_pointer, relative_pointer_v1_handle_resource_destroy); struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = relative_pointer_manager_from_resource(resource); + + wl_list_insert(&relative_pointer_manager->relative_pointers, + wl_resource_get_link(relative_pointer_resource)); + wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer, relative_pointer); @@ -174,6 +176,7 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_manager_v1_create(s } wl_list_init(&relative_pointer_manager->resources); + wl_list_init(&relative_pointer_manager->relative_pointers); relative_pointer_manager->global = wl_global_create(display, &zwp_relative_pointer_manager_v1_interface, RELATIVE_POINTER_MANAGER_VERSION, From d0c940d796418672a2421afe108e01b23b0452c4 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Fri, 14 Dec 2018 09:34:09 -0600 Subject: [PATCH 11/19] Only send relative motion to correct seat --- rootston/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootston/cursor.c b/rootston/cursor.c index 87f35435..e34fe4b2 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -321,7 +321,7 @@ static void notify_relative_motion(struct roots_seat *seat, uint64_t time_msec, struct wlr_relative_pointer_v1 *pointer = wlr_relative_pointer_v1_from_resource(resource); - if (pointer == NULL) { + if (pointer == NULL || seat->seat != pointer->seat) { continue; } From f5ea393bca7a427c0d97217c67b0be563b28dc19 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Fri, 14 Dec 2018 09:42:24 -0600 Subject: [PATCH 12/19] Remove pointer resource from relative pointer --- include/wlr/types/wlr_relative_pointer_v1.h | 1 - rootston/cursor.c | 8 +++++++- types/wlr_relative_pointer_v1.c | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index 1fd6e610..6f2e0878 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -54,7 +54,6 @@ struct wlr_relative_pointer_manager_v1 { struct wlr_relative_pointer_v1 { struct wl_resource *resource; struct wlr_seat *seat; - struct wl_resource *pointer; struct wl_list link; // wlr_relative_pointer_manager_v1::relative_pointers struct { diff --git a/rootston/cursor.c b/rootston/cursor.c index e34fe4b2..ba8d0860 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -327,7 +327,13 @@ static void notify_relative_motion(struct roots_seat *seat, uint64_t time_msec, wlr_relative_pointer_v1_send_relative_motion(pointer, time_msec, dx, dy, dx_unaccel, dy_unaccel); - wl_pointer_send_frame(pointer->pointer); + } + + wl_resource_for_each(resource, &client->pointers) { + if (wlr_seat_client_from_pointer_resource(resource) == NULL) { + continue; + } + wl_pointer_send_frame(resource); } } diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index ef937829..e5568f5f 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -99,7 +99,6 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl relative_pointer->resource = relative_pointer_resource; relative_pointer->seat = seat_client->seat; - relative_pointer->pointer = pointer; wl_signal_init(&relative_pointer->events.destroy); From a803a007fb9c572e0eccc22ab670ac711cb89b13 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Mon, 17 Dec 2018 14:04:49 -0600 Subject: [PATCH 13/19] Address @emersion's comments --- include/wlr/types/wlr_relative_pointer_v1.h | 8 +-- include/wlr/types/wlr_seat.h | 13 ----- rootston/cursor.c | 20 ++----- types/seat/wlr_seat_pointer.c | 1 - types/wlr_relative_pointer_v1.c | 59 +++++++++++++++------ 5 files changed, 53 insertions(+), 48 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index 6f2e0878..292be238 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -15,7 +15,7 @@ /** * This protocol specifies a set of interfaces used for making clients able to * receive relative pointer events not obstructed by barriers (such as the - * monitor edge or other pointer barriers). + * monitor edge or pointer constraints). */ @@ -26,7 +26,7 @@ struct wlr_relative_pointer_manager_v1 { struct wl_global *global; - struct wl_list resources; + struct wl_list resources; // wl_resource_get_link() struct wl_list relative_pointers; struct { @@ -60,6 +60,8 @@ struct wlr_relative_pointer_v1 { struct wl_signal destroy; } events; + struct wl_listener seat_destroy; + void *data; }; @@ -69,7 +71,7 @@ void wlr_relative_pointer_manager_v1_destroy( struct wlr_relative_pointer_manager_v1 *relative_pointer_manager); void wlr_relative_pointer_v1_send_relative_motion( - struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time, + struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time_msec, double dx, double dy, double dx_unaccel, double dy_unaccel); struct wlr_relative_pointer_v1 *wlr_relative_pointer_v1_from_resource( diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 48c48d73..942a3420 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -313,19 +313,6 @@ void wlr_seat_pointer_clear_focus(struct wlr_seat *wlr_seat); void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time, double sx, double sy); -/** - * Send relative motion events to the surface with pointer focus. Coordinates - * for the motion event are relative to current pointer location, both - * accelerated and unaccelerated. Compositors should use - * `wlr_seat_pointer_notify_relative_motion()` to send relative motion events - * to respect relative pointer requests by clients. - * - * Note that the timestamp is 64 bit, split into high 32 bits and low 32 bits. - */ -void wlr_seat_pointer_notify_relative_motion(struct wlr_seat *wlr_seat, - uint64_t time, double dx, double dy, - double dx_unaccel, double dy_unaccel); - /** * Send a button event to the surface with pointer focus. Coordinates for the * button event are surface-local. Returns the serial. Compositors should use diff --git a/rootston/cursor.c b/rootston/cursor.c index ba8d0860..16fb9c70 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -307,7 +307,6 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, static void notify_relative_motion(struct roots_seat *seat, uint64_t time_msec, double dx, double dy, double dx_unaccel, double dy_unaccel) { - struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = seat->input->server->desktop->relative_pointer_manager; @@ -316,26 +315,15 @@ static void notify_relative_motion(struct roots_seat *seat, uint64_t time_msec, return; } - struct wl_resource *resource; - wl_resource_for_each(resource, &relative_pointer_manager->relative_pointers) { - - struct wlr_relative_pointer_v1 *pointer = - wlr_relative_pointer_v1_from_resource(resource); - if (pointer == NULL || seat->seat != pointer->seat) { + struct wlr_relative_pointer_v1 *pointer; + wl_list_for_each(pointer, &relative_pointer_manager->relative_pointers, link) { + if (seat->seat != pointer->seat) { continue; } wlr_relative_pointer_v1_send_relative_motion(pointer, time_msec, dx, dy, dx_unaccel, dy_unaccel); } - - wl_resource_for_each(resource, &client->pointers) { - if (wlr_seat_client_from_pointer_resource(resource) == NULL) { - continue; - } - wl_pointer_send_frame(resource); - } - } void roots_cursor_handle_motion(struct roots_cursor *cursor, @@ -343,6 +331,7 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor, double dx = event->delta_x; double dy = event->delta_y; + /* TODO send unaccelerated values */ notify_relative_motion(cursor->seat, (uint64_t)event->time_msec * 1000, dx, dy, dx, dy); @@ -388,6 +377,7 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, double dx = lx - cursor->cursor->x; double dy = ly - cursor->cursor->y; + /* TODO send unaccelerated values */ notify_relative_motion(cursor->seat, (uint64_t)event->time_msec * 1000, dx, dy, dx, dy); diff --git a/types/seat/wlr_seat_pointer.c b/types/seat/wlr_seat_pointer.c index 936ac0dc..594a5b81 100644 --- a/types/seat/wlr_seat_pointer.c +++ b/types/seat/wlr_seat_pointer.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include "types/wlr_seat.h" #include "util/signal.h" diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index e5568f5f..6f686431 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -19,7 +19,7 @@ static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl; * helper functions */ -struct wlr_relative_pointer_v1 *relative_pointer_from_resource(struct wl_resource *resource) { +struct wlr_relative_pointer_v1 *wlr_relative_pointer_v1_from_resource(struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zwp_relative_pointer_v1_interface, &relative_pointer_v1_impl)); return wl_resource_get_user_data(resource); @@ -37,26 +37,42 @@ static struct wlr_relative_pointer_manager_v1 *relative_pointer_manager_from_res * relative_pointer handler functions */ -static void relative_pointer_v1_handle_resource_destroy(struct wl_resource *resource) { - struct wlr_relative_pointer_v1 *relative_pointer = - relative_pointer_from_resource(resource); +static void relative_pointer_destroy(struct wlr_relative_pointer_v1 *relative_pointer) { wlr_signal_emit_safe(&relative_pointer->events.destroy, relative_pointer); - wl_list_remove(wl_resource_get_link(resource)); + wl_list_remove(&relative_pointer->link); + wl_list_remove(&relative_pointer->seat_destroy.link); free(relative_pointer); } +static void relative_pointer_v1_handle_resource_destroy(struct wl_resource *resource) { + struct wlr_relative_pointer_v1 *relative_pointer = + wlr_relative_pointer_v1_from_resource(resource); + if (relative_pointer == NULL) { + return; + } + relative_pointer_destroy(relative_pointer); +} + static void relative_pointer_v1_handle_destroy(struct wl_client *client, struct wl_resource *resource) { struct wlr_relative_pointer_v1 *relative_pointer = - relative_pointer_from_resource(resource); + wlr_relative_pointer_v1_from_resource(resource); wlr_log(WLR_DEBUG, "relative_pointer_v1 %p released by client %p", relative_pointer, client); wl_resource_destroy(resource); } +static void relative_pointer_handle_seat_destroy(struct wl_listener *listener, + void *data) { + struct wlr_relative_pointer_v1 *relative_pointer = + wl_container_of(listener, relative_pointer, seat_destroy); + + relative_pointer_destroy(relative_pointer); + wl_resource_set_user_data(relative_pointer->resource, NULL); +} /** * relative_pointer_manager handler functions @@ -75,12 +91,10 @@ static void relative_pointer_manager_v1_handle_destroy(struct wl_client *client, client); } - static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *pointer) { struct wlr_seat_client *seat_client = wlr_seat_client_from_pointer_resource(pointer); - assert(seat_client->client == client); struct wlr_relative_pointer_v1 *relative_pointer = calloc(1, sizeof(struct wlr_relative_pointer_v1)); @@ -109,7 +123,11 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl relative_pointer_manager_from_resource(resource); wl_list_insert(&relative_pointer_manager->relative_pointers, - wl_resource_get_link(relative_pointer_resource)); + &relative_pointer->link); + + wl_signal_add(&relative_pointer->seat->events.destroy, + &relative_pointer->seat_destroy); + relative_pointer->seat_destroy.notify = relative_pointer_handle_seat_destroy; wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer, relative_pointer); @@ -141,9 +159,9 @@ static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void * } static void handle_display_destroy(struct wl_listener *listener, void *data) { - struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = - wl_container_of(listener, relative_pointer_manager, display_destroy_listener); - wlr_relative_pointer_manager_v1_destroy(relative_pointer_manager); + struct wlr_relative_pointer_manager_v1 *manager = + wl_container_of(listener, manager, display_destroy_listener); + wlr_relative_pointer_manager_v1_destroy(manager); } @@ -222,13 +240,22 @@ void wlr_relative_pointer_manager_v1_destroy(struct wlr_relative_pointer_manager void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time, double dx, double dy, double dx_unaccel, double dy_unaccel) { + struct wlr_seat_client *client = + relative_pointer->seat->pointer_state.focused_client; + + if (client == NULL) { + return; + } zwp_relative_pointer_v1_send_relative_motion(relative_pointer->resource, (uint32_t)(time >> 32), (uint32_t)time, wl_fixed_from_double(dx), wl_fixed_from_double(dy), wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel)); -} - -struct wlr_relative_pointer_v1 *wlr_relative_pointer_v1_from_resource(struct wl_resource *resource) { - return relative_pointer_from_resource(resource); + struct wl_resource *resource; + wl_resource_for_each(resource, &client->pointers) { + if (wlr_seat_client_from_pointer_resource(resource) == NULL) { + continue; + } + wl_pointer_send_frame(resource); + } } From e276d310e81c6bebf883ff3eeff5210d306b1c57 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Mon, 17 Dec 2018 14:24:07 -0600 Subject: [PATCH 14/19] Add unaccelerated pointer values to wlr_event_pointer_motion events --- backend/libinput/pointer.c | 2 ++ include/wlr/types/wlr_pointer.h | 1 + rootston/cursor.c | 7 ++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index fb85cddd..b9cf1dfe 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -36,6 +36,8 @@ void handle_pointer_motion(struct libinput_event *event, usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); wlr_event.delta_x = libinput_event_pointer_get_dx(pevent); wlr_event.delta_y = libinput_event_pointer_get_dy(pevent); + wlr_event.unaccel_dx = libinput_event_pointer_get_dx_unaccelerated(pevent); + wlr_event.unaccel_dy = libinput_event_pointer_get_dy_unaccelerated(pevent); wlr_signal_emit_safe(&wlr_dev->pointer->events.motion, &wlr_event); } diff --git a/include/wlr/types/wlr_pointer.h b/include/wlr/types/wlr_pointer.h index 7dc643ae..6da4c02a 100644 --- a/include/wlr/types/wlr_pointer.h +++ b/include/wlr/types/wlr_pointer.h @@ -32,6 +32,7 @@ struct wlr_event_pointer_motion { struct wlr_input_device *device; uint32_t time_msec; double delta_x, delta_y; + double unaccel_dx, unaccel_dy; }; struct wlr_event_pointer_motion_absolute { diff --git a/rootston/cursor.c b/rootston/cursor.c index 16fb9c70..ffb38816 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -331,9 +331,11 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor, double dx = event->delta_x; double dy = event->delta_y; - /* TODO send unaccelerated values */ + double unaccel_dx = event->unaccel_dx; + double unaccel_dy = event->unaccel_dy; + notify_relative_motion(cursor->seat, - (uint64_t)event->time_msec * 1000, dx, dy, dx, dy); + (uint64_t)event->time_msec * 1000, dx, dy, unaccel_dx, unaccel_dy); if (cursor->active_constraint) { struct roots_view *view = cursor->pointer_view->view; @@ -377,7 +379,6 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, double dx = lx - cursor->cursor->x; double dy = ly - cursor->cursor->y; - /* TODO send unaccelerated values */ notify_relative_motion(cursor->seat, (uint64_t)event->time_msec * 1000, dx, dy, dx, dy); From 12d9edc0c92c321a43331f23854e3de2e84a6aa0 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Mon, 17 Dec 2018 16:58:31 -0600 Subject: [PATCH 15/19] Address more of @emersion's comments --- include/wlr/types/wlr_relative_pointer_v1.h | 7 ++----- types/wlr_relative_pointer_v1.c | 20 ++++++-------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index 292be238..1bc85b05 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -31,11 +31,7 @@ struct wlr_relative_pointer_manager_v1 { struct { struct wl_signal destroy; - /** - * returns struct wlr_relative_pointer_v1 *relative_pointer - * called when a new relative_pointer is successfully created - */ - struct wl_signal new_relative_pointer; + struct wl_signal new_relative_pointer; //wlr_relative_pointer_v1 } events; struct wl_listener display_destroy_listener; @@ -53,6 +49,7 @@ struct wlr_relative_pointer_manager_v1 { struct wlr_relative_pointer_v1 { struct wl_resource *resource; + struct wl_resource *pointer; struct wlr_seat *seat; struct wl_list link; // wlr_relative_pointer_manager_v1::relative_pointers diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index 6f686431..9d12bd93 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -42,6 +42,8 @@ static void relative_pointer_destroy(struct wlr_relative_pointer_v1 *relative_po wl_list_remove(&relative_pointer->link); wl_list_remove(&relative_pointer->seat_destroy.link); + + wl_resource_set_user_data(relative_pointer->resource, NULL); free(relative_pointer); } @@ -71,7 +73,6 @@ static void relative_pointer_handle_seat_destroy(struct wl_listener *listener, wl_container_of(listener, relative_pointer, seat_destroy); relative_pointer_destroy(relative_pointer); - wl_resource_set_user_data(relative_pointer->resource, NULL); } /** @@ -113,6 +114,7 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl relative_pointer->resource = relative_pointer_resource; relative_pointer->seat = seat_client->seat; + relative_pointer->pointer = pointer; wl_signal_init(&relative_pointer->events.destroy); @@ -127,6 +129,8 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl wl_signal_add(&relative_pointer->seat->events.destroy, &relative_pointer->seat_destroy); + wl_resource_add_destroy_listener(relative_pointer->pointer, + &relative_pointer->seat_destroy); relative_pointer->seat_destroy.notify = relative_pointer_handle_seat_destroy; wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer, @@ -240,22 +244,10 @@ void wlr_relative_pointer_manager_v1_destroy(struct wlr_relative_pointer_manager void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time, double dx, double dy, double dx_unaccel, double dy_unaccel) { - struct wlr_seat_client *client = - relative_pointer->seat->pointer_state.focused_client; - - if (client == NULL) { - return; - } zwp_relative_pointer_v1_send_relative_motion(relative_pointer->resource, (uint32_t)(time >> 32), (uint32_t)time, wl_fixed_from_double(dx), wl_fixed_from_double(dy), wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel)); - struct wl_resource *resource; - wl_resource_for_each(resource, &client->pointers) { - if (wlr_seat_client_from_pointer_resource(resource) == NULL) { - continue; - } - wl_pointer_send_frame(resource); - } + wl_pointer_send_frame(relative_pointer->pointer); } From 5999d0322b63c4dd9f2cd902c2b798fc4df77116 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Wed, 19 Dec 2018 11:32:36 -0600 Subject: [PATCH 16/19] Add a listener for when the pointer gets destroyed --- include/wlr/types/wlr_relative_pointer_v1.h | 1 + types/wlr_relative_pointer_v1.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index 1bc85b05..cc4b2746 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -58,6 +58,7 @@ struct wlr_relative_pointer_v1 { } events; struct wl_listener seat_destroy; + struct wl_listener pointer_destroy; void *data; }; diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index 9d12bd93..4d3620bd 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -75,6 +75,14 @@ static void relative_pointer_handle_seat_destroy(struct wl_listener *listener, relative_pointer_destroy(relative_pointer); } +static void relative_pointer_handle_pointer_destroy(struct wl_listener *listener, + void *data) { + struct wlr_relative_pointer_v1 *relative_pointer = + wl_container_of(listener, relative_pointer, pointer_destroy); + + relative_pointer_destroy(relative_pointer); +} + /** * relative_pointer_manager handler functions */ @@ -129,10 +137,12 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl wl_signal_add(&relative_pointer->seat->events.destroy, &relative_pointer->seat_destroy); - wl_resource_add_destroy_listener(relative_pointer->pointer, - &relative_pointer->seat_destroy); relative_pointer->seat_destroy.notify = relative_pointer_handle_seat_destroy; + wl_resource_add_destroy_listener(relative_pointer->pointer, + &relative_pointer->pointer_destroy); + relative_pointer->pointer_destroy.notify = relative_pointer_handle_pointer_destroy; + wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer, relative_pointer); From b8460f448cb67fef63c04b9a1217701855f6e692 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Sun, 23 Dec 2018 06:50:39 -0600 Subject: [PATCH 17/19] Rename some variables for clarity --- types/wlr_relative_pointer_v1.c | 56 ++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/types/wlr_relative_pointer_v1.c b/types/wlr_relative_pointer_v1.c index 4d3620bd..a6e6e4b3 100644 --- a/types/wlr_relative_pointer_v1.c +++ b/types/wlr_relative_pointer_v1.c @@ -129,10 +129,10 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl wl_resource_set_implementation(relative_pointer_resource, &relative_pointer_v1_impl, relative_pointer, relative_pointer_v1_handle_resource_destroy); - struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = + struct wlr_relative_pointer_manager_v1 *manager = relative_pointer_manager_from_resource(resource); - wl_list_insert(&relative_pointer_manager->relative_pointers, + wl_list_insert(&manager->relative_pointers, &relative_pointer->link); wl_signal_add(&relative_pointer->seat->events.destroy, @@ -143,7 +143,7 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl &relative_pointer->pointer_destroy); relative_pointer->pointer_destroy.notify = relative_pointer_handle_pointer_destroy; - wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer, + wlr_signal_emit_safe(&manager->events.new_relative_pointer, relative_pointer); wlr_log(WLR_DEBUG, "relative_pointer_v1 %p created for client %p", @@ -153,7 +153,7 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { - struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = data; + struct wlr_relative_pointer_manager_v1 *manager = data; struct wl_resource *manager_resource = wl_resource_create(wl_client, &zwp_relative_pointer_manager_v1_interface, version, id); @@ -163,10 +163,10 @@ static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void * return; } - wl_list_insert(&relative_pointer_manager->resources, wl_resource_get_link(manager_resource)); + wl_list_insert(&manager->resources, wl_resource_get_link(manager_resource)); wl_resource_set_implementation(manager_resource, &relative_pointer_manager_v1_impl, - relative_pointer_manager, relative_pointer_manager_v1_handle_resource_destroy); + manager, relative_pointer_manager_v1_handle_resource_destroy); wlr_log(WLR_DEBUG, "relative_pointer_v1 manager bound to client %p", wl_client); @@ -199,63 +199,63 @@ static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl = */ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_manager_v1_create(struct wl_display *display) { - struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = + struct wlr_relative_pointer_manager_v1 *manager = calloc(1, sizeof(struct wlr_relative_pointer_manager_v1)); - if (relative_pointer_manager == NULL) { + if (manager == NULL) { return NULL; } - wl_list_init(&relative_pointer_manager->resources); - wl_list_init(&relative_pointer_manager->relative_pointers); + wl_list_init(&manager->resources); + wl_list_init(&manager->relative_pointers); - relative_pointer_manager->global = wl_global_create(display, + manager->global = wl_global_create(display, &zwp_relative_pointer_manager_v1_interface, RELATIVE_POINTER_MANAGER_VERSION, - relative_pointer_manager, relative_pointer_manager_v1_bind); + manager, relative_pointer_manager_v1_bind); - if (relative_pointer_manager->global == NULL) { - free(relative_pointer_manager); + if (manager->global == NULL) { + free(manager); return NULL; } - wl_signal_init(&relative_pointer_manager->events.destroy); - wl_signal_init(&relative_pointer_manager->events.new_relative_pointer); + wl_signal_init(&manager->events.destroy); + wl_signal_init(&manager->events.new_relative_pointer); - relative_pointer_manager->display_destroy_listener.notify = handle_display_destroy; - wl_display_add_destroy_listener(display, &relative_pointer_manager->display_destroy_listener); + manager->display_destroy_listener.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &manager->display_destroy_listener); wlr_log(WLR_DEBUG, "relative_pointer_v1 manager created"); - return relative_pointer_manager; + return manager; } -void wlr_relative_pointer_manager_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager) { - if (relative_pointer_manager == NULL) { +void wlr_relative_pointer_manager_v1_destroy(struct wlr_relative_pointer_manager_v1 *manager) { + if (manager == NULL) { return; } - wlr_signal_emit_safe(&relative_pointer_manager->events.destroy, relative_pointer_manager); - wl_list_remove(&relative_pointer_manager->display_destroy_listener.link); + wlr_signal_emit_safe(&manager->events.destroy, manager); + wl_list_remove(&manager->display_destroy_listener.link); struct wl_resource *resource; struct wl_resource *tmp_resource; - wl_resource_for_each_safe(resource, tmp_resource, &relative_pointer_manager->resources) { + wl_resource_for_each_safe(resource, tmp_resource, &manager->resources) { wl_resource_destroy(resource); } - wl_global_destroy(relative_pointer_manager->global); - free(relative_pointer_manager); + wl_global_destroy(manager->global); + free(manager); wlr_log(WLR_DEBUG, "relative_pointer_v1 manager destroyed"); } void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1 *relative_pointer, - uint64_t time, double dx, double dy, + uint64_t time_msec, double dx, double dy, double dx_unaccel, double dy_unaccel) { zwp_relative_pointer_v1_send_relative_motion(relative_pointer->resource, - (uint32_t)(time >> 32), (uint32_t)time, + (uint32_t)(time_msec >> 32), (uint32_t)time_msec, wl_fixed_from_double(dx), wl_fixed_from_double(dy), wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel)); From 8b97c20d01a869497d5e0545319597b3b57e79c2 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Wed, 2 Jan 2019 11:46:13 -0600 Subject: [PATCH 18/19] Finish addressing @emersion's comments --- include/wlr/types/wlr_relative_pointer_v1.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/wlr/types/wlr_relative_pointer_v1.h b/include/wlr/types/wlr_relative_pointer_v1.h index cc4b2746..f9f91219 100644 --- a/include/wlr/types/wlr_relative_pointer_v1.h +++ b/include/wlr/types/wlr_relative_pointer_v1.h @@ -27,7 +27,7 @@ struct wlr_relative_pointer_manager_v1 { struct wl_global *global; struct wl_list resources; // wl_resource_get_link() - struct wl_list relative_pointers; + struct wl_list relative_pointers; // wlr_relative_pointer_v1::link struct { struct wl_signal destroy; @@ -68,6 +68,9 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_manager_v1_create( void wlr_relative_pointer_manager_v1_destroy( struct wlr_relative_pointer_manager_v1 *relative_pointer_manager); +/** + * Send a relative motion event to the seat with the same wl_pointer as relative_pointer + */ void wlr_relative_pointer_v1_send_relative_motion( struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time_msec, double dx, double dy, double dx_unaccel, double dy_unaccel); From 78caed0c99f64e6192778ea90371848323f72379 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Wed, 2 Jan 2019 13:06:37 -0600 Subject: [PATCH 19/19] Only send relative events to the focused client in rootston --- rootston/cursor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rootston/cursor.c b/rootston/cursor.c index ffb38816..1fdf1dbb 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -317,12 +317,15 @@ static void notify_relative_motion(struct roots_seat *seat, uint64_t time_msec, struct wlr_relative_pointer_v1 *pointer; wl_list_for_each(pointer, &relative_pointer_manager->relative_pointers, link) { - if (seat->seat != pointer->seat) { - continue; + struct wlr_seat_client *relative_pointer_client = + wlr_seat_client_from_pointer_resource(pointer->pointer); + + if (seat->seat == pointer->seat && + client == relative_pointer_client) { + wlr_relative_pointer_v1_send_relative_motion(pointer, + time_msec, dx, dy, dx_unaccel, dy_unaccel); } - wlr_relative_pointer_v1_send_relative_motion(pointer, time_msec, - dx, dy, dx_unaccel, dy_unaccel); } }