display workspacename with osd

a well known feature (among others) of windowmaker is to display the workspace in a bright font ontop of the current workspace so one could never get lost when switiching the workspace. this howto describes a way to fake this behavior until a certain degree.

the display-part is pretty easy, we just need osd_cat, its part of xosd from http://www.ignavus.net/

the tricky part is, howto get the current workspacename out of a running fluxbox. well, its not *that* tricky:

$> xprop -root _WIN_WORKSPACE \\
                   _WIN_WORKSPACE_COUNT \\
                   _WIN_WORKSPACE_NAMES \\
                   _NET_CURRENT_DESKTOP \\
                   _NET_NUMBER_OF_DESKTOPS \\
                   _NET_DESKTOP_NAMES

magicly a certain amount of information about the workspaces in fluxbox appears. lets stick with the _NET* - hints. to get the name of the current used workspace one can do this:

$> xprop -root _NET_CURRENT_DESKTOP \\
                      _NET_NUMBER_OF_DESKTOPS \\
                      _NET_DESKTOP_NAMES | \\
      awk '
        /_NET_CURRENT_DESKTOP/ { current = $3 + 1; }
        /_NET_NUMBER_OF_DESKTOPS/ { no_ws = $3; }
        /_NET_DESKTOP_NAMES/ { for (i = 3; i < no_ws + 3; i++) {
                                 names[i - 3] = $i;
                                 gsub( "\"|,", " ", names[i - 3]);
                                 gsub ("[[:space:]]*", "", names[i - 3]);
                               };
                             };
        END { 
          print names[current - 1]" "current"/"no_ws;
        };'

hehe, yeah, looks pretty funny, but this should give you:

name_of_your_workspace no_current/no_total

ok, now what? easy: pipe this to osd_cat. since the awk-command is a bit long its a good idea to put this to a tiny shell-script:

-+- fbwsname.sh ------------------------------------------+-
#!/bin/sh
xprop -root _NET_CURRENT_DESKTOP \\
                 _NET_NUMBER_OF_DESKTOPS \\
                 _NET_DESKTOP_NAMES | \\
    awk '
      /_NET_CURRENT_DESKTOP/ { current = $3 + 1; }
      /_NET_NUMBER_OF_DESKTOPS/ { no_ws = $3; }
      /_NET_DESKTOP_NAMES/ { for (i = 3; i < no_ws + 3; i++) {
                               names[i - 3] = $i;
                               gsub( "\"|,", " ", names[i - 3]);
                               gsub ("[[:space:]]*", "", names[i - 3]);
                             };
                           };
      END { 
        print names[current - 1]" "current"/"no_ws;
      };'
-+--------------------------------------------------------+-

ok, now put this to a place where PATH will catch it (i use $HOME/bin) and add something like this to your ~/.fluxbox/keys:

Control Mod4 Right :MacroCmd {RightWorkspace} {ExecCommand fbwsname.sh}
Control Mod4 Left  :MacroCmd {LeftWorkspace} {ExecCommand fbwsname.sh}

and thats it. all the magic is done. one can customize this whole thingy a lot. i wrote "fbcmd", available at http://darkshed.net/files/c_cpp/fbcmd/ to (among other things) fetch some info back from info. for example, i use this command instead of fbwsname.sh:

$> fbcmd_osd.sh print ws_name

fbcmd_osd.sh contains nothing more but:

-+- fbcmd_osd.sh -----------------------------------------+-
\#!/bin/sh
pkill -9 -U `id -u` osd_cat  2>&1 > /dev/null
fbcmd $@ | osd_cat -a 1 -c "#d2efff" -s 2 -A center -o 30 &
-+--------------------------------------------------------+-

one can do evil stuff while combining tiny tools, i can tell you.

regards, akira