Skip to content

Commit

Permalink
hyprland: change plugins settings generation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SamueleFacenda committed Jan 20, 2024
1 parent ce4b88c commit 9b378af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
31 changes: 16 additions & 15 deletions modules/services/window-managers/hyprland.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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) ''
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9b378af

Please sign in to comment.