mirror of
https://github.com/tmate-io/tmate.git
synced 2025-06-24 03:21:26 +02:00
Sync all session windows
This commit is contained in:
parent
bf4edb4056
commit
69bc1bfde5
@ -491,6 +491,8 @@ server_client_loop(void)
|
|||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
|
int tmate_should_sync_layout = 0;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
c = ARRAY_ITEM(&clients, i);
|
c = ARRAY_ITEM(&clients, i);
|
||||||
if (c == NULL)
|
if (c == NULL)
|
||||||
@ -513,7 +515,7 @@ server_client_loop(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (w->flags & WINDOW_REDRAW)
|
if (w->flags & WINDOW_REDRAW)
|
||||||
tmate_sync_window(w);
|
tmate_should_sync_layout = 1;
|
||||||
|
|
||||||
w->flags &= ~WINDOW_REDRAW;
|
w->flags &= ~WINDOW_REDRAW;
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
@ -522,6 +524,9 @@ server_client_loop(void)
|
|||||||
wp->flags &= ~PANE_REDRAW;
|
wp->flags &= ~PANE_REDRAW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tmate_should_sync_layout)
|
||||||
|
tmate_sync_layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if pane should be resized. */
|
/* Check if pane should be resized. */
|
||||||
|
12
session.c
12
session.c
@ -91,10 +91,12 @@ session_create(const char *name, const char *cmd, const char *cwd,
|
|||||||
{
|
{
|
||||||
struct session *s;
|
struct session *s;
|
||||||
|
|
||||||
|
#ifdef TMATE
|
||||||
if (next_session_id != 0) {
|
if (next_session_id != 0) {
|
||||||
xasprintf(cause, "multi sessions is not supported with tmate");
|
xasprintf(cause, "multi sessions is not supported with tmate");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
s = xmalloc(sizeof *s);
|
s = xmalloc(sizeof *s);
|
||||||
s->references = 0;
|
s->references = 0;
|
||||||
@ -270,6 +272,11 @@ session_new(struct session *s,
|
|||||||
options_set_number(&w->options, "remain-on-exit", 1);
|
options_set_number(&w->options, "remain-on-exit", 1);
|
||||||
|
|
||||||
session_group_synchronize_from(s);
|
session_group_synchronize_from(s);
|
||||||
|
|
||||||
|
#ifdef TMATE
|
||||||
|
tmate_sync_layout();
|
||||||
|
#endif
|
||||||
|
|
||||||
return (wl);
|
return (wl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,6 +430,11 @@ session_set_current(struct session *s, struct winlink *wl)
|
|||||||
winlink_stack_push(&s->lastw, s->curw);
|
winlink_stack_push(&s->lastw, s->curw);
|
||||||
s->curw = wl;
|
s->curw = wl;
|
||||||
winlink_clear_flags(wl);
|
winlink_clear_flags(wl);
|
||||||
|
|
||||||
|
#ifdef TMATE
|
||||||
|
tmate_sync_layout();
|
||||||
|
#endif
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,20 +35,54 @@ void tmate_write_header(void)
|
|||||||
pack(int, TMATE_PROTOCOL_VERSION);
|
pack(int, TMATE_PROTOCOL_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tmate_sync_window(struct window *w)
|
void tmate_sync_layout(void)
|
||||||
{
|
{
|
||||||
|
struct session *s;
|
||||||
|
struct winlink *wl;
|
||||||
|
struct window *w;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
int num_panes = 0;
|
int num_panes = 0;
|
||||||
|
int num_windows = 0;
|
||||||
int active_pane_id = -1;
|
int active_pane_id = -1;
|
||||||
|
int active_window_id = -1;
|
||||||
|
|
||||||
pack(array, 7);
|
/*
|
||||||
pack(int, TMATE_SYNC_WINDOW);
|
* We only allow one session, it makes our lives easier.
|
||||||
|
* Especially when the HTML5 client will come along.
|
||||||
|
* We make no distinction between a winlink and its window.
|
||||||
|
* TODO send the winlink in the current session stack order.
|
||||||
|
*/
|
||||||
|
|
||||||
|
s = RB_MIN(sessions, &sessions);
|
||||||
|
if (!s)
|
||||||
|
return;
|
||||||
|
|
||||||
|
num_windows = 0;
|
||||||
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
|
if (wl->window)
|
||||||
|
num_windows++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!num_windows)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pack(array, 5);
|
||||||
|
pack(int, TMATE_SYNC_LAYOUT);
|
||||||
|
|
||||||
|
pack(int, s->sx);
|
||||||
|
pack(int, s->sy);
|
||||||
|
|
||||||
|
pack(array, num_windows);
|
||||||
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
|
w = wl->window;
|
||||||
|
if (!w)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pack(array, 4);
|
||||||
pack(int, w->id);
|
pack(int, w->id);
|
||||||
pack(string, w->name);
|
pack(string, w->name);
|
||||||
pack(int, w->sx);
|
|
||||||
pack(int, w->sy);
|
|
||||||
|
|
||||||
|
num_panes = 0;
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry)
|
TAILQ_FOREACH(wp, &w->panes, entry)
|
||||||
num_panes++;
|
num_panes++;
|
||||||
|
|
||||||
@ -65,6 +99,17 @@ void tmate_sync_window(struct window *w)
|
|||||||
active_pane_id = wp->id;
|
active_pane_id = wp->id;
|
||||||
}
|
}
|
||||||
pack(int, active_pane_id);
|
pack(int, active_pane_id);
|
||||||
|
|
||||||
|
if (wl == s->curw)
|
||||||
|
active_window_id = w->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (active_window_id == -1) {
|
||||||
|
wl = RB_MIN(winlinks, &s->windows);
|
||||||
|
active_window_id = wl->window->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
pack(int, active_window_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tmate_pty_data(struct window_pane *wp, const char *buf, size_t len)
|
void tmate_pty_data(struct window_pane *wp, const char *buf, size_t len)
|
||||||
|
4
tmate.h
4
tmate.h
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
enum tmate_commands {
|
enum tmate_commands {
|
||||||
TMATE_HEADER,
|
TMATE_HEADER,
|
||||||
TMATE_SYNC_WINDOW,
|
TMATE_SYNC_LAYOUT,
|
||||||
TMATE_PTY_DATA,
|
TMATE_PTY_DATA,
|
||||||
TMATE_CMD,
|
TMATE_CMD,
|
||||||
TMATE_STATUS,
|
TMATE_STATUS,
|
||||||
@ -35,7 +35,7 @@ struct tmate_encoder {
|
|||||||
extern void tmate_encoder_init(struct tmate_encoder *encoder);
|
extern void tmate_encoder_init(struct tmate_encoder *encoder);
|
||||||
|
|
||||||
extern void tmate_write_header(void);
|
extern void tmate_write_header(void);
|
||||||
extern void tmate_sync_window(struct window *w);
|
extern void tmate_sync_layout(void);
|
||||||
extern void tmate_pty_data(struct window_pane *wp, const char *buf, size_t len);
|
extern void tmate_pty_data(struct window_pane *wp, const char *buf, size_t len);
|
||||||
extern int tmate_should_replicate_cmd(const struct cmd_entry *cmd);
|
extern int tmate_should_replicate_cmd(const struct cmd_entry *cmd);
|
||||||
extern void tmate_cmd(const char *cmd);
|
extern void tmate_cmd(const char *cmd);
|
||||||
|
4
window.c
4
window.c
@ -329,8 +329,6 @@ window_create(const char *name, const char *cmd, const char *shell,
|
|||||||
} else
|
} else
|
||||||
w->name = default_window_name(w);
|
w->name = default_window_name(w);
|
||||||
|
|
||||||
tmate_sync_window(w);
|
|
||||||
|
|
||||||
return (w);
|
return (w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,7 +375,7 @@ window_set_name(struct window *w, const char *new_name)
|
|||||||
free(w->name);
|
free(w->name);
|
||||||
w->name = xstrdup(new_name);
|
w->name = xstrdup(new_name);
|
||||||
notify_window_renamed(w);
|
notify_window_renamed(w);
|
||||||
tmate_sync_window(w);
|
tmate_sync_layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user