aboutsummaryrefslogtreecommitdiff
path: root/server-client.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2013-02-22 14:32:33 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2013-02-22 14:32:33 +0000
commite43fc6f08a2fcd54df6bcc0218ad77db8dea5603 (patch)
tree6779737ecafb38607c6e06f2f790d01f8a485a5d /server-client.c
parent31407b70e00cd3e18eb9107b99ba54a5f55b79d0 (diff)
parent7d3c1016ce33d8a74af7b876e8e7c9ca00452ec1 (diff)
downloadrtmux-e43fc6f08a2fcd54df6bcc0218ad77db8dea5603.tar.gz
rtmux-e43fc6f08a2fcd54df6bcc0218ad77db8dea5603.tar.bz2
rtmux-e43fc6f08a2fcd54df6bcc0218ad77db8dea5603.zip
Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code
Diffstat (limited to 'server-client.c')
-rw-r--r--server-client.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/server-client.c b/server-client.c
index 56dd3797..d9a647e8 100644
--- a/server-client.c
+++ b/server-client.c
@@ -27,6 +27,7 @@
#include "tmux.h"
+void server_client_check_focus(struct window_pane *);
void server_client_check_mouse(struct client *, struct window_pane *);
void server_client_repeat_timer(int, short, void *);
void server_client_check_exit(struct client *);
@@ -494,7 +495,7 @@ server_client_loop(void)
/*
* Any windows will have been redrawn as part of clients, so clear
- * their flags now.
+ * their flags now. Also check and update pane focus.
*/
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
w = ARRAY_ITEM(&windows, i);
@@ -502,9 +503,52 @@ server_client_loop(void)
continue;
w->flags &= ~WINDOW_REDRAW;
- TAILQ_FOREACH(wp, &w->panes, entry)
+ TAILQ_FOREACH(wp, &w->panes, entry) {
+ server_client_check_focus(wp);
wp->flags &= ~PANE_REDRAW;
+ }
+ }
+}
+
+/* Check whether pane should be focused. */
+void
+server_client_check_focus(struct window_pane *wp)
+{
+ struct session *s;
+
+ /* If we don't care about focus, forget it. */
+ if (!(wp->base.mode & MODE_FOCUSON))
+ return;
+
+ /* If we're not the active pane in our window, we're not focused. */
+ if (wp->window->active != wp)
+ goto not_focused;
+
+ /* If we're in a mode, we're not focused. */
+ if (wp->screen != &wp->base)
+ goto not_focused;
+
+ /*
+ * If our window is the current window in any attached sessions, we're
+ * focused.
+ */
+ RB_FOREACH(s, sessions, &sessions) {
+ if (s->flags & SESSION_UNATTACHED)
+ continue;
+ if (s->curw->window == wp->window)
+ goto focused;
}
+
+not_focused:
+ if (wp->flags & PANE_FOCUSED)
+ bufferevent_write(wp->event, "\033[O", 3);
+ wp->flags &= ~PANE_FOCUSED;
+ return;
+
+focused:
+ if (!(wp->flags & PANE_FOCUSED))
+ bufferevent_write(wp->event, "\033[I", 3);
+ wp->flags |= PANE_FOCUSED;
}
/*