Last active
December 30, 2015 17:39
-
-
Save jgrar/9a84a66c85ed8a985726 to your computer and use it in GitHub Desktop.
add support for better window hint matching
This file contains 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
diff --git a/runorraise.c b/runorraise.c | |
new file mode 100644 | |
index 0000000..5494aaa | |
--- /dev/null | |
+++ b/runorraise.c | |
@@ -0,0 +1,52 @@ | |
+typedef struct { | |
+ char *class; | |
+ char *name; | |
+ char *spawncmd[]; | |
+} ClassHintedCmd; | |
+ | |
+void | |
+runorraise(const Arg *_arg) { | |
+ ClassHintedCmd *arg = *(ClassHintedCmd **)_arg; | |
+ Arg a = { .ui = ~0 }; | |
+ Monitor *mon; | |
+ Client *c; | |
+ XClassHint hint = { NULL, NULL }; | |
+ | |
+ if (arg->class == NULL && arg->name == NULL) { | |
+ return; | |
+ } | |
+ | |
+ /* Tries to find the client */ | |
+ for (mon = mons; mon; mon = mon->next) { | |
+ for (c = mon->clients; c; c = c->next) { | |
+ XGetClassHint(dpy, c->win, &hint); | |
+ | |
+ if (arg->class && arg->name | |
+ && strcmp(arg->class, hint.res_class) != 0 | |
+ || strcmp(arg->name, hint.res_name) != 0) { | |
+ continue; | |
+ | |
+ } else { | |
+ | |
+ } if (arg->class && hint.res_class | |
+ && strcmp(arg->class, hint.res_class) != 0) { | |
+ continue; | |
+ | |
+ if (arg->name && hint.res_name | |
+ && strcmp(arg->name, hint.res_name) != 0) { | |
+ continue; | |
+ } | |
+ } | |
+ | |
+ a.ui = c->tags; | |
+ view(&a); | |
+ focus(c); | |
+ XRaiseWindow(dpy, c->win); | |
+ return; | |
+ | |
+ } | |
+ } | |
+ /* Client not found: spawn it */ | |
+ spawn(&(Arg){.v = arg->spawncmd}); | |
+} | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Runorraise
Original
http://dwm.suckless.org/patches/runorraise
Changes
Usage:
The original patch enforced a 5 element limit on the runorraise argument, using the last element for the class name. So you would really only get 3 elements to use (i.e. 5 elements minus the class name and terminating NULL field) and if you didn't use them you would waste space padding the array with NULLs. This change removes that restriction and adds window name hint matching, which is likely the hint you actually want to use to match windows seeing as the class hint encapsulates multiple window types and as far as I know there's no way for a user to set it.
config.h: