From 2755f856236acc05b1e860076931de7b0f5fba61 Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Fri, 15 Oct 2021 17:17:55 +0300 Subject: mpris-widget: remove some dead code the mpdarc widget is not really used and is a copy-paste leftover. The current widget has its own bindings already. --- mpris-widget/init.lua | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 7669b10..040c34c 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -16,8 +16,6 @@ local gears = require("gears") local GET_MPD_CMD = "playerctl -p %s -f '{{status}};{{xesam:artist}};{{xesam:title}};{{mpris:artUrl}}' metadata" local TOGGLE_MPD_CMD = "playerctl play-pause" -local PAUSE_MPD_CMD = "playerctl pause" -local STOP_MPD_CMD = "playerctl stop" local NEXT_MPD_CMD = "playerctl next" local PREV_MPD_CMD = "playerctl previous" local LIST_PLAYERS_CMD = "playerctl -l" @@ -201,25 +199,6 @@ local function worker() end end - mpdarc:connect_signal("button::press", function(_, _, _, button) - if (button == 1) then - awful.spawn(TOGGLE_MPD_CMD, false) -- left click - elseif (button == 2) then - awful.spawn(STOP_MPD_CMD, false) - elseif (button == 3) then - awful.spawn(PAUSE_MPD_CMD, false) - elseif (button == 4) then - awful.spawn(NEXT_MPD_CMD, false) -- scroll up - elseif (button == 5) then - awful.spawn(PREV_MPD_CMD, false) -- scroll down - end - - -- spawn.easy_async(string.format(GET_MPD_CMD, "'" .. default_player .. "'"), - -- function(stdout, stderr, exitreason, exitcode) - -- update_graphic(mpdarc, stdout, stderr, exitreason, exitcode) - -- end) - end) - mpris_widget:buttons( awful.util.table.join( awful.button({}, 3, function() -- cgit v1.2.3 From db0b3e9e8cbe54d1fe7a6c6b38e83366ae1c744d Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Fri, 15 Oct 2021 17:19:05 +0300 Subject: mpris-widget: fix incorrect boolean expression the loop is not meant to be executed if the player name is nil or '', so the expression needs to be an and. --- mpris-widget/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 040c34c..0dac632 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -73,7 +73,7 @@ local popup = awful.popup{ local function rebuild_popup() awful.spawn.easy_async(LIST_PLAYERS_CMD, function(stdout, _, _, _) for player_name in stdout:gmatch("[^\r\n]+") do - if player_name ~='' or player_name ~=nil then + if player_name ~='' and player_name ~=nil then for i = 0, #rows do rows[i]=nil end local checkbox = wibox.widget{ -- cgit v1.2.3 From c5852546ae2d7dfddc72526ca164073db86ae2db Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Fri, 15 Oct 2021 17:41:37 +0300 Subject: mpris-widget: correctly clean list of players Do it outside the loop, otherwise the last player wins. --- mpris-widget/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 0dac632..22fd0f7 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -72,9 +72,9 @@ local popup = awful.popup{ local function rebuild_popup() awful.spawn.easy_async(LIST_PLAYERS_CMD, function(stdout, _, _, _) + for i = 0, #rows do rows[i]=nil end for player_name in stdout:gmatch("[^\r\n]+") do if player_name ~='' and player_name ~=nil then - for i = 0, #rows do rows[i]=nil end local checkbox = wibox.widget{ { -- cgit v1.2.3 From 435d5d14f89d4a2ca4c8d190d4c6840f7063431d Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Fri, 15 Oct 2021 17:50:12 +0300 Subject: mpris-widget: fix api call there is no naughty.notification, notify returns a notification --- mpris-widget/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 22fd0f7..3d801ff 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -220,7 +220,7 @@ local function worker() local notification local function show_MPD_status() spawn.easy_async(GET_MPD_CMD, function() - notification = naughty.notification { + notification = naughty.notify { margin = 10, timeout = 5, hover_timeout = 0.5, -- cgit v1.2.3 From 588227cc1ad051b4e921a97271ed8e80456396a6 Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Fri, 15 Oct 2021 17:50:59 +0300 Subject: mpris-widget: rename mpdstatus to player_status --- mpris-widget/init.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 3d801ff..5bb5fc6 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -128,7 +128,7 @@ end local function worker() -- retrieve song info - local current_song, artist, mpdstatus, art, artUrl + local current_song, artist, player_status, art, artUrl local icon = wibox.widget { id = "icon", @@ -159,11 +159,10 @@ local function worker() } local update_graphic = function(widget, stdout, _, _, _) - -- mpdstatus, artist, current_song = stdout:match("(%w+)%;+(.-)%;(.*)") local words = {} for w in stdout:gmatch("([^;]*);") do table.insert(words, w) end - mpdstatus = words[1] + player_status = words[1] artist = words[2] current_song = words[3] art = words[4] @@ -175,19 +174,19 @@ local function worker() if art ~= nil then artUrl = string.sub(art, 8, -1) end - if mpdstatus == "Playing" then + if player_status == "Playing" then mpdarc_icon_widget.visible = true icon.image = PLAY_ICON_NAME widget.colors = {beautiful.widget_main_color} mpdarc_current_song_widget.markup = current_song widget:set_text(artist, current_song) - elseif mpdstatus == "Paused" then + elseif player_status == "Paused" then mpdarc_icon_widget.visible = true icon.image = PAUSE_ICON_NAME widget.colors = {beautiful.widget_main_color} mpdarc_current_song_widget.markup = current_song widget:set_text(artist, current_song) - elseif mpdstatus == "Stopped" then + elseif player_status == "Stopped" then mpdarc_icon_widget.visible = true icon.image = STOP_ICON_NAME mpdarc_current_song_widget.markup = "" @@ -226,7 +225,7 @@ local function worker() hover_timeout = 0.5, width = 240, height = 90, - title = "" .. mpdstatus .. "", + title = "" .. player_status .. "", text = current_song .. " by " .. artist, image = artUrl } -- cgit v1.2.3 From 2b829c72575bfd31aec5ad7606bc746025a9d027 Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Fri, 15 Oct 2021 18:18:30 +0300 Subject: mpris-widget: remove more dead code no need to update a widget that is never updated --- mpris-widget/init.lua | 9 --------- 1 file changed, 9 deletions(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 5bb5fc6..0f84161 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -152,11 +152,6 @@ local function worker() } local mpdarc_icon_widget = wibox.container.mirror(mpdarc, {horizontal = true}) - local mpdarc_current_song_widget = wibox.widget { - id = 'current_song', - widget = wibox.widget.textbox, - font = 'Play 10' - } local update_graphic = function(widget, stdout, _, _, _) local words = {} @@ -178,22 +173,18 @@ local function worker() mpdarc_icon_widget.visible = true icon.image = PLAY_ICON_NAME widget.colors = {beautiful.widget_main_color} - mpdarc_current_song_widget.markup = current_song widget:set_text(artist, current_song) elseif player_status == "Paused" then mpdarc_icon_widget.visible = true icon.image = PAUSE_ICON_NAME widget.colors = {beautiful.widget_main_color} - mpdarc_current_song_widget.markup = current_song widget:set_text(artist, current_song) elseif player_status == "Stopped" then mpdarc_icon_widget.visible = true icon.image = STOP_ICON_NAME - mpdarc_current_song_widget.markup = "" else -- no player is running icon.image = LIBRARY_ICON_NAME mpdarc_icon_widget.visible = false - mpdarc_current_song_widget.markup = "" widget.colors = {beautiful.widget_red} end end -- cgit v1.2.3 From aacbf61fac0e0a52ddd641699c373745de547c9f Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Fri, 15 Oct 2021 18:19:00 +0300 Subject: mpris-widget: enable notification on mouse enter use the right widget and it just works(TM). Changed the title to not have bold formatting, as it's already formatted and the was printed literally, changed the by to - as it looks nicer to me. --- mpris-widget/init.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 0f84161..0398951 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -208,7 +208,7 @@ local function worker() local notification - local function show_MPD_status() + local function show_status() spawn.easy_async(GET_MPD_CMD, function() notification = naughty.notify { margin = 10, @@ -216,17 +216,17 @@ local function worker() hover_timeout = 0.5, width = 240, height = 90, - title = "" .. player_status .. "", - text = current_song .. " by " .. artist, + title = player_status, + text = current_song .. " - " .. artist, image = artUrl } end) end - mpdarc:connect_signal("mouse::enter", function() - if current_song ~= nil and artist ~= nil then show_MPD_status() end + mpris_widget:connect_signal("mouse::enter", function() + if current_song ~= nil and artist ~= nil then show_status() end end) - mpdarc:connect_signal("mouse::leave", function() naughty.destroy(notification) end) + mpris_widget:connect_signal("mouse::leave", function() naughty.destroy(notification) end) watch(string.format(GET_MPD_CMD, "'" .. default_player .. "'"), 1, update_graphic, mpris_widget) -- cgit v1.2.3 From 567b5bb84fb0a572c30d72b09b3db195ca06a6bf Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Fri, 15 Oct 2021 18:34:09 +0300 Subject: mpris-widget: make play/pause icon work The middle part of mpris_widget was meant to be a play/pause icon. It only displayed a circle, as an unrelated widget that was not shown was set up and modified according to the play state. Delete the invisible widget, add the icon where it should be. --- mpris-widget/init.lua | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 0398951..74bb74e 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -28,12 +28,19 @@ local LIBRARY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/music-library.png" local default_player = '' +local icon = wibox.widget { + id = "icon", + widget = wibox.widget.imagebox, + image = PLAY_ICON_NAME +} + local mpris_widget = wibox.widget{ { id = 'artist', widget = wibox.widget.textbox }, { + icon, max_value = 1, value = 0, thickness = 2, @@ -130,29 +137,6 @@ local function worker() -- retrieve song info local current_song, artist, player_status, art, artUrl - local icon = wibox.widget { - id = "icon", - widget = wibox.widget.imagebox, - image = PLAY_ICON_NAME - } - local mirrored_icon = wibox.container.mirror(icon, {horizontal = true}) - - local mpdarc = wibox.widget { - mirrored_icon, - -- max_value = 1, - -- value = 0, - thickness = 2, - start_angle = 4.71238898, -- 2pi*3/4 - forced_height = 24, - forced_width = 24, - rounded_edge = true, - bg = "#ffffff11", - paddings = 0, - widget = wibox.container.arcchart - } - - local mpdarc_icon_widget = wibox.container.mirror(mpdarc, {horizontal = true}) - local update_graphic = function(widget, stdout, _, _, _) local words = {} for w in stdout:gmatch("([^;]*);") do table.insert(words, w) end @@ -170,21 +154,17 @@ local function worker() if art ~= nil then artUrl = string.sub(art, 8, -1) end if player_status == "Playing" then - mpdarc_icon_widget.visible = true icon.image = PLAY_ICON_NAME widget.colors = {beautiful.widget_main_color} widget:set_text(artist, current_song) elseif player_status == "Paused" then - mpdarc_icon_widget.visible = true icon.image = PAUSE_ICON_NAME widget.colors = {beautiful.widget_main_color} widget:set_text(artist, current_song) elseif player_status == "Stopped" then - mpdarc_icon_widget.visible = true icon.image = STOP_ICON_NAME else -- no player is running icon.image = LIBRARY_ICON_NAME - mpdarc_icon_widget.visible = false widget.colors = {beautiful.widget_red} end end -- cgit v1.2.3 From ca085289269122da468dd123edb8cd4a0144dc59 Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Fri, 15 Oct 2021 18:41:49 +0300 Subject: mpris-widget: correct artUrl Perhaps due to the regex change, or maybe it never did work, art was always nil. Use gears.string.split(), which works, is much easier to read than the regex and removes the need to munge the artUrl after too. --- mpris-widget/init.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index 74bb74e..c9fa723 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -135,24 +135,20 @@ end local function worker() -- retrieve song info - local current_song, artist, player_status, art, artUrl + local current_song, artist, player_status, artUrl local update_graphic = function(widget, stdout, _, _, _) - local words = {} - for w in stdout:gmatch("([^;]*);") do table.insert(words, w) end - + local words = gears.string.split(stdout, ';') player_status = words[1] artist = words[2] current_song = words[3] - art = words[4] + artUrl = words[4] if current_song ~= nil 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 player_status == "Playing" then icon.image = PLAY_ICON_NAME widget.colors = {beautiful.widget_main_color} -- cgit v1.2.3 From 4bc22fbb70fc50d402dacd3bdabbc2f405def9ff Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Sat, 16 Oct 2021 09:56:12 +0300 Subject: mpris-widget: delete on mouse::enter code this code is janky, because the notification is set asynchronously, it can end up not being cleaned by the mouse exit and then you can end up with multiple ones. Also, the image field of the table needs to be icon, but if the icon is an http url like some players print or even a local file like firefox does, setting the icon causes an error as it can't be read. --- mpris-widget/init.lua | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'mpris-widget/init.lua') diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua index c9fa723..5e45ffa 100644 --- a/mpris-widget/init.lua +++ b/mpris-widget/init.lua @@ -7,13 +7,11 @@ ------------------------------------------------- local awful = require("awful") local beautiful = require("beautiful") -local spawn = require("awful.spawn") local watch = require("awful.widget.watch") local wibox = require("wibox") -local naughty = require("naughty") local gears = require("gears") -local GET_MPD_CMD = "playerctl -p %s -f '{{status}};{{xesam:artist}};{{xesam:title}};{{mpris:artUrl}}' metadata" +local GET_MPD_CMD = "playerctl -p %s -f '{{status}};{{xesam:artist}};{{xesam:title}}' metadata" local TOGGLE_MPD_CMD = "playerctl play-pause" local NEXT_MPD_CMD = "playerctl next" @@ -135,14 +133,13 @@ end local function worker() -- retrieve song info - local current_song, artist, player_status, artUrl + local current_song, artist, player_status local update_graphic = function(widget, stdout, _, _, _) local words = gears.string.split(stdout, ';') player_status = words[1] artist = words[2] current_song = words[3] - artUrl = words[4] if current_song ~= nil then if string.len(current_song) > 18 then current_song = string.sub(current_song, 0, 9) .. ".." @@ -181,29 +178,6 @@ local function worker() ) ) - - - local notification - local function show_status() - spawn.easy_async(GET_MPD_CMD, function() - notification = naughty.notify { - margin = 10, - timeout = 5, - hover_timeout = 0.5, - width = 240, - height = 90, - title = player_status, - text = current_song .. " - " .. artist, - image = artUrl - } - end) - end - - mpris_widget:connect_signal("mouse::enter", function() - if current_song ~= nil and artist ~= nil then show_status() end - end) - mpris_widget:connect_signal("mouse::leave", function() naughty.destroy(notification) end) - watch(string.format(GET_MPD_CMD, "'" .. default_player .. "'"), 1, update_graphic, mpris_widget) return mpris_widget -- cgit v1.2.3