Add more functions for cmus widget

This commit is contained in:
Augusto Gunsch 2022-07-10 20:59:28 +02:00
parent 83914c91c8
commit 12cfe038f8
2 changed files with 31 additions and 6 deletions

View File

@ -31,10 +31,11 @@ s.mytasklist, -- Middle widget
To improve responsiveness of the widget when playback is changed by a shortcut use corresponding methods of the widget: To improve responsiveness of the widget when playback is changed by a shortcut use corresponding methods of the widget:
```lua ```lua
awful.key({ modkey, "Shift" }, awful.key({ modkey, "Shift" }, "p", function () cmus_widget:play_pause() end, {description = "toggle track", group = "cmus"}),
"p", awful.key({ }, "XF86AudioPlay", function () cmus_widget:play() end, {description = "play track", group = "cmus"}),
function() cmus_widget:play_pause() end, awful.key({ }, "XF86AudioPause", function () cmus_widget:play() end, {description = "pause track", group = "cmus"}),
{description = "play/pause cmus", group = "custom"}), awful.key({ }, "XF86AudioNext", function () cmus_widget:next_track() end, {description = "next track", group = "cmus"}),
awful.key({ }, "XF86AudioPrev", function () cmus_widget:prev_track() end, {description = "previous track", group = "cmus"}),
``` ```
## Customization ## Customization

View File

@ -96,14 +96,38 @@ local function worker(user_args)
end end
end end
function cmus_widget:play_pause() function cmus_widget:update()
spawn("cmus-remote -u")
spawn.easy_async("cmus-remote -Q", spawn.easy_async("cmus-remote -Q",
function(stdout, _, _, code) function(stdout, _, _, code)
update_widget(cmus_widget.widget, stdout, _, _, code) update_widget(cmus_widget.widget, stdout, _, _, code)
end) end)
end end
function cmus_widget:play_pause()
spawn("cmus-remote -u")
cmus_widget.update()
end
function cmus_widget:pause()
spawn("cmus-remote -u")
cmus_widget.update()
end
function cmus_widget:play()
spawn("cmus-remote -u")
cmus_widget.update()
end
function cmus_widget:next_track()
spawn("cmus-remote -u")
cmus_widget.update()
end
function cmus_widget:prev_track()
spawn("cmus-remote -u")
cmus_widget.update()
end
cmus_widget.widget:buttons( cmus_widget.widget:buttons(
awful.util.table.join( awful.util.table.join(
awful.button({}, 1, function() cmus_widget:play_pause() end) awful.button({}, 1, function() cmus_widget:play_pause() end)