public
Last active

equivalent to stumpwm's [run-or-raise] action for DWM

  • Download Gist
runorraise.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
--- config.def.h.orig 2013-11-29 13:55:53.503216554 +0100
+++ config.def.h 2013-11-29 13:56:58.268191528 +0100
@@ -53,12 +53,14 @@
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", se\
lbgcolor, "-sf", selfgcolor, NULL };
static const char *termcmd[] = { "st", NULL };
+static const char *emacs[] = { "emacs", NULL, NULL, NULL, "Emacs" };
static Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} },
+ { Modkey, XK_e, runorraise, {.v = emacs } },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
@@ -107,4 +109,3 @@
{ ClkTagBar, MODKEY, Button1, tag, {0} },
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
};
-
--- dwm.c.orig 2013-11-29 13:58:49.673588564 +0100
+++ dwm.c 2013-11-23 22:56:49.725007370 +0100
@@ -193,6 +193,7 @@
static void resizemouse(const Arg *arg);
static void restack(Monitor *m);
static void run(void);
+static void runorraise(const Arg *arg);
static void scan(void);
static Bool sendevent(Client *c, Atom proto);
static void sendmon(Client *c, Monitor *m);
@@ -1349,6 +1350,30 @@
}
void
+runorraise(const Arg *arg) {
+ char *app = ((char **)arg->v)[4];
+ Arg a = { .ui = ~0 };
+ Monitor *mon;
+ Client *c;
+ XClassHint hint = { NULL, NULL };
+ /* 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 (hint.res_class && strcmp(app, hint.res_class) == 0) {
+ a.ui = c->tags;
+ view(&a);
+ focus(c);
+ XRaiseWindow(dpy, c->win);
+ return;
+ }
+ }
+ }
+ /* Client not found: spawn it */
+ spawn(arg);
+}
+
+void
scan(void) {
unsigned int i, num;
Window d1, d2, *wins = NULL;

can it run opera ?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.