Some further adjustments. I realised that checking the percentage is not
necessary because downstream code handles large values correctly. Also, the
layout type of the parent layout_cell is always LAYOUT_WINDOWPANE so I
check the args instead while calculating the adjustment (which is also
what's done in split-window).
Best,
Anindya
On Mon, Oct 7, 2019 at 9:17 PM Anindya Mukherjee <[email protected]>
wrote:
> Hi Nicholas,
>
> Thanks for the feedback! I have adjusted the code accordingly.
>
> percentage can now be 0 to INT_MAX as in split-window.
>
> Yes, initially I was setting the increment as a percentage of the current
> pane size thinking that would be convenient. However, upon trying
> percentage of the available space in the parent cell I prefer that. Also it
> is then consistent with split-window.
>
> Changes attached. Please have a look.
>
> Best,
> Anindya
>
> On Mon, Oct 7, 2019 at 4:57 AM Nicholas Marriott <
> [email protected]> wrote:
>
>> Thanks for this.
>>
>> For strtonum - I think it does no harm to let people do -p0 or
>> -p99999999 to mean as small or as big as possible.
>>
>> With split-window, -p is a % of the available space, but you have made
>> it a % of the existing size? Is this more useful?
>>
>> You should be able to get the available space by looking at the size of
>> the parent cell (wp->layout_cell->parent->sx and sy).
>>
>>
>> On Sun, Oct 06, 2019 at 03:34:33PM -0700, Anindya Mukherjee wrote:
>> > Thanks Thomas for the tips! I have adjusted the code accordingly.
>> > Regarding the args_strtonum call: I want to disallow percent <=0 and
>> >
>> > 100. I thought adding 1, 100 is a convenient way of doing that, and
>> I get
>> > a "too small/large" error when invalid values are supplied.A Is
>> there any
>> > issue with doing it this way?
>> > Best,
>> > Anindya
>> > On Sun, Oct 6, 2019 at 3:03 PM Thomas Adam <[email protected]>
>> wrote:
>> >
>> > Hi,
>> >
>> > Thanks.A Comments below:
>> >
>> > 1.A You shouldn't need to use 0U for integer definitions.
>> > 2.A In terms of calling args_strtonum() for percentage:A 0,
>> INT_MAX
>> > should be OK, rather than 1, 100, no?
>> > 3.A When you're resizing in either L/R or U/D, the layout cells
>> are
>> > either LEFTRIGHT or TOPBOTTOM.A Rather than embed your percentage
>> > check in all of the if statements that check for 'L', 'R', etc.,
>> you
>> > can pull this check out to the top, something like:
>> >
>> > if (layout == LAYOUT_TOPBOTTOM)
>> > A A adjust = (wp->sy * percentage) / 100
>> > else
>> > A A adjust = (wp->sx * percentage) / 100
>> >
>> > I'm sure you get the idea.
>> >
>> > Kindly,
>> > Thomas
>> >
>> > On Sun, 6 Oct 2019 at 20:56, Anindya Mukherjee <
>> [email protected]>
>> > wrote:
>> > >
>> > > Hi, I have been playing with adding a percent option to
>> resize-pane.
>> > It's on the todo list (small things) for tmux, and I find it very
>> > useful. Right now it's working for me but being new to tmux code I
>> would
>> > love to have some eyes on it. I have attached my changes.
>> > >
>> > > If this is worthwhile/useful then I can do it properly via
>> github. In
>> > that case any advice on the proper procedure is welcome!
>> > >
>> > > Anindya
>> > >
>> > > --
>> > > You received this message because you are subscribed to the
>> Google
>> > Groups "tmux-users" group.
>> > > To unsubscribe from this group and stop receiving emails from
>> it, send
>> > an email to [email protected].
>> > > To view this discussion on the web, visit
>> >
>> https://groups.google.com/d/msgid/tmux-users/CAN%2Bi5iO9yh4TSNJ_r7397%2BCwW55%2BwHqDOs20CBYpFmoXeZfHTA%40mail.gmail.com
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web, visit
https://groups.google.com/d/msgid/tmux-users/CAN%2Bi5iNopiyPUkE2v7Z0FBt1oOXLG7mPVdKORR_7ONJqZo%3DE2Q%40mail.gmail.com.
diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c
index 8d35d96f..8396db07 100644
--- a/cmd-resize-pane.c
+++ b/cmd-resize-pane.c
@@ -35,9 +35,9 @@ const struct cmd_entry cmd_resize_pane_entry = {
.name = "resize-pane",
.alias = "resizep",
- .args = { "DLMRt:Ux:y:Z", 0, 1 },
+ .args = { "DLMp:Rt:Ux:y:Z", 0, 1 },
.usage = "[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
- "[adjustment]",
+ "[-p percentage] [adjustment]",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -57,8 +57,9 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = item->target.s;
const char *errstr;
char *cause;
- u_int adjust;
+ u_int adjust = 0;
int x, y;
+ u_int percentage = 0;
if (args_has(args, 'M')) {
if (cmd_mouse_window(&shared->mouse, &s) == NULL)
@@ -81,7 +82,21 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item
*item)
}
server_unzoom_window(w);
- if (args->argc == 0)
+ if (args_has(args, 'p')) {
+ percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
+ if (cause != NULL) {
+ cmdq_error(item, "percentage %s", cause);
+ free(cause);
+ return (CMD_RETURN_ERROR);
+ }
+
+ /* Should not also have an adjustment in this case. */
+ if (args->argc > 0) {
+ cmdq_error(item, "percentage and adjustment are
mutually exclusive");
+ return (CMD_RETURN_ERROR);
+ }
+ }
+ else if (args->argc == 0)
adjust = 1;
else {
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
@@ -110,6 +125,14 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item
*item)
layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
}
+ /* Calculate adjustment from parent window size. */
+ if (wp->layout_cell->parent) { /* A window filling the terminal has no
parent */
+ if (args_has(args, 'U') || args_has(args, 'D'))
+ adjust = (wp->layout_cell->parent->sy * percentage) /
100;
+ else
+ adjust = (wp->layout_cell->parent->sx * percentage) /
100;
+ }
+
if (args_has(args, 'L'))
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust, 1);
else if (args_has(args, 'R'))
diff --git a/tmux.1 b/tmux.1
index e095ba40..f548af2c 100644
--- a/tmux.1
+++ b/tmux.1
@@ -2224,13 +2224,18 @@ if specified, to
.Ar new-name .
.It Xo Ic resize-pane
.Op Fl DLMRUZ
+.Op Fl p Ar percentage
.Op Fl t Ar target-pane
.Op Fl x Ar width
.Op Fl y Ar height
.Op Ar adjustment
.Xc
.D1 (alias: Ic resizep )
-Resize a pane, up, down, left or right by
+Resize a pane, up, down, left or right by a
+.Ar percentage
+of the available space
+.Fl p
+or by
.Ar adjustment
with
.Fl U ,
@@ -2246,7 +2251,11 @@ or
.Fl y .
The
.Ar adjustment
-is given in lines or cells (the default is 1).
+is given in lines or cells (the default is 1). The
+.Ar percentage
+and the
+.Ar adjustment
+are mutually exclusive.
.Pp
With
.Fl Z ,