From ecf7d9254dbf3b2e1a0d71d873beb6fcc1886112 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 28 Feb 2026 18:09:02 -0800 Subject: [PATCH] [digesting_libdecor] simplify a little, eliminate dead code --- digesting_libdecor.c | 90 +++++++++++++++----------------------------- digesting_libdecor.h | 10 ++--- 2 files changed, 33 insertions(+), 67 deletions(-) diff --git a/digesting_libdecor.c b/digesting_libdecor.c index 750f44b..277f990 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -560,11 +560,8 @@ const struct wl_registry_listener wl_registry_listener = { static void xdg_surface_configure(void *user_data, struct xdg_surface *xdg_surface, uint32_t serial){ - struct libdecor_configuration *configuration; - - configuration = ctx.pending_configuration; + struct libdecor_configuration *configuration = ctx.pending_configuration; ctx.pending_configuration = 0; - if (configuration == 0){ configuration = calloc(1, sizeof *configuration); } @@ -576,8 +573,7 @@ xdg_surface_configure(void *user_data, struct xdg_surface *xdg_surface, uint32_t int h = ctx.h; bool got_size = false; - if (configuration->has_window_state && - configuration->has_size && + if (configuration->initialized && configuration->window_width != 0 && configuration->window_height != 0){ @@ -587,13 +583,11 @@ xdg_surface_configure(void *user_data, struct xdg_surface *xdg_surface, uint32_t if (ctx.visible && ctx.decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE){ ctx.frame_window_state = configuration->window_state; Sides2D border_size = border_size_from_window_state(configuration->window_state); - w -= border_size.x[0] + border_size.x[1]; + w -= border_size.x[0] + border_size.x[1]; h -= border_size.y[0] + border_size.y[1]; } - /* constrain content dimensions manually */ - if (!(configuration->window_state & LIBDECOR_WINDOW_STATE_NON_FLOATING)) { - // TODO(allen): + if (!(configuration->window_state & LIBDECOR_WINDOW_STATE_NON_FLOATING)){ if (ctx.size_bounds.x[0] > 0){ w = MAX(ctx.size_bounds.x[0], w); } @@ -608,15 +602,17 @@ xdg_surface_configure(void *user_data, struct xdg_surface *xdg_surface, uint32_t } } - got_size = true; - } - if (got_size){ ctx.w = w; ctx.h = h; } + if (!ctx.configured){ ctx.configured = 1; - libdecor_frame_commit(w, h, configuration); + if (configuration->initialized){ + ctx.frame_window_state = configuration->window_state; + } + libdecor_frame_commit(w, h); + xdg_surface_ack_configure(ctx.xdg_surface, configuration->serial); } else{ ctx.has_cached_config = 1; @@ -662,10 +658,9 @@ xdg_toplevel_configure(void *user_data, struct xdg_toplevel *xdg_toplevel, } ctx.pending_configuration = calloc(1, sizeof *ctx.pending_configuration); - ctx.pending_configuration->has_size = true; + ctx.pending_configuration->initialized = true; ctx.pending_configuration->window_width = width; ctx.pending_configuration->window_height = height; - ctx.pending_configuration->has_window_state = true; ctx.pending_configuration->window_state = window_state; } @@ -1097,7 +1092,11 @@ int main(){ if (ctx.has_cached_config){ ctx.has_cached_config = 0; - libdecor_frame_commit(ctx.w, ctx.h, &ctx.cached_config); + if (ctx.cached_config.initialized){ + ctx.frame_window_state = ctx.cached_config.window_state; + } + libdecor_frame_commit(ctx.w, ctx.h); + xdg_surface_ack_configure(ctx.xdg_surface, ctx.cached_config.serial); } /* (nodocs-wl_egl) */ @@ -1275,27 +1274,6 @@ update_client_side_rendering_state(void){ } } -void -libdecor_frame_set_visibility(bool visible){ - ctx.visible = visible; - if (ctx.decoration_manager != 0 && - ctx.toplevel_decoration != 0 && - ctx.has_decoration_mode && - ctx.decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE){ - zxdg_toplevel_decoration_v1_set_mode(ctx.toplevel_decoration, - ctx.visible ? - ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE : - ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); - } - - if (ctx.frame_content_width > 0 && - ctx.frame_content_height > 0){ - update_client_side_rendering_state(); - - wl_surface_commit(ctx.wl_surface); - } -} - static enum xdg_toplevel_resize_edge xdg_edge_from_edge(enum libdecor_resize_edge edge){ enum xdg_toplevel_resize_edge result = XDG_TOPLEVEL_RESIZE_EDGE_NONE; @@ -1324,14 +1302,14 @@ libdecor_frame_unset_fullscreen(void){ } void -libdecor_frame_commit(int w, int h, struct libdecor_configuration *configuration){ - if (configuration != 0 && configuration->has_window_state){ - ctx.frame_window_state = configuration->window_state; - } - +libdecor_frame_commit(int w, int h){ Sides2D border_size = border_size_from_window_state(ctx.frame_window_state); - int border_added_w = border_size.x[0] + border_size.x[1]; - int border_added_h = border_size.y[0] + border_size.y[1]; + int border_added_w = 0; + int border_added_h = 0; + if (ctx.visible && ctx.decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE){ + border_added_w = border_size.x[0] + border_size.x[1]; + border_added_h = border_size.y[0] + border_size.y[1]; + } struct libdecor_state state = {0}; state.content_width = w; @@ -1349,30 +1327,22 @@ libdecor_frame_commit(int w, int h, struct libdecor_configuration *configuration } for (int i = 0; i < 2; i += 1){ - int w = 0; - int h = 0; + int mw = 0; + int mh = 0; if (ctx.size_bounds.x[i] > 0 && ctx.size_bounds.y[i] > 0){ - w = ctx.size_bounds.x[i]; - h = ctx.size_bounds.y[i]; - if (ctx.visible && ctx.decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE){ - w += border_added_w; - h += border_added_h; - } + mw = ctx.size_bounds.x[i] + border_added_w; + mh = ctx.size_bounds.y[i] + border_added_h; } if (i == 0){ - xdg_toplevel_set_min_size(ctx.xdg_toplevel, w, h); + xdg_toplevel_set_min_size(ctx.xdg_toplevel, mw, mh); } else{ - xdg_toplevel_set_max_size(ctx.xdg_toplevel, w, h); + xdg_toplevel_set_max_size(ctx.xdg_toplevel, mw, mh); } } } update_client_side_rendering_state(); - - if (configuration != 0){ - xdg_surface_ack_configure(ctx.xdg_surface, configuration->serial); - } } void @@ -2304,7 +2274,7 @@ draw_title_bar(void){ H = ctx.frame_content_height; if (W < ctx.size_bounds.x[0]){ W = ctx.size_bounds.x[0]; - libdecor_frame_commit(W, H, NULL); + libdecor_frame_commit(W, H); } else{ /* set default height */ diff --git a/digesting_libdecor.h b/digesting_libdecor.h index 214fa23..9fe009d 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -184,13 +184,10 @@ struct libdecor_state { int content_height; }; -struct libdecor_configuration { +struct libdecor_configuration{ + bool initialized; uint32_t serial; - - bool has_window_state; enum libdecor_window_state window_state; - - bool has_size; int window_width; int window_height; }; @@ -250,10 +247,9 @@ enum titlebar_gesture { // libdecor.h -void libdecor_frame_set_visibility(bool visible); void libdecor_frame_show_window_menu(struct wl_seat *wl_seat, uint32_t serial, int x, int y); -void libdecor_frame_commit(int w, int h, struct libdecor_configuration *configuration); +void libdecor_frame_commit(int w, int h); void libdecor_frame_set_fullscreen(struct wl_output *output); void libdecor_frame_unset_fullscreen(void);