diff options
| author | gonzo <gonzo@toniatuh.com> | 2023-05-17 20:28:10 +0200 |
|---|---|---|
| committer | gonzo <gonzo@toniatuh.com> | 2023-05-17 20:28:10 +0200 |
| commit | b206a544652e7f1c06172b4c059c057cf946d9ef (patch) | |
| tree | 5d7ff326fb9dd4eb156f555501da9b908e2928d9 | |
| parent | f385a8797302dfdfcd6a38649f09011b491783c5 (diff) | |
| download | dwm-b206a544652e7f1c06172b4c059c057cf946d9ef.tar.gz | |
added scratchpads for term and bc
| -rw-r--r-- | config.h | 16 | ||||
| -rw-r--r-- | dwm.c | 43 |
2 files changed, 57 insertions, 2 deletions
@@ -21,6 +21,18 @@ static const char *colors[][3] = { [SchemeSel] = { col_gray4, col_cyan, col_cyan }, }; +typedef struct { + const char *name; + const void *cmd; +} Sp; +const char *spterm[] = {"st", "-n", "spterm", "-g", "50x20", NULL }; +const char *spcalc[] = {"st", "-n", "spcalc", "-g", "40x10", "-e", "bc", "-l", NULL }; +static Sp scratchpads[] = { + /* name cmd */ + {"spterm", spterm}, + {"spcalc", spcalc}, +}; + /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; @@ -32,6 +44,8 @@ static const Rule rules[] = { /* class instance title tags mask isfloating monitor */ { "Gimp", NULL, NULL, 0, 1, -1 }, { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, + { NULL, "spterm", NULL, SPTAG(0), 1, -1 }, + { NULL, "spcalc", NULL, SPTAG(1), 1, -1 }, }; /* layout(s) */ @@ -66,8 +80,10 @@ static const Key keys[] = { /* modifier key function argument */ { MODKEY, XK_d, spawn, {.v = dmenucmd } }, { MODKEY, XK_Return, spawn, {.v = termcmd } }, + { MODKEY, XK_grave, togglescratch, {.ui = 0 } }, // spterm { MODKEY, XK_b, togglebar, {0} }, { MODKEY|ShiftMask, XK_b, toggleborder, {0} }, + { MODKEY, XK_c, togglescratch, {.ui = 1 } }, // spcalc { MODKEY, XK_s, togglesticky, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, @@ -54,7 +54,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) /* enums */ @@ -214,6 +217,7 @@ static void tile(Monitor *m); static void togglebar(const Arg *arg); static void toggleborder(const Arg *arg); static void togglefloating(const Arg *arg); +static void togglescratch(const Arg *arg); static void togglesticky(const Arg *arg); static void togglefullscr(const Arg *arg); static void toggletag(const Arg *arg); @@ -304,6 +308,11 @@ 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; @@ -313,7 +322,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 @@ -1647,6 +1656,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) @@ -1773,6 +1786,32 @@ togglesticky(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; |
