Skip to content

Commit d8376f7

Browse files
committed
minor improvements
1 parent 484eb68 commit d8376f7

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

mpris-widget/init.lua

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ local PLAY_ICON_NAME = PATH_TO_ICONS .. "/symbolic/actions/media-playback-sta
2424
local STOP_ICON_NAME = PATH_TO_ICONS .. "/symbolic/actions/media-playback-stop-symbolic.svg"
2525
local LIBRARY_ICON_NAME = PATH_TO_ICONS .. "/symbolic/places/folder-music-symbolic.svg"
2626

27-
local FONT = 'Roboto Mono 18px'
27+
local FONT = 'Roboto Condensed 16px'
2828

2929
local default_player = 'mpv'
3030

@@ -72,13 +72,14 @@ local mpris_widget = wibox.widget {
7272

7373
local cover_art_widget = wibox.widget {
7474
widget = wibox.widget.imagebox,
75-
forced_height = 300,
75+
forced_height = 0,
7676
forced_width = 300,
7777
resize_allowed = true,
7878
}
7979

8080
local metadata_widget = wibox.widget {
8181
widget = wibox.widget.textbox,
82+
font = FONT,
8283
forced_height = 100,
8384
forced_width = 300,
8485
}
@@ -162,12 +163,19 @@ local function update_metadata(artist, current_song, progress, art_url)
162163
-- poor man's urldecode
163164
art_url = art_url:gsub("file://", "/")
164165
art_url = art_url:gsub("%%(%x%x)", function(x) return string.char(tonumber(x, 16)) end)
165-
cover_art_widget:set_image(art_url)
166+
167+
if art_url ~= nil and art_url ~= "" then
168+
cover_art_widget.image = art_url
169+
cover_art_widget.forced_height = 300
170+
else
171+
cover_art_widget.image = nil
172+
cover_art_widget.forced_height = 0
173+
end
166174
end
167175

168176
local function worker()
169177
-- retrieve song info
170-
local current_song, artist, player_status, art_url
178+
local current_song, artist, player_status, art_url, progress
171179

172180
local update_graphic = function(widget, stdout, _, _, _)
173181
local words = gears.string.split(stdout, ';')
@@ -178,20 +186,24 @@ local function worker()
178186
art_url = words[4]
179187

180188
if current_song ~= nil then
181-
if string.len(current_song) > 30 then
182-
current_song = string.sub(current_song, 0, 28) .. ".."
189+
if string.len(current_song) > 40 then
190+
current_song = string.sub(current_song, 0, 38) .. ""
183191
end
184192
end
185193

186194
if player_status == "Playing" then
187195
icon.image = PLAY_ICON_NAME
188196
widget.colors = { beautiful.widget_main_color }
189-
progress = tonumber(words[5]) / tonumber(words[6])
197+
if words[5] ~= nil and words[6] ~= nil then
198+
progress = tonumber(words[5]) / tonumber(words[6])
199+
end
190200
update_metadata(artist, current_song, progress, art_url)
191201
elseif player_status == "Paused" then
192202
icon.image = PAUSE_ICON_NAME
193203
widget.colors = { beautiful.widget_main_color }
194-
progress = tonumber(words[5]) / tonumber(words[6])
204+
if words[5] ~= nil and words[6] ~= nil then
205+
progress = tonumber(words[5]) / tonumber(words[6])
206+
end
195207
update_metadata(artist, current_song, progress, art_url)
196208
elseif player_status == "Stopped" then
197209
icon.image = STOP_ICON_NAME

0 commit comments

Comments
 (0)