From 2c90e636b519fb48797d0c4025378ef6d7a3c08d Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Tue, 19 Sep 2023 22:08:24 +0200 Subject: [PATCH] pinwheel: Add module for `spotify` --- hosts/pinwheel/configuration.nix | 1 + hosts/pinwheel/home.nix | 1 - hosts/pinwheel/modules/spotify/default.nix | 19 +++++++++ hosts/pinwheel/modules/waybar/default.nix | 46 ++++++++++++++++------ 4 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 hosts/pinwheel/modules/spotify/default.nix diff --git a/hosts/pinwheel/configuration.nix b/hosts/pinwheel/configuration.nix index 610f913..bb1e4ba 100644 --- a/hosts/pinwheel/configuration.nix +++ b/hosts/pinwheel/configuration.nix @@ -27,6 +27,7 @@ ./modules/calibre ./modules/go ./modules/nix + ./modules/spotify ]; nix.settings.experimental-features = [ "nix-command" "flakes" ]; diff --git a/hosts/pinwheel/home.nix b/hosts/pinwheel/home.nix index a4cb213..c23ea9a 100644 --- a/hosts/pinwheel/home.nix +++ b/hosts/pinwheel/home.nix @@ -15,7 +15,6 @@ home.packages = with pkgs; [ gnumake tig - spotify onlyoffice-bin qmk ]; diff --git a/hosts/pinwheel/modules/spotify/default.nix b/hosts/pinwheel/modules/spotify/default.nix new file mode 100644 index 0000000..69a335f --- /dev/null +++ b/hosts/pinwheel/modules/spotify/default.nix @@ -0,0 +1,19 @@ +{ pkgs, ... }: +{ + home-manager.users.alex = { + home.packages = with pkgs; [ + spotify + playerctl + ]; + + wayland.windowManager.hyprland = { + settings = { + bind = [ + "$mod ALT, LEFT, exec, ${pkgs.playerctl}/bin/playerctl -p spotify previous" + "$mod ALT, RIGHT, exec, ${pkgs.playerctl}/bin/playerctl -p spotify next" + "$mod ALT, DOWN, exec, ${pkgs.playerctl}/bin/playerctl -p spotify play-pause" + ]; + }; + }; + }; +} diff --git a/hosts/pinwheel/modules/waybar/default.nix b/hosts/pinwheel/modules/waybar/default.nix index 7faf8fb..2d7f1be 100644 --- a/hosts/pinwheel/modules/waybar/default.nix +++ b/hosts/pinwheel/modules/waybar/default.nix @@ -1,4 +1,28 @@ { pkgs, ... }: +let + spotify-status = pkgs.writeShellScript "spotify-status" '' + STATUS=$(${pkgs.playerctl}/bin/playerctl -p spotify status 2>&1) + + if [ "$STATUS" = "No players found" ]; then + echo " " + else + TITLE=$(${pkgs.playerctl}/bin/playerctl -p spotify metadata xesam:title) + ARTIST=$(${pkgs.playerctl}/bin/playerctl -p spotify metadata xesam:artist) + + case "$STATUS" in + "Playing") + echo " $TITLE - $ARTIST" + ;; + "Paused") + echo " $TITLE - $ARTIST" + ;; + *) + echo " " + ;; + esac + fi + ''; +in { home-manager.users.alex = { programs.waybar = { @@ -16,16 +40,12 @@ ]; modules-left = [ "hyprland/workspaces" ]; - modules-center = [ "custom/hello" ]; - modules-right = [ "tray" "wireplumber" "battery" "clock" ]; + modules-right = [ "custom/spotify" "wireplumber" "battery" "clock" ]; - "custom/hello" = { - format = "hello {}"; - max-length = 40; - interval = "once"; - exec = pkgs.writeShellScript "hello-from-waybar" '' - echo "from within waybar" - ''; + "custom/spotify" = { + exec = spotify-status; + interval = 1; + tooltip = false; }; wireplumber = { @@ -45,7 +65,8 @@ in '' * { - margin-right: 2px; + font-family: 'DejaVuSansM Nerd Font Mono'; + font-size: 20px; } #workspaces button { @@ -72,9 +93,8 @@ background-color: ${background}; } - #custom-hello { - color: ${foreground}; - background-color: ${background}; + #custom-spotify, #wireplumber, #battery, #clock { + margin: 0 12px; } ''; };