dwm

my fork of dwm
Index Commits Files Refs README LICENSE
commit be0cc94e54c4f3db891b83427edeb2c6e2974d78
parent 0bb1cb5da1ca701740f0dd862e531b080f09ea7b
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Sun, 27 Mar 2022 22:17:39 -0300

update

Diffstat:
Mconfig.def.h | 12+++++++++---
Mdwm.c | 67++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Apatches/dwm-fullgaps-toggle-20200830.diff | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 213 insertions(+), 14 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -2,6 +2,7 @@
 
 /* appearance */
 static const unsigned int borderpx  = 3;        /* border pixel of windows */
+static const Gap default_gap        = {.isgap = 1, .realgap = 20, .gappx = 20};
 static const unsigned int snap      = 16;       /* snap pixel */
 static const unsigned int systraypinning = 0;   /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
 static const unsigned int systrayonleft = 0;       /* 0: systray in the right corner, >0: systray on left of status text */
@@ -10,8 +11,8 @@ static const int systraypinningfailfirst = 1;   /* 1: if pinning fails, display 
 static const int showsystray        = 1;     /* 0 means no systray */
 static const int showbar            = 1;        /* 0 means no bar */
 static const int topbar             = 0;        /* 0 means bottom bar */
-static const char *fonts[]          = { "Source Code Pro:style=Regular:size=8", "JoyPixels:style=Regular:size=7:antialias=true:autohint=true", "DejaVu Sans" };
-static const char dmenufont[]       = "DejaVuSansMono Nerd Font:style=Regular:size=8";
+static const char *fonts[]          = { "Source Code Pro:style=Regular:size=9", "JoyPixels:style=Regular:size=8:antialias=true:autohint=true", "DejaVu Sans" };
+static const char dmenufont[]       = "DejaVuSansMono Nerd Font:style=Regular:size=9";
 static const char col_gray1[]       = "#000000";
 static const char col_gray2[]       = "#444444";
 static const char col_gray3[]       = "#cccccc";
@@ -46,6 +47,7 @@ static const char *colors[][3]      = {
 
 /* tagging */
 static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
+static const int initlayouts[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 };
 
 static const Rule rules[] = {
     /* xprop(1):
@@ -57,7 +59,7 @@ static const Rule rules[] = {
     { "Firefox",          NULL,           NULL,    1<<8,         0,            -1,            50,50,500,500,        2 },
     { "calculator",     NULL,            NULL,    0,             1,            -1,            80,50,400,300,        2 },
     { "floating",        NULL,            NULL,    0,             1,            -1,            80,50,800,600,        0 },
-    { "scratchpad",        NULL,            NULL,    0,             1,            -1,            80,50,995,668,        0 },
+    { "scratchpad",        NULL,            NULL,    0,             1,            -1,            80,50,1366,900,        0 },
     { "qBittorrent",    "qbittorrent",    NULL,    1<<8,        0,            -1,            80,50,800,600,      0 },
     { "Spotify",        "spotify",      NULL,       1<<8,           0,           -1,        80,50,800,600,      0 },
     { NULL,             NULL,           "Spotify",  1<<8,           0,           -1,        80,50,800,600,      0 },
@@ -154,6 +156,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
@@ -82,6 +82,9 @@
 #define VERSION_MINOR               0
 #define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
 
+#define GAP_TOGGLE 100
+#define GAP_RESET  0
+
 /* enums */
 enum { CurNormal, CurHand, CurResize, CurMove, CurLast }; /* cursor */
 enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
@@ -138,6 +141,12 @@ typedef struct {
     void (*arrange)(Monitor *);
 } Layout;
 
+typedef struct {
+    int isgap;
+    int realgap;
+    int gappx;
+} Gap;
+
 typedef struct Pertag Pertag;
 struct Monitor {
     char ltsymbol[16];
@@ -147,6 +156,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];
@@ -207,6 +217,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);
@@ -243,6 +254,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);
@@ -779,6 +791,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);
@@ -789,7 +803,9 @@ createmon(void)
         m->pertag->nmasters[i] = m->nmaster;
         m->pertag->mfacts[i] = m->mfact;
 
-        m->pertag->ltidxs[i][0] = m->lt[0];
+        /* m->pertag->ltidxs[i][0] = m->lt[0]; */
+        m->pertag->ltidxs[i][0] = &layouts[initlayouts[i]];
+
         m->pertag->ltidxs[i][1] = m->lt[1];
         m->pertag->sellts[i] = m->sellt;
 
@@ -1882,6 +1898,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)
 {
     if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
@@ -2109,18 +2154,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/patches/dwm-fullgaps-toggle-20200830.diff b/patches/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..25bc9b7 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 100
++#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;
+         }
+ }
+