From 459a6456574070cf6fe8cee24a59ecc5d6044479 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Wed, 26 Nov 2014 22:55:19 +0100 Subject: [PATCH] Show mode label in statusbar. This avoid often opening inputbox in case 'input-autohide=on' is set. --- src/input.c | 14 ++++++++++---- src/main.c | 17 +++++++++++++++++ src/main.h | 2 ++ src/pass.c | 7 ++----- tests/test-map.c | 2 +- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/input.c b/src/input.c index 5da62e8..043039a 100644 --- a/src/input.c +++ b/src/input.c @@ -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'): diff --git a/src/main.c b/src/main.c index 7a4d5d4..7384d34 100644 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/src/main.h b/src/main.h index 4c480b7..76b5d8c 100644 --- a/src/main.h +++ b/src/main.h @@ -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); diff --git a/src/pass.c b/src/pass.c index 73d7eb3..d98104a 100644 --- a/src/pass.c +++ b/src/pass.c @@ -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) diff --git a/tests/test-map.c b/tests/test-map.c index 93f51e7..a862acd 100644 --- a/tests/test-map.c +++ b/tests/test-map.c @@ -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); -- 2.20.1