diff options
-rw-r--r-- | spotify-widget/spotify.lua | 70 | ||||
-rw-r--r-- | volume-widget/README.md | 7 | ||||
-rw-r--r-- | volume-widget/audio-volume-muted-symbolic.png | bin | 0 -> 435 bytes | |||
-rw-r--r-- | volume-widget/audio-volume-muted-symbolic_red.png | bin | 0 -> 450 bytes |
4 files changed, 54 insertions, 23 deletions
diff --git a/spotify-widget/spotify.lua b/spotify-widget/spotify.lua index f9ffa02..a3f72f0 100644 --- a/spotify-widget/spotify.lua +++ b/spotify-widget/spotify.lua @@ -2,33 +2,63 @@ local wibox = require("wibox") local awful = require("awful") local watch = require("awful.widget.watch") -spotify_widget = wibox.widget.textbox() -spotify_widget:set_font('Play 9') +local get_spotify_status_cmd = '/home/'.. os.getenv("USER") .. '/.config/awesome/awesome-wm-widgets/spotify-widget/spotify_stat' +local get_current_song_cmd = 'sp current-oneline' --- optional icon, could be replaced by spotfiy logo (https://developer.spotify.com/design/) -spotify_icon = wibox.widget.imagebox() -spotify_icon:set_image("/usr/share/icons/Arc/devices/22/audio-headphones.png") - -watch( - "sp current-oneline", 1, - function(widget, stdout, _, _, _) - if string.find(stdout, 'Error: Spotify is not running.') ~= nil then - widget:set_text("") - else - widget:set_text(stdout) - end +spotify_widget = wibox.widget { + { + id = "icon", + widget = wibox.widget.imagebox, + }, + { + id = 'current_song', + widget = wibox.widget.textbox, + font = 'Play 9' + }, + layout = wibox.layout.align.horizontal, + set_image = function(self, path) + self.icon.image = path + end, + set_text = function(self, path) + self.current_song.text = path end, - spotify_widget -) +} + +local update_widget_icon = function(widget, stdout, _, _, _) + stdout = string.gsub(stdout, "\n", "") + if (stdout == 'RUNNING') then + widget:set_image("/usr/share/icons/Arc/actions/24/player_play.png") + elseif (stdout == "CORKED") then + widget:set_image("/usr/share/icons/Arc/actions/24/player_pause.png") + else + widget:set_image(nil) + end +end + +local update_widget_text = function(widget, stdout, _, _, _) + if string.find(stdout, 'Error: Spotify is not running.') ~= nil then + widget:set_text('') + widget:set_visible(false) + else + widget:set_text(stdout) + widget:set_visible(true) + end +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: -- - left click - play/pause -- - scroll up - play next song -- - scroll down - play previous song ]] -spotify_widget:connect_signal("button::press", function(_,_,_,button) - if (button == 1) then awful.spawn("sp play", false) - elseif (button == 4) then awful.spawn("sp next", false) - elseif (button == 5) then awful.spawn("sp prev", false) +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 + elseif (button == 5) then awful.spawn("sp prev", false) -- scroll down end + 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 diff --git a/volume-widget/README.md b/volume-widget/README.md index 747879c..19946a2 100644 --- a/volume-widget/README.md +++ b/volume-widget/README.md @@ -21,8 +21,9 @@ s.mytasklist, -- Middle widget volume_widget, ... ``` -- _Optional step._ In Arc icon theme the muted audio level icon looks like 0 level icon, which could be a bit misleading. - So I decided to use original muted icon for low audio level, and the same icon, but colored in red for muted audio level. Fortunately icons are in svg format, so you can easily recolor them with `sed`: + +- _Optional step._ In Arc icon theme the muted audio level icon (![Volume-widget](./audio-volume-muted-symbolic.png)) looks like 0 level icon, which could be a bit misleading. + So I decided to use original muted icon for low audio level, and the same icon, but colored in red for muted audio level. Fortunately icons are in svg format, so you can easily recolor them with `sed`, so it would look like this (![Volume Widget](./audio-volume-muted-symbolic_red.png)): ```bash cd /usr/share/icons/Arc/status/symbolic && @@ -39,5 +40,5 @@ If you want to control volume level by keyboard shortcuts add following lines in ```lua awful.key({ modkey}, "[", function () awful.spawn("amixer -D pulse sset Master 5%-") end, {description = "increase volume", group = "custom"}), awful.key({ modkey}, "]", function () awful.spawn("amixer -D pulse sset Master 5%+") end, {description = "decrease volume", group = "custom"}), -awful.key({ modkey}, "\\", function () awful.spawn("amixer -D pulse set Master +1 toggle") end, {description = "mute volume", group = "custom"}), +awful.key({ modkey}, "\", function () awful.spawn("amixer -D pulse set Master +1 toggle") end, {description = "mute volume", group = "custom"}), ``` diff --git a/volume-widget/audio-volume-muted-symbolic.png b/volume-widget/audio-volume-muted-symbolic.png Binary files differnew file mode 100644 index 0000000..b9dffd6 --- /dev/null +++ b/volume-widget/audio-volume-muted-symbolic.png diff --git a/volume-widget/audio-volume-muted-symbolic_red.png b/volume-widget/audio-volume-muted-symbolic_red.png Binary files differnew file mode 100644 index 0000000..f47807d --- /dev/null +++ b/volume-widget/audio-volume-muted-symbolic_red.png |