Skip to content

Commit

Permalink
Add gaps between dwm windows via patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaweees committed Mar 5, 2024
1 parent 349a20c commit e613380
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .config/dwm/config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

/* The border pixel determines the size of the window border. */
static const unsigned int borderpx = 15; /* border pixel of windows */
static const unsigned int gappx = 15; /* gaps between windows */
/* The snap pixel controls two things:
* - how close to the window area border a window must be before it "snaps"
* (or docks) against that border when moving a floating window using the mouse
Expand Down Expand Up @@ -155,7 +156,7 @@ static const int nmaster = 1; /* number of clients in master area */
* of a client window when the client is tiled. Refer to the applysizehints
* function writeup for more details. */
static const int resizehints =
1; /* 1 means respect size hints in tiled resizals */
0; /* 1 means respect size hints in tiled resizals */
/* The lockfullscreen variable controls whether or not focus is allowed to drift
* from a fullscreen window. Refer to the writeup of the focusstack function for
* which this feature is isolated. */
Expand Down
42 changes: 30 additions & 12 deletions .config/dwm/dwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,10 @@
#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
/* The actual width of a client window includes the border and this macro helps
* calculate that. */
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
#define WIDTH(X) ((X)->w + 2 * (X)->bw + gappx)
/* The actual height of a client window includes the border and this macro helps
* calculate that. */
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
#define HEIGHT(X) ((X)->h + 2 * (X)->bw + gappx)
/* The TAGMASK macro gives a binary value that represents a valid bitmask
* according to how many tags are defined.
*
Expand Down Expand Up @@ -4578,6 +4578,29 @@ void resize(Client *c, int x, int y, int w, int h, int interact) {
*/
void resizeclient(Client *c, int x, int y, int w, int h) {
XWindowChanges wc;
unsigned int n;
unsigned int gapoffset;
unsigned int gapincr;
Client *nbc;
wc.border_width = c->bw;

/* Get number of clients for the client's monitor */
for (n = 0, nbc = nexttiled(c->mon->clients); nbc; nbc = nexttiled(nbc->next), n++);

/* Do nothing if layout is floating */
if (c->isfloating || c->mon->lt[c->mon->sellt]->arrange == NULL) {
gapincr = gapoffset = 0;
} else {
/* Remove border and gap if layout is monocle or only one client */
if (c->mon->lt[c->mon->sellt]->arrange == monocle || n == 1) {
gapoffset = 0;
gapincr = -2 * borderpx;
wc.border_width = 0;
} else {
gapoffset = gappx;
gapincr = 2 * gappx;
}
}

/* There are three things happening here:
* - the existing x, y, w and h are stored in oldx, oldy, oldw and oldh
Expand All @@ -4590,15 +4613,10 @@ void resizeclient(Client *c, int x, int y, int w, int h) {
* function, so setting those here is only in relation to the resizeclient
* call being made in that function.
*/
c->oldx = c->x;
c->x = wc.x = x;
c->oldy = c->y;
c->y = wc.y = y;
c->oldw = c->w;
c->w = wc.width = w;
c->oldh = c->h;
c->h = wc.height = h;
wc.border_width = c->bw;
c->oldx = c->x; c->x = wc.x = x + gapoffset;
c->oldy = c->y; c->y = wc.y = y + gapoffset;
c->oldw = c->w; c->w = wc.width = w - gapincr;
c->oldh = c->h; c->h = wc.height = h - gapincr;
/* This calls reconfigures the window's size, position and border according to
* the XWindowChanges structure that have been populated with data above. */
XConfigureWindow(
Expand Down Expand Up @@ -6188,7 +6206,7 @@ void tile(Monitor *m) {
* client, we subtract the border width from the size 0 -
* this resize is not the result of the user interacting with the window
*/
resize(c, m->wx, m->wy + my, mw - (2 * c->bw), h - (2 * c->bw), 0);
resize(c, m->wx, m->wy + my, mw - (2*c->bw) + (n > 1 ? gappx : 0), h - (2*c->bw), 0);

/* We increment the master y position with the height of the client after
* the resize so that we know where the next client can be positioned.
Expand Down
100 changes: 100 additions & 0 deletions .config/dwm/patches/dwm-uselessgap-20211119-58414bee958f2.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
From 58414bee958f2e7ed91d6fe31f503ec4a406981b Mon Sep 17 00:00:00 2001
From: cirala <thim@cederlund.de>
Date: Fri, 19 Nov 2021 18:14:07 +0100
Subject: [PATCH] Fix for dwm-uselessgap
Previous versions of the patch doubles the
gap between the master and slave stacks.

---
config.def.h | 3 ++-
dwm.c | 38 +++++++++++++++++++++++++++++++-------
2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/config.def.h b/config.def.h
index a2ac963..17a205f 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 unsigned int gappx = 6; /* gaps between windows */
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 */
@@ -34,7 +35,7 @@ static const Rule rules[] = {
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */
-static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
+static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */

static const Layout layouts[] = {
diff --git a/dwm.c b/dwm.c
index 5e4d494..b626e89 100644
--- a/dwm.c
+++ b/dwm.c
@@ -52,8 +52,8 @@
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
-#define WIDTH(X) ((X)->w + 2 * (X)->bw)
-#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
+#define WIDTH(X) ((X)->w + 2 * (X)->bw + gappx)
+#define HEIGHT(X) ((X)->h + 2 * (X)->bw + gappx)
#define TAGMASK ((1 << LENGTH(tags)) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)

@@ -1277,12 +1277,36 @@ void
resizeclient(Client *c, int x, int y, int w, int h)
{
XWindowChanges wc;
+ unsigned int n;
+ unsigned int gapoffset;
+ unsigned int gapincr;
+ Client *nbc;

- c->oldx = c->x; c->x = wc.x = x;
- c->oldy = c->y; c->y = wc.y = y;
- c->oldw = c->w; c->w = wc.width = w;
- c->oldh = c->h; c->h = wc.height = h;
wc.border_width = c->bw;
+
+ /* Get number of clients for the client's monitor */
+ for (n = 0, nbc = nexttiled(c->mon->clients); nbc; nbc = nexttiled(nbc->next), n++);
+
+ /* Do nothing if layout is floating */
+ if (c->isfloating || c->mon->lt[c->mon->sellt]->arrange == NULL) {
+ gapincr = gapoffset = 0;
+ } else {
+ /* Remove border and gap if layout is monocle or only one client */
+ if (c->mon->lt[c->mon->sellt]->arrange == monocle || n == 1) {
+ gapoffset = 0;
+ gapincr = -2 * borderpx;
+ wc.border_width = 0;
+ } else {
+ gapoffset = gappx;
+ gapincr = 2 * gappx;
+ }
+ }
+
+ c->oldx = c->x; c->x = wc.x = x + gapoffset;
+ c->oldy = c->y; c->y = wc.y = y + gapoffset;
+ c->oldw = c->w; c->w = wc.width = w - gapincr;
+ c->oldh = c->h; c->h = wc.height = h - gapincr;
+
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
configure(c);
XSync(dpy, False);
@@ -1688,7 +1712,7 @@ tile(Monitor *m)
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);
- resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
+ resize(c, m->wx, m->wy + my, mw - (2*c->bw) + (n > 1 ? gappx : 0), h - (2*c->bw), 0);
if (my + HEIGHT(c) < m->wh)
my += HEIGHT(c);
} else {
--
2.33.1

0 comments on commit e613380

Please sign in to comment.