From fb76c306cd71a9a9e0e112da1cd9fa0a0d554364 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 26 Feb 2026 15:50:10 -0800 Subject: [PATCH] [digesting_libdecor] eliminate libdecor_decorate --- digesting_libdecor.c | 102 ++++++++++++++++++------------------------- digesting_libdecor.h | 5 +-- 2 files changed, 44 insertions(+), 63 deletions(-) diff --git a/digesting_libdecor.c b/digesting_libdecor.c index 5fc0df8..7994a2d 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -262,6 +262,9 @@ int main(){ */ { + ctx.w = 640; + ctx.h = 480; + wl_list_init(&ctx.frames); wl_list_init(&ctx.visible_frame_list); @@ -294,19 +297,20 @@ int main(){ if (ctx.wl_compositor == 0){ printf("failed to get wl_compositor\n"); + ctx.has_error = 1; } if (ctx.wl_subcompositor == 0){ printf("failed to get wl_subcompositor\n"); + ctx.has_error = 1; } if (ctx.wl_shm == 0){ printf("failed to get wl_shm\n"); + ctx.has_error = 1; } } int opengl_load_success = 0; - if (ctx.wl_compositor != 0 && - ctx.wl_subcompositor != 0 && - ctx.wl_shm != 0){ + if (!ctx.has_error){ /* (egl) eglGetDisplay ** " obtains the EGL display connection for the native display " */ @@ -392,9 +396,6 @@ int main(){ */ if (opengl_load_success){ - ctx.w = 640; - ctx.h = 480; - /* (1) Appendix A: wl_compositor::create_surface ** " create new surface " */ @@ -405,22 +406,49 @@ int main(){ } if (ctx.wl_surface != 0){ - /* (libdecor.h) " Decorate the given content wl_surface. " */ - ctx.libdecor_frame = libdecor_decorate(ctx.wl_surface, 0); + ctx.frame = libdecor_plugin_gtk_frame_new(); + if (ctx.frame != 0){ + struct libdecor_frame_private *frame_priv; + + ctx.frame->priv = frame_priv = calloc(1, sizeof *frame_priv); + + frame_priv->ref_count = 1; + + frame_priv->wl_surface = ctx.wl_surface; + frame_priv->wm_capabilities = (LIBDECOR_WM_CAPABILITIES_WINDOW_MENU | + LIBDECOR_WM_CAPABILITIES_MAXIMIZE | + LIBDECOR_WM_CAPABILITIES_FULLSCREEN | + LIBDECOR_WM_CAPABILITIES_MINIMIZE); + + wl_list_insert(&ctx.frames, &ctx.frame->link); + + libdecor_frame_set_capabilities(ctx.frame, + LIBDECOR_ACTION_MOVE | + LIBDECOR_ACTION_RESIZE | + LIBDECOR_ACTION_MINIMIZE | + LIBDECOR_ACTION_FULLSCREEN | + LIBDECOR_ACTION_CLOSE); + + frame_priv->visible = true; + + if (ctx.init_done){ + init_shell_surface(ctx.frame); + } + } } - if (ctx.libdecor_frame != 0){ + if (ctx.frame != 0){ /* (libdecor.h) " Set the title of the window. " */ - libdecor_frame_set_title(ctx.libdecor_frame, "Example Window"); + libdecor_frame_set_title(ctx.frame, "Example Window"); /* (libdecor.h) " This translates roughly to xdg_toplevel_set_min_size() " **~ NOTE: I recommend setting this to something greater than 0 on each ** axis, to prevent some artifacts when resize goes 0 or negative. */ - libdecor_frame_set_min_content_size(ctx.libdecor_frame, 80, 60); + libdecor_frame_set_min_content_size(ctx.frame, 80, 60); /* (libdecor.h) " Map the window. " */ - libdecor_frame_map(ctx.libdecor_frame); + libdecor_frame_map(ctx.frame); /* (nodocs-wl_egl) */ ctx.wl_egl_window = wl_egl_window_create(ctx.wl_surface, ctx.w, ctx.h); @@ -514,7 +542,7 @@ int main(){ if (ctx.has_cached_config){ ctx.has_cached_config = 0; struct libdecor_state *state = libdecor_state_new(ctx.w, ctx.h); - libdecor_frame_commit(ctx.libdecor_frame, state, &ctx.cached_config); + libdecor_frame_commit(ctx.frame, state, &ctx.cached_config); libdecor_state_free(state); } @@ -777,10 +805,7 @@ libdecor_configuration_get_window_state(struct libdecor_configuration *configura } static void -xdg_surface_configure(void *user_data, - struct xdg_surface *xdg_surface, - uint32_t serial) -{ +xdg_surface_configure(void *user_data, struct xdg_surface *xdg_surface, uint32_t serial){ struct libdecor_frame *frame = user_data; struct libdecor_frame_private *frame_priv = frame->priv; struct libdecor_configuration *configuration; @@ -1050,49 +1075,6 @@ init_shell_surface(struct libdecor_frame *frame) do_map(frame); } -struct libdecor_frame * -libdecor_decorate(struct wl_surface *wl_surface, void *user_data){ - struct libdecor_frame *frame; - struct libdecor_frame_private *frame_priv; - - if (ctx.has_error){ - return NULL; - } - - frame = libdecor_plugin_gtk_frame_new(); - if (!frame){ - return NULL; - } - - frame_priv = calloc(1, sizeof *frame_priv); - frame->priv = frame_priv; - - frame_priv->ref_count = 1; - - frame_priv->wl_surface = wl_surface; - frame_priv->user_data = user_data; - frame_priv->wm_capabilities = LIBDECOR_WM_CAPABILITIES_WINDOW_MENU | - LIBDECOR_WM_CAPABILITIES_MAXIMIZE | - LIBDECOR_WM_CAPABILITIES_FULLSCREEN | - LIBDECOR_WM_CAPABILITIES_MINIMIZE; - - wl_list_insert(&ctx.frames, &frame->link); - - libdecor_frame_set_capabilities(frame, - LIBDECOR_ACTION_MOVE | - LIBDECOR_ACTION_RESIZE | - LIBDECOR_ACTION_MINIMIZE | - LIBDECOR_ACTION_FULLSCREEN | - LIBDECOR_ACTION_CLOSE); - - frame_priv->visible = true; - - if (ctx.init_done) - init_shell_surface(frame); - - return frame; -} - void libdecor_frame_ref(struct libdecor_frame *frame) { diff --git a/digesting_libdecor.h b/digesting_libdecor.h index 17b8575..8f32cd3 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -61,7 +61,6 @@ // libdecor.h -struct libdecor_frame; struct libdecor_configuration; struct libdecor_state; @@ -452,7 +451,6 @@ bool libdecor_configuration_get_content_size(struct libdecor_configuration *conf bool libdecor_configuration_get_window_state(struct libdecor_configuration *configuration, enum libdecor_window_state *window_state); -struct libdecor_frame* libdecor_decorate(struct wl_surface *wl_surface, void *user_data); int libdecor_dispatch(int timeout); // libdecor-plugin.h @@ -499,6 +497,7 @@ int libdecor_os_create_anonymous_file(off_t size); // #include "libdecor.c" static void finish_init(void); +static void init_shell_surface(struct libdecor_frame *frame); //#include "plugins/gtk/libdecor-gtk.c" @@ -556,7 +555,7 @@ typedef struct Ctx{ /* window */ struct wl_surface *wl_surface; - struct libdecor_frame *libdecor_frame; + struct libdecor_frame *frame; struct wl_egl_window *wl_egl_window; int configured; int w;