Xmms2 Widgets

How to control xmms2d through widgets
This article describes how to make a music player widget for xmms2. It contains play/pause, next and previous track buttons and displays artist - title of the current song. Preview

Requires:
 * awesome >= 2.1-rc1
 * awesome-client
 * xmms2 (daemon and default client)
 * these icons

Adjusting your .awesomerc

This is the part of my .awesomerc defining the widgets. I use a textbox for the status-display of xmms2d and iconboxes for the control buttons. As you can see I put the icons in ~/.config/awesome/icons/xmms2/, I suggest you to do it the same way, it is some standard and quite a good place for your awesome customizations. You can make your own icons of course, they have to be in .png format as far as I know. Remember that awesome will crash through clicking on a widget with a wrong image path.

textbox nowplaying { text = "-" #the - will be replaced by `xmms2 current` piped to awesome-client }       iconbox xmms2_prev { image = "/home/wakeup/.config/awesome/icons/xmms2/prev.png" #on left mouse button click xmms2 prev will be executed as if in a terminal mouse { button = "1" command = "spawn" arg = "xmms2 prev" }       }        iconbox xmms2_toggleplay { image = "/home/wakeup/.config/awesome/icons/xmms2/toggleplay.png" mouse { button = "1" command = "spawn" arg = "xmms2 toggleplay" }       }        iconbox xmms2_next { image = "/home/wakeup/.config/awesome/icons/xmms2/next.png" mouse { button = "1" command = "spawn" arg = "xmms2 next" }       }

Script to update "artist - title"

My update-script is located at ~/.config/awesome/scripts/nowplaying and of really simple nature. It is started through the following line in ~/.xinitrc

/home/wakeup/.config/awesome/scripts/nowplaying &

The script while true do       song=`xmms2 current` echo "0 widget_tell nowplaying $song" | /usr/local/bin/awesome-client #tells the textbox-widget mentioned above to display the output of `xmms2 current` sleep 3 done
 * 1) !/bin/bash

Another option for the script is to use. This script supports on-broadcast/signal messaging, so that you don't have to wait 3 seconds for a song update. It also handles changing the icon of the play/pause button depending on the playback state. It also includes (commented out) support for working with cover art and playtime.

Keyboard controls
I use my funky keyboard to control my player. So, all I had to do is add the following to rc.lua:

awful.key({}, "XF86AudioPlay", function awful.util.spawn_with_shell("nyxmms2 toggle") end), awful.key({}, "XF86AudioStop", function awful.util.spawn_with_shell("nyxmms2 stop") end), awful.key({}, "XF86AudioPrev", function awful.util.spawn_with_shell("nyxmms2 prev") end), awful.key({}, "XF86AudioNext", function awful.util.spawn_with_shell("nyxmms2 next") end)

and I can then use the media part of my Logitech Wave keyboard. Note that you may have to use xev and xmodmap to map the right key for your keyboard as the number will not be the same.

Dirty hack
For the status bar, I wanted a nice icon and the title which I ended up doing as:

nowplaying = widget({ type = "textbox" }) xmms2icon = widget({ type = "imagebox" }) xmms2icon.image = image(beautiful.widget_xmms2) xmms2icon:buttons(awful.util.table.join( awful.button({ }, 1, function awful.util.spawn_with_shell("~/bin/xmms2_status.sh") end) ))

where beautiful.widget_xmms2 is defined in my theme file and is the XMMS2 logo -- but you could change that to be whatever you liked. Finally, I wrote a small shell script to display the band and title based on the above code which works with newer versions of xmms2.

while true do    echo "nowplaying.text = \"`nyxmms2 status -f '${artist} - ${title}'`\"" | awesome-client sleep 5 done
 * 1) !/bin/bash

When the xmms2 icon is clicked, this shell script is run:

urxvt256c-ml -geometry 256x7 -tr -e nyxmms2 status -r 1
 * 1) !/bin/sh

which starts a shell with an interactive nyxmms2 session.

MPD Info
Note that you can use Donearm's | Mpd-Info script to display alerts that will show covert art and information about any new track played. This is much much much better than the ugly hack above. This is what you should use.