diff --git a/personal-gui/wm/sway.nix b/personal-gui/wm/sway.nix
index 651fecc..1c552e0 100644
--- a/personal-gui/wm/sway.nix
+++ b/personal-gui/wm/sway.nix
@@ -21,173 +21,322 @@ with builtins; let
startup = startupNotifications ++ cfg.startup;
in {
- config = mkIf (cfg.enable && cfg.kind == "sway") {
- home.packages = with pkgs;
- [
- sway
- ]
- ++ (
- if cfg.wallpaper != null
- then [pkgs.swaybg]
- else []
- );
+ options = {
+ traxys.waybar = with lib.types; let
+ jsonFormat = pkgs.formats.json {};
- home.sessionVariables = {
- MOZ_ENABLE_WAYLAND = "1";
- XDG_CURRENT_DESKTOP = "sway";
- LIBSEAT_BACKEND = "logind";
- _JAVA_AWT_WM_NONREPARENTING = 1;
- };
+ modulesListOpt = mkOption {
+ type = listOf (submodule {
+ options = {
+ name = mkOption {type = str;};
+ priority = mkOption {
+ type = types.int;
+ };
+ };
+ });
+ default = [];
+ apply = opt:
+ builtins.map (v: v.name) (
+ lib.sortOn (v: v.priority) opt
+ );
+ };
+ in {
+ modules-left = modulesListOpt;
+ modules-center = modulesListOpt;
+ modules-right = modulesListOpt;
- programs.rofi.package = pkgs.rofi-wayland;
-
- services.mako = mkIf cfg.notifications.enable {
- enable = true;
- font = cfg.notifications.font;
- margin = "20,20,5,5";
- defaultTimeout = cfg.notifications.defaultTimeout;
- extraConfig = ''
- [mode=do-not-disturb]
- invisible=1
- '';
- };
-
- programs = {
- waybar = {
- enable = true;
- style = builtins.readFile ./waybar.css;
- settings = [
+ modules = let
+ moduleOpt = {
+ side ? "right",
+ enable ? true,
+ priority,
+ extraOpts ? {},
+ settings,
+ }:
{
- layer = "top";
- position = "bottom";
- modules-left = [
- "network#wifi"
- "sway/workspaces"
- "sway/mode"
- ];
- modules-center = ["sway/window"];
- modules-right = [
- "cpu"
- "memory"
- "disk#home"
- "disk#root"
- "battery"
- "clock"
- "tray"
- "pulseaudio"
- ];
- modules = let
- is = "";
- ie = "";
- in {
- "custom/khal" = {
- format = "{}";
- tooltip = true;
- interval = 300;
- format-icons = {
- default = "";
- };
- exec = "${lib.getExe pkgs.python3} ${./waybar-khal.py}";
- return-type = "json";
- };
- "sway/workspaces" = {
- persistent_workspaces = {
- "" = [];
- "" = [];
- "1:" = [];
- };
- numeric-first = true;
- };
- "network#wifi" = {
- interface = "wlp1s0";
- format-wifi = "{essid} ({signalStrength}%) ";
- };
- cpu = {
- format = "${is}${ie} {load}";
- };
- memory = {
- format = "${is}${ie} {used:.0f}G/{total:.0f}G";
- };
- "sway/window" = {
- max-length = 50;
- };
- "disk#home" = {
- path = "/home";
- format = "${is}${ie} {free}";
- };
- "disk#root" = {
- path = "/";
- format = " {percentage_free}%";
- };
- "battery" = {
- format = "{capacity}% ${is}{icon}${ie}";
- format-icons = ["" "" "" "" ""];
- };
- "clock" = {
- format-alt = "{:%a, %d. %b %H:%M}";
- };
+ enable = mkOption {
+ type = bool;
+ default = enable;
+ };
+
+ side = mkOption {
+ type = enum ["left" "center" "right"];
+ default = side;
+ };
+ priority = mkOption {
+ type = int;
+ default = priority;
+ };
+
+ settings = mkOption {
+ inherit (jsonFormat) type;
+ default = settings;
};
}
- ];
- };
- };
+ // extraOpts;
- wm.printScreen.command = mkDefault "${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp)\" - | ${pkgs.wl-clipboard}/bin/wl-copy -t image/png";
- wm.exit.command = mkDefault "exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'";
+ is = "";
+ ie = "";
+ in {
+ /*
+ Left
+ */
- wayland.windowManager.sway = {
- enable = true;
- extraConfig = mkIf (cfg.wallpaper != null) ''
- output "*" bg ${cfg.wallpaper} fill
- '';
- config = {
- inherit startup;
- modifier = cfg.modifier;
- bars = [
- {
- command = "waybar";
- }
- ];
- input = let
- inputs = config.extraInfo.inputs;
- inputsCfg = [
- (
- if inputs.touchpad != null
- then {
- name = inputs.touchpad;
- value = {dwt = "disable";};
- }
- else null
- )
- {
- name = "type:keyboard";
- value = {
- xkb_layout = "us(dvp),us";
- xkb_options = "compose:102";
- };
- }
- ];
- in
- builtins.listToAttrs (builtins.filter (s: s != null) inputsCfg);
- output = config.extraInfo.outputs;
- fonts = common.mkFont cfg.font;
- window = {
- titlebar = true;
- commands = [
- {
- criteria.class = "davmail-DavGateway";
- command = "floating enable";
- }
- {
- criteria.window_type = "menu";
- command = "floating enable";
- }
- ];
+ "network#wifi" = moduleOpt {
+ side = "left";
+ enable = false;
+ priority = 10;
+ extraOpts = {
+ interface = mkOption {
+ type = str;
+ };
+ };
+ settings = {
+ inherit (config.traxys.waybar.modules."network#wifi") interface;
+ format-wifi = "{essid} ({signalStrength}%) ";
+ };
+ };
+
+ "sway/workspaces" = moduleOpt {
+ side = "left";
+ priority = 20;
+ settings = {
+ persistent-workspaces = {
+ "" = [];
+ "" = [];
+ "1:" = [];
+ };
+ numeric-first = true;
+ };
+ };
+
+ "sway/mode" = moduleOpt {
+ side = "left";
+ priority = 30;
+ settings = {};
+ };
+
+ /*
+ Center
+ */
+
+ "sway/window" = moduleOpt {
+ side = "center";
+ priority = 10;
+ settings = {
+ max-length = 50;
+ };
+ };
+
+ /*
+ Right
+ */
+
+ "cpu" = moduleOpt {
+ priority = 10;
+ settings = {
+ format = "${is}${ie} {load}";
+ };
+ };
+
+ "memory" = moduleOpt {
+ priority = 20;
+ settings = {
+ format = "${is}${ie} {used:.0f}G/{total:.0f}G";
+ };
+ };
+
+ "disk#home" = moduleOpt {
+ priority = 30;
+ settings = {
+ path = "/home";
+ format = "${is}${ie} {free}";
+ };
+ };
+
+ "disk#root" = moduleOpt {
+ priority = 40;
+ settings = {
+ path = "/";
+ format = " {percentage_free}%";
+ };
+ };
+
+ "battery" = moduleOpt {
+ enable = false;
+ priority = 50;
+ settings = {
+ format = "{capacity}% ${is}{icon}${ie}";
+ format-icons = ["" "" "" "" ""];
+ };
+ };
+
+ "custom/khal" = moduleOpt {
+ enable = false;
+ priority = 55;
+ settings = {
+ format = "{}";
+ tooltip = true;
+ interval = 300;
+ format-icons = {
+ default = "";
+ };
+ exec = "${lib.getExe pkgs.python3} ${./waybar-khal.py}";
+ return-type = "json";
+ };
+ };
+
+ "clock" = moduleOpt {
+ priority = 60;
+ settings = {
+ format-alt = "{:%a, %d. %b %H:%M}";
+ };
+ };
+
+ "tray" = moduleOpt {
+ priority = 70;
+ settings = {};
+ };
+
+ "pulseaudio" = moduleOpt {
+ priority = 80;
+ settings = {};
};
- keybindings = common.keybindings;
- workspaceOutputAssign = common.workspaceOutputAssign;
- assigns = common.assigns;
};
};
};
+
+ config = let
+ addKey = key: value: attrs: attrs // {${key} = attrs.${key} // value;};
+ modulesList =
+ lib.foldlAttrs
+ (acc: name: mod: addKey mod.side {${name} = mod;} acc)
+ {
+ center = {};
+ left = {};
+ right = {};
+ }
+ config.traxys.waybar.modules;
+ enabledModulesSide = side: lib.filterAttrs (_: v: v.enable) modulesList.${side};
+ moduleListSide = side:
+ lib.mapAttrsToList (name: v: {
+ inherit name;
+ inherit (v) priority;
+ }) (enabledModulesSide side);
+ in
+ mkIf (cfg.enable && cfg.kind == "sway") {
+ traxys.waybar.modules-left = moduleListSide "left";
+ traxys.waybar.modules-center = moduleListSide "center";
+ traxys.waybar.modules-right = moduleListSide "right";
+
+ home.packages = with pkgs;
+ [
+ sway
+ ]
+ ++ (
+ if cfg.wallpaper != null
+ then [pkgs.swaybg]
+ else []
+ );
+
+ home.sessionVariables = {
+ MOZ_ENABLE_WAYLAND = "1";
+ XDG_CURRENT_DESKTOP = "sway";
+ LIBSEAT_BACKEND = "logind";
+ _JAVA_AWT_WM_NONREPARENTING = 1;
+ };
+
+ programs.rofi.package = pkgs.rofi-wayland;
+
+ services.mako = mkIf cfg.notifications.enable {
+ enable = true;
+ font = cfg.notifications.font;
+ margin = "20,20,5,5";
+ defaultTimeout = cfg.notifications.defaultTimeout;
+ extraConfig = ''
+ [mode=do-not-disturb]
+ invisible=1
+ '';
+ };
+
+ programs = {
+ waybar = {
+ enable = true;
+ style = builtins.readFile ./waybar.css;
+ settings = [
+ (
+ {
+ layer = "top";
+ position = "bottom";
+ inherit (config.traxys.waybar) modules-left;
+ inherit (config.traxys.waybar) modules-center;
+ inherit (config.traxys.waybar) modules-right;
+ }
+ // (
+ builtins.mapAttrs (_: v: v.settings)
+ (lib.filterAttrs (_: v: v.enable) config.traxys.waybar.modules)
+ )
+ )
+ ];
+ };
+ };
+
+ wm.printScreen.command = mkDefault "${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp)\" - | ${pkgs.wl-clipboard}/bin/wl-copy -t image/png";
+ wm.exit.command = mkDefault "exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'";
+
+ wayland.windowManager.sway = {
+ enable = true;
+ extraConfig = mkIf (cfg.wallpaper != null) ''
+ output "*" bg ${cfg.wallpaper} fill
+ '';
+ config = {
+ inherit startup;
+ modifier = cfg.modifier;
+ bars = [
+ {
+ command = "waybar";
+ }
+ ];
+ input = let
+ inputs = config.extraInfo.inputs;
+ inputsCfg = [
+ (
+ if inputs.touchpad != null
+ then {
+ name = inputs.touchpad;
+ value = {dwt = "disable";};
+ }
+ else null
+ )
+ {
+ name = "type:keyboard";
+ value = {
+ xkb_layout = "us(dvp),us";
+ xkb_options = "compose:102";
+ };
+ }
+ ];
+ in
+ builtins.listToAttrs (builtins.filter (s: s != null) inputsCfg);
+ output = config.extraInfo.outputs;
+ fonts = common.mkFont cfg.font;
+ window = {
+ titlebar = true;
+ commands = [
+ {
+ criteria.class = "davmail-DavGateway";
+ command = "floating enable";
+ }
+ {
+ criteria.window_type = "menu";
+ command = "floating enable";
+ }
+ ];
+ };
+ keybindings = common.keybindings;
+ workspaceOutputAssign = common.workspaceOutputAssign;
+ assigns = common.assigns;
+ };
+ };
+ };
}