From bef534c030e2df9f808035fe7bf9e6d9480b73e3 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sun, 13 Oct 2013 18:44:57 +0200 Subject: [PATCH] Added strict-focus setting. This allows to ignore possible focused form fields on pages that forces vimb into input mode. If 'strict-focus' is on, vimb removes the focus from form fields event if the page say that say should be focussed, --- src/default.h | 1 + src/dom.c | 10 +++++++--- src/main.h | 15 ++++++++------- src/setting.c | 16 ++++++++++++++++ 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/default.h b/src/default.h index 3664fa6..ec07a51 100644 --- a/src/default.h +++ b/src/default.h @@ -35,6 +35,7 @@ static char *default_config[] = { "set proxy=on", "set cookie-timeout=4800", "set strict-ssl=on", + "set strict-focus=off", "set scrollstep=40", "set status-color-bg=#000", "set status-color-fg=#fff", diff --git a/src/dom.c b/src/dom.c index c9d7ade..f13c3af 100644 --- a/src/dom.c +++ b/src/dom.c @@ -35,9 +35,13 @@ void dom_check_auto_insert(WebKitWebView *view) Document *doc = webkit_web_view_get_dom_document(view); Element *active = get_active_element(doc); - /* the focus was not set automatically - add event listener to track focus - * events on the document */ - if (!auto_insert(active)) { + if (vb.config.strict_focus || !auto_insert(active)) { + /* if the strict-focus is on also blur the possible active element */ + if (vb.config.strict_focus) { + dom_clear_focus(view); + } + /* the focus was not set automatically - add event listener to track + * focus events on the document */ HtmlElement *element = webkit_dom_document_get_body(doc); if (!element) { element = WEBKIT_DOM_HTML_ELEMENT(webkit_dom_document_get_document_element(doc)); diff --git a/src/main.h b/src/main.h index 5ad8805..7ff281b 100644 --- a/src/main.h +++ b/src/main.h @@ -274,13 +274,14 @@ typedef struct { } State; typedef struct { - time_t cookie_timeout; - int scrollstep; - char *home_page; - char *download_dir; - guint history_max; - char *editor_command; - guint timeoutlen; /* timeout for ambiguous mappings */ + time_t cookie_timeout; + int scrollstep; + char *home_page; + char *download_dir; + guint history_max; + char *editor_command; + guint timeoutlen; /* timeout for ambiguous mappings */ + gboolean strict_focus; } Config; typedef struct { diff --git a/src/setting.c b/src/setting.c index fab9d19..6ebacc4 100644 --- a/src/setting.c +++ b/src/setting.c @@ -37,6 +37,7 @@ static gboolean status_font(const Setting *s, const SettingType type); static gboolean input_style(const Setting *s, const SettingType type); static gboolean completion_style(const Setting *s, const SettingType type); static gboolean strict_ssl(const Setting *s, const SettingType type); +static gboolean strict_focus(const Setting *s, const SettingType type); static gboolean ca_bundle(const Setting *s, const SettingType type); static gboolean home_page(const Setting *s, const SettingType type); static gboolean download_path(const Setting *s, const SettingType type); @@ -79,6 +80,7 @@ static Setting default_settings[] = { {NULL, "proxy", TYPE_BOOLEAN, proxy, {0}}, {NULL, "cookie-timeout", TYPE_INTEGER, cookie_timeout, {0}}, {NULL, "strict-ssl", TYPE_BOOLEAN, strict_ssl, {0}}, + {NULL, "strict-focus", TYPE_BOOLEAN, strict_focus, {0}}, {NULL, "scrollstep", TYPE_INTEGER, scrollstep, {0}}, {NULL, "status-color-bg", TYPE_COLOR, status_color_bg, {0}}, @@ -547,6 +549,20 @@ static gboolean strict_ssl(const Setting *s, const SettingType type) return true; } +static gboolean strict_focus(const Setting *s, const SettingType type) +{ + if (type != SETTING_SET) { + if (type == SETTING_TOGGLE) { + vb.config.strict_focus = !vb.config.strict_focus; + } + print_value(s, &vb.config.strict_focus); + } else { + vb.config.strict_focus = s->arg.i ? true : false; + } + + return true; +} + static gboolean ca_bundle(const Setting *s, const SettingType type) { char *value; -- 2.20.1