summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-09-25 07:41:23 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-09-25 07:41:23 +0000
commit364f9c056d58d6405fd541d95b067d8af7b7ed8b (patch)
tree2feb15c4d90974fe1915c55f8884e696e4c4cd67
parent3d4cdfc1fd61fa3b649de9056b5eca2cc058a564 (diff)
Add notification for input from a pane, from George Nachman.
-rw-r--r--usr.bin/tmux/control-notify.c31
-rw-r--r--usr.bin/tmux/input.c3
-rw-r--r--usr.bin/tmux/notify.c22
-rw-r--r--usr.bin/tmux/tmux.h5
4 files changed, 57 insertions, 4 deletions
diff --git a/usr.bin/tmux/control-notify.c b/usr.bin/tmux/control-notify.c
index 4e05dc944e6..f23d4618c99 100644
--- a/usr.bin/tmux/control-notify.c
+++ b/usr.bin/tmux/control-notify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control-notify.c,v 1.1 2012/09/03 09:32:38 nicm Exp $ */
+/* $OpenBSD: control-notify.c,v 1.2 2012/09/25 07:41:22 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -25,6 +25,35 @@
((c) != NULL && ((c)->flags & CLIENT_CONTROL))
void
+control_notify_input(struct client *c, struct window_pane *wp,
+ struct evbuffer *input)
+{
+ u_char *buf;
+ size_t len;
+ struct evbuffer *message;
+ u_int i;
+
+ if (c->session == NULL)
+ return;
+
+ buf = EVBUFFER_DATA(input);
+ len = EVBUFFER_LENGTH(input);
+
+ /*
+ * Only write input if the window pane is linked to a window belonging
+ * to the client's session.
+ */
+ if (winlink_find_by_window(&c->session->windows, wp->window) != NULL) {
+ message = evbuffer_new();
+ evbuffer_add_printf(message, "%%output %%%u ", wp->id);
+ for (i = 0; i < len; i++)
+ evbuffer_add_printf(message, "%02hhx", buf[i]);
+ control_write_buffer(c, message);
+ evbuffer_free(message);
+ }
+}
+
+void
control_notify_window_layout_changed(struct window *w)
{
struct client *c;
diff --git a/usr.bin/tmux/input.c b/usr.bin/tmux/input.c
index 9d366b43220..f44e2d45fe3 100644
--- a/usr.bin/tmux/input.c
+++ b/usr.bin/tmux/input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input.c,v 1.53 2012/07/10 11:53:01 nicm Exp $ */
+/* $OpenBSD: input.c,v 1.54 2012/09/25 07:41:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -752,6 +752,7 @@ input_parse(struct window_pane *wp)
buf = EVBUFFER_DATA(evb);
len = EVBUFFER_LENGTH(evb);
+ notify_input(wp, evb);
off = 0;
/* Parse the input. */
diff --git a/usr.bin/tmux/notify.c b/usr.bin/tmux/notify.c
index d0157dced55..dfd415bee19 100644
--- a/usr.bin/tmux/notify.c
+++ b/usr.bin/tmux/notify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: notify.c,v 1.4 2012/09/03 09:32:38 nicm Exp $ */
+/* $OpenBSD: notify.c,v 1.5 2012/09/25 07:41:22 nicm Exp $ */
/*
* Copyright (c) 2012 George Nachman <tmux@georgester.com>
@@ -133,6 +133,26 @@ notify_drain(void)
}
void
+notify_input(struct window_pane *wp, struct evbuffer *input)
+{
+ struct client *c;
+ u_int i;
+
+ /*
+ * notify_input() is not queued and only does anything when
+ * notifications are enabled.
+ */
+ if (!notify_enabled)
+ return;
+
+ for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+ c = ARRAY_ITEM(&clients, i);
+ if (c != NULL && (c->flags & CLIENT_CONTROL))
+ control_notify_input(c, wp, input);
+ }
+}
+
+void
notify_window_layout_changed(struct window *w)
{
notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED, NULL, NULL, w);
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index b0eeea156b1..b1fbc65295e 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.357 2012/09/24 13:39:10 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.358 2012/09/25 07:41:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1531,6 +1531,7 @@ enum mode_key_cmd mode_key_lookup(struct mode_key_data *, int);
/* notify.c */
void notify_enable(void);
void notify_disable(void);
+void notify_input(struct window_pane *, struct evbuffer *);
void notify_window_layout_changed(struct window *);
void notify_window_unlinked(struct session *, struct window *);
void notify_window_linked(struct session *, struct window *);
@@ -2224,6 +2225,8 @@ void printflike2 control_write(struct client *, const char *, ...);
void control_write_buffer(struct client *, struct evbuffer *);
/* control-notify.c */
+void control_notify_input(struct client *, struct window_pane *,
+ struct evbuffer *);
void control_notify_window_layout_changed(struct window *);
void control_notify_window_unlinked(struct session *, struct window *);
void control_notify_window_linked(struct session *, struct window *);