From 57ae9fef44ea8f5070109033fc5c9377e584f9a9 Mon Sep 17 00:00:00 2001 From: streetturtle Date: Fri, 3 May 2019 20:28:50 -0400 Subject: [PATCH] spotify config --- spotify-widget/README.md | 48 +++++++++++-- spotify-widget/spo-wid-custom.png | Bin 0 -> 4608 bytes spotify-widget/spo-wid-default.png | Bin 0 -> 3778 bytes spotify-widget/spotify.lua | 112 ++++++++++++++++------------- 4 files changed, 107 insertions(+), 53 deletions(-) create mode 100644 spotify-widget/spo-wid-custom.png create mode 100644 spotify-widget/spo-wid-default.png diff --git a/spotify-widget/README.md b/spotify-widget/README.md index eff3027..083963f 100644 --- a/spotify-widget/README.md +++ b/spotify-widget/README.md @@ -1,9 +1,9 @@ # Spotify widget -This widget displays currently playing song on [Spotify for Linux](https://www.spotify.com/download/linux/) client: ![screenshot](./spo-wid-1.png) and consists of two parts: +This widget displays currently playing song on [Spotify for Linux](https://www.spotify.com/download/linux/) client: ![screenshot](./spo-wid-default.png) and consists of two parts: - status icon which shows if music is currently playing - - artist and name of the current song playing + - artist and name of the current song ## Controls @@ -15,11 +15,42 @@ This widget displays currently playing song on [Spotify for Linux](https://www.s Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder. +## Customization + +It is possible to customize widget by providing a table with all or some of the following config parameters: + +| Name | Default | Description | +|---|---|---| +| `play_icon` | `/usr/share/icons/Arc/actions/24/player_play.png` | Play icon | +| `pause_icon` | `/usr/share/icons/Arc/actions/24/player_pause.png` | Pause icon | +| `font` | `Play 9`| Font | + +### Example: + +```lua +spotify_widget({ + font = 'Ubuntu Mono 9', + play_icon = '/usr/share/icons/Papirus-Light/24x24/categories/spotify.svg', + pause_icon = '/usr/share/icons/Papirus-Dark/24x24/panel/spotify-indicator.svg' +}) +``` + +Gives following widget: + +![screenshot](./spo-wid-custom.png) + ## Installation -First you need to have spotify CLI installed. Here is how you can do it (except widget part): [pavelmakhov.com/2016/02/awesome-wm-spotify](http://pavelmakhov.com/2016/02/awesome-wm-spotify) +First you need to have spotify CLI installed, it uses dbus to communicate with spotify-client: -To use this widget clone repo under **~/.config/awesome/** and then add it in **rc.lua**: +```bash +git clone https://gist.github.com/fa6258f3ff7b17747ee3.git +cd ./fa6258f3ff7b17747ee3 +chmod +x sp +sudo cp ./sp /usr/local/bin/ +``` + +Then clone repo under **~/.config/awesome/** and add widget in **rc.lua**: ```lua local spotify_widget = require("awesome-wm-widgets.spotify-widget.spotify") @@ -28,6 +59,13 @@ s.mytasklist, -- Middle widget { -- Right widgets layout = wibox.layout.fixed.horizontal, ... - spotify_widget, + -- default + spotify_widget(), + -- customized + spotify_widget({ + font = 'Ubuntu Mono 9', + play_icon = '/usr/share/icons/Papirus-Light/24x24/categories/spotify.svg', + pause_icon = '/usr/share/icons/Papirus-Dark/24x24/panel/spotify-indicator.svg' + }), ... ``` diff --git a/spotify-widget/spo-wid-custom.png b/spotify-widget/spo-wid-custom.png new file mode 100644 index 0000000000000000000000000000000000000000..979ad3151822da722a42e5bffd91951a1cec5abd GIT binary patch literal 4608 zcmai2^;^^5`+hOHnTVuxGY}cl0!~Idx)H}|HK;}zoi_m~b^>Fh^ zA<2;Y!Su{&XlQ1ajh09*r$5}<-wfsIAL!)k0zC0XdAUgYA$?t3y#3rz{`=$|>Hq+K ztEY9(JP5msb@$idnMqS` zR!MO&h3oqPx@#Of-)c@p>tz!}-P|bX0k`B2+}^&yv15!9ZGtC#M3o0@@ABlJBdM(P zhlbB?NB!{G+wBlHPk9Xi!)UVpecl$An(D(H8M?vK#9rQXb*AG5m;p`U54w;+IZxXM z10~_6cZw5qi7Ga1?^*;Ep`QlB7as9(2=juGgLsCaBL>3OiAu&O z-1&;F>o}E7_>rr3W3A*IE9G@Jekf(J6kW81C^~cakZi{!!`6Hcs!;iG9gV59bzuWr~n)wny^y;~@mRxV~*- z%(`_2;-`<&#dn*7H<<@x{Lm^0G`L_``2EUDP|%>R&5h@Sp}Mdlb=iz{ormsS2{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Ay3 z|0@>f<(kb#ZQH19d5PQY@qe86et{4&==GQlzBcUtXAbkvVki{K0|Lupj^!}M+7`R2 zYWs(h>^B3Le~A)>LU}-tWkr_5Z2ZC{cu342438BGh6i6iO7K7DJ&>q6oDZ3WX9y ssKrnylqft<807*qoM6N<$g8y(ag8%>k literal 0 HcmV?d00001 diff --git a/spotify-widget/spotify.lua b/spotify-widget/spotify.lua index c6f2188..e826de9 100644 --- a/spotify-widget/spotify.lua +++ b/spotify-widget/spotify.lua @@ -14,59 +14,75 @@ local watch = require("awful.widget.watch") local GET_SPOTIFY_STATUS_CMD = 'sp status' local GET_CURRENT_SONG_CMD = 'sp current-oneline' -local PATH_TO_ICONS = "/usr/share/icons/Arc" -local 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_status = function(self, is_playing) - self.icon.image = PATH_TO_ICONS .. - (is_playing and "/actions/24/player_play.png" - or "/actions/24/player_pause.png") - end, - set_text = function(self, path) - self.current_song.markup = path - end, -} +local spotify_widget = {} -local update_widget_icon = function(widget, stdout, _, _, _) - stdout = string.gsub(stdout, "\n", "") - widget:set_status(stdout == 'Playing' and true or false) -end +local function worker(args) -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) + local args = args or {} + + local play_icon = args.play_icon or '/usr/share/icons/Arc/actions/24/player_play.png' + local pause_icon = args.pause_icon or '/usr/share/icons/Arc/actions/24/player_pause.png' + local font = args.font or 'Play 9' + + spotify_widget = wibox.widget { + { + id = "icon", + widget = wibox.widget.imagebox, + }, + { + id = 'current_song', + widget = wibox.widget.textbox, + font = font + }, + layout = wibox.layout.align.horizontal, + set_status = function(self, is_playing) + self.icon.image = (is_playing and play_icon or pause_icon) + end, + set_text = function(self, path) + self.current_song.markup = path + end, + } + + local update_widget_icon = function(widget, stdout, _, _, _) + stdout = string.gsub(stdout, "\n", "") + widget:set_status(stdout == 'Playing' and true or false) 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 controls 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) -- left click - elseif (button == 4) then awful.spawn("sp next", false) -- scroll up - elseif (button == 5) then awful.spawn("sp prev", false) -- scroll down + 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 - awful.spawn.easy_async(GET_SPOTIFY_STATUS_CMD, function(stdout, stderr, exitreason, exitcode) - update_widget_icon(spotify_widget, stdout, stderr, exitreason, exitcode) + + watch(GET_SPOTIFY_STATUS_CMD, 1, update_widget_icon, spotify_widget) + watch(GET_CURRENT_SONG_CMD, 1, update_widget_text, spotify_widget) + + --- Adds mouse controls 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) -- 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) -end) -return spotify_widget + return spotify_widget + +end + +return setmetatable(spotify_widget, { __call = function(_, ...) + return worker(...) +end }) \ No newline at end of file