diff options
Diffstat (limited to 'dwm.c')
-rw-r--r-- | dwm.c | 47 |
1 files changed, 45 insertions, 2 deletions
@@ -54,7 +54,9 @@ #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 TAGMASK (~0) +#define SPTAG(X) (1 << (LENGTH(tags) + (X))) +#define SPTAGMASK (~0 << LENGTH(tags)) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) #define OPAQUE 0xffU @@ -145,6 +147,7 @@ typedef struct { unsigned int tags; int isfloating; int monitor; + const char *scratchpad_exec; } Rule; /* function declarations */ @@ -226,6 +229,7 @@ static void tile(Monitor *m); static void togglebar(const Arg *arg); static void holdbar(const Arg *arg); static void togglefloating(const Arg *arg); +static void togglescratch(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c, int setfocus); @@ -381,6 +385,10 @@ applyrules(Client *c) { 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; @@ -390,7 +398,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 @@ -1994,6 +2002,41 @@ togglefloating(const Arg *arg) } void +togglescratch(const Arg *arg) +{ + const Rule *sp = arg->v; + + unsigned int found = 0; + unsigned int scratchtag = sp->tags; + Client *c; + + 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 { + const char *exec[] = { "st", "-n", sp->instance, "-g", scratchpad_size, NULL, NULL, NULL }; + if (sp->scratchpad_exec) { + exec[5] = "-e"; + exec[6] = sp->scratchpad_exec; + } + + Arg execarg = {.v = exec}; + selmon->tagset[selmon->seltags] |= scratchtag; + spawn(&execarg); + } +} + +void toggletag(const Arg *arg) { unsigned int newtags; |