From: Daniel Carl Date: Sat, 20 Sep 2014 22:31:16 +0000 (+0200) Subject: Added setting input-autohide. X-Git-Url: https://git.owens.tech/about.html/about.html/git?a=commitdiff_plain;h=8b05f6652bf26b4829e3e191af546678eb2be585;p=vimb.git Added setting input-autohide. This allows to hide the inputbox whenever it contains no text. This is the behaviour of pentadactyl and might be useful if vimb is running on small screens. --- diff --git a/doc/vimb.1 b/doc/vimb.1 index c65abf9..c190b27 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -1047,6 +1047,9 @@ Homepage that vimb opens if started without a URI. .B hsts (bool) Enable or disables the HSTS (HTTP Strict Transport Security) feature. .TP +.B input-autohide (bool) +If enabled the inputbox will be hidden whenever it contains no text. +.TP .B input-bg-error (color) Background color for the inputbox if error is shown. .TP diff --git a/src/main.c b/src/main.c index 27eb08b..efe3841 100644 --- a/src/main.c +++ b/src/main.c @@ -161,6 +161,9 @@ static void input_print(gboolean force, const MessageType type, gboolean hide, void vb_set_input_text(const char *text) { gtk_text_buffer_set_text(vb.gui.buffer, text, -1); + if (vb.config.input_autohide) { + gtk_widget_set_visible(GTK_WIDGET(vb.gui.input), *text != '\0'); + } } /** diff --git a/src/main.h b/src/main.h index 103ac09..5f2e7d9 100644 --- a/src/main.h +++ b/src/main.h @@ -324,6 +324,7 @@ typedef struct { GTlsDatabase *tls_db; /* tls database */ float default_zoom; /* default zoomlevel that is applied on zz zoom reset */ gboolean kioskmode; + gboolean input_autohide; /* indicates if the inputbox should be hidden if it's empty */ #ifdef FEATURE_HSTS HSTSProvider *hsts_provider; /* the hsts session feature that is added to soup session */ #endif diff --git a/src/setting.c b/src/setting.c index be0efcb..8f265da 100644 --- a/src/setting.c +++ b/src/setting.c @@ -63,6 +63,7 @@ static int webkit(const char *name, int type, void *value, void *data); static int pagecache(const char *name, int type, void *value, void *data); static int soup(const char *name, int type, void *value, void *data); static int internal(const char *name, int type, void *value, void *data); +static int input_autohide(const char *name, int type, void *value, void *data); static int input_color(const char *name, int type, void *value, void *data); static int statusbar(const char *name, int type, void *value, void *data); static int status_color(const char *name, int type, void *value, void *data); @@ -178,6 +179,7 @@ void setting_init() setting_add("status-sslinvalid-font", TYPE_FONT, &SETTING_GUI_FONT_EMPH, status_font, 0, &vb.style.status_font[VB_STATUS_SSL_INVALID]); i = 1000; setting_add("timeoutlen", TYPE_INTEGER, &i, internal, 0, &vb.config.timeoutlen); + setting_add("input-autohide", TYPE_BOOLEAN, &off, input_autohide, 0, &vb.config.input_autohide); setting_add("input-bg-normal", TYPE_COLOR, &"#ffffff", input_color, 0, &vb.style.input_bg[VB_MSG_NORMAL]); setting_add("input-bg-error", TYPE_COLOR, &"#ff7777", input_color, 0, &vb.style.input_bg[VB_MSG_ERROR]); setting_add("input-fg-normal", TYPE_COLOR, &"#000000", input_color, 0, &vb.style.input_fg[VB_MSG_NORMAL]); @@ -592,6 +594,27 @@ static int internal(const char *name, int type, void *value, void *data) return SETTING_OK; } +static int input_autohide(const char *name, int type, void *value, void *data) +{ + char *text; + /* save selected value in internal variable */ + *(gboolean*)data = *(gboolean*)value; + + /* if autohide is on and inputbox contains no text - hide it now */ + if (*(gboolean*)value) { + text = vb_get_input_text(); + if (!*text) { + gtk_widget_set_visible(GTK_WIDGET(vb.gui.input), false); + } + g_free(text); + } else { + /* autohide is off - make sure the input box is shown */ + gtk_widget_set_visible(GTK_WIDGET(vb.gui.input), true); + } + + return SETTING_OK; +} + static int input_color(const char *name, int type, void *value, void *data) { VB_COLOR_PARSE((VbColor*)data, (char*)value);