Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam
2026-05-18 09:38:02 +01:00
21 changed files with 694 additions and 293 deletions

136
window.c
View File

@@ -71,7 +71,7 @@ static struct window_pane *window_pane_create(struct window *, u_int, u_int,
u_int);
static void window_pane_destroy(struct window_pane *);
static void window_pane_full_size_offset(struct window_pane *wp,
u_int *xoff, u_int *yoff, u_int *sx, u_int *sy);
int *xoff, int *yoff, u_int *sx, u_int *sy);
RB_GENERATE(windows, window, entry, window_cmp);
RB_GENERATE(winlinks, winlink, entry, winlink_cmp);
@@ -306,6 +306,7 @@ window_create(u_int sx, u_int sy, u_int xpixel, u_int ypixel)
w->flags = 0;
TAILQ_INIT(&w->panes);
TAILQ_INIT(&w->z_index);
TAILQ_INIT(&w->last_panes);
w->active = NULL;
@@ -530,6 +531,8 @@ window_set_active_pane(struct window *w, struct window_pane *wp, int notify)
if (wp == w->active)
return (0);
if (w->flags & WINDOW_ZOOMED)
window_unzoom(w, 1);
lastwp = w->active;
window_pane_stack_remove(&w->last_panes, wp);
@@ -672,7 +675,7 @@ window_zoom(struct window_pane *wp)
if (w->flags & WINDOW_ZOOMED)
return (-1);
if (window_count_panes(w) == 1)
if (window_count_panes(w, 1) == 1)
return (-1);
if (w->active != wp)
@@ -859,14 +862,15 @@ window_pane_index(struct window_pane *wp, u_int *i)
}
u_int
window_count_panes(struct window *w)
window_count_panes(struct window *w, int with_floating)
{
struct window_pane *wp;
u_int n;
u_int n = 0;
n = 0;
TAILQ_FOREACH(wp, &w->panes, entry)
n++;
TAILQ_FOREACH(wp, &w->panes, entry) {
if (with_floating || ~wp->flags & PANE_FLOATING)
n++;
}
return (n);
}
@@ -1388,7 +1392,7 @@ window_pane_choose_best(struct window_pane **list, u_int size)
* scrollbars if they were visible but not including the border(s).
*/
static void
window_pane_full_size_offset(struct window_pane *wp, u_int *xoff, u_int *yoff,
window_pane_full_size_offset(struct window_pane *wp, int *xoff, int *yoff,
u_int *sx, u_int *sy)
{
struct window *w = wp->window;
@@ -1422,9 +1426,9 @@ window_pane_find_up(struct window_pane *wp)
{
struct window *w;
struct window_pane *next, *best, **list;
u_int edge, left, right, end, size;
int status, found;
u_int xoff, yoff, sx, sy;
int edge, left, right, end, status, found;
int xoff, yoff;
u_int size, sx, sy;
if (wp == NULL)
return (NULL);
@@ -1439,25 +1443,25 @@ window_pane_find_up(struct window_pane *wp)
edge = yoff;
if (status == PANE_STATUS_TOP) {
if (edge == 1)
edge = w->sy + 1;
edge = (int)w->sy + 1;
} else if (status == PANE_STATUS_BOTTOM) {
if (edge == 0)
edge = w->sy;
edge = (int)w->sy;
} else {
if (edge == 0)
edge = w->sy + 1;
edge = (int)w->sy + 1;
}
left = xoff;
right = xoff + sx;
right = xoff + (int)sx;
TAILQ_FOREACH(next, &w->panes, entry) {
window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy);
if (next == wp)
continue;
if (yoff + sy + 1 != edge)
if (yoff + (int)sy + 1 != edge)
continue;
end = xoff + sx - 1;
end = xoff + (int)sx - 1;
found = 0;
if (xoff < left && end > right)
@@ -1483,9 +1487,9 @@ window_pane_find_down(struct window_pane *wp)
{
struct window *w;
struct window_pane *next, *best, **list;
u_int edge, left, right, end, size;
int status, found;
u_int xoff, yoff, sx, sy;
int edge, left, right, end, status, found;
int xoff, yoff;
u_int size, sx, sy;
if (wp == NULL)
return (NULL);
@@ -1497,20 +1501,20 @@ window_pane_find_down(struct window_pane *wp)
window_pane_full_size_offset(wp, &xoff, &yoff, &sx, &sy);
edge = yoff + sy + 1;
edge = yoff + (int)sy + 1;
if (status == PANE_STATUS_TOP) {
if (edge >= w->sy)
if (edge >= (int)w->sy)
edge = 1;
} else if (status == PANE_STATUS_BOTTOM) {
if (edge >= w->sy - 1)
if (edge >= (int)w->sy - 1)
edge = 0;
} else {
if (edge >= w->sy)
if (edge >= (int)w->sy)
edge = 0;
}
left = wp->xoff;
right = wp->xoff + wp->sx;
right = wp->xoff + (int)wp->sx;
TAILQ_FOREACH(next, &w->panes, entry) {
window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy);
@@ -1518,7 +1522,7 @@ window_pane_find_down(struct window_pane *wp)
continue;
if (yoff != edge)
continue;
end = xoff + sx - 1;
end = xoff + (int)sx - 1;
found = 0;
if (xoff < left && end > right)
@@ -1544,9 +1548,9 @@ window_pane_find_left(struct window_pane *wp)
{
struct window *w;
struct window_pane *next, *best, **list;
u_int edge, top, bottom, end, size;
int found;
u_int xoff, yoff, sx, sy;
int edge, top, bottom, end, found;
int xoff, yoff;
u_int size, sx, sy;
if (wp == NULL)
return (NULL);
@@ -1559,18 +1563,18 @@ window_pane_find_left(struct window_pane *wp)
edge = xoff;
if (edge == 0)
edge = w->sx + 1;
edge = (int)w->sx + 1;
top = yoff;
bottom = yoff + sy;
bottom = yoff + (int)sy;
TAILQ_FOREACH(next, &w->panes, entry) {
window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy);
if (next == wp)
continue;
if (xoff + sx + 1 != edge)
if (xoff + (int)sx + 1 != edge)
continue;
end = yoff + sy - 1;
end = yoff + (int)sy - 1;
found = 0;
if (yoff < top && end > bottom)
@@ -1596,9 +1600,9 @@ window_pane_find_right(struct window_pane *wp)
{
struct window *w;
struct window_pane *next, *best, **list;
u_int edge, top, bottom, end, size;
int found;
u_int xoff, yoff, sx, sy;
int edge, top, bottom, end, found;
int xoff, yoff;
u_int size, sx, sy;
if (wp == NULL)
return (NULL);
@@ -1609,12 +1613,12 @@ window_pane_find_right(struct window_pane *wp)
window_pane_full_size_offset(wp, &xoff, &yoff, &sx, &sy);
edge = xoff + sx + 1;
if (edge >= w->sx)
edge = xoff + (int)sx + 1;
if (edge >= (int)w->sx)
edge = 0;
top = wp->yoff;
bottom = wp->yoff + wp->sy;
bottom = wp->yoff + (int)wp->sy;
TAILQ_FOREACH(next, &w->panes, entry) {
window_pane_full_size_offset(next, &xoff, &yoff, &sx, &sy);
@@ -1622,7 +1626,7 @@ window_pane_find_right(struct window_pane *wp)
continue;
if (xoff != edge)
continue;
end = yoff + sy - 1;
end = yoff + (int)sy - 1;
found = 0;
if (yoff < top && end > bottom)
@@ -1642,6 +1646,7 @@ window_pane_find_right(struct window_pane *wp)
return (best);
}
/* Add window to stack. */
void
window_pane_stack_push(struct window_panes *stack, struct window_pane *wp)
{
@@ -1652,6 +1657,7 @@ window_pane_stack_push(struct window_panes *stack, struct window_pane *wp)
}
}
/* Remove window from stack. */
void
window_pane_stack_remove(struct window_panes *stack, struct window_pane *wp)
{
@@ -2032,3 +2038,53 @@ window_pane_border_status_get_range(struct window_pane *wp, u_int x, u_int y)
*/
return (style_ranges_get_range(srs, x - wp->xoff - 2));
}
int
window_pane_tile_geometry(struct window *w, struct window_pane *wp,
int *out_size, int *out_flags, enum layout_type *out_type,
struct cmdq_item *item, struct args *args, char **cause)
{
int size = -1, flags = *out_flags;
enum layout_type type;
u_int curval = 0;
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
type = LAYOUT_LEFTRIGHT;
if (args_has(args, 'l') || args_has(args, 'p')) {
if (args_has(args, 'f')) {
if (type == LAYOUT_TOPBOTTOM)
curval = w->sy;
else
curval = w->sx;
} else {
if (type == LAYOUT_TOPBOTTOM)
curval = wp->sy;
else
curval = wp->sx;
}
}
if (args_has(args, 'l')) {
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
item, cause);
} else if (args_has(args, 'p')) {
size = args_strtonum_and_expand(args, 'p', 0, 100, item,
cause);
if (cause == NULL)
size = curval * size / 100;
}
if (*cause != NULL)
return (-1);
if (args_has(args, 'b'))
flags |= SPAWN_BEFORE;
if (args_has(args, 'f'))
flags |= SPAWN_FULLSIZE;
*out_size = size;
*out_flags = flags;
*out_type = type;
return (0);
}