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.
This commit is contained in:
Romanos Skiadas 2021-10-16 09:56:12 +03:00
parent ca08528926
commit 4bc22fbb70
1 changed files with 2 additions and 28 deletions

View File

@ -7,13 +7,11 @@
------------------------------------------------- -------------------------------------------------
local awful = require("awful") local awful = require("awful")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local spawn = require("awful.spawn")
local watch = require("awful.widget.watch") local watch = require("awful.widget.watch")
local wibox = require("wibox") local wibox = require("wibox")
local naughty = require("naughty")
local gears = require("gears") 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 TOGGLE_MPD_CMD = "playerctl play-pause"
local NEXT_MPD_CMD = "playerctl next" local NEXT_MPD_CMD = "playerctl next"
@ -135,14 +133,13 @@ end
local function worker() local function worker()
-- retrieve song info -- retrieve song info
local current_song, artist, player_status, artUrl local current_song, artist, player_status
local update_graphic = function(widget, stdout, _, _, _) local update_graphic = function(widget, stdout, _, _, _)
local words = gears.string.split(stdout, ';') local words = gears.string.split(stdout, ';')
player_status = words[1] player_status = words[1]
artist = words[2] artist = words[2]
current_song = words[3] current_song = words[3]
artUrl = words[4]
if current_song ~= nil then if current_song ~= nil then
if string.len(current_song) > 18 then if string.len(current_song) > 18 then
current_song = string.sub(current_song, 0, 9) .. ".." 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) watch(string.format(GET_MPD_CMD, "'" .. default_player .. "'"), 1, update_graphic, mpris_widget)
return mpris_widget return mpris_widget