All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2014, anticlockwise <http://github.com/anticlockwise>
9 local helpers = require("lain.helpers")
10 local async = require("lain.asyncshell")
12 local escape_f = require("awful.util").escape
13 local naughty = require("naughty")
14 local wibox = require("wibox")
16 local io = { popen = io.popen }
17 local os = { execute = os.execute,
19 local string = { format = string.format,
20 gmatch = string.gmatch }
22 local setmetatable = setmetatable
25 -- lain.widgets.contrib.moc
28 local function worker(args)
29 local args = args or {}
30 local timeout = args.timeout or 2
31 local music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
32 local cover_size = args.cover_size or 100
33 local default_art = args.default_art or ""
34 local followmouse = args.followmouse or false
35 local settings = args.settings or function() end
37 local mpdcover = helpers.scripts_dir .. "mpdcover"
39 moc.widget = wibox.widget.textbox('')
41 moc_notification_preset = {
42 title = "Now playing",
46 helpers.set_map("current moc track", nil)
49 -- mocp -i will produce output like:
53 async.request("mocp -i", function(f)
64 for line in string.gmatch(f, "[^\n]+") do
65 for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
66 if k == "State" then moc_now.state = v
67 elseif k == "File" then moc_now.file = v
68 elseif k == "Artist" then moc_now.artist = escape_f(v)
69 elseif k == "SongTitle" then moc_now.title = escape_f(v)
70 elseif k == "Album" then moc_now.album = escape_f(v)
71 elseif k == "CurrentTime" then moc_now.elapsed = escape_f(v)
72 elseif k == "TotalTime" then moc_now.total = escape_f(v)
77 moc_notification_preset.text = string.format("%s (%s) - %s\n%s", moc_now.artist,
78 moc_now.album, moc_now.total, moc_now.title)
82 if moc_now.state == "PLAY" then
83 if moc_now.title ~= helpers.get_map("current moc track") then
84 helpers.set_map("current moc track", moc_now.title)
85 os.execute(string.format("%s %q %q %d %q", mpdcover, "",
86 moc_now.file, cover_size, default_art))
89 moc_notification_preset.screen = mouse.screen
92 moc.id = naughty.notify({
93 preset = moc_notification_preset,
94 icon = "/tmp/mpdcover.png",
98 elseif moc_now.state ~= "PAUSE" then
99 helpers.set_map("current moc track", nil)
104 helpers.newtimer("moc", timeout, moc.update)
106 return setmetatable(moc, { __index = moc.widget })
109 return setmetatable(moc, { __call = function(_, ...) return worker(...) end })