From ce1fcd3d58f6406f457a5f9a6ce1858626e8f790 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Mon, 5 Aug 2013 21:10:30 +0200
Subject: [PATCH] Added command pass-through to switch to pass through mode.

The pass-through mode allows to skip all keybindings accept of <esc> and
<ctrl-c> in vimb to let the webview handle them.
---
 doc/vimb.1    | 14 ++++++++++++++
 src/command.c |  6 ++++++
 src/command.h |  1 +
 src/default.h |  1 +
 src/keybind.c |  5 +++++
 src/main.c    |  6 ++++++
 src/main.h    |  7 ++++---
 7 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/doc/vimb.1 b/doc/vimb.1
index c6b2041..9e0cdfd 100644
--- a/doc/vimb.1
+++ b/doc/vimb.1
@@ -48,6 +48,12 @@ Used for editing text elements in a webpage.
 .TP
 .B Command Mode
 Execute PROJECT commands from the builtin inputbox (commandline).
+.TP
+.B Pass-Through Mode
+In Pass-Through mode only the <ctrl-c> and <esc> keybindings are interpreted
+by PROJECT, all other keystrokes are given to the webview to handle them. This
+allows to use websites that uses keybindings itself, that might be swallowed
+by PROJECT else.
 
 .SH COMMANDS
 Commands are a central part in PROJECT. They are used for nearly all things
@@ -369,6 +375,11 @@ Format:
 
 Example:
 ":run set input-bg-normal=#ff0 | set input-fg-normal=#f0f | 5pagedown"
+
+.TP
+.B pass-through
+Switch PROJECT into pass-trough mode.
+
 .TP
 .BI "shellcmd " CMD
 Runs given shell \fICMD\fP syncron and print the output into inputbox. The
@@ -636,6 +647,9 @@ Search for \fIN\fPnth next search result.
 .TP
 .BI [ N ]N
 Search for \fIN\fPnth previous search result.
+.TP
+.B ctrl-z
+Switch PROJECT into pass-through mode.
 
 .SS COMMAND_MODE
 .TP
diff --git a/src/command.c b/src/command.c
index 62b8cb1..0f64951 100644
--- a/src/command.c
+++ b/src/command.c
@@ -131,6 +131,7 @@ static CommandInfo cmd_list[] = {
     {"queue-pop",                 NULL,    command_queue,                {COMMAND_QUEUE_POP}},
     {"queue-clear",               NULL,    command_queue,                {COMMAND_QUEUE_CLEAR}},
 #endif
+    {"pass-through",              NULL,    command_mode,                 {VB_MODE_PASSTHROUGH}},
 };
 
 static void editor_resume(GPid pid, int status, OpenEditorData *data);
@@ -944,6 +945,11 @@ gboolean command_queue(const Arg *arg)
 }
 #endif
 
+gboolean command_mode(const Arg *arg)
+{
+    return vb_set_mode(arg->i, false);
+}
+
 gboolean command_editor(const Arg *arg)
 {
     char *file_path = NULL;
diff --git a/src/command.h b/src/command.h
index 50e5ab0..3cdd36f 100644
--- a/src/command.h
+++ b/src/command.h
@@ -93,5 +93,6 @@ gboolean command_shellcmd(const Arg *arg);
 #ifdef FEATURE_QUEUE
 gboolean command_queue(const Arg *arg);
 #endif
+gboolean command_mode(const Arg *arg);
 
 #endif /* end of include guard: _COMMAND_H */
diff --git a/src/default.h b/src/default.h
index 7dfb4be..929c222 100644
--- a/src/default.h
+++ b/src/default.h
@@ -83,6 +83,7 @@ static char *default_config[] = {
     "nmap zz=zoomreset",
     "nmap gu=descent",
     "nmap gU=descent!",
+    "nmap <ctrl-z>=pass-through",
     "cmap <tab>=next",
     "cmap <shift-tab>=prev",
     "cmap <up>=hist-prev",
diff --git a/src/keybind.c b/src/keybind.c
index 00c7879..59ea62e 100644
--- a/src/keybind.c
+++ b/src/keybind.c
@@ -255,6 +255,11 @@ static gboolean keypress_cb(WebKitWebView *webview, GdkEventKey *event)
         return true;
     }
 
+    /* skip further logic if we are in pass through mode */
+    if (vb.state.mode & VB_MODE_PASSTHROUGH) {
+        return true;
+    }
+
     /* allow mode keys and counts only in normal mode and search mode */
     if (vb.state.mode & (VB_MODE_NORMAL|VB_MODE_SEARCH)) {
         if (vb.state.modkey == 0 && ((keyval >= GDK_1 && keyval <= GDK_9)
diff --git a/src/main.c b/src/main.c
index 5b9739f..5732823 100644
--- a/src/main.c
+++ b/src/main.c
@@ -232,6 +232,12 @@ gboolean vb_set_mode(Mode mode, gboolean clean)
                 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 --");
+                break;
         }
         vb.state.mode = mode;
     }
diff --git a/src/main.h b/src/main.h
index 6e6854d..6618191 100644
--- a/src/main.h
+++ b/src/main.h
@@ -116,10 +116,11 @@ 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_SEARCH        = 1<<3, /* normal mode */
-    VB_MODE_COMPLETE      = 1<<4, /* command mode */
-    VB_MODE_HINTING       = 1<<5, /* command mode */
+    VB_MODE_SEARCH        = 1<<4, /* normal mode */
+    VB_MODE_COMPLETE      = 1<<5, /* command mode */
+    VB_MODE_HINTING       = 1<<6, /* command mode */
 } Mode;
 
 typedef enum {
-- 
2.20.1