os/shared/home/gui/sway.nix

106 lines
2.8 KiB
Nix
Raw Normal View History

2023-05-21 21:15:04 +02:00
{ pkgs, lib, config, ... }:
2023-05-24 11:32:54 +02:00
let mod = "Mod4";
cfg = config.custom.gui.sway;
# Generate the workspace keybinds
genWorkspaces = { numbered, named }: with lib; (
let nums = genAttrs (map toString (range 1 (min numbered 9))) id;
genBindings = (num: key: {
"${mod}+${key}" = "workspace ${num}";
"${mod}+Shift+${key}" = "move window to workspace ${num}";
});
keybinds = mapAttrsToList genBindings (nums // named);
in mkMerge keybinds
);
2023-05-21 21:15:04 +02:00
in with lib; {
2023-05-24 11:32:54 +02:00
options.custom.gui.sway = with types; {
2023-05-21 21:15:04 +02:00
enable = mkEnableOption "sway window manager";
2023-05-24 11:32:54 +02:00
workspaces.named = mkOption {
type = attrsOf str;
default = {};
};
workspaces.numbered = mkOption {
type = int;
default = 5;
};
2023-05-21 21:15:04 +02:00
};
config = mkIf (cfg.enable) {
2023-05-22 17:38:39 +02:00
home.packages = with pkgs; [
wl-clipboard
(writeScriptBin "c" ''
${wl-clipboard}/bin/wl-copy
'')
(writeScriptBin "p" ''
${wl-clipboard}/bin/wl-paste
'')
];
programs.swaylock.enable = true;
programs.waybar.enable = true;
services.swayidle.enable = true;
2023-05-21 21:15:04 +02:00
wayland.windowManager.sway = {
# This is all required to get it to not die.
enable = true;
extraSessionCommands = "export WLR_NO_HARDWARE_CURSORS=1";
extraOptions = [ "--unsupported-gpu" ];
2023-05-22 17:38:39 +02:00
config = rec {
2023-05-22 00:45:36 +02:00
output."*".bg = "${../../data/wallpaper.jpg} fill";
2023-05-22 17:38:39 +02:00
input."type:keyboard".xkb_options = "caps:escape";
2023-05-22 00:45:36 +02:00
terminal = "${pkgs.kitty}/bin/kitty";
2023-05-22 17:38:39 +02:00
# Directional keys
2023-05-24 11:32:54 +02:00
modifier = mod;
2023-05-22 17:38:39 +02:00
fonts = {
names = [ "Fira Code" ];
size = 8.0;
};
keybindings = mkMerge [
(genWorkspaces { inherit (cfg.workspaces) numbered named; })
{
"${mod}+h" = "focus left";
"${mod}+j" = "focus down";
"${mod}+k" = "focus up";
"${mod}+l" = "focus right";
"${mod}+Shift+h" = "move left";
"${mod}+Shift+j" = "move down";
"${mod}+Shift+k" = "move up";
"${mod}+Shift+l" = "move right";
"${mod}+a" = "split v";
"${mod}+s" = "split h";
"${mod}+f" = "fullscreen toggle";
"${mod}+Alt+a" = "layout toggle stacking splitv";
"${mod}+Alt+s" = "layout toggle tabbed splith";
"${mod}+Return" = "exec ${terminal}";
"${mod}+Escape" = "exec ${pkgs.swaylock}/bin/swaylock";
"${mod}+Tab" = "exec ${pkgs.firefox}/bin/firefox";
"${mod}+Backspace" = "mode kill";
}
];
2023-05-22 17:38:39 +02:00
modes."kill" = {
Backspace = "kill; mode default";
Escape = "mode default";
};
window.titlebar = true;
2023-05-22 00:45:36 +02:00
};
2023-05-21 21:15:04 +02:00
};
};
}