From 9769aea3b32cdfed7b6dde8c8fccd509af2fe911 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 15 May 2023 02:36:28 +0000 Subject: [PATCH] sway: split waybar-config.nix out from toplevel config --- hosts/modules/gui/sway/default.nix | 67 +----------------------- hosts/modules/gui/sway/waybar-config.nix | 67 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 66 deletions(-) create mode 100644 hosts/modules/gui/sway/waybar-config.nix diff --git a/hosts/modules/gui/sway/default.nix b/hosts/modules/gui/sway/default.nix index 95ab3875..1002df21 100644 --- a/hosts/modules/gui/sway/default.nix +++ b/hosts/modules/gui/sway/default.nix @@ -4,72 +4,7 @@ with lib; let cfg = config.sane.gui.sway; - # docs: https://github.com/Alexays/Waybar/wiki/Configuration - # format specifiers: https://fmt.dev/latest/syntax.html#syntax - waybar-config = [ - { # TOP BAR - layer = "top"; - height = 40; - modules-left = ["sway/workspaces" "sway/mode"]; - modules-center = ["sway/window"]; - modules-right = ["custom/mediaplayer" "clock" "battery" "cpu" "network"]; - "sway/window" = { - max-length = 50; - }; - # include song artist/title. source: https://www.reddit.com/r/swaywm/comments/ni0vso/waybar_spotify_tracktitle/ - "custom/mediaplayer" = { - exec = pkgs.writeShellScript "waybar-mediaplayer" '' - player_status=$(${pkgs.playerctl}/bin/playerctl status 2> /dev/null) - if [ "$player_status" = "Playing" ]; then - echo "$(${pkgs.playerctl}/bin/playerctl metadata artist) - $(${pkgs.playerctl}/bin/playerctl metadata title)" - elif [ "$player_status" = "Paused" ]; then - echo " $(${pkgs.playerctl}/bin/playerctl metadata artist) - $(${pkgs.playerctl}/bin/playerctl metadata title)" - fi - ''; - interval = 2; - format = "{} "; - # return-type = "json"; - on-click = "${pkgs.playerctl}/bin/playerctl play-pause"; - on-scroll-up = "${pkgs.playerctl}/bin/playerctl next"; - on-scroll-down = "${pkgs.playerctl}/bin/playerctl previous"; - }; - network = { - # docs: https://github.com/Alexays/Waybar/blob/master/man/waybar-network.5.scd - interval = 2; - max-length = 40; - # custom :> format specifier explained here: https://github.com/Alexays/Waybar/pull/472 - format-ethernet = " {bandwidthUpBits:>}▲ {bandwidthDownBits:>}▼"; - tooltip-format-ethernet = "{ifname} {bandwidthUpBits:>}▲ {bandwidthDownBits:>}▼"; - - format-wifi = "{ifname} ({signalStrength}%) {bandwidthUpBits:>}▲ {bandwidthDownBits:>}▼"; - tooltip-format-wifi = "{essid} ({signalStrength}%) {bandwidthUpBits:>}▲ {bandwidthDownBits:>}▼"; - - format-disconnected = ""; - }; - cpu = { - format = " {usage:2}%"; - tooltip = false; - }; - battery = { - states = { - good = 95; - warning = 30; - critical = 10; - }; - format = "{icon} {capacity}%"; - format-icons = [ - "" - "" - "" - "" - "" - ]; - }; - clock = { - format-alt = "{:%a, %d. %b %H:%M}"; - }; - } - ]; + waybar-config = import ./waybar-config.nix pkgs; # waybar-config-text = lib.generators.toJSON {} waybar-config; waybar-config-text = (pkgs.formats.json {}).generate "waybar-config.json" waybar-config; diff --git a/hosts/modules/gui/sway/waybar-config.nix b/hosts/modules/gui/sway/waybar-config.nix new file mode 100644 index 00000000..06dfb8b7 --- /dev/null +++ b/hosts/modules/gui/sway/waybar-config.nix @@ -0,0 +1,67 @@ +# docs: https://github.com/Alexays/Waybar/wiki/Configuration +# format specifiers: https://fmt.dev/latest/syntax.html#syntax +pkgs: +[ + { # TOP BAR + layer = "top"; + height = 40; + modules-left = ["sway/workspaces" "sway/mode"]; + modules-center = ["sway/window"]; + modules-right = ["custom/mediaplayer" "clock" "battery" "cpu" "network"]; + "sway/window" = { + max-length = 50; + }; + # include song artist/title. source: https://www.reddit.com/r/swaywm/comments/ni0vso/waybar_spotify_tracktitle/ + "custom/mediaplayer" = { + exec = pkgs.writeShellScript "waybar-mediaplayer" '' + player_status=$(${pkgs.playerctl}/bin/playerctl status 2> /dev/null) + if [ "$player_status" = "Playing" ]; then + echo "$(${pkgs.playerctl}/bin/playerctl metadata artist) - $(${pkgs.playerctl}/bin/playerctl metadata title)" + elif [ "$player_status" = "Paused" ]; then + echo " $(${pkgs.playerctl}/bin/playerctl metadata artist) - $(${pkgs.playerctl}/bin/playerctl metadata title)" + fi + ''; + interval = 2; + format = "{} "; + # return-type = "json"; + on-click = "${pkgs.playerctl}/bin/playerctl play-pause"; + on-scroll-up = "${pkgs.playerctl}/bin/playerctl next"; + on-scroll-down = "${pkgs.playerctl}/bin/playerctl previous"; + }; + network = { + # docs: https://github.com/Alexays/Waybar/blob/master/man/waybar-network.5.scd + interval = 2; + max-length = 40; + # custom :> format specifier explained here: https://github.com/Alexays/Waybar/pull/472 + format-ethernet = " {bandwidthUpBits:>}▲ {bandwidthDownBits:>}▼"; + tooltip-format-ethernet = "{ifname} {bandwidthUpBits:>}▲ {bandwidthDownBits:>}▼"; + + format-wifi = "{ifname} ({signalStrength}%) {bandwidthUpBits:>}▲ {bandwidthDownBits:>}▼"; + tooltip-format-wifi = "{essid} ({signalStrength}%) {bandwidthUpBits:>}▲ {bandwidthDownBits:>}▼"; + + format-disconnected = ""; + }; + cpu = { + format = " {usage:2}%"; + tooltip = false; + }; + battery = { + states = { + good = 95; + warning = 30; + critical = 10; + }; + format = "{icon} {capacity}%"; + format-icons = [ + "" + "" + "" + "" + "" + ]; + }; + clock = { + format-alt = "{:%a, %d. %b %H:%M}"; + }; + } +]