From e556f5aa26b277310ac11399a7799302f05f8376 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 27 Feb 2026 14:08:10 -0800 Subject: [PATCH] [digesting_libdecor] eliminate frame poitner pass throughs everywhere --- digesting_libdecor.c | 593 ++++++++++++++++++------------------------- digesting_libdecor.h | 80 ++---- 2 files changed, 268 insertions(+), 405 deletions(-) diff --git a/digesting_libdecor.c b/digesting_libdecor.c index 079575e..25fd8db 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -407,8 +407,6 @@ int main(){ } if (ctx.wl_surface != 0){ - ctx.frame = calloc(1, sizeof *ctx.frame); - { static const int size = 128; static const int boundary = 32; @@ -434,29 +432,27 @@ int main(){ ctx.visible = true; - set_capabilities(ctx.frame, (LIBDECOR_ACTION_MOVE | - LIBDECOR_ACTION_RESIZE | - LIBDECOR_ACTION_MINIMIZE | - LIBDECOR_ACTION_FULLSCREEN | - LIBDECOR_ACTION_CLOSE)); + set_capabilities(LIBDECOR_ACTION_MOVE | + LIBDECOR_ACTION_RESIZE | + LIBDECOR_ACTION_MINIMIZE | + LIBDECOR_ACTION_FULLSCREEN | + LIBDECOR_ACTION_CLOSE); ctx.xdg_surface = xdg_wm_base_get_xdg_surface(ctx.xdg_wm_base, ctx.wl_surface); - xdg_surface_add_listener(ctx.xdg_surface, &xdg_surface_listener, ctx.frame); + xdg_surface_add_listener(ctx.xdg_surface, &xdg_surface_listener, 0); ctx.xdg_toplevel = xdg_surface_get_toplevel(ctx.xdg_surface); - xdg_toplevel_add_listener(ctx.xdg_toplevel, &xdg_toplevel_listener, ctx.frame); + xdg_toplevel_add_listener(ctx.xdg_toplevel, &xdg_toplevel_listener, 0); ctx.decoration_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; ctx.toplevel_decoration = 0; if (ctx.decoration_manager != 0){ ctx.toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(ctx.decoration_manager, ctx.xdg_toplevel); - zxdg_toplevel_decoration_v1_add_listener(ctx.toplevel_decoration, &xdg_toplevel_decoration_listener, ctx.frame); + zxdg_toplevel_decoration_v1_add_listener(ctx.toplevel_decoration, &xdg_toplevel_decoration_listener, 0); } - } - - if (ctx.frame != 0){ - libdecor_frame_set_app_id(ctx.frame, "demo"); - libdecor_frame_set_title(ctx.frame, "Example Window"); + + libdecor_frame_set_app_id("demo"); + libdecor_frame_set_title("Example Window"); ctx.content_limits.min_width = 80; ctx.content_limits.min_height = 60; @@ -553,7 +549,7 @@ int main(){ if (ctx.has_cached_config){ ctx.has_cached_config = 0; - libdecor_frame_commit(ctx.frame, ctx.w, ctx.h, &ctx.cached_config); + libdecor_frame_commit(ctx.w, ctx.h, &ctx.cached_config); } /* (nodocs-wl_egl) */ @@ -633,7 +629,7 @@ state_is_floating(enum libdecor_window_state window_state){ } static void -constrain_content_size(const struct libdecor_frame *frame, int *width, int *height){ +constrain_content_size(int *width, int *height){ const struct libdecor_limits lim = ctx.content_limits; if (lim.min_width > 0) @@ -648,7 +644,7 @@ constrain_content_size(const struct libdecor_frame *frame, int *width, int *heig } static bool -frame_has_visible_client_side_decoration(struct libdecor_frame *frame){ +frame_has_visible_client_side_decoration(void){ return(ctx.visible != 0 && ctx.decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); } @@ -664,17 +660,13 @@ libdecor_configuration_new(void) } static bool -frame_get_window_size_for(struct libdecor_frame *frame, - struct libdecor_state *state, - int *window_width, - int *window_height) -{ +frame_get_window_size_for(struct libdecor_state *state, int *window_width, int *window_height){ *window_width = state->content_width; *window_height = state->content_height; - if (frame_has_visible_client_side_decoration(frame)) { + if (frame_has_visible_client_side_decoration()) { int left, right, top, bottom; - if (!libdecor_plugin_gtk_frame_get_border_size(frame, NULL, &left, &right, &top, &bottom)){ + if (!libdecor_plugin_gtk_frame_get_border_size(0, &left, &right, &top, &bottom)){ return false; } *window_width += left + right; @@ -685,13 +677,12 @@ frame_get_window_size_for(struct libdecor_frame *frame, } static void -frame_set_window_geometry(struct libdecor_frame *frame, - int32_t content_width, int32_t content_height){ +frame_set_window_geometry(int32_t content_width, int32_t content_height){ int x, y, width, height; int left, right, top, bottom; - if (frame_has_visible_client_side_decoration(frame) && - libdecor_plugin_gtk_frame_get_border_size(frame, NULL, &left, &right, &top, &bottom)){ + if (frame_has_visible_client_side_decoration() && + libdecor_plugin_gtk_frame_get_border_size(0, &left, &right, &top, &bottom)){ x = -left; y = -top; width = content_width + left + right; @@ -708,11 +699,7 @@ frame_set_window_geometry(struct libdecor_frame *frame, } bool -libdecor_configuration_get_content_size(struct libdecor_configuration *configuration, - struct libdecor_frame *frame, - int *width, - int *height) -{ +libdecor_configuration_get_content_size(struct libdecor_configuration *configuration, int *width, int *height){ /* get configured toplevel dimensions */ if (!configuration->has_size) return false; @@ -724,12 +711,12 @@ libdecor_configuration_get_content_size(struct libdecor_configuration *configura *height = configuration->window_height; /* remove plugin-specific border size */ - if (frame_has_visible_client_side_decoration(frame)) { + if (frame_has_visible_client_side_decoration()) { int left, right, top, bottom; /* Update window state for correct border size calculation */ ctx.frame_window_state = configuration->window_state; - if (!libdecor_plugin_gtk_frame_get_border_size(frame, configuration, &left, &right, &top, &bottom)){ + if (!libdecor_plugin_gtk_frame_get_border_size(configuration, &left, &right, &top, &bottom)){ return false; } @@ -739,7 +726,7 @@ libdecor_configuration_get_content_size(struct libdecor_configuration *configura /* constrain content dimensions manually */ if (state_is_floating(configuration->window_state)) { - constrain_content_size(frame, width, height); + constrain_content_size(width, height); } return true; @@ -758,7 +745,6 @@ 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_configuration *configuration; configuration = ctx.pending_configuration; @@ -772,13 +758,13 @@ xdg_surface_configure(void *user_data, struct xdg_surface *xdg_surface, uint32_t { int w = ctx.w; int h = ctx.h; - if (libdecor_configuration_get_content_size(configuration, frame, &w, &h)){ + if (libdecor_configuration_get_content_size(configuration, &w, &h)){ ctx.w = w; ctx.h = h; } if (!ctx.configured){ ctx.configured = 1; - libdecor_frame_commit(frame, w, h, configuration); + libdecor_frame_commit(w, h, configuration); } else{ ctx.has_cached_config = 1; @@ -860,7 +846,6 @@ xdg_toplevel_configure(void *user_data, int32_t height, struct wl_array *states) { - struct libdecor_frame *frame = user_data; enum libdecor_window_state window_state; window_state = parse_states(states); @@ -880,16 +865,11 @@ xdg_toplevel_close(void *user_data, struct xdg_toplevel *xdg_toplevel){ #ifdef XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION static void -xdg_toplevel_configure_bounds(void *user_data, - struct xdg_toplevel *xdg_toplevel, - int32_t width, - int32_t height) -{ - struct libdecor_frame *frame = user_data; +xdg_toplevel_configure_bounds(void *user_data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height){ int left = 0, top = 0, right = 0, bottom = 0; - if (frame_has_visible_client_side_decoration(frame)) { - libdecor_plugin_gtk_frame_get_border_size(frame, NULL, &left, &right, &top, &bottom); + if (frame_has_visible_client_side_decoration()){ + libdecor_plugin_gtk_frame_get_border_size(0, &left, &right, &top, &bottom); } width -= left + right; @@ -903,7 +883,6 @@ static void xdg_toplevel_wm_capabilities(void *user_data, struct xdg_toplevel *xdg_toplevel, struct wl_array *capabilities){ - struct libdecor_frame *frame = user_data; enum xdg_toplevel_wm_capabilities *wm_cap; ctx.wm_capabilities = 0; @@ -948,7 +927,6 @@ toplevel_decoration_configure(void *data, struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, uint32_t mode) { - struct libdecor_frame *frame = (struct libdecor_frame*)data; /* Ignore any _configure calls after the first, they will be * from our set_mode call. */ if (!ctx.has_decoration_mode) { @@ -963,7 +941,7 @@ xdg_toplevel_decoration_listener = { }; void -libdecor_frame_unref(struct libdecor_frame *frame){ +libdecor_frame_unref(void){ if (ctx.decoration_manager != 0 && ctx.toplevel_decoration != 0){ zxdg_toplevel_decoration_v1_destroy(ctx.toplevel_decoration); ctx.toplevel_decoration = 0; @@ -976,15 +954,14 @@ libdecor_frame_unref(struct libdecor_frame *frame){ xdg_surface_destroy(ctx.xdg_surface); } - libdecor_plugin_gtk_frame_free(frame); + libdecor_plugin_gtk_frame_free(); free(ctx.title); free(ctx.app_id); - free(frame); } void -libdecor_frame_set_visibility(struct libdecor_frame *frame, bool visible){ +libdecor_frame_set_visibility(bool visible){ ctx.visible = visible; /* enable/disable decorations that are managed by the compositor. @@ -1007,30 +984,30 @@ libdecor_frame_set_visibility(struct libdecor_frame *frame, bool visible){ if (ctx.frame_content_width > 0 && ctx.frame_content_height > 0){ /* enable/disable decorations that are managed by a plugin */ - if (frame_has_visible_client_side_decoration(frame)){ + if (frame_has_visible_client_side_decoration()){ /* show client-side decorations */ - libdecor_plugin_gtk_frame_commit(frame, NULL, NULL); + libdecor_plugin_gtk_frame_commit(0, 0); } else{ /* destroy client-side decorations */ - libdecor_plugin_gtk_frame_free(frame); + libdecor_plugin_gtk_frame_free(); } - frame_set_window_geometry(frame, ctx.frame_content_width, ctx.frame_content_height); + frame_set_window_geometry(ctx.frame_content_width, ctx.frame_content_height); wl_surface_commit(ctx.wl_surface); } } void -libdecor_frame_set_title(struct libdecor_frame *frame, const char *title){ +libdecor_frame_set_title(const char *title){ if (!STREQL(ctx.title, title)){ free(ctx.title); ctx.title = strdup(title); if (ctx.xdg_toplevel != 0){ xdg_toplevel_set_title(ctx.xdg_toplevel, title); if (GTK_IS_WIDGET(ctx.header)){ - draw_decoration(frame); + draw_decoration(); wl_surface_commit(ctx.wl_surface); } } @@ -1038,7 +1015,7 @@ libdecor_frame_set_title(struct libdecor_frame *frame, const char *title){ } void -libdecor_frame_set_app_id(struct libdecor_frame *frame, const char *app_id){ +libdecor_frame_set_app_id(const char *app_id){ free(ctx.app_id); ctx.app_id = strdup(app_id); @@ -1048,7 +1025,7 @@ libdecor_frame_set_app_id(struct libdecor_frame *frame, const char *app_id){ } static void -set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities new_capabilities){ +set_capabilities(const enum libdecor_capabilities new_capabilities){ struct libdecor_state *state; if (ctx.frame_capabilities != new_capabilities){ @@ -1058,7 +1035,7 @@ set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities ctx.gtk_capabilities = ctx.frame_capabilities; if (GTK_IS_WIDGET(ctx.header)){ - draw_decoration(frame); + draw_decoration(); wl_surface_commit(ctx.wl_surface); } @@ -1073,7 +1050,7 @@ set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities ctx.content_limits = ctx.interactive_limits; } - libdecor_frame_commit(frame, ctx.frame_content_width, ctx.frame_content_height, 0); + libdecor_frame_commit(ctx.frame_content_width, ctx.frame_content_height, 0); wl_surface_commit(ctx.wl_surface); } @@ -1081,30 +1058,30 @@ set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities } void -libdecor_frame_popup_grab(struct libdecor_frame *frame, const char *seat_name){ - libdecor_plugin_gtk_frame_popup_grab(frame, seat_name); +libdecor_frame_popup_grab(const char *seat_name){ + libdecor_plugin_gtk_frame_popup_grab(seat_name); } void -libdecor_frame_popup_ungrab(struct libdecor_frame *frame, const char *seat_name){ - libdecor_plugin_gtk_frame_popup_ungrab(frame, seat_name); +libdecor_frame_popup_ungrab(const char *seat_name){ + libdecor_plugin_gtk_frame_popup_ungrab(seat_name); } void -libdecor_frame_show_window_menu(struct libdecor_frame *frame, struct wl_seat *wl_seat, uint32_t serial, int x, int y){ +libdecor_frame_show_window_menu(struct wl_seat *wl_seat, uint32_t serial, int x, int y){ if (ctx.xdg_toplevel != 0){ xdg_toplevel_show_window_menu(ctx.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){ +libdecor_frame_translate_coordinate(int content_x, int content_y, int *frame_x, int *frame_y){ *frame_x = content_x; *frame_y = content_y; - if (frame_has_visible_client_side_decoration(frame)){ + if (frame_has_visible_client_side_decoration()){ int left, top; - libdecor_plugin_gtk_frame_get_border_size(frame, NULL, &left, NULL, &top, NULL); + libdecor_plugin_gtk_frame_get_border_size(0, &left, 0, &top, 0); *frame_x += left; *frame_y += top; } @@ -1138,36 +1115,34 @@ 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){ +libdecor_frame_resize(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(ctx.xdg_toplevel, wl_seat, serial, xdg_edge); } void -libdecor_frame_move(struct libdecor_frame *frame, struct wl_seat *wl_seat, uint32_t serial){ +libdecor_frame_move(struct wl_seat *wl_seat, uint32_t serial){ xdg_toplevel_move(ctx.xdg_toplevel, wl_seat, serial); } void -libdecor_frame_set_fullscreen(struct libdecor_frame *frame, struct wl_output *output){ +libdecor_frame_set_fullscreen(struct wl_output *output){ xdg_toplevel_set_fullscreen(ctx.xdg_toplevel, output); } void -libdecor_frame_unset_fullscreen(struct libdecor_frame *frame){ +libdecor_frame_unset_fullscreen(void){ xdg_toplevel_unset_fullscreen(ctx.xdg_toplevel); } bool -libdecor_frame_is_floating(struct libdecor_frame *frame){ +libdecor_frame_is_floating(void){ return state_is_floating(ctx.frame_window_state); } bool -valid_limits(struct libdecor_frame *frame) -{ +valid_limits(void){ if (ctx.content_limits.min_width > 0 && ctx.content_limits.max_width > 0 && ctx.content_limits.min_width > @@ -1184,8 +1159,8 @@ valid_limits(struct libdecor_frame *frame) } static void -libdecor_frame_apply_limits(struct libdecor_frame *frame, enum libdecor_window_state window_state){ - if (!valid_limits(frame)) { +libdecor_frame_apply_limits(enum libdecor_window_state window_state){ + if (!valid_limits()){ ctx.has_error = true; } @@ -1208,7 +1183,7 @@ libdecor_frame_apply_limits(struct libdecor_frame *frame, enum libdecor_window_s state_min.content_height = ctx.content_limits.min_height; state_min.window_state = window_state; - frame_get_window_size_for(frame, &state_min, &win_min_width, &win_min_height); + frame_get_window_size_for(&state_min, &win_min_width, &win_min_height); xdg_toplevel_set_min_size(ctx.xdg_toplevel, win_min_width, win_min_height); } else{ @@ -1224,7 +1199,7 @@ libdecor_frame_apply_limits(struct libdecor_frame *frame, enum libdecor_window_s state_max.content_height = ctx.content_limits.max_height; state_max.window_state = window_state; - frame_get_window_size_for(frame, &state_max, &win_max_width, &win_max_height); + frame_get_window_size_for(&state_max, &win_max_width, &win_max_height); xdg_toplevel_set_max_size(ctx.xdg_toplevel, win_max_width, win_max_height); } else{ @@ -1233,15 +1208,14 @@ libdecor_frame_apply_limits(struct libdecor_frame *frame, enum libdecor_window_s } static void -libdecor_frame_apply_state(struct libdecor_frame *frame, struct libdecor_state *state){ +libdecor_frame_apply_state(struct libdecor_state *state){ ctx.frame_content_width = state->content_width; ctx.frame_content_height = state->content_height; - libdecor_frame_apply_limits(frame, state->window_state); + libdecor_frame_apply_limits(state->window_state); } void -libdecor_frame_commit(struct libdecor_frame *frame, int w, int h, - struct libdecor_configuration *configuration){ +libdecor_frame_commit(int w, int h, struct libdecor_configuration *configuration){ struct libdecor_state state = {0}; state.content_width = w; state.content_height = h; @@ -1254,17 +1228,17 @@ libdecor_frame_commit(struct libdecor_frame *frame, int w, int h, state.window_state = ctx.frame_window_state; } - libdecor_frame_apply_state(frame, &state); + libdecor_frame_apply_state(&state); /* switch between decoration modes */ - if (frame_has_visible_client_side_decoration(frame)){ - libdecor_plugin_gtk_frame_commit(frame, &state, configuration); + if (frame_has_visible_client_side_decoration()){ + libdecor_plugin_gtk_frame_commit(&state, configuration); } else{ - libdecor_plugin_gtk_frame_free(frame); + libdecor_plugin_gtk_frame_free(); } - frame_set_window_geometry(frame, ctx.frame_content_width, ctx.frame_content_height); + frame_set_window_geometry(ctx.frame_content_width, ctx.frame_content_height); if (configuration != 0){ xdg_surface_ack_configure(ctx.xdg_surface, configuration->serial); @@ -1800,9 +1774,7 @@ static void buffer_free(struct buffer *buffer); static void -draw_border_component(struct libdecor_frame *frame, - struct border_component *border_component, - enum component component); +draw_border_component(struct border_component *border_component, enum component component); static void send_cursor(struct seat *seat); @@ -1961,7 +1933,7 @@ free_border_component(struct border_component *border_component){ } static void -libdecor_plugin_gtk_frame_free(struct libdecor_frame *frame){ +libdecor_plugin_gtk_frame_free(void){ g_clear_pointer(&ctx.header, gtk_widget_destroy); g_clear_pointer(&ctx.window, gtk_widget_destroy); @@ -1976,7 +1948,7 @@ libdecor_plugin_gtk_frame_free(struct libdecor_frame *frame){ } static bool -is_border_surfaces_showing(struct libdecor_frame *frame){ +is_border_surfaces_showing(void){ return ctx.shadow_showing; } @@ -1989,13 +1961,13 @@ hide_border_component(struct border_component *border_component){ } static void -hide_border_surfaces(struct libdecor_frame *frame){ +hide_border_surfaces(void){ hide_border_component(&ctx.shadow); ctx.shadow_showing = false; } static struct border_component * -get_component_for_surface(struct libdecor_frame *frame, const struct wl_surface *surface){ +get_component_for_surface(const struct wl_surface *surface){ struct border_component *result = 0; if (ctx.shadow.wl_surface == surface){ result = &ctx.shadow; @@ -2007,8 +1979,7 @@ get_component_for_surface(struct libdecor_frame *frame, const struct wl_surface } static bool -redraw_scale(struct libdecor_frame *frame, struct border_component *cmpnt) -{ +redraw_scale(struct border_component *cmpnt){ struct surface_output *surface_output; int scale = 1; @@ -2021,8 +1992,8 @@ redraw_scale(struct libdecor_frame *frame, struct border_component *cmpnt) if (scale != cmpnt->scale) { cmpnt->scale = scale; if ((ctx.decoration_type != DECORATION_TYPE_NONE) && - ((cmpnt->type != SHADOW) || is_border_surfaces_showing(frame))) { - draw_border_component(frame, cmpnt, cmpnt->type); + ((cmpnt->type != SHADOW) || is_border_surfaces_showing())) { + draw_border_component(cmpnt, cmpnt->type); return true; } } @@ -2049,24 +2020,20 @@ add_surface_output(struct wl_output *wl_output, struct wl_list *list){ } static void -surface_enter(void *data, - struct wl_surface *wl_surface, - struct wl_output *wl_output) -{ - struct libdecor_frame *frame = data; +surface_enter(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output){ struct border_component *cmpnt; if (!(own_surface(wl_surface) && own_output(wl_output))) return; - cmpnt = get_component_for_surface(frame, wl_surface); + cmpnt = get_component_for_surface(wl_surface); if (cmpnt == NULL) return; if (!add_surface_output(wl_output, &cmpnt->output_list)) return; - if (redraw_scale(frame, cmpnt)){ + if (redraw_scale(cmpnt)){ wl_surface_commit(ctx.wl_surface); } } @@ -2086,24 +2053,20 @@ remove_surface_output(struct wl_list *list, const struct wl_output *wl_output) } static void -surface_leave(void *data, - struct wl_surface *wl_surface, - struct wl_output *wl_output) -{ - struct libdecor_frame *frame = data; +surface_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output){ struct border_component *cmpnt; if (!(own_surface(wl_surface) && own_output(wl_output))) return; - cmpnt = get_component_for_surface(frame, wl_surface); + cmpnt = get_component_for_surface(wl_surface); if (cmpnt == NULL) return; if (!remove_surface_output(&cmpnt->output_list, wl_output)) return; - if (redraw_scale(frame, cmpnt)){ + if (redraw_scale(cmpnt)){ wl_surface_commit(ctx.wl_surface); } } @@ -2114,9 +2077,7 @@ static struct wl_surface_listener surface_listener = { }; static void -create_surface_subsurface_pair(struct libdecor_frame *frame, - struct wl_surface **out_wl_surface, - struct wl_subsurface **out_wl_subsurface){ +create_surface_subsurface_pair(struct wl_surface **out_wl_surface, struct wl_subsurface **out_wl_subsurface){ struct wl_surface *wl_surface; struct wl_subsurface *wl_subsurface; @@ -2129,29 +2090,29 @@ create_surface_subsurface_pair(struct libdecor_frame *frame, } static void -ensure_component(struct libdecor_frame *frame, struct border_component *cmpnt){ +ensure_component(struct border_component *cmpnt){ if (!cmpnt->wl_surface){ wl_list_init(&cmpnt->output_list); cmpnt->scale = 1; - create_surface_subsurface_pair(frame, &cmpnt->wl_surface, &cmpnt->wl_subsurface); - wl_surface_add_listener(cmpnt->wl_surface, &surface_listener, frame); + create_surface_subsurface_pair(&cmpnt->wl_surface, &cmpnt->wl_subsurface); + wl_surface_add_listener(cmpnt->wl_surface, &surface_listener, 0); } } static void -ensure_border_surfaces(struct libdecor_frame *frame){ +ensure_border_surfaces(void){ ctx.shadow.type = SHADOW; ctx.shadow.opaque = false; - ensure_component(frame, &ctx.shadow); + ensure_component(&ctx.shadow); } static void -ensure_title_bar_surfaces(struct libdecor_frame *frame){ +ensure_title_bar_surfaces(void){ GtkStyleContext *context_hdr; ctx.headerbar.type = HEADER; ctx.headerbar.opaque = false; - ensure_component(frame, &ctx.headerbar); + ensure_component( &ctx.headerbar); if (ctx.shadow.wl_surface){ wl_subsurface_place_above(ctx.headerbar.wl_subsurface, @@ -2198,13 +2159,9 @@ ensure_title_bar_surfaces(struct libdecor_frame *frame){ } static void -calculate_component_size(struct libdecor_frame *frame, - enum component component, - int *component_x, - int *component_y, - int *component_width, - int *component_height) -{ +calculate_component_size(enum component component, + int *component_x, int *component_y, + int *component_width, int *component_height){ int content_width, content_height; content_width = ctx.frame_content_width; @@ -2252,7 +2209,7 @@ array_append(enum header_element **array, size_t *n, enum header_element item){ } static void -draw_header_background(struct libdecor_frame *frame, cairo_t *cr){ +draw_header_background(cairo_t *cr){ /* background */ GtkAllocation allocation; GtkStyleContext* style; @@ -2263,7 +2220,7 @@ draw_header_background(struct libdecor_frame *frame, cairo_t *cr){ } static void -draw_header_title(struct libdecor_frame *frame_gtk, cairo_surface_t *surface){ +draw_header_title(cairo_surface_t *surface){ /* title */ GtkWidget *label; GtkAllocation allocation; @@ -2286,12 +2243,8 @@ draw_header_title(struct libdecor_frame *frame_gtk, cairo_surface_t *surface){ } static void -draw_header_button(struct libdecor_frame *frame, - cairo_t *cr, - cairo_surface_t *surface, - enum header_element button_type, - enum libdecor_window_state window_state) -{ +draw_header_button(cairo_t *cr, cairo_surface_t *surface, + enum header_element button_type, enum libdecor_window_state window_state){ struct header_element_data elem; GtkWidget *button; GtkStyleContext* button_style; @@ -2429,7 +2382,7 @@ draw_header_button(struct libdecor_frame *frame, } static void -draw_header_buttons(struct libdecor_frame *frame, cairo_t *cr, cairo_surface_t *surface){ +draw_header_buttons(cairo_t *cr, cairo_surface_t *surface){ /* buttons */ enum libdecor_window_state window_state; enum header_element *buttons = NULL; @@ -2449,25 +2402,20 @@ draw_header_buttons(struct libdecor_frame *frame, cairo_t *cr, cairo_surface_t * } for (size_t i = 0; i < nbuttons; i++) { - draw_header_button(frame, cr, surface, buttons[i], window_state); - } /* loop buttons */ + draw_header_button(cr, surface, buttons[i], window_state); + } free(buttons); } static void -draw_header(struct libdecor_frame *frame, - cairo_t *cr, cairo_surface_t *surface){ - draw_header_background(frame, cr); - draw_header_title(frame, surface); - draw_header_buttons(frame, cr, surface); +draw_header(cairo_t *cr, cairo_surface_t *surface){ + draw_header_background(cr); + draw_header_title(surface); + draw_header_buttons(cr, surface); } static void -draw_component_content(struct libdecor_frame *frame, - struct buffer *buffer, - int component_width, - int component_height, - enum component component){ +draw_component_content(struct buffer *buffer, int component_width, int component_height, enum component component){ cairo_surface_t *surface; cairo_t *cr; @@ -2495,16 +2443,14 @@ draw_component_content(struct libdecor_frame *frame, }break; case HEADER: { - draw_header(frame, cr, surface); + draw_header(cr, surface); }break; } /* mask the toplevel surface */ if (component == SHADOW) { int component_x, component_y, component_width, component_height; - calculate_component_size(frame, component, - &component_x, &component_y, - &component_width, &component_height); + calculate_component_size(component, &component_x, &component_y, &component_width, &component_height); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_rectangle(cr, -component_x, -component_y, ctx.frame_content_width, @@ -2517,8 +2463,7 @@ draw_component_content(struct libdecor_frame *frame, } static void -set_component_input_region(struct libdecor_frame *frame, - struct border_component *border_component){ +set_component_input_region(struct border_component *border_component){ if (border_component->type == SHADOW && ctx.shadow_showing){ struct wl_region *input_region; int component_x; @@ -2526,7 +2471,7 @@ set_component_input_region(struct libdecor_frame *frame, int component_width; int component_height; - calculate_component_size(frame, border_component->type, + calculate_component_size(border_component->type, &component_x, &component_y, &component_width, &component_height); @@ -2546,9 +2491,7 @@ set_component_input_region(struct libdecor_frame *frame, } static void -draw_border_component(struct libdecor_frame *frame, - struct border_component *border_component, - enum component component){ +draw_border_component(struct border_component *border_component, enum component component){ struct buffer *old_buffer; struct buffer *buffer = NULL; int component_x; @@ -2560,11 +2503,11 @@ draw_border_component(struct libdecor_frame *frame, if (border_component->wl_surface == NULL) return; - calculate_component_size(frame, component, + calculate_component_size(component, &component_x, &component_y, &component_width, &component_height); - set_component_input_region(frame, border_component); + set_component_input_region(border_component); old_buffer = border_component->buffer; if (old_buffer){ @@ -2586,9 +2529,7 @@ draw_border_component(struct libdecor_frame *frame, border_component->scale); } - draw_component_content(frame, buffer, - component_width, component_height, - component); + draw_component_content(buffer, component_width, component_height, component); wl_surface_attach(border_component->wl_surface, buffer->wl_buffer, 0, 0); wl_surface_set_buffer_scale(border_component->wl_surface, buffer->scale); @@ -2604,13 +2545,13 @@ draw_border_component(struct libdecor_frame *frame, } static void -draw_border(struct libdecor_frame *frame){ - draw_border_component(frame, &ctx.shadow, SHADOW); +draw_border(void){ + draw_border_component(&ctx.shadow, SHADOW); ctx.shadow_showing = true; } static void -draw_title_bar(struct libdecor_frame *frame){ +draw_title_bar(void){ GtkAllocation allocation = {0, 0, ctx.gtk_content_width, 0}; enum libdecor_window_state state; GtkStyleContext *style; @@ -2627,7 +2568,7 @@ draw_title_bar(struct libdecor_frame *frame){ gtk_widget_unset_state_flags(ctx.window, GTK_STATE_FLAG_BACKDROP); } - if (libdecor_frame_is_floating(frame)){ + if (libdecor_frame_is_floating()){ gtk_style_context_remove_class(style, "maximized"); } else{ @@ -2651,42 +2592,43 @@ draw_title_bar(struct libdecor_frame *frame){ H = ctx.frame_content_height; if (W < ctx.content_limits.min_width){ W = ctx.content_limits.min_width; - libdecor_frame_commit(frame, W, H, NULL); + libdecor_frame_commit(W, H, NULL); } else{ /* set default height */ gtk_widget_get_preferred_height(ctx.header, 0, &allocation.height); gtk_widget_size_allocate(ctx.header, &allocation); - draw_border_component(frame, &ctx.headerbar, HEADER); + draw_border_component(&ctx.headerbar, HEADER); } } static void -draw_decoration(struct libdecor_frame *frame){ +draw_decoration(void){ switch (ctx.decoration_type) { case DECORATION_TYPE_NONE: { - if (is_border_surfaces_showing(frame)){ - hide_border_surfaces(frame); + if (is_border_surfaces_showing()){ + hide_border_surfaces(); } hide_border_component(&ctx.headerbar); }break; case DECORATION_TYPE_ALL: { /* show borders */ - ensure_border_surfaces(frame); - draw_border(frame); + ensure_border_surfaces(); + draw_border(); /* show title bar */ - ensure_title_bar_surfaces(frame); - draw_title_bar(frame); + ensure_title_bar_surfaces(); + draw_title_bar(); }break; case DECORATION_TYPE_TITLE_ONLY: { /* hide borders */ - if (is_border_surfaces_showing(frame)) - hide_border_surfaces(frame); + if (is_border_surfaces_showing()){ + hide_border_surfaces(); + } /* show title bar */ - ensure_title_bar_surfaces(frame); - draw_title_bar(frame); + ensure_title_bar_surfaces(); + draw_title_bar(); }break; } } @@ -2712,9 +2654,7 @@ window_state_to_decoration_type(enum libdecor_window_state window_state) } static void -libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame, - struct libdecor_state *state, - struct libdecor_configuration *configuration){ +libdecor_plugin_gtk_frame_commit(struct libdecor_state *state, struct libdecor_configuration *configuration){ enum libdecor_window_state old_window_state; enum libdecor_window_state new_window_state; int old_content_width, old_content_height; @@ -2744,7 +2684,7 @@ libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame, ctx.gtk_window_state = new_window_state; ctx.decoration_type = new_decoration_type; - draw_decoration(frame); + draw_decoration(); /* set fixed window size */ if (!(ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)){ @@ -2756,21 +2696,19 @@ libdecor_plugin_gtk_frame_commit(struct libdecor_frame *frame, } static void -update_component_focus(struct libdecor_frame *frame, struct wl_surface *surface, struct seat *seat){ +update_component_focus(struct wl_surface *surface, struct seat *seat){ static struct border_component *border_component; static struct border_component *child_component; static struct border_component *focus_component; - border_component = get_component_for_surface(frame, surface); + border_component = get_component_for_surface(surface); focus_component = border_component; wl_list_for_each(child_component, &border_component->child_components, link) { int component_x = 0, component_y = 0; int component_width = 0, component_height = 0; - calculate_component_size(frame, child_component->type, - &component_x, &component_y, - &component_width, &component_height); + calculate_component_size(child_component->type, &component_x, &component_y, &component_width, &component_height); if (seat->pointer_x >= component_x && seat->pointer_x < component_x + component_width && seat->pointer_y >= component_y && @@ -2790,42 +2728,37 @@ update_component_focus(struct libdecor_frame *frame, struct wl_surface *surface, } static void -sync_active_component(struct libdecor_frame *frame, struct seat *seat){ +sync_active_component(struct seat *seat){ struct border_component *old_active; - if (!seat->pointer_focus) - return; - - old_active = ctx.active; - update_component_focus(frame, seat->pointer_focus, seat); - if (old_active != ctx.active) { - draw_decoration(frame); - wl_surface_commit(ctx.wl_surface); - } - - if (update_local_cursor(seat)){ - send_cursor(seat); + if (seat->pointer_focus){ + old_active = ctx.active; + update_component_focus(seat->pointer_focus, seat); + if (old_active != ctx.active) { + draw_decoration(); + wl_surface_commit(ctx.wl_surface); + } + + if (update_local_cursor(seat)){ + send_cursor(seat); + } } } static void synthesize_pointer_enter(struct seat *seat){ struct wl_surface *surface; - struct libdecor_frame *frame; surface = seat->pointer_focus; if (surface && own_surface(surface)){ - frame = wl_surface_get_user_data(surface); - if (frame != 0){ - update_component_focus(frame, seat->pointer_focus, seat); - ctx.grab = 0; - if (ctx.active) { - draw_decoration(frame); - wl_surface_commit(ctx.wl_surface); - } - update_local_cursor(seat); - send_cursor(seat); + update_component_focus(seat->pointer_focus, seat); + ctx.grab = 0; + if (ctx.active) { + draw_decoration(); + wl_surface_commit(ctx.wl_surface); } + update_local_cursor(seat); + send_cursor(seat); } } @@ -2833,20 +2766,17 @@ static void synthesize_pointer_leave(struct seat *seat){ struct wl_surface *surface = seat->pointer_focus; if (surface != 0 && own_surface(surface)){ - struct libdecor_frame *frame = wl_surface_get_user_data(surface); - if (frame != 0){ - if (ctx.active != 0){ - ctx.active = 0; - draw_decoration(frame); - wl_surface_commit(ctx.wl_surface); - update_local_cursor(seat); - } + if (ctx.active != 0){ + ctx.active = 0; + draw_decoration(); + wl_surface_commit(ctx.wl_surface); + update_local_cursor(seat); } } } static void -libdecor_plugin_gtk_frame_popup_grab(struct libdecor_frame *frame, const char *seat_name){ +libdecor_plugin_gtk_frame_popup_grab(const char *seat_name){ struct seat *seat; wl_list_for_each(seat, &ctx.seat_list, link) { @@ -2864,7 +2794,7 @@ libdecor_plugin_gtk_frame_popup_grab(struct libdecor_frame *frame, const char *s } static void -libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_frame *frame, const char *seat_name){ +libdecor_plugin_gtk_frame_popup_ungrab(const char *seat_name){ struct seat *seat; wl_list_for_each(seat, &ctx.seat_list, link) { @@ -2875,7 +2805,7 @@ libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_frame *frame, const char } seat->grabbed = false; synthesize_pointer_enter(seat); - sync_active_component(frame, seat); + sync_active_component(seat); return; } } @@ -2884,7 +2814,7 @@ libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_frame *frame, const char } static bool -libdecor_plugin_gtk_frame_get_border_size(struct libdecor_frame *frame, struct libdecor_configuration *configuration, +libdecor_plugin_gtk_frame_get_border_size(struct libdecor_configuration *configuration, int *left, int *right, int *top, int *bottom){ enum libdecor_window_state window_state; @@ -2915,12 +2845,12 @@ libdecor_plugin_gtk_frame_get_border_size(struct libdecor_frame *frame, struct l }break; case DECORATION_TYPE_ALL:{ - ensure_border_surfaces(frame); + ensure_border_surfaces(); } G_GNUC_FALLTHROUGH; case DECORATION_TYPE_TITLE_ONLY: { if (!ctx.header){ - ensure_title_bar_surfaces(frame); + ensure_title_bar_surfaces(); } gtk_widget_show_all(ctx.window); gtk_widget_get_preferred_height(ctx.header, NULL, top); @@ -3064,10 +2994,9 @@ update_local_cursor(struct seat *seat){ return false; } - struct libdecor_frame *frame = wl_surface_get_user_data(seat->pointer_focus); struct wl_cursor *wl_cursor = NULL; - if (!frame || !ctx.active){ + if (!ctx.active){ seat->current_cursor = seat->cursor_left_ptr; return false; } @@ -3075,7 +3004,7 @@ update_local_cursor(struct seat *seat){ bool theme_updated = ensure_cursor_theme(seat); if (ctx.active->type == SHADOW && - is_border_surfaces_showing(frame) && + is_border_surfaces_showing() && (ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)){ enum libdecor_resize_edge edge; edge = component_edge(ctx.active, seat->pointer_x, seat->pointer_y, SHADOW_MARGIN); @@ -3122,41 +3051,29 @@ send_cursor(struct seat *seat) static void pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y){ - if (!surface) - return; - - struct seat *seat = data; - struct libdecor_frame *frame = 0; - - if (!own_surface(surface)){ - if (!ctx.handle_cursor){ - return; + if (surface){ + struct seat *seat = data; + + bool is_own_surface = own_surface(surface); + if (is_own_surface || ctx.handle_cursor){ + ensure_cursor_surface(seat); + + seat->pointer_x = wl_fixed_to_int(surface_x); + seat->pointer_y = wl_fixed_to_int(surface_y); + seat->serial = serial; + seat->pointer_focus = surface; + } + + if (is_own_surface){ + ctx.active = get_component_for_surface(surface); + if (ctx.active){ + draw_decoration(); + wl_surface_commit(ctx.wl_surface); + } + update_local_cursor(seat); + send_cursor(seat); } } - else{ - frame = wl_surface_get_user_data(surface); - } - - ensure_cursor_surface(seat); - - seat->pointer_x = wl_fixed_to_int(surface_x); - seat->pointer_y = wl_fixed_to_int(surface_y); - seat->serial = serial; - seat->pointer_focus = surface; - - if (!frame) - return; - - ctx.active = get_component_for_surface(frame, surface); - - /* update decorations */ - if (ctx.active){ - draw_decoration(frame); - wl_surface_commit(ctx.wl_surface); - } - - update_local_cursor(seat); - send_cursor(seat); } static void @@ -3166,19 +3083,15 @@ pointer_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct seat->pointer_focus = NULL; if (surface != 0 && own_surface(surface)){ - struct libdecor_frame *frame = wl_surface_get_user_data(surface); + ctx.titlebar_gesture.state = TITLEBAR_GESTURE_STATE_INIT; + ctx.titlebar_gesture.first_pressed_button = 0; - if (frame != 0){ - ctx.titlebar_gesture.state = TITLEBAR_GESTURE_STATE_INIT; - ctx.titlebar_gesture.first_pressed_button = 0; - - ctx.active = 0; - ctx.hdr_focus.widget = 0; - ctx.hdr_focus.type = HEADER_NONE; - draw_decoration(frame); - wl_surface_commit(ctx.wl_surface); - update_local_cursor(seat); - } + ctx.active = 0; + ctx.hdr_focus.widget = 0; + ctx.hdr_focus.type = HEADER_NONE; + draw_decoration(); + wl_surface_commit(ctx.wl_surface); + update_local_cursor(seat); } } @@ -3186,7 +3099,6 @@ static void pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y){ struct seat *seat = data; - struct libdecor_frame *frame; struct header_element_data new_focus; if (!seat->pointer_focus || !own_surface(seat->pointer_focus)) @@ -3198,9 +3110,8 @@ pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, send_cursor(seat); } - frame = wl_surface_get_user_data(seat->pointer_focus); /* avoid warnings after decoration has been turned off */ - if (!GTK_IS_WIDGET(ctx.header) || ctx.active->type != HEADER) { + if (!GTK_IS_WIDGET(ctx.header) || ctx.active->type != HEADER){ ctx.hdr_focus.type = HEADER_NONE; } @@ -3213,7 +3124,7 @@ pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, } ctx.hdr_focus.state |= GTK_STATE_FLAG_PRELIGHT; /* redraw with updated button visuals */ - draw_title_bar(frame); + draw_title_bar(); wl_surface_commit(ctx.wl_surface); switch (ctx.titlebar_gesture.state) { @@ -3221,7 +3132,7 @@ pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, if (ctx.titlebar_gesture.first_pressed_button == BTN_LEFT) { if (ABS((double)seat->pointer_x - (double)ctx.titlebar_gesture.pressed_x) > ctx.drag_threshold || ABS((double)seat->pointer_y - (double)ctx.titlebar_gesture.pressed_y) > ctx.drag_threshold){ - libdecor_frame_move(frame, seat->wl_seat, ctx.titlebar_gesture.pressed_serial); + libdecor_frame_move(seat->wl_seat, ctx.titlebar_gesture.pressed_serial); } } case TITLEBAR_GESTURE_STATE_INIT: @@ -3232,20 +3143,18 @@ pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, } static void -handle_button_on_shadow(struct libdecor_frame *frame, struct seat *seat, - uint32_t serial, uint32_t time, +handle_button_on_shadow(struct seat *seat, uint32_t serial, uint32_t time, uint32_t button, uint32_t state){ enum libdecor_resize_edge edge = LIBDECOR_RESIZE_EDGE_NONE; edge = component_edge(ctx.active, seat->pointer_x, seat->pointer_y, SHADOW_MARGIN); if (edge != LIBDECOR_RESIZE_EDGE_NONE && (ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)){ - libdecor_frame_resize(frame, seat->wl_seat, serial, edge); + libdecor_frame_resize(seat->wl_seat, serial, edge); } } static void -handle_titlebar_gesture(struct libdecor_frame *frame, struct seat *seat, - uint32_t serial, enum titlebar_gesture gesture){ +handle_titlebar_gesture(struct seat *seat, uint32_t serial, enum titlebar_gesture gesture){ switch (gesture){ case TITLEBAR_GESTURE_DOUBLE_CLICK: { if ((ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)){ @@ -3257,27 +3166,25 @@ handle_titlebar_gesture(struct libdecor_frame *frame, struct seat *seat, case TITLEBAR_GESTURE_RIGHT_CLICK: { const int title_height = gtk_widget_get_allocated_height(ctx.header); - libdecor_frame_show_window_menu(frame, seat->wl_seat, serial, - seat->pointer_x, seat->pointer_y -title_height); + libdecor_frame_show_window_menu(seat->wl_seat, serial, seat->pointer_x, seat->pointer_y -title_height); }break; } } static void -handle_button_on_header(struct libdecor_frame *frame, struct seat *seat, uint32_t serial, - uint32_t time, uint32_t button, uint32_t state){ +handle_button_on_header(struct seat *seat, uint32_t serial, uint32_t time, uint32_t button, uint32_t state){ switch (ctx.titlebar_gesture.state){ case TITLEBAR_GESTURE_STATE_INIT: { if (state == WL_POINTER_BUTTON_STATE_PRESSED){ if (button == BTN_RIGHT){ - handle_titlebar_gesture(frame, seat, serial, TITLEBAR_GESTURE_RIGHT_CLICK); + handle_titlebar_gesture(seat, serial, TITLEBAR_GESTURE_RIGHT_CLICK); ctx.titlebar_gesture.state = TITLEBAR_GESTURE_STATE_CONSUMED; } else{ if (button == BTN_LEFT && ctx.titlebar_gesture.first_pressed_button == BTN_LEFT && time - ctx.titlebar_gesture.first_pressed_time < (uint32_t)ctx.double_click_time_ms){ - handle_titlebar_gesture(frame, seat, serial, TITLEBAR_GESTURE_DOUBLE_CLICK); + handle_titlebar_gesture(seat, serial, TITLEBAR_GESTURE_DOUBLE_CLICK); ctx.titlebar_gesture.state = TITLEBAR_GESTURE_STATE_CONSUMED; } else{ @@ -3297,7 +3204,7 @@ handle_button_on_header(struct libdecor_frame *frame, struct seat *seat, uint32_ case HEADER_MAX: case HEADER_CLOSE: { ctx.hdr_focus.state |= GTK_STATE_FLAG_ACTIVE; - draw_title_bar(frame); + draw_title_bar(); wl_surface_commit(ctx.wl_surface); }break; @@ -3333,7 +3240,7 @@ handle_button_on_header(struct libdecor_frame *frame, struct seat *seat, uint32_ case HEADER_CLOSE: { if (ctx.frame_capabilities & LIBDECOR_ACTION_CLOSE){ - xdg_toplevel_close(frame, ctx.xdg_toplevel); + xdg_toplevel_close(0, ctx.xdg_toplevel); seat->pointer_focus = 0; } }break; @@ -3343,7 +3250,7 @@ handle_button_on_header(struct libdecor_frame *frame, struct seat *seat, uint32_ ctx.hdr_focus.state &= ~GTK_STATE_FLAG_ACTIVE; if (GTK_IS_WIDGET(ctx.header)){ - draw_title_bar(frame); + draw_title_bar(); wl_surface_commit(ctx.wl_surface); } } @@ -3351,7 +3258,7 @@ handle_button_on_header(struct libdecor_frame *frame, struct seat *seat, uint32_ else{ ctx.hdr_focus.state &= ~GTK_STATE_FLAG_ACTIVE; if (GTK_IS_WIDGET(ctx.header)) { - draw_title_bar(frame); + draw_title_bar(); wl_surface_commit(ctx.wl_surface); } } @@ -3380,21 +3287,16 @@ pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state){ struct seat *seat = data; if (seat->pointer_focus && own_surface(seat->pointer_focus)){ - struct libdecor_frame *frame = wl_surface_get_user_data(seat->pointer_focus); - if (frame != 0){ - switch (ctx.active->type) { - case SHADOW: - { - handle_button_on_shadow(frame, seat, serial, time, button, state); - }break; - - case HEADER: - { - handle_button_on_header(frame, seat, serial, time, button, state); - }break; - - default: break; - } + switch (ctx.active->type) { + case SHADOW: { + handle_button_on_shadow(seat, serial, time, button, state); + }break; + + case HEADER: { + handle_button_on_header(seat, serial, time, button, state); + }break; + + default: break; } } } @@ -3412,15 +3314,14 @@ const struct wl_pointer_listener pointer_listener = { }; static void -update_touch_focus(struct seat *seat, struct libdecor_frame *frame, - wl_fixed_t x, wl_fixed_t y){ +update_touch_focus(struct seat *seat, wl_fixed_t x, wl_fixed_t y){ if (GTK_IS_WIDGET(ctx.header) && ctx.touch_active->type == HEADER){ struct header_element_data new_focus = get_header_focus(GTK_HEADER_BAR(ctx.header), wl_fixed_to_int(x), wl_fixed_to_int(y)); if (ctx.hdr_focus.widget != new_focus.widget){ ctx.hdr_focus = new_focus; } ctx.hdr_focus.state |= GTK_STATE_FLAG_PRELIGHT; - draw_title_bar(frame); + draw_title_bar(); wl_surface_commit(ctx.wl_surface); } else{ @@ -3433,25 +3334,20 @@ touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t time, struct wl_surface *surface, int32_t id, wl_fixed_t x, wl_fixed_t y){ struct seat *seat = data; - struct libdecor_frame *frame; if (!surface || !own_surface(surface)) return; - frame = wl_surface_get_user_data(surface); - if (!frame) - return; - seat->touch_focus = surface; - ctx.touch_active = get_component_for_surface(frame, surface); + ctx.touch_active = get_component_for_surface(surface); if (!ctx.touch_active) return; - update_touch_focus(seat, frame, x, y); + update_touch_focus(seat, x, y); /* update decorations */ - draw_decoration(frame); + draw_decoration(); wl_surface_commit(ctx.wl_surface); enum libdecor_resize_edge edge = LIBDECOR_RESIZE_EDGE_NONE; @@ -3466,9 +3362,10 @@ touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial, case HEADER_MAX: case HEADER_CLOSE: { ctx.hdr_focus.state |= GTK_STATE_FLAG_ACTIVE; - draw_title_bar(frame); + draw_title_bar(); wl_surface_commit(ctx.wl_surface); }break; + default: { if (time - seat->touch_down_time_stamp < (uint32_t)ctx.double_click_time_ms) { if ((ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)){ @@ -3478,7 +3375,7 @@ touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial, else{ if (ctx.frame_capabilities & LIBDECOR_ACTION_MOVE){ seat->touch_down_time_stamp = time; - libdecor_frame_move(frame, seat->wl_seat, serial); + libdecor_frame_move(seat->wl_seat, serial); } } }break; @@ -3489,7 +3386,7 @@ touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial, } if (edge != LIBDECOR_RESIZE_EDGE_NONE && (ctx.frame_capabilities & LIBDECOR_ACTION_RESIZE)) { - libdecor_frame_resize(frame, seat->wl_seat, serial, edge); + libdecor_frame_resize(seat->wl_seat, serial, edge); } } @@ -3497,8 +3394,7 @@ static void touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t time, int32_t id){ struct seat *seat = data; if (seat->touch_focus && own_surface(seat->touch_focus)){ - struct libdecor_frame *frame = wl_surface_get_user_data(seat->touch_focus); - if (frame != 0 && ctx.touch_active != 0){ + if (ctx.touch_active != 0){ if (ctx.touch_active->type == HEADER){ switch (ctx.hdr_focus.type) { case HEADER_MIN: { @@ -3515,7 +3411,7 @@ touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t time, case HEADER_CLOSE: { if (ctx.frame_capabilities & LIBDECOR_ACTION_CLOSE){ - xdg_toplevel_close(frame, ctx.xdg_toplevel); + xdg_toplevel_close(0, ctx.xdg_toplevel); seat->touch_focus = 0; } }break; @@ -3526,7 +3422,7 @@ touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t time, /* unset active/clicked state once released */ ctx.hdr_focus.state &= ~GTK_STATE_FLAG_ACTIVE; if (GTK_IS_WIDGET(ctx.header)) { - draw_title_bar(frame); + draw_title_bar(); wl_surface_commit(ctx.wl_surface); } } @@ -3535,7 +3431,7 @@ touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial, uint32_t time, ctx.touch_active = 0; ctx.hdr_focus.widget = 0; ctx.hdr_focus.type = HEADER_NONE; - draw_decoration(frame); + draw_decoration(); wl_surface_commit(ctx.wl_surface); } } @@ -3545,13 +3441,9 @@ static void touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y){ struct seat *seat = data; - struct libdecor_frame *frame; if (seat->touch_focus && own_surface(seat->touch_focus)){ - frame = wl_surface_get_user_data(seat->touch_focus); - if (frame != 0){ - update_touch_focus(seat, frame, x, y); - } + update_touch_focus(seat, x, y); } } @@ -3584,12 +3476,10 @@ output_mode(void *data, struct wl_output *wl_output, static void output_done(void *data, struct wl_output *wl_output){ struct output *output = data; - struct libdecor_frame *frame; struct seat *seat; - if (ctx.frame != 0 && - ctx.decoration_type != DECORATION_TYPE_NONE){ - bool updated = redraw_scale(ctx.frame, &ctx.shadow); + if (ctx.decoration_type != DECORATION_TYPE_NONE){ + bool updated = redraw_scale(&ctx.shadow); if (updated){ wl_surface_commit(ctx.wl_surface); } @@ -3627,10 +3517,9 @@ remove_surface_outputs(struct border_component *cmpnt, const struct output *outp static void output_removed(struct output *output){ - struct libdecor_frame *frame; struct seat *seat; - if (ctx.frame != 0 && ctx.decoration_type != DECORATION_TYPE_NONE){ + if (ctx.decoration_type != DECORATION_TYPE_NONE){ remove_surface_outputs(&ctx.shadow, output); } wl_list_for_each(seat, &ctx.seat_list, link) { @@ -3656,12 +3545,14 @@ get_cursor_settings_from_env(char **theme, int *size){ char *env_xsize; env_xtheme = getenv("XCURSOR_THEME"); - if (env_xtheme != NULL) + if (env_xtheme != 0){ *theme = strdup(env_xtheme); + } env_xsize = getenv("XCURSOR_SIZE"); - if (env_xsize != NULL) + if (env_xsize != 0){ *size = atoi(env_xsize); + } return env_xtheme != NULL && env_xsize != NULL; } diff --git a/digesting_libdecor.h b/digesting_libdecor.h index b48dfa8..0eba988 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -162,10 +162,6 @@ struct border_component { struct wl_list link; /* border_component::child_components */ }; -struct libdecor_frame { - int dummy; -}; - // #include "libdecor.c" struct libdecor_state { @@ -279,50 +275,27 @@ enum titlebar_gesture { // libdecor.h -void libdecor_frame_unref(struct libdecor_frame *frame); -void libdecor_frame_set_visibility(struct libdecor_frame *frame, - bool visible); +void libdecor_frame_unref(void); +void libdecor_frame_set_visibility(bool visible); -void libdecor_frame_set_title(struct libdecor_frame *frame, - const char *title); -void libdecor_frame_set_app_id(struct libdecor_frame *frame, - const char *app_id); -void libdecor_frame_show_window_menu(struct libdecor_frame *frame, - struct wl_seat *wl_seat, - uint32_t serial, - int x, - int y); +void libdecor_frame_set_title(const char *title); +void libdecor_frame_set_app_id(const char *app_id); +void libdecor_frame_show_window_menu(struct wl_seat *wl_seat, uint32_t serial, int x, int y); -void libdecor_frame_popup_grab(struct libdecor_frame *frame, - const char *seat_name); -void libdecor_frame_popup_ungrab(struct libdecor_frame *frame, - const char *seat_name); -void libdecor_frame_translate_coordinate(struct libdecor_frame *frame, - int surface_x, int surface_y, - int *frame_x, int *frame_y); +void libdecor_frame_popup_grab(const char *seat_name); +void libdecor_frame_popup_ungrab(const char *seat_name); +void libdecor_frame_translate_coordinate(int surface_x, int surface_y, int *frame_x, int *frame_y); -void libdecor_frame_resize(struct libdecor_frame *frame, - struct wl_seat *wl_seat, - uint32_t serial, - enum libdecor_resize_edge edge); -void libdecor_frame_move(struct libdecor_frame *frame, - struct wl_seat *wl_seat, - uint32_t serial); -void libdecor_frame_commit(struct libdecor_frame *frame, - int w, int h, - struct libdecor_configuration *configuration); -void libdecor_frame_set_fullscreen(struct libdecor_frame *frame, - struct wl_output *output); -void libdecor_frame_unset_fullscreen(struct libdecor_frame *frame); -bool libdecor_frame_is_floating(struct libdecor_frame *frame); -void libdecor_frame_map(struct libdecor_frame *frame); +void libdecor_frame_resize(struct wl_seat *wl_seat, uint32_t serial, enum libdecor_resize_edge edge); +void libdecor_frame_move(struct wl_seat *wl_seat, uint32_t serial); +void libdecor_frame_commit(int w, int h, struct libdecor_configuration *configuration); +void libdecor_frame_set_fullscreen(struct wl_output *output); +void libdecor_frame_unset_fullscreen(void); +bool libdecor_frame_is_floating(void); +void libdecor_frame_map(void); -bool libdecor_configuration_get_content_size(struct libdecor_configuration *configuration, - struct libdecor_frame *frame, - int *width, - int *height); -bool libdecor_configuration_get_window_state(struct libdecor_configuration *configuration, - enum libdecor_window_state *window_state); +bool libdecor_configuration_get_content_size(struct libdecor_configuration *configuration, int *width, int *height); +bool libdecor_configuration_get_window_state(struct libdecor_configuration *configuration, enum libdecor_window_state *window_state); int libdecor_dispatch(int timeout); @@ -343,11 +316,11 @@ int libdecor_os_create_anonymous_file(off_t size); // #include "libdecor.c" -static void init_shell_surface(struct libdecor_frame *frame); +static void init_shell_surface(void); -static void set_capabilities(struct libdecor_frame *frame, const enum libdecor_capabilities new_capabilities); +static void set_capabilities(const enum libdecor_capabilities new_capabilities); -static void do_map(struct libdecor_frame *frame); +static void do_map(void); //#include "plugins/gtk/libdecor-gtk.c" @@ -360,13 +333,13 @@ static const char *libdecor_gtk_proxy_tag = "libdecor-gtk"; 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_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 libdecor_plugin_gtk_frame_free(void); +static void libdecor_plugin_gtk_frame_commit(struct libdecor_state *state, struct libdecor_configuration *configuration); +static void libdecor_plugin_gtk_frame_popup_grab(const char *seat_name); +static void libdecor_plugin_gtk_frame_popup_ungrab(const char *seat_name); +static bool libdecor_plugin_gtk_frame_get_border_size(struct libdecor_configuration *configuration, int *left, int *right, int *top, int *bottom); -static void draw_decoration(struct libdecor_frame *frame); +static void draw_decoration(void); // digesting_libdecor @@ -400,7 +373,6 @@ typedef struct Ctx{ /* window */ struct wl_surface *wl_surface; - struct libdecor_frame *frame; struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; struct zxdg_toplevel_decoration_v1 *toplevel_decoration;