diff options
| author | Douglas Rumbaugh <doug@douglasrumbaugh.com> | 2021-12-19 18:57:04 -0500 |
|---|---|---|
| committer | Douglas Rumbaugh <doug@douglasrumbaugh.com> | 2021-12-19 19:12:50 -0500 |
| commit | 8388bc59ddc2c672d02ff265fb5a3fa7ea6c5228 (patch) | |
| tree | 8c864474d8ca87ef4d99f74a43b0ee4e9626772b | |
| parent | aefa8dd026134400faf173258e2a63f5927cef9a (diff) | |
| download | dwm-8388bc59ddc2c672d02ff265fb5a3fa7ea6c5228.tar.gz | |
Added scratchpads patch
https://dwm.suckless.org/patches/scratchpads/
| -rw-r--r-- | config.def.h | 43 | ||||
| -rw-r--r-- | dwm.c | 43 |
2 files changed, 75 insertions, 11 deletions
diff --git a/config.def.h b/config.def.h index 5dc1f41..266648a 100644 --- a/config.def.h +++ b/config.def.h @@ -28,6 +28,22 @@ static char *colors[][3] = { [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor }, }; +/* scratchpads setup */ +typedef struct { + const char *name; + const void *cmd; +} Sp; + +const char *spcmd1[] = {"st", "-n", "spcalc", "-g", "144x41", "-e", "calc", NULL }; +const char *spcmd2[] = {"st", "-n", "spterm", "-g", "120x34", NULL }; +const char *spcmd3[] = {"st", "-n", "spnvim", "-g", "144x41", "-e", "nvim", NULL }; +static Sp scratchpads[] = { + /* name cmd */ + {"spcalc", spcmd1}, + {"spterm", spcmd2}, + {"spnvim", spcmd3}, +}; + /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; @@ -36,12 +52,15 @@ static const Rule rules[] = { * WM_CLASS(STRING) = instance, class * WM_NAME(STRING) = title */ - /* class instance title tags mask isfloating isterminal noswallow monitor */ - { "Gimp", NULL, NULL, 0, 1, 0, 0, -1 }, - { "Firefox", NULL, NULL, 1 << 8, 0, 0, -1, -1 }, - { "St", NULL, NULL, 0, 0, 1, 0, -1 }, - { NULL, "st", NULL, 0, 0, 1, 0, -1 }, - { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */ + /* class instance title tags mask isfloating isterminal noswallow monitor */ + { "Gimp", NULL, NULL, 0, 1, 0, 0, -1 }, + { "Firefox", NULL, NULL, 1 << 8, 0, 0, -1, -1 }, + { "St", NULL, NULL, 0, 0, 1, 0, -1 }, + { NULL, "st", NULL, 0, 0, 1, 0, -1 }, + { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */ + { NULL, "spcalc", NULL, SPTAG(0), 1, 1, 0, -1 }, + { NULL, "spterm", NULL, SPTAG(1), 1, 1, 0, -1 }, + { NULL, "spnvim", NULL, SPTAG(2), 1, 1, 0, -1 }, }; /* layout(s) */ @@ -109,6 +128,7 @@ ResourcePref resources[] = { { "mfact", FLOAT, &mfact }, }; + static Key keys[] = { /* modifier key function argument */ { MODKEY, XK_d, spawn, {.v = dmenucmd } }, @@ -116,8 +136,8 @@ static Key keys[] = { { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, - { MODKEY, XK_i, incnmaster, {.i = +1 } }, - { MODKEY, XK_p, incnmaster, {.i = -1 } }, + { MODKEY, XK_equal, incnmaster, {.i = +1 } }, + { MODKEY, XK_minus, incnmaster, {.i = -1 } }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY, XK_space, zoom, {0} }, @@ -164,6 +184,11 @@ static Key keys[] = { TAGKEYS( XK_9, 8) { MODKEY|ShiftMask, XK_q, quit, {0} }, { MODKEY|ShiftMask, XK_r, quit, {1} }, + + /* Application Launching Hotkeys */ + { MODKEY, XK_y, togglescratch, {.ui = 0 } }, + { MODKEY, XK_u, togglescratch, {.ui = 1 } }, + { MODKEY, XK_i, togglescratch, {.ui = 2 } }, }; /* button definitions */ @@ -176,7 +201,7 @@ static Button buttons[] = { { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, { ClkClientWin, MODKEY, Button1, movemouse, {0} }, { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, - { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, + { ClkClientWin, MODKEY, Button1, resizemouse, {0} }, { ClkTagBar, 0, Button1, view, {0} }, { ClkTagBar, 0, Button3, toggleview, {0} }, { ClkTagBar, MODKEY, Button1, tag, {0} }, @@ -61,7 +61,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 */ @@ -241,6 +244,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 toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c, int setfocus); @@ -342,6 +346,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; @@ -351,7 +360,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 @@ -1724,6 +1733,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) @@ -1816,6 +1829,32 @@ togglefloating(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; |