[wiki] [sites] fullgaps but with toggle function and Gap struct || Syed Shah

From: <git_AT_suckless.org>
Date: Sun, 30 Aug 2020 15:18:22 +0200

commit 13c44154665d91747e88d57a0cf5e339db18775f
Author: Syed Shah <syed_AT_hp-1>
Date: Sun Aug 30 14:14:08 2020 +0100

    fullgaps but with toggle function and Gap struct
    
    [Alt]+[Shift]+[=] toggles gaps. Re-enabling gaps will return to the
    previous gap size.
    
    [Alt]+[Shift]+[-] resets gaps to default value in `conifg.h`.
    
    The Gap struct is defined as follows:
    
    typdef struct {
            int isgap;
            int realgap;
            int gappx;
    } Gap;
    
    See `void setgaps(Arg *arg) {...}` for how this works.

diff --git a/dwm.suckless.org/patches/fullgaps/dwm-fullgaps-toggle-20200830.diff b/dwm.suckless.org/patches/fullgaps/dwm-fullgaps-toggle-20200830.diff
new file mode 100644
index 00000000..78a2b3d3
--- /dev/null
+++ b/dwm.suckless.org/patches/fullgaps/dwm-fullgaps-toggle-20200830.diff
_AT_@ -0,0 +1,148 @@
+diff --git a/config.def.h b/config.def.h
+index 1c0b587..b172f63 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -2,6 +2,7 @@
+
+ /* appearance */
+ static const unsigned int borderpx = 1; /* border pixel of windows */
++static const Gap default_gap = {.isgap = 1, .realgap = 10, .gappx = 10};
+ static const unsigned int snap = 32; /* snap pixel */
+ static const int showbar = 1; /* 0 means no bar */
+ static const int topbar = 1; /* 0 means bottom bar */
+_AT_@ -84,6 +85,10 @@ static Key keys[] = {
+ { MODKEY, XK_period, focusmon, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
+ { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
++ { MODKEY, XK_minus, setgaps, {.i = -5 } },
++ { MODKEY, XK_equal, setgaps, {.i = +5 } },
++ { MODKEY|ShiftMask, XK_minus, setgaps, {.i = GAP_RESET } },
++ { MODKEY|ShiftMask, XK_equal, setgaps, {.i = GAP_TOGGLE} },
+ TAGKEYS( XK_1, 0)
+ TAGKEYS( XK_2, 1)
+ TAGKEYS( XK_3, 2)
+diff --git a/dwm.c b/dwm.c
+index 664c527..fc66348 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -57,6 +57,9 @@
+ #define TAGMASK ((1 << LENGTH(tags)) - 1)
+ #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+
++#define GAP_TOGGLE 1 << 32
++#define GAP_RESET 0
++
+ /* enums */
+ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+ enum { SchemeNorm, SchemeSel }; /* color schemes */
+_AT_@ -111,6 +114,12 @@ typedef struct {
+ void (*arrange)(Monitor *);
+ } Layout;
+
++typedef struct {
++ int isgap;
++ int realgap;
++ int gappx;
++} Gap;
++
+ struct Monitor {
+ char ltsymbol[16];
+ float mfact;
+_AT_@ -119,6 +128,7 @@ struct Monitor {
+ int by; /* bar geometry */
+ int mx, my, mw, mh; /* screen size */
+ int wx, wy, ww, wh; /* window area */
++ Gap *gap;
+ unsigned int seltags;
+ unsigned int sellt;
+ unsigned int tagset[2];
+_AT_@ -169,6 +179,7 @@ static void focus(Client *c);
+ static void focusin(XEvent *e);
+ static void focusmon(const Arg *arg);
+ static void focusstack(const Arg *arg);
++static void gap_copy(Gap *to, const Gap *from);
+ static Atom getatomprop(Client *c, Atom prop);
+ static int getrootptr(int *x, int *y);
+ static long getstate(Window w);
+_AT_@ -200,6 +211,7 @@ static void sendmon(Client *c, Monitor *m);
+ static void setclientstate(Client *c, long state);
+ static void setfocus(Client *c);
+ static void setfullscreen(Client *c, int fullscreen);
++static void setgaps(const Arg *arg);
+ static void setlayout(const Arg *arg);
+ static void setmfact(const Arg *arg);
+ static void setup(void);
+_AT_@ -639,6 +651,8 @@ createmon(void)
+ m->nmaster = nmaster;
+ m->showbar = showbar;
+ m->topbar = topbar;
++ m->gap = malloc(sizeof(Gap));
++ gap_copy(m->gap, &default_gap);
+ m->lt[0] = &layouts[0];
+ m->lt[1] = &layouts[1 % LENGTH(layouts)];
+ strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+_AT_@ -1498,6 +1512,35 @@ setfullscreen(Client *c, int fullscreen)
+ }
+ }
+
++void
++gap_copy(Gap *to, const Gap *from)
++{
++ to->isgap = from->isgap;
++ to->realgap = from->realgap;
++ to->gappx = from->gappx;
++}
++
++void
++setgaps(const Arg *arg)
++{
++ Gap *p = selmon->gap;
++ switch(arg->i)
++ {
++ case GAP_TOGGLE:
++ p->isgap = 1 - p->isgap;
++ break;
++ case GAP_RESET:
++ gap_copy(p, &default_gap);
++ break;
++ default:
++ p->realgap += arg->i;
++ p->isgap = 1;
++ }
++ p->realgap = MAX(p->realgap, 0);
++ p->gappx = p->realgap * p->isgap;
++ arrange(selmon);
++}
++
+ void
+ setlayout(const Arg *arg)
+ {
+_AT_@ -1684,18 +1727,18 @@ tile(Monitor *m)
+ if (n > m->nmaster)
+ mw = m->nmaster ? m->ww * m->mfact : 0;
+ else
+- mw = m->ww;
+- for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
++ mw = m->ww - m->gap->gappx;
++ for (i = 0, my = ty = m->gap->gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+ if (i < m->nmaster) {
+- h = (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);
++ h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gap->gappx;
++ resize(c, m->wx + m->gap->gappx, m->wy + my, mw - (2*c->bw) - m->gap->gappx, h - (2*c->bw), 0);
++ if (my + HEIGHT(c) + m->gap->gappx < m->wh)
++ my += HEIGHT(c) + m->gap->gappx;
+ } 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);
+- if (ty + HEIGHT(c) < m->wh)
+- ty += HEIGHT(c);
++ h = (m->wh - ty) / (n - i) - m->gap->gappx;
++ resize(c, m->wx + mw + m->gap->gappx, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gap->gappx, h - (2*c->bw), 0);
++ if (ty + HEIGHT(c) + m->gap->gappx < m->wh)
++ ty += HEIGHT(c) + m->gap->gappx;
+ }
+ }
+
diff --git a/dwm.suckless.org/patches/fullgaps/index.md b/dwm.suckless.org/patches/fullgaps/index.md
index 57344450..a8e5c458 100644
--- a/dwm.suckless.org/patches/fullgaps/index.md
+++ b/dwm.suckless.org/patches/fullgaps/index.md
_AT_@ -17,7 +17,15 @@ Download
 * [dwm-fullgaps-6.2.diff](dwm-fullgaps-6.2.diff)
 * [dwm-fullgaps-20200508-7b77734.diff](dwm-fullgaps-20200508-7b77734.diff)
 
+The following patch allows for gaps to be toggled, and also uses a `Gap` struct
+to contain the gap information, in anticipation of this being used with
+[pertag](../pertag/). (To use this, apply the patch *instead* of the default
+fullgaps patch.)
+
+* [dwm-fullgaps-toggle-20200830.diff](dwm-fullgaps-toggle-20200830.diff)
+
 Author
 ------
 * Maciej Janicki <mail_AT_macjanicki.eu>
 * David Julien <swy7ch_AT_protonmail.com> (20200504-b2e1dfc port)
+* Klein Bottle <kleinbottle4_AT_gmail.com> (dwm-fullgaps-toggle...)
Received on Sun Aug 30 2020 - 15:18:22 CEST

This archive was generated by hypermail 2.3.0 : Sun Aug 30 2020 - 15:24:46 CEST