mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-24 02:38:33 +02:00
spotify: try to support the new version of Spotify
Use dbus-mediakeys to get an appropriate DBus interface. In future versions, this should not be needed anymore. See: https://github.com/vincentbernat/dbus-mediakeys
This commit is contained in:
parent
86c36c91c6
commit
e3747d1b9f
3 changed files with 66 additions and 46 deletions
100
lib/spotify.lua
100
lib/spotify.lua
|
@ -7,62 +7,72 @@
|
|||
-- mdbus2 org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2
|
||||
|
||||
local awful = require("awful")
|
||||
local dbg = dbg
|
||||
local pairs = pairs
|
||||
local os = os
|
||||
local capi = {
|
||||
client = client
|
||||
}
|
||||
|
||||
module("vbe/spotify")
|
||||
|
||||
-- Send a command to spotify
|
||||
local function spotify(command)
|
||||
awful.util.spawn("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify " ..
|
||||
"/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." .. command, false)
|
||||
end
|
||||
|
||||
function playpause()
|
||||
spotify("PlayPause")
|
||||
end
|
||||
|
||||
function play()
|
||||
-- Play seems unable to play in many situations, let's use
|
||||
-- PlayPause instead.
|
||||
spotify("PlayPause")
|
||||
end
|
||||
|
||||
function pause()
|
||||
spotify("Pause")
|
||||
end
|
||||
|
||||
function stop()
|
||||
spotify("Stop")
|
||||
end
|
||||
|
||||
function next()
|
||||
spotify("Next")
|
||||
end
|
||||
|
||||
function previous()
|
||||
spotify("Previous")
|
||||
end
|
||||
|
||||
function show()
|
||||
-- This should work, but no:
|
||||
-- spotify("Raise")
|
||||
-- Get spotify window
|
||||
local function spotify()
|
||||
local clients = capi.client.get()
|
||||
for k, c in pairs(clients) do
|
||||
if awful.rules.match(c, { instance = "spotify",
|
||||
class = "Spotify" }) then
|
||||
if not c:isvisible() then
|
||||
awful.tag.viewonly(c:tags()[1])
|
||||
end
|
||||
capi.client.focus = c
|
||||
c:raise()
|
||||
return
|
||||
return c
|
||||
end
|
||||
end
|
||||
awful.util.spawn("spotify")
|
||||
-- To disable notifications, add the following line to
|
||||
-- ~/.config/spotify/Users/<spotifylogin>-user/prefs:
|
||||
-- ui.track_notifications_enabled=false
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Send a command to spotify
|
||||
local function cmd(command)
|
||||
local client = spotify()
|
||||
if client then
|
||||
os.execute("dbus-send --print-reply --reply-timeout=1000 --dest=org.gnome.SettingsDaemon "
|
||||
.. "/org/gnome/SettingsDaemon/MediaKeys "
|
||||
.. "org.gnome.SettingsDaemon.MediaKeys.PressMediaKey "
|
||||
.. "string:" .. command)
|
||||
end
|
||||
end
|
||||
|
||||
-- Show spotify
|
||||
function show()
|
||||
local client = spotify()
|
||||
if client then
|
||||
if not client:isvisible() then
|
||||
awful.tag.viewonly(client:tags()[1])
|
||||
end
|
||||
capi.client.focus = client
|
||||
client:raise()
|
||||
else
|
||||
awful.util.spawn("spotify")
|
||||
end
|
||||
end
|
||||
|
||||
function playpause()
|
||||
cmd("Play")
|
||||
end
|
||||
|
||||
function play()
|
||||
cmd("Play")
|
||||
end
|
||||
|
||||
function pause()
|
||||
cmd("Pause")
|
||||
end
|
||||
|
||||
function stop()
|
||||
cmd("Stop")
|
||||
end
|
||||
|
||||
function next()
|
||||
cmd("Next")
|
||||
end
|
||||
|
||||
function previous()
|
||||
cmd("Previous")
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue