From 59f4f50d89d3cf8ae903f3756551787e8d438912 Mon Sep 17 00:00:00 2001
From: Anish Athalye <me@anishathalye.com>
Date: Wed, 6 Aug 2014 22:29:59 -0700
Subject: [PATCH] Add feature to enable or disable keyboard input

Add new options to the select-pane and last-pane commands to enable or
disable keyboard input for specific panes.
---
 cmd-select-pane.c | 34 +++++++++++++++++++++++-----------
 tmux.1            | 23 +++++++++++++++++++----
 tmux.h            |  1 +
 window.c          |  4 ++++
 4 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/cmd-select-pane.c b/cmd-select-pane.c
index c342fef..30cfed4 100644
--- a/cmd-select-pane.c
+++ b/cmd-select-pane.c
@@ -29,8 +29,8 @@ enum cmd_retval	 cmd_select_pane_exec(struct cmd *, struct cmd_q *);
 
 const struct cmd_entry cmd_select_pane_entry = {
 	"select-pane", "selectp",
-	"lDLRt:U", 0, 0,
-	"[-lDLRU] " CMD_TARGET_PANE_USAGE,
+	"DdeLlRt:U", 0, 0,
+	"[-DdeLlRU] " CMD_TARGET_PANE_USAGE,
 	0,
 	cmd_select_pane_key_binding,
 	cmd_select_pane_exec
@@ -38,8 +38,8 @@ const struct cmd_entry cmd_select_pane_entry = {
 
 const struct cmd_entry cmd_last_pane_entry = {
 	"last-pane", "lastp",
-	"t:", 0, 0,
-	CMD_TARGET_WINDOW_USAGE,
+	"det:", 0, 0,
+	"[-de] " CMD_TARGET_WINDOW_USAGE,
 	0,
 	NULL,
 	cmd_select_pane_exec
@@ -78,10 +78,16 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
 			return (CMD_RETURN_ERROR);
 		}
 
-		server_unzoom_window(wl->window);
-		window_set_active_pane(wl->window, wl->window->last);
-		server_status_window(wl->window);
-		server_redraw_window_borders(wl->window);
+		if (args_has(self->args, 'e'))
+			wl->window->last->flags &= ~PANE_INPUT_DISABLED;
+		else if (args_has(self->args, 'd'))
+			wl->window->last->flags |= PANE_INPUT_DISABLED;
+		else {
+			server_unzoom_window(wl->window);
+			window_set_active_pane(wl->window, wl->window->last);
+			server_status_window(wl->window);
+			server_redraw_window_borders(wl->window);
+		}
 
 		return (CMD_RETURN_NORMAL);
 	}
@@ -108,9 +114,15 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
 		return (CMD_RETURN_ERROR);
 	}
 
-	window_set_active_pane(wl->window, wp);
-	server_status_window(wl->window);
-	server_redraw_window_borders(wl->window);
+	if (args_has(self->args, 'e'))
+		wp->flags &= ~PANE_INPUT_DISABLED;
+	else if (args_has(self->args, 'd'))
+		wp->flags |= PANE_INPUT_DISABLED;
+	else {
+		window_set_active_pane(wl->window, wp);
+		server_status_window(wl->window);
+		server_redraw_window_borders(wl->window);
+	}
 
 	return (CMD_RETURN_NORMAL);
 }
diff --git a/tmux.1 b/tmux.1
index 924157d..dec79b5 100644
--- a/tmux.1
+++ b/tmux.1
@@ -14,7 +14,7 @@
 .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: March 25 2013 $
+.Dd $Mdocdate: August 7 2014 $
 .Dt TMUX 1
 .Os
 .Sh NAME
@@ -1296,7 +1296,7 @@ flag, see the
 section.
 This command works only if at least one client is attached.
 .It Ic display-panes Op Fl t Ar target-client
-.D1 (alias: Ic displayp)
+.D1 (alias: Ic displayp )
 Display a visible indicator of each pane shown by
 .Ar target-client .
 See the
@@ -1386,9 +1386,18 @@ The
 .Fl a
 option kills all but the window given with
 .Fl t .
-.It Ic last-pane Op Fl t Ar target-window
+.It Xo Ic last-pane
+.Op Fl de
+.Op Fl t Ar target-window
+.Xc
 .D1 (alias: Ic lastp )
 Select the last (previously selected) pane.
+If one of
+.Fl e
+or
+.Fl d
+is used, the pane is not selected, and instead, keyboard input to the pane is
+enabled or disabled, respectively.
 .It Ic last-window Op Fl t Ar target-session
 .D1 (alias: Ic last )
 Select the last (previously selected) window.
@@ -1705,7 +1714,7 @@ and
 .Ic previous-layout
 commands.
 .It Xo Ic select-pane
-.Op Fl lDLRU
+.Op Fl DdeLlRU
 .Op Fl t Ar target-pane
 .Xc
 .D1 (alias: Ic selectp )
@@ -1714,6 +1723,12 @@ Make pane
 the active pane in window
 .Ar target-window .
 If one of
+.Fl e
+or
+.Fl d
+is used, the pane is not made the active pane, and instead, keyboard input to
+the pane is enabled or disabled, respectively.
+If one of
 .Fl D ,
 .Fl L ,
 .Fl R ,
diff --git a/tmux.h b/tmux.h
index c4c5236..f7e10e0 100644
--- a/tmux.h
+++ b/tmux.h
@@ -918,6 +918,7 @@ struct window_pane {
 #define PANE_FOCUSED 0x4
 #define PANE_RESIZE 0x8
 #define PANE_FOCUSPUSH 0x10
+#define PANE_INPUT_DISABLED 0x20
 
 	int		 argc;
 	char	       **argv;
diff --git a/window.c b/window.c
index 5b93f93..e78142a 100644
--- a/window.c
+++ b/window.c
@@ -1076,6 +1076,10 @@ window_pane_key(struct window_pane *wp, struct session *sess, int key)
 
 	if (wp->fd == -1)
 		return;
+
+	if (wp->flags & PANE_INPUT_DISABLED)
+		return;
+
 	input_key(wp, key);
 	if (options_get_number(&wp->window->options, "synchronize-panes")) {
 		TAILQ_FOREACH(wp2, &wp->window->panes, entry) {
-- 
1.9.1
