From 99f0074362a698d7e9dc2070e849394909e820c0 Mon Sep 17 00:00:00 2001 From: Nicolas Berbiche Date: Mon, 28 Dec 2020 20:43:40 -0500 Subject: [PATCH] waybar: allow CSS class when using a default module Fixes #1682 --- modules/programs/waybar.nix | 18 ++++++++++++------ .../waybar/settings-complex-expected.json | 3 ++- .../programs/waybar/settings-complex.nix | 3 ++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/modules/programs/waybar.nix b/modules/programs/waybar.nix index a2b8aa0f..7234278f 100644 --- a/modules/programs/waybar.nix +++ b/modules/programs/waybar.nix @@ -2,9 +2,9 @@ let inherit (lib) - attrByPath attrNames concatMap concatMapStringsSep elem filter filterAttrs - flip foldl' hasPrefix mergeAttrs optionalAttrs stringLength subtractLists - types unique; + any attrByPath attrNames concatMap concatMapStringsSep elem filter + filterAttrs flip foldl' hasPrefix mergeAttrs optionalAttrs removePrefix + stringLength subtractLists types unique; inherit (lib.options) literalExample mkEnableOption mkOption; inherit (lib.modules) mkIf mkMerge; @@ -15,8 +15,10 @@ let jsonFormat = pkgs.formats.json { }; - # Taken from + # Taken from (2020/10/10) + # Order is preserved from the file for easier matching defaultModuleNames = [ + "battery" "sway/mode" "sway/workspaces" "sway/window" @@ -36,11 +38,15 @@ let "sndio" "temperature" "bluetooth" - "battery" ]; + # Allow specifying a CSS class after the default module name + isValidDefaultModuleName = x: + any (name: hasPrefix name x && hasPrefix "#" (removePrefix name x)) + defaultModuleNames; + isValidCustomModuleName = x: - elem x defaultModuleNames || (hasPrefix "custom/" x && stringLength x > 7); + hasPrefix "custom/" x && stringLength x > 7 || isValidDefaultModuleName x; margins = let mkMargin = name: { diff --git a/tests/modules/programs/waybar/settings-complex-expected.json b/tests/modules/programs/waybar/settings-complex-expected.json index 0d020c19..c5c21a6e 100644 --- a/tests/modules/programs/waybar/settings-complex-expected.json +++ b/tests/modules/programs/waybar/settings-complex-expected.json @@ -25,7 +25,8 @@ "memory", "backlight", "tray", - "battery", + "battery#bat1", + "battery#bat2", "clock" ], "output": [ diff --git a/tests/modules/programs/waybar/settings-complex.nix b/tests/modules/programs/waybar/settings-complex.nix index 750e52f4..1756ae12 100644 --- a/tests/modules/programs/waybar/settings-complex.nix +++ b/tests/modules/programs/waybar/settings-complex.nix @@ -24,7 +24,8 @@ in { "memory" "backlight" "tray" - "battery" + "battery#bat1" + "battery#bat2" "clock" ];