local mpc = require("widgets/mpc")
local textbox = require("wibox.widget.textbox")
+local gears = require("gears")
+local awful = require("awful")
+local naughty = require("naughty")
local timer = require("gears.timer")
+--TODO remove
+local dbg = require("gears.debug")
+
mpd_widget = textbox()
local function update_widget()
, awful.button({}, 5, function() connection:change_volume(-5) end))
)
+local function sec_to_min(sec)
+ m, s = math.modf((sec or 0.0) / 60)
+ return string.format('%d:%02d', m, math.floor(s * 60))
+end
+
+local function song_duration(elapsed, duration)
+ return sec_to_min(elapsed) .. "/" .. sec_to_min(duration)
+end
+
+local function get_info(callback)
+ local status = nil
+ connection:send("status", function(_, s) status = s end)
+
+ local song = nil
+ connection:send("currentsong", function(_, s) song = s end)
+
+ timer.start_new(0.10, function()
+ if status == nil or song == nil then return true end
+
+ dbg.dump(status)
+ dbg.dump(song)
+
+ local info = {}
+ info.title = status.state .. " " .. status.song .. "/" .. status.playlistlength .. " " .. song_duration(status.elapsed, status.duration)
+ info.text = tostring(song.artist or "") .. " - " .. tostring(song.title or "") .. "\n"
+ .. tostring(song.album or "")
+ callback(info)
+ return false
+ end)
+end
+
+local popup = {}
+function popup:show()
+ get_info(function(table)
+ if self._notification ~= nil then return end
+ self._notification = naughty.notify(
+ { title = table.title
+ -- , icon = img
+ , text = table.text
+ , timeout = 0
+ })
+ end)
+end
+
+function popup:hide()
+ if self._notification ~= nil then
+ naughty.destroy(self._notification)
+ self._notification = nil
+ end
+end
+
+function popup:update()
+ get_info(function(table)
+ if self._notification == nil then return end
+ naughty.replace_text(self._notification, table.title, table.text)
+ end)
+end
+
+function popup:run()
+ self._timer = timer({ timeout = 1 })
+ self._timer:connect_signal("start", function() self:show() end)
+ self._timer:connect_signal("timeout", function() self:update() end)
+ self._timer:connect_signal("stop", function() self:hide() end) --TODO delay
+
+ mpd_widget:connect_signal("mouse::enter", function() self._timer:again() end)
+ mpd_widget:connect_signal("mouse::leave", function() self._timer:stop() end)
+end
+
+popup:run()
+
globalkeys = gears.table.join(globalkeys,
awful.key({ modkey }, "p", function() connection:toggle_play() end,
{ description = "toogle play", group = "mpd" }),