summaryrefslogtreecommitdiff
path: root/spotify-widget
diff options
context:
space:
mode:
Diffstat (limited to 'spotify-widget')
-rw-r--r--spotify-widget/README.md26
-rw-r--r--spotify-widget/spo-wid-1.pngbin1283 -> 1431 bytes
-rw-r--r--spotify-widget/spo-wid-custom.pngbin4608 -> 0 bytes
-rw-r--r--spotify-widget/spo-wid-default.pngbin3778 -> 0 bytes
-rw-r--r--spotify-widget/spotify-widget-custom-paused.pngbin0 -> 2303 bytes
-rw-r--r--spotify-widget/spotify-widget-custom-playing.pngbin0 -> 2889 bytes
-rw-r--r--spotify-widget/spotify.lua86
7 files changed, 96 insertions, 16 deletions
diff --git a/spotify-widget/README.md b/spotify-widget/README.md
index 083963f..e52e58f 100644
--- a/spotify-widget/README.md
+++ b/spotify-widget/README.md
@@ -1,9 +1,14 @@
# Spotify widget
-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:
+This widget displays currently playing song on [Spotify for Linux](https://www.spotify.com/download/linux/) client: ![screenshot](./spo-wid-1.png)
+
+Some features:
- status icon which shows if music is currently playing
- artist and name of the current song
+ - dim widget if spotify is paused
+ - trim long artist/song names
+ - tooltip with more info about the song
## Controls
@@ -24,6 +29,11 @@ It is possible to customize widget by providing a table with all or some of the
| `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 |
+| `dim_when_paused` | `false` | Decrease the widget opacity if spotify is paused |
+| `dim_opacity` | `0.2` | Widget's opacity when dimmed, `dim_when_paused` should be set to `true` |
+| `max_length` | `15` | Maximum lentgh of artist and title names. Text will be ellipsized if longer. |
+| `show_tooltip` | `true`| Show tooltip on hover with information about the playing song |
+
### Example:
@@ -31,13 +41,21 @@ It is possible to customize widget by providing a table with all or some of the
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'
+ pause_icon = '/usr/share/icons/Papirus-Dark/24x24/panel/spotify-indicator.svg',
+ dim_when_paused = true,
+ dim_opacity = 0.5,
+ max_length = -1,
+ show_tooltip = false
})
```
-Gives following widget:
+Gives following widget
+
+Playing:
+![screenshot](./spotify-widget-custom-playing.png)
-![screenshot](./spo-wid-custom.png)
+Paused:
+![screenshot](./spotify-widget-custom-paused.png)
## Installation
diff --git a/spotify-widget/spo-wid-1.png b/spotify-widget/spo-wid-1.png
index 296c2f6..5c7e403 100644
--- a/spotify-widget/spo-wid-1.png
+++ b/spotify-widget/spo-wid-1.png
Binary files differ
diff --git a/spotify-widget/spo-wid-custom.png b/spotify-widget/spo-wid-custom.png
deleted file mode 100644
index 979ad31..0000000
--- a/spotify-widget/spo-wid-custom.png
+++ /dev/null
Binary files differ
diff --git a/spotify-widget/spo-wid-default.png b/spotify-widget/spo-wid-default.png
deleted file mode 100644
index 67785f2..0000000
--- a/spotify-widget/spo-wid-default.png
+++ /dev/null
Binary files differ
diff --git a/spotify-widget/spotify-widget-custom-paused.png b/spotify-widget/spotify-widget-custom-paused.png
new file mode 100644
index 0000000..9ac9c4a
--- /dev/null
+++ b/spotify-widget/spotify-widget-custom-paused.png
Binary files differ
diff --git a/spotify-widget/spotify-widget-custom-playing.png b/spotify-widget/spotify-widget-custom-playing.png
new file mode 100644
index 0000000..f9628f9
--- /dev/null
+++ b/spotify-widget/spotify-widget-custom-playing.png
Binary files differ
diff --git a/spotify-widget/spotify.lua b/spotify-widget/spotify.lua
index f8b2b62..eea9b0b 100644
--- a/spotify-widget/spotify.lua
+++ b/spotify-widget/spotify.lua
@@ -5,15 +5,22 @@
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/spotify-widget
-- @author Pavel Makhov
--- @copyright 2018 Pavel Makhov
+-- @copyright 2020 Pavel Makhov
-------------------------------------------------
local awful = require("awful")
local wibox = require("wibox")
local watch = require("awful.widget.watch")
+local naughty = require("naughty")
local GET_SPOTIFY_STATUS_CMD = 'sp status'
-local GET_CURRENT_SONG_CMD = 'sp current-oneline'
+local GET_CURRENT_SONG_CMD = 'sp current'
+
+local function ellipsize(text, length)
+ return (text:len() > length and length > 0)
+ and text:sub(0, length - 3) .. '...'
+ or text
+end
local spotify_widget = {}
@@ -24,24 +31,53 @@ local function worker(args)
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'
+ local dim_when_paused = args.dim_when_paused == nil and false or args.dim_when_paused
+ local dim_opacity = args.dim_opacity or 0.2
+ local max_length = args.max_length or 15
+ local show_tooltip = args.show_tooltip == nil and false or args.show_tooltip
+
+ local cur_artist = ''
+ local cur_title = ''
+ local cur_album = ''
spotify_widget = wibox.widget {
{
+ id = 'artistw',
+ font = font,
+ widget = wibox.widget.textbox,
+ },
+ {
id = "icon",
widget = wibox.widget.imagebox,
},
{
- id = 'current_song',
- widget = wibox.widget.textbox,
- font = font
+ id = 'titlew',
+ font = font,
+ widget = wibox.widget.textbox
},
layout = wibox.layout.align.horizontal,
set_status = function(self, is_playing)
self.icon.image = (is_playing and play_icon or pause_icon)
+ if dim_when_paused then
+ self.icon.opacity = (is_playing and 1 or dim_opacity)
+
+ self.titlew:set_opacity(is_playing and 1 or dim_opacity)
+ self.titlew:emit_signal('widget::redraw_needed')
+
+ self.artistw:set_opacity(is_playing and 1 or dim_opacity)
+ self.artistw:emit_signal('widget::redraw_needed')
+ end
end,
- set_text = function(self, path)
- self.current_song.markup = path
- end,
+ set_text = function(self, artist, song)
+ local artist_to_display = ellipsize(artist, max_length)
+ if self.artistw.text ~= artist_to_display then
+ self.artistw.text = artist_to_display
+ end
+ local title_to_display = ellipsize(song, max_length)
+ if self.titlew.text ~= title_to_display then
+ self.titlew.text = title_to_display
+ end
+ end
}
local update_widget_icon = function(widget, stdout, _, _, _)
@@ -50,12 +86,22 @@ local function worker(args)
end
local update_widget_text = function(widget, stdout, _, _, _)
- local escaped = string.gsub(stdout, "&", '&')
if string.find(stdout, 'Error: Spotify is not running.') ~= nil then
- widget:set_text('')
+ widget:set_text('','')
widget:set_visible(false)
- else
- widget:set_text(escaped)
+ return
+ end
+
+ local escaped = string.gsub(stdout, "&", '&')
+ local album, album_artist, artist, title =
+ string.match(escaped, 'Album%s*(.*)\nAlbumArtist%s*(.*)\nArtist%s*(.*)\nTitle%s*(.*)\n')
+
+ if album ~= nil and title ~=nil and artist ~= nil then
+ cur_artist = artist
+ cur_title = title
+ cur_album = album
+
+ widget:set_text(artist, title)
widget:set_visible(true)
end
end
@@ -80,6 +126,22 @@ local function worker(args)
end)
end)
+
+ if show_tooltip then
+ local spotify_tooltip = awful.tooltip {
+ mode = 'outside',
+ preferred_positions = {'bottom'},
+ }
+
+ spotify_tooltip:add_to_object(spotify_widget)
+
+ spotify_widget:connect_signal('mouse::enter', function()
+ spotify_tooltip.markup = '<b>Album</b>: ' .. cur_album
+ .. '\n<b>Artist</b>: ' .. cur_artist
+ .. '\n<b>Song</b>: ' .. cur_title
+ end)
+ end
+
return spotify_widget
end