nix-dotfiles/home/programs/hyprland.nix

274 lines
8.5 KiB
Nix

{ config, pkgs, lib, ... }:
let
cfg = config.wayland.windowManager.hyprland;
in
{
home.sessionVariables = {
WLR_NO_HARDWARE_CURSORS = "1";
WLR_RENDERER_ALLOW_SOFTWARE = "1";
XDG_CURRENT_DESKTOP = "Hyprland";
XDG_SESSION_DESKTOP = "Hyprland";
XDG_SESSION_TYPE = "wayland";
GDK_BACKEND = "wayland,x11,*";
QT_QPA_PLATFORM = "wayland;xcb";
NIXOS_OZONE_WL = "1";
MOZ_ENABLE_WAYLAND = "1";
SDL_VIDEODRIVER = "wayland";
OZONE_PLATFORM = "wayland";
CLUTTER_BACKEND = "wayland";
QT_WAYLAND_DISABLE_WINDOWDECORATION = "1";
# QT_QPA_PLATFORMTHEME = "qt6ct";
QT_AUTO_SCREEN_SCALE_FACTOR = "1";
LIBVA_DRIVER_NAME = "nvidia";
GBM_BACKEND = "nvidia-drm";
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
};
wayland.windowManager.hyprland = {
enable = true;
settings = let
scratchpads = [
(rec {
title = "Floating terminal";
class = "floatingTerminal";
command = "alacritty --class ${class} -e tmux new-session -A -s f";
size = { h = 90; w = 95; };
keys = [
"$mod, RETURN"
"$mod, SPACE"
];
})
(rec {
title = "Ncmpcpp";
class = "floatingNcmpcpp";
command = "alacritty --class ${class} -e ncmpcpp";
size = { h = 95; w = 95; };
keys = [ "$mod, Q" ];
})
# "$mod, W, emacs"
# "$mod, E, filebrowser"
# "$mod, X, taskwarriortui"
];
in {
"$mod" = "SUPER";
# https://github.com/xkbcommon/libxkbcommon/blob/master/include/xkbcommon/xkbcommon-keysyms.h
bind = [
"$mod SHIFT, Q, exit"
"$mod, R, exec, ${pkgs.rofi}/bin/rofi -show drun"
"$mod, T, togglefloating"
"$mod, F, fakefullscreen"
"$mod, C, exec, hyprctl reload"
"$mod, BACKSPACE, exec, ${lib.getExe (pkgs.writeShellApplication {
name = "hyprland-kill-windows-except-scratchpads";
runtimeInputs = [ cfg.package pkgs.jq ];
text = ''
ACTIVE_WINDOW_CLASS=$(hyprctl activewindow -j | jq -r '.class')
case "$ACTIVE_WINDOW_CLASS" in
${lib.pipe scratchpads [
(map ({ class , ... }: ''
'${class}')
hyprctl dispatch togglespecialworkspace '${class}Ws'
;;
''))
(map (lib.splitString "\n"))
(lib.flatten)
(map (x: " " + x))
(lib.concatStringsSep "\n")
]}
*)
hyprctl dispatch killactive
;;
esac
'';
})}"
"$mod SHIFT, RETURN, exec, alacritty --class termTerminal -e tmux new-session -A -s term"
"$mod SHIFT, SPACE, exec, alacritty --class termTerminal -e tmux new-session -A -s term"
"$mod, j, layoutmsg,cyclenext"
"$mod, k, layoutmsg,cycleprev"
"$mod SHIFT, j, layoutmsg, swapnext"
"$mod SHIFT, k, layoutmsg, swapprev"
"$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 SHIFT, 1, movetoworkspace, 1"
"$mod SHIFT, 2, movetoworkspace, 2"
"$mod SHIFT, 3, movetoworkspace, 3"
"$mod SHIFT, 4, movetoworkspace, 4"
"$mod SHIFT, 5, movetoworkspace, 5"
"$mod SHIFT, 6, movetoworkspace, 6"
"$mod SHIFT, 7, movetoworkspace, 7"
"$mod SHIFT, 8, movetoworkspace, 8"
"$mod SHIFT, 9, movetoworkspace, 9"
# TODO: ensure this exists in env
",XF86MonBrightnessUp, exec, brightnessctl s +5%"
",XF86MonBrightnessDown, exec, brightnessctl s 5%-"
# TODO: swap out for wireplumber commands
",XF86AudioLowerVolume, exec, ${pkgs.alsaUtils}/bin/amixer set Master 2%-"
",XF86AudioRaiseVolume, exec, ${pkgs.alsaUtils}/bin/amixer set Master 2%+"
"$mod ,F7, exec, ${pkgs.alsaUtils}/bin/amixer set Master 2%-"
"$mod ,F8, exec, ${pkgs.alsaUtils}/bin/amixer set Master 2%+"
"$mod, p, exec, ${pkgs.mpc_cli}/bin/mpc toggle"
",XF86AudioPlay, exec, ${pkgs.mpc_cli}/bin/mpc toggle"
",XF86AudioPrev, exec, ${pkgs.mpc_cli}/bin/mpc prev"
",XF86AudioNext, exec, ${pkgs.mpc_cli}/bin/mpc next"
"$mod, b, exec, ${pkgs.fcitx5}/bin/fcitx5-remote -s mozc"
"$mod, n, exec, ${pkgs.fcitx5}/bin/fcitx5-remote -s keyboard-no"
"$mod, m, exec, ${pkgs.fcitx5}/bin/fcitx5-remote -s keyboard-us"
# TODO: ensure exists in environment
"$mod, l, exec, loginctl lock-session"
# TODO: fix
# "super + minus" = "${pkgs.xcalib}/bin/xcalib -invert -alter"
# TODO: fix
# "@Print" = "${pkgs.maim}/bin/maim --hidecursor --nokeyboard --select | ${pkgs.xclip}/bin/xclip -selection clipboard -target image/png -in"
# "shift + @Print" = "${pkgs.maim}/bin/maim --hidecursor --nokeyboard $SCREENSHOT_DIR/$(date +%s).png"
# TODO: Add boomer as package
# "super + @Print" = "boomer"
]
++
(lib.pipe scratchpads [
(map ({ keys, command, class, ... }:
(map (key: let
# TODO: rewrite the scratchpad logic to move windows back and forth
# from the special workspaces, rather than overlay the workspaces.
#
# TODO: don't invoke the program upon close toggling the scratchpad
#
# TODO: ensure program becomes in focus upon open toggling the scratchpad
invokeIfNotRunningAndToggleWorkspace = pkgs.writeShellApplication {
name = "hyprland-toggle-scratchpad-${class}";
runtimeInputs = [ cfg.package pkgs.jq ];
text = ''
SCRATCHPAD_EXISTS=$(hyprctl clients -j | jq -r '[.[].class]|any(. == "${class}")')
if [ "$SCRATCHPAD_EXISTS" != "true" ]; then
${command} &
fi
hyprctl dispatch togglespecialworkspace '${class}Ws'
'';
};
in "${key}, exec, ${lib.getExe invokeIfNotRunningAndToggleWorkspace}"
) keys)
))
lib.flatten
]);
windowrulev2 = [
"float,class:(Rofi)"
"workspace 2,class:(firefox)"
"workspace 2,class:(google-chrome)"
"workspace 3,class:(Emacs)"
"workspace 3,class:(Code)"
"workspace 3,class:(code-url-handler)"
"workspace 5,class:(discord)"
"workspace 5,class:(Element)"
]
++
(lib.pipe scratchpads [
(map ({ class, size, ... }: [
"workspace special:${class}Ws, class:^${class}$"
"float, class:^${class}$"
"size ${toString size.w}% ${toString size.h}%, class:^${class}$"
"move ${toString ((100 - size.w) / 2)}% ${toString ((100 - size.h) / 2)}%, class:^${class}$"
]))
lib.flatten
]);
monitor = [
"DP-6, 1920x1080@144.00Hz, 0x0, 1"
"DVI-D-1, 1920x1080@144.00Hz, 1920x0, 1"
",preferred,auto,1"
];
general = {
gaps_in = 5;
gaps_out = 15;
border_size = 2;
"col.active_border" = "rgba(33ccffee) rgba(00ff99ee) 45deg";
"col.inactive_border" = "rgba(595959aa)";
resize_on_border = false;
allow_tearing = false;
layout = "master";
};
decoration = {
rounding = 10;
# Change transparency of focused and unfocused windows
active_opacity = 1.0;
inactive_opacity = 1.0;
drop_shadow = true;
shadow_range = 4;
shadow_render_power = 3;
"col.shadow" = "rgba(1a1a1aee)";
# https://wiki.hyprland.org/Configuring/Variables/#blur
blur = {
enabled = true;
size = 3;
passes = 1;
vibrancy = 0.1696;
};
};
animations.enabled = false;
master = {
new_is_master = false;
};
misc = {
force_default_wallpaper = 0; # Set to 0 or 1 to disable the anime mascot wallpapers
disable_hyprland_logo = false; # If true disables the random hyprland logo / anime girl background. :(
};
input ={
kb_layout = "us";
kb_variant = "";
kb_model = "";
kb_options = "";
kb_rules = "";
follow_mouse = 1;
sensitivity = 0; # -1.0 - 1.0, 0 means no modification.
touchpad = {
natural_scroll = false;
};
};
};
};
}