From 812675ba34ce612e9294e8a9814b1baf4b4775d4 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Sun, 12 May 2024 11:53:09 +0300 Subject: [PATCH] fixes: add implementation --- include/wlr/types/wlr_fixes.h | 28 +++++++++++++++ meson.build | 2 +- types/meson.build | 11 +++--- types/wlr_fixes.c | 65 +++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 6 deletions(-) create mode 100644 include/wlr/types/wlr_fixes.h create mode 100644 types/wlr_fixes.c diff --git a/include/wlr/types/wlr_fixes.h b/include/wlr/types/wlr_fixes.h new file mode 100644 index 000000000..b227f7e28 --- /dev/null +++ b/include/wlr/types/wlr_fixes.h @@ -0,0 +1,28 @@ +/* + * 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_FIXES_H +#define WLR_TYPES_WLR_FIXES_H + +#include + +struct wlr_fixes { + struct wl_global *global; + + struct { + struct wl_signal destroy; + } events; + + struct { + struct wl_listener display_destroy; + } WLR_PRIVATE; +}; + +struct wlr_fixes *wlr_fixes_create(struct wl_display *display, uint32_t version); + +#endif diff --git a/meson.build b/meson.build index 8319eff69..4b24e5046 100644 --- a/meson.build +++ b/meson.build @@ -86,7 +86,7 @@ internal_features = { internal_config = configuration_data() wayland_kwargs = { - 'version': '>=1.23.1', + 'version': '>=1.24.0', 'fallback': 'wayland', 'default_options': [ 'tests=false', diff --git a/types/meson.build b/types/meson.build index 25a0d4434..402fd3e11 100644 --- a/types/meson.build +++ b/types/meson.build @@ -39,19 +39,20 @@ wlr_files += files( 'buffer/resource.c', 'wlr_alpha_modifier_v1.c', 'wlr_color_management_v1.c', + 'wlr_color_representation_v1.c', 'wlr_compositor.c', 'wlr_content_type_v1.c', - 'wlr_cursor_shape_v1.c', 'wlr_cursor.c', + 'wlr_cursor_shape_v1.c', 'wlr_damage_ring.c', 'wlr_data_control_v1.c', 'wlr_drm.c', 'wlr_export_dmabuf_v1.c', - 'wlr_foreign_toplevel_management_v1.c', - 'wlr_color_representation_v1.c', - 'wlr_ext_image_copy_capture_v1.c', - 'wlr_ext_foreign_toplevel_list_v1.c', 'wlr_ext_data_control_v1.c', + 'wlr_ext_foreign_toplevel_list_v1.c', + 'wlr_ext_image_copy_capture_v1.c', + 'wlr_fixes.c', + 'wlr_foreign_toplevel_management_v1.c', 'wlr_fractional_scale_v1.c', 'wlr_gamma_control_v1.c', 'wlr_idle_inhibit_v1.c', diff --git a/types/wlr_fixes.c b/types/wlr_fixes.c new file mode 100644 index 000000000..b5435aaf8 --- /dev/null +++ b/types/wlr_fixes.c @@ -0,0 +1,65 @@ +#include +#include +#include + +#include + +#define FIXES_VERSION 1 + +static void fixes_destroy(struct wl_client *client, struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static void fixes_destroy_registry(struct wl_client *client, struct wl_resource *resource, + struct wl_resource *registry) { + wl_resource_destroy(registry); +} + +static const struct wl_fixes_interface fixes_impl = { + .destroy = fixes_destroy, + .destroy_registry = fixes_destroy_registry, +}; + +static void fixes_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { + struct wlr_fixes *fixes = data; + + struct wl_resource *resource = wl_resource_create(wl_client, &wl_fixes_interface, version, id); + if (resource == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + wl_resource_set_implementation(resource, &fixes_impl, fixes, NULL); +} + +static void fixes_handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_fixes *fixes = wl_container_of(listener, fixes, display_destroy); + wl_signal_emit_mutable(&fixes->events.destroy, NULL); + + assert(wl_list_empty(&fixes->events.destroy.listener_list)); + + wl_list_remove(&fixes->display_destroy.link); + wl_global_destroy(fixes->global); + free(fixes); +} + +struct wlr_fixes *wlr_fixes_create(struct wl_display *display, uint32_t version) { + assert(version <= FIXES_VERSION); + + struct wlr_fixes *fixes = calloc(1, sizeof(*fixes)); + if (fixes == NULL) { + return NULL; + } + + fixes->global = wl_global_create(display, &wl_fixes_interface, version, fixes, fixes_bind); + if (fixes->global == NULL) { + free(fixes); + return NULL; + } + + wl_signal_init(&fixes->events.destroy); + + fixes->display_destroy.notify = fixes_handle_display_destroy; + wl_display_add_destroy_listener(display, &fixes->display_destroy); + + return fixes; +}