Re: Tab width

Stelian Ionescu <[email protected]>
Newsgroups gmane.comp.web.galeon.user,gmane.comp.web.galeon.devel
Message-ID <[email protected]>
On Mon, Mar 28, 2005 at 01:21:03PM +0300, Tommi Komulainen wrote:
>On Mon, 2005-03-21 at 12:07 -0800, h3 wrote:
>> 
>> How can I get my 1.3.20 tabs to be as wide as my 1.3.14 tabs?
>
>At the moment the tab width is not configurable, the gconf keys others
>have mentioned are obsolete.  We might eventually make it configurable,
>but so far the default setting seems to have been quite alright.
>
>Anyway, currently the tab width is hardcoded to approximately 15
>characters (give or take favicon and the close button) which you can
>trivially change by modifying the DEFAULT_TAB_WIDTH_CHARS in
>utils/gul-notebook.c
>
>It would be relatively easy to make the tab width configurable, but as
>the defaults work quite nicely there hasn't been too big a need to do
>that.  If anyone is interested in hacking Galeon, this would be a nice
>task, I'd think.
I've attached a patch for this. I've tested it on single/multiple
windows and looks ok to me

Changelog:

2005-03-29  Stelian Ionescu  <[email protected]>

        * utils/prefs-strings.h
        * galeon.schemas.in: Added /apps/galeon/UI/Tabs/tab_width key

        * src/galeon-window.c: Added gconf listener for tab_width key

        * utils/gul-notebook.h
        * utils/gul-notebook.c: New function:
        * gul_notebook_set_tab_width()

-- 
Stelian Ionescu aka fe[nl]ix
Quidquid latine dictum sit, altum viditur.
tab_width.diff (text/plain, 6.6 KB)
diff -abBdru --exclude-from=exclude /usr/src/cvs/gnome/galeon/galeon.schemas.in galeon/galeon.schemas.in
--- /usr/src/cvs/gnome/galeon/galeon.schemas.in	2004-11-13 12:59:08.000000000 +0100
+++ galeon/galeon.schemas.in	2005-03-28 15:06:59.993919824 +0200
@@ -349,6 +349,17 @@
         </locale>
       </schema>
       <schema>
+        <key>/schemas/apps/galeon/UI/Tabs/tab_width</key>
+        <applyto>/apps/galeon/UI/Tabs/tab_width</applyto>
+        <owner>galeon</owner>
+        <type>int</type>
+        <default>15</default>
+        <locale name="C">
+        <short>Tab width</short>
+        <long>Tab width in characters.</long>
+        </locale>
+      </schema>
+      <schema>
         <key>/schemas/apps/galeon/UI/Tabs/favicons_in_tabs</key>
         <applyto>/apps/galeon/UI/Tabs/favicons_in_tabs</applyto>
         <owner>galeon</owner>
diff -abBdru --exclude-from=exclude /usr/src/cvs/gnome/galeon/src/galeon-window.c galeon/src/galeon-window.c
--- /usr/src/cvs/gnome/galeon/src/galeon-window.c	2005-01-31 18:53:35.000000000 +0100
+++ galeon/src/galeon-window.c	2005-03-29 01:58:11.827454312 +0200
@@ -188,6 +188,9 @@
 #define BOOKMARK_MENU_PATH		"/menubar/Bookmarks"
 #define TAB_POPUP_PATH			"/GaleonTabPopup"
 
+static GaleonTab *
+get_tab_from_page_num (GtkNotebook *notebook, gint page_num);
+
 static void
 set_offline_action_state(GtkToggleAction *action, gboolean offline)
 {
@@ -944,6 +947,59 @@
 	gul_notebook_set_policy (GUL_NOTEBOOK (notebook), policy);
 }
 
+static gint calc_tab_width_in_pixels(GtkNotebook *notebook,
+				     GaleonTab *tab,
+				     gint tab_width)
+{
+	GtkWidget	 *label, *hbox;
+	PangoFontMetrics *metrics;
+	PangoContext	 *context;
+	gint		 char_width, n_pixels;
+
+	label = tab_get_label(GUL_NOTEBOOK (notebook), GTK_WIDGET(tab));
+	hbox = GTK_WIDGET (gtk_widget_get_ancestor (label, GTK_TYPE_HBOX));
+
+	context = gtk_widget_get_pango_context (label);
+	metrics = pango_context_get_metrics (context,
+					     label->style->font_desc,
+					     pango_context_get_language (context));
+
+	char_width = pango_font_metrics_get_approximate_char_width (metrics);
+	pango_font_metrics_unref (metrics);
+
+	n_pixels = tab_width * PANGO_PIXELS(char_width);
+	n_pixels += 16;
+	n_pixels += SPACING;
+
+	return n_pixels;
+}
+
+static void
+tab_width_gconf_changed_cb(GConfClient *client,
+			   guint cnxn_id,
+			   GConfEntry *entry,
+			   GtkNotebook *notebook)
+{
+	gint		 tab_width;
+	gint		 n_pixels;
+	guint		 tab_num;
+	GaleonTab	 *curr_tab;
+	GtkWidget	 *label, *hbox;
+
+	tab_width = eel_gconf_get_integer (CONF_TABS_TAB_WIDTH);
+	tab_width = tab_width >= 0 ? tab_width : 0;
+	gul_notebook_set_tab_width (GUL_NOTEBOOK (notebook), tab_width);
+
+	curr_tab = get_tab_from_page_num(notebook, 0);
+	n_pixels = calc_tab_width_in_pixels(notebook, curr_tab, tab_width);
+
+	for(tab_num = 0; (curr_tab = get_tab_from_page_num(notebook, tab_num)); tab_num++) {
+		label = tab_get_label(GUL_NOTEBOOK (notebook), GTK_WIDGET(curr_tab));
+		hbox = GTK_WIDGET (gtk_widget_get_ancestor (label, GTK_TYPE_HBOX));
+		gtk_widget_set_size_request (hbox, n_pixels, -1);
+	}
+}
+
 static GtkNotebook *
 setup_notebook (GaleonWindow *window)
 {
@@ -1012,6 +1068,10 @@
 				(GConfClientNotifyFunc)tabbed_always_show_gconf_changed_cb,
 				notebook, &window->priv->notifiers);
     
