diff options
author | random human <random.bored.human@gmail.com> | 2018-10-01 03:54:21 +0530 |
---|---|---|
committer | Alex Maese <memaese@hotmail.com> | 2018-12-21 12:20:48 -0600 |
commit | ba5b1676dfb0041c88e4966a6c32dee5a5a6513a (patch) | |
tree | adaa30aec4f6514299d077b8ad0da3abdd8ad307 | |
parent | 3a3d1b661714a7d37b8a4450fe0c3dec50027622 (diff) |
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).
-rw-r--r-- | include/wlr/types/wlr_relative_pointer_v1.h | 30 | ||||
-rw-r--r-- | include/wlr/types/wlr_seat.h | 1 | ||||
-rw-r--r-- | types/seat/wlr_seat.c | 4 | ||||
-rw-r--r-- | 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 <stdlib.h> +#include <assert.h> +#include <inttypes.h> #include <wlr/util/log.h> #include <util/signal.h> #include <wlr/types/wlr_relative_pointer_v1.h> +#include <wlr/types/wlr_seat.h> #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"); } |