[dwm] Configurable app launcher for dwm...

From: Glyn Faulkner <glyn.faulkner_AT_gmail.com>
Date: Thu, 30 Oct 2008 15:17:45 +0000

Hello all,

First of all, thank you for the excellent window manager - I've been
using dwm for a couple of months now (my first foray into tiling WMs)
and I'm definitely a convert.

Anyway, I don't know if anyone can make use of the following, but this
is a re-configurable application launcher (in the form of a three-line
shell script) I wrote for dwm, which needs to be placed somewhere in
your $PATH:

--- dlauncher
#!/bin/bash

source ~/.dlauncherrc

[[ ! -z "${!1}" ]] && exec bash -c "${!1}" &
--- end

it's called with a single argument, which is used as a lookup string
for commands contained in the .dlauncherrc config file. This string
can be anything (as long as it's a valid bash variable name) but I've
written the following macro for use in config.h that automatically
uses the xorg key macro name:

--- begin
#define LAUNCHKEYS(KEY) \
    { MODKEY, KEY, spawn, {.v = (const
char*[]){ "dlauncher", #KEY } } }, \
    { MODKEY|ControlMask, KEY, spawn, {.v = (const
char*[]){ "dlauncher", "CTRL_" #KEY } } }, \
    { MODKEY|ShiftMask, KEY, spawn, {.v = (const
char*[]){ "dlauncher", "SHIFT_" #KEY } } }, \
    { MODKEY|ControlMask|ShiftMask, KEY, spawn, {.v = (const
char*[]){ "dlauncher", "SHIFT_CTRL_" #KEY } } },
--- end

This lets you bind (for example) MOD-F1, Shift-MOD-F1, Ctrl-MOD-F1 and
Ctrl-Shift-MOD-F1 with the following single line in config.h:

    LAUNCHKEYS( XK_F1 )

And handle the results in ~/.dlauncherrc like this:

--- .dlauncherrc
XK_F1="urxvtc -ls || ( urxvtd -q -o -f && urxvtc -ls )"
SHIFT_XK_F1="xterm -ls"
CTRL_XK_F1="kdialog --getexistingdirectory /home/music | sed
's:^/home/music/::' | mpc add && mpc play"
#SHIFT_CTRL_XK_F1=""
--- end

If you have a keyboard with extra multimedia keys you want to bind
with no modifier, you can just add something like this to your
config.h:

    { 0, XF86XK_AudioPlay, spawn,
SHCMD("dlauncher XF86XK_AudioPlay") },
    { 0, XF86XK_HomePage, spawn,
SHCMD("dlauncher Browser") },

and in .dlauncherrc:

    XF86XK_AudioPlay="mpc toggle"
    Browser="opera"

Keys without an entry in .dlauncherrc are simply ignored, and as you
can see there are no arbitrary restrictions on the complexity of the
command that can be run. As well as letting you re-bind application
launch keys on-the-fly (without restarting or recompiling dwm) it also
keeps your config.h manageable if (like me) you have a lot of keys
bound to launching common applications.

Questions, comments and cheap abuse are always welcome. :)

Cheers

Glyn
Received on Thu Oct 30 2008 - 15:17:45 UTC

This archive was generated by hypermail 2.2.0 : Thu Oct 30 2008 - 15:24:03 UTC