From a059fe247c6ba6be105986b229bf2d8374f40583 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Jan=20Dj=C3=A4rv?= <jan.h.d@swipnet.se>
Date: Sun, 5 Jun 2011 21:04:51 +0200
Subject: [PATCH] Handle scroll bar width larger than 16 for GTK3.

* gtkutil.c (xg_get_default_scrollbar_width): New function.

* gtkutil.h: Declare xg_get_default_scrollbar_width.

* xfns.c (x_set_scroll_bar_default_width): If USE_GTK, get
min width by calling x_set_scroll_bar_default_width.

Fixes: debbugs:8505
---
 src/ChangeLog |  9 +++++++++
 src/gtkutil.c | 15 +++++++++++++++
 src/gtkutil.h |  1 +
 src/xfns.c    |  7 +++++--
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 8d55e443f65..34982819c28 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
+2011-06-05  Jan Djärv  <jan.h.d@swipnet.se>
+
+	* gtkutil.c (xg_get_default_scrollbar_width): New function.
+
+	* gtkutil.h: Declare xg_get_default_scrollbar_width.
+
+	* xfns.c (x_set_scroll_bar_default_width): If USE_GTK, get
+	min width by calling x_set_scroll_bar_default_width (Bug#8505).
+
 2011-06-05  Juanma Barranquero  <lekktu@gmail.com>
 
 	* xdisp.c (single_display_spec_intangible_p): Remove declaration.
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 6e54006d913..18c6c185eae 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -3326,6 +3326,21 @@ xg_get_widget_from_map (int idx)
   return 0;
 }
 
+int
+xg_get_default_scrollbar_width (FRAME_PTR f)
+{
+  GtkWidget *wscroll = gtk_vscrollbar_new (gtk_adjustment_new (XG_SB_MIN,
+                                                               XG_SB_MIN,
+                                                               XG_SB_MAX,
+                                                               0.1, 0.1, 0.1));
+  int w = 0, b = 0;
+  gtk_widget_style_get (wscroll, "slider-width", &w, "trough-border", &b, NULL);
+  gtk_widget_destroy (wscroll);
+  w += 2*b;
+  if (w < 16) w = 16;
+  return w;
+}
+
 /* Return the scrollbar id for X Window WID on display DPY.
    Return -1 if WID not in id_to_widget.  */
 
diff --git a/src/gtkutil.h b/src/gtkutil.h
index 3dc0a1dd150..cf58d03b0ce 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -135,6 +135,7 @@ extern void xg_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar,
                                              int position,
                                              int whole);
 extern int xg_event_is_for_scrollbar (FRAME_PTR f, XEvent *event);
+extern int xg_get_default_scrollbar_width (FRAME_PTR f);
 
 extern void update_frame_tool_bar (FRAME_PTR f);
 extern void free_frame_tool_bar (FRAME_PTR f);
diff --git a/src/xfns.c b/src/xfns.c
index f3dc493ff85..2fd995df341 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1695,10 +1695,13 @@ void
 x_set_scroll_bar_default_width (struct frame *f)
 {
   int wid = FRAME_COLUMN_WIDTH (f);
-
+  int minw = 16;
 #ifdef USE_TOOLKIT_SCROLL_BARS
+#ifdef USE_GTK
+  minw = xg_get_default_scrollbar_width (f);
+#endif
   /* A minimum width of 14 doesn't look good for toolkit scroll bars.  */
-  int width = 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM;
+  int width = minw + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM;
   FRAME_CONFIG_SCROLL_BAR_COLS (f) = (width + wid - 1) / wid;
   FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = width;
 #else
-- 
2.39.5