Skip to content

Commit 269dab4

Browse files
committed
Merge branch 'obsd-master'
2 parents e4c4ceb + 4ece43a commit 269dab4

File tree

8 files changed

+73
-29
lines changed

8 files changed

+73
-29
lines changed

client.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,22 @@ client_signal(int sig)
533533
{
534534
struct sigaction sigact;
535535
int status;
536+
pid_t pid;
536537

537538
log_debug("%s: %s", __func__, strsignal(sig));
538-
if (sig == SIGCHLD)
539-
waitpid(WAIT_ANY, &status, WNOHANG);
540-
else if (!client_attached) {
539+
if (sig == SIGCHLD) {
540+
for (;;) {
541+
pid = waitpid(WAIT_ANY, &status, WNOHANG);
542+
if (pid == 0)
543+
break;
544+
if (pid == -1) {
545+
if (errno == ECHILD)
546+
break;
547+
log_debug("waitpid failed: %s",
548+
strerror(errno));
549+
}
550+
}
551+
} else if (!client_attached) {
541552
if (sig == SIGTERM || sig == SIGHUP)
542553
proc_exit(client_proc);
543554
} else {

cmd-find.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
582582

583583
/* Try special characters. */
584584
if (strcmp(pane, "!") == 0) {
585-
fs->wp = fs->w->last;
585+
fs->wp = TAILQ_FIRST(&fs->w->last_panes);
586586
if (fs->wp == NULL)
587587
return (-1);
588588
return (0);

cmd-select-pane.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
9898
struct options_entry *o;
9999

100100
if (entry == &cmd_last_pane_entry || args_has(args, 'l')) {
101-
lastwp = w->last;
101+
/*
102+
* Check for no last pane found in case the other pane was
103+
* spawned without being visited (for example split-window -d).
104+
*/
105+
lastwp = TAILQ_FIRST(&w->last_panes);
102106
if (lastwp == NULL && window_count_panes(w) == 2) {
103107
lastwp = TAILQ_PREV(w->active, window_panes, entry);
104108
if (lastwp == NULL)

cmd-swap-pane.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
128128
window_set_active_pane(dst_w, src_wp, 1);
129129
}
130130
if (src_w != dst_w) {
131-
if (src_w->last == src_wp)
132-
src_w->last = NULL;
133-
if (dst_w->last == dst_wp)
134-
dst_w->last = NULL;
131+
window_pane_stack_remove(&src_w->last_panes, src_wp);
132+
window_pane_stack_remove(&dst_w->last_panes, dst_wp);
135133
colour_palette_from_option(&src_wp->palette, src_wp->options);
136134
colour_palette_from_option(&dst_wp->palette, dst_wp->options);
137135
}

format.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,7 @@ static void *
19021902
format_cb_pane_last(struct format_tree *ft)
19031903
{
19041904
if (ft->wp != NULL) {
1905-
if (ft->wp == ft->wp->window->last)
1905+
if (ft->wp == TAILQ_FIRST(&ft->wp->window->last_panes))
19061906
return (xstrdup("1"));
19071907
return (xstrdup("0"));
19081908
}

spawn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ spawn_window(struct spawn_context *sc, char **cause)
113113
window_pane_resize(sc->wp0, w->sx, w->sy);
114114

115115
layout_init(w, sc->wp0);
116+
w->active = NULL;
116117
window_set_active_pane(w, sc->wp0, 0);
117118
}
118119

tmux.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ struct window_pane {
10421042
#define PANE_REDRAW 0x1
10431043
#define PANE_DROP 0x2
10441044
#define PANE_FOCUSED 0x4
1045-
/* 0x8 unused */
1045+
#define PANE_VISITED 0x8
10461046
/* 0x10 unused */
10471047
/* 0x20 unused */
10481048
#define PANE_INPUTOFF 0x40
@@ -1097,7 +1097,8 @@ struct window_pane {
10971097
int border_gc_set;
10981098
struct grid_cell border_gc;
10991099

1100-
TAILQ_ENTRY(window_pane) entry;
1100+
TAILQ_ENTRY(window_pane) entry; /* link in list of all panes */
1101+
TAILQ_ENTRY(window_pane) sentry; /* link in list of last visited */
11011102
RB_ENTRY(window_pane) tree_entry;
11021103
};
11031104
TAILQ_HEAD(window_panes, window_pane);
@@ -1118,7 +1119,7 @@ struct window {
11181119
struct timeval activity_time;
11191120

11201121
struct window_pane *active;
1121-
struct window_pane *last;
1122+
struct window_panes last_panes;
11221123
struct window_panes panes;
11231124

11241125
int lastlayout;
@@ -1171,6 +1172,7 @@ struct winlink {
11711172
#define WINLINK_ACTIVITY 0x2
11721173
#define WINLINK_SILENCE 0x4
11731174
#define WINLINK_ALERTFLAGS (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_SILENCE)
1175+
#define WINLINK_VISITED 0x8
11741176

11751177
RB_ENTRY(winlink) entry;
11761178
TAILQ_ENTRY(winlink) wentry;
@@ -3046,6 +3048,10 @@ struct window_pane *window_pane_find_up(struct window_pane *);
30463048
struct window_pane *window_pane_find_down(struct window_pane *);
30473049
struct window_pane *window_pane_find_left(struct window_pane *);
30483050
struct window_pane *window_pane_find_right(struct window_pane *);
3051+
void window_pane_stack_push(struct window_panes *,
3052+
struct window_pane *);
3053+
void window_pane_stack_remove(struct window_panes *,
3054+
struct window_pane *);
30493055
void window_set_name(struct window *, const char *);
30503056
void window_add_ref(struct window *, const char *);
30513057
void window_remove_ref(struct window *, const char *);

window.c

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,21 +246,15 @@ winlink_stack_push(struct winlink_stack *stack, struct winlink *wl)
246246

247247
winlink_stack_remove(stack, wl);
248248
TAILQ_INSERT_HEAD(stack, wl, sentry);
249+
wl->flags |= WINLINK_VISITED;
249250
}
250251

251252
void
252253
winlink_stack_remove(struct winlink_stack *stack, struct winlink *wl)
253254
{
254-
struct winlink *wl2;
255-
256-
if (wl == NULL)
257-
return;
258-
259-
TAILQ_FOREACH(wl2, stack, sentry) {
260-
if (wl2 == wl) {
261-
TAILQ_REMOVE(stack, wl, sentry);
262-
return;
263-
}
255+
if (wl != NULL && (wl->flags & WINLINK_VISITED)) {
256+
TAILQ_REMOVE(stack, wl, sentry);
257+
wl->flags &= ~WINLINK_VISITED;
264258
}
265259
}
266260

@@ -310,6 +304,7 @@ window_create(u_int sx, u_int sy, u_int xpixel, u_int ypixel)
310304
w->flags = 0;
311305

312306
TAILQ_INIT(&w->panes);
307+
TAILQ_INIT(&w->last_panes);
313308
w->active = NULL;
314309

315310
w->lastlayout = -1;
@@ -519,18 +514,23 @@ window_pane_update_focus(struct window_pane *wp)
519514
int
520515
window_set_active_pane(struct window *w, struct window_pane *wp, int notify)
521516
{
517+
struct window_pane *lastwp;
518+
522519
log_debug("%s: pane %%%u", __func__, wp->id);
523520

524521
if (wp == w->active)
525522
return (0);
526-
w->last = w->active;
523+
lastwp = w->active;
524+
525+
window_pane_stack_remove(&w->last_panes, wp);
526+
window_pane_stack_push(&w->last_panes, lastwp);
527527

528528
w->active = wp;
529529
w->active->active_point = next_active_point++;
530530
w->active->flags |= PANE_CHANGED;
531531

532532
if (options_get_number(global_options, "focus-events")) {
533-
window_pane_update_focus(w->last);
533+
window_pane_update_focus(lastwp);
534534
window_pane_update_focus(w->active);
535535
}
536536

@@ -753,21 +753,21 @@ window_lost_pane(struct window *w, struct window_pane *wp)
753753
if (wp == marked_pane.wp)
754754
server_clear_marked();
755755

756+
window_pane_stack_remove(&w->last_panes, wp);
756757
if (wp == w->active) {
757-
w->active = w->last;
758-
w->last = NULL;
758+
w->active = TAILQ_FIRST(&w->last_panes);
759759
if (w->active == NULL) {
760760
w->active = TAILQ_PREV(wp, window_panes, entry);
761761
if (w->active == NULL)
762762
w->active = TAILQ_NEXT(wp, entry);
763763
}
764764
if (w->active != NULL) {
765+
window_pane_stack_remove(&w->last_panes, w->active);
765766
w->active->flags |= PANE_CHANGED;
766767
notify_window("window-pane-changed", w);
767768
window_update_focus(w);
768769
}
769-
} else if (wp == w->last)
770-
w->last = NULL;
770+
}
771771
}
772772

773773
void
@@ -851,6 +851,11 @@ window_destroy_panes(struct window *w)
851851
{
852852
struct window_pane *wp;
853853

854+
while (!TAILQ_EMPTY(&w->last_panes)) {
855+
wp = TAILQ_FIRST(&w->last_panes);
856+
window_pane_stack_remove(&w->last_panes, wp);
857+
}
858+
854859
while (!TAILQ_EMPTY(&w->panes)) {
855860
wp = TAILQ_FIRST(&w->panes);
856861
TAILQ_REMOVE(&w->panes, wp, entry);
@@ -1488,6 +1493,25 @@ window_pane_find_right(struct window_pane *wp)
14881493
return (best);
14891494
}
14901495

1496+
void
1497+
window_pane_stack_push(struct window_panes *stack, struct window_pane *wp)
1498+
{
1499+
if (wp != NULL) {
1500+
window_pane_stack_remove(stack, wp);
1501+
TAILQ_INSERT_HEAD(stack, wp, sentry);
1502+
wp->flags |= PANE_VISITED;
1503+
}
1504+
}
1505+
1506+
void
1507+
window_pane_stack_remove(struct window_panes *stack, struct window_pane *wp)
1508+
{
1509+
if (wp != NULL && (wp->flags & PANE_VISITED)) {
1510+
TAILQ_REMOVE(stack, wp, sentry);
1511+
wp->flags &= ~PANE_VISITED;
1512+
}
1513+
}
1514+
14911515
/* Clear alert flags for a winlink */
14921516
void
14931517
winlink_clear_flags(struct winlink *wl)

0 commit comments

Comments
 (0)