Skip to content

Instantly share code, notes, and snippets.

@jgrar
Last active December 30, 2015 17:39
Show Gist options
  • Save jgrar/9a84a66c85ed8a985726 to your computer and use it in GitHub Desktop.
Save jgrar/9a84a66c85ed8a985726 to your computer and use it in GitHub Desktop.
add support for better window hint matching
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});
+}
+
@jgrar
Copy link
Author

jgrar commented Dec 30, 2015

Runorraise

Original

http://dwm.suckless.org/patches/runorraise

Changes

* reduce amount of changes to main source to ease patch application
* add window name matching
* improve window class matching and add window name matching

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:

#include "runorraise.c"
ClassHintedCmd singletontermcmd = {
    /* it's just like window rules! use xprop to get the class, instance (name) hints
     * you can omit either, but not both.
     */
    .class = "URxvt",
    .name = "singleton",
    .spawncmd = { "urxvtc", "-name", "singleton", NULL }
};
// ... static Key keys[] = {
    { MODKEY|ShiftMask,             XK_a,      runorraise,          {.v = &singletontermcmd} },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment