[dwm] [dvtm][RFC] dvtm command interface over a named pipe

From: Marc Andre Tanner <mat_AT_brain-dump.org>
Date: Mon, 23 Jun 2008 23:36:32 +0200


I was recently asked whether it would be possible to add a command
interface to dvtm which would allow external scripts to control dvtm.

One usecase which was given are shell aliases which could be defined so
that certain apps would automatically run in a new window (man was
mentioned as an example which would open all the manual pages in a new
window by sending an appropirate command to dvtm).

Another possible usecase are monitoring scripts running in a minimized
window which would bring themself to focus when something interesting

To make this work i have added a new command line option -c which expects
the file name of a named pipe and creates it if it doesn't exists.
The name of the pipe is stored in an environment variable called
DVTM_CMD_FIFO. dvtm will then look for commands it knows based on
what is defined in config.h where we find a new section with a
commands array:

Cmd commands[] = {
        { "create", { create, { NULL } } },

This allows us to specify commands with associated actions. If the command
has no parameters defined (as in the example above with NULL) then the
arguments which are read from the named pipe are passed to the function.
However if there are parameters given in config.h the arguments from the
named pipe which follow the command name are ignored.

Each window has a unique window id which is stored in an environment
variable called DVTM_WINDOW_ID. This id can be used to apply certain
commands to individual windows. For example a function could be written
which focuses and unminimizes a window based on a given id:

Cmd commands[] = {
        { "focus", { focus_by_id, { NULL } } },

focus_by_id(const char *args[]) {
        Client *c;

        if (!args || !args[0])
        for (c = clients; c; c = c->next) {
                if (c->id == atoi(args[0])) {
                        if (c->minimized)

This could then be called from a script which is run from within dvtm
as shown below:


Some basic argument processing which handles quotes is implemented and i
hope it will work for most cases. However remember that the shell eats
normal quotes so you will need to escape them with \'

echo create \'irssi -c irc.freenode.net\' > $DVTM_CMD_FIFO

So what do you guys think? Is this useful enough to be in mainline dvtm?

By the way this feature can be disabled at compile time so it shouldn't
bother people who think this is unecessary bloat.

Anyway my current implementation to play around can be found at:


Comments welcome.

Have fun,

 Marc Andre Tanner >< http://www.brain-dump.org/ >< GPG key: CF7D56C0
Received on Mon Jun 23 2008 - 23:38:29 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:51:19 UTC