From fd6c12bfd7f9dd0987d5ce5cd749b34bd9f817ad Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sun, 2 Jun 2024 21:15:43 +0530 Subject: [PATCH] sway: add settings option --- .../services/window-managers/i3-sway/sway.nix | 146 +++++++++++------- 1 file changed, 89 insertions(+), 57 deletions(-) diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index 8e3d3aa3..4eafed2d 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -272,63 +272,73 @@ let ${pkgs.xvfb-run}/bin/xvfb-run ${swayPackage}/bin/sway --config "$target" --validate --unsupported-gpu ''; - text = concatStringsSep "\n" - ((optional (cfg.extraConfigEarly != "") cfg.extraConfigEarly) - ++ (if cfg.config != null then - with cfg.config; - ([ - (fontConfigStr fonts) - "floating_modifier ${floating.modifier}" - (windowBorderString window floating) - "hide_edge_borders ${window.hideEdgeBorders}" - "focus_wrapping ${focus.wrapping}" - "focus_follows_mouse ${focus.followMouse}" - "focus_on_window_activation ${focus.newWindow}" - "mouse_warping ${ - if builtins.isString (focus.mouseWarping) then - focus.mouseWarping - else if focus.mouseWarping then - "output" - else - "none" - }" - "workspace_layout ${workspaceLayout}" - "workspace_auto_back_and_forth ${ - lib.hm.booleans.yesNo workspaceAutoBackAndForth - }" - "client.focused ${colorSetStr colors.focused}" - "client.focused_inactive ${colorSetStr colors.focusedInactive}" - "client.unfocused ${colorSetStr colors.unfocused}" - "client.urgent ${colorSetStr colors.urgent}" - "client.placeholder ${colorSetStr colors.placeholder}" - "client.background ${colors.background}" - (keybindingsStr { - keybindings = keybindingDefaultWorkspace; - bindsymArgs = - lib.optionalString (cfg.config.bindkeysToCode) "--to-code"; - }) - (keybindingsStr { - keybindings = keybindingsRest; - bindsymArgs = - lib.optionalString (cfg.config.bindkeysToCode) "--to-code"; - }) - (keycodebindingsStr keycodebindings) - ] ++ mapAttrsToList inputStr input - ++ mapAttrsToList outputStr output # outputs - ++ mapAttrsToList seatStr seat # seats - ++ mapAttrsToList (modeStr cfg.config.bindkeysToCode) modes # modes - ++ mapAttrsToList assignStr assigns # assigns - ++ map barStr bars # bars - ++ optional (gaps != null) gapsStr # gaps - ++ map floatingCriteriaStr floating.criteria # floating - ++ map windowCommandsStr window.commands # window commands - ++ map startupEntryStr startup # startup - ++ map workspaceOutputStr workspaceOutputAssign # custom mapping - ) - else - [ ]) ++ (optional cfg.systemd.enable systemdActivation) - ++ (optional (!cfg.xwayland) "xwayland disable") - ++ [ cfg.extraConfig ]); + text = let + # include and set should be at the top of the configuration + setSettings = lib.filterAttrs (key: _: key == "set") cfg.settings; + includeSettings = lib.filterAttrs (key: _: key == "include") cfg.settings; + otherSettings = + lib.filterAttrs (key: _: key != "set" && key != "include") cfg.settings; + in lib.optionalString (setSettings != { }) + (lib.hm.generators.toSwayConf { } setSettings) + + lib.optionalString (includeSettings != { }) + (lib.hm.generators.toSwayConf { } includeSettings) + + lib.optionalString (otherSettings != { }) + (lib.hm.generators.toSwayConf { } otherSettings) + concatStringsSep "\n" + ((optional (cfg.extraConfigEarly != "") cfg.extraConfigEarly) + ++ (if cfg.config != null then + with cfg.config; + ([ + (fontConfigStr fonts) + "floating_modifier ${floating.modifier}" + (windowBorderString window floating) + "hide_edge_borders ${window.hideEdgeBorders}" + "focus_wrapping ${focus.wrapping}" + "focus_follows_mouse ${focus.followMouse}" + "focus_on_window_activation ${focus.newWindow}" + "mouse_warping ${ + if builtins.isString (focus.mouseWarping) then + focus.mouseWarping + else if focus.mouseWarping then + "output" + else + "none" + }" + "workspace_layout ${workspaceLayout}" + "workspace_auto_back_and_forth ${ + lib.hm.booleans.yesNo workspaceAutoBackAndForth + }" + "client.focused ${colorSetStr colors.focused}" + "client.focused_inactive ${colorSetStr colors.focusedInactive}" + "client.unfocused ${colorSetStr colors.unfocused}" + "client.urgent ${colorSetStr colors.urgent}" + "client.placeholder ${colorSetStr colors.placeholder}" + "client.background ${colors.background}" + (keybindingsStr { + keybindings = keybindingDefaultWorkspace; + bindsymArgs = + lib.optionalString (cfg.config.bindkeysToCode) "--to-code"; + }) + (keybindingsStr { + keybindings = keybindingsRest; + bindsymArgs = + lib.optionalString (cfg.config.bindkeysToCode) "--to-code"; + }) + (keycodebindingsStr keycodebindings) + ] ++ mapAttrsToList inputStr input + ++ mapAttrsToList outputStr output # outputs + ++ mapAttrsToList seatStr seat # seats + ++ mapAttrsToList (modeStr cfg.config.bindkeysToCode) modes # modes + ++ mapAttrsToList assignStr assigns # assigns + ++ map barStr bars # bars + ++ optional (gaps != null) gapsStr # gaps + ++ map floatingCriteriaStr floating.criteria # floating + ++ map windowCommandsStr window.commands # window commands + ++ map startupEntryStr startup # startup + ++ map workspaceOutputStr workspaceOutputAssign # custom mapping + ) + else + [ ]) ++ (optional cfg.systemd.enable systemdActivation) + ++ (optional (!cfg.xwayland) "xwayland disable") ++ [ cfg.extraConfig ]); }; defaultSwayPackage = pkgs.sway.override { @@ -473,6 +483,20 @@ in { ''; }; + settings = lib.mkOption { + type = with lib.types; + let + valueType = + oneOf [ int float str path (listOf str) (attrsOf valueType) ] // { + description = "Sway configuration value"; + }; + in valueType; + default = { }; + description = '' + Configuration for `sway`. See `sway(5)` for supported values. + ''; + }; + config = mkOption { type = types.nullOr configModule; default = { }; @@ -518,6 +542,14 @@ in { assertions = [ (hm.assertions.assertPlatform "wayland.windowManager.sway" pkgs platforms.linux) + { + assertion = cfg.settings != { } -> cfg.extraConfigEarly == ""; + message = '' + `wayland.windowManager.sway.extraConfigEarly` is not needed when + using `wayland.windowManager.sway.settings`, it'll properly handle + `set` and `include` configuration. + ''; + } ]; home.packages = optional (cfg.package != null) cfg.package