From 6c6f116885fd0f7bab424ce05f9e5c5f1761cfd6 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 26 Feb 2026 14:51:02 -0800 Subject: [PATCH] [digesting_libdecor] eliminate the allocation and pass-through of the plugin completely --- digesting_libdecor.c | 177 +++++++++++++------------------------------ digesting_libdecor.h | 29 ++++--- 2 files changed, 65 insertions(+), 141 deletions(-) diff --git a/digesting_libdecor.c b/digesting_libdecor.c index cdcc309..71e9ff8 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -117,7 +117,7 @@ wlevent__wl_registry_global(void *data, struct wl_registry *wl_registry, else if (strcmp(interface, "wl_shm") == 0){ ctx.wl_shm = wl_registry_bind(ctx.wl_registry, name, &wl_shm_interface, 1); - wl_shm_add_listener(ctx.wl_shm, &shm_listener, ctx.plugin_gtk); + wl_shm_add_listener(ctx.wl_shm, &shm_listener, 0); } else if (strcmp(interface, "wl_seat") == 0){ struct seat *seat; @@ -128,7 +128,6 @@ wlevent__wl_registry_global(void *data, struct wl_registry *wl_registry, seat = calloc(1, sizeof *seat); seat->cursor_scale = 1; - seat->plugin_gtk = ctx.plugin_gtk; wl_list_init(&seat->cursor_outputs); wl_list_insert(&ctx.seat_list, &seat->link); seat->wl_seat = wl_registry_bind(ctx.wl_registry, name, &wl_seat_interface, 3); @@ -142,7 +141,6 @@ wlevent__wl_registry_global(void *data, struct wl_registry *wl_registry, } output = calloc(1, sizeof *output); - output->plugin_gtk = ctx.plugin_gtk; wl_list_insert(&ctx.output_list, &output->link); output->id = name; output->wl_output = wl_registry_bind(ctx.wl_registry, name, &wl_output_interface, MIN(version, 3)); @@ -324,9 +322,6 @@ int main(){ */ { - ctx.plugin_gtk = calloc(1, sizeof *ctx.plugin_gtk); - libdecor_plugin_init(&ctx.plugin_gtk->plugin, >k_plugin_iface); - wl_list_init(&ctx.frames); wl_list_init(&ctx.visible_frame_list); @@ -373,18 +368,13 @@ int main(){ 0); wl_display_roundtrip(ctx.wl_display); - ctx.plugin = &ctx.plugin_gtk->plugin; - - if (ctx.plugin == 0){ - fprintf(stderr, "Failed to load static plugin: failed to init\n"); - exit(1); - } - wl_display_flush(ctx.wl_display); } int opengl_load_success = 0; - if (ctx.plugin != 0){ + if (ctx.wl_compositor != 0 && + ctx.wl_subcompositor != 0 && + ctx.wl_shm != 0){ /* (egl) eglGetDisplay ** " obtains the EGL display connection for the native display " */ @@ -772,17 +762,16 @@ frame_get_window_size_for(struct libdecor_frame *frame, int *window_height) { struct libdecor_frame_private *frame_priv = frame->priv; - struct libdecor_plugin *plugin = ctx.plugin; *window_width = state->content_width; *window_height = state->content_height; - if (frame_has_visible_client_side_decoration(frame) && - plugin->priv->iface->frame_get_border_size) { + if (frame_has_visible_client_side_decoration(frame)) { int left, right, top, bottom; - if (!plugin->priv->iface->frame_get_border_size( - plugin, frame, NULL, &left, &right, &top, &bottom)) + if (!libdecor_plugin_gtk_frame_get_border_size(0, frame, NULL, + &left, &right, &top, &bottom)){ return false; + } *window_width += left + right; *window_height += top + bottom; } @@ -794,15 +783,12 @@ static void frame_set_window_geometry(struct libdecor_frame *frame, int32_t content_width, int32_t content_height) { - struct libdecor_plugin *plugin = ctx.plugin; int x, y, width, height; int left, right, top, bottom; if (frame_has_visible_client_side_decoration(frame) && - plugin->priv->iface->frame_get_border_size(plugin, frame, - NULL, - &left, &right, - &top, &bottom)) { + libdecor_plugin_gtk_frame_get_border_size(0, frame, NULL, + &left, &right, &top, &bottom)) { x = -left; y = -top; width = content_width + left + right; @@ -823,8 +809,6 @@ libdecor_configuration_get_content_size(struct libdecor_configuration *configura int *width, int *height) { - struct libdecor_plugin *plugin = ctx.plugin; - /* get configured toplevel dimensions */ if (!configuration->has_size) return false; @@ -836,15 +820,14 @@ libdecor_configuration_get_content_size(struct libdecor_configuration *configura *height = configuration->window_height; /* remove plugin-specific border size */ - if (frame_has_visible_client_side_decoration(frame) && - plugin->priv->iface->frame_get_border_size) { + if (frame_has_visible_client_side_decoration(frame)) { int left, right, top, bottom; /* Update window state for correct border size calculation */ frame->priv->window_state = configuration->window_state; - if (!plugin->priv->iface->frame_get_border_size( - plugin, frame, configuration, &left, &right, &top, &bottom)) + if (!libdecor_plugin_gtk_frame_get_border_size(0, frame, configuration, &left, &right, &top, &bottom)){ return false; + } *width -= (left + right); *height -= (top + bottom); @@ -998,13 +981,11 @@ xdg_toplevel_configure_bounds(void *user_data, { struct libdecor_frame *frame = user_data; struct libdecor_frame_private *frame_priv = frame->priv; - struct libdecor_plugin *plugin = ctx.plugin; int left = 0, top = 0, right = 0, bottom = 0; - if (frame_has_visible_client_side_decoration(frame) && - plugin->priv->iface->frame_get_border_size) { - plugin->priv->iface->frame_get_border_size(plugin, frame, NULL, - &left, &right, &top, &bottom); + if (frame_has_visible_client_side_decoration(frame)) { + libdecor_plugin_gtk_frame_get_border_size(0, frame, NULL, + &left, &right, &top, &bottom); } width -= left + right; @@ -1136,16 +1117,17 @@ init_shell_surface(struct libdecor_frame *frame) struct libdecor_frame * libdecor_decorate(struct wl_surface *wl_surface, void *user_data){ - struct libdecor_plugin *plugin = ctx.plugin; struct libdecor_frame *frame; struct libdecor_frame_private *frame_priv; - if (ctx.has_error) + if (ctx.has_error){ return NULL; + } - frame = plugin->priv->iface->frame_new(plugin); - if (!frame) + frame = libdecor_plugin_gtk_frame_new(0); + if (!frame){ return NULL; + } frame_priv = calloc(1, sizeof *frame_priv); frame->priv = frame_priv; @@ -1191,8 +1173,6 @@ libdecor_frame_unref(struct libdecor_frame *frame) frame_priv->ref_count--; if (frame_priv->ref_count == 0) { - struct libdecor_plugin *plugin = ctx.plugin; - if (ctx.decoration_manager && frame_priv->toplevel_decoration) { zxdg_toplevel_decoration_v1_destroy(frame_priv->toplevel_decoration); frame_priv->toplevel_decoration = NULL; @@ -1205,7 +1185,7 @@ libdecor_frame_unref(struct libdecor_frame *frame) if (frame_priv->xdg_surface) xdg_surface_destroy(frame_priv->xdg_surface); - plugin->priv->iface->frame_free(plugin, frame); + libdecor_plugin_gtk_frame_free(0, frame); free(frame_priv->state.title); free(frame_priv->state.app_id); @@ -1233,7 +1213,6 @@ libdecor_frame_set_visibility(struct libdecor_frame *frame, bool visible) { struct libdecor_frame_private *frame_priv = frame->priv; - struct libdecor_plugin *plugin = ctx.plugin; frame_priv->visible = visible; @@ -1261,10 +1240,10 @@ libdecor_frame_set_visibility(struct libdecor_frame *frame, /* enable/disable decorations that are managed by a plugin */ if (frame_has_visible_client_side_decoration(frame)) { /* show client-side decorations */ - plugin->priv->iface->frame_commit(plugin, frame, NULL, NULL); + libdecor_plugin_gtk_frame_commit(0, frame, NULL, NULL); } else { /* destroy client-side decorations */ - plugin->priv->iface->frame_free(plugin, frame); + libdecor_plugin_gtk_frame_free(0, frame); } frame_set_window_geometry(frame, @@ -1300,18 +1279,18 @@ libdecor_frame_set_title(struct libdecor_frame *frame, const char *title) { struct libdecor_frame_private *frame_priv = frame->priv; - struct libdecor_plugin *plugin = ctx.plugin; if (!streql(frame_priv->state.title, title)) { free(frame_priv->state.title); frame_priv->state.title = strdup(title); - if (!frame_priv->xdg_toplevel) + if (!frame_priv->xdg_toplevel){ return; + } xdg_toplevel_set_title(frame_priv->xdg_toplevel, title); - plugin->priv->iface->frame_property_changed(plugin, frame); + libdecor_plugin_gtk_frame_property_changed(0, frame); } } @@ -1340,7 +1319,6 @@ static void notify_on_capability_change(struct libdecor_frame *frame, const enum libdecor_capabilities old_capabilities) { - struct libdecor_plugin *plugin = ctx.plugin; struct libdecor_state *state; if (frame->priv->capabilities == old_capabilities) @@ -1350,7 +1328,7 @@ notify_on_capability_change(struct libdecor_frame *frame, frame->priv->content_height == 0) return; - plugin->priv->iface->frame_property_changed(plugin, frame); + libdecor_plugin_gtk_frame_property_changed(0, frame); if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) { frame->priv->interactive_limits = frame->priv->state.content_limits; @@ -1399,30 +1377,20 @@ libdecor_frame_unset_capabilities(struct libdecor_frame *frame, } bool -libdecor_frame_has_capability(struct libdecor_frame *frame, - enum libdecor_capabilities capability) -{ +libdecor_frame_has_capability(struct libdecor_frame *frame, enum libdecor_capabilities capability){ return frame->priv->capabilities & capability; } void -libdecor_frame_popup_grab(struct libdecor_frame *frame, - const char *seat_name) -{ +libdecor_frame_popup_grab(struct libdecor_frame *frame, const char *seat_name){ struct libdecor_frame_private *frame_priv = frame->priv; - struct libdecor_plugin *plugin = ctx.plugin; - - plugin->priv->iface->frame_popup_grab(plugin, frame, seat_name); + libdecor_plugin_gtk_frame_popup_grab(0, frame, seat_name); } void -libdecor_frame_popup_ungrab(struct libdecor_frame *frame, - const char *seat_name) -{ +libdecor_frame_popup_ungrab(struct libdecor_frame *frame, const char *seat_name){ struct libdecor_frame_private *frame_priv = frame->priv; - struct libdecor_plugin *plugin = ctx.plugin; - - plugin->priv->iface->frame_popup_ungrab(plugin, frame, seat_name); + libdecor_plugin_gtk_frame_popup_ungrab(0, frame, seat_name); } void @@ -1461,16 +1429,14 @@ libdecor_frame_translate_coordinate(struct libdecor_frame *frame, int *frame_y) { struct libdecor_frame_private *frame_priv = frame->priv; - struct libdecor_plugin *plugin = ctx.plugin; *frame_x = content_x; *frame_y = content_y; - if (frame_has_visible_client_side_decoration(frame) && - plugin->priv->iface->frame_get_border_size) { + if (frame_has_visible_client_side_decoration(frame)){ int left, top; - plugin->priv->iface->frame_get_border_size(plugin, frame, NULL, - &left, NULL, &top, NULL); + libdecor_plugin_gtk_frame_get_border_size(0, frame, NULL, + &left, NULL, &top, NULL); *frame_x += left; *frame_y += top; } @@ -1729,7 +1695,6 @@ libdecor_frame_commit(struct libdecor_frame *frame, struct libdecor_configuration *configuration) { struct libdecor_frame_private *frame_priv = frame->priv; - struct libdecor_plugin *plugin = ctx.plugin; if (configuration && configuration->has_window_state) { frame_priv->window_state = configuration->window_state; @@ -1742,10 +1707,10 @@ libdecor_frame_commit(struct libdecor_frame *frame, /* switch between decoration modes */ if (frame_has_visible_client_side_decoration(frame)) { - plugin->priv->iface->frame_commit(plugin, frame, state, - configuration); + libdecor_plugin_gtk_frame_commit(0, frame, state, + configuration); } else { - plugin->priv->iface->frame_free(plugin, frame); + libdecor_plugin_gtk_frame_free(0, frame); } frame_set_window_geometry(frame, @@ -1834,25 +1799,6 @@ libdecor_frame_get_wm_capabilities(struct libdecor_frame *frame) return frame_priv->wm_capabilities; } -int -libdecor_plugin_init(struct libdecor_plugin *plugin, - struct libdecor_plugin_interface *iface) -{ - plugin->priv = calloc(1, sizeof (struct libdecor_plugin_private)); - if (!plugin->priv) - return -1; - - plugin->priv->iface = iface; - - return 0; -} - -void -libdecor_plugin_release(struct libdecor_plugin *plugin) -{ - free(plugin->priv); -} - static void xdg_wm_base_ping(void *user_data, struct xdg_wm_base *xdg_wm_base, @@ -1870,7 +1816,7 @@ notify_error(enum libdecor_error error, const char *message) { ctx.has_error = true; libdecorevent__error(error, message); - ctx.plugin->priv->iface->destroy(ctx.plugin); + libdecor_plugin_gtk_destroy(0); } static void @@ -1884,8 +1830,7 @@ finish_init(void){ int libdecor_dispatch(int timeout) { - struct libdecor_plugin *plugin = ctx.plugin; - return plugin->priv->iface->dispatch(plugin, timeout); + return libdecor_plugin_gtk_dispatch(0, timeout); } void @@ -1923,9 +1868,7 @@ libdecor_notify_plugin_error(enum libdecor_error error, void cleanup(void){ - if (ctx.plugin != 0){ - ctx.plugin->priv->iface->destroy(ctx.plugin); - } + libdecor_plugin_gtk_destroy(0); if (ctx.wl_subcompositor != 0){ wl_subcompositor_destroy(ctx.wl_subcompositor); } @@ -1943,10 +1886,7 @@ cleanup(void){ //#include "libdecor-fallback.c" static void libdecor_plugin_fallback_destroy(struct libdecor_plugin *plugin) -{ - libdecor_plugin_release(plugin); - free(plugin); -} +{} static int libdecor_plugin_fallback_get_fd(struct libdecor_plugin *plugin) @@ -2090,7 +2030,6 @@ libdecor_fallback_plugin_new(void){ struct libdecor_plugin_fallback *plugin; plugin = calloc(1, sizeof *plugin); - libdecor_plugin_init(&plugin->plugin, &fallback_plugin_iface); plugin->context = 0; libdecor_notify_plugin_ready(); @@ -2624,8 +2563,6 @@ update_local_cursor(struct seat *seat); static void libdecor_plugin_gtk_destroy(struct libdecor_plugin *plugin) { - struct libdecor_plugin_gtk *plugin_gtk = - (struct libdecor_plugin_gtk *) plugin; struct seat *seat, *seat_tmp; struct output *output, *output_tmp; struct libdecor_frame_gtk *frame, *frame_tmp; @@ -2667,23 +2604,19 @@ libdecor_plugin_gtk_destroy(struct libdecor_plugin *plugin) wl_list_remove(&frame->link); } - if (ctx.wl_shm) + if (ctx.wl_shm){ wl_shm_destroy(ctx.wl_shm); - - libdecor_plugin_release(&plugin_gtk->plugin); - free(plugin_gtk); + } } static struct libdecor_frame_gtk * -libdecor_frame_gtk_new(struct libdecor_plugin_gtk *plugin_gtk) -{ +libdecor_frame_gtk_new(void){ struct libdecor_frame_gtk *frame_gtk = calloc(1, sizeof *frame_gtk); cairo_t *cr; static const int size = 128; static const int boundary = 32; - frame_gtk->plugin_gtk = plugin_gtk; frame_gtk->shadow_blur = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, size, size); wl_list_insert(&ctx.visible_frame_list, &frame_gtk->link); @@ -2712,8 +2645,7 @@ libdecor_plugin_gtk_get_fd(struct libdecor_plugin *plugin) } static int -libdecor_plugin_gtk_dispatch(struct libdecor_plugin *plugin, - int timeout) +libdecor_plugin_gtk_dispatch(struct libdecor_plugin *plugin, int timeout) { struct libdecor_plugin_gtk *plugin_gtk = (struct libdecor_plugin_gtk *) plugin; @@ -2768,7 +2700,7 @@ libdecor_plugin_gtk_frame_new(struct libdecor_plugin *plugin) (struct libdecor_plugin_gtk *) plugin; struct libdecor_frame_gtk *frame_gtk; - frame_gtk = libdecor_frame_gtk_new(plugin_gtk); + frame_gtk = libdecor_frame_gtk_new(); return &frame_gtk->frame; } @@ -2802,6 +2734,7 @@ const struct wl_buffer_listener buffer_listener = { buffer_release }; +struct libdecor_plugin_gtk; static struct buffer * create_shm_buffer(struct libdecor_plugin_gtk *plugin_gtk, int width, @@ -3011,8 +2944,7 @@ surface_enter(void *data, if (cmpnt == NULL) return; - if (!add_surface_output(frame_gtk->plugin_gtk, wl_output, - &cmpnt->output_list)) + if (!add_surface_output(0, wl_output, &cmpnt->output_list)) return; if (redraw_scale(frame_gtk, cmpnt)) @@ -3065,7 +2997,6 @@ create_surface_subsurface_pair(struct libdecor_frame_gtk *frame_gtk, struct wl_surface **out_wl_surface, struct wl_subsurface **out_wl_subsurface) { - struct libdecor_plugin_gtk *plugin_gtk = frame_gtk->plugin_gtk; struct libdecor_frame *frame = &frame_gtk->frame; struct wl_compositor *wl_compositor = ctx.wl_compositor; struct wl_surface *wl_surface; @@ -3531,7 +3462,6 @@ draw_border_component(struct libdecor_frame_gtk *frame_gtk, struct border_component *border_component, enum component component) { - struct libdecor_plugin_gtk *plugin_gtk = frame_gtk->plugin_gtk; struct buffer *old_buffer; struct buffer *buffer = NULL; int component_x; @@ -3562,7 +3492,7 @@ draw_border_component(struct libdecor_frame_gtk *frame_gtk, } if (!buffer) - buffer = create_shm_buffer(plugin_gtk, + buffer = create_shm_buffer(0, component_width, component_height, border_component->opaque, @@ -3901,7 +3831,6 @@ libdecor_plugin_gtk_frame_popup_grab(struct libdecor_plugin *plugin, { struct libdecor_frame_gtk *frame_gtk = (struct libdecor_frame_gtk *) frame; - struct libdecor_plugin_gtk *plugin_gtk = frame_gtk->plugin_gtk; struct seat *seat; wl_list_for_each(seat, &ctx.seat_list, link) { @@ -3927,7 +3856,6 @@ libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_plugin *plugin, { struct libdecor_frame_gtk *frame_gtk = (struct libdecor_frame_gtk *) frame; - struct libdecor_plugin_gtk *plugin_gtk = frame_gtk->plugin_gtk; struct seat *seat; wl_list_for_each(seat, &ctx.seat_list, link) { @@ -4073,7 +4001,6 @@ ensure_cursor_surface(struct seat *seat) static bool ensure_cursor_theme(struct seat *seat) { - struct libdecor_plugin_gtk *plugin_gtk = seat->plugin_gtk; int scale = 1; struct wl_cursor_theme *theme; struct cursor_output *cursor_output; @@ -4226,8 +4153,6 @@ pointer_enter(void *data, if (!own_surface(surface)) { struct seat *seat = wl_pointer_get_user_data(wl_pointer); - struct libdecor_plugin_gtk *plugin_gtk = seat->plugin_gtk; - if (!ctx.handle_cursor) return; } else { diff --git a/digesting_libdecor.h b/digesting_libdecor.h index 7b8ba86..d4d4938 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -307,8 +307,6 @@ enum component { }; struct seat { - struct libdecor_plugin_gtk *plugin_gtk; - char *name; struct wl_seat *wl_seat; @@ -340,8 +338,6 @@ struct seat { }; struct output { - struct libdecor_plugin_gtk *plugin_gtk; - struct wl_output *wl_output; uint32_t id; int scale; @@ -389,8 +385,6 @@ struct cursor_output { struct libdecor_frame_gtk { struct libdecor_frame frame; - struct libdecor_plugin_gtk *plugin_gtk; - int content_width; int content_height; @@ -432,10 +426,6 @@ struct libdecor_frame_gtk { } titlebar_gesture; }; -struct libdecor_plugin_gtk { - struct libdecor_plugin plugin; -}; - enum titlebar_gesture { TITLEBAR_GESTURE_DOUBLE_CLICK, TITLEBAR_GESTURE_MIDDLE_CLICK, @@ -553,8 +543,6 @@ int libdecor_state_get_content_height(struct libdecor_state *state); enum libdecor_window_state libdecor_state_get_window_state(struct libdecor_state *state); -int libdecor_plugin_init(struct libdecor_plugin *plugin, struct libdecor_plugin_interface *iface); - void libdecor_plugin_release(struct libdecor_plugin *plugin); // #include "libdecor-fallback.h" @@ -592,6 +580,20 @@ static void output_removed(struct output *output); static const char *libdecor_gtk_proxy_tag = "libdecor-gtk"; +static void libdecor_plugin_gtk_destroy(struct libdecor_plugin *plugin); +static int libdecor_plugin_gtk_get_fd(struct libdecor_plugin *plugin); +static int libdecor_plugin_gtk_get_fd(struct libdecor_plugin *plugin); +static int libdecor_plugin_gtk_dispatch(struct libdecor_plugin *plugin, int timeout); +static void libdecor_plugin_gtk_set_handle_application_cursor(struct libdecor_plugin *plugin, bool handle_cursor); +static struct libdecor_frame * libdecor_plugin_gtk_frame_new(struct libdecor_plugin *plugin); +static void libdecor_plugin_gtk_frame_free(struct libdecor_plugin *plugin, struct libdecor_frame *frame); +static void libdecor_plugin_gtk_frame_commit(struct libdecor_plugin *plugin, struct libdecor_frame *frame, struct libdecor_state *state, struct libdecor_configuration *configuration); +static void libdecor_plugin_gtk_frame_property_changed(struct libdecor_plugin *plugin, struct libdecor_frame *frame); +static void libdecor_plugin_gtk_frame_popup_grab(struct libdecor_plugin *plugin, struct libdecor_frame *frame, const char *seat_name); +static void libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_plugin *plugin, struct libdecor_frame *frame, const char *seat_name); +static bool libdecor_plugin_gtk_frame_get_border_size(struct libdecor_plugin *plugin, struct libdecor_frame *frame, struct libdecor_configuration *configuration, + int *left, int *right, int *top, int *bottom); + // digesting_libdecor typedef struct Ctx{ @@ -615,9 +617,6 @@ typedef struct Ctx{ struct wl_list seat_list; struct wl_list output_list; - struct libdecor_plugin_gtk *plugin_gtk; - struct libdecor_plugin *plugin; - bool plugin_ready; bool init_done; bool has_error;