From 775181e57001c08e14d6f9b75e355aeeaf456215 Mon Sep 17 00:00:00 2001 From: lelgenio Date: Wed, 8 Feb 2023 17:12:54 -0300 Subject: [PATCH] playerctl: update playerctl config --- scripts/default.nix | 1 + scripts/playerctl-status | 14 ++++++++++++++ user/sway.nix | 14 ++++++++++++-- user/waybar.nix | 23 +++++++---------------- 4 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 scripts/playerctl-status diff --git a/scripts/default.nix b/scripts/default.nix index 74f4f22..de8769e 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -34,6 +34,7 @@ create_scripts showkeys = [ ]; # This will not work unless programs.wshowkeys is enabled systemwide terminal = [ alacritty ]; + playerctl-status = [ playerctl ]; wpass = [ final.wdmenu fd pass sd wl-clipboard wtype ]; screenshotsh = [ capitaine-cursors grim slurp jq sway wl-clipboard xdg-user-dirs ]; diff --git a/scripts/playerctl-status b/scripts/playerctl-status new file mode 100644 index 0000000..754fe5a --- /dev/null +++ b/scripts/playerctl-status @@ -0,0 +1,14 @@ +#!/bin/sh + +PLAYERCTL="playerctl --ignore-player=mpd" + +STATUS="$(env LC_ALL=C $PLAYERCTL status title)" +TITLE="$($PLAYERCTL metadata title)" +ARTIST="$($PLAYERCTL metadata artist)" + +test "$STATUS" = "Playing" \ +&& printf " %s" "$TITLE" \ +&& test -n "$ARTIST" \ +&& printf " - %s" "$ARTIST" + +echo "" diff --git a/user/sway.nix b/user/sway.nix index 2eb99fd..79b2108 100644 --- a/user/sway.nix +++ b/user/sway.nix @@ -136,6 +136,7 @@ in code_binds = lib.mapAttrs' (k: v: lib.nameValuePair "--to-code ${k}" v); return_mode = lib.mapAttrs (k: v: "${v}; mode default"); + playerctl = "exec ${pkgs.playerctl}/bin/playerctl"; in { audio = code_binds @@ -166,11 +167,20 @@ in "Ctrl+c" = "exec musmenu pclear"; }; playerctl = code_binds + ((locked_binds + { + ${key.left} = "${playerctl} previous"; + ${key.right} = "${playerctl} next"; + ${key.up} = "${playerctl} volume 10+"; + ${key.down} = "${playerctl} volume 10-"; + ${key.tabR} = "${playerctl} volume 10+"; + ${key.tabL} = "${playerctl} volume 10-"; + }) // (return_mode { - "space" = "exec ${pkgs.playerctl}/bin/playerctl toggle"; + "space" = "${playerctl} play-pause"; "escape" = ""; "q" = ""; - }); + })); passthrough = { "${mod}+escape" = "mode default;exec notify-send 'Passthrough off'"; }; diff --git a/user/waybar.nix b/user/waybar.nix index 862247c..9bb9d0f 100644 --- a/user/waybar.nix +++ b/user/waybar.nix @@ -94,22 +94,13 @@ in on-scroll-up = "${mpc} vol +10"; on-scroll-down = "${mpc} vol -10"; }; - "custom/playerctl" = - let - playerctl = "${pkgs.playerctl}/bin/playerctl --ignore-player=mpd"; - statusScript = pkgs.writeShellScript "waybar-playerctl-status" '' - test "$(env LC_ALL=C ${playerctl} status title)" = "Playing" \ - && ${playerctl} metadata title \ - || echo "" - ''; - in - { - format = "{}"; - exec = "${statusScript}"; - on-click = "${playerctl} play-pause"; - interval = 1; - tooltip = false; - }; + "custom/playerctl" = { + format = "{}"; + exec = "${pkgs.playerctl-status}/bin/playerctl-status"; + on-click = "${pkgs.playerctl}/bin/playerctl --ignore-player=mpd play-pause"; + interval = 1; + tooltip = false; + }; "sway/language" = { format = "{short} {variant}"; }; "custom/caffeine" = { format = "{}";