diff options
author | 2013-03-24 09:18:16 +0000 | |
---|---|---|
committer | 2013-03-24 09:18:16 +0000 | |
commit | 02ae13655d5c683ec92e1d2bb2aede2dd929b94f (patch) | |
tree | cb2aab3d8ce6477f5dcc1c4e7745f6c5a47552bc /usr.bin/tmux/server-client.c | |
parent | Match documented rc.conf(5) flags. (diff) | |
download | wireguard-openbsd-02ae13655d5c683ec92e1d2bb2aede2dd929b94f.tar.xz wireguard-openbsd-02ae13655d5c683ec92e1d2bb2aede2dd929b94f.zip |
Add support for focus notifications when tmux pane changes, based on
work by Aaron Jensen.
Diffstat (limited to 'usr.bin/tmux/server-client.c')
-rw-r--r-- | usr.bin/tmux/server-client.c | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 0a1127a2210..08f387b2e1e 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.90 2013/03/22 15:54:29 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.91 2013/03/24 09:18:16 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -28,6 +28,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 *); @@ -495,7 +496,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); @@ -503,9 +504,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; } /* |