OK this looks good but there are two things: - if you are using the whole size you should be able to use wp->sx and sy for the size rather than walking up to it (or you can get the root cell directly from wp->layout_cell).
- this resizes BY a % of the total size which seems a bit odd - I was thinking it would resize TO a % of the total size? On Tue, Oct 08, 2019 at 12:34:13AM -0700, Anindya Mukherjee wrote: > Great, thanks! > I updated the code to use the root layout cell as that seems intuitive to > me, and also tried to fix some of the formatting issues. > Best, > Anindya > > On Tue, Oct 8, 2019 at 12:05 AM Nicholas Marriott > <[email protected]> wrote: > > Looks good aside from a few style nits I can fix before commit (use tabs > not spaces, all the u_int variable declarations go in the same > statement, line length needs to be <= 80 columns, new line for each new > sentence in tmux.1, "lines or columns" not "lines or cells" in tmux.1). > > I don't have strong feelings whether -p means % of parent cell or total > size, it's up to you which you prefer. I'd add a line to the manual > explaining what it means in either case. > > Thanks! > > On Mon, Oct 07, 2019 at 11:44:46PM -0700, Anindya Mukherjee wrote: > >A A Fixed a mistake in the last upload. Sorry for the noise. > >A A Although currently I am using the parent layout cell of the > target window > >A A pane's cell to calculate the available space, I wonder if it > would be > >A A better to use the root layout cell, which is basically the entire > >A A terminal. An example is a 2x2 grid with 4 panes. Here if I just > use the > >A A parent cell, it only covers half of the available space and the > results > >A A are a little less intuitive compared to using the top level cell. > >A A Best, > >A A Anindya > > > >A A On Mon, Oct 7, 2019 at 10:42 PM Anindya Mukherjee > <[email protected]> > >A A wrote: > > > >A A A Some further adjustments. I realised that checking the > percentage is not > >A A A necessary because downstream code handles large values > correctly. Also, > >A A A the layout type of the parent layout_cell is always > LAYOUT_WINDOWPANE so > >A A A I check the args instead while calculating the adjustment > (which is also > >A A A what's done in split-window). > >A A A Best, > >A A A Anindya > > > >A A A On Mon, Oct 7, 2019 at 9:17 PM Anindya Mukherjee > <[email protected]> > >A A A wrote: > > > >A A A A Hi Nicholas, > >A A A A Thanks for the feedback! I have adjusted the code > accordingly. > >A A A A percentage can now be 0 to INT_MAX as in split-window. > >A A A A Yes, initially I was setting the increment as a percentage > of the > >A A A A current pane size thinking that would be convenient. > However, upon > >A A A A trying percentage of the available space in the parent cell > I prefer > >A A A A that. Also it is then consistent with split-window. > >A A A A Changes attached. Please have a look. > >A A A A Best, > >A A A A Anindya > >A A A A On Mon, Oct 7, 2019 at 4:57 AM Nicholas Marriott > >A A A A <[email protected]> wrote: > > > >A A A A A Thanks for this. > > > >A A A A A For strtonum - I think it does no harm to let people do > -p0 or > >A A A A A -p99999999 to mean as small or as big as possible. > > > >A A A A A With split-window, -p is a % of the available space, but > you have > >A A A A A made > >A A A A A it a % of the existing size? Is this more useful? > > > >A A A A A You should be able to get the available space by looking > at the size > >A A A A A of > >A A A A A the parent cell (wp->layout_cell->parent->sx and sy). > > > >A A A A A On Sun, Oct 06, 2019 at 03:34:33PM -0700, Anindya > Mukherjee wrote: > >A A A A A >AA AA Thanks Thomas for the tips! I have adjusted the > code > >A A A A A accordingly. > >A A A A A >AA AA Regarding the args_strtonum call: I want to > disallow percent > >A A A A A <=0 and > > >A A A A A >AA AA 100. I thought adding 1, 100 is a convenient > way of doing > >A A A A A that, and I get > >A A A A A >AA AA a "too small/large" error when invalid values > are > >A A A A A supplied.AAA Is there any > >A A A A A >AA AA issue with doing it this way? > >A A A A A >AA AA Best, > >A A A A A >AA AA Anindya > >A A A A A >AA AA On Sun, Oct 6, 2019 at 3:03 PM Thomas Adam > >A A A A A <[email protected]> wrote: > >A A A A A > > >A A A A A >AA AA AA Hi, > >A A A A A > > >A A A A A >AA AA AA Thanks.AAA Comments below: > >A A A A A > > >A A A A A >AA AA AA 1.AAA You shouldn't need to use 0U for > integer > >A A A A A definitions. > >A A A A A >AA AA AA 2.AAA In terms of calling args_strtonum() > for > >A A A A A percentage:AAA 0, INT_MAX > >A A A A A >AA AA AA should be OK, rather than 1, 100, no? > >A A A A A >AA AA AA 3.AAA When you're resizing in either L/R > or U/D, the > >A A A A A layout cells are > >A A A A A >AA AA AA either LEFTRIGHT or TOPBOTTOM.AAA Rather > than embed your > >A A A A A percentage > >A A A A A >AA AA AA check in all of the if statements that > check for 'L', 'R', > >A A A A A etc., you > >A A A A A >AA AA AA can pull this check out to the top, > something like: > >A A A A A > > >A A A A A >AA AA AA if (layout == LAYOUT_TOPBOTTOM) > >A A A A A >AA AA AA AAA AAA adjust = (wp->sy * percentage) / > 100 > >A A A A A >AA AA AA else > >A A A A A >AA AA AA AAA AAA adjust = (wp->sx * percentage) / > 100 > >A A A A A > > >A A A A A >AA AA AA I'm sure you get the idea. > >A A A A A > > >A A A A A >AA AA AA Kindly, > >A A A A A >AA AA AA Thomas > >A A A A A > > >A A A A A >AA AA AA On Sun, 6 Oct 2019 at 20:56, Anindya > Mukherjee > >A A A A A <[email protected]> > >A A A A A >AA AA AA wrote: > >A A A A A >AA AA AA > > >A A A A A >AA AA AA > Hi, I have been playing with adding a > percent option to > >A A A A A resize-pane. > >A A A A A >AA AA AA It's on the todo list (small things) for > tmux, and I find > >A A A A A it very > >A A A A A >AA AA AA useful. Right now it's working for me but > being new to > >A A A A A tmux code I would > >A A A A A >AA AA AA love to have some eyes on it. I have > attached my changes. > >A A A A A >AA AA AA > > >A A A A A >AA AA AA > If this is worthwhile/useful then I can > do it properly > >A A A A A via github. In > >A A A A A >AA AA AA that case any advice on the proper > procedure is welcome! > >A A A A A >AA AA AA > > >A A A A A >AA AA AA > Anindya > >A A A A A >AA AA AA > > >A A A A A >AA AA AA > -- > >A A A A A >AA AA AA > You received this message because you are > subscribed to > >A A A A A the Google > >A A A A A >AA AA AA Groups "tmux-users" group. > >A A A A A >AA AA AA > To unsubscribe from this group and stop > receiving emails > >A A A A A from it, send > >A A A A A >AA AA AA an email to > [email protected]. > >A A A A A >AA AA AA > To view this discussion on the web, visit > >A A A A A >AA AA A > >A A A A A > > https://groups.google.com/d/msgid/tmux-users/CAN%2Bi5iO9yh4TSNJ_r7397%2BCwW55%2BwHqDOs20CBYpFmoXeZfHTA%40mail.gmail.com. > > > diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c > > index 8d35d96f..519c9d5e 100644 > > --- a/cmd-resize-pane.c > > +++ b/cmd-resize-pane.c > > @@ -35,9 +35,9 @@ const struct cmd_entry cmd_resize_pane_entry = { > >A A A A .name = "resize-pane", > >A A A A .alias = "resizep", > >A > > -A A A .args = { "DLMRt:Ux:y:Z", 0, 1 }, > > +A A A .args = { "DLMp:Rt:Ux:y:Z", 0, 1 }, > >A A A A .usage = "[-DLMRUZ] [-x width] [-y height] " > CMD_TARGET_PANE_USAGE " " > > -A A A A A A A "[adjustment]", > > +A A A A A A A "[-p percentage] [adjustment]", > >A > >A A A A .target = { 't', CMD_FIND_PANE, 0 }, > >A > > @@ -57,8 +57,9 @@ cmd_resize_pane_exec(struct cmd *self, struct > cmdq_item *item) > >A A A A struct sessionA A A A A *s = item->target.s; > >A A A A const charA A A A A A A *errstr; > >A A A A charA A A A A A A A A A *cause; > > -A A A u_intA A A A A A A A A A adjust; > > +A A A u_intA A A A A A A A A A adjust = 0; > >A A A A intA A A A A A A A A A A x, y; > > +A A A A u_intA A A A A A A A A A percentage = 0; > >A > >A A A A if (args_has(args, 'M')) { > >A A A A A A A A if (cmd_mouse_window(&shared->mouse, &s) == > NULL) > > @@ -81,7 +82,29 @@ cmd_resize_pane_exec(struct cmd *self, struct > cmdq_item *item) > >A A A A } > >A A A A server_unzoom_window(w); > >A > > -A A A if (args->argc == 0) > > +A A A A if (args_has(args, 'p')) { > > +A A A A A A A A percentage = args_strtonum(args, 'p', 0, > INT_MAX, &cause); > > +A A A A A A A if (cause != NULL) { > > +A A A A A A A A A A A cmdq_error(item, "percentage %s", > cause); > > +A A A A A A A A A A A free(cause); > > +A A A A A A A A A A A return (CMD_RETURN_ERROR); > > +A A A A A A A } > > + > > +A A A A A A A A /* Should not also have an adjustment in this > case. */ > > +A A A A A A A A if (args->argc > 0) { > > +A A A A A A A A A A A cmdq_error(item, "percentage and > adjustment are mutually exclusive"); > > +A A A A A A A A A A A return (CMD_RETURN_ERROR); > > +A A A A A A A A } > > + > > +A A A A A A A A /* Calculate adjustment from parent cell > size. */ > > +A A A A A A A A if (wp->layout_cell->parent) { /* A cell > filling the terminal has no parent */ > > +A A A A A A A A A A A A if (args_has(args, 'U') || > args_has(args, 'D')) > > +A A A A A A A A A A A A A A A A adjust = > (wp->layout_cell->parent->sy * percentage) / 100; > > +A A A A A A A A A A A A else > > +A A A A A A A A A A A A A A A A adjust = > (wp->layout_cell->parent->sx * percentage) / 100; > > +A A A A A A A A } > > +A A A A } > > +A A A else if (args->argc == 0) > >A A A A A A A A adjust = 1; > >A A A A else { > >A A A A A A A A adjust = strtonum(args->argv[0], 1, INT_MAX, > &errstr); > > 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 > >A .Ar new-name . > >A .It Xo Ic resize-pane > >A .Op Fl DLMRUZ > > +.Op Fl p Ar percentage > >A .Op Fl t Ar target-pane > >A .Op Fl x Ar width > >A .Op Fl y Ar height > >A .Op Ar adjustment > >A .Xc > >A .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 > >A .Ar adjustment > >A with > >A .Fl U , > > @@ -2246,7 +2251,11 @@ or > >A .Fl y . > >A The > >A .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. > >A .Pp > >A With > >A .Fl Z , > diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c > index 8d35d96f..eeddabf9 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 }, > > @@ -55,9 +55,10 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item > *item) > struct window *w = wl->window; > struct client *c = item->client; > struct session *s = item->target.s; > + struct layout_cell *rootlc; > const char *errstr; > char *cause; > - u_int adjust; > + u_int adjust = 0, percentage = 0; > int x, y; > > if (args_has(args, 'M')) { > @@ -81,7 +82,33 @@ 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); > + } > + > + /* Find the root layout cell */ > + rootlc = wp->layout_cell; > + while (rootlc->parent) > + rootlc = rootlc->parent; > + > + /* Calculate adjustment from the root cell size. */ > + if (args_has(args, 'U') || args_has(args, 'D')) > + adjust = (rootlc->sy * percentage) / 100; > + else > + adjust = (rootlc->sx * percentage) / 100; > + } > + else if (args->argc == 0) > adjust = 1; > else { > adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr); > diff --git a/tmux.1 b/tmux.1 > index e095ba40..41066ddc 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,12 @@ or > .Fl y . > The > .Ar adjustment > -is given in lines or cells (the default is 1). > +is given in lines or columns (the default is 1). > +The > +.Ar percentage > +and the > +.Ar adjustment > +are mutually exclusive. > .Pp > With > .Fl Z , -- 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/20191008085323.7rk2k2wq4vuklbxt%40yelena.
