6 mpd.lua - wmiirc-lua plugin for monitoring and controlling mpd (music player daemon)
10 -- in your wmiirc.lua:
11 mpd = wmii.load_plugin("mpd")
16 For binding the mpd controls to the multimedia keys you could add
17 the following keyhandlers to your wmiirc.lua:
19 wmii.add_key_handler('XF86AudioNext', mpd.next_song())
21 wmii.add_key_handler('XF86AudioPrev', mpd.prev_song())
23 wmii.add_key_handler('XF86AudioPlay', mpd.toggle_pause())
25 wmii.add_key_handler('XF86AudioStop', mpd.stop())
33 Jan-David Quesel <jdq@gmx.net>
35 =head1 LICENCE AND COPYRIGHT
37 Copyright (c) 2008, Jan-David Quesel <jdq@gmx.net>
39 This is free software. You may redistribute copies of it under the terms of
40 the GNU General Public License L<http://www.gnu.org/licenses/gpl.html>. There
41 is NO WARRANTY, to the extent permitted by law.
45 local wmii
= require("wmii")
46 local io
= require("io")
47 local string = require("string")
52 -- ------------------------------------------------------------
53 -- Configuration Settings
54 wmii
.set_conf ("mpd.server", "127.0.0.1")
55 wmii
.set_conf ("mpd.port", "6600")
57 -- ------------------------------------------------------------
59 local widget
= wmii
.widget
:new ("301_mpd_status")
61 local function _command ( cmd
)
64 wmii
.log( "about to run " .. cmd
)
65 local file
= io
.popen( cmd
)
66 local status
= file
:read("*a")
69 return status
:match("[^\n]*")
75 local function update_mpd_status (time_since_update
)
76 local printout
= _command("export MPD_HOST=" .. wmii
.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii
.get_conf("mpd.port") .. " && mpc")
80 -- if we dont get a response from the server we test every 2 minutes
81 if printout
== nil or printout
== "" then
88 _command("export MPD_HOST=" .. wmii
.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii
.get_conf("mpd.port") .. " && mpc next")
93 _command("export MPD_HOST=" .. wmii
.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii
.get_conf("mpd.port") .. " && mpc prev")
97 function toggle_pause()
98 _command("export MPD_HOST=" .. wmii
.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii
.get_conf("mpd.port") .. " && mpc toggle")
103 _command("export MPD_HOST=" .. wmii
.get_conf("mpd.server") .. "&& export MPD_PORT=" .. wmii
.get_conf("mpd.port") .. " && mpc stop")
107 function register_action()
108 wmii
.add_action_handler ("mpd",
110 local actions
= { 'play', 'pause', 'stop', 'next', 'prev' }
111 local act
= wmii
.menu(actions
, "mpd: ")
112 local fn
= function_handlers
[act
]
114 local r
, err
= pcall (fn
)
119 local timer
= wmii
.timer
:new (update_mpd_status
, 1)