Hi again,

I think I've been able to fix the odd "huge-window" issue with GTK3. I attach a
patch.

Girara was hiding the scrollbars by setting GTK_POLICY_NEVER. It seems that, in
GTK3, the ScrolledWindow container thinks that in such case he must fit the
children size. I have fixed it by always setting GTK_POLICY_AUTOMATIC (which
leads to the desired behaviour), and hiding the scrollbars via
gtk_widget_set_visible when necessary.

However, for some reason that eludes me, this does not work in GTK2, so I kept
two separate versions of it. Maybe somene else will be able to fix this
uniformly in GTK2 and GTK3.

Abdó Roig.

>From ecd09c580c7cea5dfa3b9c7ed289c41464561049 Mon Sep 17 00:00:00 2001
From: Abdo Roig-Maranges <abdo.r...@gmail.com>
Date: Sun, 7 Jul 2013 16:12:40 +0200
Subject: [PATCH] Do not toggle scrollbar visibility through scroll policy in
 GTK3

This fixes odd window size issues with gtk3. Prevously the scrollbars
where displayed or hidden by changing the scroll policy of
GtkScrolledWindow. It seems that in gtk3 a NEVER policy is understood as
no scrolling, so the container fits the size request of the page widget.

Now we set an AUTOMATIC scroll policy, and show or hide scrollbars
simply by changing the visibility of their widget.

For some reason, changing scrollbar widget visibility does not work in
GTK2, so I had handle GTK2 and GTK3 separately.
---
 config.c  | 51 +++++++++++++++++++++++++++++++++++++++------------
 session.c | 24 ++++++++++++++++++++----
 2 files changed, 59 insertions(+), 16 deletions(-)

diff --git a/config.c b/config.c
index f954dec..ef70f4f 100644
--- a/config.c
+++ b/config.c
@@ -115,34 +115,62 @@ cb_scrollbars(girara_session_t* session, const char* name,
 {
   g_return_if_fail(session != NULL && value != NULL);
 
-  GtkPolicyType h_policy, v_policy;
   bool val = *(bool*) value;
+  bool show_hscrollbar=false;
+  bool show_vscrollbar = false;
+  GtkPolicyType h_policy, v_policy;
+
+#if (GTK_MAJOR_VERSION == 3)
+  GtkWidget *vscrollbar = gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(session->gtk.view));
+  GtkWidget *hscrollbar = gtk_scrolled_window_get_hscrollbar(GTK_SCROLLED_WINDOW(session->gtk.view));
+
+  if (vscrollbar != NULL) {
+    show_vscrollbar = gtk_widget_get_visible(vscrollbar);
+  }
 
+  if (hscrollbar != NULL) {
+    show_hscrollbar = gtk_widget_get_visible(hscrollbar);
+  }
+#else
   gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(session->gtk.view), &h_policy, &v_policy);
+  show_vscrollbar = (v_policy == GTK_POLICY_AUTOMATIC);
+  show_hscrollbar = (h_policy == GTK_POLICY_AUTOMATIC);
+#endif
 
   if (!strcmp(name, "show-scrollbars")) {
-    if (val == true) {
-      h_policy = v_policy = GTK_POLICY_AUTOMATIC;
-    } else {
-      h_policy = v_policy = GTK_POLICY_NEVER;
-    }
+    show_hscrollbar = show_vscrollbar = val;
 
     girara_setting_set(session, "show-h-scrollbar", &val);
     girara_setting_set(session, "show-v-scrollbar", &val);
 
   } else if (!strcmp(name, "show-h-scrollbar")) {
-    h_policy = val ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER;
+    show_hscrollbar = val;
+
   } else if (!strcmp(name, "show-v-scrollbar")) {
-    v_policy = val ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER;
+    show_vscrollbar = val;
+  }
+
+#if (GTK_MAJOR_VERSION == 3)
+  if (vscrollbar != NULL) {
+    gtk_widget_set_visible(vscrollbar, show_vscrollbar);
   }
 
+  if (hscrollbar != NULL) {
+    gtk_widget_set_visible(hscrollbar, show_hscrollbar);
+  }
+#else
+  h_policy = show_hscrollbar ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER;
+  v_policy = show_vscrollbar ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER;
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(session->gtk.view), h_policy, v_policy);
-  girara_setting_get(session, "show-scrollbars", &val);
+#endif
 
-  if (h_policy == GTK_POLICY_AUTOMATIC && v_policy == GTK_POLICY_AUTOMATIC && val == false) {
+  /* be careful to avoid infinite recursion as changing settings triggers
+     cb_scrollbars call */
+  girara_setting_get(session, "show-scrollbars", &val);
+  if (show_hscrollbar && show_vscrollbar && !val) {
     val = true;
     girara_setting_set(session, "show-scrollbars", &val);
-  } else if (h_policy == GTK_POLICY_NEVER && v_policy == GTK_POLICY_NEVER && val == true) {
+  } else if (!(show_hscrollbar && show_vscrollbar) && val) {
     val = false;
     girara_setting_set(session, "show-scrollbars", &val);
   }
@@ -392,4 +420,3 @@ girara_config_parse(girara_session_t* session, const char* path)
 {
   config_parse(session, path);
 }
-
diff --git a/session.c b/session.c
index fb87f85..338ea7a 100644
--- a/session.c
+++ b/session.c
@@ -173,13 +173,29 @@ girara_session_init(girara_session_t* session, const char* sessionname)
 
   bool show_hscrollbar = false;
   bool show_vscrollbar = false;
-  GtkPolicyType hpolicy, vpolicy;
 
   girara_setting_get(session, "show-h-scrollbar", &show_hscrollbar);
   girara_setting_get(session, "show-v-scrollbar", &show_vscrollbar);
-  hpolicy = show_hscrollbar ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER;
-  vpolicy = show_vscrollbar ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER;
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(session->gtk.view), hpolicy, vpolicy);
+
+#if (GTK_MAJOR_VERSION == 3)
+  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(session->gtk.view), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+  GtkWidget *vscrollbar = gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(session->gtk.view));
+  GtkWidget *hscrollbar = gtk_scrolled_window_get_hscrollbar(GTK_SCROLLED_WINDOW(session->gtk.view));
+
+  if (vscrollbar != NULL) {
+    gtk_widget_set_visible(GTK_WIDGET(vscrollbar), show_vscrollbar);
+  }
+
+  if (hscrollbar != NULL) {
+    gtk_widget_set_visible(GTK_WIDGET(hscrollbar), show_hscrollbar);
+  }
+#else
+  GtkPolicyType h_policy, v_policy;
+  h_policy = show_hscrollbar ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER;
+  v_policy = show_vscrollbar ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER;
+  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(session->gtk.view), h_policy, v_policy);
+#endif
 
   /* viewport */
   gtk_container_add(GTK_CONTAINER(session->gtk.view), session->gtk.viewport);
-- 
1.8.3.2

_______________________________________________
zathura mailing list
zathura@lists.pwmt.org
http://lists.pwmt.org/mailman/listinfo/zathura

Reply via email to