mirror of
https://github.com/tmux/tmux.git
synced 2026-07-03 10:12:31 +00:00
Add a helper to swap a node into the place of a leaf, from Dane Jensen.
This commit is contained in:
55
layout.c
55
layout.c
@@ -1184,6 +1184,32 @@ layout_resize_child_cells(struct window *w, struct layout_cell *lc)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Replaces the provided layout cell with a new node of the specified type and
|
||||
* inserts the cell into it. Used when creating new cells requires a different
|
||||
* layout type, or when the root layout is a window pane.
|
||||
*/
|
||||
struct layout_cell *
|
||||
layout_replace_with_node(struct window *w, struct layout_cell *lc,
|
||||
enum layout_type type)
|
||||
{
|
||||
struct layout_cell *lcparent;
|
||||
|
||||
lcparent = layout_create_cell(lc->parent);
|
||||
layout_make_node(lcparent, type);
|
||||
layout_set_size(lcparent, lc->sx, lc->sy, lc->xoff, lc->yoff);
|
||||
if (lc->parent == NULL)
|
||||
w->layout_root = lcparent;
|
||||
else
|
||||
TAILQ_REPLACE(&lc->parent->cells, lc, lcparent, entry);
|
||||
|
||||
/* Insert the old cell. */
|
||||
lc->parent = lcparent;
|
||||
TAILQ_INSERT_HEAD(&lcparent->cells, lc, entry);
|
||||
|
||||
return (lcparent);
|
||||
}
|
||||
|
||||
/*
|
||||
* Split a pane into two. size is a hint, or -1 for default half/half
|
||||
* split. This must be followed by layout_assign_pane before much else happens!
|
||||
@@ -1315,17 +1341,7 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
*/
|
||||
|
||||
/* Create and insert the replacement parent. */
|
||||
lcparent = layout_create_cell(lc->parent);
|
||||
layout_make_node(lcparent, type);
|
||||
layout_set_size(lcparent, sx, sy, xoff, yoff);
|
||||
if (lc->parent == NULL)
|
||||
wp->window->layout_root = lcparent;
|
||||
else
|
||||
TAILQ_REPLACE(&lc->parent->cells, lc, lcparent, entry);
|
||||
|
||||
/* Insert the old cell. */
|
||||
lc->parent = lcparent;
|
||||
TAILQ_INSERT_HEAD(&lcparent->cells, lc, entry);
|
||||
lcparent = layout_replace_with_node(wp->window, lc, type);
|
||||
|
||||
/* Create the new child cell. */
|
||||
lcnew = layout_create_cell(lcparent);
|
||||
@@ -1384,14 +1400,7 @@ layout_floating_pane(struct window *w, struct window_pane *wp, u_int sx,
|
||||
* Adding a pane to a root that isn't node. Must create and
|
||||
* insert a new root.
|
||||
*/
|
||||
lcparent = layout_create_cell(NULL);
|
||||
layout_make_node(lcparent, LAYOUT_TOPBOTTOM);
|
||||
layout_set_size(lcparent, w->sx, w->sy, 0, 0);
|
||||
w->layout_root = lcparent;
|
||||
|
||||
/* Insert the old cell. */
|
||||
lc->parent = lcparent;
|
||||
TAILQ_INSERT_HEAD(&lcparent->cells, lc, entry);
|
||||
lcparent = layout_replace_with_node(w, lc, LAYOUT_TOPBOTTOM);
|
||||
}
|
||||
|
||||
lcnew = layout_create_cell(lcparent);
|
||||
@@ -1712,7 +1721,11 @@ layout_remove_tile(struct window *w, struct layout_cell *lc)
|
||||
layout_resize_adjust(w, lcneighbour, type, change);
|
||||
}
|
||||
|
||||
/* Zeroing out the cell geometry until the cell is retiled. */
|
||||
layout_set_size(lc, 0, 0, 0, 0);
|
||||
/*
|
||||
* Zeroing out the cell geometry until the cell is retiled unless this
|
||||
* is the top level node.
|
||||
*/
|
||||
if (lc->parent != NULL)
|
||||
layout_set_size(lc, 0, 0, 0, 0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
2
tmux.h
2
tmux.h
@@ -3643,6 +3643,8 @@ int layout_resize_floating_pane_to(struct window_pane *,
|
||||
enum layout_type, u_int, char **);
|
||||
void layout_assign_pane(struct layout_cell *, struct window_pane *,
|
||||
int);
|
||||
struct layout_cell *layout_replace_with_node(struct window *,
|
||||
struct layout_cell *, enum layout_type);
|
||||
struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type,
|
||||
int, int);
|
||||
struct layout_cell *layout_floating_pane(struct window *, struct window_pane *,
|
||||
|
||||
Reference in New Issue
Block a user