summaryrefslogtreecommitdiff
path: root/mpdarc-widget/mpdarc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'mpdarc-widget/mpdarc.lua')
-rw-r--r--mpdarc-widget/mpdarc.lua27
1 files changed, 23 insertions, 4 deletions
diff --git a/mpdarc-widget/mpdarc.lua b/mpdarc-widget/mpdarc.lua
index 56009ef..ca0f411 100644
--- a/mpdarc-widget/mpdarc.lua
+++ b/mpdarc-widget/mpdarc.lua
@@ -14,6 +14,7 @@ local wibox = require("wibox")
local naughty = require("naughty")
local GET_MPD_CMD = "mpc status"
+local TOGGLE_MPD_CMD = "mpc toggle"
local PAUSE_MPD_CMD = "mpc pause"
local STOP_MPD_CMD = "mpc stop"
local NEXT_MPD_CMD = "mpc next"
@@ -45,9 +46,15 @@ local mpdarc = wibox.widget {
widget = wibox.container.arcchart
}
-local mpdarc_widget = wibox.container.mirror(mpdarc, { horizontal = true })
+local mpdarc_icon_widget = wibox.container.mirror(mpdarc, { horizontal = true })
+local mpdarc_current_song_widget = wibox.widget {
+ id = 'current_song',
+ widget = wibox.widget.textbox,
+ font = 'Play 9'
+}
local update_graphic = function(widget, stdout, _, _, _)
+ local current_song = string.gmatch(stdout, "[^\r\n]+")()
stdout = string.gsub(stdout, "\n", "")
local mpdpercent = string.match(stdout, "(%d%d)%%")
local mpdstatus = string.match(stdout, "%[(%a+)%]")
@@ -55,18 +62,25 @@ local update_graphic = function(widget, stdout, _, _, _)
icon.image = PLAY_ICON_NAME
widget.colors = { beautiful.widget_main_color }
widget.value = tonumber((100-mpdpercent)/100)
- elseif mpdstatus == "paused" then
+ mpdarc_current_song_widget.markup = current_song
+ elseif mpdstatus == "paused" then
icon.image = PAUSE_ICON_NAME
widget.colors = { beautiful.widget_main_color }
widget.value = tonumber(mpdpercent/100)
+ mpdarc_current_song_widget.markup = current_song
else
icon.image = STOP_ICON_NAME
- widget.colors = { beautiful.widget_red }
+ if string.len(stdout) == 0 then -- MPD is not running
+ mpdarc_current_song_widget.markup = "MPD is not running"
+ else
+ widget.colors = { beautiful.widget_red }
+ mpdarc_current_song_widget.markup = ""
+ end
end
end
mpdarc:connect_signal("button::press", function(_, _, _, button)
- if (button == 1) then awful.spawn("mpc toggle", false) -- left click
+ if (button == 1) then awful.spawn(TOGGLE_MPD_CMD, false) -- left click
elseif (button == 2) then awful.spawn(STOP_MPD_CMD, false)
elseif (button == 3) then awful.spawn(PAUSE_MPD_CMD, false)
elseif (button == 4) then awful.spawn(NEXT_MPD_CMD, false) -- scroll up
@@ -97,4 +111,9 @@ mpdarc:connect_signal("mouse::leave", function() naughty.destroy(notification) e
watch(GET_MPD_CMD, 1, update_graphic, mpdarc)
+local mpdarc_widget = {
+ mpdarc_icon_widget,
+ mpdarc_current_song_widget,
+ layout = wibox.layout.align.horizontal,
+ }
return mpdarc_widget