From 3a3d1b661714a7d37b8a4450fe0c3dec50027622 Mon Sep 17 00:00:00 2001 From: random human Date: Fri, 28 Sep 2018 04:43:52 +0530 Subject: relative_pointer: create skeleton and build Add protocol, header and type files to build. Create skeleton structs, creator and destroyer, and define implementations. --- rootston/desktop.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'rootston') 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; } -- cgit v1.2.3 From d0203446751f2b8b4e80ecf54b6ff831096c3302 Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 1 Oct 2018 06:21:32 +0530 Subject: 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(+) (limited to 'rootston') 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)); +} -- cgit v1.2.3 From 6fa1777f94b2743747d00433c98a2251e0ef12ee Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 1 Oct 2018 20:33:21 +0530 Subject: 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(-) (limited to 'rootston') 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)); } -- cgit v1.2.3 From 68137dca3f0b20c5610a30e4c3820984b387dda5 Mon Sep 17 00:00:00 2001 From: random human Date: Thu, 4 Oct 2018 00:43:35 +0530 Subject: 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(-) (limited to 'rootston') 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); +} -- cgit v1.2.3 From 09bdbf24f4fc44cfbb9bd6079a1d7cd08edaefdb Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Thu, 13 Dec 2018 23:41:21 -0600 Subject: 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(-) (limited to 'rootston') 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, -- cgit v1.2.3 From d0c940d796418672a2421afe108e01b23b0452c4 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Fri, 14 Dec 2018 09:34:09 -0600 Subject: Only send relative motion to correct seat --- rootston/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rootston') 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; } -- cgit v1.2.3 From f5ea393bca7a427c0d97217c67b0be563b28dc19 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Fri, 14 Dec 2018 09:42:24 -0600 Subject: 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(-) (limited to 'rootston') 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); -- cgit v1.2.3 From a803a007fb9c572e0eccc22ab670ac711cb89b13 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Mon, 17 Dec 2018 14:04:49 -0600 Subject: 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(-) (limited to 'rootston') 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); + } } -- cgit v1.2.3 From e276d310e81c6bebf883ff3eeff5210d306b1c57 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Mon, 17 Dec 2018 14:24:07 -0600 Subject: 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(-) (limited to 'rootston') 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); -- cgit v1.2.3 From 78caed0c99f64e6192778ea90371848323f72379 Mon Sep 17 00:00:00 2001 From: Alex Maese Date: Wed, 2 Jan 2019 13:06:37 -0600 Subject: Only send relative events to the focused client in rootston --- rootston/cursor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'rootston') 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); } } -- cgit v1.2.3