nixos-config/home-manager/modules/sway.nix
2025-02-27 21:34:01 +01:00

220 lines
7.7 KiB
Nix

{
pkgs,
nixosConfig,
lib,
...
}:
let
lockCmd = "${pkgs.gtklock}/bin/gtklock";
in
{
wayland.windowManager.sway = {
enable = true;
wrapperFeatures.gtk = true;
# Sway can't find wallpaper.jpg and failes to build
# https://discourse.nixos.org/t/sway-fails-with-cannot-create-gles2-renderer-after-update/45703/2
checkConfig = false;
config = {
modifier = "Mod4";
focus.followMouse = false;
input = {
"type:keyboard" = {
xkb_layout = "eu";
};
"type:mouse" = {
pointer_accel = "-1";
};
"type:touchpad" = {
tap = "enabled";
};
};
output =
{
"*".bg = "/etc/nixos/wallpaper.jpg fill";
}
// lib.optionalAttrs (nixosConfig.networking.hostName == "cray") {
"DP-1" = {
mode = "3840x2160";
scale = "1.3";
position = "0,0";
};
"DP-3" = {
mode = "3840x2160";
scale = "1.3";
position = "2953,0";
};
};
gaps = {
inner = 5;
};
window.border = 2;
window.hideEdgeBorders = "smart";
workspaceAutoBackAndForth = true;
terminal = "foot";
colors = {
focused = {
border = "#4c7899";
background = "#285577";
text = "#ffffff";
indicator = "#2e9ef4";
childBorder = "#285577";
};
focusedInactive = {
border = "#333333";
background = "#5f676a";
text = "#ffffff";
indicator = "#484e50";
childBorder = "#5f676a";
};
unfocused = {
border = "#333333";
background = "#222222";
text = "#888888";
indicator = "#292d2e";
childBorder = "#900000";
};
urgent = {
border = "#2f343a";
background = "#900000";
text = "#ffffff";
indicator = "#900000";
childBorder = "#900000";
};
placeholder = {
border = "#000000";
background = "#0c0c0c";
text = "#ffffff";
indicator = "#000000";
childBorder = "#0c0c0c";
};
};
bars = [{ command = "${pkgs.waybar}/bin/waybar"; }];
startup = [
{ command = "${pkgs.swaynotificationcenter}/bin/swaync"; }
{
command = ''
${pkgs.swayidle}/bin/swayidle -w \
timeout 600 "${lockCmd}" \
timeout 900 "${pkgs.sway}/bin/swaymsg output * dpms off" \
resume "${pkgs.sway}/bin/swaymsg output * dpms on" \
before-sleep "${lockCmd}"'';
}
];
keybindings =
let
mod = "Mod4";
pactl = "${pkgs.pulseaudio}/bin/pactl";
playerctl = "${pkgs.playerctl}/bin/playerctl";
in
{
"${mod}+Return" = "exec foot";
"${mod}+p" = "exec ${pkgs.nwg-drawer}/bin/nwg-drawer";
"${mod}+Shift+c" = "reload";
"${mod}+Shift+q" = "kill";
"${mod}+Shift+e" =
"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'";
"${mod}+x" = "move workspace to output right";
"${mod}+n" = "exec ${pkgs.swaynotificationcenter}/bin/swaync-client -t";
"${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}+s" = "split v";
"${mod}+w" = "split h";
"${mod}+t" = "layout tabbed";
"${mod}+r" = "mode resize";
"${mod}+f" = "fullscreen toggle";
"${mod}+Shift+space" = "floating toggle";
"${mod}+1" = "workspace 1";
"${mod}+2" = "workspace 2";
"${mod}+3" = "workspace 3";
"${mod}+4" = "workspace 4";
"${mod}+5" = "workspace 5";
"${mod}+6" = "workspace 6";
"${mod}+7" = "workspace 7";
"${mod}+8" = "workspace 8";
"${mod}+9" = "workspace 9";
"${mod}+0" = "workspace 10";
"${mod}+Shift+1" = "move container to workspace 1";
"${mod}+Shift+2" = "move container to workspace 2";
"${mod}+Shift+3" = "move container to workspace 3";
"${mod}+Shift+4" = "move container to workspace 4";
"${mod}+Shift+5" = "move container to workspace 5";
"${mod}+Shift+6" = "move container to workspace 6";
"${mod}+Shift+7" = "move container to workspace 7";
"${mod}+Shift+8" = "move container to workspace 8";
"${mod}+Shift+9" = "move container to workspace 9";
"${mod}+Shift+0" = "move container to workspace 10";
## MacroPad
# Print, Pause, AudioRaiseVolume
"Print" = "exec grimshot save area";
"Pause" = "exec systemctl suspend";
"XF86AudioRaiseVolume" = "exec ${pactl} set-sink-volume @DEFAULT_SINK@ +5%";
# Tools, AudioMute, AudioLowerVolume
"XF86Tools" = "exec ${lockCmd}";
"XF86AudioMute" = "exec ${pactl} set-sink-mute @DEFAULT_SINK@ toggle";
"XF86AudioLowerVolume" = "exec ${pactl} set-sink-volume @DEFAULT_SINK@ -5%";
# AudioPrev, AudioPlay, AudioNext
"XF86AudioNext" = "exec ${playerctl} next";
"XF86AudioPlay" = "exec ${playerctl} play-pause";
"XF86AudioPrev" = "exec ${playerctl} previous";
# Laptop Brightness controll
"XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set +10%";
"XF86MonBrightnessDown" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set 10%-";
# Lockscreen on laptop without macropad
"Control+Escape" = "exec ${lockCmd}";
};
};
extraConfig = ''
# Display window as floating. Find out wayland app_id with "swaymsg -t get_tree | jq '.' | grep app_id" and xorg class with xprop
# mostly stolen from https://github.com/madic-creates/Sway-DE/blob/master/config/sway/sway.d/06_floating.conf
for_window [app_id = "floating"] floating enable
for_window [app_id = "floating_update"] floating enable, resize set width 1000px height 600px
for_window [app_id = "firefox" title="Library"] floating enable, border pixel 1, sticky enable
for_window [title = "Extension: (Bitwarden Password Manager) - Bitwarden Mozilla Firefox"] floating enable
for_window [app_id = "wdisplays"] floating enable, resize set width 1150px height 480px
for_window [class = "(?i)pinentry"] floating enable
for_window [title = "(?:Open|Save) (?:File|Folder|As)"] floating enable, resize set width 1030 height 710
for_window [title = "About Mozilla Firefox"] floating enable
for_window [title = "Firefox - Choose User Profile" ] floating enable
for_window [title = "Firefox Sharing Indicator"] floating enable
for_window [window_role = "GtkFileChooserDialog"] resize set 590 340
for_window [window_role = "bubble"] floating enable
for_window [window_role = "dialog"] floating enable
for_window [window_role = "pop-up"] floating enable
for_window [window_role = "task_dialog"] floating enable
for_window [window_type = "dialog"] floating enable
for_window [window_type = "menu"] floating enable
# Tag xwayland windows with [X]
for_window [shell="xwayland"] title_format "<span>[X] %title</span>"
'';
};
}