Skip to content

Commit faf6453

Browse files
author
nicm
committed
Get rid of the PANE_HIDDEN flag in favour of a function, and moving the
decision for whether or not a pane should be drawn out of the layout code and into the redraw code. This is needed for the new layout design, getting it in now to make that easier to work on.
1 parent 6f55b89 commit faf6453

13 files changed

+108
-103
lines changed

TODO

+4
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,8 @@
9999
- option to show bells visually
100100
- window-status command to show current window info in status line
101101
- H/M/L commands in copy mode with vi-keys, for jumping to the top/middle/last line on the screen
102+
- if the server is started with IDENTIFY_UTF8 then set the global utf8 option?
103+
- I think there are potential leaks in the prompt code if a new prompt is created without the
104+
callback for the old being cleared; this might be quite hard to hit, lock-server seems the only
105+
candidate
102106
- tidy up and prioritise todo list ;-)

cmd-down-pane.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: cmd-down-pane.c,v 1.8 2009-07-14 06:43:32 nicm Exp $ */
1+
/* $Id: cmd-down-pane.c,v 1.9 2009-07-15 17:42:43 nicm Exp $ */
22

33
/*
44
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -55,7 +55,7 @@ cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
5555
if (w->active == NULL)
5656
w->active = TAILQ_FIRST(&w->panes);
5757
layout_refresh(w, 1);
58-
} while (w->active->flags & PANE_HIDDEN);
58+
} while (!window_pane_visible(w->active));
5959

6060
return (0);
6161
}

cmd-rotate-window.c

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: cmd-rotate-window.c,v 1.5 2009-07-14 06:43:32 nicm Exp $ */
1+
/* $Id: cmd-rotate-window.c,v 1.6 2009-07-15 17:42:43 nicm Exp $ */
22

33
/*
44
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -60,7 +60,6 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
6060
struct window *w;
6161
struct window_pane *wp, *wp2;
6262
u_int sx, sy, xoff, yoff;
63-
int flags;
6463

6564
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
6665
return (-1);
@@ -73,18 +72,13 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
7372

7473
xoff = wp->xoff; yoff = wp->yoff;
7574
sx = wp->sx; sy = wp->sy;
76-
flags = wp->flags;
7775
TAILQ_FOREACH(wp, &w->panes, entry) {
7876
if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL)
7977
break;
8078
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
81-
wp->flags &= ~PANE_HIDDEN;
82-
wp->flags |= wp2->flags & PANE_HIDDEN;
8379
window_pane_resize(wp, wp2->sx, wp2->sy);
8480
}
8581
wp->xoff = xoff; wp->yoff = yoff;
86-
wp->flags &= ~PANE_HIDDEN;
87-
wp->flags |= flags & PANE_HIDDEN;
8882
window_pane_resize(wp, sx, sy);
8983

9084
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
@@ -97,18 +91,13 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
9791

9892
xoff = wp->xoff; yoff = wp->yoff;
9993
sx = wp->sx; sy = wp->sy;
100-
flags = wp->flags;
10194
TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) {
10295
if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL)
10396
break;
10497
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
105-
wp->flags &= ~PANE_HIDDEN;
106-
wp->flags |= wp2->flags & PANE_HIDDEN;
10798
window_pane_resize(wp, wp2->sx, wp2->sy);
10899
}
109100
wp->xoff = xoff; wp->yoff = yoff;
110-
wp->flags &= ~PANE_HIDDEN;
111-
wp->flags |= flags & PANE_HIDDEN;
112101
window_pane_resize(wp, sx, sy);
113102

114103
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)

cmd-select-pane.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: cmd-select-pane.c,v 1.5 2009-07-14 06:43:32 nicm Exp $ */
1+
/* $Id: cmd-select-pane.c,v 1.6 2009-07-15 17:42:43 nicm Exp $ */
22

