From 062a6d77628647d26a92126a3484907115e7fa3b Mon Sep 17 00:00:00 2001 From: gaberm Date: Wed, 25 Nov 2020 23:11:32 +0200 Subject: Added image icon for streaming from firefox --- mpris-widget/init.lua | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'mpris-widget') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 5144ea8..5af85b4 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -32,7 +32,7 @@ local mpdarc_widget = {} local function worker(args) -- retriving song info - local current_song, artist, mpdstatus + local current_song, artist, mpdstatus, art, artUrl local icon = wibox.widget { id = "icon", @@ -55,7 +55,8 @@ local function worker(args) widget = wibox.container.arcchart } - local mpdarc_icon_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, @@ -63,13 +64,22 @@ local function worker(args) } local update_graphic = function(widget, stdout, _, _, _) - mpdstatus, artist, current_song = stdout:match("(%w+)%;+(.-)%;(.*)") + -- mpdstatus, artist, current_song = stdout:match("(%w+)%;+(.-)%;(.*)") + local words = {} + for w in stdout:gmatch("([^;]*)") do table.insert(words, w) end + + mpdstatus = words[1] + artist = words[2] + current_song = words[3] + art = words[4] if current_song ~= nil then - if current_song.len == 18 then + if string.len(current_song) > 18 then current_song = string.sub(current_song, 0, 9) .. ".." end end + if art ~= nil then artUrl = string.sub(art, 8, -1) end + if mpdstatus == "Playing" then mpdarc_icon_widget.visible = true icon.image = PLAY_ICON_NAME @@ -105,7 +115,8 @@ local function worker(args) awful.spawn(PREV_MPD_CMD, false) -- scroll down end - spawn.easy_async(GET_MPD_CMD, function(stdout, stderr, exitreason, exitcode) + spawn.easy_async(GET_MPD_CMD, + function(stdout, stderr, exitreason, exitcode) update_graphic(mpdarc, stdout, stderr, exitreason, exitcode) end) end) @@ -113,12 +124,15 @@ local function worker(args) local notification local function show_MPD_status() spawn.easy_async(GET_MPD_CMD, function(stdout, _, _, _) - notification = naughty.notify { - text = current_song .. " by " .. artist, - title = mpdstatus, + notification = naughty.notification { + margin = 10, timeout = 5, hover_timeout = 0.5, - width = 600 + width = 240, + height = 90, + title = "" .. mpdstatus .. "", + text = current_song .. " by " .. artist, + image = artUrl } end) end @@ -127,7 +141,7 @@ local function worker(args) if current_song ~= nil and artist ~= nil then show_MPD_status() end end) mpdarc:connect_signal("mouse::leave", - function() naughty.destroy(notification) end) + function() naughty.destroy(notification) end) watch(GET_MPD_CMD, 1, update_graphic, mpdarc) @@ -141,6 +155,5 @@ local function worker(args) end -return setmetatable(mpdarc_widget, { __call = function(_, ...) - return worker(...) -end }) \ No newline at end of file +return setmetatable(mpdarc_widget, + {__call = function(_, ...) return worker(...) end}) -- cgit v1.2.3