summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authorjoshua <joshua@joshuayun.com>2023-12-23 12:07:02 -0500
committerjoshua <joshua@joshuayun.com>2023-12-23 12:07:02 -0500
commit5821fed4cfe0ae6753c1abe1981f2df0acbc09f7 (patch)
tree7754e7a13f234cee54156249fcde4ad8573ed671 /dwm.c
parentcfea1741794fd7caba75078105ad95f2bafdd2ed (diff)
downloaddwm-5821fed4cfe0ae6753c1abe1981f2df0acbc09f7.tar.gz
patched in scratch pads
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/dwm.c b/dwm.c
index 94c8cfc..0e116eb 100644
--- a/dwm.c
+++ b/dwm.c
@@ -66,7 +66,10 @@
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
-#define TAGMASK ((1 << LENGTH(tags)) - 1)
+#define NUMTAGS (LENGTH(tags) + LENGTH(scratchpads))
+#define TAGMASK ((1 << NUMTAGS) - 1)
+#define SPTAG(i) ((1 << LENGTH(tags)) << (i))
+#define SPTAGMASK (((1 << LENGTH(scratchpads))-1) << LENGTH(tags))
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
#define TRUNC(X,A,B) (MAX((A), MIN((X), (B))))
@@ -274,6 +277,7 @@ static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
+static void togglescratch(const Arg *arg);
static void togglefullscr(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
@@ -382,6 +386,11 @@ applyrules(Client *c)
c->noswallow = r->noswallow;
c->isfloating = r->isfloating;
c->tags |= r->tags;
+ if ((r->tags & SPTAGMASK) && r->isfloating) {
+ c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
+ c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
+ }
+
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
c->mon = m;
@@ -391,7 +400,7 @@ applyrules(Client *c)
XFree(ch.res_class);
if (ch.res_name)
XFree(ch.res_name);
- c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
+ c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : (c->mon->tagset[c->mon->seltags] & ~SPTAGMASK);
}
int
@@ -1947,6 +1956,10 @@ showhide(Client *c)
if (!c)
return;
if (ISVISIBLE(c)) {
+ if ((c->tags & SPTAGMASK) && c->isfloating) {
+ c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
+ c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
+ }
/* show clients top down */
XMoveWindow(dpy, c->win, c->x, c->y);
if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
@@ -2085,6 +2098,32 @@ togglefullscr(const Arg *arg)
}
void
+togglescratch(const Arg *arg)
+{
+ Client *c;
+ unsigned int found = 0;
+ unsigned int scratchtag = SPTAG(arg->ui);
+ Arg sparg = {.v = scratchpads[arg->ui].cmd};
+
+ for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next);
+ if (found) {
+ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag;
+ if (newtagset) {
+ selmon->tagset[selmon->seltags] = newtagset;
+ focus(NULL);
+ arrange(selmon);
+ }
+ if (ISVISIBLE(c)) {
+ focus(c);
+ restack(selmon);
+ }
+ } else {
+ selmon->tagset[selmon->seltags] |= scratchtag;
+ spawn(&sparg);
+ }
+}
+
+void
toggletag(const Arg *arg)
{
unsigned int newtags;