Created
November 3, 2011 01:45
-
-
Save ropery/1335543 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scratchpad.patch for dwm 5.9 | |
A scratchpad is a window that is assigned the (hidden) scratchtag. | |
A window becomes a scratchpad if its WM_NAME at its creation time is the value | |
of the scratchpadname variable. | |
togglescratchpad() is actually a variant of toggleview(). | |
To use this, put the following definitions in config.h: | |
static const char scratchpadname[] = "Scratchpad"; /* make it unique, avoid name collision */ | |
static const char *scratchpadcmd[] = { "uxterm", "-title", scratchpadname, "-geometry", "80x20", NULL }; /* WM_NAME must be scratchpadname */ | |
static Key keys[] = { | |
{ MODKEY|ControlMask, XK_x, spawn, {.v = scratchpadcmd } }, /* for more scratchpads */ | |
{ MODKEY, XK_x, togglescratchpad, {.v = scratchpadcmd } }, | |
} | |
BUGS | |
* With more than one scratchpad, a second scratch does not restore the focus | |
state of the last scratch, but will always focus the first scratchpad that is | |
found while looping through selmon->clients. | |
* With more than one scratchpad, only the focused (floating) scratchpad will be | |
raised to top of the stack. I think a better behavior would be to raise all | |
(floating) scratchpads to top of the stack. | |
diff -up a/dwm.c b/dwm.c | |
--- a/dwm.c 2011-07-13 12:00:00.000000000 +0000 | |
+++ b/dwm.c 2011-07-13 12:00:00.000000000 +0000 | |
@@ -224,6 +224,7 @@ static int textnw(const char *text, unsi | |
static void tile(Monitor *); | |
static void togglebar(const Arg *arg); | |
static void togglefloating(const Arg *arg); | |
+static void togglescratchpad(const Arg *arg); | |
static void toggletag(const Arg *arg); | |
static void toggleview(const Arg *arg); | |
static void unfocus(Client *c, Bool setfocus); | |
@@ -279,6 +280,9 @@ static Window root; | |
/* configuration, allows nested code to access above variables */ | |
#include "config.h" | |
+/* any client in scratchtag is a scratchpad */ | |
+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]; }; | |
@@ -1135,6 +1139,17 @@ manage(Window w, XWindowAttributes *wa) | |
&& (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my); | |
c->bw = borderpx; | |
} | |
+ /* scratchpad */ | |
+ if(!strcmp(c->name, scratchpadname)) { | |
+ c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag; | |
+ c->isfloating = True; | |
+ c->x = (c->mon->mw - WIDTH(c)) / 2; | |
+ c->y = (c->mon->mh - HEIGHT(c)) / 2; | |
+ } | |
+ else { | |
+ /* anything else must stay out of scratchtag */ | |
+ c->tags &= TAGMASK; | |
+ } | |
wc.border_width = c->bw; | |
XConfigureWindow(dpy, w, CWBorderWidth, &wc); | |
XSetWindowBorder(dpy, w, dc.norm[ColBorder]); | |
@@ -1689,6 +1704,27 @@ togglefloating(const Arg *arg) { | |
} | |
void | |
+togglescratchpad(const Arg *arg) { | |
+ Client *c = NULL; | |
+ unsigned int found = 0; | |
+ /* check if a scratchpad already exists in scratchtag */ | |
+ 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; | |
+ arrange(selmon); | |
+ } | |
+ if(ISVISIBLE(c)) { | |
+ focus(c); | |
+ restack(selmon); | |
+ } | |
+ } | |
+ else | |
+ spawn(arg); /* launch a new scratchpad, details handled by manage() */ | |
+} | |
+ | |
+void | |
toggletag(const Arg *arg) { | |
unsigned int newtags; | |
Hi. I would just make a scratchpadcmd2 and use it in the same manner scratchpadcmd is used.
Thanks, I got it to work now! The only caveat is I need to actually exit either scratchpad version manually for the other scratchpad to appear, but it's only a minor problem.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks lolilolicon, I finally got it to work!
One question: How would I make a scratchpad called by a different key combination spawn with a document opened in fx. vim? This is what I'd like it to do:
"urxvt -e vim /home/lys/txt/notes.txt" fx.?
I already changed scratchpadcmd to urxvt, so it's just how I append the latter part, while not overwriting the default scratchpadcmd? Do I copy scratchpadcmd and make a modified version or can I just append something to the shortcut after the ".v = scratchpadcmd" part?