Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam
2026-06-26 11:15:06 +01:00
6 changed files with 180 additions and 44 deletions

View File

@@ -149,7 +149,7 @@ args_parse_flag_argument(struct args_value *values, u_int count, char **cause,
int optional_argument)
{
struct args_value *argument, *new;
const char *s;
const char *s, *as;
new = xcalloc(1, sizeof *new);
if (*string != '\0') {
@@ -180,12 +180,24 @@ args_parse_flag_argument(struct args_value *values, u_int count, char **cause,
xasprintf(cause, "-%c expects an argument", flag);
return (-1);
}
if (optional_argument && argument->type == ARGS_STRING) {
as = argument->string;
if (as[0] == '-' && (as[1] == '-' || isalpha((u_char)as[1]))) {
args_free_value(new);
free(new);
log_debug("%s: -%c (optional)", __func__, flag);
args_set(args, flag, NULL, ARGS_ENTRY_OPTIONAL_VALUE);
return (0);
}
}
args_copy_value(new, argument);
(*i)++;
out:
s = args_value_as_string(new);
log_debug("%s: -%c = %s", __func__, flag, s);
args_set(args, flag, new, 0);
return (0);
}

View File

@@ -34,9 +34,10 @@ const struct cmd_entry cmd_break_pane_entry = {
.name = "break-pane",
.alias = "breakp",
.args = { "abdPF:n:s:t:", 0, 0, NULL },
.usage = "[-abdP] [-F format] [-n window-name] [-s src-pane] "
"[-t dst-window]",
.args = { "abdPF:n:s:t:Wx:X:y:Y:", 0, 0, NULL },
.usage = "[-abdPW] [-F format] [-n window-name] [-s src-pane] "
"[-t dst-window] [-x width] [-y height] [-X x-position] "
"[-Y y-position]",
.source = { 's', CMD_FIND_PANE, 0 },
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
@@ -45,6 +46,48 @@ const struct cmd_entry cmd_break_pane_entry = {
.exec = cmd_break_pane_exec
};
static enum cmd_retval
cmd_break_pane_float(struct cmdq_item *item, struct args *args,
struct window *w, struct window_pane *wp)
{
struct layout_cell *lc = wp->layout_cell;
u_int sx = lc->saved_sx, sy = lc->saved_sy;
int ox = lc->saved_xoff, oy = lc->saved_yoff;
char *cause = NULL;
enum pane_lines lines = window_get_pane_lines(w);
if (window_pane_is_floating(wp)) {
cmdq_error(item, "pane is already floating");
return (CMD_RETURN_ERROR);
}
if (w->flags & WINDOW_ZOOMED) {
cmdq_error(item, "can't float a pane while window is zoomed");
return (CMD_RETURN_ERROR);
}
if (layout_floating_args_parse(item, args, lines, w, &sx, &sy, &ox, &oy,
&cause) != 0) {
cmdq_error(item, "failed to float pane: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
layout_remove_tile(w, lc);
layout_set_size(lc, sx, sy, ox, oy);
lc->flags |= LAYOUT_CELL_FLOATING;
TAILQ_REMOVE(&w->z_index, wp, zentry);
TAILQ_INSERT_HEAD(&w->z_index, wp, zentry);
if (!args_has(args, 'd'))
window_set_active_pane(w, wp, 1);
layout_fix_offsets(w);
layout_fix_panes(w, NULL);
notify_window("window-layout-changed", w);
server_redraw_window(w);
return (CMD_RETURN_NORMAL);
}
static enum cmd_retval
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
{
@@ -62,6 +105,9 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
int idx = target->idx, before;
const char *template, *name = args_get(args, 'n');
if (args_has(args, 'W'))
return (cmd_break_pane_float(item, args, w, wp));
if (name != NULL && !check_name(name, WINDOW_NAME_FORBID)) {
cmdq_error(item, "invalid window name: %s", name);
return (CMD_RETURN_ERROR);

View File

@@ -18,6 +18,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@@ -63,8 +64,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
const char *errstr, *argval;
const char flags[4] = { 'U', 'D', 'L', 'R' };
char *cause = NULL, flag;
u_int opposite = 0;
int adjust, x, y, status;
int adjust, x, y, status, opposite = 0;
long unsigned i;
struct grid *gd = wp->base.grid;
@@ -101,9 +101,8 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR);
}
if (window_pane_is_floating(wp)) {
layout_resize_floating_pane_to(wp, LAYOUT_LEFTRIGHT, x,
&cause);
if (cause != NULL) {
if (layout_resize_floating_pane_to(wp, LAYOUT_LEFTRIGHT,
x, &cause) != 0) {
cmdq_error(item, "size %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
@@ -130,9 +129,8 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
break;
}
if (window_pane_is_floating(wp)) {
layout_resize_floating_pane_to(wp, LAYOUT_TOPBOTTOM, y,
&cause);
if (cause != NULL) {
if (layout_resize_floating_pane_to(wp, LAYOUT_TOPBOTTOM,
y, &cause) != 0) {
cmdq_error(item, "size %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
@@ -147,8 +145,12 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
continue;
argval = args_get(args, flag);
if (argval == NULL)
argval = "1";
if (argval == NULL) {
if (args_count(args) == 0)
argval = "1";
else
argval = args_string(args, 0);
}
adjust = strtonum(argval, INT_MIN, INT_MAX, &errstr);
if (errstr != NULL) {
@@ -164,9 +166,8 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
if (flag == 'L' || flag == 'U')
opposite = 1;
layout_resize_floating_pane(wp, type, adjust, opposite,
&cause);
if (cause != NULL) {
if (layout_resize_floating_pane(wp, type, adjust,
opposite, &cause) != 0) {
cmdq_error(item, "adjustment %s", cause);
free(cause);
return (CMD_RETURN_ERROR);

View File

@@ -74,6 +74,12 @@ layout_create_cell(struct layout_cell *lcparent)
lc->xoff = INT_MAX;
lc->yoff = INT_MAX;
lc->saved_sx = UINT_MAX;
lc->saved_sy = UINT_MAX;
lc->saved_xoff = INT_MAX;
lc->saved_yoff = INT_MAX;
lc->wp = NULL;
return (lc);
@@ -814,7 +820,7 @@ layout_resize_pane_to(struct window_pane *wp, enum layout_type type,
}
/* Resize a floating pane to an absolute size. */
void
int
layout_resize_floating_pane_to(struct window_pane *wp, enum layout_type type,
u_int size, char **cause)
{
@@ -822,7 +828,7 @@ layout_resize_floating_pane_to(struct window_pane *wp, enum layout_type type,
if (~lc->flags & LAYOUT_CELL_FLOATING) {
*cause = xstrdup("pane is not floating");
return;
return (-1);
}
if (window_pane_get_pane_lines(wp) != PANE_LINES_NONE &&
@@ -830,23 +836,24 @@ layout_resize_floating_pane_to(struct window_pane *wp, enum layout_type type,
size -= 2;
if (size < PANE_MINIMUM || size > PANE_MAXIMUM) {
*cause = xstrdup("size is too big or too small");
return;
return (-1);
}
if (type == LAYOUT_TOPBOTTOM) {
if (lc->sy == size)
return;
return (0);
lc->sy = size;
} else {
if (lc->sx == size)
return;
return (0);
lc->sx = size;
}
redraw_invalidate_scene(wp->window);
return (0);
}
/* Resize a floating pane relative to its current size. */
void
int
layout_resize_floating_pane(struct window_pane *wp, enum layout_type type,
int change, int opposite, char **cause)
{
@@ -855,16 +862,16 @@ layout_resize_floating_pane(struct window_pane *wp, enum layout_type type,
if (~lc->flags & LAYOUT_CELL_FLOATING) {
*cause = xstrdup("pane is not floating");
return;
return (-1);
}
if (change == 0)
return;
return (0);
if (type == LAYOUT_TOPBOTTOM) {
size = lc->sy + change;
if (size < PANE_MINIMUM || size > PANE_MAXIMUM) {
*cause = xstrdup("change is too big or too small");
return;
return (-1);
}
lc->sy = size;
if (opposite)
@@ -873,13 +880,14 @@ layout_resize_floating_pane(struct window_pane *wp, enum layout_type type,
size = lc->sx + change;
if (size < PANE_MINIMUM || size > PANE_MAXIMUM) {
*cause = xstrdup("change is too big or too small");
return;
return (-1);
}
lc->sx = size;
if (opposite)
lc->xoff -= change;
}
redraw_invalidate_scene(wp->window);
return (0);
}
/* Resize a layout cell. */
@@ -1561,16 +1569,35 @@ layout_get_tiled_cell(struct cmdq_item *item, struct args *args,
return (lc);
}
/* Get a new floating cell. */
struct layout_cell *
layout_get_floating_cell(struct cmdq_item *item, struct args *args,
enum pane_lines lines, struct window *w, struct window_pane *wp,
char **cause)
{
struct layout_cell *lcnew;
int sx = w->sx / 2, sy = w->sy / 4;
u_int sx = UINT_MAX, sy = UINT_MAX;
int ox = INT_MAX, oy = INT_MAX;
char *error;
if (layout_floating_args_parse(item, args, lines, w, &sx, &sy, &ox, &oy,
cause) != 0)
return (NULL);
lcnew = layout_floating_pane(w, wp, sx, sy, ox, oy);
return (lcnew);
}
int
layout_floating_args_parse(struct cmdq_item *item, struct args *args,
enum pane_lines lines, struct window *w, u_int *sxp, u_int *syp, int *oxp,
int *oyp, char **cause)
{
int sx, sy, ox, oy;
char *error = NULL;
sx = *sxp == UINT_MAX ? w->sx / 2 : *sxp;
sy = *syp == UINT_MAX ? w->sy / 4 : *syp;
ox = *oxp == INT_MAX ? INT_MAX : *oxp;
oy = *oyp == INT_MAX ? INT_MAX : *oyp;
if (args_has(args, 'x')) {
sx = args_percentage_and_expand(args, 'x', 0, PANE_MAXIMUM,
@@ -1578,7 +1605,7 @@ layout_get_floating_cell(struct cmdq_item *item, struct args *args,
if (error != NULL) {
xasprintf(cause, "position %s", error);
free(error);
return (NULL);
return (-1);
}
if (lines != PANE_LINES_NONE)
sx -= 2;
@@ -1589,7 +1616,7 @@ layout_get_floating_cell(struct cmdq_item *item, struct args *args,
if (error != NULL) {
xasprintf(cause, "position %s", error);
free(error);
return (NULL);
return (-1);
}
if (lines != PANE_LINES_NONE)
sy -= 2;
@@ -1598,18 +1625,18 @@ layout_get_floating_cell(struct cmdq_item *item, struct args *args,
ox = args_percentage_and_expand(args, 'X', -sx, w->sx,
w->sx, item, &error);
if (error != NULL) {
xasprintf(cause, "size %s", error);
xasprintf(cause, "position %s", error);
free(error);
return (NULL);
return (-1);
}
}
if (args_has(args, 'Y')) {
oy = args_percentage_and_expand(args, 'Y', -sy, w->sy,
w->sy, item, &error);
if (error != NULL) {
xasprintf(cause, "size %s", error);
xasprintf(cause, "position %s", error);
free(error);
return (NULL);
return (-1);
}
}
@@ -1640,15 +1667,18 @@ layout_get_floating_cell(struct cmdq_item *item, struct args *args,
if (sx < PANE_MINIMUM || sx > PANE_MAXIMUM) {
*cause = xstrdup("invalid width");
return (NULL);
return (-1);
}
if (sy < PANE_MINIMUM || sy > PANE_MAXIMUM) {
*cause = xstrdup("invalid height");
return (NULL);
return (-1);
}
lcnew = layout_floating_pane(w, wp, sx, sy, ox, oy);
return (lcnew);
*sxp = sx;
*syp = sy;
*oxp = ox;
*oyp = oy;
return (0);
}
/*

40
tmux.1
View File

@@ -2692,11 +2692,15 @@ Commands related to windows and panes are as follows:
.Bl -tag -width Ds
.Tg breakp
.It Xo Ic break\-pane
.Op Fl abdP
.Op Fl abdPW
.Op Fl F Ar format
.Op Fl n Ar window\-name
.Op Fl s Ar src\-pane
.Op Fl t Ar dst\-window
.Op Fl x Ar width
.Op Fl y Ar height
.Op Fl X Ar x-position
.Op Fl Y Ar y-position
.Xc
.D1 Pq alias: Ic breakp
Break
@@ -2719,6 +2723,40 @@ By default, it uses the format
.Ql #{session_name}:#{window_index}.#{pane_index}
but a different format may be specified with
.Fl F .
.Pp
If the
.Fl W
option is given,
.Ar src\-pane
is lifted out of the tiled layout and made floating.
The
.Fl x
and
.Fl y
options set the width and height of the floating pane in columns and lines
respectively.
The default is half the window width and a quarter the window height.
The
.Fl X
and
.Fl Y
options set the position of the upper-left corner of the pane.
If omitted, new floating panes are cascaded from the top-left of the window.
.Pp
If the pane had previously been floating, the position and sizes are restored
from the saved values not specified by the
.Fl x ,
.Fl y ,
.Fl X ,
and
.Fl Y
options.
.Pp
If
.Fl d
is given, the active pane is not changed.
The pane must not already be floating or hidden, and the window must not
be zoomed.
.Tg capturep
.It Xo Ic capture\-pane
.Op Fl aeFHLpPqCJMN

15
tmux.h
View File

@@ -1512,6 +1512,12 @@ struct layout_cell {
int xoff;
int yoff;
u_int saved_sx;
u_int saved_sy;
int saved_xoff;
int saved_yoff;
struct window_pane *wp;
struct layout_cells cells;
@@ -3675,9 +3681,9 @@ void layout_resize_pane(struct window_pane *, enum layout_type,
int, int);
void layout_resize_pane_to(struct window_pane *, enum layout_type,
u_int);
void layout_resize_floating_pane(struct window_pane *,
int layout_resize_floating_pane(struct window_pane *,
enum layout_type, int, int, char **);
void layout_resize_floating_pane_to(struct window_pane *,
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);
@@ -3692,7 +3698,10 @@ struct layout_cell *layout_get_tiled_cell(struct cmdq_item *, struct args *,
struct window *, struct window_pane *, int, char **);
struct layout_cell *layout_get_floating_cell(struct cmdq_item *, struct args *,
enum pane_lines, struct window *, struct window_pane *,
char **);
char **cause);
int layout_floating_args_parse(struct cmdq_item *, struct args *,
enum pane_lines, struct window *, u_int *, u_int *, int *,
int *, char **);
int layout_remove_tile(struct window *, struct layout_cell *);
/* layout-custom.c */