Moved new-pane into split-window.

This commit is contained in:
Dane Jensen
2026-05-16 17:30:30 -07:00
parent fd4e683151
commit 76196b8ffa
4 changed files with 136 additions and 109 deletions

View File

@@ -38,13 +38,12 @@ const struct cmd_entry cmd_new_pane_entry = {
.name = "new-pane",
.alias = "newp",
.args = { "bc:de:fF:hIkl:m:M:p:PR:s:S:t:x:X:y:Y:vZ", 0, -1, NULL },
.args = { "bc:de:fF:hIkl:Lm:p:PR:s:S:t:vx:X:y:Y:Z", 0, -1, NULL },
.usage = "[-bdefhIklPvZ] [-c start-directory] [-e environment] "
"[-F format] [-l size] [-m message] [-M mode] "
"[-R inactive-border-style] [-s style] "
"[-S active-border-style] [-x width] [-X x-position]"
"[-y height] [-Y y-position]" CMD_TARGET_PANE_USAGE
"[shell-command [argument ...]]",
"[-F format] [-l size] [-m message] [-p percentage] [-s style] "
"[-S active-border-style] [-R inactive-border-style] "
"[-x width] [-y height] [-X x-position] [-Y y-position] "
CMD_TARGET_PANE_USAGE " [shell-command [argument ...]]",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -56,13 +55,11 @@ const struct cmd_entry cmd_split_window_entry = {
.name = "split-window",
.alias = "splitw",
.args = { "bc:de:fF:hIkl:m:M:p:PR:s:S:t:x:X:y:Y:vZ", 0, -1, NULL },
.args = { "bc:de:fF:hIkl:m:p:PR:s:S:t:vZ", 0, -1, NULL },
.usage = "[-bdefhIklPvZ] [-c start-directory] [-e environment] "
"[-F format] [-l size] [-m message] [-M mode] "
"[-R inactive-border-style] [-s style] "
"[-S active-border-style] [-x width] [-X x-position]"
"[-y height] [-Y y-position]" CMD_TARGET_PANE_USAGE
"[shell-command [argument ...]]",
"[-F format] [-l size] [-m message] [-p percentage] [-s style] "
"[-S active-border-style] [-R inactive-border-style] "
CMD_TARGET_PANE_USAGE " [shell-command [argument ...]]",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -72,67 +69,17 @@ const struct cmd_entry cmd_split_window_entry = {
static struct layout_cell *
cmd_split_window_get_floating_layout_cell(struct cmdq_item *item,
struct args *args, struct window *w)
struct args *args, struct window *w, struct window_pane *wp)
{
struct layout_cell *lc = NULL;
char *cause = NULL;
int x, y;
u_int sx, sy;
static int last_x = 0, last_y = 0;
u_int x, y, sx, sy;
/* Default size. */
sx = w->sx / 2;
sy = w->sy / 2;
if (args_has(args, 'x')) {
sx = args_percentage_and_expand(args, 'x', 0, USHRT_MAX, w->sx,
item, &cause);
if (cause != NULL) {
cmdq_error(item, "size %s", cause);
free(cause);
return (NULL);
}
}
if (args_has(args, 'y')) {
sy = args_percentage_and_expand(args, 'y', 0, USHRT_MAX, w->sy,
item, &cause);
if (cause != NULL) {
cmdq_error(item, "size %s", cause);
free(cause);
return (NULL);
}
}
/* If a position is not defined, it defaults to cascading. */
if (args_has(args, 'X')) {
x = args_percentage_and_expand(args, 'X', 0, USHRT_MAX, w->sx,
item, &cause);
if (cause != NULL) {
cmdq_error(item, "size %s", cause);
free(cause);
return (NULL);
}
} else if (last_x == 0)
x = 4;
else {
x = (last_x += 4);
if (last_x > (int)w->sx)
x = 4;
}
if (args_has(args, 'Y')) {
y = args_percentage_and_expand(args, 'Y', 0, USHRT_MAX, w->sy,
item, &cause);
if (cause != NULL) {
cmdq_error(item, "size %s", cause);
free(cause);
return (NULL);
}
} else if (last_y == 0)
y = 2;
else {
y = (last_y += 2);
if (last_y > (int)w->sy)
y = 2;
if (window_pane_float_geometry(w, wp, &x, &y, &sx, &sy, item, args, &cause)
!= 0) {
cmdq_error(item, "invalid float geometry %s", cause);
free(cause);
return (NULL);
}
/* Floating panes sit in layout cells which are not in the layout_root
@@ -143,8 +90,6 @@ cmd_split_window_get_floating_layout_cell(struct cmdq_item *item,
lc->yoff = y;
lc->sx = sx;
lc->sy = sy;
last_x = x; /* Statically save last xoff & yoff so that new */
last_y = y; /* floating panes offset so they don't overlap. */
return (lc);
}
@@ -163,6 +108,11 @@ cmd_split_window_get_tiled_layout_cell(struct cmdq_item *item,
return (NULL);
}
if (wp->flags & PANE_MINIMISED) {
cmdq_error(item, "can't split a minimised pane");
return (NULL);
}
if (window_pane_tile_geometry(w, wp, &size, &flags, &type, item, args,
&cause) != 0) {
cmdq_error(item, "invalid tiled geometry %s", cause);
@@ -191,30 +141,20 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
struct window_pane *wp = target->wp, *new_wp;
struct layout_cell *lc = NULL;
struct cmd_find_state fs;
int flags, input;
int input, is_floating, flags = 0;
const char *template, *style;
char *cause = NULL, *cp;
struct args_value *av;
u_int count = args_count(args);
enum { FLOATING, TILED, NONE } pane_mode;
if (args_has(args, 'M')) {
if (strcasecmp(args_get(args, 'M'), "f") == 0)
pane_mode = FLOATING;
else if (strcasecmp(args_get(args, 'M'), "t") == 0)
pane_mode = TILED;
else
pane_mode = NONE;
} else {
if (cmd_get_entry(self) == &cmd_new_pane_entry)
pane_mode = FLOATING;
else
pane_mode = TILED;
}
if (cmd_get_entry(self) == &cmd_new_pane_entry)
is_floating = !args_has(args, 'L');
else
is_floating = 0;
input = (args_has(args, 'I') && count == 0);
flags = (pane_mode == FLOATING) ? SPAWN_FLOATING : 0;
flags = is_floating ? SPAWN_FLOATING : 0;
if (args_has(args, 'b'))
flags |= SPAWN_BEFORE;
if (args_has(args, 'f'))
@@ -222,16 +162,12 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
if (input || (count == 1 && *args_string(args, 0) == '\0'))
flags |= SPAWN_EMPTY;
if (pane_mode == FLOATING)
lc = cmd_split_window_get_floating_layout_cell(item, args, w);
else if (pane_mode == TILED) {
if (is_floating)
lc = cmd_split_window_get_floating_layout_cell(item, args, w,
wp);
else
lc = cmd_split_window_get_tiled_layout_cell(item, args, w, wp,
flags);
} else {
cmdq_error(item, "unrecognized pane mode '%s'",
args_get(args, 'M'));
return (CMD_RETURN_ERROR);
}
if (lc == NULL)
return (CMD_RETURN_ERROR);
@@ -310,7 +246,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
switch (window_pane_start_input(new_wp, item, &cause)) {
case -1:
server_client_remove_pane(new_wp);
if (pane_mode == TILED)
if (!is_floating)
layout_close_pane(new_wp);
window_remove_pane(wp->window, new_wp);
cmdq_error(item, "%s", cause);
@@ -326,8 +262,11 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
}
if (!args_has(args, 'd'))
cmd_find_from_winlink_pane(current, wl, new_wp, 0);
window_pop_zoom(wp->window);
server_redraw_window(wp->window);
if (!is_floating) {
window_pop_zoom(wp->window);
server_redraw_window(wp->window);
}
server_status_session(s);
if (args_has(args, 'P')) {