From 2bce6b183c882f90998952ab1e5b5dc758f09d33 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 26 Feb 2026 19:21:30 -0800 Subject: [PATCH] [digesting_libdecor] eliminate a bunch of getters/setters for frame --- digesting_libdecor.c | 249 ++++++++++++------------------------------- digesting_libdecor.h | 30 +----- 2 files changed, 71 insertions(+), 208 deletions(-) diff --git a/digesting_libdecor.c b/digesting_libdecor.c index bc60cf0..e001019 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -455,11 +455,8 @@ int main(){ /* (libdecor.h) " Set the title of the 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.frame, 80, 60); + ctx.frame->state.content_limits.min_width = 80; + ctx.frame->state.content_limits.min_height = 60; /* (libdecor.h) " Map the window. " */ libdecor_frame_map(ctx.frame); @@ -1212,11 +1209,13 @@ set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities libdecor_frame_toplevel_commit(frame); } - if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)){ + if (!(frame->frame_capabilities & 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); + ctx.frame->state.content_limits.min_width = frame->frame_content_width; + ctx.frame->state.content_limits.min_height = frame->frame_content_height; + ctx.frame->state.content_limits.max_width = frame->frame_content_width; + ctx.frame->state.content_limits.max_height = frame->frame_content_height; } else{ /* restore old limits */ @@ -1232,11 +1231,6 @@ set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities } } -bool -libdecor_frame_has_capability(struct libdecor_frame *frame, enum libdecor_capabilities capability){ - return frame->frame_capabilities & capability; -} - void libdecor_frame_popup_grab(struct libdecor_frame *frame, const char *seat_name){ libdecor_plugin_gtk_frame_popup_grab(frame, seat_name); @@ -1247,13 +1241,6 @@ libdecor_frame_popup_ungrab(struct libdecor_frame *frame, const char *seat_name) libdecor_plugin_gtk_frame_popup_ungrab(frame, seat_name); } -void -libdecor_frame_dismiss_popup(struct libdecor_frame *frame, - const char *seat_name) -{ - // -} - void libdecor_frame_show_window_menu(struct libdecor_frame *frame, struct wl_seat *wl_seat, uint32_t serial, int x, int y){ @@ -1280,35 +1267,6 @@ libdecor_frame_translate_coordinate(struct libdecor_frame *frame, } } -void -libdecor_frame_set_min_content_size(struct libdecor_frame *frame, int content_width, int content_height){ - frame->state.content_limits.min_width = content_width; - frame->state.content_limits.min_height = content_height; -} - -void -libdecor_frame_set_max_content_size(struct libdecor_frame *frame, int content_width, int content_height){ - frame->state.content_limits.max_width = content_width; - frame->state.content_limits.max_height = content_height; -} - -void -libdecor_frame_get_min_content_size(const struct libdecor_frame *frame, int *content_width, int *content_height){ - *content_width = frame->state.content_limits.min_width; - *content_height = frame->state.content_limits.min_height; -} - -void -libdecor_frame_get_max_content_size(const struct libdecor_frame *frame, int *content_width, int *content_height){ - *content_width = frame->state.content_limits.max_width; - *content_height = frame->state.content_limits.max_height; -} - -enum libdecor_capabilities -libdecor_frame_get_capabilities(const struct libdecor_frame *frame){ - return frame->frame_capabilities; -} - enum xdg_toplevel_resize_edge edge_to_xdg_edge(enum libdecor_resize_edge edge) { @@ -1419,7 +1377,7 @@ libdecor_frame_apply_limits(struct libdecor_frame *frame, enum libdecor_window_s /* If the frame is configured as non-resizable before the first * configure event is received, we have to manually set the min/max * limits with the configured content size afterwards. */ - if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) { + if (!(frame->frame_capabilities & LIBDECOR_ACTION_RESIZE)) { frame->state.content_limits.min_width = frame->frame_content_width; frame->state.content_limits.max_width = frame->frame_content_width; @@ -1521,36 +1479,6 @@ libdecor_frame_map(struct libdecor_frame *frame) do_map(frame); } -struct wl_surface * -libdecor_frame_get_wl_surface(struct libdecor_frame *frame){ - return frame->wl_surface; -} - -struct xdg_surface * -libdecor_frame_get_xdg_surface(struct libdecor_frame *frame){ - return frame->xdg_surface; -} - -struct xdg_toplevel * -libdecor_frame_get_xdg_toplevel(struct libdecor_frame *frame){ - return frame->xdg_toplevel; -} - -int -libdecor_frame_get_content_width(struct libdecor_frame *frame){ - return frame->frame_content_width; -} - -int -libdecor_frame_get_content_height(struct libdecor_frame *frame){ - return frame->frame_content_height; -} - -enum libdecor_window_state -libdecor_frame_get_window_state(struct libdecor_frame *frame){ - return frame->frame_window_state; -} - enum libdecor_wm_capabilities libdecor_frame_get_wm_capabilities(struct libdecor_frame *frame){ return frame->wm_capabilities; @@ -2188,14 +2116,14 @@ libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor){ static void toggle_maximized(struct libdecor_frame *const frame){ - if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) - return; - - if (!(libdecor_frame_get_window_state(frame) & - LIBDECOR_WINDOW_STATE_MAXIMIZED)) - libdecor_frame_set_maximized(frame); - else - libdecor_frame_unset_maximized(frame); + if ((frame->frame_capabilities & LIBDECOR_ACTION_RESIZE)){ + if (!(frame->frame_window_state & LIBDECOR_WINDOW_STATE_MAXIMIZED)){ + libdecor_frame_set_maximized(frame); + } + else{ + libdecor_frame_unset_maximized(frame); + } + } } static void @@ -2462,13 +2390,10 @@ create_surface_subsurface_pair(struct libdecor_frame *frame, struct wl_subsurface *wl_subsurface; wl_surface = wl_compositor_create_surface(wl_compositor); - wl_proxy_set_tag((struct wl_proxy *) wl_surface, - &libdecor_gtk_proxy_tag); + wl_proxy_set_tag((struct wl_proxy *) wl_surface, &libdecor_gtk_proxy_tag); - parent = libdecor_frame_get_wl_surface(frame); - wl_subsurface = wl_subcompositor_get_subsurface(ctx.wl_subcompositor, - wl_surface, - parent); + parent = frame->wl_surface; + wl_subsurface = wl_subcompositor_get_subsurface(ctx.wl_subcompositor, wl_surface, parent); *out_wl_surface = wl_surface; *out_wl_subsurface = wl_subsurface; @@ -2544,7 +2469,7 @@ ensure_title_bar_surfaces(struct libdecor_frame *frame){ gtk_window_set_titlebar(GTK_WINDOW(frame->window), frame->header); gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(frame->header), TRUE); - gtk_window_set_resizable(GTK_WINDOW(frame->window), libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)); + gtk_window_set_resizable(GTK_WINDOW(frame->window), (frame->frame_capabilities & LIBDECOR_ACTION_RESIZE) != 0); } static void @@ -2557,8 +2482,8 @@ calculate_component_size(struct libdecor_frame *frame, { int content_width, content_height; - content_width = libdecor_frame_get_content_width(frame); - content_height = libdecor_frame_get_content_height(frame); + content_width = frame->frame_content_width; + content_height = frame->frame_content_height; /* avoid warning when restoring previously turned off decoration */ const int title_height = GTK_IS_WIDGET(frame->header)?gtk_widget_get_allocated_height(frame->header):0; @@ -2779,16 +2704,16 @@ draw_header_buttons(struct libdecor_frame *frame, cairo_t *cr, cairo_surface_t * enum header_element *buttons = NULL; size_t nbuttons = 0; - window_state = libdecor_frame_get_window_state(frame); + window_state = frame->frame_window_state; /* set buttons by capability */ - if (libdecor_frame_has_capability(frame, LIBDECOR_ACTION_MINIMIZE)){ + if ((frame->frame_capabilities & LIBDECOR_ACTION_MINIMIZE)){ array_append(&buttons, &nbuttons, HEADER_MIN); } - if (libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)){ + if ((frame->frame_capabilities & LIBDECOR_ACTION_RESIZE)){ array_append(&buttons, &nbuttons, HEADER_MAX); } - if (libdecor_frame_has_capability(frame, LIBDECOR_ACTION_CLOSE)){ + if ((frame->frame_capabilities & LIBDECOR_ACTION_CLOSE)){ array_append(&buttons, &nbuttons, HEADER_CLOSE); } @@ -2852,8 +2777,8 @@ draw_component_content(struct libdecor_frame *frame, &component_width, &component_height); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_rectangle(cr, -component_x, -component_y, - libdecor_frame_get_content_width(frame), - libdecor_frame_get_content_height(frame)); + frame->frame_content_width, + frame->frame_content_height); cairo_fill(cr); } @@ -2884,8 +2809,8 @@ set_component_input_region(struct libdecor_frame *frame, wl_region_add(input_region, 0, 0, component_width, component_height); wl_region_subtract(input_region, -component_x, -component_y, - libdecor_frame_get_content_width(frame), - libdecor_frame_get_content_height(frame)); + frame->frame_content_width, + frame->frame_content_height); wl_surface_set_input_region(border_component->wl_surface, input_region); wl_region_destroy(input_region); @@ -2963,9 +2888,9 @@ draw_title_bar(struct libdecor_frame *frame) enum libdecor_window_state state; GtkStyleContext *style; int pref_width; - int current_min_w, current_min_h, current_max_w, current_max_h, W, H; + int W, H; - state = libdecor_frame_get_window_state(frame); + state = frame->frame_window_state; style = gtk_widget_get_style_context(frame->window); if (!(state & LIBDECOR_WINDOW_STATE_ACTIVE)) { @@ -2985,20 +2910,20 @@ draw_title_bar(struct libdecor_frame *frame) /* set default width, using an empty title to estimate its smallest admissible value */ gtk_header_bar_set_title(GTK_HEADER_BAR(frame->header), ""); gtk_widget_get_preferred_width(frame->header, NULL, &pref_width); - gtk_header_bar_set_title(GTK_HEADER_BAR(frame->header), libdecor_frame_get_title(frame)); - libdecor_frame_get_min_content_size(frame, ¤t_min_w, ¤t_min_h); - if (current_min_w < pref_width) { - current_min_w = pref_width; - libdecor_frame_set_min_content_size(frame, current_min_w, current_min_h); + gtk_header_bar_set_title(GTK_HEADER_BAR(frame->header), + libdecor_frame_get_title(frame)); + if (frame->state.content_limits.min_width < pref_width){ + frame->state.content_limits.min_width = pref_width; } - libdecor_frame_get_max_content_size(frame, ¤t_max_w, ¤t_max_h); - if (current_max_w && current_max_w < current_min_w) { - libdecor_frame_set_max_content_size(frame, current_min_w, current_max_h); + if (frame->state.content_limits.max_width != 0 && + frame->state.content_limits.max_width < + frame->state.content_limits.min_width) { + frame->state.content_limits.max_width = frame->state.content_limits.min_width; } - W = libdecor_frame_get_content_width(frame); - H = libdecor_frame_get_content_height(frame); - if (W < current_min_w) { - W = current_min_w; + W = frame->frame_content_width; + H = frame->frame_content_height; + if (W < frame->state.content_limits.min_width) { + W = frame->state.content_limits.min_width; struct libdecor_state *libdecor_state = libdecor_state_new(W, H); libdecor_frame_commit(frame, libdecor_state, NULL); libdecor_state_free(libdecor_state); @@ -3084,12 +3009,12 @@ libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame, enum decoration_type new_decoration_type; old_window_state = frame->gtk_window_state; - new_window_state = libdecor_frame_get_window_state(frame); + new_window_state = frame->frame_window_state; old_content_width = frame->gtk_content_width; old_content_height = frame->gtk_content_height; - new_content_width = libdecor_frame_get_content_width(frame); - new_content_height = libdecor_frame_get_content_height(frame); + new_content_width = frame->frame_content_width; + new_content_height = frame->frame_content_height; old_decoration_type = frame->decoration_type; new_decoration_type = window_state_to_decoration_type(new_window_state); @@ -3108,51 +3033,14 @@ libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame, draw_decoration(frame); /* set fixed window size */ - if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)){ - libdecor_frame_set_min_content_size(frame, - frame->gtk_content_width, - frame->gtk_content_height); - libdecor_frame_set_max_content_size(frame, - frame->gtk_content_width, - frame->gtk_content_height); + if (!(frame->frame_capabilities & LIBDECOR_ACTION_RESIZE)){ + ctx.frame->state.content_limits.min_width = frame->gtk_content_width; + ctx.frame->state.content_limits.min_height = frame->gtk_content_height; + ctx.frame->state.content_limits.max_width = frame->gtk_content_width; + ctx.frame->state.content_limits.max_height = frame->gtk_content_height; } } -#if 0 -static void -libdecor_plugin_gtk_frame_property_changed(struct libdecor_frame *frame){ - bool redraw_needed = false; - const char *new_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)){ - - 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){ static struct border_component *border_component; @@ -3305,19 +3193,22 @@ libdecor_plugin_gtk_frame_get_border_size(struct libdecor_frame *frame, enum libdecor_window_state window_state; if (configuration) { - if (!libdecor_configuration_get_window_state( - configuration, &window_state)) + if (!libdecor_configuration_get_window_state(configuration, &window_state)) return false; - } else { - window_state = libdecor_frame_get_window_state(frame); + } + else{ + window_state = frame->frame_window_state; } - if (left) + if (left){ *left = 0; - if (right) + } + if (right){ *right = 0; - if (bottom) + } + if (bottom){ *bottom = 0; + } if (top) { enum decoration_type type = window_state_to_decoration_type(window_state); @@ -3494,7 +3385,7 @@ update_local_cursor(struct seat *seat) if (frame->active->type == SHADOW && is_border_surfaces_showing(frame) && - libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) { + (frame->frame_capabilities & LIBDECOR_ACTION_RESIZE)){ enum libdecor_resize_edge edge; edge = component_edge(frame->active, seat->pointer_x, @@ -3682,7 +3573,7 @@ handle_button_on_shadow(struct libdecor_frame *frame, enum libdecor_resize_edge edge = LIBDECOR_RESIZE_EDGE_NONE; edge = component_edge(frame->active, seat->pointer_x, seat->pointer_y, SHADOW_MARGIN); if (edge != LIBDECOR_RESIZE_EDGE_NONE && - libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) { + (frame->frame_capabilities & LIBDECOR_ACTION_RESIZE)){ libdecor_frame_resize(frame, seat->wl_seat, serial, edge); } } @@ -3768,7 +3659,7 @@ handle_button_on_header(struct libdecor_frame *frame, struct seat *seat, uint32_ libdecor_frame_ref(frame); switch (frame->hdr_focus.type) { case HEADER_MIN: { - if (libdecor_frame_has_capability(frame, LIBDECOR_ACTION_MINIMIZE)){ + if (frame->frame_capabilities & LIBDECOR_ACTION_MINIMIZE){ libdecor_frame_set_minimized(frame); } }break; @@ -3778,7 +3669,7 @@ handle_button_on_header(struct libdecor_frame *frame, struct seat *seat, uint32_ }break; case HEADER_CLOSE: { - if (libdecor_frame_has_capability(frame, LIBDECOR_ACTION_CLOSE)){ + if (frame->frame_capabilities & LIBDECOR_ACTION_CLOSE){ libdecor_frame_close(frame); seat->pointer_focus = NULL; } @@ -3947,7 +3838,7 @@ touch_down(void *data, if (time - seat->touch_down_time_stamp < (uint32_t)ctx.double_click_time_ms) { toggle_maximized(frame); } - else if (libdecor_frame_has_capability(frame, LIBDECOR_ACTION_MOVE)){ + else if (frame->frame_capabilities & LIBDECOR_ACTION_MOVE){ seat->touch_down_time_stamp = time; libdecor_frame_move(frame, seat->wl_seat, serial); } @@ -3958,7 +3849,7 @@ touch_down(void *data, default: break; } if (edge != LIBDECOR_RESIZE_EDGE_NONE && - libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) { + (frame->frame_capabilities & LIBDECOR_ACTION_RESIZE)) { libdecor_frame_resize(frame, seat->wl_seat, serial, edge); } } @@ -3984,7 +3875,7 @@ touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial, libdecor_frame_ref(frame); switch (frame->hdr_focus.type) { case HEADER_MIN: { - if (libdecor_frame_has_capability(frame, LIBDECOR_ACTION_MINIMIZE)) { + if (frame->frame_capabilities & LIBDECOR_ACTION_MINIMIZE){ libdecor_frame_set_minimized(frame); } }break; @@ -3994,7 +3885,7 @@ touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial, }break; case HEADER_CLOSE: { - if (libdecor_frame_has_capability(frame, LIBDECOR_ACTION_CLOSE)){ + if (frame->frame_capabilities & LIBDECOR_ACTION_CLOSE){ libdecor_frame_close(frame); seat->touch_focus = NULL; } diff --git a/digesting_libdecor.h b/digesting_libdecor.h index 83e18a6..1a449a7 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -372,8 +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); -bool libdecor_frame_has_capability(struct libdecor_frame *frame, - enum libdecor_capabilities capability); void libdecor_frame_show_window_menu(struct libdecor_frame *frame, struct wl_seat *wl_seat, uint32_t serial, @@ -387,18 +385,7 @@ void libdecor_frame_popup_ungrab(struct libdecor_frame *frame, void libdecor_frame_translate_coordinate(struct libdecor_frame *frame, int surface_x, int surface_y, int *frame_x, int *frame_y); -void libdecor_frame_set_min_content_size(struct libdecor_frame *frame, - int content_width, - int content_height); -void libdecor_frame_set_max_content_size(struct libdecor_frame *frame, - int content_width, - int content_height); -void libdecor_frame_get_min_content_size(const struct libdecor_frame *frame, - int *content_width, - int *content_height); -void libdecor_frame_get_max_content_size(const struct libdecor_frame *frame, - int *content_width, - int *content_height); + void libdecor_frame_resize(struct libdecor_frame *frame, struct wl_seat *wl_seat, uint32_t serial, @@ -418,8 +405,6 @@ void libdecor_frame_unset_fullscreen(struct libdecor_frame *frame); bool libdecor_frame_is_floating(struct libdecor_frame *frame); void libdecor_frame_close(struct libdecor_frame *frame); void libdecor_frame_map(struct libdecor_frame *frame); -struct xdg_surface * libdecor_frame_get_xdg_surface(struct libdecor_frame *frame); -struct xdg_toplevel * libdecor_frame_get_xdg_toplevel(struct libdecor_frame *frame); enum libdecor_wm_capabilities libdecor_frame_get_wm_capabilities(struct libdecor_frame *frame); struct libdecor_state * libdecor_state_new(int width, int height); void libdecor_state_free(struct libdecor_state *state); @@ -434,19 +419,6 @@ int libdecor_dispatch(int timeout); // libdecor-plugin.h -struct wl_surface * libdecor_frame_get_wl_surface(struct libdecor_frame *frame); - -int libdecor_frame_get_content_width(struct libdecor_frame *frame); - -int libdecor_frame_get_content_height(struct libdecor_frame *frame); - -enum libdecor_window_state libdecor_frame_get_window_state(struct libdecor_frame *frame); - -enum libdecor_capabilities libdecor_frame_get_capabilities(const struct libdecor_frame *frame); - -void libdecor_frame_dismiss_popup(struct libdecor_frame *frame, - const char *seat_name); - void libdecor_frame_toplevel_commit(struct libdecor_frame *frame); void libdecor_notify_plugin_ready(void);