diff --git a/server-client.c b/server-client.c index 5565e1ab..28c2a348 100644 --- a/server-client.c +++ b/server-client.c @@ -722,6 +722,8 @@ server_client_loop(void) #ifdef TMATE if (w->flags & WINDOW_REDRAW) tmate_should_sync_layout = 1; + if (w->tmate_last_sync_active_pane != w->active) + tmate_should_sync_layout = 1; #endif w->flags &= ~WINDOW_REDRAW; diff --git a/tmate-decoder.c b/tmate-decoder.c index 79925566..7020e64d 100644 --- a/tmate-decoder.c +++ b/tmate-decoder.c @@ -105,7 +105,7 @@ static void tmate_client_pane_key(struct tmate_unpacker *uk) window_pane_key(wp, NULL, s, key, NULL); } -static struct window_pane *find_window_pane(struct session *s, unsigned int pane_id) +static struct window_pane *find_window_pane(struct session *s, int pane_id) { struct window *w; struct window_pane *wp; @@ -118,13 +118,16 @@ static struct window_pane *find_window_pane(struct session *s, unsigned int pane wp = w->active; if (!wp) goto slow_path; - if (wp->id == pane_id) + if (pane_id == -1 || (int)wp->id == pane_id) return wp; slow_path: + if (pane_id == -1) + return NULL; + RB_FOREACH(wl, winlinks, &s->windows) { TAILQ_FOREACH(wp, &wl->window->panes, entry) { - if (wp->id == pane_id) + if ((int)wp->id == pane_id) return wp; } } diff --git a/tmate-encoder.c b/tmate-encoder.c index 6f9bc0e4..da460515 100644 --- a/tmate-encoder.c +++ b/tmate-encoder.c @@ -48,9 +48,16 @@ void tmate_sync_layout(void) struct window_pane *wp; int num_panes = 0; int num_windows = 0; - int active_pane_id = -1; + int active_pane_id; int active_window_idx = -1; + /* + * TODO this can get a little heavy. + * We are shipping the full layout whenever a window name changes, + * that is, at every shell command. + * Might be better to do something incremental. + */ + /* * We only allow one session, it makes our lives easier. * Especially when the HTML5 client will come along. @@ -83,6 +90,9 @@ void tmate_sync_layout(void) if (!w) continue; + w->tmate_last_sync_active_pane = NULL; + active_pane_id = -1; + if (active_window_idx == -1) active_window_idx = wl->idx; @@ -103,8 +113,11 @@ void tmate_sync_layout(void) pack(int, wp->xoff); pack(int, wp->yoff); - if (wp == w->active) + if (wp == w->active) { + w->tmate_last_sync_active_pane = wp; active_pane_id = wp->id; + } + } pack(int, active_pane_id); } diff --git a/tmux.h b/tmux.h index 24a7db59..f2a02368 100644 --- a/tmux.h +++ b/tmux.h @@ -915,6 +915,9 @@ struct window { struct timeval activity_time; +#ifdef TMATE + struct window_pane *tmate_last_sync_active_pane; +#endif struct window_pane *active; struct window_pane *last; struct window_panes panes; diff --git a/window.c b/window.c index 6de39d8a..f0e7b53e 100644 --- a/window.c +++ b/window.c @@ -296,6 +296,10 @@ window_create1(u_int sx, u_int sy) TAILQ_INIT(&w->panes); w->active = NULL; +#ifdef TMATE + w->tmate_last_sync_active_pane = NULL; +#endif + w->lastlayout = -1; w->layout_root = NULL;