aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2013-06-23 13:10:46 +0000
committerNicholas Marriott <nicm@openbsd.org>2013-06-23 13:10:46 +0000
commit3977dba76139b5d4b0a6e60458d39a374beeedf3 (patch)
treec9a2eb74d17f3b685766bd460258b460eddb3a4b
parenta41cd8d75b55da5a1e75e187b30b33917c18c1b2 (diff)
downloadrtmux-3977dba76139b5d4b0a6e60458d39a374beeedf3.tar.gz
rtmux-3977dba76139b5d4b0a6e60458d39a374beeedf3.tar.bz2
rtmux-3977dba76139b5d4b0a6e60458d39a374beeedf3.zip
Focus events can cause trouble if left on and they can't be turned off
during idle periods (like the other states are) because we'd miss events. So add a server option to control them. Defaults to off.
-rw-r--r--options-table.c5
-rw-r--r--server-client.c13
-rw-r--r--tmux.18
-rw-r--r--tmux.h5
-rw-r--r--tty.c14
5 files changed, 41 insertions, 4 deletions
diff --git a/options-table.c b/options-table.c
index c73842f7..cf0202b7 100644
--- a/options-table.c
+++ b/options-table.c
@@ -76,6 +76,11 @@ const struct options_table_entry server_options_table[] = {
.default_num = 0
},
+ { .name = "focus-events",
+ .type = OPTIONS_TABLE_FLAG,
+ .default_num = 0
+ },
+
{ .name = "quiet",
.type = OPTIONS_TABLE_FLAG,
.default_num = 0 /* overridden in main() */
diff --git a/server-client.c b/server-client.c
index 3b7b988a..5f61f5c0 100644
--- a/server-client.c
+++ b/server-client.c
@@ -548,6 +548,15 @@ server_client_check_focus(struct window_pane *wp)
{
u_int i;
struct client *c;
+ int push;
+
+ /* Are focus events off? */
+ if (!options_get_number(&global_options, "focus-events"))
+ return;
+
+ /* Do we need to push the focus state? */
+ push = wp->flags & PANE_FOCUSPUSH;
+ wp->flags &= ~PANE_FOCUSPUSH;
/* If we don't care about focus, forget it. */
if (!(wp->base.mode & MODE_FOCUSON))
@@ -580,13 +589,13 @@ server_client_check_focus(struct window_pane *wp)
}
not_focused:
- if (wp->flags & PANE_FOCUSED)
+ if (push || (wp->flags & PANE_FOCUSED))
bufferevent_write(wp->event, "\033[O", 3);
wp->flags &= ~PANE_FOCUSED;
return;
focused:
- if (!(wp->flags & PANE_FOCUSED))
+ if (push || !(wp->flags & PANE_FOCUSED))
bufferevent_write(wp->event, "\033[I", 3);
wp->flags |= PANE_FOCUSED;
}
diff --git a/tmux.1 b/tmux.1
index e59b9a6e..012f2069 100644
--- a/tmux.1
+++ b/tmux.1
@@ -2092,6 +2092,14 @@ The default is 500 milliseconds.
.Op Ic on | off
.Xc
If enabled, the server will exit when there are no attached clients.
+.It Xo Ic focus-events
+.Op Ic on | off
+.Xc
+When enabled, focus events are requested from the terminal if supported and
+passed through to applications running in
+.Nm .
+Attached clients should be detached and attached again after changing this
+option.
.It Xo Ic quiet
.Op Ic on | off
.Xc
diff --git a/tmux.h b/tmux.h
index b1624b6a..b3f314c5 100644
--- a/tmux.h
+++ b/tmux.h
@@ -941,6 +941,7 @@ struct window_pane {
#define PANE_DROP 0x2
#define PANE_FOCUSED 0x4
#define PANE_RESIZE 0x8
+#define PANE_FOCUSPUSH 0x10
char *cmd;
char *shell;
@@ -1232,6 +1233,7 @@ struct tty {
#define TTY_UTF8 0x8
#define TTY_STARTED 0x10
#define TTY_OPENED 0x20
+#define TTY_FOCUS 0x40
int flags;
int term_flags;
@@ -1383,6 +1385,9 @@ struct cmd {
char *file;
u_int line;
+#define CMD_CONTROL 0x1
+ int flags;
+
TAILQ_ENTRY(cmd) qentry;
};
struct cmd_list {
diff --git a/tty.c b/tty.c
index cf6e9652..c989aaaa 100644
--- a/tty.c
+++ b/tty.c
@@ -219,8 +219,13 @@ tty_start_tty(struct tty *tty)
if (tty_term_has(tty->term, TTYC_KMOUS))
tty_puts(tty, "\033[?1000l\033[?1006l\033[?1005l");
- if (tty_term_has(tty->term, TTYC_XT))
+ if (tty_term_has(tty->term, TTYC_XT)) {
+ if (options_get_number(&global_options, "focus-events")) {
+ tty->flags |= TTY_FOCUS;
+ tty_puts(tty, "\033[?1004h");
+ }
tty_puts(tty, "\033[c\033[>4;1m\033[m");
+ }
tty->cx = UINT_MAX;
tty->cy = UINT_MAX;
@@ -282,8 +287,13 @@ tty_stop_tty(struct tty *tty)
if (tty_term_has(tty->term, TTYC_KMOUS))
tty_raw(tty, "\033[?1000l\033[?1006l\033[?1005l");
- if (tty_term_has(tty->term, TTYC_XT))
+ if (tty_term_has(tty->term, TTYC_XT)) {
+ if (tty->flags & TTY_FOCUS) {
+ tty->flags &= ~TTY_FOCUS;
+ tty_puts(tty, "\033[?1004l");
+ }
tty_raw(tty, "\033[>4m\033[m");
+ }
tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP));