Show progress in window title.
authorDaniel Carl <danielcarl@gmx.de>
Thu, 16 Jun 2016 21:48:55 +0000 (23:48 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Thu, 16 Jun 2016 21:48:55 +0000 (23:48 +0200)
src/config.def.h
src/main.c
src/main.h

index 3f85383..cc3b915 100644 (file)
 #define FEATURE_HISTORY_INDICATOR
 /* show wget style progressbar in status bar */
 #define FEATURE_WGET_PROGRESS_BAR
+/* show load progress in window title */
+#define FEATURE_TITLE_PROGRESS
+/* show page title in url completions */
+#define FEATURE_TITLE_IN_COMPLETION
+
 #ifdef FEATURE_WGET_PROGRESS_BAR
 /* chars to use for the progressbar */
-#define PROGRESS_BAR                "=> "
+#define PROGRESS_BAR             "=> "
 #define PROGRESS_BAR_LEN            20
 #endif
-/* show page title in url completions */
-#define FEATURE_TITLE_IN_COMPLETION
 
 /* time in seconds after that message will be removed from inputbox if the
  * message where only temporary */
index 982ec7c..39d8770 100644 (file)
@@ -70,6 +70,7 @@ static gboolean on_webview_web_process_crashed(WebKitWebView *webview, Client *c
 static void on_window_destroy(GtkWidget *window, Client *c);
 static gboolean quit(Client *c);
 static void register_cleanup(Client *c);
+static void update_title(Client *c);
 static void update_urlbar(Client *c);
 static void set_statusbar_style(Client *c, StatusType type);
 static void set_title(Client *c, const char *title);
@@ -683,7 +684,9 @@ static void set_statusbar_style(Client *c, StatusType type)
  */
 static void set_title(Client *c, const char *title)
 {
-    gtk_window_set_title(GTK_WINDOW(c->window), title);
+    OVERWRITE_STRING(c->state.title, title);
+    update_title(c);
+    g_setenv("VIMB_TITLE", title ? title : "", true);
 }
 
 /**
@@ -909,6 +912,7 @@ static void on_webview_notify_estimated_load_progress(WebKitWebView *webview,
 {
     c->state.progress = webkit_web_view_get_estimated_load_progress(webview) * 100;
     vb_statusbar_update(c);
+    update_title(c);
 }
 
 /**
@@ -983,6 +987,26 @@ static void register_cleanup(Client *c)
     }
 }
 
+static void update_title(Client *c)
+{
+#ifdef FEATURE_TITLE_PROGRESS
+    /* Show load status of page or the downloads. */
+    if (c->state.progress != 100) {
+        char *title = g_strdup_printf(
+                "[%i%%] %s",
+                c->state.progress,
+                c->state.title ? c->state.title : "");
+        gtk_window_set_title(GTK_WINDOW(c->window), title);
+        g_free(title);
+
+        return;
+    }
+#endif
+    if (c->state.title) {
+        gtk_window_set_title(GTK_WINDOW(c->window), c->state.title);
+    }
+}
+
 /**
  * Update the contents of the url bar on the left of the statu bar according
  * to current opened url and position in back forward history.
index b4af03e..6e91291 100644 (file)
@@ -162,6 +162,7 @@ struct State {
     StatusType          status_type;
     glong               scroll_max;         /* Maxmimum scrollable height of the document. */
     guint               scroll_percent;     /* Current position of the viewport in document. */
+    char                *title;             /* Window title of the client. */
 
     char                *reg[REG_SIZE];     /* holds the yank buffers */
     /* TODO rename to reg_{enabled,current} */