add support for sway modes

This commit is contained in:
LordGrimmauld 2024-04-10 16:42:11 +02:00
parent dd7b143833
commit e8abbd0c1f
3 changed files with 95 additions and 68 deletions

View file

@ -2,13 +2,10 @@
cfg = config.grimmShared; cfg = config.grimmShared;
in { in {
config = let 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" ( waybar_full = pkgs.writeShellScriptBin "waybar-full" (
"${config.programs.waybar.package}/bin/waybar" "${config.programs.waybar.package}/bin/waybar"
+ (if isNull cfg.sway.barConfig then "" else " -c ${cfg.sway.barConfig}") + (if isNull cfg.sway.bar.config then "" else " -c ${cfg.sway.bar.config}")
+ (if isNull cfg.sway.barStyle then "" else " -s ${cfg.sway.barStyle}") + (if isNull cfg.sway.bar.style then "" else " -s ${cfg.sway.bar.style}")
); );
bar_config = '' bar_config = ''
@ -16,13 +13,26 @@ bar {
swaybar_command ${waybar_full}/bin/waybar-full swaybar_command ${waybar_full}/bin/waybar-full
} }
''; '';
text = lib.strings.concatLines [
(lib.strings.concatLines (build_definition_lines cfg.sway.definitions)) build_conf = sway_conf : let
(lib.strings.concatLines (build_keybind_lines cfg.sway.keybinds)) build_definition_lines = lib.mapAttrsToList (name: value: "set \$${name} ${value}");
(lib.strings.concatLines (build_exec_lines cfg.sway.autolaunch)) build_keybind_lines = lib.mapAttrsToList (key: value: "bindsym ${key} ${value}");
cfg.sway.extraConfig build_exec_lines = map (item: "exec " + item);
bar_config 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; sway_conf = pkgs.writeText "sway.conf" text;
in with cfg; lib.mkIf (enable && sway.enable) { in with cfg; lib.mkIf (enable && sway.enable) {

View file

@ -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 { in {
options.grimmShared = { options.grimmShared = {
enable = mkEnableOption "grimm-shared-common"; enable = mkEnableOption "grimm-shared-common";
@ -103,40 +137,25 @@ in {
sway = { sway = {
enable = mkEnableOption "grimm-sway"; enable = mkEnableOption "grimm-sway";
definitions = mkOption { bar = {
type = types.attrsOf types.str; enable = mkEnableOption "grimm-sway-bar";
default = {};
description = "set of definitions assigning variable to value"; 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 { config = mkOption {
type = types.attrsOf types.str; type = sway_conf;
default = {}; description = "sway config to use";
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";
}; };
}; };

View file

@ -13,9 +13,13 @@
grimmShared.sway = { grimmShared.sway = {
enable = true; enable = true;
barConfig = ./bar/config; bar = {
barStyle = ./bar/style.css; enable = true;
config = ./bar/config;
style = ./bar/style.css;
};
config = {
definitions = { definitions = {
mod = "Mod4"; mod = "Mod4";
left = "h"; left = "h";
@ -142,7 +146,6 @@
"systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP" "systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP"
]; ];
extraConfig = '' extraConfig = ''
# fixme: wallpaper
output * bg ${./wallpapers/switzerland.jpg} fill output * bg ${./wallpapers/switzerland.jpg} fill
output HDMI-A-1 mode 1920x1080@60Hz position 0,0 output HDMI-A-1 mode 1920x1080@60Hz position 0,0
for_window [app_id="lxqt-policykit-agent"] floating enable; 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="swaymux"] floating enable
for_window [app_id="rmenu"] 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\"";
};
};
}; };
} }