33
/*
44
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -58,8 +58,8 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
5858
}
5959
}
6060

61-
if (wp->flags & PANE_HIDDEN) {
62-
ctx->error(ctx, "pane %d is hidden", data->pane);
61+
if (!window_pane_visible(wp)) {
62+
ctx->error(ctx, "pane %d is not visible", data->pane);
6363
return (-1);
6464
}
6565
window_set_active_pane(wl->window, wp);

cmd-swap-pane.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: cmd-swap-pane.c,v 1.7 2009-07-14 06:43:33 nicm Exp $ */
1+
/* $Id: cmd-swap-pane.c,v 1.8 2009-07-15 17:42:43 nicm Exp $ */
22

33
/*
44
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -158,7 +158,6 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
158158
struct window *w;
159159
struct window_pane *tmp_wp, *src_wp, *dst_wp;
160160
u_int xx, yy;
161-
int flags;
162161

163162
if (data == NULL)
164163
return (0);
@@ -210,15 +209,10 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
210209

211210
xx = src_wp->xoff;
212211
yy = src_wp->yoff;
213-
flags = src_wp->flags;
214212
src_wp->xoff = dst_wp->xoff;
215213
src_wp->yoff = dst_wp->yoff;
216-
src_wp->flags &= ~PANE_HIDDEN;
217-
src_wp->flags |= dst_wp->flags & PANE_HIDDEN;
218214
dst_wp->xoff = xx;
219215
dst_wp->yoff = yy;
220-
dst_wp->flags &= ~PANE_HIDDEN;
221-
dst_wp->flags |= flags & PANE_HIDDEN;
222216

223217
xx = src_wp->sx;
224218
yy = src_wp->sy;
@@ -227,7 +221,7 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
227221

228222
if (!data->flag_detached) {
229223
tmp_wp = dst_wp;
230-
if (tmp_wp->flags & PANE_HIDDEN)
224+
if (!window_pane_visible(tmp_wp))
231225
tmp_wp = src_wp;
232226
window_set_active_pane(w, tmp_wp);
233227
layout_refresh(w, 0);

cmd-up-pane.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: cmd-up-pane.c,v 1.8 2009-07-14 06:43:33 nicm Exp $ */
1+
/* $Id: cmd-up-pane.c,v 1.9 2009-07-15 17:42:43 nicm Exp $ */
22

33
/*
44
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -55,7 +55,7 @@ cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
5555
if (w->active == NULL)
5656
w->active = TAILQ_LAST(&w->panes, window_panes);
5757
layout_refresh(w, 1);
58-
} while (w->active->flags & PANE_HIDDEN);
58+
} while (!window_pane_visible(w->active));
5959

6060
return (0);
6161
}

layout-manual.c

+17-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: layout-manual.c,v 1.3 2009-05-18 21:29:11 nicm Exp $ */
1+
/* $Id: layout-manual.c,v 1.4 2009-07-15 17:42:44 nicm Exp $ */
22

