summaryrefslogtreecommitdiff
path: root/mpris-widget
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@users.noreply.github.com>2021-11-19 20:29:10 -0500
committerGitHub <noreply@github.com>2021-11-19 20:29:10 -0500
commit2df874c543fd26a20eeb7509904145f26a1beec1 (patch)
treee612ff2bc9fac23c8ed94b96eb6093e8693c385b /mpris-widget
parent050f328c321c0d9fc585a63452bb830e20ce62a0 (diff)
parent4bc22fbb70fc50d402dacd3bdabbc2f405def9ff (diff)
Merge pull request #304 from rski/master
mpris-widget: another round of improvements
Diffstat (limited to 'mpris-widget')
-rw-r--r--mpris-widget/init.lua113
1 files changed, 16 insertions, 97 deletions
diff --git a/mpris-widget/init.lua b/mpris-widget/init.lua
index 7669b10..5e45ffa 100644
--- a/mpris-widget/init.lua
+++ b/mpris-widget/init.lua
@@ -7,17 +7,13 @@
-------------------------------------------------
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 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"
@@ -30,12 +26,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,
@@ -74,9 +77,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 ~='' or player_name ~=nil then
- for i = 0, #rows do rows[i]=nil end
+ if player_name ~='' and player_name ~=nil then
local checkbox = wibox.widget{
{
@@ -130,96 +133,35 @@ end
local function worker()
-- retrieve song info
- local current_song, artist, mpdstatus, 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 mpdarc_current_song_widget = wibox.widget {
- id = 'current_song',
- widget = wibox.widget.textbox,
- font = 'Play 10'
- }
+ local current_song, artist, player_status
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]
+ local words = gears.string.split(stdout, ';')
+ player_status = words[1]
artist = words[2]
current_song = words[3]
- art = 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 mpdstatus == "Playing" then
- mpdarc_icon_widget.visible = true
+ if player_status == "Playing" then
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
- mpdarc_icon_widget.visible = true
+ elseif player_status == "Paused" then
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
- mpdarc_icon_widget.visible = true
+ elseif player_status == "Stopped" then
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
- 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()
@@ -236,29 +178,6 @@ local function worker()
)
)
-
-
- local notification
- local function show_MPD_status()
- spawn.easy_async(GET_MPD_CMD, function()
- notification = naughty.notification {
- margin = 10,
- timeout = 5,
- hover_timeout = 0.5,
- width = 240,
- height = 90,
- title = "<b>" .. mpdstatus .. "</b>",
- text = current_song .. " <b>by</b> " .. artist,
- image = artUrl
- }
- end)
- end
-
- mpdarc:connect_signal("mouse::enter", function()
- if current_song ~= nil and artist ~= nil then show_MPD_status() end
- end)
- mpdarc: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