Show mode label in statusbar.
authorDaniel Carl <danielcarl@gmx.de>
Wed, 26 Nov 2014 21:55:19 +0000 (22:55 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 1 Dec 2014 23:17:59 +0000 (00:17 +0100)
This avoid often opening inputbox in case 'input-autohide=on' is set.

src/input.c
src/main.c
src/main.h
src/pass.c
tests/test-map.c

index 5da62e8..043039a 100644 (file)
@@ -44,7 +44,7 @@ void input_enter(void)
     /* switch focus first to make sure we can write to the inputbox without
      * disturbing the user */
     gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview));
-    vb_echo(VB_MSG_NORMAL, false, "-- INPUT --");
+    vb_update_mode_label("-- INPUT --");
 }
 
 /**
@@ -52,7 +52,7 @@ void input_enter(void)
  */
 void input_leave(void)
 {
-    vb_set_input_text("");
+    vb_update_mode_label("");
 }
 
 /**
@@ -68,7 +68,13 @@ VbResult input_keypress(int key)
         VbResult res = normal_keypress(key);
         if (res != RESULT_MORE) {
             ctrlo = false;
-            vb_echo(VB_MSG_NORMAL, false, "-- INPUT --");
+            /* Don't overwrite the mode label in case we landed in another
+             * mode. This might occurre by CTRL-0 CTRL-Z or after running ex
+             * command, where we mainly end up in normal mode. */
+            if (vb.mode->id == 'i') {
+                /* reenter the input mode */
+                input_enter();
+            }
         }
         return res;
     }
@@ -82,7 +88,7 @@ VbResult input_keypress(int key)
             /* enter CTRL-0 mode to execute next command in normal mode */
             ctrlo           = true;
             vb.mode->flags |= FLAG_NOMAP;
-            vb_echo(VB_MSG_NORMAL, false, "-- (input) --");
+            vb_update_mode_label("-- (input) --");
             return RESULT_MORE;
 
         case CTRL('T'):
index 7a4d5d4..7384d34 100644 (file)
@@ -365,6 +365,9 @@ void vb_update_status_style(void)
     vb_set_widget_font(
         vb.gui.eventbox, &vb.style.status_fg[type], &vb.style.status_bg[type], vb.style.status_font[type]
     );
+    vb_set_widget_font(
+        vb.gui.statusbar.mode, &vb.style.status_fg[type], &vb.style.status_bg[type], vb.style.status_font[type]
+    );
     vb_set_widget_font(
         vb.gui.statusbar.left, &vb.style.status_fg[type], &vb.style.status_bg[type], vb.style.status_font[type]
     );
@@ -407,6 +410,16 @@ void vb_update_urlbar(const char *uri)
 #endif
 }
 
+void vb_update_mode_label(const char *label)
+{
+    if (GET_BOOL("input-autohide")) {
+        /* if the inputbox is potentially not shown write mode into statusbar */
+        gtk_label_set_text(GTK_LABEL(vb.gui.statusbar.mode), label);
+    } else {
+        vb_echo(VB_MSG_NORMAL, false, "%s", label);
+    }
+}
+
 void vb_quit(gboolean force)
 {
     /* if not forced quit - don't quit if there are still running downloads */
@@ -780,6 +793,7 @@ static void init_core(void)
     gui->box             = GTK_BOX(gtk_vbox_new(false, 0));
     gui->statusbar.box   = GTK_BOX(gtk_hbox_new(false, 0));
 #endif
+    gui->statusbar.mode  = gtk_label_new(NULL);
     gui->statusbar.left  = gtk_label_new(NULL);
     gui->statusbar.right = gtk_label_new(NULL);
     gui->statusbar.cmd   = gtk_label_new(NULL);
@@ -794,11 +808,14 @@ static void init_core(void)
     gtk_container_add(GTK_CONTAINER(gui->eventbox), GTK_WIDGET(gui->statusbar.box));
     gtk_container_add(GTK_CONTAINER(gui->window), GTK_WIDGET(gui->pane));
 #ifdef HAS_GTK3
+    gtk_widget_set_halign(gui->statusbar.mode, GTK_ALIGN_START);
     gtk_widget_set_halign(gui->statusbar.left, GTK_ALIGN_START);
 #else
+    gtk_misc_set_alignment(GTK_MISC(gui->statusbar.mode), 0.0, 0.0);
     gtk_misc_set_alignment(GTK_MISC(gui->statusbar.left), 0.0, 0.0);
 #endif
     gtk_label_set_ellipsize(GTK_LABEL(gui->statusbar.left), PANGO_ELLIPSIZE_END);
+    gtk_box_pack_start(gui->statusbar.box, gui->statusbar.mode, false, true, 0);
     gtk_box_pack_start(gui->statusbar.box, gui->statusbar.left, true, true, 2);
     gtk_box_pack_start(gui->statusbar.box, gui->statusbar.cmd, false, false, 0);
     gtk_box_pack_start(gui->statusbar.box, gui->statusbar.right, false, false, 2);
index 4c480b7..76b5d8c 100644 (file)
@@ -271,6 +271,7 @@ typedef struct {
 /* statusbar */
 typedef struct {
     GtkBox    *box;
+    GtkWidget *mode;
     GtkWidget *left;
     GtkWidget *right;
     GtkWidget *cmd;
@@ -393,6 +394,7 @@ void vb_update_statusbar(void);
 void vb_update_status_style(void);
 void vb_update_input_style(void);
 void vb_update_urlbar(const char *uri);
+void vb_update_mode_label(const char *label);
 void vb_register_add(char buf, const char *value);
 const char *vb_register_get(char buf);
 gboolean vb_download(WebKitWebView *view, WebKitDownload *download, const char *path);
index 73d7eb3..d98104a 100644 (file)
@@ -32,10 +32,7 @@ extern VbCore vb;
  */
 void pass_enter(void)
 {
-    /* switch focus first to make sure we can write to the inputbox without
-     * disturbing the user */
-    gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview));
-    vb_echo(VB_MSG_NORMAL, false, "-- PASS THROUGH --");
+    vb_update_mode_label("-- PASS THROUGH --");
 }
 
 /**
@@ -43,7 +40,7 @@ void pass_enter(void)
  */
 void pass_leave(void)
 {
-    vb_set_input_text("");
+    vb_update_mode_label("");
 }
 
 VbResult pass_keypress(int key)
index 93f51e7..a862acd 100644 (file)
@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
 
     /* add a test mode to handle the maped sequences */
     mode_init();
-    mode_add('t', NULL, NULL, keypress, NULL);
+    mode_add('t', NULL, NULL, keypress, NULL, "");
     mode_enter('t');
 
     g_test_add_func("/test-map/handle_string/simple", test_handle_string_simple);