sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 13c44154665d91747e88d57a0cf5e339db18775f
parent 3b8e1d672474f842ff111a03da9a9967e0da7f05
Author: Syed Shah <syed@hp-1>
Date:   Sun, 30 Aug 2020 14:14:08 +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.

Diffstat:
Adwm.suckless.org/patches/fullgaps/dwm-fullgaps-toggle-20200830.diff | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdwm.suckless.org/patches/fullgaps/index.md | 8++++++++
2 files changed, 156 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/patches/fullgaps/dwm-fullgaps-toggle-20200830.diff b/dwm.suckless.org/patches/fullgaps/dwm-fullgaps-toggle-20200830.diff @@ -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 +@@ -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 */ +@@ -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 +@@ -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 */ +@@ -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; +@@ -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]; +@@ -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); +@@ -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); +@@ -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); +@@ -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) + { +@@ -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 @@ -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@macjanicki.eu> * David Julien <swy7ch@protonmail.com> (20200504-b2e1dfc port) +* Klein Bottle <kleinbottle4@gmail.com> (dwm-fullgaps-toggle...)