Dump nixos config after scrubing
This commit is contained in:
commit
5fa4c76c24
854 changed files with 30072 additions and 0 deletions
|
|
@ -0,0 +1,95 @@
|
|||
# Spotify widget
|
||||
|
||||
This widget displays currently playing song on [Spotify for Linux](https://www.spotify.com/download/linux/) client: 
|
||||
|
||||
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
|
||||
|
||||
- left click - play/pause
|
||||
- scroll up - play next song
|
||||
- scroll down - play previous song
|
||||
|
||||
## Dependencies
|
||||
|
||||
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 |
|
||||
| `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 |
|
||||
| `timeout` | 1 | How often in seconds the widget refreshes |
|
||||
| `sp_bin` | `sp` | Path to the `sp` binary. Required if `sp` is not in environment PATH. |
|
||||
|
||||
|
||||
### 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',
|
||||
dim_when_paused = true,
|
||||
dim_opacity = 0.5,
|
||||
max_length = -1,
|
||||
show_tooltip = false,
|
||||
sp_bin = gears.filesystem.get_configuration_dir() .. 'scripts/sp'
|
||||
})
|
||||
```
|
||||
|
||||
Gives following widget
|
||||
|
||||
Playing:
|
||||

|
||||
|
||||
Paused:
|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
First you need to have spotify CLI installed, it uses dbus to communicate with spotify-client:
|
||||
|
||||
```bash
|
||||
git clone https://gist.github.com/fa6258f3ff7b17747ee3.git
|
||||
cd ./fa6258f3ff7b17747ee3
|
||||
chmod +x sp
|
||||
# This widget will work by default if the binary is in the system PATH
|
||||
sudo cp ./sp /usr/local/bin/
|
||||
# Alternatively, you may save the binary anywhere and supply the path via this widget's sp_bin argument:
|
||||
# cp ./sp ~/.config/awesome/scripts/
|
||||
```
|
||||
|
||||
Then clone repo under **~/.config/awesome/** and add widget in **rc.lua**:
|
||||
|
||||
```lua
|
||||
local spotify_widget = require("awesome-wm-widgets.spotify-widget.spotify")
|
||||
...
|
||||
s.mytasklist, -- Middle widget
|
||||
{ -- Right widgets
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
...
|
||||
-- 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'
|
||||
}),
|
||||
...
|
||||
```
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
|
|
@ -0,0 +1,174 @@
|
|||
-------------------------------------------------
|
||||
-- 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 2020 Pavel Makhov
|
||||
-------------------------------------------------
|
||||
|
||||
local awful = require("awful")
|
||||
local wibox = require("wibox")
|
||||
local watch = require("awful.widget.watch")
|
||||
|
||||
local function ellipsize(text, length)
|
||||
-- utf8 only available in Lua 5.3+
|
||||
if utf8 == nil then
|
||||
return text:sub(0, length)
|
||||
end
|
||||
return (utf8.len(text) > length and length > 0)
|
||||
and text:sub(0, utf8.offset(text, length - 2) - 1) .. '...'
|
||||
or text
|
||||
end
|
||||
|
||||
local spotify_widget = {}
|
||||
|
||||
local function worker(user_args)
|
||||
|
||||
local args = user_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'
|
||||
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 true or args.show_tooltip
|
||||
local timeout = args.timeout or 1
|
||||
local sp_bin = args.sp_bin or 'sp'
|
||||
|
||||
local GET_SPOTIFY_STATUS_CMD = sp_bin .. ' status'
|
||||
local GET_CURRENT_SONG_CMD = sp_bin .. ' current'
|
||||
local PLAY_PAUSE_CMD = sp_bin .. ' play'
|
||||
local NEXT_SONG_CMD = sp_bin .. ' next'
|
||||
local PREVIOUS_SONG_CMD = sp_bin .. ' prev'
|
||||
|
||||
local cur_artist = ''
|
||||
local cur_title = ''
|
||||
local cur_album = ''
|
||||
|
||||
spotify_widget = wibox.widget {
|
||||
{
|
||||
id = 'artistw',
|
||||
font = font,
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
{
|
||||
layout = wibox.layout.stack,
|
||||
{
|
||||
id = "icon",
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
{
|
||||
widget = wibox.widget.textbox,
|
||||
font = font,
|
||||
text = ' ',
|
||||
forced_height = 1
|
||||
}
|
||||
},
|
||||
{
|
||||
layout = wibox.container.scroll.horizontal,
|
||||
max_size = 100,
|
||||
step_function = wibox.container.scroll.step_functions.waiting_nonlinear_back_and_forth,
|
||||
speed = 40,
|
||||
{
|
||||
id = 'titlew',
|
||||
font = font,
|
||||
widget = wibox.widget.textbox
|
||||
}
|
||||
},
|
||||
layout = wibox.layout.align.horizontal,
|
||||
set_status = function(self, is_playing)
|
||||
self:get_children_by_id('icon')[1]:set_image(is_playing and play_icon or pause_icon)
|
||||
if dim_when_paused then
|
||||
self:get_children_by_id('icon')[1]:set_opacity(is_playing and 1 or dim_opacity)
|
||||
|
||||
self:get_children_by_id('titlew')[1]:set_opacity(is_playing and 1 or dim_opacity)
|
||||
self:get_children_by_id('titlew')[1]:emit_signal('widget::redraw_needed')
|
||||
|
||||
self:get_children_by_id('artistw')[1]:set_opacity(is_playing and 1 or dim_opacity)
|
||||
self:get_children_by_id('artistw')[1]:emit_signal('widget::redraw_needed')
|
||||
end
|
||||
end,
|
||||
set_text = function(self, artist, song)
|
||||
local artist_to_display = ellipsize(artist, max_length)
|
||||
if self:get_children_by_id('artistw')[1]:get_markup() ~= artist_to_display then
|
||||
self:get_children_by_id('artistw')[1]:set_markup(artist_to_display)
|
||||
end
|
||||
local title_to_display = ellipsize(song, max_length)
|
||||
if self:get_children_by_id('titlew')[1]:get_markup() ~= title_to_display then
|
||||
self:get_children_by_id('titlew')[1]:set_markup(title_to_display)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
local update_widget_icon = function(widget, stdout, _, _, _)
|
||||
stdout = string.gsub(stdout, "\n", "")
|
||||
widget:set_status(stdout == 'Playing' and true or false)
|
||||
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)
|
||||
return
|
||||
end
|
||||
|
||||
local escaped = string.gsub(stdout, "&", '&')
|
||||
local album, _, 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
|
||||
|
||||
watch(GET_SPOTIFY_STATUS_CMD, timeout, update_widget_icon, spotify_widget)
|
||||
watch(GET_CURRENT_SONG_CMD, timeout, 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(PLAY_PAUSE_CMD, false) -- left click
|
||||
elseif (button == 4) then
|
||||
awful.spawn(NEXT_SONG_CMD, false) -- scroll up
|
||||
elseif (button == 5) then
|
||||
awful.spawn(PREVIOUS_SONG_CMD, 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)
|
||||
|
||||
|
||||
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
|
||||
|
||||
return setmetatable(spotify_widget, { __call = function(_, ...)
|
||||
return worker(...)
|
||||
end })
|
||||
Loading…
Add table
Add a link
Reference in a new issue