Add media control support with playerctl or default to dbus on Spotify
This commit is contained in:
parent
6c82d8fefc
commit
cff3debfdb
16
README.md
16
README.md
@ -7,6 +7,18 @@ As simple as it sounds
|
||||
|
||||
By default, Simple Awesome uses
|
||||
|
||||
- `rofi` for the launch bar/window switcher
|
||||
- `rofi` - launch bar / window switcher
|
||||
- `flameshot` - screenshot utility
|
||||
|
||||
- `flameshot` for making screenshots
|
||||
## Optional dependencies
|
||||
|
||||
- `playerctl` - enables global media control. If not present on your system, only Spotify will work.
|
||||
|
||||
## To do
|
||||
|
||||
- Add a media control widget
|
||||
- Add a network control widget
|
||||
- Manage workspaces
|
||||
- Improve "leave menu"'s design
|
||||
- Modify "start menu"
|
||||
- Make "start menu" and "leave menu" not sticky (they currently stay open and focus even when clicking outside)
|
||||
|
54
media_control.lua
Normal file
54
media_control.lua
Normal file
@ -0,0 +1,54 @@
|
||||
-- Control playing music/media and sound volume
|
||||
-- Currently supports :
|
||||
-- - playerctl
|
||||
-- - Spotify
|
||||
|
||||
-- DEBUG
|
||||
local inspect = require("debug/inspect")
|
||||
|
||||
local awful = require("awful")
|
||||
local naughty = require("naughty")
|
||||
|
||||
local hasPlayerctl = os.execute("playerctl -v") == true
|
||||
|
||||
-- playerctl
|
||||
function sendToPlayerctl(command)
|
||||
os.execute("playerctl " .. command)
|
||||
end
|
||||
|
||||
-- Spotify
|
||||
function sendToSpotify(command)
|
||||
awful.util.spawn_with_shell("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player." .. command)
|
||||
end
|
||||
|
||||
-- {{{ Control
|
||||
local playPause = function()
|
||||
if hasPlayerctl then
|
||||
sendToPlayerctl("play-pause")
|
||||
else
|
||||
sendToSpotify("PlayPause")
|
||||
end
|
||||
end
|
||||
|
||||
local nextTrack = function()
|
||||
if hasPlayerctl then
|
||||
sendToPlayerctl("next")
|
||||
else
|
||||
sendToSpotify("Next")
|
||||
end
|
||||
end
|
||||
|
||||
local previousTrack = function()
|
||||
if hasPlayerctl then
|
||||
sendToPlayerctl("previous")
|
||||
else
|
||||
sendToSpotify("Previous")
|
||||
end
|
||||
end
|
||||
-- }}}
|
||||
|
||||
return {
|
||||
playPause = playPause,
|
||||
nextTrack = nextTrack,
|
||||
previousTrack = previousTrack
|
||||
}
|
15
rc.lua
15
rc.lua
@ -24,6 +24,7 @@ require("awful.hotkeys_popup.keys")
|
||||
-- Simple awesome
|
||||
local config = require("default_config")
|
||||
local tiling = require("tiling")
|
||||
local media_control = require("media_control")
|
||||
|
||||
|
||||
-- {{{ Error handling
|
||||
@ -312,11 +313,6 @@ root.buttons(gears.table.join(
|
||||
globalkeys = gears.table.join(
|
||||
awful.key({ modkey, }, "s", hotkeys_popup.show_help,
|
||||
{description="show help", group="awesome"}),
|
||||
-- awful.key({ modkey, }, "Left", awful.tag.viewprev,
|
||||
-- {description = "view previous", group = "tag"}),
|
||||
-- awful.key({ modkey, }, "Right", awful.tag.viewnext,
|
||||
-- {description = "view next", group = "tag"}),
|
||||
|
||||
|
||||
awful.key({ modkey, }, "Escape", awful.tag.history.restore,
|
||||
{description = "go back", group = "tag"}),
|
||||
@ -421,7 +417,14 @@ globalkeys = gears.table.join(
|
||||
{description = "switch keyboard layout"}),
|
||||
-- Flameshot
|
||||
awful.key({}, "Print", function () os.execute( config.screenshotCmd ) end,
|
||||
{description = "screenshot using the specified command"})
|
||||
{description = "screenshot using the specified command"}),
|
||||
-- Media control
|
||||
awful.key({}, "XF86AudioPlay", media_control.playPause,
|
||||
{description = "Toggle Play / Pause", group="media control"}),
|
||||
awful.key({}, "XF86AudioNext", media_control.nextTrack,
|
||||
{description = "Next track", group="media control"}),
|
||||
awful.key({}, "XF86AudioPrev", media_control.previousTrack,
|
||||
{description = "Previous track", group="media control"})
|
||||
)
|
||||
|
||||
clientkeys = gears.table.join(
|
||||
|
Loading…
Reference in New Issue
Block a user