+end
+
+function widget:popup_update()
+ self:get_info(function(table)
+ if not self._notification then return end
+ naughty.replace_text(self._notification, table.title, table.text)
+ end)
+end
+
+function widget:popup_oneshot(timeout)
+ if self._notification then
+ self:popup_update()
+ self:popup_hide(5)
+ else
+ self:popup_show()
+ self:popup_hide(5)
+ end
+end
+
+function widget:error_handler(err)
+ self._textbox:set_text("Error: " .. tostring(err))
+ timer.start_new(10, function()
+ self._connection:send("ping")
+ end)
+end
+
+function widget:run()
+ self._connection = mpc.new(nil, nil, nil, function(err) self:error_handler(err) end,
+ "status", function(_, result)
+ if not self._status or result.state ~= self._status.state then
+ self._status = result
+ self:update_widget()
+ self:popup_oneshot(5)
+ end
+ end,
+ "currentsong", function(_, result)
+ if not self._currentsong or result.id ~= self._currentsong.id then
+ self._currentsong = result
+ self:update_widget()
+ self:popup_oneshot(5)
+ end
+ end
+ )
+
+ self._timer = timer({ timeout = 1 })
+ self._timer:connect_signal("timeout", function() self:popup_update() end)
+
+ self._hover = false;
+ self.scroll:connect_signal("mouse::enter", function() self._hover = true; self:popup_show() end)
+ self.scroll:connect_signal("mouse::leave", function() self._hover = false; self:popup_hide(2) end)
+end
+
+widget:run()