Made pass through mode to a submode (#48).
authorDaniel Carl <danielcarl@gmx.de>
Tue, 6 Aug 2013 19:05:47 +0000 (21:05 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Tue, 6 Aug 2013 19:05:47 +0000 (21:05 +0200)
This allows to use pass through mode together with insert mode. There where
also some bugs around the vb_set_mode()'s handling for insert mode, that are
now fixed.

src/command.c
src/default.h
src/keybind.c
src/main.c
src/main.h

index 92507ee..d1cd64f 100644 (file)
@@ -948,7 +948,14 @@ gboolean command_queue(const Arg *arg)
 
 gboolean command_mode(const Arg *arg)
 {
-    return vb_set_mode(arg->i, false);
+    /* if a main mode is given - set the mode like it is */
+    if (CLEAN_MODE(arg->i)) {
+        return vb_set_mode(arg->i, false);
+    }
+
+    /* else combine the current main mode with the new submode */
+    /* TODO move this logic to main.c: vb_set_mode() */
+    return vb_set_mode(arg->i|CLEAN_MODE(vb.state.mode), false);
 }
 
 gboolean command_focusinput(const Arg *arg)
index a64931b..060e34b 100644 (file)
@@ -90,6 +90,7 @@ static char *default_config[] = {
     "cmap <up>=hist-prev",
     "cmap <down>=hist-next",
     "imap <ctrl-t>=editor",
+    "imap <ctrl-z>=pass-through",
     "shortcut-add dl=https://duckduckgo.com/html/?q=$0",
     "shortcut-add dd=https://duckduckgo.com/?q=$0",
     "shortcut-default dl",
index 59ea62e..ecae4b3 100644 (file)
@@ -257,7 +257,7 @@ static gboolean keypress_cb(WebKitWebView *webview, GdkEventKey *event)
 
     /* skip further logic if we are in pass through mode */
     if (vb.state.mode & VB_MODE_PASSTHROUGH) {
-        return true;
+        return false;
     }
 
     /* allow mode keys and counts only in normal mode and search mode */
index 09ba47c..90c9bdb 100644 (file)
@@ -196,10 +196,6 @@ gboolean vb_set_clipboard(const Arg *arg)
     return result;
 }
 
-/**
- * Set the base modes. All other mode flags like completion can be set directly
- * to vb.state.mode.
- */
 gboolean vb_set_mode(Mode mode, gboolean clean)
 {
     /* process only if mode has changed */
@@ -211,7 +207,7 @@ gboolean vb_set_mode(Mode mode, gboolean clean)
             command_search(&((Arg){VB_SEARCH_OFF}));
         } else if ((vb.state.mode & VB_MODE_HINTING) && !(mode & VB_MODE_HINTING)) {
             hints_clear();
-        } else if (CLEAN_MODE(vb.state.mode) == VB_MODE_INSERT) {
+        } else if (CLEAN_MODE(vb.state.mode) == VB_MODE_INSERT && !(mode & VB_MODE_INSERT)) {
             clean = true;
             dom_clear_focus(vb.gui.webview);
         }
@@ -221,6 +217,10 @@ gboolean vb_set_mode(Mode mode, gboolean clean)
             case VB_MODE_NORMAL:
                 history_rewind();
                 gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview));
+                if (mode & VB_MODE_PASSTHROUGH) {
+                    clean = false;
+                    vb_echo(VB_MSG_NORMAL, false, "-- PASS THROUGH --");
+                }
                 break;
 
             case VB_MODE_COMMAND:
@@ -230,13 +230,11 @@ gboolean vb_set_mode(Mode mode, gboolean clean)
             case VB_MODE_INSERT:
                 clean = false;
                 gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview));
-                vb_echo(VB_MSG_NORMAL, false, "-- INPUT --");
-                break;
-
-            case VB_MODE_PASSTHROUGH:
-                clean = false;
-                gtk_widget_grab_focus(GTK_WIDGET(vb.gui.webview));
-                vb_echo(VB_MSG_NORMAL, false, "-- PASS THROUGH --");
+                if (mode & VB_MODE_PASSTHROUGH) {
+                    vb_echo(VB_MSG_NORMAL, false, "-- PASS THROUGH --");
+                } else {
+                    vb_echo(VB_MSG_NORMAL, false, "-- INPUT --");
+                }
                 break;
         }
         vb.state.mode = mode;
index 6618191..a4d630a 100644 (file)
@@ -61,7 +61,7 @@
     gtk_editable_set_position(GTK_EDITABLE(vb.gui.inputbox), -1); \
 }
 #define GET_URI() (webkit_web_view_get_uri(vb.gui.webview))
-#define CLEAN_MODE(mode) ((mode) & ~(VB_MODE_COMPLETE | VB_MODE_SEARCH | VB_MODE_HINTING))
+#define CLEAN_MODE(mode) ((mode) & (VB_MODE_NORMAL|VB_MODE_COMMAND|VB_MODE_INSERT))
 #define CLEAR_INPUT() (vb_echo(VB_MSG_NORMAL, ""))
 #define PRIMARY_CLIPBOARD() gtk_clipboard_get(GDK_SELECTION_PRIMARY)
 #define SECONDARY_CLIPBOARD() gtk_clipboard_get(GDK_NONE)
@@ -116,8 +116,8 @@ typedef enum _vb_mode {
     VB_MODE_NORMAL        = 1<<0,
     VB_MODE_COMMAND       = 1<<1,
     VB_MODE_INSERT        = 1<<2,
-    VB_MODE_PASSTHROUGH   = 1<<3,
     /* sub modes */
+    VB_MODE_PASSTHROUGH   = 1<<3, /* normal or insert mode */
     VB_MODE_SEARCH        = 1<<4, /* normal mode */
     VB_MODE_COMPLETE      = 1<<5, /* command mode */
     VB_MODE_HINTING       = 1<<6, /* command mode */