[gtk+] Allow theme to set close button position in headerbars
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Allow theme to set close button position in headerbars
- Date: Mon, 16 Sep 2013 20:16:26 +0000 (UTC)
commit 54773ba45ba6348cc8c94e7fbab10049fac02884
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Sep 16 16:13:07 2013 -0400
Allow theme to set close button position in headerbars
This allows GTK+ applications with headerbars to fit in
better in platforms that have window controls on the left.
To use this, set -GtkWindow-decoration-button-layout: 'close:'
in the theme.
https://bugzilla.gnome.org/show_bug.cgi?id=706708
gtk/gtkheaderbar.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index 400f34a..c1c1842 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -643,6 +643,27 @@ gtk_header_bar_get_preferred_height_for_width (GtkWidget *widget,
gtk_header_bar_compute_size_for_opposing_orientation (widget, width, minimum_height, natural_height);
}
+static gboolean
+close_button_at_end (GtkWidget *widget)
+{
+ gchar *layout_desc;
+ gboolean at_end;
+ gchar *p;
+
+ gtk_widget_style_get (gtk_widget_get_toplevel (widget),
+ "decoration-button-layout", &layout_desc, NULL);
+
+ p = strchr (layout_desc, ':');
+ if (p && strstr (p, "close"))
+ at_end = TRUE;
+ else
+ at_end = FALSE;
+
+ g_free (layout_desc);
+
+ return at_end;
+}
+
static void
gtk_header_bar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
@@ -667,6 +688,9 @@ gtk_header_bar_size_allocate (GtkWidget *widget,
gint child_size;
GtkTextDirection direction;
GtkBorder css_borders;
+ gboolean at_end;
+
+ at_end = close_button_at_end (widget);
gtk_widget_set_allocation (widget, allocation);
@@ -734,9 +758,9 @@ gtk_header_bar_size_allocate (GtkWidget *widget,
child_allocation.y = allocation->y + css_borders.top;
child_allocation.height = height;
if (packing == GTK_PACK_START)
- x = allocation->x + css_borders.left;
+ x = allocation->x + css_borders.left + (at_end ? 0 : close_width);
else
- x = allocation->x + allocation->width - close_width - css_borders.right;
+ x = allocation->x + allocation->width - (at_end ? close_width : 0) - css_borders.right;
if (packing == GTK_PACK_START)
{
@@ -790,7 +814,10 @@ gtk_header_bar_size_allocate (GtkWidget *widget,
}
}
- side[GTK_PACK_END] += close_width;
+ if (at_end)
+ side[GTK_PACK_END] += close_width;
+ else
+ side[GTK_PACK_START] += close_width;
child_allocation.y = allocation->y + css_borders.top;
child_allocation.height = height;
@@ -822,14 +849,21 @@ gtk_header_bar_size_allocate (GtkWidget *widget,
if (priv->close_button)
{
+ gboolean left;
+
if (direction == GTK_TEXT_DIR_RTL)
+ left = at_end;
+ else
+ left = !at_end;
+
+ if (left)
child_allocation.x = allocation->x + css_borders.left;
else
child_allocation.x = allocation->x + allocation->width - css_borders.right - close_button_width;
child_allocation.width = close_button_width;
gtk_widget_size_allocate (priv->close_button, &child_allocation);
- if (direction == GTK_TEXT_DIR_RTL)
+ if (left)
child_allocation.x = allocation->x + css_borders.left + close_button_width + priv->spacing;
else
child_allocation.x = allocation->x + allocation->width - css_borders.right - close_button_width -
priv->spacing - separator_width;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]