mirror of
https://github.com/tmate-io/tmate.git
synced 2025-01-23 22:38:44 +01:00
Change the windows array into an RB tree and fix some places where we
were only looking at the first winlink for a window in a session.
This commit is contained in:
parent
89e80cabd5
commit
8d66f4fba4
@ -176,9 +176,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
|
|
||||||
/* Start or stop timers when automatic-rename changed. */
|
/* Start or stop timers when automatic-rename changed. */
|
||||||
if (strcmp(oe->name, "automatic-rename") == 0) {
|
if (strcmp(oe->name, "automatic-rename") == 0) {
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
RB_FOREACH(w, windows, &windows) {
|
||||||
if ((w = ARRAY_ITEM(&windows, i)) == NULL)
|
|
||||||
continue;
|
|
||||||
if (options_get_number(&w->options, "automatic-rename"))
|
if (options_get_number(&w->options, "automatic-rename"))
|
||||||
queue_window_name(w);
|
queue_window_name(w);
|
||||||
else if (event_initialized(&w->name_timer))
|
else if (event_initialized(&w->name_timer))
|
||||||
|
11
resize.c
11
resize.c
@ -49,7 +49,7 @@ recalculate_sizes(void)
|
|||||||
struct client *c;
|
struct client *c;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int i, j, ssx, ssy, has, limit;
|
u_int i, ssx, ssy, has, limit;
|
||||||
int flag, has_status, is_zoomed, forced;
|
int flag, has_status, is_zoomed, forced;
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
@ -57,8 +57,8 @@ recalculate_sizes(void)
|
|||||||
|
|
||||||
s->attached = 0;
|
s->attached = 0;
|
||||||
ssx = ssy = UINT_MAX;
|
ssx = ssy = UINT_MAX;
|
||||||
for (j = 0; j < ARRAY_LENGTH(&clients); j++) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
c = ARRAY_ITEM(&clients, j);
|
c = ARRAY_ITEM(&clients, i);
|
||||||
if (c == NULL || c->flags & CLIENT_SUSPENDED)
|
if (c == NULL || c->flags & CLIENT_SUSPENDED)
|
||||||
continue;
|
continue;
|
||||||
if (c->session == s) {
|
if (c->session == s) {
|
||||||
@ -92,9 +92,8 @@ recalculate_sizes(void)
|
|||||||
s->sy = ssy;
|
s->sy = ssy;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
RB_FOREACH(w, windows, &windows) {
|
||||||
w = ARRAY_ITEM(&windows, i);
|
if (w->active == NULL)
|
||||||
if (w == NULL || w->active == NULL)
|
|
||||||
continue;
|
continue;
|
||||||
flag = options_get_number(&w->options, "aggressive-resize");
|
flag = options_get_number(&w->options, "aggressive-resize");
|
||||||
|
|
||||||
|
@ -720,11 +720,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. Also check pane focus and resize.
|
* their flags now. Also check pane focus and resize.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
RB_FOREACH(w, windows, &windows) {
|
||||||
w = ARRAY_ITEM(&windows, i);
|
|
||||||
if (w == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
w->flags &= ~WINDOW_REDRAW;
|
w->flags &= ~WINDOW_REDRAW;
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
if (wp->fd != -1) {
|
if (wp->fd != -1) {
|
||||||
|
@ -34,18 +34,13 @@ void
|
|||||||
server_window_loop(void)
|
server_window_loop(void)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct winlink *wl;
|
|
||||||
struct session *s;
|
struct session *s;
|
||||||
u_int i;
|
struct winlink *wl;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
|
||||||
w = ARRAY_ITEM(&windows, i);
|
|
||||||
if (w == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
RB_FOREACH(w, windows, &windows) {
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
wl = session_has(s, w);
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
if (wl == NULL)
|
if (wl->window != w)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (server_window_check_bell(s, wl) ||
|
if (server_window_check_bell(s, wl) ||
|
||||||
@ -55,6 +50,7 @@ server_window_loop(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Check for bell in window. */
|
/* Check for bell in window. */
|
||||||
int
|
int
|
||||||
|
21
server.c
21
server.c
@ -137,7 +137,7 @@ server_start(int lockfd, char *lockfile)
|
|||||||
logfile("server");
|
logfile("server");
|
||||||
log_debug("server started, pid %ld", (long) getpid());
|
log_debug("server started, pid %ld", (long) getpid());
|
||||||
|
|
||||||
ARRAY_INIT(&windows);
|
RB_INIT(&windows);
|
||||||
RB_INIT(&all_window_panes);
|
RB_INIT(&all_window_panes);
|
||||||
ARRAY_INIT(&clients);
|
ARRAY_INIT(&clients);
|
||||||
ARRAY_INIT(&dead_clients);
|
ARRAY_INIT(&dead_clients);
|
||||||
@ -438,14 +438,11 @@ server_child_signal(void)
|
|||||||
void
|
void
|
||||||
server_child_exited(pid_t pid, int status)
|
server_child_exited(pid_t pid, int status)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w, *w1;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct job *job;
|
struct job *job;
|
||||||
u_int i;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
RB_FOREACH_SAFE(w, windows, &windows, w1) {
|
||||||
if ((w = ARRAY_ITEM(&windows, i)) == NULL)
|
|
||||||
continue;
|
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
if (wp->pid == pid) {
|
if (wp->pid == pid) {
|
||||||
wp->status = status;
|
wp->status = status;
|
||||||
@ -469,14 +466,11 @@ server_child_stopped(pid_t pid, int status)
|
|||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int i;
|
|
||||||
|
|
||||||
if (WSTOPSIG(status) == SIGTTIN || WSTOPSIG(status) == SIGTTOU)
|
if (WSTOPSIG(status) == SIGTTIN || WSTOPSIG(status) == SIGTTOU)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
RB_FOREACH(w, windows, &windows) {
|
||||||
if ((w = ARRAY_ITEM(&windows, i)) == NULL)
|
|
||||||
continue;
|
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
if (wp->pid == pid) {
|
if (wp->pid == pid) {
|
||||||
if (killpg(pid, SIGCONT) != 0)
|
if (killpg(pid, SIGCONT) != 0)
|
||||||
@ -493,18 +487,13 @@ server_second_callback(unused int fd, unused short events, unused void *arg)
|
|||||||
struct window *w;
|
struct window *w;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
u_int i;
|
|
||||||
|
|
||||||
if (options_get_number(&global_s_options, "lock-server"))
|
if (options_get_number(&global_s_options, "lock-server"))
|
||||||
server_lock_server();
|
server_lock_server();
|
||||||
else
|
else
|
||||||
server_lock_sessions();
|
server_lock_sessions();
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
RB_FOREACH(w, windows, &windows) {
|
||||||
w = ARRAY_ITEM(&windows, i);
|
|
||||||
if (w == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||||
if (wp->mode != NULL && wp->mode->timer != NULL)
|
if (wp->mode != NULL && wp->mode->timer != NULL)
|
||||||
wp->mode->timer(wp);
|
wp->mode->timer(wp);
|
||||||
|
6
tmux.h
6
tmux.h
@ -983,8 +983,10 @@ struct window {
|
|||||||
struct options options;
|
struct options options;
|
||||||
|
|
||||||
u_int references;
|
u_int references;
|
||||||
|
|
||||||
|
RB_ENTRY(window) entry;
|
||||||
};
|
};
|
||||||
ARRAY_DECL(windows, struct window *);
|
RB_HEAD(windows, window);
|
||||||
|
|
||||||
/* Entry on local window list. */
|
/* Entry on local window list. */
|
||||||
struct winlink {
|
struct winlink {
|
||||||
@ -2121,6 +2123,8 @@ void screen_reflow(struct screen *, u_int);
|
|||||||
/* window.c */
|
/* window.c */
|
||||||
extern struct windows windows;
|
extern struct windows windows;
|
||||||
extern struct window_pane_tree all_window_panes;
|
extern struct window_pane_tree all_window_panes;
|
||||||
|
int window_cmp(struct window *, struct window *);
|
||||||
|
RB_PROTOTYPE(windows, window, entry, window_cmp);
|
||||||
int winlink_cmp(struct winlink *, struct winlink *);
|
int winlink_cmp(struct winlink *, struct winlink *);
|
||||||
RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
|
RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
|
||||||
int window_pane_cmp(struct window_pane *, struct window_pane *);
|
int window_pane_cmp(struct window_pane *, struct window_pane *);
|
||||||
|
66
window.c
66
window.c
@ -64,6 +64,14 @@ void window_pane_error_callback(struct bufferevent *, short, void *);
|
|||||||
|
|
||||||
struct window_pane *window_pane_choose_best(struct window_pane_list *);
|
struct window_pane *window_pane_choose_best(struct window_pane_list *);
|
||||||
|
|
||||||
|
RB_GENERATE(windows, window, entry, window_cmp);
|
||||||
|
|
||||||
|
int
|
||||||
|
window_cmp(struct window *w1, struct window *w2)
|
||||||
|
{
|
||||||
|
return (w1->id - w2->id);
|
||||||
|
}
|
||||||
|
|
||||||
RB_GENERATE(winlinks, winlink, entry, winlink_cmp);
|
RB_GENERATE(winlinks, winlink, entry, winlink_cmp);
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -248,25 +256,18 @@ winlink_stack_remove(struct winlink_stack *stack, struct winlink *wl)
|
|||||||
struct window *
|
struct window *
|
||||||
window_find_by_id(u_int id)
|
window_find_by_id(u_int id)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window w;
|
||||||
u_int i;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
w.id = id;
|
||||||
w = ARRAY_ITEM(&windows, i);
|
return (RB_FIND(windows, &windows, &w));
|
||||||
if (w != NULL && w->id == id)
|
|
||||||
return (w);
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct window *
|
struct window *
|
||||||
window_create1(u_int sx, u_int sy)
|
window_create1(u_int sx, u_int sy)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w;
|
||||||
u_int i;
|
|
||||||
|
|
||||||
w = xcalloc(1, sizeof *w);
|
w = xcalloc(1, sizeof *w);
|
||||||
w->id = next_window_id++;
|
|
||||||
w->name = NULL;
|
w->name = NULL;
|
||||||
w->flags = 0;
|
w->flags = 0;
|
||||||
|
|
||||||
@ -283,16 +284,11 @@ window_create1(u_int sx, u_int sy)
|
|||||||
if (options_get_number(&w->options, "automatic-rename"))
|
if (options_get_number(&w->options, "automatic-rename"))
|
||||||
queue_window_name(w);
|
queue_window_name(w);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
|
||||||
if (ARRAY_ITEM(&windows, i) == NULL) {
|
|
||||||
ARRAY_SET(&windows, i, w);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == ARRAY_LENGTH(&windows))
|
|
||||||
ARRAY_ADD(&windows, w);
|
|
||||||
w->references = 0;
|
w->references = 0;
|
||||||
|
|
||||||
|
w->id = next_window_id++;
|
||||||
|
RB_INSERT (windows, &windows, w);
|
||||||
|
|
||||||
return (w);
|
return (w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,19 +323,9 @@ window_create(const char *name, int argc, char **argv, const char *path,
|
|||||||
void
|
void
|
||||||
window_destroy(struct window *w)
|
window_destroy(struct window *w)
|
||||||
{
|
{
|
||||||
u_int i;
|
|
||||||
|
|
||||||
window_unzoom(w);
|
window_unzoom(w);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
RB_REMOVE(windows, &windows, w);
|
||||||
if (w == ARRAY_ITEM(&windows, i))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i == ARRAY_LENGTH(&windows))
|
|
||||||
fatalx("index not found");
|
|
||||||
ARRAY_SET(&windows, i, NULL);
|
|
||||||
while (!ARRAY_EMPTY(&windows) && ARRAY_LAST(&windows) == NULL)
|
|
||||||
ARRAY_TRUNC(&windows, 1);
|
|
||||||
|
|
||||||
if (w->layout_root != NULL)
|
if (w->layout_root != NULL)
|
||||||
layout_free(w);
|
layout_free(w);
|
||||||
@ -1328,26 +1314,18 @@ window_pane_find_right(struct window_pane *wp)
|
|||||||
void
|
void
|
||||||
winlink_clear_flags(struct winlink *wl)
|
winlink_clear_flags(struct winlink *wl)
|
||||||
{
|
{
|
||||||
struct winlink *wm;
|
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct window *w;
|
struct winlink *wl_loop;
|
||||||
u_int i;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
|
|
||||||
if ((w = ARRAY_ITEM(&windows, i)) == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
if ((wm = session_has(s, w)) == NULL)
|
RB_FOREACH(wl_loop, winlinks, &s->windows) {
|
||||||
|
if (wl_loop->window != wl->window)
|
||||||
|
continue;
|
||||||
|
if ((wl_loop->flags & WINLINK_ALERTFLAGS) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (wm->window != wl->window)
|
wl_loop->flags &= ~WINLINK_ALERTFLAGS;
|
||||||
continue;
|
wl_loop->window->flags &= ~WINDOW_ALERTFLAGS;
|
||||||
if ((wm->flags & WINLINK_ALERTFLAGS) == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
wm->flags &= ~WINLINK_ALERTFLAGS;
|
|
||||||
wm->window->flags &= ~WINDOW_ALERTFLAGS;
|
|
||||||
server_status_session(s);
|
server_status_session(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user