From 2b904ccef43f88b53b23f9a9159f7bad72d37574 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Thu, 21 Apr 2022 06:47:14 +0200 Subject: [PATCH] Apply changes from upstream: https://gitlab.gnome.org/jadahl/libdecor --- libdecor/demo/demo.c | 3 +- libdecor/src/libdecor-fallback.c | 44 +---- libdecor/src/libdecor-plugin.h | 34 +--- libdecor/src/libdecor.c | 183 ++++++++++---------- libdecor/src/plugins/cairo/libdecor-cairo.c | 141 ++++----------- libdecor/src/plugins/dummy/libdecor-dummy.c | 49 +----- libdecor/src/plugins/gtk/libdecor-gtk.c | 154 ++++------------ 7 files changed, 171 insertions(+), 437 deletions(-) diff --git a/libdecor/demo/demo.c b/libdecor/demo/demo.c index 041e35d6c..85efcd739 100644 --- a/libdecor/demo/demo.c +++ b/libdecor/demo/demo.c @@ -656,8 +656,7 @@ keyboard_key(void *data, printf("set fixed-size\n"); libdecor_frame_unset_capabilities(window->frame, LIBDECOR_ACTION_RESIZE); - } - else { + } else { printf("set resizeable\n"); libdecor_frame_set_capabilities(window->frame, LIBDECOR_ACTION_RESIZE); diff --git a/libdecor/src/libdecor-fallback.c b/libdecor/src/libdecor-fallback.c index c281197c2..7f5f2fddc 100644 --- a/libdecor/src/libdecor-fallback.c +++ b/libdecor/src/libdecor-fallback.c @@ -127,18 +127,6 @@ libdecor_plugin_fallback_frame_property_changed(struct libdecor_plugin *plugin, { } -static void -libdecor_plugin_fallback_frame_translate_coordinate(struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - int content_x, - int content_y, - int *frame_x, - int *frame_y) -{ - *frame_x = content_x; - *frame_y = content_y; -} - static void libdecor_plugin_fallback_frame_popup_grab(struct libdecor_plugin *plugin, struct libdecor_frame *frame, @@ -154,27 +142,16 @@ libdecor_plugin_fallback_frame_popup_ungrab(struct libdecor_plugin *plugin, } static bool -libdecor_plugin_fallback_configuration_get_content_size(struct libdecor_plugin *plugin, - struct libdecor_configuration *configuration, - struct libdecor_frame *frame, - int *content_width, - int *content_height) +libdecor_plugin_fallback_frame_get_border_size(struct libdecor_plugin *plugin, + struct libdecor_frame *frame, + struct libdecor_configuration *configuration, + int *left, + int *right, + int *top, + int *bottom) { - return libdecor_configuration_get_window_size(configuration, - content_width, - content_height); -} + *left = *right = *top = *bottom = 0; -static bool -libdecor_plugin_fallback_frame_get_window_size_for( - struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - struct libdecor_state *state, - int *window_width, - int *window_height) -{ - *window_width = libdecor_state_get_content_width (state); - *window_height = libdecor_state_get_content_height (state); return true; } @@ -186,12 +163,9 @@ static struct libdecor_plugin_interface fallback_plugin_iface = { .frame_free = libdecor_plugin_fallback_frame_free, .frame_commit = libdecor_plugin_fallback_frame_commit, .frame_property_changed = libdecor_plugin_fallback_frame_property_changed, - .frame_translate_coordinate = - libdecor_plugin_fallback_frame_translate_coordinate, .frame_popup_grab = libdecor_plugin_fallback_frame_popup_grab, .frame_popup_ungrab = libdecor_plugin_fallback_frame_popup_ungrab, - .configuration_get_content_size = libdecor_plugin_fallback_configuration_get_content_size, - .frame_get_window_size_for = libdecor_plugin_fallback_frame_get_window_size_for, + .frame_get_border_size = libdecor_plugin_fallback_frame_get_border_size, }; struct libdecor_plugin * diff --git a/libdecor/src/libdecor-plugin.h b/libdecor/src/libdecor-plugin.h index 9e5d9510b..eba41d409 100644 --- a/libdecor/src/libdecor-plugin.h +++ b/libdecor/src/libdecor-plugin.h @@ -97,12 +97,6 @@ struct libdecor_plugin_interface { struct libdecor_configuration *configuration); void (*frame_property_changed)(struct libdecor_plugin *plugin, struct libdecor_frame *frame); - void (* frame_translate_coordinate)(struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - int content_x, - int content_y, - int *window_x, - int *window_y); void (* frame_popup_grab)(struct libdecor_plugin *plugin, struct libdecor_frame *frame, const char *seat_name); @@ -110,17 +104,13 @@ struct libdecor_plugin_interface { struct libdecor_frame *frame, const char *seat_name); - bool (* frame_get_window_size_for)(struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - struct libdecor_state *state, - int *window_width, - int *window_height); - - bool (* configuration_get_content_size)(struct libdecor_plugin *plugin, - struct libdecor_configuration *configuration, - struct libdecor_frame *frame, - int *content_width, - int *content_height); + bool (* frame_get_border_size)(struct libdecor_plugin *plugin, + struct libdecor_frame *frame, + struct libdecor_configuration *configuration, + int *left, + int *right, + int *top, + int *bottom); /* Reserved */ void (* reserved0)(void); @@ -147,11 +137,6 @@ libdecor_frame_get_content_height(struct libdecor_frame *frame); enum libdecor_window_state libdecor_frame_get_window_state(struct libdecor_frame *frame); -void -libdecor_frame_set_window_geometry(struct libdecor_frame *frame, - int32_t x, int32_t y, - int32_t width, int32_t height); - enum libdecor_capabilities libdecor_frame_get_capabilities(const struct libdecor_frame *frame); @@ -183,11 +168,6 @@ libdecor_state_get_content_height (struct libdecor_state *state); enum libdecor_window_state libdecor_state_get_window_state(struct libdecor_state *state); -bool -libdecor_configuration_get_window_size(struct libdecor_configuration *configuration, - int *width, - int *height); - int libdecor_plugin_init(struct libdecor_plugin *plugin, struct libdecor *context, diff --git a/libdecor/src/libdecor.c b/libdecor/src/libdecor.c index 2de2da3be..9fedf1a35 100644 --- a/libdecor/src/libdecor.c +++ b/libdecor/src/libdecor.c @@ -245,36 +245,37 @@ frame_get_window_size_for(struct libdecor_frame *frame, struct libdecor *context = frame_priv->context; struct libdecor_plugin *plugin = context->plugin; - if (frame_has_visible_client_side_decoration(frame)) { - return plugin->priv->iface->frame_get_window_size_for( - plugin, frame, state, - window_width, window_height); - } else { - *window_width = state->content_width; - *window_height = state->content_height; - return true; + *window_width = state->content_width; + *window_height = state->content_height; + + if (frame_has_visible_client_side_decoration(frame) && + plugin->priv->iface->frame_get_border_size) { + int left, right, top, bottom; + if (!plugin->priv->iface->frame_get_border_size( + plugin, frame, NULL, &left, &right, &top, &bottom)) + return false; + *window_width += left + right; + *window_height += top + bottom; } + + return true; } -static bool -window_size_to_content_size(struct libdecor_configuration *configuration, - struct libdecor_frame *frame, - int *content_width, - int *content_height) +static void +frame_set_window_geometry(struct libdecor_frame *frame, + int32_t content_width, int32_t content_height) { - struct libdecor_frame_private *frame_priv = frame->priv; - struct libdecor *context = frame_priv->context; - struct libdecor_plugin *plugin = context->plugin; + struct libdecor_plugin *plugin = frame->priv->context->plugin; + int x, y, width, height; + int left, right, top, bottom; - if (frame_has_visible_client_side_decoration(frame)) { - return plugin->priv->iface->configuration_get_content_size( - plugin, configuration, frame, - content_width, content_height); - } else { - *content_width = configuration->window_width; - *content_height = configuration->window_height; - return true; - } + plugin->priv->iface->frame_get_border_size(plugin, frame, NULL, + &left, &right, &top, &bottom); + x = -left; + y = -top; + width = content_width + left + right; + height = content_height + top + bottom; + xdg_surface_set_window_geometry(frame->priv->xdg_surface, x, y, width, height); } LIBDECOR_EXPORT bool @@ -283,36 +284,9 @@ libdecor_configuration_get_content_size(struct libdecor_configuration *configura int *width, int *height) { - int content_width; - int content_height; + struct libdecor_plugin *plugin = frame->priv->context->plugin; - if (!configuration->has_size) - return false; - - if (configuration->window_width == 0 || configuration->window_height == 0) - return false; - - if (!window_size_to_content_size(configuration, - frame, - &content_width, - &content_height)) - return false; - - *width = content_width; - *height = content_height; - - if (state_is_floating(configuration->window_state)) { - constrain_content_size(frame, width, height); - } - - return true; -} - -LIBDECOR_EXPORT bool -libdecor_configuration_get_window_size(struct libdecor_configuration *configuration, - int *width, - int *height) -{ + /* get configured toplevel dimensions */ if (!configuration->has_size) return false; @@ -321,6 +295,24 @@ libdecor_configuration_get_window_size(struct libdecor_configuration *configurat *width = configuration->window_width; *height = configuration->window_height; + + /* remove plugin-specific border size */ + if (frame_has_visible_client_side_decoration(frame) && + plugin->priv->iface->frame_get_border_size) { + int left, right, top, bottom; + if (!plugin->priv->iface->frame_get_border_size( + plugin, frame, configuration, &left, &right, &top, &bottom)) + return false; + + *width -= (left + right); + *height -= (top + bottom); + } + + /* constrain content dimensions manually */ + if (state_is_floating(configuration->window_state)) { + constrain_content_size(frame, width, height); + } + return true; } @@ -632,12 +624,12 @@ libdecor_frame_set_visibility(struct libdecor_frame *frame, } else { /* destroy client-side decorations */ plugin->priv->iface->frame_free(plugin, frame); - - libdecor_frame_set_window_geometry(frame, 0, 0, - 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); } @@ -677,7 +669,7 @@ libdecor_frame_set_title(struct libdecor_frame *frame, return; xdg_toplevel_set_title(frame_priv->xdg_toplevel, title); - + plugin->priv->iface->frame_property_changed(plugin, frame); } } @@ -833,9 +825,17 @@ libdecor_frame_translate_coordinate(struct libdecor_frame *frame, struct libdecor *context = frame_priv->context; struct libdecor_plugin *plugin = context->plugin; - plugin->priv->iface->frame_translate_coordinate(plugin, frame, - content_x, content_y, - frame_x, frame_y); + *frame_x = content_x; + *frame_y = content_y; + + if (frame_has_visible_client_side_decoration(frame) && + plugin->priv->iface->frame_get_border_size) { + int left, top; + plugin->priv->iface->frame_get_border_size(plugin, frame, NULL, + &left, NULL, &top, NULL); + *frame_x += left; + *frame_y += top; + } } LIBDECOR_EXPORT void @@ -882,14 +882,6 @@ libdecor_frame_get_max_content_size(struct libdecor_frame *frame, *pcontent_height = frame_priv->state.content_limits.max_height; } -LIBDECOR_EXPORT void -libdecor_frame_set_window_geometry(struct libdecor_frame *frame, - int32_t x, int32_t y, - int32_t width, int32_t height) -{ - xdg_surface_set_window_geometry(frame->priv->xdg_surface, x, y, width, height); -} - LIBDECOR_EXPORT enum libdecor_capabilities libdecor_frame_get_capabilities(const struct libdecor_frame *frame) { @@ -1122,12 +1114,12 @@ libdecor_frame_commit(struct libdecor_frame *frame, configuration); } else { plugin->priv->iface->frame_free(plugin, frame); - - libdecor_frame_set_window_geometry(frame, 0, 0, - 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); @@ -1260,6 +1252,12 @@ registry_handle_global(void *user_data, if (!strcmp(interface, xdg_wm_base_interface.name)) { init_xdg_wm_base(context, id, version); } else if (!strcmp(interface, zxdg_decoration_manager_v1_interface.name)) { + const char *force_csd = getenv("LIBDECOR_FORCE_CSD"); + + if (force_csd && atoi(force_csd)) { + return; + } + context->decoration_manager = wl_registry_bind( context->wl_registry, id, &zxdg_decoration_manager_v1_interface, @@ -1488,25 +1486,26 @@ init_plugins(struct libdecor *context) if (!dir) { fprintf(stderr, "Couldn't open plugin directory: %s\n", strerror(errno)); - continue; + } else { + + while (true) { + struct dirent *de; + + de = readdir(dir); + if (!de) + break; + + plugin_loader = load_plugin_loader(context, + plugin_dir, + de->d_name); + if (!plugin_loader) + continue; + + wl_list_insert(plugin_loaders.prev, &plugin_loader->link); + } + + closedir(dir); } - - while (true) { - struct dirent *de; - - de = readdir(dir); - if (!de) - break; - - plugin_loader = load_plugin_loader(context, plugin_dir, de->d_name); - if (!plugin_loader) - continue; - - wl_list_insert(plugin_loaders.prev, &plugin_loader->link); - } - - closedir(dir); - plugin_dir = strtok_r(NULL, ":", &saveptr); } free(all_plugin_dirs); diff --git a/libdecor/src/plugins/cairo/libdecor-cairo.c b/libdecor/src/plugins/cairo/libdecor-cairo.c index 704939b50..642bcb4e4 100644 --- a/libdecor/src/plugins/cairo/libdecor-cairo.c +++ b/libdecor/src/plugins/cairo/libdecor-cairo.c @@ -1007,13 +1007,11 @@ ensure_border_surfaces(struct libdecor_frame_cairo *frame_cairo) frame_cairo->shadow.opaque = false; ensure_component(frame_cairo, &frame_cairo->shadow); -#if 1 // ! APPLY_FLTK_CHANGES // activate this to get feedback about its impact libdecor_frame_get_min_content_size(&frame_cairo->frame, &min_width, &min_height); - libdecor_frame_set_min_content_size(&frame_cairo->frame, - MAX(min_width, (int)MAX(56, 4 * BUTTON_WIDTH)), + libdecor_frame_set_min_content_size(&frame_cairo->frame, + MAX(min_width, (int)MAX(56, 4 * BUTTON_WIDTH)), MAX(min_height, (int)MAX(56, TITLE_HEIGHT + 1))); -#endif } static void @@ -1335,8 +1333,7 @@ draw_component_content(struct libdecor_frame_cairo *frame_cairo, cairo_rel_line_to(cr, small - 1, 0); cairo_rel_line_to(cr, 0, small - 1); cairo_line_to(cr, x + small - 1, y + small - 1); - } - else { + } else { cairo_rectangle(cr, x, y, SYM_DIM - 1, SYM_DIM - 1); } cairo_stroke(cr); @@ -1670,32 +1667,6 @@ draw_decoration(struct libdecor_frame_cairo *frame_cairo) } } -static void -set_window_geometry(struct libdecor_frame_cairo *frame_cairo) -{ - struct libdecor_frame *frame = &frame_cairo->frame; - int x = 0, y = 0, width = 0, height = 0; - - switch (frame_cairo->decoration_type) { - case DECORATION_TYPE_NONE: - x = 0; - y = 0; - width = libdecor_frame_get_content_width(frame); - height = libdecor_frame_get_content_height(frame); - break; - case DECORATION_TYPE_ALL: - case DECORATION_TYPE_TILED: - case DECORATION_TYPE_MAXIMIZED: - x = 0; - y = -(int)TITLE_HEIGHT; - width = libdecor_frame_get_content_width(frame); - height = libdecor_frame_get_content_height(frame) + TITLE_HEIGHT; - break; - } - - libdecor_frame_set_window_geometry(frame, x, y, width, height); -} - static enum decoration_type window_state_to_decoration_type(enum libdecor_window_state window_state) { @@ -1753,7 +1724,6 @@ libdecor_plugin_cairo_frame_commit(struct libdecor_plugin *plugin, frame_cairo->window_state = new_window_state; draw_decoration(frame_cairo); - set_window_geometry(frame_cairo); } static void @@ -1791,24 +1761,6 @@ libdecor_plugin_cairo_frame_property_changed(struct libdecor_plugin *plugin, } } -static void -libdecor_plugin_cairo_frame_translate_coordinate(struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - int content_x, - int content_y, - int *frame_x, - int *frame_y) -{ - struct libdecor_frame_cairo *frame_cairo = - (struct libdecor_frame_cairo *) frame; - - *frame_x = content_x; - *frame_y = content_y; - - if (frame_cairo->title_bar.is_showing) - *frame_y += TITLE_HEIGHT; -} - static bool streq(const char *str1, const char *str2) @@ -1876,63 +1828,38 @@ libdecor_plugin_cairo_frame_popup_ungrab(struct libdecor_plugin *plugin, } static bool -libdecor_plugin_cairo_configuration_get_content_size( - struct libdecor_plugin *plugin, - struct libdecor_configuration *configuration, - struct libdecor_frame *frame, - int *content_width, - int *content_height) +libdecor_plugin_cairo_frame_get_border_size(struct libdecor_plugin *plugin, + struct libdecor_frame *frame, + struct libdecor_configuration *configuration, + int *left, + int *right, + int *top, + int *bottom) { - int win_width, win_height; - if (!libdecor_configuration_get_window_size(configuration, - &win_width, - &win_height)) - return false; + enum libdecor_window_state window_state; - enum libdecor_window_state state; - if (!libdecor_configuration_get_window_state(configuration, &state)) { - return false; + if (configuration) { + if (!libdecor_configuration_get_window_state( + configuration, &window_state)) + return false; + } else { + window_state = libdecor_frame_get_window_state(frame); } - switch (window_state_to_decoration_type(state)) { - case DECORATION_TYPE_NONE: - *content_width = win_width; - *content_height = win_height; - break; - case DECORATION_TYPE_ALL: - case DECORATION_TYPE_TILED: - case DECORATION_TYPE_MAXIMIZED: - *content_width = win_width; - *content_height = win_height - TITLE_HEIGHT; - break; - } + if (left) + *left = 0; + if (right) + *right = 0; + if (bottom) + *bottom = 0; + if (top) { + enum decoration_type type = window_state_to_decoration_type(window_state); - return true; -} - -static bool -libdecor_plugin_cairo_frame_get_window_size_for( - struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - struct libdecor_state *state, - int *window_width, - int *window_height) -{ - enum libdecor_window_state window_state = - libdecor_state_get_window_state(state); - - switch (window_state_to_decoration_type(window_state)) { - case DECORATION_TYPE_NONE: - *window_width = libdecor_state_get_content_width(state); - *window_height = libdecor_state_get_content_height(state); - break; - case DECORATION_TYPE_ALL: - case DECORATION_TYPE_TILED: - case DECORATION_TYPE_MAXIMIZED: - *window_width = libdecor_state_get_content_width(state); - *window_height = - libdecor_state_get_content_height(state) + TITLE_HEIGHT; - break; + if (((struct libdecor_frame_cairo *)frame)->title_bar.is_showing && + (type != DECORATION_TYPE_NONE)) + *top = TITLE_HEIGHT; + else + *top = 0; } return true; @@ -1947,15 +1874,9 @@ static struct libdecor_plugin_interface cairo_plugin_iface = { .frame_free = libdecor_plugin_cairo_frame_free, .frame_commit = libdecor_plugin_cairo_frame_commit, .frame_property_changed = libdecor_plugin_cairo_frame_property_changed, - .frame_translate_coordinate = - libdecor_plugin_cairo_frame_translate_coordinate, .frame_popup_grab = libdecor_plugin_cairo_frame_popup_grab, .frame_popup_ungrab = libdecor_plugin_cairo_frame_popup_ungrab, - - .configuration_get_content_size = - libdecor_plugin_cairo_configuration_get_content_size, - .frame_get_window_size_for = - libdecor_plugin_cairo_frame_get_window_size_for, + .frame_get_border_size = libdecor_plugin_cairo_frame_get_border_size, }; static void diff --git a/libdecor/src/plugins/dummy/libdecor-dummy.c b/libdecor/src/plugins/dummy/libdecor-dummy.c index 1891b7e51..7dc2428ca 100644 --- a/libdecor/src/plugins/dummy/libdecor-dummy.c +++ b/libdecor/src/plugins/dummy/libdecor-dummy.c @@ -46,6 +46,7 @@ libdecor_plugin_dummy_destroy(struct libdecor_plugin *plugin) struct libdecor_plugin_dummy *plugin_dummy = (struct libdecor_plugin_dummy *) plugin; + libdecor_plugin_release(plugin); free(plugin_dummy); } @@ -79,18 +80,6 @@ libdecor_plugin_dummy_frame_property_changed(struct libdecor_plugin *plugin, { } -static void -libdecor_plugin_dummy_frame_translate_coordinate(struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - int content_x, - int content_y, - int *frame_x, - int *frame_y) -{ - *frame_x = content_x; - *frame_y = content_y; -} - static void libdecor_plugin_dummy_frame_popup_grab(struct libdecor_plugin *plugin, struct libdecor_frame *frame, @@ -105,32 +94,6 @@ libdecor_plugin_dummy_frame_popup_ungrab(struct libdecor_plugin *plugin, { } -static bool -libdecor_plugin_dummy_configuration_get_content_size( - struct libdecor_plugin *plugin, - struct libdecor_configuration *configuration, - struct libdecor_frame *frame, - int *content_width, - int *content_height) -{ - return libdecor_configuration_get_window_size(configuration, - content_width, - content_height); -} - -static bool -libdecor_plugin_dummy_frame_get_window_size_for( - struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - struct libdecor_state *state, - int *window_width, - int *window_height) -{ - *window_width = libdecor_state_get_content_width (state); - *window_height = libdecor_state_get_content_height (state); - return true; -} - static struct libdecor_plugin_interface dummy_plugin_iface = { .destroy = libdecor_plugin_dummy_destroy, @@ -138,15 +101,8 @@ static struct libdecor_plugin_interface dummy_plugin_iface = { .frame_free = libdecor_plugin_dummy_frame_free, .frame_commit = libdecor_plugin_dummy_frame_commit, .frame_property_changed = libdecor_plugin_dummy_frame_property_changed, - .frame_translate_coordinate = - libdecor_plugin_dummy_frame_translate_coordinate, .frame_popup_grab = libdecor_plugin_dummy_frame_popup_grab, .frame_popup_ungrab = libdecor_plugin_dummy_frame_popup_ungrab, - - .configuration_get_content_size = - libdecor_plugin_dummy_configuration_get_content_size, - .frame_get_window_size_for = - libdecor_plugin_dummy_frame_get_window_size_for, }; static struct libdecor_plugin * @@ -155,7 +111,7 @@ libdecor_plugin_new(struct libdecor *context) struct libdecor_plugin_dummy *plugin_dummy; plugin_dummy = zalloc(sizeof *plugin_dummy); - plugin_dummy->plugin.iface = &dummy_plugin_iface; + libdecor_plugin_init(&plugin_dummy->plugin, context, &dummy_plugin_iface); plugin_dummy->context = context; libdecor_notify_plugin_ready(context); @@ -170,6 +126,7 @@ static struct libdecor_plugin_priority priorities[] = { LIBDECOR_EXPORT const struct libdecor_plugin_description libdecor_plugin_description = { .api_version = LIBDECOR_PLUGIN_API_VERSION, + .capabilities = LIBDECOR_PLUGIN_CAPABILITY_BASE, .description = "dummy libdecor plugin", .priorities = priorities, .constructor = libdecor_plugin_new, diff --git a/libdecor/src/plugins/gtk/libdecor-gtk.c b/libdecor/src/plugins/gtk/libdecor-gtk.c index c5658bce9..e23115c23 100644 --- a/libdecor/src/plugins/gtk/libdecor-gtk.c +++ b/libdecor/src/plugins/gtk/libdecor-gtk.c @@ -1486,36 +1486,6 @@ draw_decoration(struct libdecor_frame_gtk *frame_gtk) } } -static void -set_window_geometry(struct libdecor_frame_gtk *frame_gtk) -{ - struct libdecor_frame *frame = &frame_gtk->frame; - int x = 0, y = 0, width = 0, height = 0; -#if APPLY_FLTK_CHANGES - const int title_height = GTK_IS_WIDGET(frame_gtk->header) ? gtk_widget_get_allocated_height(frame_gtk->header) : 0; -#else - const int title_height = gtk_widget_get_allocated_height(frame_gtk->header); -#endif - - switch (frame_gtk->decoration_type) { - case DECORATION_TYPE_NONE: - x = 0; - y = 0; - width = libdecor_frame_get_content_width(frame); - height = libdecor_frame_get_content_height(frame); - break; - case DECORATION_TYPE_ALL: - case DECORATION_TYPE_TITLE_ONLY: - x = 0; - y = -title_height; - width = libdecor_frame_get_content_width(frame); - height = libdecor_frame_get_content_height(frame) + title_height; - break; - } - - libdecor_frame_set_window_geometry(frame, x, y, width, height); -} - static enum decoration_type window_state_to_decoration_type(enum libdecor_window_state window_state) { @@ -1571,7 +1541,6 @@ libdecor_plugin_gtk_frame_commit(struct libdecor_plugin *plugin, frame_gtk->decoration_type = new_decoration_type; draw_decoration(frame_gtk); - set_window_geometry(frame_gtk); /* set fixed window size */ if (!resizable(frame_gtk)) { @@ -1626,27 +1595,6 @@ libdecor_plugin_gtk_frame_property_changed(struct libdecor_plugin *plugin, } } -static void -libdecor_plugin_gtk_frame_translate_coordinate(struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - int content_x, - int content_y, - int *frame_x, - int *frame_y) -{ - struct libdecor_frame_gtk *frame_gtk = - (struct libdecor_frame_gtk *) frame; - - *frame_x = content_x; - *frame_y = content_y; - -#if APPLY_FLTK_CHANGES - *frame_y += (frame_gtk->header ? gtk_widget_get_allocated_height(frame_gtk->header) : 0); -#else - *frame_y += gtk_widget_get_allocated_height(frame_gtk->header); -#endif -} - static void update_component_focus(struct libdecor_frame_gtk *frame_gtk, struct wl_surface *surface, @@ -1807,78 +1755,38 @@ libdecor_plugin_gtk_frame_popup_ungrab(struct libdecor_plugin *plugin, } static bool -libdecor_plugin_gtk_configuration_get_content_size( - struct libdecor_plugin *plugin, - struct libdecor_configuration *configuration, - struct libdecor_frame *frame, - int *content_width, - int *content_height) +libdecor_plugin_gtk_frame_get_border_size(struct libdecor_plugin *plugin, + struct libdecor_frame *frame, + struct libdecor_configuration *configuration, + int *left, + int *right, + int *top, + int *bottom) { - struct libdecor_frame_gtk *frame_gtk = - (struct libdecor_frame_gtk *) frame; - int win_width, win_height; - enum libdecor_window_state state; + enum libdecor_window_state window_state; - if (!libdecor_configuration_get_window_size(configuration, - &win_width, - &win_height)) - return false; - - if (!libdecor_configuration_get_window_state(configuration, &state)) - return false; -#if APPLY_FLTK_CHANGES - const int title_bar_height = GTK_IS_WIDGET(frame_gtk->header)? gtk_widget_get_allocated_height(frame_gtk->header) : 0; -#else - const int title_bar_height = gtk_widget_get_allocated_height(frame_gtk->header); -#endif - - switch (window_state_to_decoration_type(state)) { - case DECORATION_TYPE_NONE: - *content_width = win_width; - *content_height = win_height; - break; - case DECORATION_TYPE_ALL: - case DECORATION_TYPE_TITLE_ONLY: - *content_width = win_width; - *content_height = win_height - title_bar_height; - break; + if (configuration) { + if (!libdecor_configuration_get_window_state( + configuration, &window_state)) + return false; + } else { + window_state = libdecor_frame_get_window_state(frame); } - return true; -} + if (left) + *left = 0; + if (right) + *right = 0; + if (bottom) + *bottom = 0; + if (top) { + GtkWidget *header = ((struct libdecor_frame_gtk *)frame)->header; + enum decoration_type type = window_state_to_decoration_type(window_state); -static bool -libdecor_plugin_gtk_frame_get_window_size_for( - struct libdecor_plugin *plugin, - struct libdecor_frame *frame, - struct libdecor_state *state, - int *window_width, - int *window_height) -{ - enum libdecor_window_state window_state = - libdecor_state_get_window_state (state); - -#if APPLY_FLTK_CHANGES - struct libdecor_frame_gtk *frame_gtk = (struct libdecor_frame_gtk *)frame; - const int title_bar_height = (GTK_IS_WIDGET(frame_gtk->header) ? gtk_widget_get_allocated_height( - frame_gtk->header) : 0); -#else - GtkWidget *header = ((struct libdecor_frame_gtk *)frame)->header; - - const int title_bar_height = header ? gtk_widget_get_allocated_height(header) : 0; -#endif - - switch (window_state_to_decoration_type(window_state)) { - case DECORATION_TYPE_NONE: - *window_width = libdecor_state_get_content_width(state); - *window_height = libdecor_state_get_content_height(state); - break; - case DECORATION_TYPE_ALL: - case DECORATION_TYPE_TITLE_ONLY: - *window_width = libdecor_state_get_content_width(state); - *window_height = - libdecor_state_get_content_height(state) + title_bar_height; - break; + if (header && (type != DECORATION_TYPE_NONE)) + *top = gtk_widget_get_allocated_height(header); + else + *top = 0; } return true; @@ -1893,15 +1801,11 @@ static struct libdecor_plugin_interface gtk_plugin_iface = { .frame_free = libdecor_plugin_gtk_frame_free, .frame_commit = libdecor_plugin_gtk_frame_commit, .frame_property_changed = libdecor_plugin_gtk_frame_property_changed, - .frame_translate_coordinate = - libdecor_plugin_gtk_frame_translate_coordinate, + .frame_popup_grab = libdecor_plugin_gtk_frame_popup_grab, .frame_popup_ungrab = libdecor_plugin_gtk_frame_popup_ungrab, - .configuration_get_content_size = - libdecor_plugin_gtk_configuration_get_content_size, - .frame_get_window_size_for = - libdecor_plugin_gtk_frame_get_window_size_for, + .frame_get_border_size = libdecor_plugin_gtk_frame_get_border_size, }; static void