Re: Tab width

Stelian Ionescu <[email protected]> Tue, 29 Mar 2005 02:32:11 +0200
Newsgroups gmane.comp.web.galeon.user,gmane.comp.web.galeon.devel
Message-ID <[email protected]>
--5I6of5zJg18YgZEa
Content-Type: multipart/mixed; boundary="DocE+STaALJfprDB"
Content-Disposition: inline


--DocE+STaALJfprDB
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Mar 28, 2005 at 01:21:03PM +0300, Tommi Komulainen wrote:
>On Mon, 2005-03-21 at 12:07 -0800, h3 wrote:
>>=20
>> 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()

--=20
Stelian Ionescu aka fe[nl]ix
Quidquid latine dictum sit, altum viditur.

--DocE+STaALJfprDB
Content-Type: text/plain; charset=utf-8
Content-Disposition: attachment; filename="tab_width.diff"
Content-Transfer-Encoding: quoted-printable

diff -abBdru --exclude-from=3Dexclude /usr/src/cvs/gnome/galeon/galeon.sche=
mas.in galeon/galeon.schemas.in
--- /usr/src/cvs/gnome/galeon/galeon.schemas.in	2004-11-13 12:59:08.0000000=
00 +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=3D"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=3Dexclude /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.00000=
0000 +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"
=20
+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);
 }
=20
+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 =3D tab_get_label(GUL_NOTEBOOK (notebook), GTK_WIDGET(tab));
+	hbox =3D GTK_WIDGET (gtk_widget_get_ancestor (label, GTK_TYPE_HBOX));
+
+	context =3D gtk_widget_get_pango_context (label);
+	metrics =3D pango_context_get_metrics (context,
+					     label->style->font_desc,
+					     pango_context_get_language (context));
+
+	char_width =3D pango_font_metrics_get_approximate_char_width (metrics);
+	pango_font_metrics_unref (metrics);
+
+	n_pixels =3D tab_width * PANGO_PIXELS(char_width);
+	n_pixels +=3D 16;
+	n_pixels +=3D 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 =3D eel_gconf_get_integer (CONF_TABS_TAB_WIDTH);
+	tab_width =3D tab_width >=3D 0 ? tab_width : 0;
+	gul_notebook_set_tab_width (GUL_NOTEBOOK (notebook), tab_width);
+
+	curr_tab =3D get_tab_from_page_num(notebook, 0);
+	n_pixels =3D calc_tab_width_in_pixels(notebook, curr_tab, tab_width);
+
+	for(tab_num =3D 0; (curr_tab =3D get_tab_from_page_num(notebook, tab_num)=
); tab_num++) {
+		label =3D tab_get_label(GUL_NOTEBOOK (notebook), GTK_WIDGET(curr_tab));
+		hbox =3D 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);
    =20
+	galeon_notification_add(CONF_TABS_TAB_WIDTH,
+				(GConfClientNotifyFunc)tab_width_gconf_changed_cb,
+				notebook, &window->priv->notifiers);
+   =20
 	gtk_widget_show (GTK_WIDGET (notebook));
=20
 	return notebook;
diff -abBdru --exclude-from=3Dexclude /usr/src/cvs/gnome/galeon/utils/gul-n=
otebook.c galeon/utils/gul-notebook.c
--- /usr/src/cvs/gnome/galeon/utils/gul-notebook.c	2005-01-07 15:00:24.0000=
00000 +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"
=20
 #include <gtk/gtkalignment.h>
 #include <gtk/gtklabel.h>
@@ -47,13 +49,8 @@
 #define AFTER_ALL_TABS          -1
 #define NOT_IN_APP_WINDOWS      -2
=20
-#define DEFAULT_TAB_WIDTH_CHARS 15
 #define MENU_ITEM_MAX_LENGTH    40
=20
-/* spacing between tab border and favicon/label, and between label and clo=
se
- * button */
-#define SPACING              3
-
 struct GulNotebookPrivate=20
 {
 	GList *focused_pages;
@@ -325,7 +322,7 @@
 	}
 }
=20
-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 =3D gtk_tooltips_new ();
@@ -678,7 +677,8 @@
 	notebook->priv->automatic_tab_switch =3D FALSE;
 	notebook->priv->opened_tabs =3D NULL;
 	notebook->priv->policy =3D GTK_POLICY_AUTOMATIC;
-	notebook->priv->tab_width_chars =3D DEFAULT_TAB_WIDTH_CHARS;
+	tab_width =3D eel_gconf_get_integer (CONF_TABS_TAB_WIDTH);
+	notebook->priv->tab_width_chars =3D tab_width >=3D 0 ? tab_width : 0;
 =09
 	notebooks =3D g_list_append (notebooks, notebook);
=20
@@ -1089,3 +1089,10 @@
 	nb->priv->policy =3D policy;
 	update_tabs_visibility (nb, FALSE);
 }
+
+void
+gul_notebook_set_tab_width (GulNotebook *nb,
+			    gint width)
+{
+	nb->priv->tab_width_chars =3D width;
+}
diff -abBdru --exclude-from=3Dexclude /usr/src/cvs/gnome/galeon/utils/gul-n=
otebook.h galeon/utils/gul-notebook.h
--- /usr/src/cvs/gnome/galeon/utils/gul-notebook.h	2004-06-05 20:23:49.0000=
00000 +0200
+++ galeon/utils/gul-notebook.h	2005-03-29 01:35:14.871783392 +0200
@@ -69,6 +69,10 @@
=20
 };
=20
+/* spacing between tab border and favicon/label, and between label and clo=
se
+ * button */
+#define SPACING              3
+
 GType 		gul_notebook_get_type 		(void);
=20
 GtkWidget      *gul_notebook_new 		(void);
@@ -101,6 +105,11 @@
 						 GtkWidget *child,
 						 GtkWidget *icon);
=20
+void		gul_notebook_set_tab_width	(GulNotebook *nb,
+						 gint width);
+GtkWidget	*tab_get_label			(GulNotebook *nb,
+						 GtkWidget *child);
+
 G_END_DECLS
=20
 #endif /* GUL_NOTEBOOK_H */
diff -abBdru --exclude-from=3Dexclude /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.000=
000000 +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_s=
how"
 #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"
=20
 /* Window appeareance */

--DocE+STaALJfprDB--

--5I6of5zJg18YgZEa
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCSKIKKTyIuNqLpocRAsGcAKCnvn9bYMn23Nqevyd5Qqr/cy9m4gCgnX7v
NCSchx2elEskdxHGTKgavC8=
=U/ku
-----END PGP SIGNATURE-----

--5I6of5zJg18YgZEa--


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click