[dwm] [PATCH] Add support for on-start actions

From: Jules Villard <jules.villard_AT_ens-lyon.org>
Date: Sat, 26 Apr 2008 14:33:33 +0200

Hi all,

This patch adds the ability to perform user-defined actions on
startup. In particular, you can launch some applications like a bunch
of terms, a browser, you name it... or select a specific tag. I found
a need for it because I always perform the same actions when I start
X :) As the patch is very small --it only adds a structure and a
small loop in dwm.c, amounting to 9 lines of code-- I'm (perhaps
boldly) hoping that you might find it interesting too and consider it
for inclusion.

For my personal use, I have something similar to the following snippet
of code in config.h:

-8<-------------------------------------------------------------------

  /* tagging */
  const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "#", "zik", "www" };

  Rule rules[] = {
        /* class instance title tags ref isfloating */
        { "Firefox", NULL, NULL, tags[6], False },
        { "rxvt", NULL, "ncmpc", tags[5], False },
        { "rxvt", NULL, "alsamixer", tags[5], False },
        { "rxvt", NULL, "start", tags[0], False },
        { "rxvt", NULL, "sudo", tags[4], False },
  };

  /* actions to be performed on startup */
  Start start[] = {
        /* function argument */
        { spawn, "exec rxvt -e mutt" }, /* tagged "1" */
        { spawn, "exec rxvt -e screen irssi" }, /* same */

        { spawn, "exec rxvt -e alsamixer" }, /* tagged "zik" */
        { spawn, "exec rxvt -e sudo su -" }, /* tagged "#" */
        { spawn, "exec firefox" }, /* tagged "www" */

        /* tagged "zik" and zoomed */
        { spawn, "exec rxvt -e ncmpc" },
        /* tagged "1" and zoomed */
        { spawn, "exec rxvt -ls -title start" },
        /* now select tag 4 to type my password */
        { view, tags[4]},
  };

-8<-------------------------------------------------------------------

  This allows me to start my session with 3 terms tagged "1": mutt and
irssi are stacked on the right-hand side and an empty term is readied
on the left-hand side. Timing is important, so the last term is
spawned some time after the first two to be the last term indeed and
get the zoom. Likewise, some applications are launched between the
alsamixer and the ncmpc instances, so that the latter ends up getting
the zoom. Moreover, since I like to start seeing tag 4, which
corresponds to my sudo'd term --otherwise I tend to forget to type my
password-- I force the tagging of the third term I want with tag "1"
by assigning that term a special title (rxvt -title start) which I add
to the rules. This term might otherwise end up being spawned with
tag 4.

  I think this really is a corner case and that you might not need to
be bothered with such a level of details, e.g. if you do not mind
having to re-tag some windows by hand. I think my main point is that
basic usage --for instance launching two terms, a browser and ncmpc at
startup-- is very intuitive and that you can achieve more complex ones
without heroic efforts, the other point being that the patch ended up
being ridiculously simple.

Thanks for reading this long email, -p1 patch against 4.9 follows.
Cheers,

Jules

diff -rNu dwm-4.9/config.def.h dwm-4.9-new/config.def.h
--- dwm-4.9/config.def.h 2008-04-25 00:17:29.000000000 +0200
+++ dwm-4.9-new/config.def.h 2008-04-25 00:20:34.000000000 +0200
@@ -40,6 +40,12 @@
         { "[M]", monocle, True },
 };
 
+/* on-start actions */
+Start start[] = {
+ /* function argument */
+ { spawn, "exec xterm" },
+};
+
 /* key definitions */
 #define MODKEY Mod1Mask
 Key keys[] = {
diff -rNu dwm-4.9/dwm.c dwm-4.9-new/dwm.c
--- dwm-4.9/dwm.c 2008-04-03 22:57:01.000000000 +0200
+++ dwm-4.9-new/dwm.c 2008-04-25 00:18:21.000000000 +0200
@@ -119,6 +119,11 @@
         Bool isfloating;
 } Rule;
 
+typedef struct {
+ void (*func)(const char *arg);
+ const char *arg;
+} Start;
+
 /* function declarations */
 void applyrules(Client *c);
 void arrange(void);
@@ -1559,6 +1564,10 @@
 
         /* grab keys */
         grabkeys();
+
+ /* run startup commands */
+ for(i = 0; i < LENGTH(start); i++)
+ start[i].func(start[i].arg);
 }
 
 void
Received on Sat Apr 26 2008 - 14:33:41 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:35:27 UTC