Merge pull request #1 from streetturtle/pr-213
wrap widget in a function
This commit is contained in:
commit
b454f198cf
|
@ -19,7 +19,7 @@ local TOGGLE_MPD_CMD = "playerctl play-pause"
|
||||||
local PAUSE_MPD_CMD = "playerctl pause"
|
local PAUSE_MPD_CMD = "playerctl pause"
|
||||||
local STOP_MPD_CMD = "playerctl stop"
|
local STOP_MPD_CMD = "playerctl stop"
|
||||||
local NEXT_MPD_CMD = "playerctl next"
|
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 PATH_TO_ICONS = "/usr/share/icons/Arc"
|
||||||
local PAUSE_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_pause.png"
|
local PAUSE_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_pause.png"
|
||||||
|
@ -27,17 +27,21 @@ 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 STOP_ICON_NAME = PATH_TO_ICONS .. "/actions/24/player_stop.png"
|
||||||
local LIBRARY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/music-library.png"
|
local LIBRARY_ICON_NAME = PATH_TO_ICONS .. "/actions/24/music-library.png"
|
||||||
|
|
||||||
-- retriving song info
|
local mpdarc_widget = {}
|
||||||
current_song, artist, artUrl = nil, nil, nil
|
|
||||||
|
|
||||||
local icon = wibox.widget {
|
local function worker(args)
|
||||||
|
|
||||||
|
-- retriving song info
|
||||||
|
local current_song, artist, mpdstatus
|
||||||
|
|
||||||
|
local icon = wibox.widget {
|
||||||
id = "icon",
|
id = "icon",
|
||||||
widget = wibox.widget.imagebox,
|
widget = wibox.widget.imagebox,
|
||||||
image = PLAY_ICON_NAME
|
image = PLAY_ICON_NAME
|
||||||
}
|
}
|
||||||
local mirrored_icon = wibox.container.mirror(icon, {horizontal = true})
|
local mirrored_icon = wibox.container.mirror(icon, {horizontal = true})
|
||||||
|
|
||||||
local mpdarc = wibox.widget {
|
local mpdarc = wibox.widget {
|
||||||
mirrored_icon,
|
mirrored_icon,
|
||||||
-- max_value = 1,
|
-- max_value = 1,
|
||||||
-- value = 0,
|
-- value = 0,
|
||||||
|
@ -49,36 +53,23 @@ local mpdarc = wibox.widget {
|
||||||
bg = "#ffffff11",
|
bg = "#ffffff11",
|
||||||
paddings = 0,
|
paddings = 0,
|
||||||
widget = wibox.container.arcchart
|
widget = wibox.container.arcchart
|
||||||
}
|
}
|
||||||
|
|
||||||
local mpdarc_icon_widget = wibox.container.mirror(mpdarc, {horizontal = true})
|
local mpdarc_icon_widget = wibox.container.mirror(mpdarc, {horizontal = true})
|
||||||
local mpdarc_current_song_widget = wibox.widget {
|
local mpdarc_current_song_widget = wibox.widget {
|
||||||
id = 'current_song',
|
id = 'current_song',
|
||||||
widget = wibox.widget.textbox,
|
widget = wibox.widget.textbox,
|
||||||
font = 'Play 10'
|
font = 'Play 10'
|
||||||
}
|
}
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
|
local update_graphic = function(widget, stdout, _, _, _)
|
||||||
|
mpdstatus, artist, current_song = stdout:match("(%w+)%;+(.-)%;(.*)")
|
||||||
if current_song ~= nil then
|
if current_song ~= nil then
|
||||||
if string.len(current_song) > 18 then
|
if current_song.len == 18 then
|
||||||
current_song = string.sub(current_song, 0, 12) .. " .."
|
current_song = string.sub(current_song, 0, 9) .. ".."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if art ~= nil then artUrl = string.sub(art, 8, -1) end
|
|
||||||
|
|
||||||
if mpdstatus == "Playing" then
|
if mpdstatus == "Playing" then
|
||||||
mpdarc_icon_widget.visible = true
|
mpdarc_icon_widget.visible = true
|
||||||
icon.image = PLAY_ICON_NAME
|
icon.image = PLAY_ICON_NAME
|
||||||
|
@ -99,9 +90,9 @@ local update_graphic = function(widget, stdout, _, _, _)
|
||||||
mpdarc_current_song_widget.markup = ""
|
mpdarc_current_song_widget.markup = ""
|
||||||
widget.colors = {beautiful.widget_red}
|
widget.colors = {beautiful.widget_red}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mpdarc:connect_signal("button::press", function(_, _, _, button)
|
mpdarc:connect_signal("button::press", function(_, _, _, button)
|
||||||
if (button == 1) then
|
if (button == 1) then
|
||||||
awful.spawn(TOGGLE_MPD_CMD, false) -- left click
|
awful.spawn(TOGGLE_MPD_CMD, false) -- left click
|
||||||
elseif (button == 2) then
|
elseif (button == 2) then
|
||||||
|
@ -117,37 +108,39 @@ mpdarc:connect_signal("button::press", function(_, _, _, button)
|
||||||
spawn.easy_async(GET_MPD_CMD, function(stdout, stderr, exitreason, exitcode)
|
spawn.easy_async(GET_MPD_CMD, function(stdout, stderr, exitreason, exitcode)
|
||||||
update_graphic(mpdarc, stdout, stderr, exitreason, exitcode)
|
update_graphic(mpdarc, stdout, stderr, exitreason, exitcode)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- local notification
|
local notification
|
||||||
function show_MPD_status()
|
local function show_MPD_status()
|
||||||
spawn.easy_async(GET_MPD_CMD, function(stdout, _, _, _)
|
spawn.easy_async(GET_MPD_CMD, function(stdout, _, _, _)
|
||||||
notification = naughty.notify {
|
notification = naughty.notify {
|
||||||
margin = 5,
|
|
||||||
title = mpdstatus,
|
|
||||||
-- position = "top_left",
|
|
||||||
width = 440,
|
|
||||||
height = 120,
|
|
||||||
text = current_song .. " by " .. artist,
|
text = current_song .. " by " .. artist,
|
||||||
|
title = mpdstatus,
|
||||||
timeout = 5,
|
timeout = 5,
|
||||||
hover_timeout = 0.5,
|
hover_timeout = 0.5,
|
||||||
image = artUrl
|
width = 600
|
||||||
};
|
}
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
mpdarc:connect_signal("mouse::enter", function()
|
mpdarc:connect_signal("mouse::enter", function()
|
||||||
if current_song ~= nil and artist ~= nil then show_MPD_status() end
|
if current_song ~= nil and artist ~= nil then show_MPD_status() end
|
||||||
end)
|
end)
|
||||||
mpdarc:connect_signal("mouse::leave",
|
mpdarc:connect_signal("mouse::leave",
|
||||||
function() naughty.destroy(notification) end)
|
function() naughty.destroy(notification) end)
|
||||||
|
|
||||||
watch(GET_MPD_CMD, 1, update_graphic, mpdarc)
|
watch(GET_MPD_CMD, 1, update_graphic, mpdarc)
|
||||||
|
|
||||||
local mpdarc_widget = wibox.widget {
|
mpdarc_widget = wibox.widget {
|
||||||
screen = 'primary',
|
screen = 'primary',
|
||||||
mpdarc_icon_widget,
|
mpdarc_icon_widget,
|
||||||
mpdarc_current_song_widget,
|
mpdarc_current_song_widget,
|
||||||
layout = wibox.layout.align.horizontal
|
layout = wibox.layout.align.horizontal
|
||||||
}
|
}
|
||||||
return mpdarc_widget
|
return mpdarc_widget
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(mpdarc_widget, { __call = function(_, ...)
|
||||||
|
return worker(...)
|
||||||
|
end })
|
Loading…
Reference in New Issue