Re: [hackers] [dwm][PATCH] Vertical size factor for first tile in master/stacking area

From: Xavier Baez <xavierbaez_AT_gmail.com>
Date: Sun, 29 Nov 2020 13:52:02 -0800

I think like it is good with dwm.c and config.def.h
You can name it

‘ stackvfact’

I would recommend you try your patch with vanitygaps and with csfact and
with stackmfact just to see you don’t have weird results.

On Sat, Nov 28, 2020 at 11:26 AM Sebastiano Tronto <
sebastiano.tronto_AT_gmail.com> wrote:

> Hello,
>
> I have made this patch for personal use. It introduces two new variables
> for each monitor, vfactmaster and vfactstack, which determine which
> proportion of the master (resp. stacking) area should be taken by the
> first tile in that area. These variables can also be set to 0.0 to get
> back the original behavior.
>
> My patch is similar to two other patches:
> - stackmfact (https://dwm.suckless.org/patches/stackmfact/)
> But my patch works also for the master area.
> - cfacts (https://dwm.suckless.org/patches/cfacts/)
> My patch is less flexible because one can only choose the size
> factor for the first tile (not client) in an area. However the way
> it works is closer to how the master area size factor (mfact) works.
> Also, one advantage over cfacts is that one does not need to focus a
> particular windows to change its size.
>
> I like to use this patch combined with a "zoomstack" function that I
> wrote, which sends the selected window to the top of the stacking area
> (and if the selected window is not in the stacking area, it swaps the
> first two windows of the stacking area).
> This function can be simply added to config.h. Should I send it as a
> separate patch or should I just post it here? In case it is better to
> send it as a separate patch, is it preferable to add this function to
> dwm.c or to config.def.h?
>
> Best,
> Sebastiano
>
>
> From a138e7361ed1592e55a6b463ad559df054ce13e2 Mon Sep 17 00:00:00 2001
> From: Sebastiano Tronto <sebastiano.tronto_AT_gmail.com>
> Date: Sat, 28 Nov 2020 19:35:30 +0100
> Subject: [PATCH] Vertical size factor for first tile in master/stacking
> area
>
> ---
> config.def.h | 8 ++++++++
> dwm.c | 38 +++++++++++++++++++++++++++++++++++---
> 2 files changed, 43 insertions(+), 3 deletions(-)
>
> diff --git a/config.def.h b/config.def.h
> index 1c0b587..ff87720 100644
> --- a/config.def.h
> +++ b/config.def.h
> _AT_@ -33,6 +33,8 @@ static const Rule rules[] = {
>
> /* layout(s) */
> static const float mfact = 0.55; /* factor of master area size
> [0.05..0.95] */
> +static const float vfactmaster = 0.5; /* vertical factor of first master
> tile */
> +static const float vfactstack = 0.5; /* vertical factor of first stack
> tile */
> static const int nmaster = 1; /* number of clients in master area
> */
> static const int resizehints = 1; /* 1 means respect size hints in
> tiled resizals */
>
> _AT_@ -94,6 +96,12 @@ static Key keys[] = {
> TAGKEYS( XK_8, 7)
> TAGKEYS( XK_9, 8)
> { MODKEY|ShiftMask, XK_q, quit, {0} },
> + { MODKEY, XK_y, setvfactmaster, {.f = +0.05} },
> + { MODKEY|ShiftMask, XK_y, setvfactmaster, {.f = -0.05} },
> + { MODKEY|ControlMask, XK_y, setvfactmaster, {.f = +1.0 } },
> + { MODKEY, XK_o, setvfactstack, {.f = +0.05} },
> + { MODKEY|ShiftMask, XK_o, setvfactstack, {.f = -0.05} },
> + { MODKEY|ControlMask, XK_o, setvfactstack, {.f = +1.0 } },
> };
>
> /* button definitions */
> diff --git a/dwm.c b/dwm.c
> index 664c527..fe71c14 100644
> --- a/dwm.c
> +++ b/dwm.c
> _AT_@ -114,6 +114,8 @@ typedef struct {
> struct Monitor {
> char ltsymbol[16];
> float mfact;
> + float vfactmaster;
> + float vfactstack;
> int nmaster;
> int num;
> int by; /* bar geometry */
> _AT_@ -204,6 +206,9 @@ static void setlayout(const Arg *arg);
> static void setmfact(const Arg *arg);
> static void setup(void);
> static void seturgent(Client *c, int urg);
> +static void setvfact(float *factor, float f);
> +static void setvfactmaster(const Arg *arg);
> +static void setvfactstack(const Arg *arg);
> static void showhide(Client *c);
> static void sigchld(int unused);
> static void spawn(const Arg *arg);
> _AT_@ -636,6 +641,8 @@ createmon(void)
> m = ecalloc(1, sizeof(Monitor));
> m->tagset[0] = m->tagset[1] = 1;
> m->mfact = mfact;
> + m->vfactmaster = vfactmaster;
> + m->vfactstack = vfactstack;
> m->nmaster = nmaster;
> m->showbar = showbar;
> m->topbar = topbar;
> _AT_@ -1611,6 +1618,27 @@ seturgent(Client *c, int urg)
> XFree(wmh);
> }
>
> +void
> +setvfact(float *factor, float f) {
> + if (!selmon->lt[selmon->sellt]->arrange)
> + return;
> + f += (*factor < 0.05 ? 0.5 : *factor);
> + *factor = f < 1.0 ? (f < 0.05 || f > 0.95 ? *factor : f) : 0.0;
> + arrange(selmon);
> +}
> +
> +void
> +setvfactmaster(const Arg *arg)
> +{
> + setvfact(&selmon->vfactmaster, arg->f);
> +}
> +
> +void
> +setvfactstack(const Arg *arg)
> +{
> + setvfact(&selmon->vfactstack, arg->f);
> +}
> +
> void
> showhide(Client *c)
> {
> _AT_@ -1687,13 +1715,17 @@ tile(Monitor *m)
> mw = m->ww;
> for (i = my = ty = 0, c = nexttiled(m->clients); c; c =
> nexttiled(c->next), i++)
> if (i < m->nmaster) {
> - h = (m->wh - my) / (MIN(n, m->nmaster) - i);
> + h = (i == 0 && MIN(n, m->nmaster) > 1 &&
> m->vfactmaster > 0.01) ?
> + m->wh * m->vfactmaster :
> + (m->wh - my) / (MIN(n, m->nmaster) - i);
> resize(c, m->wx, m->wy + my, mw - (2*c->bw), h -
> (2*c->bw), 0);
> if (my + HEIGHT(c) < m->wh)
> my += HEIGHT(c);
> } else {
> - h = (m->wh - ty) / (n - i);
> - resize(c, m->wx + mw, m->wy + ty, m->ww - mw -
> (2*c->bw), h - (2*c->bw), 0);
> + h = (i == m->nmaster && n - i > 1 && m->vfactstack
> > 0.01) ?
> + m->wh * m->vfactstack : (m->wh - ty) / (n - i);
> + resize(c, m->wx + mw, m->wy + ty,
> + m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
> if (ty + HEIGHT(c) < m->wh)
> ty += HEIGHT(c);
> }
> --
> 2.29.2
>
> --
Regards

Xavier
Received on Sun Nov 29 2020 - 22:52:02 CET

This archive was generated by hypermail 2.3.0 : Sun Nov 29 2020 - 23:24:30 CET