+	galeon_notification_add(CONF_TABS_TAB_WIDTH,
+				(GConfClientNotifyFunc)tab_width_gconf_changed_cb,
+				notebook, &window->priv->notifiers);
+    
 	gtk_widget_show (GTK_WIDGET (notebook));
 
 	return notebook;
diff -abBdru --exclude-from=exclude /usr/src/cvs/gnome/galeon/utils/gul-notebook.c galeon/utils/gul-notebook.c
--- /usr/src/cvs/gnome/galeon/utils/gul-notebook.c	2005-01-07 15:00:24.000000000 +0100
+++ galeon/utils/gul-notebook.c	2005-03-29 01:35:01.200861688 +0200
@@ -30,6 +30,8 @@
 #include "gul-gui.h"
 #include "gul-string.h"
 #include "galeon-marshal.h"
+#include "prefs-strings.h"
+#include "eel-gconf-extensions.h"
 
 #include <gtk/gtkalignment.h>
 #include <gtk/gtklabel.h>
@@ -47,13 +49,8 @@
 #define AFTER_ALL_TABS          -1
 #define NOT_IN_APP_WINDOWS      -2
 
-#define DEFAULT_TAB_WIDTH_CHARS 15
 #define MENU_ITEM_MAX_LENGTH    40
 
-/* spacing between tab border and favicon/label, and between label and close
- * button */
-#define SPACING              3
-
 struct GulNotebookPrivate 
 {
 	GList *focused_pages;
@@ -325,7 +322,7 @@
 	}
 }
 
-static GtkWidget *
+GtkWidget *
 tab_get_label (GulNotebook *nb, GtkWidget *child)
 {
 	GtkWidget *hbox, *label;
@@ -661,6 +658,8 @@
 static void
 gul_notebook_init (GulNotebook *notebook)
 {
+	gint tab_width;
+
 	if (!_gul_notebook_tooltips)
 	{
 		_gul_notebook_tooltips = gtk_tooltips_new ();
@@ -678,7 +677,8 @@
 	notebook->priv->automatic_tab_switch = FALSE;
 	notebook->priv->opened_tabs = NULL;
 	notebook->priv->policy = GTK_POLICY_AUTOMATIC;
-	notebook->priv->tab_width_chars = DEFAULT_TAB_WIDTH_CHARS;
+	tab_width = eel_gconf_get_integer (CONF_TABS_TAB_WIDTH);
+	notebook->priv->tab_width_chars = tab_width >= 0 ? tab_width : 0;
 	
 	notebooks = g_list_append (notebooks, notebook);
 
@@ -1089,3 +1089,10 @@
 	nb->priv->policy = policy;
 	update_tabs_visibility (nb, FALSE);
 }
+
+void
+gul_notebook_set_tab_width (GulNotebook *nb,
+			    gint width)
+{
+	nb->priv->tab_width_chars = width;
+}
diff -abBdru --exclude-from=exclude /usr/src/cvs/gnome/galeon/utils/gul-notebook.h galeon/utils/gul-notebook.h
--- /usr/src/cvs/gnome/galeon/utils/gul-notebook.h	2004-06-05 20:23:49.000000000 +0200
+++ galeon/utils/gul-notebook.h	2005-03-29 01:35:14.871783392 +0200
@@ -69,6 +69,10 @@
 
 };
 
+/* spacing between tab border and favicon/label, and between label and close
+ * button */
+#define SPACING              3
+
 GType 		gul_notebook_get_type 		(void);
 
 GtkWidget      *gul_notebook_new 		(void);
@@ -101,6 +105,11 @@
 						 GtkWidget *child,
 						 GtkWidget *icon);
 
+void		gul_notebook_set_tab_width	(GulNotebook *nb,
+						 gint width);
+GtkWidget	*tab_get_label			(GulNotebook *nb,
+						 GtkWidget *child);
+
 G_END_DECLS
 
 #endif /* GUL_NOTEBOOK_H */
diff -abBdru --exclude-from=exclude /usr/src/cvs/gnome/galeon/utils/prefs-strings.h galeon/utils/prefs-strings.h
--- /usr/src/cvs/gnome/galeon/utils/prefs-strings.h	2004-07-26 16:53:38.000000000 +0200
+++ galeon/utils/prefs-strings.h	2005-03-28 13:34:43.300625144 +0200
@@ -24,6 +24,7 @@
 #define CONF_TABS_TABBED_NEW_COLOR "/apps/galeon/UI/Tabs/tabbed_new_color"
 #define CONF_TABS_TABBED_ALWAYS_SHOW "/apps/galeon/UI/Tabs/tabbed_always_show"
 #define CONF_TABS_TABBED_EDGE "/apps/galeon/UI/Tabs/tabbed_position"
+#define CONF_TABS_TAB_WIDTH "/apps/galeon/UI/Tabs/tab_width"
 #define CONF_TABS_FAVICON "/apps/galeon/UI/Tabs/favicons_in_tabs"
 
 /* Window appeareance */
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCSKIKKTyIuNqLpocRAsGcAKCnvn9bYMn23Nqevyd5Qqr/cy9m4gCgnX7v
NCSchx2elEskdxHGTKgavC8=
=U/ku
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.