Merge pull request #1 from streetturtle/pr-213

wrap widget in a function
This commit is contained in:
mgabs 2020-11-23 21:20:06 +02:00 committed by GitHub
commit b454f198cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 102 additions and 109 deletions

View File

@ -19,7 +19,7 @@ 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 prev"
local PREV_MPD_CMD = "playerctl previous"
local PATH_TO_ICONS = "/usr/share/icons/Arc"
local PAUSE_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_pause.png"
@ -27,8 +27,12 @@ local PLAY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_play.png"
local STOP_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_stop.png"
local LIBRARY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/music-library.png"
local mpdarc_widget = {}
local function worker(args)
-- retriving song info
current_song, artist, artUrl = nil, nil, nil
local current_song, artist, mpdstatus
local icon = wibox.widget {
id = "icon",
@ -59,26 +63,13 @@ local mpdarc_current_song_widget = wibox.widget {
}
local update_graphic = function(widget, stdout, _, _, _)
-- mpdstatus, artist, current_song = stdout:match("(%w+)%;+(.-)%;(.*)")
local words = {}
for w in stdout:gmatch("([^;]*)") do
print(w)
table.insert(words, w)
end
mpdstatus = words[1]
current_song = words[2]
artist = words[3]
local art = words[4]
mpdstatus, artist, current_song = stdout:match("(%w+)%;+(.-)%;(.*)")
if current_song ~= nil then
if string.len(current_song) > 18 then
current_song = string.sub(current_song, 0, 12) .. " .."
if current_song.len == 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
icon.image = PLAY_ICON_NAME
@ -119,20 +110,16 @@ mpdarc:connect_signal("button::press", function(_, _, _, button)
end)
end)
-- local notification
function show_MPD_status()
local notification
local function show_MPD_status()
spawn.easy_async(GET_MPD_CMD, function(stdout, _, _, _)
notification = naughty.notify {
margin = 5,
title = mpdstatus,
-- position = "top_left",
width = 440,
height = 120,
text = current_song .. " by " .. artist,
title = mpdstatus,
timeout = 5,
hover_timeout = 0.5,
image = artUrl
};
width = 600
}
end)
end
@ -144,10 +131,16 @@ mpdarc:connect_signal("mouse::leave",
watch(GET_MPD_CMD, 1, update_graphic, mpdarc)
local mpdarc_widget = wibox.widget {
mpdarc_widget = wibox.widget {
screen = 'primary',
mpdarc_icon_widget,
mpdarc_current_song_widget,
layout = wibox.layout.align.horizontal
}
return mpdarc_widget
end
return setmetatable(mpdarc_widget, { __call = function(_, ...)
return worker(...)
end })