@@ -11,14 +11,6 @@ local watch = require("awful.widget.watch")
11
11
local wibox = require (" wibox" )
12
12
local gears = require (" gears" )
13
13
14
- local PATH_TO_ICONS = " /usr/share/icons/Adwaita"
15
- local PAUSE_ICON_NAME = PATH_TO_ICONS .. " /symbolic/actions/media-playback-pause-symbolic.svg"
16
- local PLAY_ICON_NAME = PATH_TO_ICONS .. " /symbolic/actions/media-playback-start-symbolic.svg"
17
- local STOP_ICON_NAME = PATH_TO_ICONS .. " /symbolic/actions/media-playback-stop-symbolic.svg"
18
- local LIBRARY_ICON_NAME = PATH_TO_ICONS .. " /symbolic/places/folder-music-symbolic.svg"
19
-
20
- local FONT = ' Roboto Condensed 16px'
21
-
22
14
local playerctl = {
23
15
player_name = ' mpv' ,
24
16
}
@@ -44,18 +36,19 @@ function playerctl:watch(timeout, callback, widget)
44
36
local cb = function (widget , stdout , _ , _ , _ )
45
37
local words = gears .string .split (stdout , ' ;' )
46
38
47
- local progress
48
- if words [5 ] ~= nil and words [6 ] ~= nil then
49
- progress = tonumber (words [5 ]) / tonumber (words [6 ])
39
+ local position , length , progress = tonumber (words [5 ]), tonumber (words [6 ])
40
+
41
+ if position ~= nil and length ~= nil then
42
+ progress = position / length
50
43
end
51
44
52
45
local metadata = {
53
46
status = words [1 ],
54
47
artist = words [2 ],
55
48
current_song = words [3 ],
56
49
art_url = words [4 ],
57
- position = words [ 5 ] ,
58
- length = words [ 6 ] ,
50
+ position = position ,
51
+ length = length ,
59
52
album = words [7 ],
60
53
progress = progress ,
61
54
}
@@ -78,61 +71,6 @@ function playerctl:prev()
78
71
awful .spawn (self :cmd (" previous" ), false )
79
72
end
80
73
81
- local icon = wibox .widget {
82
- id = " icon" ,
83
- widget = wibox .widget .imagebox ,
84
- image = PLAY_ICON_NAME
85
- }
86
-
87
- local progress_widget = wibox .widget {
88
- id = ' progress' ,
89
- widget = wibox .container .arcchart ,
90
- icon ,
91
- min_value = 0 ,
92
- max_value = 1 ,
93
- value = 0 ,
94
- thickness = 2 ,
95
- start_angle = 4.71238898 , -- 2pi*3/4
96
- forced_height = 24 ,
97
- forced_width = 24 ,
98
- rounded_edge = true ,
99
- bg = " #ffffff11" ,
100
- paddings = 2 ,
101
- }
102
-
103
- local artist_widget = wibox .widget {
104
- id = ' artist' ,
105
- font = FONT ,
106
- widget = wibox .widget .textbox
107
- }
108
-
109
- local title_widget = wibox .widget {
110
- id = ' title' ,
111
- font = FONT ,
112
- widget = wibox .widget .textbox
113
- }
114
-
115
- local mpris_widget = wibox .widget {
116
- artist_widget ,
117
- progress_widget ,
118
- title_widget ,
119
- spacing = 4 ,
120
- layout = wibox .layout .fixed .horizontal ,
121
- }
122
-
123
- local cover_art_widget = wibox .widget {
124
- widget = wibox .widget .imagebox ,
125
- forced_height = 0 ,
126
- forced_width = 300 ,
127
- resize_allowed = true ,
128
- }
129
-
130
- local metadata_widget = wibox .widget {
131
- widget = wibox .widget .textbox ,
132
- font = FONT ,
133
- forced_height = 100 ,
134
- forced_width = 300 ,
135
- }
136
74
137
75
local player_selector_popup = {
138
76
popup = awful .popup {
@@ -198,8 +136,9 @@ function player_selector_popup:add_radio_button(player_name)
198
136
end
199
137
200
138
function player_selector_popup :rebuild ()
201
- self .rows = { layout = wibox .layout .fixed .vertical }
202
139
awful .spawn .easy_async (" playerctl -l" , function (stdout , _ , _ , _ )
140
+ for i = 0 , # self .rows do self .rows [i ] = nil end
141
+
203
142
for name in stdout :gmatch (" [^\r\n ]+" ) do
204
143
if name ~= ' ' and name ~= nil then
205
144
self :add_radio_button (name )
@@ -221,18 +160,87 @@ function player_selector_popup:toggle()
221
160
end
222
161
223
162
local function duration (microseconds )
224
- local seconds = microseconds / 1000000
225
- local minutes = seconds / 60
226
- seconds = seconds % 60
227
- local hours = minutes / 60
228
- minutes = minutes % 60
163
+ if microseconds == nil then
164
+ return " --:--"
165
+ end
166
+
167
+ local seconds = math.floor (microseconds / 1000000 )
168
+ local minutes = math.floor (seconds / 60 )
169
+ seconds = seconds - minutes * 60
170
+ local hours = math.floor (minutes / 60 )
171
+ minutes = minutes - hours * 60
229
172
if hours >= 1 then
230
- return string.format (" %.f:%02.f:%02.f " , hours , minutes , seconds )
173
+ return string.format (" %d:%02d:%02d " , hours , minutes , seconds )
231
174
end
232
- return string.format (" %.f:%02.f " , minutes , seconds )
175
+ return string.format (" %d:%02d " , minutes , seconds )
233
176
end
234
177
235
- local function worker ()
178
+ local mpris_widget = {}
179
+
180
+ local function worker (user_args )
181
+ local args = user_args or {}
182
+
183
+ local font = args .font or ' Roboto Condensed 16px'
184
+
185
+ local path_to_icons = " /usr/share/icons/Adwaita"
186
+
187
+ local pause_icon = args .pause_icon or path_to_icons .. " /symbolic/actions/media-playback-pause-symbolic.svg"
188
+ local play_icon = args .play_icon or path_to_icons .. " /symbolic/actions/media-playback-start-symbolic.svg"
189
+ local stop_icon = args .stop_icon or path_to_icons .. " /symbolic/actions/media-playback-stop-symbolic.svg"
190
+ local library_icon = args .library_icon or path_to_icons .. " /symbolic/places/folder-music-symbolic.svg"
191
+
192
+ local icon = wibox .widget {
193
+ widget = wibox .widget .imagebox ,
194
+ image = play_icon
195
+ }
196
+
197
+ local progress_widget = wibox .widget {
198
+ widget = wibox .container .arcchart ,
199
+ icon ,
200
+ min_value = 0 ,
201
+ max_value = 1 ,
202
+ value = 0 ,
203
+ thickness = 2 ,
204
+ start_angle = 4.71238898 , -- 2pi*3/4
205
+ forced_height = 24 ,
206
+ forced_width = 24 ,
207
+ rounded_edge = true ,
208
+ bg = " #ffffff11" ,
209
+ paddings = 2 ,
210
+ }
211
+
212
+ local artist_widget = wibox .widget {
213
+ font = font ,
214
+ widget = wibox .widget .textbox
215
+ }
216
+
217
+ local title_widget = wibox .widget {
218
+ font = font ,
219
+ widget = wibox .widget .textbox
220
+ }
221
+
222
+ mpris_widget = wibox .widget {
223
+ artist_widget ,
224
+ progress_widget ,
225
+ title_widget ,
226
+ spacing = 4 ,
227
+ layout = wibox .layout .fixed .horizontal ,
228
+ }
229
+
230
+ local cover_art_widget = wibox .widget {
231
+ widget = wibox .widget .imagebox ,
232
+ forced_height = 0 ,
233
+ forced_width = 300 ,
234
+ resize_allowed = true ,
235
+ }
236
+
237
+ local metadata_widget = wibox .widget {
238
+ widget = wibox .widget .textbox ,
239
+ font = font ,
240
+ forced_height = 100 ,
241
+ forced_width = 300 ,
242
+ }
243
+
236
244
local update_metadata = function (meta )
237
245
artist_widget :set_text (meta .artist )
238
246
title_widget :set_text (meta .current_song )
@@ -260,17 +268,17 @@ local function worker()
260
268
end
261
269
262
270
if metadata .status == " Playing" then
263
- icon .image = PLAY_ICON_NAME
271
+ icon .image = play_icon
264
272
widget .colors = { beautiful .widget_main_color }
265
273
update_metadata (metadata )
266
274
elseif metadata .status == " Paused" then
267
- icon .image = PAUSE_ICON_NAME
275
+ icon .image = pause_icon
268
276
widget .colors = { beautiful .widget_main_color }
269
277
update_metadata (metadata )
270
278
elseif metadata .status == " Stopped" then
271
- icon .image = STOP_ICON_NAME
279
+ icon .image = stop_icon
272
280
else -- no player is running
273
- icon .image = LIBRARY_ICON_NAME
281
+ icon .image = library_icon
274
282
widget .colors = { beautiful .widget_red }
275
283
end
276
284
end
0 commit comments