33
/*
44
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -26,7 +26,7 @@ void
2626
layout_manual_v_refresh(struct window *w, unused int active_only)
2727
{
2828
struct window_pane *wp;
29-
u_int npanes, canfit, total;
29+
u_int npanes, total, height;
3030
int left;
3131

3232
if (active_only)
@@ -35,34 +35,25 @@ layout_manual_v_refresh(struct window *w, unused int active_only)
3535
if (TAILQ_EMPTY(&w->panes))
3636
return;
3737

38-
/* Clear hidden flags. */
39-
TAILQ_FOREACH(wp, &w->panes, entry)
40-
wp->flags &= ~PANE_HIDDEN;
41-
4238
/* Check the new size. */
4339
npanes = window_count_panes(w);
4440
if (w->sy <= PANE_MINIMUM * npanes) {
45-
/* How many can we fit? */
46-
canfit = w->sy / PANE_MINIMUM;
47-
if (canfit == 0) {
48-
/* None. Just use this size for the first. */
49-
TAILQ_FOREACH(wp, &w->panes, entry) {
50-
if (wp == TAILQ_FIRST(&w->panes))
51-
wp->sy = w->sy;
52-
else
53-
wp->flags |= PANE_HIDDEN;
54-
}
55-
} else {
56-
/* >=1, set minimum for them all. */
57-
TAILQ_FOREACH(wp, &w->panes, entry) {
58-
if (canfit-- > 0)
59-
wp->sy = PANE_MINIMUM - 1;
60-
else
61-
wp->flags |= PANE_HIDDEN;
62-
}
63-
/* And increase the first by the rest. */
64-
TAILQ_FIRST(&w->panes)->sy += 1 + w->sy % PANE_MINIMUM;
41+
/*
42+
* Make the first pane the smaller of the minimum and total (it
43+
* must fit to be visible) and the rest the minimum size.
44+
*/
45+
height = PANE_MINIMUM;
46+
if (height > w->sy)
47+
height = w->sy + 1;
48+
TAILQ_FOREACH(wp, &w->panes, entry) {
49+
if (wp == TAILQ_FIRST(&w->panes))
50+
wp->sy = height - 1;
51+
else
52+
wp->sy = PANE_MINIMUM - 1;
6553
}
54+
/* And increase the first by the rest if possible. */
55+
if (w->sy >= PANE_MINIMUM)
56+
TAILQ_FIRST(&w->panes)->sy += 1 + w->sy % PANE_MINIMUM;
6657
} else {
6758
/* In theory they will all fit. Find the current total. */
6859
total = 0;
@@ -174,8 +165,6 @@ layout_manual_v_update_offsets(struct window *w)
174165

175166
yoff = 0;
176167
TAILQ_FOREACH(wp, &w->panes, entry) {
177-
if (wp->flags & PANE_HIDDEN)
178-
continue;
179168
wp->xoff = 0;
180169
wp->yoff = yoff;
181170
yoff += wp->sy + 1;

layout.c

+30-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: layout.c,v 1.14 2009-05-18 22:17:24 nicm Exp $ */
1+
/* $Id: layout.c,v 1.15 2009-07-15 17:42:44 nicm Exp $ */
22

33
/*
44
* Copyright (c) 2009 Nicholas Marriott <[email protected]>
@@ -125,14 +125,19 @@ void
125125
layout_active_only_refresh(struct window *w, unused int active_only)
126126
{
127127
struct window_pane *wp;
128+
u_int xoff;
128129

130+
xoff = w->sx;
129131
TAILQ_FOREACH(wp, &w->panes, entry) {
130-
if (wp == w->active) {
131-
wp->flags &= ~PANE_HIDDEN;
132-
wp->xoff = wp->yoff = 0;
133-
window_pane_resize(wp, w->sx, w->sy);
134-
} else
135-
wp->flags |= PANE_HIDDEN;
132+
/* Put the active pane on screen and the rest to the right. */
133+
if (wp == w->active)
134+
wp->xoff = 0;
135+
else {
136+
wp->xoff = xoff;
137+
xoff += w->sx;
138+
}
139+
wp->yoff = 0;
140+
window_pane_resize(wp, w->sx, w->sy);
136141
}
137142
}
138143

@@ -145,6 +150,12 @@ layout_even_h_refresh(struct window *w, int active_only)
145150
if (active_only)
146151
return;
147152

153+
/* If the screen is too small, show active only. */
154+
if (w->sx < PANE_MINIMUM || w->sy < PANE_MINIMUM) {
155+
layout_active_only_refresh(w, active_only);
156+
return;
157+
}
158+
148159
/* Get number of panes. */
149160
n = window_count_panes(w);
150161
if (n == 0)
@@ -153,19 +164,13 @@ layout_even_h_refresh(struct window *w, int active_only)
153164
/* How many can we fit? */
154165
if (w->sx / n < PANE_MINIMUM) {
155166
width = PANE_MINIMUM;
156-
n = w->sx / PANE_MINIMUM;
167+
n = UINT_MAX;
157168
} else
158169
width = w->sx / n;
159170

160171
/* Fit the panes. */
161172
i = xoff = 0;
162173
TAILQ_FOREACH(wp, &w->panes, entry) {
163-
if (i > n) {
164-
wp->flags |= PANE_HIDDEN;
165-
continue;
166-
}
167-
wp->flags &= ~PANE_HIDDEN;
168-
169174
wp->xoff = xoff;
170175
wp->yoff = 0;
171176
if (i != n - 1)
@@ -193,6 +198,12 @@ layout_even_v_refresh(struct window *w, int active_only)
193198
if (active_only)
194199
return;
195200

201+
/* If the screen is too small, show active only. */
202+
if (w->sx < PANE_MINIMUM || w->sy < PANE_MINIMUM) {
203+
layout_active_only_refresh(w, active_only);
204+
return;
205+
}
206+
196207
/* Get number of panes. */
197208
n = window_count_panes(w);
198209
if (n == 0)
@@ -201,19 +212,13 @@ layout_even_v_refresh(struct window *w, int active_only)
201212
/* How many can we fit? */
202213
if (w->sy / n < PANE_MINIMUM) {
203214
height = PANE_MINIMUM;
204-
n = w->sy / PANE_MINIMUM;
215+
n = UINT_MAX;
205216
} else
206217
height = w->sy / n;
207218

208219
/* Fit the panes. */
209220
i = yoff = 0;
210221
TAILQ_FOREACH(wp, &w->panes, entry) {
211-
if (i > n) {
212-
wp->flags |= PANE_HIDDEN;
213-
continue;
214-
}
215-
wp->flags &= ~PANE_HIDDEN;
216-
217222
wp->xoff = 0;
218223
wp->yoff = yoff;
219224
if (i != n - 1)
@@ -250,7 +255,8 @@ layout_main_v_refresh(struct window *w, int active_only)
250255
mainwidth = options_get_number(&w->options, "main-pane-width") + 1;
251256

252257
/* Need >1 pane and minimum columns; if fewer, display active only. */
253-
if (n == 1 || w->sx < mainwidth + PANE_MINIMUM) {
258+
if (n == 1 ||
259+
w->sx < mainwidth + PANE_MINIMUM || w->sy < PANE_MINIMUM) {
254260
layout_active_only_refresh(w, active_only);
255261
return;
256262
}
@@ -270,16 +276,9 @@ layout_main_v_refresh(struct window *w, int active_only)
270276
wp->xoff = 0;
271277
wp->yoff = 0;
272278
window_pane_resize(wp, mainwidth - 1, w->sy);
273-
wp->flags &= ~PANE_HIDDEN;
274279
continue;
275280
}
276281

277-
if (i > n) {
278-
wp->flags |= PANE_HIDDEN;
279-
continue;
280-
}
281-
wp->flags &= ~PANE_HIDDEN;
282-
283282
wp->xoff = mainwidth;
284283
wp->yoff = yoff;
285284
if (i != n - 1)
@@ -320,7 +319,8 @@ layout_main_h_refresh(struct window *w, int active_only)
320319
mainheight = options_get_number(&w->options, "main-pane-height") + 1;
321320

322321
/* Need >1 pane and minimum rows; if fewer, display active only. */
323-
if (n == 1 || w->sy < mainheight + PANE_MINIMUM) {
322+
if (n == 1 ||
323+
w->sy < mainheight + PANE_MINIMUM || w->sx < PANE_MINIMUM) {
324324
layout_active_only_refresh(w, active_only);
325325
return;
326326
}
@@ -340,15 +340,8 @@ layout_main_h_refresh(struct window *w, int active_only)
340340
wp->xoff = 0;
341341
wp->yoff = 0;
342342
window_pane_resize(wp, w->sx, mainheight - 1);
343-
wp->flags &= ~PANE_HIDDEN;
344-
continue;
345-
}
346-
347-
if (i > n) {
348-
wp->flags |= PANE_HIDDEN;
349343
continue;
350344
}
351-
wp->flags &= ~PANE_HIDDEN;
352345

353346
wp->xoff = xoff;
354347
wp->yoff = mainheight;

0 commit comments

Comments
 (0)