Added strict-focus setting.
authorDaniel Carl <danielcarl@gmx.de>
Sun, 13 Oct 2013 16:44:57 +0000 (18:44 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 13 Oct 2013 16:44:57 +0000 (18:44 +0200)
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
src/dom.c
src/main.h
src/setting.c

index 3664fa6..ec07a51 100644 (file)
@@ -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",
index c9d7ade..f13c3af 100644 (file)
--- 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));
index 5ad8805..7ff281b 100644 (file)
@@ -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 {
index fab9d19..6ebacc4 100644 (file)
@@ -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;