diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-24 09:29:01 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-24 09:29:01 +0000 |
commit | 420e6fb4b9f11a32f753f5dc15ff734f11635e16 (patch) | |
tree | 6ec6654d457e89efa86aa92ecfc82cebf7f1836d /usr.bin | |
parent | 305b745009bf24b8ebbc52b8222585c7e8aa0f92 (diff) |
Handle focus events from the terminal, from Aaron Jensen.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/server-client.c | 24 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 6 | ||||
-rw-r--r-- | usr.bin/tmux/tty-keys.c | 15 | ||||
-rw-r--r-- | usr.bin/tmux/tty.c | 6 |
4 files changed, 39 insertions, 12 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 50d3d48780e..56945a18451 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.92 2013/03/24 09:25:04 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.93 2013/03/24 09:28:59 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -97,6 +97,8 @@ server_client_create(int fd) c->tty.mouse.event = MOUSE_EVENT_UP; c->tty.mouse.flags = 0; + c->flags |= CLIENT_FOCUSED; + evtimer_set(&c->repeat_timer, server_client_repeat_timer, c); for (i = 0; i < ARRAY_LENGTH(&clients); i++) { @@ -547,7 +549,8 @@ server_client_check_resize(struct window_pane *wp) void server_client_check_focus(struct window_pane *wp) { - struct session *s; + u_int i; + struct client *c; /* If we don't care about focus, forget it. */ if (!(wp->base.mode & MODE_FOCUSON)) @@ -562,13 +565,20 @@ server_client_check_focus(struct window_pane *wp) goto not_focused; /* - * If our window is the current window in any attached sessions, we're - * focused. + * If our window is the current window in any focused clients with an + * attached session, we're focused. */ - RB_FOREACH(s, sessions, &sessions) { - if (s->flags & SESSION_UNATTACHED) + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c == NULL || c->session == NULL) + continue; + + if (!(c->flags & CLIENT_FOCUSED)) continue; - if (s->curw->window == wp->window) + if (c->session->flags & SESSION_UNATTACHED) + continue; + + if (c->session->curw->window == wp->window) goto focused; } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 7cace64adb8..b4f391ef894 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.395 2013/03/24 09:27:20 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.396 2013/03/24 09:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -241,6 +241,9 @@ enum key_code { KEYC_KP_ENTER, KEYC_KP_ZERO, KEYC_KP_PERIOD, + + KEYC_FOCUS_IN, + KEYC_FOCUS_OUT, }; /* Termcap codes. */ @@ -1320,6 +1323,7 @@ struct client { #define CLIENT_READONLY 0x800 #define CLIENT_REDRAWWINDOW 0x1000 #define CLIENT_CONTROL 0x2000 +#define CLIENT_FOCUSED 0x4000 int flags; struct event identify_timer; diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c index 3125c01470b..93e04feab9d 100644 --- a/usr.bin/tmux/tty-keys.c +++ b/usr.bin/tmux/tty-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty-keys.c,v 1.55 2013/03/22 10:33:50 nicm Exp $ */ +/* $OpenBSD: tty-keys.c,v 1.56 2013/03/24 09:28:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -174,6 +174,10 @@ const struct tty_default_key_raw tty_default_raw_keys[] = { { "\033[8@", KEYC_END|KEYC_CTRL|KEYC_SHIFT }, { "\033[6@", KEYC_NPAGE|KEYC_CTRL|KEYC_SHIFT }, { "\033[5@", KEYC_PPAGE|KEYC_CTRL|KEYC_SHIFT }, + + /* Focus tracking. */ + { "\033[I", KEYC_FOCUS_IN }, + { "\033[O", KEYC_FOCUS_OUT }, }; /* Default terminfo(5) keys. */ @@ -559,6 +563,15 @@ complete_key: evtimer_del(&tty->key_timer); tty->flags &= ~TTY_TIMER; + /* Check for focus events. */ + if (key == KEYC_FOCUS_OUT) { + tty->client->flags &= ~CLIENT_FOCUSED; + return (1); + } else if (key == KEYC_FOCUS_IN) { + tty->client->flags |= CLIENT_FOCUSED; + return (1); + } + /* Fire the key. */ if (key != KEYC_NONE) server_client_handle_key(tty->client, key); diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index 0cdb382985b..c10818f6cc0 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.156 2013/03/24 09:18:16 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.157 2013/03/24 09:29:00 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -221,7 +221,7 @@ tty_start_tty(struct tty *tty) tty_puts(tty, "\033[?1000l\033[?1006l\033[?1005l"); if (tty_term_has(tty->term, TTYC_XT)) - tty_puts(tty, "\033[c\033[>4;1m\033[?1004l"); + tty_puts(tty, "\033[c\033[>4;1m\033[?1004h"); tty->cx = UINT_MAX; tty->cy = UINT_MAX; @@ -284,7 +284,7 @@ tty_stop_tty(struct tty *tty) tty_raw(tty, "\033[?1000l\033[?1006l\033[?1005l"); if (tty_term_has(tty->term, TTYC_XT)) - tty_raw(tty, "\033[>4m"); + tty_raw(tty, "\033[>4m\033[?1004l"); tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP)); |