[gtk+] gtkwindow: apply csd offset to set/get_default_size
- From: Olivier Fourdan <ofourdan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtkwindow: apply csd offset to set/get_default_size
- Date: Wed, 18 Nov 2015 07:37:36 +0000 (UTC)
commit 370e3469c60a450f90731679440df79953aaee2a
Author: Olivier Fourdan <ofourdan redhat com>
Date: Thu Nov 12 16:56:20 2015 +0100
gtkwindow: apply csd offset to set/get_default_size
An application may use gtk_window_get_size() to retrieve the current
window size and later reuse that size with
gtk_window_set_default_size().
gtk_window_set_default_size() and gtk_window_get_default_size() should
also take client side decorations offset into account.
Bugzilla: https://bugzilla.gnome.org/show_bug.cgi?id=756618
gtk/gtkwindow.c | 97 +++++++++++++++++++++++++++++++------------------------
1 files changed, 55 insertions(+), 42 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index db41f91..1c1fd85 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -5076,6 +5076,54 @@ gtk_window_get_default_icon_list (void)
return g_list_copy (default_icon_list);
}
+#define INCLUDE_CSD_SIZE 1
+#define EXCLUDE_CSD_SIZE -1
+
+static void
+gtk_window_update_csd_size (GtkWindow *window,
+ gint *width,
+ gint *height,
+ gint apply)
+{
+ GtkWindowPrivate *priv = window->priv;
+ GtkBorder window_border = { 0 };
+ gint w, h;
+
+ if (priv->type != GTK_WINDOW_TOPLEVEL)
+ return;
+
+ if (!priv->decorated ||
+ priv->fullscreen)
+ return;
+
+ get_shadow_width (window, &window_border);
+ w = *width + apply * (window_border.left + window_border.right);
+ h = *height + apply * (window_border.top + window_border.bottom);
+
+ if (priv->title_box != NULL &&
+ gtk_widget_get_visible (priv->title_box) &&
+ gtk_widget_get_child_visible (priv->title_box))
+ {
+ gint minimum_height;
+ gint natural_height;
+
+ gtk_widget_get_preferred_height (priv->title_box, &minimum_height, &natural_height);
+ h += apply * natural_height;
+ }
+
+ /* Make sure the size remains acceptable */
+ if (w < 1)
+ w = 1;
+ if (h < 1)
+ h = 1;
+
+ /* Only update given size if not negative */
+ if (*width > -1)
+ *width = w;
+ if (*height > -1)
+ *height = h;
+}
+
static void
gtk_window_set_default_size_internal (GtkWindow *window,
gboolean change_width,
@@ -5174,6 +5222,7 @@ gtk_window_set_default_size (GtkWindow *window,
g_return_if_fail (width >= -1);
g_return_if_fail (height >= -1);
+ gtk_window_update_csd_size (window, &width, &height, INCLUDE_CSD_SIZE);
gtk_window_set_default_size_internal (window, TRUE, width, TRUE, height, FALSE);
}
@@ -5219,56 +5268,20 @@ gtk_window_get_default_size (GtkWindow *window,
gint *height)
{
GtkWindowGeometryInfo *info;
+ gint w, h;
g_return_if_fail (GTK_IS_WINDOW (window));
info = gtk_window_get_geometry_info (window, FALSE);
+ w = info ? info->default_width : -1;
+ h = info ? info->default_height : -1;
+ gtk_window_update_csd_size (window, &w, &h, EXCLUDE_CSD_SIZE);
if (width)
- *width = info ? info->default_width : -1;
+ *width = w;
if (height)
- *height = info ? info->default_height : -1;
-}
-
-#define INCLUDE_CSD_SIZE 1
-#define EXCLUDE_CSD_SIZE -1
-
-static void
-gtk_window_update_csd_size (GtkWindow *window,
- gint *width,
- gint *height,
- gint apply)
-{
- GtkWindowPrivate *priv = window->priv;
- GtkBorder window_border = { 0 };
-
- if (priv->type != GTK_WINDOW_TOPLEVEL)
- return;
-
- if (priv->decorated &&
- !priv->fullscreen)
- {
- get_shadow_width (window, &window_border);
- *width += apply * (window_border.left + window_border.right);
- *height += apply * (window_border.top + window_border.bottom);
-
- if (priv->title_box != NULL &&
- gtk_widget_get_visible (priv->title_box) &&
- gtk_widget_get_child_visible (priv->title_box))
- {
- gint minimum_height;
- gint natural_height;
-
- gtk_widget_get_preferred_height (priv->title_box, &minimum_height, &natural_height);
- *height += apply * natural_height;
- }
- }
- /* Make sure the size remains acceptable */
- if (*width < 1)
- *width = 1;
- if (*height < 1)
- *height = 1;
+ *height = h;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]