mirror of
https://github.com/tmux/tmux.git
synced 2025-01-26 07:58:55 +00:00
Handle focus events from the terminal, from Aaron Jensen.
This commit is contained in:
parent
bb8457b166
commit
a60687f9ba
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <event.h>
|
#include <event.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -28,6 +29,8 @@
|
|||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
|
void server_client_check_focus(struct window_pane *);
|
||||||
|
void server_client_check_resize(struct window_pane *);
|
||||||
void server_client_check_mouse(struct client *, struct window_pane *);
|
void server_client_check_mouse(struct client *, struct window_pane *);
|
||||||
void server_client_repeat_timer(int, short, void *);
|
void server_client_repeat_timer(int, short, void *);
|
||||||
void server_client_check_exit(struct client *);
|
void server_client_check_exit(struct client *);
|
||||||
@ -94,6 +97,8 @@ server_client_create(int fd)
|
|||||||
c->tty.mouse.event = MOUSE_EVENT_UP;
|
c->tty.mouse.event = MOUSE_EVENT_UP;
|
||||||
c->tty.mouse.flags = 0;
|
c->tty.mouse.flags = 0;
|
||||||
|
|
||||||
|
c->flags |= CLIENT_FOCUSED;
|
||||||
|
|
||||||
evtimer_set(&c->repeat_timer, server_client_repeat_timer, c);
|
evtimer_set(&c->repeat_timer, server_client_repeat_timer, c);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
@ -495,7 +500,7 @@ server_client_loop(void)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Any windows will have been redrawn as part of clients, so clear
|
* Any windows will have been redrawn as part of clients, so clear
|
||||||
* their flags now.
|
* their flags now. Also check pane focus and resize.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
||||||
w = ARRAY_ITEM(&windows, i);
|
w = ARRAY_ITEM(&windows, i);
|
||||||
@ -503,11 +508,92 @@ server_client_loop(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
w->flags &= ~WINDOW_REDRAW;
|
w->flags &= ~WINDOW_REDRAW;
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry)
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
|
server_client_check_focus(wp);
|
||||||
|
server_client_check_resize(wp);
|
||||||
wp->flags &= ~PANE_REDRAW;
|
wp->flags &= ~PANE_REDRAW;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check if pane should be resized. */
|
||||||
|
void
|
||||||
|
server_client_check_resize(struct window_pane *wp)
|
||||||
|
{
|
||||||
|
struct winsize ws;
|
||||||
|
|
||||||
|
if (wp->fd == -1 || !(wp->flags & PANE_RESIZE))
|
||||||
|
return;
|
||||||
|
|
||||||
|
memset(&ws, 0, sizeof ws);
|
||||||
|
ws.ws_col = wp->sx;
|
||||||
|
ws.ws_row = wp->sy;
|
||||||
|
|
||||||
|
if (ioctl(wp->fd, TIOCSWINSZ, &ws) == -1) {
|
||||||
|
#ifdef __sun
|
||||||
|
/*
|
||||||
|
* Some versions of Solaris apparently can return an error when
|
||||||
|
* resizing; don't know why this happens, can't reproduce on
|
||||||
|
* other platforms and ignoring it doesn't seem to cause any
|
||||||
|
* issues.
|
||||||
|
*/
|
||||||
|
if (errno != EINVAL)
|
||||||
|
#endif
|
||||||
|
fatal("ioctl failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
wp->flags &= ~PANE_RESIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check whether pane should be focused. */
|
||||||
|
void
|
||||||
|
server_client_check_focus(struct window_pane *wp)
|
||||||
|
{
|
||||||
|
u_int i;
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
/* 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 focused clients with an
|
||||||
|
* attached session, we're focused.
|
||||||
|
*/
|
||||||
|
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 (c->session->flags & SESSION_UNATTACHED)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (c->session->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;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update cursor position and mode settings. The scroll region and attributes
|
* Update cursor position and mode settings. The scroll region and attributes
|
||||||
* are cleared when idle (waiting for an event) as this is the most likely time
|
* are cleared when idle (waiting for an event) as this is the most likely time
|
||||||
|
9
tmux.h
9
tmux.h
@ -241,6 +241,9 @@ enum key_code {
|
|||||||
KEYC_KP_ENTER,
|
KEYC_KP_ENTER,
|
||||||
KEYC_KP_ZERO,
|
KEYC_KP_ZERO,
|
||||||
KEYC_KP_PERIOD,
|
KEYC_KP_PERIOD,
|
||||||
|
|
||||||
|
KEYC_FOCUS_IN,
|
||||||
|
KEYC_FOCUS_OUT,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Termcap codes. */
|
/* Termcap codes. */
|
||||||
@ -669,6 +672,7 @@ struct mode_key_table {
|
|||||||
#define MODE_MOUSE_UTF8 0x100
|
#define MODE_MOUSE_UTF8 0x100
|
||||||
#define MODE_MOUSE_SGR 0x200
|
#define MODE_MOUSE_SGR 0x200
|
||||||
#define MODE_BRACKETPASTE 0x400
|
#define MODE_BRACKETPASTE 0x400
|
||||||
|
#define MODE_FOCUSON 0x800
|
||||||
|
|
||||||
#define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)
|
#define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)
|
||||||
|
|
||||||
@ -930,6 +934,8 @@ struct window_pane {
|
|||||||
int flags;
|
int flags;
|
||||||
#define PANE_REDRAW 0x1
|
#define PANE_REDRAW 0x1
|
||||||
#define PANE_DROP 0x2
|
#define PANE_DROP 0x2
|
||||||
|
#define PANE_FOCUSED 0x4
|
||||||
|
#define PANE_RESIZE 0x8
|
||||||
|
|
||||||
char *cmd;
|
char *cmd;
|
||||||
char *shell;
|
char *shell;
|
||||||
@ -1317,6 +1323,7 @@ struct client {
|
|||||||
#define CLIENT_READONLY 0x800
|
#define CLIENT_READONLY 0x800
|
||||||
#define CLIENT_REDRAWWINDOW 0x1000
|
#define CLIENT_REDRAWWINDOW 0x1000
|
||||||
#define CLIENT_CONTROL 0x2000
|
#define CLIENT_CONTROL 0x2000
|
||||||
|
#define CLIENT_FOCUSED 0x4000
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
struct event identify_timer;
|
struct event identify_timer;
|
||||||
@ -1729,7 +1736,7 @@ struct cmd *cmd_parse(int, char **, char **);
|
|||||||
size_t cmd_print(struct cmd *, char *, size_t);
|
size_t cmd_print(struct cmd *, char *, size_t);
|
||||||
struct session *cmd_current_session(struct cmd_ctx *, int);
|
struct session *cmd_current_session(struct cmd_ctx *, int);
|
||||||
struct client *cmd_current_client(struct cmd_ctx *);
|
struct client *cmd_current_client(struct cmd_ctx *);
|
||||||
struct client *cmd_find_client(struct cmd_ctx *, const char *);
|
struct client *cmd_find_client(struct cmd_ctx *, const char *, int);
|
||||||
struct session *cmd_find_session(struct cmd_ctx *, const char *, int);
|
struct session *cmd_find_session(struct cmd_ctx *, const char *, int);
|
||||||
struct winlink *cmd_find_window(
|
struct winlink *cmd_find_window(
|
||||||
struct cmd_ctx *, const char *, struct session **);
|
struct cmd_ctx *, const char *, struct session **);
|
||||||
|
13
tty-keys.c
13
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[8@", KEYC_END|KEYC_CTRL|KEYC_SHIFT },
|
||||||
{ "\033[6@", KEYC_NPAGE|KEYC_CTRL|KEYC_SHIFT },
|
{ "\033[6@", KEYC_NPAGE|KEYC_CTRL|KEYC_SHIFT },
|
||||||
{ "\033[5@", KEYC_PPAGE|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. */
|
/* Default terminfo(5) keys. */
|
||||||
@ -559,6 +563,15 @@ complete_key:
|
|||||||
evtimer_del(&tty->key_timer);
|
evtimer_del(&tty->key_timer);
|
||||||
tty->flags &= ~TTY_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. */
|
/* Fire the key. */
|
||||||
if (key != KEYC_NONE)
|
if (key != KEYC_NONE)
|
||||||
server_client_handle_key(tty->client, key);
|
server_client_handle_key(tty->client, key);
|
||||||
|
4
tty.c
4
tty.c
@ -221,7 +221,7 @@ tty_start_tty(struct tty *tty)
|
|||||||
tty_puts(tty, "\033[?1000l\033[?1006l\033[?1005l");
|
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))
|
||||||
tty_puts(tty, "\033[c\033[>4;1m");
|
tty_puts(tty, "\033[c\033[>4;1m\033[?1004h");
|
||||||
|
|
||||||
tty->cx = UINT_MAX;
|
tty->cx = UINT_MAX;
|
||||||
tty->cy = 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");
|
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))
|
||||||
tty_raw(tty, "\033[>4m");
|
tty_raw(tty, "\033[>4m\033[?1004l");
|
||||||
|
|
||||||
tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP));
|
tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user