diff options
author | Andri Yngvason <andri@yngvason.is> | 2020-02-08 15:52:59 +0000 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2024-01-31 08:22:05 +0000 |
commit | 3a91dc1b483fbcb480c69b4dd2af1073cf69b52f (patch) | |
tree | f55e2f09d0e7215dd0d85a495508a153de6299bd | |
parent | 435ca39960f47d622017630b28788f4dd14be757 (diff) |
Create & implement transient seat protocol
-rw-r--r-- | include/wlr/types/wlr_transient_seat_v1.h | 63 | ||||
-rw-r--r-- | protocol/meson.build | 1 | ||||
-rw-r--r-- | types/meson.build | 1 | ||||
-rw-r--r-- | types/wlr_transient_seat_v1.c | 160 |
4 files changed, 225 insertions, 0 deletions
diff --git a/include/wlr/types/wlr_transient_seat_v1.h b/include/wlr/types/wlr_transient_seat_v1.h new file mode 100644 index 00000000..84d419bc --- /dev/null +++ b/include/wlr/types/wlr_transient_seat_v1.h @@ -0,0 +1,63 @@ +/* + * 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_TRANSIENT_SEAT_V1_H +#define WLR_TYPES_WLR_TRANSIENT_SEAT_V1_H + +#include <wayland-server-core.h> + +struct wlr_seat; + +struct wlr_transient_seat_v1 { + struct wl_resource *resource; + struct wlr_seat *seat; + + // private state + struct wl_listener seat_destroy; +}; + +struct wlr_transient_seat_manager_v1 { + struct wl_global *global; + struct wl_listener display_destroy; + + struct { + /** + * Upon receiving this signal, call + * wlr_transient_seat_v1_ready() to pass a newly created seat + * to the manager, or + * wlr_transient_seat_v1_deny() to deny the request to create + * a seat. + */ + struct wl_signal create_seat; // struct wlr_transient_seat_v1 + } events; +}; + +struct wlr_transient_seat_manager_v1 *wlr_transient_seat_manager_v1_create( + struct wl_display *display); + +/** + * To be called when the create_seat event is received. + * + * This signals that the seat was successfully added and is ready. + * + * When the transient seat is destroyed by the client, the wlr_seat will be + * destroyed. The wlr_seat may also be destroyed from elsewhere, in which case + * the transient seat will become inert. + */ +void wlr_transient_seat_v1_ready(struct wlr_transient_seat_v1 *seat, + struct wlr_seat *wlr_seat); + +/** + * To be called when the create_seat event is received. + * + * This signals that the compositor has denied the user's request to create a + * transient seat. + */ +void wlr_transient_seat_v1_deny(struct wlr_transient_seat_v1 *seat); + +#endif /* WLR_TYPES_WLR_TRANSIENT_SEAT_V1_H */ diff --git a/protocol/meson.build b/protocol/meson.build index b2971591..d8e93d62 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -45,6 +45,7 @@ protocols = { 'xdg-foreign-unstable-v1': wl_protocol_dir / 'unstable/xdg-foreign/xdg-foreign-unstable-v1.xml', 'xdg-foreign-unstable-v2': wl_protocol_dir / 'unstable/xdg-foreign/xdg-foreign-unstable-v2.xml', 'xdg-output-unstable-v1': wl_protocol_dir / 'unstable/xdg-output/xdg-output-unstable-v1.xml', + 'ext-transient-seat-v1': wl_protocol_dir / 'staging/ext-transient-seat/ext-transient-seat-v1.xml', # Other protocols 'drm': 'drm.xml', diff --git a/types/meson.build b/types/meson.build index 8ae21b56..688ddece 100644 --- a/types/meson.build +++ b/types/meson.build @@ -79,6 +79,7 @@ wlr_files += files( 'wlr_tablet_tool.c', 'wlr_text_input_v3.c', 'wlr_touch.c', + 'wlr_transient_seat_v1.c', 'wlr_viewporter.c', 'wlr_virtual_keyboard_v1.c', 'wlr_virtual_pointer_v1.c', diff --git a/types/wlr_transient_seat_v1.c b/types/wlr_transient_seat_v1.c new file mode 100644 index 00000000..379ce0a3 --- /dev/null +++ b/types/wlr_transient_seat_v1.c @@ -0,0 +1,160 @@ +#include <assert.h> +#include <stdlib.h> +#include <wayland-util.h> +#include <wlr/types/wlr_seat.h> +#include <wlr/types/wlr_transient_seat_v1.h> +#include "ext-transient-seat-v1-protocol.h" + +static const struct ext_transient_seat_manager_v1_interface manager_impl; +static const struct ext_transient_seat_v1_interface transient_seat_impl; + +static struct wlr_transient_seat_manager_v1 *manager_from_resource( + struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, + &ext_transient_seat_manager_v1_interface, &manager_impl)); + return wl_resource_get_user_data(resource); +} + +static struct wlr_transient_seat_v1 *transient_seat_from_resource( + struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, + &ext_transient_seat_v1_interface, &transient_seat_impl)); + return wl_resource_get_user_data(resource); +} + +static void transient_seat_destroy(struct wlr_transient_seat_v1 *seat) { + wl_list_remove(&seat->seat_destroy.link); + wlr_seat_destroy(seat->seat); + free(seat); +} + +static void transient_seat_handle_resource_destroy( + struct wl_resource *resource) { + struct wlr_transient_seat_v1 *seat = + transient_seat_from_resource(resource); + transient_seat_destroy(seat); +} + +static void transient_seat_handle_destroy(struct wl_client *client, + struct wl_resource *seat_resource) { + wl_resource_destroy(seat_resource); +} + +static const struct ext_transient_seat_v1_interface transient_seat_impl = { + .destroy = transient_seat_handle_destroy, +}; + +static void manager_create_transient_seat(struct wl_client *client, + struct wl_resource *manager_resource, uint32_t id) { + struct wlr_transient_seat_manager_v1 *manager = + manager_from_resource(manager_resource); + + struct wlr_transient_seat_v1 *seat = calloc(1, sizeof(*seat)); + if (!seat) { + goto failure; + } + + int version = wl_resource_get_version(manager_resource); + seat->resource = wl_resource_create(client, + &ext_transient_seat_v1_interface, version, id); + if (!seat->resource) { + goto failure; + } + + wl_resource_set_implementation(seat->resource, &transient_seat_impl, + seat, transient_seat_handle_resource_destroy); + + wl_signal_emit_mutable(&manager->events.create_seat, seat); + + return; + +failure: + free(seat); + wl_client_post_no_memory(client); +} + +static void transient_seat_handle_seat_destroy(struct wl_listener *listener, + void *data) { + struct wlr_transient_seat_v1 *seat = wl_container_of(listener, seat, + seat_destroy); + seat->seat = NULL; + wl_resource_set_user_data(seat->resource, NULL); + transient_seat_destroy(seat); +} + +void wlr_transient_seat_v1_ready(struct wlr_transient_seat_v1 *seat, + struct wlr_seat *wlr_seat) { + assert(wlr_seat); + + seat->seat = wlr_seat; + + seat->seat_destroy.notify = transient_seat_handle_seat_destroy; + wl_signal_add(&wlr_seat->events.destroy, &seat->seat_destroy); + + struct wl_client *client = wl_resource_get_client(seat->resource); + uint32_t global_name = wl_global_get_name(seat->seat->global, client); + assert(global_name != 0); + ext_transient_seat_v1_send_ready(seat->resource, global_name); +} + +void wlr_transient_seat_v1_deny(struct wlr_transient_seat_v1 *seat) { + ext_transient_seat_v1_send_denied(seat->resource); +} + +static void manager_handle_destroy(struct wl_client *client, + struct wl_resource *manager_resource) { + wl_resource_destroy(manager_resource); +} + +static const struct ext_transient_seat_manager_v1_interface manager_impl = { + .create = manager_create_transient_seat, + .destroy = manager_handle_destroy, +}; + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_transient_seat_manager_v1 *manager = + wl_container_of(listener, manager, display_destroy); + + wl_list_remove(&manager->display_destroy.link); + wl_global_destroy(manager->global); + free(manager); +} + +static void transient_seat_manager_bind(struct wl_client *client, void *data, + uint32_t version, uint32_t id) { + struct wlr_transient_seat_manager_v1 *manager = data; + + struct wl_resource *resource = wl_resource_create(client, + &ext_transient_seat_manager_v1_interface, version, id); + + if (!resource) { + wl_client_post_no_memory(client); + return; + } + + wl_resource_set_implementation(resource, &manager_impl, manager, NULL); +} + +struct wlr_transient_seat_manager_v1 *wlr_transient_seat_manager_v1_create( + struct wl_display *display) { + struct wlr_transient_seat_manager_v1 *manager = + calloc(1, sizeof(*manager)); + if (!manager) { + return NULL; + } + + manager->global = wl_global_create(display, + &ext_transient_seat_manager_v1_interface, 1, manager, + transient_seat_manager_bind); + if (!manager->global) { + free(manager); + return NULL; + } + + manager->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &manager->display_destroy); + + wl_signal_init(&manager->events.create_seat); + + return manager; +} |