nixos/malte/sway.nix
2021-10-30 16:28:48 +02:00

350 lines
10 KiB
Nix

{ pkgs, config, lib, ... }:
let
col_light = "#ebdbb2";
col_dark0 = "#282828";
col_dark1 = "#3c3836";
col_urgent = "#d65d0e";
col_red = "#b16286";
bemenu = (import ./bemenu.nix) pkgs;
grim = "${pkgs.grim}/bin/grim";
wl-copy = "${pkgs.wl-clipboard}/bin/wl-copy";
wf-recorder = "${pkgs.wf-recorder}/bin/wf-recorder";
slurp = "${pkgs.slurp}/bin/slurp -db '#000000AA' -c '#EBDBB2' -w1";
fuser = "${pkgs.psmisc}/bin/fuser";
alsa_rec =
"alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink.monitor";
screenshot-path = "/home/malte/Pictures/screenshots/screenshot.png";
screenshot-all =
"${grim} ${screenshot-path} && ${wl-copy} < ${screenshot-path}";
screenshot-region = ''
${grim} -g "$(${slurp})" ${screenshot-path} && ${wl-copy} < ${screenshot-path}'';
screencast-path = "/home/malte/Videos/screencasts/screencast.mp4";
screencast-all =
''${wf-recorder} --audio="${alsa_rec}" -f ${screencast-path}'';
screencast-region = ''
${wf-recorder} --audio="${alsa_rec}" -g "$$(${slurp})" -f ${screencast-path}'';
screencast-stop =
"killall -s SIGINT wf-recorder && ${wl-copy} < ${screencast-path}";
swaylockConfig = ''
screenshots
indicator
clock
grace=5
effect-pixelate=50
fade-in=0.5
font=FiraCode Nerd Font
font-size=70
indicator-radius=120
indicator-thickness=3
key-hl-color=#fbf1c7
bs-hl-color=#d65d0e
inside-color=#282828cc
line-color=#282828
ring-color=#d5c5a1
text-color=#ebdbb2
inside-clear-color=#282828cc
line-clear-color=#282828
ring-clear-color=#d5c5a1
text-clear-color=#ebdbb2
inside-ver-color=#282828cc
line-ver-color=#282828
ring-ver-color=#d5c5a1
text-ver-color=#ebdbb2
inside-wrong-color=#282828cc
line-wrong-color=#282828
ring-wrong-color=#cc241d
text-wrong-color=#ebdbb2
inside-caps-lock-color=#282828cc
line-caps-lock-color=#282828
ring-caps-lock-color=#d65d0e
text-caps-lock-color=#ebdbb2
'';
in {
imports = [
./gammastep.nix
./waybar.nix
./gtk.nix
./qt.nix
./pass.nix
./mako.nix
./kanshi.nix
];
config = {
home.packages = [
pkgs.firaCodeNerd
pkgs.grim
pkgs.libappindicator
pkgs.libappindicator-gtk3
pkgs.numix-cursor-theme
pkgs.psmisc
pkgs.slurp
pkgs.swaylock-effects
pkgs.wf-recorder
pkgs.wl-clipboard
];
wayland.windowManager.sway = {
enable = true;
extraOptions = [ "--unsupported-gpu" ];
systemdIntegration = true;
wrapperFeatures = {
base = true;
gtk = true;
};
extraSessionCommands = ''
# Set DRM devices and fix cursor
export WLR_NO_HARDWARE_CURSORS=1
export WLR_DRM_DEVICES=/dev/dri/card0:/dev/dri/card1
# Let's not, since it breaks most games
#export SDL_VIDEODRIVER=wayland
# needs qt5.qtwayland in systemPackages
export QT_QPA_PLATFORM=wayland
export QT_WAYLAND_DISABLE_WINDOWDECORATION="1"
export MOZ_ENABLE_WAYLAND=1
export GDK_BACKEND=wayland
# Fix for some Java AWT applications (e.g. Android Studio),
# use this if they aren't displayed properly:
export _JAVA_AWT_WM_NONREPARENTING=1
# Breaks QT applications on wayland..
#export QT_WAYLAND_FORCE_DPI=physical
export XDG_CURRENT_DESKTOP=Sway
export XDG_SESSION_TYPE=wayland
'';
config = {
modifier = "Mod4";
terminal = "kitty";
menu = "${bemenu}/bin/bemenu-run-configured -p 'Program:'";
window = {
border = 2;
titlebar = true;
commands = [
{
command = ''
title_format "[<span foreground='${col_red}'><b>X</b></span>] %title"'';
criteria = { shell = "xwayland"; };
}
{
command = "floating enable; kill";
criteria = {
app_id = "firefox";
title = "Firefox Sharing Indicator";
};
}
{
command = "floating enable";
criteria = { app_id = "org.gnome.Nautilus"; };
}
{
command = "floating enable";
criteria = { class = "Mojosetup"; };
}
];
};
bars = [{
command = "${pkgs.waybar}/bin/waybar";
position = "top";
}];
seat = { "*" = { xcursor_theme = "Numix-Cursor-Light 48"; }; };
keybindings = let
mod = config.wayland.windowManager.sway.config.modifier;
move_follow = workspace:
"move container to workspace ${workspace}; workspace ${workspace}";
in lib.mkOptionDefault {
"${mod}+Shift+e" = "exit";
# Move focused container to workspace and follow
"${mod}+Ctrl+Shift+1" = move_follow "1";
"${mod}+Ctrl+Shift+2" = move_follow "2";
"${mod}+Ctrl+Shift+3" = move_follow "3";
"${mod}+Ctrl+Shift+4" = move_follow "4";
"${mod}+Ctrl+Shift+5" = move_follow "5";
"${mod}+Ctrl+Shift+6" = move_follow "6";
"${mod}+Ctrl+Shift+7" = move_follow "7";
"${mod}+Ctrl+Shift+8" = move_follow "8";
"${mod}+Ctrl+Shift+9" = move_follow "9";
# Move workspaces between displays
"${mod}+Ctrl+Shift+l" = "move workspace to output right";
"${mod}+Ctrl+Shift+k" = "move workspace to output up";
"${mod}+Ctrl+Shift+j" = "move workspace to output down";
"${mod}+Ctrl+Shift+h" = "move workspace to output left";
# Sound control
"XF86AudioRaiseVolume" =
"exec ${pkgs.ponymix}/bin/ponymix increase 5%";
"XF86AudioLowerVolume" =
"exec ${pkgs.ponymix}/bin/ponymix decrease 5%";
"XF86AudioMute" = "exec ${pkgs.ponymix}/bin/ponymix toggle";
"XF86AudioMicMute" =
"exec ${pkgs.ponymix}/bin/ponymix --input toggle";
# Additional menus
"${mod}+p" = "exec passmenu-bemenu";
# Screenshots
"${mod}+Ctrl+s" = "exec ${screenshot-all}";
"${mod}+Ctrl+Shift+s" = "exec ${screenshot-region}";
# Screencasts
"${mod}+Ctrl+r" = "exec ${screencast-all}; mode recording";
"${mod}+Ctrl+Shift+r" = "exec ${screencast-region}; mode recording";
# Special window actions
"${mod}+Ctrl+Shift+w" = "mode window";
# Screenlocking
"XF86Favorites" = "exec swaylock";
};
gaps = { smartBorders = "on"; };
assigns = {
"2" = [{ app_id = "firefox"; }];
"5" = [
{ title = "Korrektur.pdf(.xopp)? . Xournal++"; }
{ title = ".*HWP Betreuung/Skript.pdf"; }
];
"6" = [{ class = "com-cburch-logisim-Main"; }];
"7" = [{ app_id = "Element"; }];
"8" = [ { app_id = "telegramdesktop"; } { class = "discord"; } ];
"9" = [{ app_id = "pavucontrol"; }];
};
fonts = {
names = [ "FiraCode Nerd Font" ];
size = 8.0;
};
modes = let mod = config.wayland.windowManager.sway.config.modifier;
in lib.mkOptionDefault {
recording = {
"${mod}+Escape" = "exec ${screencast-stop}; mode default";
};
window = {
"Escape" = "mode default";
"1" = let
width = 1920;
win_width = 500;
win_height = 500 * 9 / 16;
str = builtins.toString;
in "floating enable; sticky enable; resize set width ${
str win_width
}px height ${str win_height}px; move position ${
str (1920 - win_width)
}px 0px";
};
};
input = {
# Build into the Thinkpad
"1:1:AT_Translated_Set_2_keyboard" = {
xkb_layout = "us,us";
xkb_variant = ",workman";
xkb_options = "compose:rctrl,grp:alt_space_toggle,grp_led:caps";
};
# Fancy Keyboardio Atreus
"4617:8963:Keyboardio_Atreus_Keyboard" = {
xkb_layout = "us";
xkb_options = "compose:rctrl";
};
# Shabby Logitech keyboard
"1133:49947:Logitech_Logitech_USB_Keyboard" = {
xkb_layout = "us";
xkb_variant = "workman";
xkb_options = "compose:rctrl";
};
# Build into the Thinkpad
"2:7:SynPS/2_Synaptics_TouchPad" = {
natural_scroll = "enabled";
scroll_method = "two_finger";
pointer_accel = ".5";
accel_profile = "adaptive";
tap = "enabled";
drag = "enabled";
};
};
output = { eDP-1 = { bg = "~/Pictures/wallpapers/bg.jpg fill"; }; };
colors = {
background = col_light;
focused = {
background = col_light;
border = col_light;
childBorder = col_light;
indicator = col_light;
text = col_dark0;
};
focusedInactive = {
background = col_dark1;
border = col_dark1;
childBorder = col_dark1;
indicator = col_dark1;
text = col_light;
};
unfocused = {
background = col_dark0;
border = col_dark0;
childBorder = col_dark0;
indicator = col_dark0;
text = col_light;
};
urgent = {
background = col_urgent;
border = col_urgent;
childBorder = col_urgent;
indicator = col_urgent;
text = col_dark0;
};
};
};
};
};
config.systemd.user.services = {
swaylock = {
Unit = {
Description = "Idle manager for Wayland";
Documentation = [ "man:swayidle(1)" ];
PartOf = "graphical-session.target";
};
Service = {
Type = "simple";
ExecStart = ''
${pkgs.swayidle}/bin/swayidle \
timeout 300 swaylock \
timeout 600 'systemctl suspend' \
'';
};
Install = { WantedBy = [ "graphical-session.target" ]; };
};
};
# Configure swaylock
config.xdg.configFile."swaylock/config".text = swaylockConfig;
# If running from tty1 start sway
config.xdg.configFile."fish/conf.d/sway.fish".text = ''
set TTY1 (tty)
if test -z \"$DISPLAY\"; and test $TTY1 = '/dev/tty1'
systemd-cat -t sway sway
end
'';
}