]> git.armaanb.net Git - chorizo.git/commitdiff
Update main window title again
authorPeter Hofmann <scm@uninformativ.de>
Thu, 30 Apr 2020 13:50:21 +0000 (15:50 +0200)
committerPeter Hofmann <scm@uninformativ.de>
Thu, 30 Apr 2020 13:54:39 +0000 (15:54 +0200)
This is important for password managers like keepass.

Unlike the previous version of this code, we no longer traverse widget
hierarchies. Instead, a pointer to the real tab label widget is stored
on whatever widget happens to be returned by gtk_notebook_get_tab_label().
Luckily, there is an easy way to do this via g_object.

browser.c

index 2390b1cba0f4cdc862e72c81478e09bc4bb0ed5f..70460d2ddfa942afe4dc687a980c87b074c1a079 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -44,6 +44,8 @@ gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
 gboolean key_tablabel(GtkWidget *, GdkEvent *, gpointer);
 gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
 void mainwindow_setup(void);
 gboolean key_tablabel(GtkWidget *, GdkEvent *, gpointer);
 gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
 void mainwindow_setup(void);
+void mainwindow_title(gint);
+void notebook_switch_page(GtkNotebook *, GtkWidget *, guint, gpointer);
 gboolean quit_if_nothing_active(void);
 gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
 void run_user_scripts(WebKitWebView *);
 gboolean quit_if_nothing_active(void);
 gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
 void run_user_scripts(WebKitWebView *);
@@ -242,6 +244,9 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
     g_signal_connect(G_OBJECT(evbox), "scroll-event",
                      G_CALLBACK(key_tablabel), c);
 
     g_signal_connect(G_OBJECT(evbox), "scroll-event",
                      G_CALLBACK(key_tablabel), c);
 
+    /* For easy access, store a reference to our label. */
+    g_object_set_data(G_OBJECT(evbox), "lariza-tab-label", c->tablabel);
+
     /* This only shows the event box and the label inside, nothing else.
      * Needed because the evbox/label is "internal" to the notebook and
      * not part of the normal "widget tree" (IIUC). */
     /* This only shows the event box and the label inside, nothing else.
      * Needed because the evbox/label is "internal" to the notebook and
      * not part of the normal "widget tree" (IIUC). */
@@ -444,6 +449,7 @@ changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
 
     gtk_label_set_text(GTK_LABEL(c->tablabel), t);
     gtk_widget_set_tooltip_text(c->tablabel, t);
 
     gtk_label_set_text(GTK_LABEL(c->tablabel), t);
     gtk_widget_set_tooltip_text(c->tablabel, t);
+    mainwindow_title(gtk_notebook_get_current_page(GTK_NOTEBOOK(mw.notebook)));
 }
 
 void
 }
 
 void
@@ -1082,6 +1088,30 @@ mainwindow_setup(void)
     gtk_notebook_set_scrollable(GTK_NOTEBOOK(mw.notebook), TRUE);
     gtk_notebook_set_tab_pos(GTK_NOTEBOOK(mw.notebook), tab_pos);
     gtk_container_add(GTK_CONTAINER(mw.win), mw.notebook);
     gtk_notebook_set_scrollable(GTK_NOTEBOOK(mw.notebook), TRUE);
     gtk_notebook_set_tab_pos(GTK_NOTEBOOK(mw.notebook), tab_pos);
     gtk_container_add(GTK_CONTAINER(mw.win), mw.notebook);
+    g_signal_connect(G_OBJECT(mw.notebook), "switch-page",
+                     G_CALLBACK(notebook_switch_page), NULL);
+}
+
+void
+mainwindow_title(gint idx)
+{
+    GtkWidget *child, *widg, *tablabel;
+    const gchar *text;
+
+    child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(mw.notebook), idx);
+    if (child == NULL)
+        return;
+
+    widg = gtk_notebook_get_tab_label(GTK_NOTEBOOK(mw.notebook), child);
+    tablabel = (GtkWidget *)g_object_get_data(G_OBJECT(widg), "lariza-tab-label");
+    text = gtk_label_get_text(GTK_LABEL(tablabel));
+    gtk_window_set_title(GTK_WINDOW(mw.win), text);
+}
+
+void
+notebook_switch_page(GtkNotebook *nb, GtkWidget *p, guint idx, gpointer data)
+{
+    mainwindow_title(idx);
 }
 
 gboolean
 }
 
 gboolean