Skip to content

Instantly share code, notes, and snippets.

@ivoarch
Last active October 12, 2015 23:57
Show Gist options
  • Save ivoarch/4107047 to your computer and use it in GitHub Desktop.
Save ivoarch/4107047 to your computer and use it in GitHub Desktop.
equivalent to stumpwm's [run-or-raise] action for DWM
--- 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;
@sw2wolf
Copy link

sw2wolf commented Jun 16, 2013

can it run opera ?

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