mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-03 06:44:21 +02:00
music: abstract the functions used to control music player
We still use Spotify but we isolate the music functions into a specific module. Other music player would implement the same interface.
This commit is contained in:
parent
51525044ae
commit
8f6b6733bc
2 changed files with 42 additions and 10 deletions
35
lib/spotify.lua
Normal file
35
lib/spotify.lua
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
-- Drive spotify
|
||||||
|
|
||||||
|
local awful = require("awful")
|
||||||
|
|
||||||
|
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()
|
||||||
|
spotify("Play")
|
||||||
|
end
|
||||||
|
|
||||||
|
function pause()
|
||||||
|
spotify("Pause")
|
||||||
|
end
|
||||||
|
|
||||||
|
function stop()
|
||||||
|
spotify("Stop")
|
||||||
|
end
|
||||||
|
|
||||||
|
function next()
|
||||||
|
spotify("Next")
|
||||||
|
end
|
||||||
|
|
||||||
|
function previous()
|
||||||
|
spotify("Previous")
|
||||||
|
end
|
|
@ -135,11 +135,7 @@ local function screen_focus(i)
|
||||||
if c then client.focus = c end
|
if c then client.focus = c end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Send a command to spotify
|
local music = loadrc("spotify", "vbe/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
|
|
||||||
|
|
||||||
config.keys.global = awful.util.table.join(
|
config.keys.global = awful.util.table.join(
|
||||||
keydoc.group("Focus"),
|
keydoc.group("Focus"),
|
||||||
|
@ -217,11 +213,12 @@ config.keys.global = awful.util.table.join(
|
||||||
awful.key({ }, "XF86AudioRaiseVolume", volume.increase),
|
awful.key({ }, "XF86AudioRaiseVolume", volume.increase),
|
||||||
awful.key({ }, "XF86AudioLowerVolume", volume.decrease),
|
awful.key({ }, "XF86AudioLowerVolume", volume.decrease),
|
||||||
awful.key({ }, "XF86AudioMute", volume.toggle),
|
awful.key({ }, "XF86AudioMute", volume.toggle),
|
||||||
awful.key({ }, "XF86AudioPlay", function() spotify("PlayPause") end),
|
|
||||||
awful.key({ }, "XF86AudioPause", function() spotify("PlayPause") end),
|
awful.key({ }, "XF86AudioPlay", music.playpause),
|
||||||
awful.key({ }, "XF86AudioStop", function() spotify("Stop") end),
|
awful.key({ }, "XF86AudioPause", music.pause),
|
||||||
awful.key({ }, "XF86AudioNext", function() spotify("Next") end),
|
awful.key({ }, "XF86AudioStop", music.stop),
|
||||||
awful.key({ }, "XF86AudioPrev", function() spotify("Previous") end),
|
awful.key({ }, "XF86AudioNext", music.next),
|
||||||
|
awful.key({ }, "XF86AudioPrev", music.previous),
|
||||||
|
|
||||||
-- Help
|
-- Help
|
||||||
awful.key({ modkey, }, "F1", keydoc.display)
|
awful.key({ modkey, }, "F1", keydoc.display)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue