The branch, master has been updated
       via  ee0f8adfac76cdf21cfd2c0b503d8d66dcb883cc (commit)
      from  1ed37385c66cbfe9221e9ee4025105a5370d1ef2 (commit)

- Log -----------------------------------------------------------------
commit ee0f8adfac76cdf21cfd2c0b503d8d66dcb883cc
Author: Nicholas Marriott <nicholas.marri...@gmail.com>
Commit: Nicholas Marriott <nicholas.marri...@gmail.com>

    Handle focus events from the terminal, from Aaron Jensen.
---
 server-client.c |   23 +++++++++++++++++------
 tmux.h          |    4 ++++
 tty-keys.c      |   13 +++++++++++++
 tty.c           |    4 ++--
 4 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/server-client.c b/server-client.c
index 3c14ff8..9ac6088 100644
--- a/server-client.c
+++ b/server-client.c
@@ -17,6 +17,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/ioctl.h>
 
 #include <event.h>
 #include <fcntl.h>
@@ -95,6 +96,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++) {
@@ -545,7 +548,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))
@@ -560,13 +564,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/tmux.h b/tmux.h
index c905b66..966588c 100644
--- a/tmux.h
+++ b/tmux.h
@@ -237,6 +237,9 @@ enum key_code {
        KEYC_KP_ENTER,
        KEYC_KP_ZERO,
        KEYC_KP_PERIOD,
+
+       KEYC_FOCUS_IN,
+       KEYC_FOCUS_OUT,
 };
 
 /* Termcap codes. */
@@ -1316,6 +1319,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/tty-keys.c b/tty-keys.c
index 00327bb..575920e 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -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/tty.c b/tty.c
index b5dcf6d..ab75d94 100644
--- a/tty.c
+++ b/tty.c
@@ -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));
 


-----------------------------------------------------------------------

Summary of changes:
 server-client.c |   23 +++++++++++++++++------
 tmux.h          |    4 ++++
 tty-keys.c      |   13 +++++++++++++
 tty.c           |    4 ++--
 4 files changed, 36 insertions(+), 8 deletions(-)


hooks/post-receive
-- 
tmux

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
tmux-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to