From 12cfe038f87b2f8366e9865135087a61b5a3c2c0 Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Sun, 10 Jul 2022 20:59:28 +0200 Subject: Add more functions for cmus widget --- cmus-widget/README.md | 9 +++++---- cmus-widget/cmus.lua | 28 ++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'cmus-widget') diff --git a/cmus-widget/README.md b/cmus-widget/README.md index eec5773..0f6dbc2 100644 --- a/cmus-widget/README.md +++ b/cmus-widget/README.md @@ -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: ```lua -awful.key({ modkey, "Shift" }, - "p", - function() cmus_widget:play_pause() end, - {description = "play/pause cmus", group = "custom"}), +awful.key({ modkey, "Shift" }, "p", function () cmus_widget:play_pause() end, {description = "toggle track", group = "cmus"}), +awful.key({ }, "XF86AudioPlay", function () cmus_widget:play() end, {description = "play track", group = "cmus"}), +awful.key({ }, "XF86AudioPause", function () cmus_widget:play() end, {description = "pause track", group = "cmus"}), +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 diff --git a/cmus-widget/cmus.lua b/cmus-widget/cmus.lua index 2ffa872..d676550 100644 --- a/cmus-widget/cmus.lua +++ b/cmus-widget/cmus.lua @@ -96,14 +96,38 @@ local function worker(user_args) end end - function cmus_widget:play_pause() - spawn("cmus-remote -u") + function cmus_widget:update() spawn.easy_async("cmus-remote -Q", function(stdout, _, _, code) update_widget(cmus_widget.widget, stdout, _, _, code) 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( awful.util.table.join( awful.button({}, 1, function() cmus_widget:play_pause() end) -- cgit v1.2.3 From d9c689d73383debb4e7277285dab85427eb356b5 Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Sun, 10 Jul 2022 21:04:15 +0200 Subject: Add stop function --- cmus-widget/README.md | 11 ++++++----- cmus-widget/cmus.lua | 13 +++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'cmus-widget') diff --git a/cmus-widget/README.md b/cmus-widget/README.md index 0f6dbc2..e33655e 100644 --- a/cmus-widget/README.md +++ b/cmus-widget/README.md @@ -31,11 +31,12 @@ s.mytasklist, -- Middle widget To improve responsiveness of the widget when playback is changed by a shortcut use corresponding methods of the widget: ```lua -awful.key({ modkey, "Shift" }, "p", function () cmus_widget:play_pause() end, {description = "toggle track", group = "cmus"}), -awful.key({ }, "XF86AudioPlay", function () cmus_widget:play() end, {description = "play track", group = "cmus"}), -awful.key({ }, "XF86AudioPause", function () cmus_widget:play() end, {description = "pause track", group = "cmus"}), -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"}), +awful.key({ modkey, "Shift" }, "p", function () cmus_widget:play_pause() end, {description = "toggle track", group = "cmus"}), +awful.key({ }, "XF86AudioPlay", function () cmus_widget:play() end, {description = "play track", group = "cmus"}), +awful.key({ }, "XF86AudioPause", function () cmus_widget:play() end, {description = "pause track", group = "cmus"}), +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"}), +awful.key({ }, "XF86AudioStop", function () cmus_widget:stop() end, {description = "stop cmus", group = "cmus"}), ``` ## Customization diff --git a/cmus-widget/cmus.lua b/cmus-widget/cmus.lua index d676550..0c2fca2 100644 --- a/cmus-widget/cmus.lua +++ b/cmus-widget/cmus.lua @@ -109,22 +109,27 @@ local function worker(user_args) end function cmus_widget:pause() - spawn("cmus-remote -u") + spawn("cmus-remote -U") cmus_widget.update() end function cmus_widget:play() - spawn("cmus-remote -u") + spawn("cmus-remote -p") cmus_widget.update() end function cmus_widget:next_track() - spawn("cmus-remote -u") + spawn("cmus-remote -n") cmus_widget.update() end function cmus_widget:prev_track() - spawn("cmus-remote -u") + spawn("cmus-remote -p") + cmus_widget.update() + end + + function cmus_widget:stop() + spawn("cmus-remote -s") cmus_widget.update() end -- cgit v1.2.3 From e2e680c11ebdfa58d3bbd2741a70439417c2bef5 Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Sun, 10 Jul 2022 21:11:17 +0200 Subject: Fix prev command --- cmus-widget/cmus.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmus-widget') diff --git a/cmus-widget/cmus.lua b/cmus-widget/cmus.lua index 0c2fca2..b1287c5 100644 --- a/cmus-widget/cmus.lua +++ b/cmus-widget/cmus.lua @@ -124,7 +124,7 @@ local function worker(user_args) end function cmus_widget:prev_track() - spawn("cmus-remote -p") + spawn("cmus-remote -r") cmus_widget.update() end -- cgit v1.2.3