Add scratchpad for terminal
This commit is contained in:
parent
20edd67116
commit
175f76256f
@ -65,11 +65,14 @@ static const Layout layouts[] = {
|
||||
/* commands */
|
||||
static const char *dmenucmd[] = { "dmenu_run", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
|
||||
static const char *termcmd[] = { "st", NULL };
|
||||
static const char scratchpadname[] = "scratchpad";
|
||||
static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL };
|
||||
|
||||
static const Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
||||
{ MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } },
|
||||
{ MODKEY, XK_b, togglebar, {0} },
|
||||
{ MODKEY, XK_j, focusstack, {.i = +1 } },
|
||||
{ MODKEY, XK_k, focusstack, {.i = -1 } },
|
||||
|
3
config.h
3
config.h
@ -94,12 +94,15 @@ static const Layout layouts[] = {
|
||||
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
|
||||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray5, "-sb", col_gray2, "-sf", col_gray4, NULL };
|
||||
static const char *termcmd[] = { "st", NULL };
|
||||
static const char scratchpadname[] = "scratchpad";
|
||||
static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL };
|
||||
|
||||
static Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XK_d, spawn, {.v = dmenucmd } },
|
||||
{ MODKEY, XK_b, spawn, SHCMD("bt-menu") },
|
||||
{ MODKEY, XK_Return, spawn, {.v = termcmd } },
|
||||
{ MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } },
|
||||
{ MODKEY, XK_j, focusstack, {.i = +1 } },
|
||||
{ MODKEY, XK_k, focusstack, {.i = -1 } },
|
||||
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
|
||||
|
34
dwm.c
34
dwm.c
@ -261,6 +261,7 @@ static void tile(Monitor *m);
|
||||
static void togglebar(const Arg *arg);
|
||||
static void togglefloating(const Arg *arg);
|
||||
static void togglefullscr(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);
|
||||
@ -330,6 +331,8 @@ static xcb_connection_t *xcon;
|
||||
/* configuration, allows nested code to access above variables */
|
||||
#include "config.h"
|
||||
|
||||
static unsigned int scratchtag = 1 << LENGTH(tags);
|
||||
|
||||
/* compile-time check if all tags fit into an unsigned int bit array. */
|
||||
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
|
||||
|
||||
@ -1262,6 +1265,14 @@ manage(Window w, XWindowAttributes *wa)
|
||||
c->y = MAX(c->y, c->mon->wy);
|
||||
c->bw = borderpx;
|
||||
|
||||
selmon->tagset[selmon->seltags] &= ~scratchtag;
|
||||
if (!strcmp(c->name, scratchpadname)) {
|
||||
c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag;
|
||||
c->isfloating = True;
|
||||
c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
|
||||
c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
|
||||
}
|
||||
|
||||
wc.border_width = c->bw;
|
||||
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
|
||||
XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
|
||||
@ -1974,6 +1985,7 @@ sigchld(int unused)
|
||||
void
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
selmon->tagset[selmon->seltags] &= ~scratchtag;
|
||||
if (fork() == 0) {
|
||||
if (dpy)
|
||||
close(ConnectionNumber(dpy));
|
||||
@ -2097,6 +2109,28 @@ togglefullscr(const Arg *arg)
|
||||
setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
|
||||
}
|
||||
|
||||
void
|
||||
togglescratch(const Arg *arg)
|
||||
{
|
||||
Client *c;
|
||||
unsigned int found = 0;
|
||||
|
||||
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
|
||||
spawn(arg);
|
||||
}
|
||||
|
||||
void
|
||||
toggletag(const Arg *arg)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user