diff --git a/common/sway.nix b/common/sway.nix index 5687423..78506c0 100644 --- a/common/sway.nix +++ b/common/sway.nix @@ -2,13 +2,10 @@ cfg = config.grimmShared; in { config = let - build_definition_lines = lib.mapAttrsToList (name: value: "set \$${name} ${value}"); - build_keybind_lines = lib.mapAttrsToList (key: value: "bindsym ${key} ${value}"); - build_exec_lines = map (item: "exec " + item); waybar_full = pkgs.writeShellScriptBin "waybar-full" ( "${config.programs.waybar.package}/bin/waybar" - + (if isNull cfg.sway.barConfig then "" else " -c ${cfg.sway.barConfig}") - + (if isNull cfg.sway.barStyle then "" else " -s ${cfg.sway.barStyle}") + + (if isNull cfg.sway.bar.config then "" else " -c ${cfg.sway.bar.config}") + + (if isNull cfg.sway.bar.style then "" else " -s ${cfg.sway.bar.style}") ); bar_config = '' @@ -16,13 +13,26 @@ bar { swaybar_command ${waybar_full}/bin/waybar-full } ''; - text = lib.strings.concatLines [ - (lib.strings.concatLines (build_definition_lines cfg.sway.definitions)) - (lib.strings.concatLines (build_keybind_lines cfg.sway.keybinds)) - (lib.strings.concatLines (build_exec_lines cfg.sway.autolaunch)) - cfg.sway.extraConfig - bar_config - ]; + + build_conf = sway_conf : let + build_definition_lines = lib.mapAttrsToList (name: value: "set \$${name} ${value}"); + build_keybind_lines = lib.mapAttrsToList (key: value: "bindsym ${key} ${value}"); + build_exec_lines = map (item: "exec " + item); + build_mode_lines = lib.mapAttrsToList (name: value: '' +mode "${name}" { +${lib.strings.concatLines (map (item: " " + item ) (build_conf value))}}''); + in ([] + ++ (build_definition_lines sway_conf.definitions) + ++ (build_keybind_lines sway_conf.keybinds) + ++ (build_exec_lines sway_conf.autolaunch) + ++ (build_mode_lines sway_conf.modes) + ++ lib.optional (sway_conf.extraConfig != "") sway_conf.extraConfig + ); + + text = lib.strings.concatLines ( + (build_conf cfg.sway.config) + ++ lib.optional cfg.sway.bar.enable bar_config + ); sway_conf = pkgs.writeText "sway.conf" text; in with cfg; lib.mkIf (enable && sway.enable) { diff --git a/load_common.nix b/load_common.nix index 9513414..fccc95d 100644 --- a/load_common.nix +++ b/load_common.nix @@ -16,6 +16,40 @@ let }; }; }); + + sway_conf = types.submodule ({config, ...} : rec { + options = { + keybinds = mkOption { + type = types.attrsOf types.str; + default = {}; + description = "set of keybinds assigning key combo to action"; + }; + + autolaunch = mkOption { + type = types.listOf types.str; + default = []; + description = "set of commands to be run at sway startup"; + }; + + extraConfig = mkOption { + type = types.str; + default = ""; + description = "additional sway config to be included"; + }; + + definitions = mkOption { + type = types.attrsOf types.str; + default = {}; + description = "set of definitions assigning variable to value"; + }; + + modes = mkOption { + type = types.attrsOf sway_conf; + default = {}; + description = "possible modes to switch to, e.g. resize"; + }; + }; + }); in { options.grimmShared = { enable = mkEnableOption "grimm-shared-common"; @@ -103,40 +137,25 @@ in { sway = { enable = mkEnableOption "grimm-sway"; - definitions = mkOption { - type = types.attrsOf types.str; - default = {}; - description = "set of definitions assigning variable to value"; + bar = { + enable = mkEnableOption "grimm-sway-bar"; + + style = mkOption { + type = types.nullOr types.path; + default = null; + description = "waybar style sheet to use"; + }; + + config = mkOption { + type = types.nullOr types.path; + default = null; + description = "waybar config to use"; + }; }; - keybinds = mkOption { - type = types.attrsOf types.str; - default = {}; - description = "set of keybinds assigning key combo to action"; - }; - - autolaunch = mkOption { - type = types.listOf types.str; - default = []; - description = "set of commands to be run at sway startup"; - }; - - extraConfig = mkOption { - type = types.str; - default = ""; - description = "additional sway config to be included"; - }; - - barStyle = mkOption { - type = types.nullOr types.path; - default = null; - description = "waybar style sheet to use"; - }; - - barConfig = mkOption { - type = types.nullOr types.path; - default = null; - description = "waybar config to use"; + config = mkOption { + type = sway_conf; + description = "sway config to use"; }; }; diff --git a/sway/sway-conf.nix b/sway/sway-conf.nix index 02f5008..767e9f8 100644 --- a/sway/sway-conf.nix +++ b/sway/sway-conf.nix @@ -13,9 +13,13 @@ grimmShared.sway = { enable = true; - barConfig = ./bar/config; - barStyle = ./bar/style.css; + bar = { + enable = true; + config = ./bar/config; + style = ./bar/style.css; + }; + config = { definitions = { mod = "Mod4"; left = "h"; @@ -142,7 +146,6 @@ "systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP" ]; extraConfig = '' -# fixme: wallpaper output * bg ${./wallpapers/switzerland.jpg} fill output HDMI-A-1 mode 1920x1080@60Hz position 0,0 for_window [app_id="lxqt-policykit-agent"] floating enable; @@ -168,28 +171,23 @@ input * { for_window [app_id="swaymux"] floating enable for_window [app_id="rmenu"] floating enable - -mode "resize" { - # left will shrink the containers width - # right will grow the containers width - # up will shrink the containers height - # down will grow the containers height - bindsym $left resize shrrnk width 10px - bindsym $down resize grow height 10px - bindsym $up resize shrink height 10px - bindsym $right resize grow width 10px - - # Ditto, with arrow keys - bindsym Left resize shrink width 10px - bindsym Down resize grow height 10px - bindsym Up resize shrink height 10px - bindsym Right resize grow width 10px - - # Return to default mode - bindsym Return mode "default" - bindsym Escape mode "default" -} ''; + + modes.resize.keybinds = { + "$left" = "resize shrink width 10px"; + "$down" = "resize grow height 10px"; + "$up" = "resize shrink height 10px"; + "$right" = "resize grow width 10px"; + + Left = "resize shrink width 10px"; + Down = "resize grow height 10px"; + Up = "resize shrink height 10px"; + Right = "resize grow width 10px"; + + Return = "mode \"default\""; + Escape = "mode \"default\""; + }; + }; }; }