From c1f41242ecc57775950240d479807259439f45b3 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 26 Feb 2026 18:46:28 -0800 Subject: [PATCH] [digesting_libdecor] clean up the property changing code, eliminate notify_on_property_change --- digesting_libdecor.c | 251 ++++++++++++++++++++----------------------- digesting_libdecor.h | 19 +--- 2 files changed, 121 insertions(+), 149 deletions(-) diff --git a/digesting_libdecor.c b/digesting_libdecor.c index 03e473c..bc60cf0 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -406,51 +406,49 @@ int main(){ } if (ctx.wl_surface != 0){ - { - ctx.frame = calloc(1, sizeof *ctx.frame); - wl_list_insert(&ctx.visible_frame_list, &ctx.frame->gtk_link); - - { - static const int size = 128; - static const int boundary = 32; - cairo_t *cr; - - ctx.frame->shadow_blur = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size); - cr = cairo_create(ctx.frame->shadow_blur); - cairo_set_operator(cr, CAIRO_OPERATOR_OVER); - cairo_set_source_rgba(cr, 0, 0, 0, 1); - cairo_rectangle(cr, boundary, boundary, size - 2*boundary, size - 2*boundary); - cairo_fill(cr); - cairo_destroy(cr); - - blur_surface(ctx.frame->shadow_blur, 64); - } - } + ctx.frame = calloc(1, sizeof *ctx.frame); { - ctx.frame->ref_count = 1; + static const int size = 128; + static const int boundary = 32; + cairo_t *cr; + cairo_surface_t *shadow_blur; - ctx.frame->wl_surface = ctx.wl_surface; - ctx.frame->wm_capabilities = (LIBDECOR_WM_CAPABILITIES_WINDOW_MENU | - LIBDECOR_WM_CAPABILITIES_MAXIMIZE | - LIBDECOR_WM_CAPABILITIES_FULLSCREEN | - LIBDECOR_WM_CAPABILITIES_MINIMIZE); + shadow_blur = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size); + cr = cairo_create(shadow_blur); + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + cairo_set_source_rgba(cr, 0, 0, 0, 1); + cairo_rectangle(cr, boundary, boundary, size - 2*boundary, size - 2*boundary); + cairo_fill(cr); + cairo_destroy(cr); - wl_list_insert(&ctx.frames, &ctx.frame->frame_link); - - libdecor_frame_set_capabilities(ctx.frame, - LIBDECOR_ACTION_MOVE | - LIBDECOR_ACTION_RESIZE | - LIBDECOR_ACTION_MINIMIZE | - LIBDECOR_ACTION_FULLSCREEN | - LIBDECOR_ACTION_CLOSE); - - ctx.frame->visible = true; - - if (ctx.init_done){ - init_shell_surface(ctx.frame); - } + blur_surface(shadow_blur, 64); + ctx.frame->shadow_blur = shadow_blur; } + + ctx.frame->ref_count = 1; + + ctx.frame->wl_surface = ctx.wl_surface; + ctx.frame->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->frame_link); + wl_list_insert(&ctx.visible_frame_list, &ctx.frame->gtk_link); + ctx.frame->visible = true; + + set_capabilities(ctx.frame, + LIBDECOR_ACTION_MOVE | + LIBDECOR_ACTION_RESIZE | + LIBDECOR_ACTION_MINIMIZE | + LIBDECOR_ACTION_FULLSCREEN | + LIBDECOR_ACTION_CLOSE); + + if (ctx.init_done){ + init_shell_surface(ctx.frame); + } + } if (ctx.frame != 0){ @@ -1160,13 +1158,21 @@ libdecor_frame_set_title(struct libdecor_frame *frame, const char *title){ free(frame->state.title); frame->state.title = strdup(title); - if (!frame->xdg_toplevel){ - return; + free(frame->title); + frame->title = strdup(title); + + if (frame->xdg_toplevel != 0){ + xdg_toplevel_set_title(frame->xdg_toplevel, title); + + /* + * when in SSD mode, the window title is not to be managed by GTK; + * this is detected by frame_gtk->header not being a proper GTK widget + */ + if (GTK_IS_WIDGET(frame->header)){ + draw_decoration(frame); + libdecor_frame_toplevel_commit(frame); + } } - - xdg_toplevel_set_title(frame->xdg_toplevel, title); - - libdecor_plugin_gtk_frame_property_changed(frame); } } @@ -1187,58 +1193,43 @@ libdecor_frame_set_app_id(struct libdecor_frame *frame, const char *app_id){ } static void -notify_on_capability_change(struct libdecor_frame *frame, - const enum libdecor_capabilities old_capabilities) -{ +set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities new_capabilities){ struct libdecor_state *state; - if (frame->frame_capabilities == old_capabilities) - return; - - if (frame->frame_content_width == 0 || - frame->frame_content_height == 0) - return; - - libdecor_plugin_gtk_frame_property_changed(frame); - - if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) { - frame->interactive_limits = frame->state.content_limits; - /* set fixed window size */ - libdecor_frame_set_min_content_size(frame, - frame->frame_content_width, - frame->frame_content_height); - libdecor_frame_set_max_content_size(frame, - frame->frame_content_width, - frame->frame_content_height); - } else { - /* restore old limits */ - frame->state.content_limits = frame->interactive_limits; + if (frame->frame_capabilities != new_capabilities){ + frame->frame_capabilities = new_capabilities; + if (frame->frame_content_width != 0 && + frame->frame_content_height != 0){ + + frame->gtk_capabilities = frame->frame_capabilities; + + /* + * when in SSD mode, the window title is not to be managed by GTK; + * this is detected by frame_gtk->header not being a proper GTK widget + */ + if (GTK_IS_WIDGET(frame->header)){ + draw_decoration(frame); + libdecor_frame_toplevel_commit(frame); + } + + if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)){ + frame->interactive_limits = frame->state.content_limits; + /* set fixed window size */ + libdecor_frame_set_min_content_size(frame, frame->frame_content_width, frame->frame_content_height); + libdecor_frame_set_max_content_size(frame, frame->frame_content_width, frame->frame_content_height); + } + else{ + /* restore old limits */ + frame->state.content_limits = frame->interactive_limits; + } + + state = libdecor_state_new(frame->frame_content_width, frame->frame_content_height); + libdecor_frame_commit(frame, state, NULL); + libdecor_state_free(state); + + libdecor_frame_toplevel_commit(frame); + } } - - state = libdecor_state_new(frame->frame_content_width, - frame->frame_content_height); - libdecor_frame_commit(frame, state, NULL); - libdecor_state_free(state); - - libdecor_frame_toplevel_commit(frame); -} - -void -libdecor_frame_set_capabilities(struct libdecor_frame *frame, - enum libdecor_capabilities capabilities) -{ - const enum libdecor_capabilities old_capabilities = frame->frame_capabilities; - frame->frame_capabilities |= capabilities; - notify_on_capability_change(frame, old_capabilities); -} - -void -libdecor_frame_unset_capabilities(struct libdecor_frame *frame, - enum libdecor_capabilities capabilities) -{ - const enum libdecor_capabilities old_capabilities = frame->frame_capabilities; - frame->frame_capabilities &= ~capabilities; - notify_on_capability_change(frame, old_capabilities); } bool @@ -1615,8 +1606,7 @@ cleanup(void){ //#include "libdecor-cairo-blur.c" int -blur_surface(cairo_surface_t *surface, int margin) -{ +blur_surface(cairo_surface_t *surface, int margin){ int32_t width, height, stride, x, y, z, w; uint8_t *src, *dst; uint32_t *s, *d, a, p; @@ -1705,8 +1695,7 @@ blur_surface(cairo_surface_t *surface, int margin) void render_shadow(cairo_t *cr, cairo_surface_t *surface, - int x, int y, int width, int height, int margin, int top_margin) -{ + int x, int y, int width, int height, int margin, int top_margin){ cairo_pattern_t *pattern; cairo_matrix_t matrix; int i, fx, fy, shadow_height, shadow_width; @@ -2198,8 +2187,7 @@ libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor){ } static void -toggle_maximized(struct libdecor_frame *const frame) -{ +toggle_maximized(struct libdecor_frame *const frame){ if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) return; @@ -2211,9 +2199,7 @@ toggle_maximized(struct libdecor_frame *const frame) } static void -buffer_release(void *user_data, - struct wl_buffer *wl_buffer) -{ +buffer_release(void *user_data, struct wl_buffer *wl_buffer){ struct buffer *buffer = user_data; if (buffer->is_detached) @@ -2227,11 +2213,7 @@ const struct wl_buffer_listener buffer_listener = { }; static struct buffer * -create_shm_buffer(int width, - int height, - bool opaque, - int scale) -{ +create_shm_buffer(int width, int height, bool opaque, int scale){ struct wl_shm_pool *pool; int fd, size, buffer_width, buffer_height, stride; void *data; @@ -2280,8 +2262,7 @@ create_shm_buffer(int width, } static void -buffer_free(struct buffer *buffer) -{ +buffer_free(struct buffer *buffer){ if (buffer->wl_buffer) { wl_buffer_destroy(buffer->wl_buffer); munmap(buffer->data, buffer->data_size); @@ -2292,8 +2273,7 @@ buffer_free(struct buffer *buffer) } static void -free_border_component(struct border_component *border_component) -{ +free_border_component(struct border_component *border_component){ if (border_component->wl_surface) { wl_subsurface_destroy(border_component->wl_subsurface); border_component->wl_subsurface = NULL; @@ -3138,9 +3118,9 @@ libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame, } } +#if 0 static void -libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame) -{ +libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame){ bool redraw_needed = false; const char *new_title; @@ -3148,27 +3128,30 @@ libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame) * when in SSD mode, the window title is not to be managed by GTK; * this is detected by frame_gtk->header not being a proper GTK widget */ - if (!GTK_IS_WIDGET(frame->header)) return; - - new_title = libdecor_frame_get_title(frame); - if (!STREQL(frame->title, new_title)) - redraw_needed = true; - free(frame->title); - frame->title = NULL; - if (new_title){ - frame->title = strdup(new_title); - } - - if (frame->gtk_capabilities != libdecor_frame_get_capabilities(frame)){ - frame->gtk_capabilities = libdecor_frame_get_capabilities(frame); - redraw_needed = true; - } - - if (redraw_needed){ - draw_decoration(frame); - libdecor_frame_toplevel_commit(frame); + if (GTK_IS_WIDGET(frame->header)){ + + new_title = libdecor_frame_get_title(frame); + if (!STREQL(frame->title, new_title)){ + redraw_needed = true; + } + free(frame->title); + frame->title = NULL; + if (new_title){ + frame->title = strdup(new_title); + } + + if (frame->gtk_capabilities != libdecor_frame_get_capabilities(frame)){ + frame->gtk_capabilities = libdecor_frame_get_capabilities(frame); + redraw_needed = true; + } + + if (redraw_needed){ + draw_decoration(frame); + libdecor_frame_toplevel_commit(frame); + } } } +#endif static void update_component_focus(struct libdecor_frame *frame, struct wl_surface *surface, struct seat *seat){ diff --git a/digesting_libdecor.h b/digesting_libdecor.h index 3daf7bf..83e18a6 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -33,15 +33,6 @@ // config.h -/* Version number of package */ -#define VERSION "0.2.2" - -/* Plugin directiory path */ -#define LIBDECOR_PLUGIN_DIR "/usr/local/lib/x86_64-linux-gnu/libdecor/plugins-1" - -/* Plugin API version */ -#define LIBDECOR_PLUGIN_API_VERSION 1 - #define HAS_DBUS /* #undef HAVE_MKOSTEMP */ @@ -381,10 +372,6 @@ void libdecor_frame_set_title(struct libdecor_frame *frame, const char * libdecor_frame_get_title(struct libdecor_frame *frame); void libdecor_frame_set_app_id(struct libdecor_frame *frame, const char *app_id); -void libdecor_frame_set_capabilities(struct libdecor_frame *frame, - enum libdecor_capabilities capabilities); -void libdecor_frame_unset_capabilities(struct libdecor_frame *frame, - enum libdecor_capabilities capabilities); bool libdecor_frame_has_capability(struct libdecor_frame *frame, enum libdecor_capabilities capability); void libdecor_frame_show_window_menu(struct libdecor_frame *frame, @@ -481,7 +468,6 @@ void render_shadow(cairo_t *cr, cairo_surface_t *surface, bool libdecor_get_cursor_settings(char **theme, int *size); enum libdecor_color_scheme libdecor_get_color_scheme(); - // #include "os-compatibility.h" int libdecor_os_create_anonymous_file(off_t size); @@ -491,6 +477,8 @@ int libdecor_os_create_anonymous_file(off_t size); static void finish_init(void); static void init_shell_surface(struct libdecor_frame *frame); +static void set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities new_capabilities); + //#include "plugins/gtk/libdecor-gtk.c" @@ -507,11 +495,12 @@ static int libdecor_plugin_gtk_dispatch(int timeout); static void libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor); static void libdecor_plugin_gtk_frame_free(struct libdecor_frame *frame); static void libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame, struct libdecor_state *state, struct libdecor_configuration *configuration); -static void libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame); static void libdecor_plugin_gtk_frame_popup_grab(struct libdecor_frame *frame, const char *seat_name); static void libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_frame *frame, const char *seat_name); static bool libdecor_plugin_gtk_frame_get_border_size(struct libdecor_frame *frame, struct libdecor_configuration *configuration, int *left, int *right, int *top, int *bottom); +static void draw_decoration(struct libdecor_frame *frame); + // digesting_libdecor typedef struct Ctx{