From c4f50c6f6e596c0fedbba1f8f5dc831242d21fb8 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 28 Feb 2026 12:53:12 -0800 Subject: [PATCH] [digesting_libdecor] refer to border components by slot index instead of by pointer --- digesting_libdecor.c | 57 ++++++++++++++++++++------------------------ digesting_libdecor.h | 29 +++++++++++----------- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/digesting_libdecor.c b/digesting_libdecor.c index 4838aee..c8e214c 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -1919,7 +1919,6 @@ static void ensure_title_bar_surfaces(void){ GtkStyleContext *context_hdr; - ctx.component_slot[COMPONENT_SLOT_HEADER].slot = COMPONENT_SLOT_HEADER; ctx.component_slot[COMPONENT_SLOT_HEADER].opaque = false; ensure_component(&ctx.component_slot[COMPONENT_SLOT_HEADER]); @@ -1961,7 +1960,7 @@ ensure_title_bar_surfaces(void){ } static Extent2D -extent2d_from_component_type(enum component_slot slot){ +extent2d_from_component_slot(enum component_slot slot){ Extent2D result = {0}; int width = ctx.frame_content_width; int height = ctx.frame_content_height; @@ -2139,34 +2138,29 @@ draw_header_button(cairo_t *cr, cairo_surface_t *surface, } static void -set_component_input_region(struct border_component *border_component){ - if (border_component->slot == COMPONENT_SLOT_SHADOW && ctx.shadow_showing){ +set_component_input_region(enum component_slot slot){ + if (slot == COMPONENT_SLOT_SHADOW && ctx.shadow_showing){ struct wl_region *input_region; - Extent2D extent = extent2d_from_component_type(border_component->slot); - - /* - * the input region is the outer surface size minus the inner - * content size - */ + Extent2D extent = extent2d_from_component_slot(COMPONENT_SLOT_SHADOW); input_region = wl_compositor_create_region(ctx.wl_compositor); wl_region_add(input_region, 0, 0, extent.w, extent.h); wl_region_subtract(input_region, -extent.x, -extent.y, ctx.frame_content_width, ctx.frame_content_height); - wl_surface_set_input_region(border_component->wl_surface, input_region); + wl_surface_set_input_region(ctx.component_slot[slot].wl_surface, input_region); wl_region_destroy(input_region); } } static void -draw_border_component(struct border_component *border_component){ +draw_border_component(enum component_slot slot){ struct buffer *old_buffer; struct buffer *buffer = 0; - if (border_component->wl_surface != 0){ - Extent2D extent = extent2d_from_component_type(border_component->slot); + if (slot < COMPONENT_SLOT_COUNT && + ctx.component_slot[slot].wl_surface != 0){ + Extent2D extent = extent2d_from_component_slot(slot); + set_component_input_region(slot); - set_component_input_region(border_component); - - old_buffer = border_component->buffer; + old_buffer = ctx.component_slot[slot].buffer; if (old_buffer != 0){ if (!old_buffer->in_use && old_buffer->buffer_width == extent.w && @@ -2175,14 +2169,14 @@ draw_border_component(struct border_component *border_component){ } else{ buffer_free(old_buffer); - border_component->buffer = 0; + ctx.component_slot[slot].buffer = 0; } } if (buffer == 0){ int width = extent.w; int height = extent.h; - bool opaque = border_component->opaque; + bool opaque = ctx.component_slot[slot].opaque; struct wl_shm_pool *pool; int fd, size, buffer_width, buffer_height, stride; @@ -2230,7 +2224,7 @@ draw_border_component(struct border_component *border_component){ cairo_t *cr = cairo_create(surface); cairo_surface_set_device_scale(surface, 1, 1); - switch (border_component->slot){ + switch (slot){ default: case COMPONENT_SLOT_NONE: break; case COMPONENT_SLOT_SHADOW: { @@ -2300,14 +2294,17 @@ draw_border_component(struct border_component *border_component){ cairo_surface_destroy(surface); } - wl_surface_attach(border_component->wl_surface, buffer->wl_buffer, 0, 0); - wl_surface_set_buffer_scale(border_component->wl_surface, 1); - buffer->in_use = true; - wl_surface_commit(border_component->wl_surface); - wl_surface_damage_buffer(border_component->wl_surface, 0, 0, extent.w, extent.h); - wl_subsurface_set_position(border_component->wl_subsurface, extent.x, extent.y); + struct wl_surface *component_surface = ctx.component_slot[slot].wl_surface; + struct wl_subsurface *component_subsurface = ctx.component_slot[slot].wl_subsurface; - border_component->buffer = buffer; + wl_surface_attach(component_surface, buffer->wl_buffer, 0, 0); + wl_surface_set_buffer_scale(component_surface, 1); + buffer->in_use = true; + wl_surface_commit(component_surface); + wl_surface_damage_buffer(component_surface, 0, 0, extent.w, extent.h); + wl_subsurface_set_position(component_subsurface, extent.x, extent.y); + + ctx.component_slot[slot].buffer = buffer; } } @@ -2360,7 +2357,7 @@ draw_title_bar(void){ /* set default height */ gtk_widget_get_preferred_height(ctx.header, 0, &allocation.height); gtk_widget_size_allocate(ctx.header, &allocation); - draw_border_component(&ctx.component_slot[COMPONENT_SLOT_HEADER]); + draw_border_component(COMPONENT_SLOT_HEADER); } } @@ -2374,10 +2371,9 @@ draw_decoration(void){ }break; case DECORATION_TYPE_ALL: { - ctx.component_slot[COMPONENT_SLOT_SHADOW].slot = COMPONENT_SLOT_SHADOW; ctx.component_slot[COMPONENT_SLOT_SHADOW].opaque = false; ensure_component(&ctx.component_slot[COMPONENT_SLOT_SHADOW]); - draw_border_component(&ctx.component_slot[COMPONENT_SLOT_SHADOW]); + draw_border_component(COMPONENT_SLOT_SHADOW); ctx.shadow_showing = true; ensure_title_bar_surfaces(); draw_title_bar(); @@ -2457,7 +2453,6 @@ border_size_from_window_state(enum libdecor_window_state window_state){ case DECORATION_TYPE_NONE: break; case DECORATION_TYPE_ALL: { - ctx.component_slot[COMPONENT_SLOT_SHADOW].slot = COMPONENT_SLOT_SHADOW; ctx.component_slot[COMPONENT_SLOT_SHADOW].opaque = false; ensure_component(&ctx.component_slot[COMPONENT_SLOT_SHADOW]); } G_GNUC_FALLTHROUGH; diff --git a/digesting_libdecor.h b/digesting_libdecor.h index 45033b3..35c7ad5 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -163,8 +163,20 @@ enum component_slot { COMPONENT_SLOT_COUNT }; +struct buffer { + struct wl_buffer *wl_buffer; + bool in_use; + bool is_detached; + + void *data; + size_t data_size; + int width; + int height; + int buffer_width; + int buffer_height; +}; + struct border_component { - enum component_slot slot; struct wl_surface *wl_surface; struct wl_subsurface *wl_subsurface; struct buffer *buffer; @@ -238,19 +250,6 @@ struct seat { struct wl_list link; }; -struct buffer { - struct wl_buffer *wl_buffer; - bool in_use; - bool is_detached; - - void *data; - size_t data_size; - int width; - int height; - int buffer_width; - int buffer_height; -}; - enum titlebar_gesture { TITLEBAR_GESTURE_DOUBLE_CLICK, TITLEBAR_GESTURE_MIDDLE_CLICK, @@ -302,7 +301,7 @@ static struct wl_cursor* wl_cursor_from_pos(int x, int y); static void draw_decoration(void); static void draw_header_button(cairo_t *cr, cairo_surface_t *surface, enum header_element button_type); static void buffer_free(struct buffer *buffer); -static void draw_border_component(struct border_component *border_component); +static void draw_border_component(enum component_slot slot); static bool own_proxy(void *proxy); static enum component_slot component_slot_from_wl_surface(const struct wl_surface *surface);