From 9b378afae72cb07471e19aefc30e8e05ef2d7a61 Mon Sep 17 00:00:00 2001 From: Samuele Facenda Date: Sun, 21 Jan 2024 00:40:55 +0100 Subject: [PATCH] hyprland: change plugins settings generation The previous syntax (`plugin:name { ...settings}`) is not working with more than one plugin. There is no documentation for this, just the source code [1]. With this update the plugins paths aren't generated together with the full config (so the "plugin" field is not "important" anymore) and the plugins settings are generated like the other fields. [1] https://github.com/hyprwm/Hyprland/blob/4d403dac3244aab217fb9bf17a68e9a009fcadd8/src/config/ConfigManager.cpp#L1574 --- modules/services/window-managers/hyprland.nix | 31 ++++++++++--------- .../hyprland/simple-config.conf | 14 +++++---- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/modules/services/window-managers/hyprland.nix b/modules/services/window-managers/hyprland.nix index d677eda75..65cf0c316 100644 --- a/modules/services/window-managers/hyprland.nix +++ b/modules/services/window-managers/hyprland.nix @@ -199,19 +199,8 @@ in { home.packages = lib.optional (cfg.package != null) cfg.finalPackage; xdg.configFile."hypr/hyprland.conf" = let - combinedSettings = cfg.settings // { - plugin = let - mkEntry = entry: - if lib.types.package.check entry then - "${entry}/lib/lib${entry.pname}.so" - else - entry; - in map mkEntry cfg.plugins; - } // lib.mapAttrs' (n: v: lib.nameValuePair "plugin:${n}" v) - (lib.attrByPath [ "plugin" ] { } cfg.settings); - shouldGenerate = cfg.systemd.enable || cfg.extraConfig != "" - || combinedSettings != { }; + || cfg.settings != { } || cfg.plugins != [ ]; toHyprconf = with lib; attrs: indentLevel: @@ -230,17 +219,29 @@ in { }; allFields = filterAttrs (n: v: !(isAttrs v)) attrs; importantFields = filterAttrs (n: _: - (hasPrefix "$" n) || (hasPrefix "bezier" n) || (n == "plugin") + (hasPrefix "$" n) || (hasPrefix "bezier" n) || (cfg.sourceFirst && (hasPrefix "source" n))) allFields; fields = builtins.removeAttrs allFields (mapAttrsToList (n: _: n) importantFields); in mkFields importantFields + concatStringsSep "\n" (mapAttrsToList mkSection sections) + mkFields fields; + + pluginsToHyprconf = plugins: + toHyprconf { + plugin = let + mkEntry = entry: + if lib.types.package.check entry then + "${entry}/lib/lib${entry.pname}.so" + else + entry; + in map mkEntry cfg.plugins; + } 0; in lib.mkIf shouldGenerate { text = lib.optionalString cfg.systemd.enable systemdActivation - + lib.optionalString (combinedSettings != { }) - (toHyprconf combinedSettings 0) + + lib.optionalString (cfg.plugins != [ ]) + (pluginsToHyprconf cfg.plugins) + + lib.optionalString (cfg.settings != { }) (toHyprconf cfg.settings 0) + lib.optionalString (cfg.extraConfig != "") cfg.extraConfig; onChange = lib.mkIf (cfg.package != null) '' diff --git a/tests/modules/services/window-managers/hyprland/simple-config.conf b/tests/modules/services/window-managers/hyprland/simple-config.conf index 4df744135..0db599a31 100644 --- a/tests/modules/services/window-managers/hyprland/simple-config.conf +++ b/tests/modules/services/window-managers/hyprland/simple-config.conf @@ -1,10 +1,10 @@ exec-once = /nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY HYPRLAND_INSTANCE_SIGNATURE WAYLAND_DISPLAY XDG_CURRENT_DESKTOP && systemctl --user stop hyprland-session.target && systemctl --user start hyprland-session.target +plugin=/path/to/plugin1 +plugin=/nix/store/00000000000000000000000000000000-foo/lib/libfoo.so $mod=SUPER bezier=smoothOut, 0.36, 0, 0.66, -0.56 bezier=smoothIn, 0.25, 1, 0.5, 1 bezier=overshot, 0.4,0.8,0.2,1.2 -plugin=/path/to/plugin1 -plugin=/nix/store/00000000000000000000000000000000-foo/lib/libfoo.so source=sourced.conf animations { animation=border, 1, 2, smoothIn @@ -27,11 +27,13 @@ input { kb_layout=ro } -plugin:plugin1 { - section { - other=dummy setting +plugin { + plugin1 { + section { + other=dummy setting + } + dummy=plugin setting } - dummy=plugin setting } bindm=$mod, mouse:272, movewindow bindm=$mod, mouse:273, resizewindow