aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h9
-rw-r--r--dwm.c63
2 files changed, 60 insertions, 12 deletions
diff --git a/config.h b/config.h
index 76e15fe..47e4c87 100644
--- a/config.h
+++ b/config.h
@@ -1,13 +1,14 @@
/* See LICENSE file for copyright and license details. */
/* appearance */
+static const Gap default_gap = {.isgap = 1, .realgap = 10, .gappx = 10};
static unsigned int borderpx = 1; /* border pixel of windows */
static unsigned int snap = 32; /* snap pixel */
static int swallowfloating = 0; /* 1 means swallow floating windows by default */
static int showbar = 1; /* 0 means no bar */
static int topbar = 1; /* 0 means bottom bar */
-static const int horizpadbar = 2; /* horizontal padding for statusbar */
-static const int vertpadbar = 0; /* vertical padding for statusbar */
+static const int horizpadbar = 2; /* horizontal padding for statusbar */
+static const int vertpadbar = 0; /* vertical padding for statusbar */
/* Display modes of the tab bar: never shown, always shown, shown only in */
/* monocle mode in presence of several windows. */
@@ -130,6 +131,10 @@ static const 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 761f292..dc73b06 100644
--- a/dwm.c
+++ b/dwm.c
@@ -64,6 +64,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 */
@@ -120,6 +123,12 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
+typedef struct {
+ int isgap;
+ int realgap;
+ int gappx;
+} Gap;
+
#define MAXTABS 50
typedef struct Pertag Pertag;
@@ -132,6 +141,7 @@ struct Monitor {
int ty; /* tab 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];
@@ -206,6 +216,7 @@ static void focusin(XEvent *e);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static void focuswin(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);
@@ -241,6 +252,7 @@ static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen);
static void setsticky(Client *c, int sticky);
+static void setgaps(const Arg *arg);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
@@ -781,6 +793,8 @@ createmon(void)
m->showtab = showtab;
m->topbar = topbar;
m->toptab = toptab;
+ m->gap = malloc(sizeof(Gap));
+ gap_copy(m->gap, &default_gap);
m->ntabs = 0;
m->lt[0] = &layouts[def_layouts[1] % LENGTH(layouts)];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
@@ -1512,6 +1526,35 @@ prevtiled(Client *c) {
}
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
propertynotify(XEvent *e)
{
Client *c;
@@ -2038,18 +2081,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;
}
}