summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@gmail.com>2018-01-06 19:06:30 -0500
committerstreetturtle <streetturtle@gmail.com>2018-01-20 14:10:53 -0500
commit364d24babe178197c5e0ce615f70698721ffdcb9 (patch)
tree4dc34cfb8f270bf3a35ca41e7a02f9ee71104644
parentdf3d0294971cd55c6bf34aacbbf27595f0145139 (diff)
refactor spotify widget
-rw-r--r--spotify-widget/spotify.lua40
1 files changed, 26 insertions, 14 deletions
diff --git a/spotify-widget/spotify.lua b/spotify-widget/spotify.lua
index be3225c..ee5217b 100644
--- a/spotify-widget/spotify.lua
+++ b/spotify-widget/spotify.lua
@@ -1,13 +1,22 @@
+-------------------------------------------------
+-- Spotify Widget for Awesome Window Manager
+-- Shows currently playing song on Spotify for Linux client
+-- More details could be found here:
+-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/spotify-widget
+
+-- @author Pavel Makhov
+-- @copyright 2018 Pavel Makhov
+-------------------------------------------------
+
local awful = require("awful")
local wibox = require("wibox")
local watch = require("awful.widget.watch")
--- local GET_SPOTIFY_STATUS_CMD = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/spotify-widget/spotify_stat'
local GET_SPOTIFY_STATUS_CMD = 'sp status'
local GET_CURRENT_SONG_CMD = 'sp current-oneline'
local PATH_TO_ICONS = "/usr/share/icons/Arc"
-spotify_widget = wibox.widget {
+local spotify_widget = wibox.widget {
{
id = "icon",
widget = wibox.widget.imagebox,
@@ -17,23 +26,25 @@ spotify_widget = wibox.widget {
widget = wibox.widget.textbox,
font = 'Play 9'
},
- layout = wibox.layout.align.horizontal,
- set_image = function(self, path)
- self.icon.image = path
+ layout = wibox.layout.align.horizontal,
+ set_status = function(self, is_playing)
+ if (is_playing) then
+ self.icon.image = PATH_TO_ICONS .. "/actions/24/player_play.png"
+ else
+ self.icon.image = PATH_TO_ICONS .. "/actions/24/player_pause.png"
+ end
end,
set_text = function(self, path)
- self.current_song.text = path
+ self.current_song.markup = path
end,
}
local update_widget_icon = function(widget, stdout, _, _, _)
stdout = string.gsub(stdout, "\n", "")
if (stdout == 'Playing') then
- widget:set_image(PATH_TO_ICONS .. "/actions/24/player_play.png")
- elseif (stdout == "Paused") then
- widget:set_image(PATH_TO_ICONS .. "/actions/24/player_pause.png")
+ widget:set_status(true)
else
- widget:set_image(nil)
+ widget:set_status(false)
end
end
@@ -50,11 +61,10 @@ end
watch(GET_SPOTIFY_STATUS_CMD, 1, update_widget_icon, spotify_widget)
watch(GET_CURRENT_SONG_CMD, 1, update_widget_text, spotify_widget)
---[[
--- Adds mouse control to the widget:
+--- Adds mouse controls to the widget:
-- - left click - play/pause
-- - scroll up - play next song
--- - scroll down - play previous song ]]
+-- - scroll down - play previous song
spotify_widget:connect_signal("button::press", function(_, _, _, button)
if (button == 1) then awful.spawn("sp play", false) -- left click
elseif (button == 4) then awful.spawn("sp next", false) -- scroll up
@@ -63,4 +73,6 @@ spotify_widget:connect_signal("button::press", function(_, _, _, button)
awful.spawn.easy_async(GET_SPOTIFY_STATUS_CMD, function(stdout, stderr, exitreason, exitcode)
update_widget_icon(spotify_widget, stdout, stderr, exitreason, exitcode)
end)
-end) \ No newline at end of file
+end)
+
+return spotify_widget