nixos/users/malte/sway.nix

371 lines
12 KiB
Nix

{ pkgs, config, lib, nixosConfig, ... }:
let
col = config.colors;
backgrounds = pkgs.fetchFromGitHub {
owner = "vctrblck";
repo = "gruvbox-wallpapers";
rev = "ff9ade4c49299e08c11bd8ce2f17cdae7f9b706d";
sha256 = "d28r/s+m32hqzF/S/ebyBCd5XLKJTFSaQXmMdHFUH64=";
};
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
'';
cfg = config.settings.sway;
nvidiaUsed = nixosConfig.settings.nvidiaUsed;
hiDPI = nixosConfig.hardware.video.hidpi.enable;
in {
imports =
[ ./waybar.nix ./gtk.nix ./qt.nix ./pass.nix ./mako.nix ./kanshi.nix ];
options.settings.sway = with lib; {
enable = mkEnableOption "Enable sway config";
};
config = lib.mkIf cfg.enable {
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 = lib.optional nvidiaUsed "--unsupported-gpu";
systemdIntegration = true;
wrapperFeatures = {
base = true;
gtk = true;
};
extraSessionCommands = ''
# 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
export XDG_CURRENT_DESKTOP=Sway
export XDG_SESSION_TYPE=wayland
'' +
# TODO: See what actually is required here!
(lib.optionalString nvidiaUsed ''
# Set DRM devices and fix cursor
# nvidia=$(readlink -f /dev/dri/by-path/pci-0000\:01\:00.0-card)
# intel=$(readlink -f /dev/dri/by-path/pci-0000:00:02.0-card)
# export WLR_DRM_DEVICES=$nvidia:$intel
# __GLX_VENDOR_LIBRARY=nvidia
# GBM_BACKEND=nvidia-drm
# GBM_BACKEND_PATH=/etc/gbm
'');
config = {
modifier = "Mod4";
terminal = "kitty";
menu = "${bemenu}/bin/bemenu-run-configured -p 'Program:'";
window = {
border = 2;
titlebar = false;
commands = [
{
command = ''title_format "[<b>X</b>] %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 =
if hiDPI then "Numix-Cursor-Light 48" else "Numix-Cursor-Light 32";
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 = let size = 3;
in {
smartBorders = "on";
smartGaps = true;
#inner = size;
#outer = size;
};
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";
};
# Ducky One 2 TKL
"1241:661:USB-HID_Keyboard" = {
xkb_layout = "us,us";
xkb_variant = ",workman";
xkb_options = "compose:rwin,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 = {
"Unknown 0x1500 0x00000000".bg = "${backgrounds}/forest2.jpg fill";
"Goldstar Company Ltd IPS226 SerialNumber".bg =
"${backgrounds}/future-town.jpg fill";
"BenQ Corporation BenQ GW2270 P9J02423SL0".bg =
"${backgrounds}/leaves3.jpg fill";
};
colors = let
primary = col.primary.hashRgb;
secondary = col.secondary.hashRgb;
#primaryDimmed = (col.primary.darker 0.6).hashRgb;
background = col.background.hashRgb;
foregroundDimm = col.foregroundDimmed.hashRgb;
border0 = (col.background.lighter 0.3).hashRgb;
border1 = (col.background.lighter 0.8).hashRgb;
in {
focused = {
background = primary;
border = primary;
childBorder = primary;
indicator = primary;
text = background;
};
focusedInactive = {
inherit background;
border = secondary;
childBorder = secondary;
indicator = secondary;
text = "#FF0000";
};
unfocused = {
inherit background;
border = border0;
childBorder = border0;
indicator = border0;
text = foregroundDimm;
};
urgent = {
background = "#FF0000";
border = "#FF0000";
childBorder = "#FF0000";
indicator = "#FF0000";
text = "#FF0000";
};
};
};
};
services.wlsunset = {
enable = true;
temperature.night = 3500;
latitude = "51.3";
longitude = "12.4";
};
# Configure swaylock
xdg.configFile."swaylock/config".text = swaylockConfig;
# If running from tty1 start sway
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
'';
};
}