combine pause/unpause and play

Today, I built a music control widget for awesome (a very nice tiling window manager, btw) and ran into some problems, when I tried to combine a play/pause button that shows ">" when moc is stopped or paused and '||' when it's playing. moc should start playing or unpause if '>' is clicked and pause if '||' is clicked.

The problem is, that there is no single command line switch for this behavior. Using mocp -p restarts the song over on every click and mocp -G doesn't start playing if stopped.

This could be overcome easily with a small external script parsing mocp -i. However I checked the source and it's really easy to do:


--- moc-2.5.0-alpha3/main.c
+++ moc-2.5.0-alpha3-hacked/main.c
@@ -373,7 +373,9 @@
|| !get_int(sock, &state))
fatal ("Can't get data from the server");

- if (state == STATE_PAUSE)
+ if (state == STATE_STOP)
+ interface_cmdline_play_first(sock);
+ else if (state == STATE_PAUSE)
cmd = CMD_UNPAUSE;
else if (state == STATE_PLAY)
cmd = CMD_PAUSE;

It's really just a small hack, but it saved my day. I guess not everybody wants toggle-pause behave that way, but if there are some, maybe this helps.

Thank you, i will try implement it here too. Nice hack!