Adding attachabove, attachaside, attachbelow and attachbottom patches

This commit is contained in:
bakkeby 2019-09-06 23:25:32 +02:00
parent ab6eb60657
commit 04a7b4de40
7 changed files with 102 additions and 1 deletions

View File

@ -1,4 +1,4 @@
This side project has a different take on dwm patching. It uses preprocessor directives to decide whether or not to include a patch during build time; essentially this means that this build, for better or worse, contains both the patched _and_ the original code. The aim being that you can select which patches to include and the build will contain that code and nothing more.
This side project has a different take on dwm patching. It uses preprocessor directives to decide whether or not to include a patch during build time. Essentially this means that this build, for better or worse, contains both the patched _and_ the original code. The aim being that you can select which patches to include and the build will contain that code and nothing more.
For example to include the alpha patch then you would only need to flip this setting from 0 to 1 in [patches.h](https://github.com/bakkeby/dwm-flexipatch/blob/master/patches.h):
```c
@ -11,6 +11,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog:
2019-09-06 - Added attachabove, attachaside, attachbelow and attachbottom patches
2019-09-05 - Alpha, systray, togglefullscreen, tagallmon, tagmonfixfs, tagswapmon, pertag and zoomswap patches added
### Patches included:
@ -18,6 +20,18 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
- [alpha](https://dwm.suckless.org/patches/alpha/)
- adds transparency for the status bar
- [attachabove](https://dwm.suckless.org/patches/attachabove/)
- new windows are placed above selected client
- [attachaside](https://dwm.suckless.org/patches/attachaside/)
- new windows are placed on top of the stack
- [attachbelow](https://dwm.suckless.org/patches/attachbelow/)
- new windows are placed below selected client
- [attachbottom](https://dwm.suckless.org/patches/attachbottom/)
- new windows are placed at the bottom of the stack
- [pertag](https://dwm.suckless.org/patches/pertag/)
- adds nmaster, mfact, layouts and more per tag rather than per monitor

13
dwm.c
View File

@ -50,7 +50,12 @@
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
#if ATTACHASIDE_PATCH
#define ISVISIBLEONTAG(C, T) ((C->tags & T))
#define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags])
#else
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
#endif // ATTACHASIDE_PATCH
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
@ -1248,7 +1253,11 @@ manage(Window w, XWindowAttributes *wa)
c->isfloating = c->oldstate = trans != None || c->isfixed;
if (c->isfloating)
XRaiseWindow(dpy, c->win);
#if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH
attachx(c);
#else
attach(c);
#endif
attachstack(c);
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &(c->win), 1);
@ -1625,7 +1634,11 @@ sendmon(Client *c, Monitor *m)
detachstack(c);
c->mon = m;
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
#if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH
attachx(c);
#else
attach(c);
#endif
attachstack(c);
focus(NULL);
arrange(NULL);

41
patch/attachx.c Normal file
View File

@ -0,0 +1,41 @@
void
attachx(Client *c)
{
#if ATTACHABOVE_PATCH
Client *at;
if (!(c->mon->sel == NULL || c->mon->sel == c->mon->clients || c->mon->sel->isfloating)) {
for (at = c->mon->clients; at->next != c->mon->sel; at = at->next);
c->next = at->next;
at->next = c;
return;
}
#elif ATTACHASIDE_PATCH
Client *at;
unsigned int n;
for (at = c->mon->clients, n = 0; at; at = at->next)
if (!at->isfloating && ISVISIBLEONTAG(at, c->tags))
if (++n >= c->mon->nmaster)
break;
if (at && c->mon->nmaster) {
c->next = at->next;
at->next = c;
return;
}
#elif ATTACHBELOW_PATCH
if (!(c->mon->sel == NULL || c->mon->sel->isfloating)) {
c->next = c->mon->sel->next;
c->mon->sel->next = c;
return;
}
#elif ATTACHBOTTOM_PATCH
Client *at;
for (at = c->mon->clients; at && at->next; at = at->next);
if (at) {
at->next = c;
return;
}
#endif
attach(c); // master (default)
}

1
patch/attachx.h Normal file
View File

@ -0,0 +1 @@
static void attachx(Client *c);

View File

@ -2,6 +2,10 @@
#include "alpha.c"
#endif
#if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH
#include "attachx.c"
#endif
#if PERTAG_PATCH
#include "pertag.c"
#endif

View File

@ -2,6 +2,10 @@
#include "alpha.h"
#endif
#if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH
#include "attachx.h"
#endif
#if SYSTRAY_PATCH
#include "systray.h"
#endif

View File

@ -12,6 +12,30 @@
*/
#define ALPHA_PATCH 0
/* This patch adds new clients above the selected client, instead of always
* becoming the new master. This behaviour is known from Xmonad.
* This patch takes precedence over ATTACHASIDE_PATCH.
* https://dwm.suckless.org/patches/attachabove/
*/
#define ATTACHABOVE_PATCH 0
/* This patch adds new clients on top of the stack.
* This patch takes precedence over ATTACHBELOW_PATCH.
* https://dwm.suckless.org/patches/attachaside/
*/
#define ATTACHASIDE_PATCH 0
/* This patch adds new clients below the selected client.
* This patch takes precedence over ATTACHBOTTOM_PATCH.
* https://dwm.suckless.org/patches/attachbelow/
*/
#define ATTACHBELOW_PATCH 0
/* This patch adds new clients at the bottom of the stack.
* https://dwm.suckless.org/patches/attachbottom/
*/
#define ATTACHBOTTOM_PATCH 0
/* The systray patch adds systray for the status bar.
* https://dwm.suckless.org/patches/systray/
*/