From 617f85544355822df6d07dd14d134d726780c3d1 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 26 Feb 2026 16:22:26 -0800 Subject: [PATCH] [digesting_libdecor] convert 'private' pointer in libdecor_frame to in-memory 'private' field --- digesting_libdecor.c | 646 ++++++++++++++++--------------------------- digesting_libdecor.h | 55 ++-- 2 files changed, 262 insertions(+), 439 deletions(-) diff --git a/digesting_libdecor.c b/digesting_libdecor.c index 7994a2d..d1fbeab 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -406,11 +406,32 @@ int main(){ } if (ctx.wl_surface != 0){ - ctx.frame = libdecor_plugin_gtk_frame_new(); - if (ctx.frame != 0){ + { + struct libdecor_frame_gtk *frame_gtk = calloc(1, sizeof *frame_gtk); + wl_list_insert(&ctx.visible_frame_list, &frame_gtk->link); + + { + static const int size = 128; + static const int boundary = 32; + cairo_t *cr; + + frame_gtk->shadow_blur = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size); + cr = cairo_create(frame_gtk->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(frame_gtk->shadow_blur, 64); + } + ctx.frame = &frame_gtk->frame; + } + + { struct libdecor_frame_private *frame_priv; - ctx.frame->priv = frame_priv = calloc(1, sizeof *frame_priv); + frame_priv = &ctx.frame->priv; frame_priv->ref_count = 1; @@ -631,7 +652,7 @@ constrain_content_size(const struct libdecor_frame *frame, int *width, int *height) { - const struct libdecor_limits lim = frame->priv->state.content_limits; + const struct libdecor_limits lim = frame->priv.state.content_limits; if (lim.min_width > 0) *width = MAX(lim.min_width, *width); @@ -648,9 +669,9 @@ static bool frame_has_visible_client_side_decoration(struct libdecor_frame *frame) { /* visibility by client configuration */ - const bool vis_client = frame->priv->visible; + const bool vis_client = frame->priv.visible; /* visibility by compositor configuration */ - const bool vis_server = (frame->priv->decoration_mode == + const bool vis_server = (frame->priv.decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); return vis_client && vis_server; @@ -715,8 +736,6 @@ frame_get_window_size_for(struct libdecor_frame *frame, int *window_width, int *window_height) { - struct libdecor_frame_private *frame_priv = frame->priv; - *window_width = state->content_width; *window_height = state->content_height; @@ -752,7 +771,7 @@ frame_set_window_geometry(struct libdecor_frame *frame, height = content_height; } - xdg_surface_set_window_geometry(frame->priv->xdg_surface, x, y, width, height); + xdg_surface_set_window_geometry(frame->priv.xdg_surface, x, y, width, height); } bool @@ -776,7 +795,7 @@ libdecor_configuration_get_content_size(struct libdecor_configuration *configura int left, right, top, bottom; /* Update window state for correct border size calculation */ - frame->priv->window_state = configuration->window_state; + frame->priv.window_state = configuration->window_state; if (!libdecor_plugin_gtk_frame_get_border_size(frame, configuration, &left, &right, &top, &bottom)){ return false; } @@ -807,11 +826,10 @@ 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){ struct libdecor_frame *frame = user_data; - struct libdecor_frame_private *frame_priv = frame->priv; struct libdecor_configuration *configuration; - configuration = frame_priv->pending_configuration; - frame_priv->pending_configuration = NULL; + configuration = frame->priv.pending_configuration; + frame->priv.pending_configuration = NULL; if (!configuration) configuration = libdecor_configuration_new(); @@ -913,19 +931,16 @@ xdg_toplevel_configure(void *user_data, struct wl_array *states) { struct libdecor_frame *frame = user_data; - struct libdecor_frame_private *frame_priv = frame->priv; enum libdecor_window_state window_state; window_state = parse_states(states); - frame_priv->pending_configuration = libdecor_configuration_new(); - - frame_priv->pending_configuration->has_size = true; - frame_priv->pending_configuration->window_width = width; - frame_priv->pending_configuration->window_height = height; - - frame_priv->pending_configuration->has_window_state = true; - frame_priv->pending_configuration->window_state = window_state; + frame->priv.pending_configuration = libdecor_configuration_new(); + frame->priv.pending_configuration->has_size = true; + frame->priv.pending_configuration->window_width = width; + frame->priv.pending_configuration->window_height = height; + frame->priv.pending_configuration->has_window_state = true; + frame->priv.pending_configuration->window_state = window_state; } static void @@ -941,7 +956,6 @@ xdg_toplevel_configure_bounds(void *user_data, int32_t height) { struct libdecor_frame *frame = user_data; - struct libdecor_frame_private *frame_priv = frame->priv; int left = 0, top = 0, right = 0, bottom = 0; if (frame_has_visible_client_side_decoration(frame)) { @@ -961,27 +975,29 @@ xdg_toplevel_wm_capabilities(void *user_data, struct wl_array *capabilities) { struct libdecor_frame *frame = user_data; - struct libdecor_frame_private *frame_priv = frame->priv; enum xdg_toplevel_wm_capabilities *wm_cap; - frame_priv->wm_capabilities = 0; + frame->priv.wm_capabilities = 0; wl_array_for_each(wm_cap, capabilities) { switch (*wm_cap) { - case XDG_TOPLEVEL_WM_CAPABILITIES_WINDOW_MENU: - frame_priv->wm_capabilities |= LIBDECOR_WM_CAPABILITIES_WINDOW_MENU; - break; - case XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE: - frame_priv->wm_capabilities |= LIBDECOR_WM_CAPABILITIES_MAXIMIZE; - break; - case XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN: - frame_priv->wm_capabilities |= LIBDECOR_WM_CAPABILITIES_FULLSCREEN; - break; - case XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE: - frame_priv->wm_capabilities |= LIBDECOR_WM_CAPABILITIES_MINIMIZE; - break; - default: - break; + case XDG_TOPLEVEL_WM_CAPABILITIES_WINDOW_MENU: { + frame->priv.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_WINDOW_MENU; + }break; + + case XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE: { + frame->priv.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_MAXIMIZE; + }break; + + case XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN: { + frame->priv.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_FULLSCREEN; + }break; + + case XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE: { + frame->priv.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_MINIMIZE; + }break; + + default: break; } } } @@ -999,17 +1015,16 @@ const struct xdg_toplevel_listener xdg_toplevel_listener = { }; static void -toplevel_decoration_configure( - void *data, +toplevel_decoration_configure(void *data, struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, uint32_t mode) { - struct libdecor_frame_private *frame_priv = (struct libdecor_frame_private *)data; + struct libdecor_frame *frame = (struct libdecor_frame*)data; /* Ignore any _configure calls after the first, they will be * from our set_mode call. */ - if (!frame_priv->has_decoration_mode) { - frame_priv->has_decoration_mode = true; - frame_priv->decoration_mode = mode; + if (!frame->priv.has_decoration_mode) { + frame->priv.has_decoration_mode = true; + frame->priv.decoration_mode = mode; } } @@ -1018,120 +1033,85 @@ xdg_toplevel_decoration_listener = { toplevel_decoration_configure, }; -void -libdecor_frame_create_xdg_decoration(struct libdecor_frame_private *frame_priv) -{ - if (!ctx.decoration_manager) - return; - - frame_priv->toplevel_decoration = - zxdg_decoration_manager_v1_get_toplevel_decoration(ctx.decoration_manager, - frame_priv->xdg_toplevel); - - zxdg_toplevel_decoration_v1_add_listener(frame_priv->toplevel_decoration, - &xdg_toplevel_decoration_listener, - frame_priv); -} - static void init_shell_surface(struct libdecor_frame *frame) { - struct libdecor_frame_private *frame_priv = frame->priv; - - if (frame_priv->xdg_surface) + if (frame->priv.xdg_surface) return; - frame_priv->xdg_surface = - xdg_wm_base_get_xdg_surface(ctx.xdg_wm_base, frame_priv->wl_surface); - xdg_surface_add_listener(frame_priv->xdg_surface, + frame->priv.xdg_surface = + xdg_wm_base_get_xdg_surface(ctx.xdg_wm_base, frame->priv.wl_surface); + xdg_surface_add_listener(frame->priv.xdg_surface, &xdg_surface_listener, frame); - frame_priv->xdg_toplevel = - xdg_surface_get_toplevel(frame_priv->xdg_surface); - xdg_toplevel_add_listener(frame_priv->xdg_toplevel, + frame->priv.xdg_toplevel = + xdg_surface_get_toplevel(frame->priv.xdg_surface); + xdg_toplevel_add_listener(frame->priv.xdg_toplevel, &xdg_toplevel_listener, frame); - frame_priv->decoration_mode = + frame->priv.decoration_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; - frame_priv->toplevel_decoration = NULL; - libdecor_frame_create_xdg_decoration(frame_priv); - - if (frame_priv->state.parent) { - xdg_toplevel_set_parent(frame_priv->xdg_toplevel, - frame_priv->state.parent); - } - if (frame_priv->state.title) { - xdg_toplevel_set_title(frame_priv->xdg_toplevel, - frame_priv->state.title); - } - if (frame_priv->state.app_id) { - xdg_toplevel_set_app_id(frame_priv->xdg_toplevel, - frame_priv->state.app_id); + frame->priv.toplevel_decoration = NULL; + //libdecor_frame_create_xdg_decoration(frame_priv); + if (ctx.decoration_manager){ + frame->priv.toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(ctx.decoration_manager, frame->priv.xdg_toplevel); + zxdg_toplevel_decoration_v1_add_listener(frame->priv.toplevel_decoration, &xdg_toplevel_decoration_listener, frame); } - if (frame_priv->pending_map) + if (frame->priv.state.parent) { + xdg_toplevel_set_parent(frame->priv.xdg_toplevel, + frame->priv.state.parent); + } + if (frame->priv.state.title) { + xdg_toplevel_set_title(frame->priv.xdg_toplevel, + frame->priv.state.title); + } + if (frame->priv.state.app_id) { + xdg_toplevel_set_app_id(frame->priv.xdg_toplevel, + frame->priv.state.app_id); + } + + if (frame->priv.pending_map) do_map(frame); } void -libdecor_frame_ref(struct libdecor_frame *frame) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - frame_priv->ref_count++; +libdecor_frame_ref(struct libdecor_frame *frame){ + frame->priv.ref_count++; } void -libdecor_frame_unref(struct libdecor_frame *frame) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - frame_priv->ref_count--; - if (frame_priv->ref_count == 0) { - if (ctx.decoration_manager && frame_priv->toplevel_decoration) { - zxdg_toplevel_decoration_v1_destroy(frame_priv->toplevel_decoration); - frame_priv->toplevel_decoration = NULL; +libdecor_frame_unref(struct libdecor_frame *frame){ + frame->priv.ref_count--; + if (frame->priv.ref_count == 0) { + if (ctx.decoration_manager && frame->priv.toplevel_decoration) { + zxdg_toplevel_decoration_v1_destroy(frame->priv.toplevel_decoration); + frame->priv.toplevel_decoration = NULL; } wl_list_remove(&frame->link); - if (frame_priv->xdg_toplevel) - xdg_toplevel_destroy(frame_priv->xdg_toplevel); - if (frame_priv->xdg_surface) - xdg_surface_destroy(frame_priv->xdg_surface); + if (frame->priv.xdg_toplevel) + xdg_toplevel_destroy(frame->priv.xdg_toplevel); + if (frame->priv.xdg_surface) + xdg_surface_destroy(frame->priv.xdg_surface); libdecor_plugin_gtk_frame_free(frame); - free(frame_priv->state.title); - free(frame_priv->state.app_id); - - free(frame_priv); + free(frame->priv.state.title); + free(frame->priv.state.app_id); free(frame); } } -void * -libdecor_frame_get_user_data(struct libdecor_frame *frame) -{ - return frame->priv->user_data; -} - -void -libdecor_frame_set_user_data(struct libdecor_frame *frame, void *user_data) -{ - frame->priv->user_data = user_data; -} - void libdecor_frame_set_visibility(struct libdecor_frame *frame, bool visible) { - struct libdecor_frame_private *frame_priv = frame->priv; - - frame_priv->visible = visible; + frame->priv.visible = visible; /* enable/disable decorations that are managed by the compositor. * Note that, as of xdg_decoration v1, this is just a hint and there is @@ -1141,17 +1121,17 @@ libdecor_frame_set_visibility(struct libdecor_frame *frame, * See also: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/17 */ if (ctx.decoration_manager && - frame_priv->toplevel_decoration && - frame_priv->has_decoration_mode && - frame_priv->decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) { - zxdg_toplevel_decoration_v1_set_mode(frame_priv->toplevel_decoration, - frame->priv->visible + frame->priv.toplevel_decoration && + frame->priv.has_decoration_mode && + frame->priv.decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) { + zxdg_toplevel_decoration_v1_set_mode(frame->priv.toplevel_decoration, + frame->priv.visible ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE : ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); } - if (frame_priv->content_width <= 0 || - frame_priv->content_height <= 0) + if (frame->priv.content_width <= 0 || + frame->priv.content_height <= 0) return; /* enable/disable decorations that are managed by a plugin */ @@ -1163,73 +1143,53 @@ libdecor_frame_set_visibility(struct libdecor_frame *frame, libdecor_plugin_gtk_frame_free(frame); } - frame_set_window_geometry(frame, - frame_priv->content_width, - frame_priv->content_height); + frame_set_window_geometry(frame, frame->priv.content_width, frame->priv.content_height); libdecor_frame_toplevel_commit(frame); } -bool -libdecor_frame_is_visible(struct libdecor_frame *frame) -{ - return frame->priv->visible; -} - void libdecor_frame_set_parent(struct libdecor_frame *frame, struct libdecor_frame *parent) { - struct libdecor_frame_private *frame_priv = frame->priv; - - if (!frame_priv->xdg_toplevel) + if (!frame->priv.xdg_toplevel) return; - frame_priv->state.parent = parent ? parent->priv->xdg_toplevel : NULL; + frame->priv.state.parent = ((parent != 0) ? parent->priv.xdg_toplevel : 0); - xdg_toplevel_set_parent(frame_priv->xdg_toplevel, - frame_priv->state.parent); + xdg_toplevel_set_parent(frame->priv.xdg_toplevel, frame->priv.state.parent); } void -libdecor_frame_set_title(struct libdecor_frame *frame, - const char *title) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - if (!STREQL(frame_priv->state.title, title)) { - free(frame_priv->state.title); - frame_priv->state.title = strdup(title); +libdecor_frame_set_title(struct libdecor_frame *frame, const char *title){ + if (!STREQL(frame->priv.state.title, title)){ + free(frame->priv.state.title); + frame->priv.state.title = strdup(title); - if (!frame_priv->xdg_toplevel){ + if (!frame->priv.xdg_toplevel){ return; } - xdg_toplevel_set_title(frame_priv->xdg_toplevel, title); + xdg_toplevel_set_title(frame->priv.xdg_toplevel, title); libdecor_plugin_gtk_frame_property_changed(frame); } } const char * -libdecor_frame_get_title(struct libdecor_frame *frame) -{ - return frame->priv->state.title; +libdecor_frame_get_title(struct libdecor_frame *frame){ + return frame->priv.state.title; } void -libdecor_frame_set_app_id(struct libdecor_frame *frame, - const char *app_id) -{ - struct libdecor_frame_private *frame_priv = frame->priv; +libdecor_frame_set_app_id(struct libdecor_frame *frame, const char *app_id){ + free(frame->priv.state.app_id); + frame->priv.state.app_id = strdup(app_id); - free(frame_priv->state.app_id); - frame_priv->state.app_id = strdup(app_id); - - if (!frame_priv->xdg_toplevel) + if (!frame->priv.xdg_toplevel) return; - xdg_toplevel_set_app_id(frame_priv->xdg_toplevel, app_id); + xdg_toplevel_set_app_id(frame->priv.xdg_toplevel, app_id); } static void @@ -1238,31 +1198,31 @@ notify_on_capability_change(struct libdecor_frame *frame, { struct libdecor_state *state; - if (frame->priv->capabilities == old_capabilities) + if (frame->priv.capabilities == old_capabilities) return; - if (frame->priv->content_width == 0 || - frame->priv->content_height == 0) + if (frame->priv.content_width == 0 || + frame->priv.content_height == 0) return; libdecor_plugin_gtk_frame_property_changed(frame); if (!libdecor_frame_has_capability(frame, LIBDECOR_ACTION_RESIZE)) { - frame->priv->interactive_limits = frame->priv->state.content_limits; + frame->priv.interactive_limits = frame->priv.state.content_limits; /* set fixed window size */ libdecor_frame_set_min_content_size(frame, - frame->priv->content_width, - frame->priv->content_height); + frame->priv.content_width, + frame->priv.content_height); libdecor_frame_set_max_content_size(frame, - frame->priv->content_width, - frame->priv->content_height); + frame->priv.content_width, + frame->priv.content_height); } else { /* restore old limits */ - frame->priv->state.content_limits = frame->priv->interactive_limits; + frame->priv.state.content_limits = frame->priv.interactive_limits; } - state = libdecor_state_new(frame->priv->content_width, - frame->priv->content_height); + state = libdecor_state_new(frame->priv.content_width, + frame->priv.content_height); libdecor_frame_commit(frame, state, NULL); libdecor_state_free(state); @@ -1273,11 +1233,8 @@ void libdecor_frame_set_capabilities(struct libdecor_frame *frame, enum libdecor_capabilities capabilities) { - const enum libdecor_capabilities old_capabilities = - frame->priv->capabilities; - - frame->priv->capabilities |= capabilities; - + const enum libdecor_capabilities old_capabilities = frame->priv.capabilities; + frame->priv.capabilities |= capabilities; notify_on_capability_change(frame, old_capabilities); } @@ -1285,28 +1242,23 @@ void libdecor_frame_unset_capabilities(struct libdecor_frame *frame, enum libdecor_capabilities capabilities) { - const enum libdecor_capabilities old_capabilities = - frame->priv->capabilities; - - frame->priv->capabilities &= ~capabilities; - + const enum libdecor_capabilities old_capabilities = frame->priv.capabilities; + frame->priv.capabilities &= ~capabilities; notify_on_capability_change(frame, old_capabilities); } bool libdecor_frame_has_capability(struct libdecor_frame *frame, enum libdecor_capabilities capability){ - return frame->priv->capabilities & capability; + return frame->priv.capabilities & capability; } void libdecor_frame_popup_grab(struct libdecor_frame *frame, const char *seat_name){ - struct libdecor_frame_private *frame_priv = frame->priv; libdecor_plugin_gtk_frame_popup_grab(frame, seat_name); } void libdecor_frame_popup_ungrab(struct libdecor_frame *frame, const char *seat_name){ - struct libdecor_frame_private *frame_priv = frame->priv; libdecor_plugin_gtk_frame_popup_ungrab(frame, seat_name); } @@ -1314,38 +1266,24 @@ void libdecor_frame_dismiss_popup(struct libdecor_frame *frame, const char *seat_name) { - struct libdecor_frame_private *frame_priv = frame->priv; // } void -libdecor_frame_show_window_menu(struct libdecor_frame *frame, - struct wl_seat *wl_seat, - uint32_t serial, - int x, - int y) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - if (!frame_priv->xdg_toplevel) { +libdecor_frame_show_window_menu(struct libdecor_frame *frame, struct wl_seat *wl_seat, uint32_t serial, + int x, int y){ + if (!frame->priv.xdg_toplevel) { fprintf(stderr, "Can't show window menu before being mapped\n"); return; } - - xdg_toplevel_show_window_menu(frame_priv->xdg_toplevel, - wl_seat, serial, - x, y); + xdg_toplevel_show_window_menu(frame->priv.xdg_toplevel, wl_seat, serial, x, y); } void libdecor_frame_translate_coordinate(struct libdecor_frame *frame, - int content_x, - int content_y, - int *frame_x, - int *frame_y) + int content_x, int content_y, + int *frame_x, int *frame_y) { - struct libdecor_frame_private *frame_priv = frame->priv; - *frame_x = content_x; *frame_y = content_y; @@ -1358,53 +1296,32 @@ 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) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - frame_priv->state.content_limits.min_width = content_width; - frame_priv->state.content_limits.min_height = content_height; +libdecor_frame_set_min_content_size(struct libdecor_frame *frame, int content_width, int content_height){ + frame->priv.state.content_limits.min_width = content_width; + frame->priv.state.content_limits.min_height = content_height; } void -libdecor_frame_set_max_content_size(struct libdecor_frame *frame, - int content_width, - int content_height) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - frame_priv->state.content_limits.max_width = content_width; - frame_priv->state.content_limits.max_height = content_height; +libdecor_frame_set_max_content_size(struct libdecor_frame *frame, int content_width, int content_height){ + frame->priv.state.content_limits.max_width = content_width; + frame->priv.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) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - *content_width = frame_priv->state.content_limits.min_width; - *content_height = frame_priv->state.content_limits.min_height; +libdecor_frame_get_min_content_size(const struct libdecor_frame *frame, int *content_width, int *content_height){ + *content_width = frame->priv.state.content_limits.min_width; + *content_height = frame->priv.state.content_limits.min_height; } void -libdecor_frame_get_max_content_size(const struct libdecor_frame *frame, - int *content_width, - int *content_height) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - *content_width = frame_priv->state.content_limits.max_width; - *content_height = frame_priv->state.content_limits.max_height; +libdecor_frame_get_max_content_size(const struct libdecor_frame *frame, int *content_width, int *content_height){ + *content_width = frame->priv.state.content_limits.max_width; + *content_height = frame->priv.state.content_limits.max_height; } enum libdecor_capabilities -libdecor_frame_get_capabilities(const struct libdecor_frame *frame) -{ - return frame->priv->capabilities; +libdecor_frame_get_capabilities(const struct libdecor_frame *frame){ + return frame->priv.capabilities; } enum xdg_toplevel_resize_edge @@ -1435,97 +1352,82 @@ edge_to_xdg_edge(enum libdecor_resize_edge edge) } void -libdecor_frame_resize(struct libdecor_frame *frame, - struct wl_seat *wl_seat, - uint32_t serial, - enum libdecor_resize_edge edge) -{ - struct libdecor_frame_private *frame_priv = frame->priv; +libdecor_frame_resize(struct libdecor_frame *frame, struct wl_seat *wl_seat, + uint32_t serial, enum libdecor_resize_edge edge){ enum xdg_toplevel_resize_edge xdg_edge; - xdg_edge = edge_to_xdg_edge(edge); - xdg_toplevel_resize(frame_priv->xdg_toplevel, - wl_seat, serial, xdg_edge); + xdg_toplevel_resize(frame->priv.xdg_toplevel, wl_seat, serial, xdg_edge); } void -libdecor_frame_move(struct libdecor_frame *frame, - struct wl_seat *wl_seat, - uint32_t serial) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - xdg_toplevel_move(frame_priv->xdg_toplevel, wl_seat, serial); +libdecor_frame_move(struct libdecor_frame *frame, struct wl_seat *wl_seat, uint32_t serial){ + xdg_toplevel_move(frame->priv.xdg_toplevel, wl_seat, serial); } void libdecor_frame_set_minimized(struct libdecor_frame *frame) { - xdg_toplevel_set_minimized(frame->priv->xdg_toplevel); + xdg_toplevel_set_minimized(frame->priv.xdg_toplevel); } void libdecor_frame_set_maximized(struct libdecor_frame *frame) { - xdg_toplevel_set_maximized(frame->priv->xdg_toplevel); + xdg_toplevel_set_maximized(frame->priv.xdg_toplevel); } void libdecor_frame_unset_maximized(struct libdecor_frame *frame) { - xdg_toplevel_unset_maximized(frame->priv->xdg_toplevel); + xdg_toplevel_unset_maximized(frame->priv.xdg_toplevel); } void libdecor_frame_set_fullscreen(struct libdecor_frame *frame, struct wl_output *output) { - xdg_toplevel_set_fullscreen(frame->priv->xdg_toplevel, output); + xdg_toplevel_set_fullscreen(frame->priv.xdg_toplevel, output); } void libdecor_frame_unset_fullscreen(struct libdecor_frame *frame) { - xdg_toplevel_unset_fullscreen(frame->priv->xdg_toplevel); + xdg_toplevel_unset_fullscreen(frame->priv.xdg_toplevel); } bool libdecor_frame_is_floating(struct libdecor_frame *frame) { - return state_is_floating(frame->priv->window_state); + return state_is_floating(frame->priv.window_state); } void libdecor_frame_close(struct libdecor_frame *frame) { - xdg_toplevel_close(frame, frame->priv->xdg_toplevel); + xdg_toplevel_close(frame, frame->priv.xdg_toplevel); } bool -valid_limits(struct libdecor_frame_private *frame_priv) +valid_limits(struct libdecor_frame *frame) { - if (frame_priv->state.content_limits.min_width > 0 && - frame_priv->state.content_limits.max_width > 0 && - frame_priv->state.content_limits.min_width > - frame_priv->state.content_limits.max_width) + if (frame->priv.state.content_limits.min_width > 0 && + frame->priv.state.content_limits.max_width > 0 && + frame->priv.state.content_limits.min_width > + frame->priv.state.content_limits.max_width) return false; - if (frame_priv->state.content_limits.min_height > 0 && - frame_priv->state.content_limits.max_height > 0 && - frame_priv->state.content_limits.min_height > - frame_priv->state.content_limits.max_height) + if (frame->priv.state.content_limits.min_height > 0 && + frame->priv.state.content_limits.max_height > 0 && + frame->priv.state.content_limits.min_height > + frame->priv.state.content_limits.max_height) return false; return true; } static void -libdecor_frame_apply_limits(struct libdecor_frame *frame, - enum libdecor_window_state window_state) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - if (!valid_limits(frame_priv)) { +libdecor_frame_apply_limits(struct libdecor_frame *frame, enum libdecor_window_state window_state){ + if (!valid_limits(frame)) { ctx.has_error = true; } @@ -1533,121 +1435,101 @@ libdecor_frame_apply_limits(struct libdecor_frame *frame, * 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)) { - frame_priv->state.content_limits.min_width = - frame_priv->content_width; - frame_priv->state.content_limits.max_width = - frame_priv->content_width; + frame->priv.state.content_limits.min_width = frame->priv.content_width; + frame->priv.state.content_limits.max_width = frame->priv.content_width; - frame_priv->state.content_limits.min_height = - frame_priv->content_height; - frame_priv->state.content_limits.max_height = - frame_priv->content_height; + frame->priv.state.content_limits.min_height = frame->priv.content_height; + frame->priv.state.content_limits.max_height = frame->priv.content_height; } - if (frame_priv->state.content_limits.min_width > 0 && - frame_priv->state.content_limits.min_height > 0) { + if (frame->priv.state.content_limits.min_width > 0 && + frame->priv.state.content_limits.min_height > 0) { struct libdecor_state state_min; int win_min_width, win_min_height; - state_min.content_width = frame_priv->state.content_limits.min_width; - state_min.content_height = frame_priv->state.content_limits.min_height; + state_min.content_width = frame->priv.state.content_limits.min_width; + state_min.content_height = frame->priv.state.content_limits.min_height; state_min.window_state = window_state; frame_get_window_size_for(frame, &state_min, &win_min_width, &win_min_height); - xdg_toplevel_set_min_size(frame_priv->xdg_toplevel, + xdg_toplevel_set_min_size(frame->priv.xdg_toplevel, win_min_width, win_min_height); } else { - xdg_toplevel_set_min_size(frame_priv->xdg_toplevel, 0, 0); + xdg_toplevel_set_min_size(frame->priv.xdg_toplevel, 0, 0); } - if (frame_priv->state.content_limits.max_width > 0 && - frame_priv->state.content_limits.max_height > 0) { + if (frame->priv.state.content_limits.max_width > 0 && + frame->priv.state.content_limits.max_height > 0) { struct libdecor_state state_max; int win_max_width, win_max_height; - state_max.content_width = frame_priv->state.content_limits.max_width; - state_max.content_height = frame_priv->state.content_limits.max_height; + state_max.content_width = frame->priv.state.content_limits.max_width; + state_max.content_height = frame->priv.state.content_limits.max_height; state_max.window_state = window_state; frame_get_window_size_for(frame, &state_max, &win_max_width, &win_max_height); - xdg_toplevel_set_max_size(frame_priv->xdg_toplevel, + xdg_toplevel_set_max_size(frame->priv.xdg_toplevel, win_max_width, win_max_height); } else { - xdg_toplevel_set_max_size(frame_priv->xdg_toplevel, 0, 0); + xdg_toplevel_set_max_size(frame->priv.xdg_toplevel, 0, 0); } } static void -libdecor_frame_apply_state(struct libdecor_frame *frame, - struct libdecor_state *state) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - frame_priv->content_width = state->content_width; - frame_priv->content_height = state->content_height; - +libdecor_frame_apply_state(struct libdecor_frame *frame, struct libdecor_state *state){ + frame->priv.content_width = state->content_width; + frame->priv.content_height = state->content_height; libdecor_frame_apply_limits(frame, state->window_state); } void -libdecor_frame_toplevel_commit(struct libdecor_frame *frame) -{ - struct libdecor_frame_private *frame_priv = frame->priv; +libdecor_frame_toplevel_commit(struct libdecor_frame *frame){ wl_surface_commit(ctx.wl_surface); } void -libdecor_frame_commit(struct libdecor_frame *frame, - struct libdecor_state *state, - struct libdecor_configuration *configuration) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - if (configuration && configuration->has_window_state) { - frame_priv->window_state = configuration->window_state; +libdecor_frame_commit(struct libdecor_frame *frame, struct libdecor_state *state, + struct libdecor_configuration *configuration){ + if (configuration && configuration->has_window_state){ + frame->priv.window_state = configuration->window_state; state->window_state = configuration->window_state; - } else { - state->window_state = frame_priv->window_state; + } + else{ + state->window_state = frame->priv.window_state; } libdecor_frame_apply_state(frame, state); /* switch between decoration modes */ - if (frame_has_visible_client_side_decoration(frame)) { + if (frame_has_visible_client_side_decoration(frame)){ libdecor_plugin_gtk_frame_commit(frame, state, configuration); - } else { + } + else{ libdecor_plugin_gtk_frame_free(frame); } - frame_set_window_geometry(frame, - frame_priv->content_width, - frame_priv->content_height); + frame_set_window_geometry(frame, frame->priv.content_width, frame->priv.content_height); - if (configuration) { - xdg_surface_ack_configure(frame_priv->xdg_surface, - configuration->serial); + if (configuration){ + xdg_surface_ack_configure(frame->priv.xdg_surface, configuration->serial); } } static void do_map(struct libdecor_frame *frame) { - struct libdecor_frame_private *frame_priv = frame->priv; - - frame_priv->pending_map = false; - wl_surface_commit(frame_priv->wl_surface); + frame->priv.pending_map = false; + wl_surface_commit(frame->priv.wl_surface); } void libdecor_frame_map(struct libdecor_frame *frame) { - struct libdecor_frame_private *frame_priv = frame->priv; - - if (!frame_priv->xdg_surface) { - frame_priv->pending_map = true; + if (!frame->priv.xdg_surface) { + frame->priv.pending_map = true; return; } @@ -1655,64 +1537,42 @@ libdecor_frame_map(struct libdecor_frame *frame) } struct wl_surface * -libdecor_frame_get_wl_surface(struct libdecor_frame *frame) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - return frame_priv->wl_surface; +libdecor_frame_get_wl_surface(struct libdecor_frame *frame){ + return frame->priv.wl_surface; } struct xdg_surface * -libdecor_frame_get_xdg_surface(struct libdecor_frame *frame) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - return frame_priv->xdg_surface; +libdecor_frame_get_xdg_surface(struct libdecor_frame *frame){ + return frame->priv.xdg_surface; } struct xdg_toplevel * -libdecor_frame_get_xdg_toplevel(struct libdecor_frame *frame) -{ - return frame->priv->xdg_toplevel; +libdecor_frame_get_xdg_toplevel(struct libdecor_frame *frame){ + return frame->priv.xdg_toplevel; } int -libdecor_frame_get_content_width(struct libdecor_frame *frame) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - return frame_priv->content_width; +libdecor_frame_get_content_width(struct libdecor_frame *frame){ + return frame->priv.content_width; } int -libdecor_frame_get_content_height(struct libdecor_frame *frame) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - return frame_priv->content_height; +libdecor_frame_get_content_height(struct libdecor_frame *frame){ + return frame->priv.content_height; } enum libdecor_window_state -libdecor_frame_get_window_state(struct libdecor_frame *frame) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - return frame_priv->window_state; +libdecor_frame_get_window_state(struct libdecor_frame *frame){ + return frame->priv.window_state; } enum libdecor_wm_capabilities -libdecor_frame_get_wm_capabilities(struct libdecor_frame *frame) -{ - struct libdecor_frame_private *frame_priv = frame->priv; - - return frame_priv->wm_capabilities; +libdecor_frame_get_wm_capabilities(struct libdecor_frame *frame){ + return frame->priv.wm_capabilities; } static void -xdg_wm_base_ping(void *user_data, - struct xdg_wm_base *xdg_wm_base, - uint32_t serial) -{ +xdg_wm_base_ping(void *user_data, struct xdg_wm_base *xdg_wm_base, uint32_t serial){ xdg_wm_base_pong(xdg_wm_base, serial); } @@ -2318,31 +2178,6 @@ libdecor_plugin_gtk_destroy(void) } } -static struct libdecor_frame_gtk * -libdecor_frame_gtk_new(void){ - struct libdecor_frame_gtk *frame_gtk = calloc(1, sizeof *frame_gtk); - cairo_t *cr; - - static const int size = 128; - static const int boundary = 32; - - frame_gtk->shadow_blur = cairo_image_surface_create( - CAIRO_FORMAT_ARGB32, size, size); - wl_list_insert(&ctx.visible_frame_list, &frame_gtk->link); - - cr = cairo_create(frame_gtk->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(frame_gtk->shadow_blur, 64); - - return frame_gtk; -} - static int libdecor_plugin_gtk_get_fd(void){ return wl_display_get_fd(ctx.wl_display); @@ -2392,13 +2227,6 @@ libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor){ ctx.handle_cursor = handle_cursor; } -static struct libdecor_frame * -libdecor_plugin_gtk_frame_new(void){ - struct libdecor_frame_gtk *frame_gtk; - frame_gtk = libdecor_frame_gtk_new(); - return &frame_gtk->frame; -} - static void toggle_maximized(struct libdecor_frame *const frame) { diff --git a/digesting_libdecor.h b/digesting_libdecor.h index 8f32cd3..f3ef396 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -115,21 +115,6 @@ enum libdecor_wm_capabilities { // libdecor-plugin.h -struct libdecor_frame_private; -struct libdecor_frame { - struct libdecor_frame_private *priv; - struct wl_list link; -}; - -// #include "libdecor.c" - -struct libdecor_state { - enum libdecor_window_state window_state; - - int content_width; - int content_height; -}; - struct libdecor_limits { int min_width; int min_height; @@ -137,17 +122,6 @@ struct libdecor_limits { int max_height; }; -struct libdecor_configuration { - uint32_t serial; - - bool has_window_state; - enum libdecor_window_state window_state; - - bool has_size; - int window_width; - int window_height; -}; - struct libdecor_frame_private { int ref_count; @@ -188,6 +162,31 @@ struct libdecor_frame_private { bool visible; }; +struct libdecor_frame { + struct libdecor_frame_private priv; + struct wl_list link; +}; + +// #include "libdecor.c" + +struct libdecor_state { + enum libdecor_window_state window_state; + + int content_width; + int content_height; +}; + +struct libdecor_configuration { + uint32_t serial; + + bool has_window_state; + enum libdecor_window_state window_state; + + bool has_size; + int window_width; + int window_height; +}; + // #include "desktop-settings.h" enum libdecor_color_scheme { @@ -376,11 +375,8 @@ enum titlebar_gesture { // libdecor.h void libdecor_frame_ref(struct libdecor_frame *frame); void libdecor_frame_unref(struct libdecor_frame *frame); -void *libdecor_frame_get_user_data(struct libdecor_frame *frame); -void libdecor_frame_set_user_data(struct libdecor_frame *frame, void *user_data); void libdecor_frame_set_visibility(struct libdecor_frame *frame, bool visible); -bool libdecor_frame_is_visible(struct libdecor_frame *frame); void libdecor_frame_set_parent(struct libdecor_frame *frame, struct libdecor_frame *parent); @@ -513,7 +509,6 @@ static int libdecor_plugin_gtk_get_fd(void); static int libdecor_plugin_gtk_get_fd(void); static int libdecor_plugin_gtk_dispatch(int timeout); static void libdecor_plugin_gtk_set_handle_application_cursor(bool handle_cursor); -static struct libdecor_frame * libdecor_plugin_gtk_frame_new(void); 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);