summaryrefslogtreecommitdiff
path: root/mpris-widget
diff options
context:
space:
mode:
authorgaberm <gaberm@gmail.com>2020-11-25 23:11:32 +0200
committergaberm <gaberm@gmail.com>2020-11-25 23:11:32 +0200
commit062a6d77628647d26a92126a3484907115e7fa3b (patch)
treef7496889ece2d936e983aaa1673ffef87bb26601 /mpris-widget
parentb454f198cfb98afa63bedb18e9ff10a822289021 (diff)
Added image icon for streaming from firefox
Diffstat (limited to 'mpris-widget')
-rw-r--r--mpris-widget/init.lua39
1 files changed, 26 insertions, 13 deletions
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 = "<b>" .. mpdstatus .. "</b>",
+ text = current_song .. " <b>by</b> " .. 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})