From cff3debfdbe4fc02c37737a3ac443c24b238e269 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Wed, 24 Jul 2019 07:08:20 +0200 Subject: [PATCH] Add media control support with playerctl or default to dbus on Spotify --- README.md | 16 ++++++++++++-- media_control.lua | 54 +++++++++++++++++++++++++++++++++++++++++++++++ rc.lua | 15 +++++++------ 3 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 media_control.lua diff --git a/README.md b/README.md index e2d3052..a7d2c53 100644 --- a/README.md +++ b/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) diff --git a/media_control.lua b/media_control.lua new file mode 100644 index 0000000..edc8452 --- /dev/null +++ b/media_control.lua @@ -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 +} \ No newline at end of file diff --git a/rc.lua b/rc.lua index 4c69fcd..4d5ee50 100644 --- a/rc.lua +++ b/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(