refactor(hyprland): change to structure of hyprland configuration

- move bind scripts to standalone shell applications
- split configuration into more modules
- still more work to be done
This commit is contained in:
ooks-io 2024-03-08 17:29:54 +13:00
parent 24e19d3c63
commit 2130903850
16 changed files with 216 additions and 189 deletions

View file

@ -1,14 +1,13 @@
{ lib, config, pkgs, ... }:
{ lib, config, pkgs, inputs, ... }:
let
cfg = config.homeModules.desktop.wayland.windowManager.hyprland;
inherit (import ./pkgs {inherit pkgs;}) hyprbrightness hyprvolume hyprkillsession;
in
{
imports = [
./binds.nix #hyprland keybindings
./appearance.nix
./rules.nix
./exec.nix
];
imports = [
inputs.hyprland.homeManagerModules.default
./settings
];
config = lib.mkIf cfg.enable {
xdg.portal = {
@ -16,57 +15,20 @@ in
configPackages = [ pkgs.inputs.hyprland.hyprland ];
};
home.packages = with pkgs; [
inputs.hyprwm-contrib.grimblast
hyprpicker
light
hyprshade
];
home.packages = [
inputs.hyprwm-contrib.packages.${pkgs.system}.grimblast
pkgs.hyprshade
hyprvolume
hyprkillsession
hyprbrightness
];
wayland.windowManager.hyprland = {
enable = true;
package = pkgs.inputs.hyprland.hyprland;
xwayland.enable = true;
systemd = {
enable = true;
extraCommands = lib.mkBefore [
"systemctl --user stop graphical-session.target"
"systemctl --user start hyprland-session.target"
];
};
settings = {
input = {
kb_layout = "us";
touchpad = {
disable_while_typing = false;
};
};
misc = {
vrr = true;
disable_hyprland_logo = true;
force_default_wallpaper = 0;
};
env = lib.mkIf cfg.nvidia [
"LIBVA_DRIVER_NAME,nvidia"
"XDG_SESSION_TYPE,wayland"
"GBM_BACKEND,nvidia-drm"
"__GLX_VENDEOR_LIBRARY_NAME,nvidia"
"WLR_NO_HARDWARE_CURSORS,1"
];
gestures = {
workspace_swipe = true;
workspace_swipe_forever = true;
};
monitor = lib.concatMap (m: let
resolution = "${toString m.width}x${toString m.height}@${toString m.refreshRate}";
position = "${toString m.x}x${toString m.y}";
basicConfig = "${m.name},${if m.enabled then "${resolution},${position},1" else "disable"}";
in
[ basicConfig ] ++ (if m.transform != 0 then ["${m.name},transform,${toString m.transform}"] else [])
) (config.monitors);
variables = ["--all"];
};
};
};

View file

@ -1,38 +0,0 @@
{ config, lib, ... }:
{
home = lib.mkIf config.homeModules.desktop.wayland.windowManager.hyprland.enable {
sessionVariables = {
# GTK_IM_MODULE = "fcitx5";
# QT_IM_MODULE = "fcitx5";
# XMODIFIERS = "@im=fcitx5";
#QT_QPA_PLATFORMTHEME = "gtk3";
QT_SCALE_FACTOR = "1";
#MOZ_ENABLE_WAYLAND = "1";
SDL_VIDEODRIVER = "wayland";
_JAVA_AWT_WM_NONREPARENTING = "1";
QT_QPA_PLATFORM = "wayland";
QT_WAYLAND_DISABLE_WINDOWDECORATION = "1";
QT_AUTO_SCREEN_SCALE_FACTOR = "1";
WLR_DRM_DEVICES = "/dev/dri/card1:/dev/dri/card0";
WLR_NO_HARDWARE_CURSORS = "1"; # if no cursor,uncomment this line
WLR_RENDERER_ALLOW_SOFTWARE = "1";
NIXOS_OZONE_WL = "1";
# GBM_BACKEND = "nvidia-drm";
CLUTTER_BACKEND = "wayland";
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
LIBVA_DRIVER_NAME = "nvidia";
WLR_RENDERER = "vulkan";
# __NV_PRIME_RENDER_OFFLOAD = "1";
XCURSOR_SIZE = "24";
XDG_CURRENT_DESKTOP = "Hyprland";
XDG_SESSION_DESKTOP = "Hyprland";
XDG_SESSION_TYPE = "wayland";
XDG_CACHE_HOME = "\${HOME}/.cache";
XDG_CONFIG_HOME = "\${HOME}/.config";
XDG_BIN_HOME = "\${HOME}/.local/bin";
XDG_DATA_HOME = "\${HOME}/.local/share";
};
};
}

View file

@ -0,0 +1,11 @@
{ pkgs, ... }:
let
packages = {
hyprvolume = pkgs.callPackage ./hyprvolume.nix {};
hyprbrightness = pkgs.callPackage ./hyprbrightness.nix {};
# Script to help Hyprland quit https://github.com/hyprwm/Hyprland/issues/3558#issuecomment-1848768654
hyprkillsession = pkgs.callPackage ./hyprkillsession.nix {};
};
in
packages

View file

@ -0,0 +1,20 @@
{ pkgs, ... }:
pkgs.writeShellApplication {
name = "hyprbrightness";
runtimeInputs = with pkgs; [brillo libnotify];
text = ''
if [ "$1" == "up" ]; then
brillo -q -u 30000 -A 5
elif [ "$1" == "down" ]; then
brillo -q -u 30000 -U 5
else
echo "Invalid argument"
exit 1
fi
BRIGHTNESS=$(brillo -G | awk -F'.' '{print$1}')
notify-send --app-name="system-notify" -h string:x-canonical-private-synchronous:sys-notify "󰃠 $BRIGHTNESS%"
'';
}

View file

@ -0,0 +1,16 @@
{ pkgs, ... }:
pkgs.writeShellApplication {
name = "hyprkillsession";
text = ''
if pgrep -x .Hyprland-wrapp >/dev/null; then
hyprctl dispatch exit 0
sleep 2
if pgrep -x .Hyprland-wrapp >/dev/null; then
killall -9 .Hyprland-wrapp
fi
fi
'';
}

View file

@ -0,0 +1,19 @@
{ pkgs, ... }:
pkgs.writeShellApplication {
name = "hyprvolume";
runtimeInputs = with pkgs; [pamixer libnotify];
text = ''
if [ "$1" == "up" ]; then
pamixer --increase 5
elif [ "$1" == "down" ]; then
pamixer --decrease 5
elif [ "$1" == "mute" ]; then
pamixer --toggle-mute
fi
VOLUME=$(pamixer --get-volume-human)
notify-send --app-name="system-notify" -h string:x-canonical-private-synchronous:sys-notify " $VOLUME"
'';
}

View file

@ -1,13 +1,16 @@
{ config, lib, ... }:
let
cfg = config.homeModules.desktop.wayland.windowManager.hyprland;
pointer = config.home.pointerCursor;
in
{
config = lib.mkIf cfg.enable {
wayland.windowManager.hyprland = {
settings = {
general = {
gaps_in = 10;
gaps_out = 10;
border_size = 2;
@ -15,26 +18,24 @@ in
"col.active_border" = "0xff${config.colorscheme.colors.base05}";
"col.inactive_border" = "0xff${config.colorscheme.colors.base02}";
};
group = {
"col.border_active" = "0xff${config.colorscheme.colors.base0B}";
"col.border_inactive" = "0xff${config.colorscheme.colors.base04}";
};
dwindle.split_width_multiplier = 1.35;
exec-once = [
"hyprctl setcursor ${pointer.name} ${toString pointer.size}"
];
decoration = {
active_opacity = 1.0;
inactive_opacity = 1.0;
fullscreen_opacity = 1.0;
rounding = 0;
blur = {
enabled = false;
new_optimizations = true;
ignore_opacity = true;
};
drop_shadow = true;
shadow_range = 12;
shadow_offset = "3 3";
@ -44,25 +45,6 @@ in
animations = {
enabled = false;
bezier = [
"easein,0.11, 0, 0.5, 0"
"easeout,0.5, 1, 0.89, 1"
"easeinback,0.36, 0, 0.66, -0.56"
"easeoutback,0.34, 1.56, 0.64, 1"
];
animation = [
"windowsIn,1,3,easeoutback,slide"
"windowsOut,1,3,easeinback,slide"
"windowsMove,1,3,easeoutback"
"workspaces,1,2,easeoutback,slide"
"fadeIn,1,3,easeout"
"fadeOut,1,3,easein"
"fadeSwitch,1,3,easeout"
"fadeShadow,1,3,easeout"
"fadeDim,1,3,easeout"
"border,1,3,easeout"
];
};
};
};

View file

@ -1,60 +1,10 @@
{ lib, config, pkgs, ... }:
let
let
cfg = config.homeModules.desktop.wayland.windowManager.hyprland;
notifysend = "${pkgs.libnotify}/bin/notify-send";
#pamixer = "${pkgs.pamixer}/bin/pamixer";
brightnessScript = pkgs.writeShellScriptBin "brightness" ''
#!/bin/sh
if [ "$1" == "up" ]; then
brillo -q -u 30000 -A 5
elif [ "$1" == "down" ]; then
brillo -q -u 30000 -U 5
else
echo "Invalid argument"
exit 1
fi
BRIGHTNESS=$(brillo -G | awk -F'.' '{print$1}')
${notifysend} --app-name="system-notify" -h string:x-canonical-private-synchronous:sys-notify "󰃠 $BRIGHTNESS%"
'';
volumeScript = pkgs.writeShellScriptBin "volume" ''
#!/bin/sh
if [ "$1" == "up" ]; then
pamixer --increase 5
elif [ "$1" == "down" ]; then
pamixer --decrease 5
elif [ "$1" == "mute" ]; then
pamixer --toggle-mute
fi
VOLUME=$(pamixer --get-volume-human)
${notifysend} --app-name="system-notify" -h string:x-canonical-private-synchronous:sys-notify " $VOLUME"
'';
# Script to help Hyprland quit https://github.com/hyprwm/Hyprland/issues/3558#issuecomment-1848768654
hyprKillScript = pkgs.writeShellScriptBin "killHyprland" ''
if pgrep -x .Hyprland-wrapp >/dev/null; then
hyprctl dispatch exit 0
sleep 2
if pgrep -x .Hyprland-wrapp >/dev/null; then
killall -9 .Hyprland-wrapp
fi
fi
'';
in
{
{
wayland.windowManager.hyprland.settings = lib.mkIf cfg.enable {
bind = let
terminal = config.home.sessionVariables.TERMINAL;
@ -62,31 +12,21 @@ in
editor = config.home.sessionVariables.EDITOR;
locker = config.home.sessionVariables.LOCKER;
bright = "${brightnessScript}/bin/brightness";
volume = "${volumeScript}/bin/volume";
spotifyctl = "${pkgs.spotify-player}/bin/spotify_player";
discord = "${pkgs.vesktop}/bin/vesktop";
explorer = "${pkgs.cinnamon.nemo-with-extensions}/bin/nemo";
#makoctl = "${config.services.mako.package}/bin/makoctl";
password = "${pkgs._1password-gui}/bin/1password";
killHyprland = "${hyprKillScript}/bin/killHyprland";
#playerctl = "${config.services.playerctld.package}/bin/playerctl";
#playerctld = "${config.services.playerctld.package}/bin/playerctld";
#pactl = "${pkgs.pulseaudio}/bin/pactl";
in [
# Program Launch
"SUPER, b, exec, ${browser}"
"SUPER, return, exec, ${terminal}"
"SUPER, e, exec, ${editor}"
"SUPER, e, exec, ${terminal} ${editor}"
"SUPERSHIFT, P, exec, ${password}"
"SUPER, d, exec, ${discord}"
"SUPER, e, exec, ${explorer}"
"SUPERSHIFT, e, exec, ${explorer}"
"SUPERSHIFT, S, exec, steam"
@ -99,20 +39,20 @@ in
# Brightness
",XF86MonBrightnessUp, exec, ${bright} up"
",XF86MonBrightnessDown, exec, ${bright} down"
",XF86MonBrightnessUp, exec, hyprbrightness up"
",XF86MonBrightnessDown, exec, hyprbrightness down"
# Volume
",XF86AudioRaiseVolume, exec, ${volume} up"
",XF86AudioLowerVolume, exec, ${volume} down"
",XF86AudioMute, exec, ${volume} mute"
",XF86AudioRaiseVolume, exec, hyprvolume up"
",XF86AudioLowerVolume, exec, hyprvolume down"
",XF86AudioMute, exec, hyprvolume mute"
# Window Management
"SUPER, Q, killactive"
"SUPER CTRL, backspace, killactive"
"SUPERSHIFT ALT, delete, exec, ${killHyprland}"
"SUPERSHIFT ALT, delete, exec, hyprkillsession"
"SUPER, F, fullscreen"
"SUPER, Space, togglefloating"
"SUPER, P, pseudo" # dwindle
@ -177,7 +117,7 @@ in
"SUPER, mouse:273, resizewindow"
];
bindr = [
"SUPER, SUPER_L, exec, tofi-drun --drun-launch=true"
"SUPER, SUPER_L, exec, killall anyrun | anyrun"
];
};
}

View file

@ -0,0 +1,13 @@
{
imports = [
./appearance.nix
./binds.nix
./rules.nix
./exec.nix
./env.nix
./inputs.nix
./misc.nix
./monitor.nix
./gestures.nix
];
}

View file

@ -0,0 +1,29 @@
{ lib, config, ... }:
let
cfg = config.homeModules.desktop.wayland.windowManager.hyprland;
in
{
config = lib.mkIf cfg.enable {
wayland.windowManager.hyprland.settings.env = [
"CLUTTER_BACKEND,wayland"
"NIXOS_OZONE_WL,1"
"GDK_BACKEND,wayland"
"QT_QPA_PLATFORM,wayland"
"QT_WAYLAND_DISABLE_WINDOWDECORATION,1"
"MOZ_ENABLE_WAYLAND,1"
"MOZ_DBUS_REMOTE,1"
"XDG_SESSION_TYPE,wayland"
"XDG_SESSIONDESKTOP,hyprland"
"XDG_CURRENT_DESKTOP,hyprland"
] ++ lib.optionals cfg.nvidia [
"LIBVA_DRIVER_NAME,nvidia"
"GBM_BACKEND,nvidia-drm"
"__GLX_VENDEOR_LIBRARY_NAME,nvidia"
"WLR_NO_HARDWARE_CURSORS,1"
];
};
}

View file

@ -1,10 +1,12 @@
{ config, lib, pkgs, ... }:
let
cfg = config.homeModules.desktop.wayland.windowManager.hyprland;
in
{
config = {
wayland.windowManager.hyprland.settings = lib.mkIf cfg.enable {
config = lib.mkIf cfg.enable {
wayland.windowManager.hyprland.settings = {
exec = [
"${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1"
"${pkgs.swaybg}/bin/swaybg -i ${config.wallpaper} --mode fill"

View file

@ -0,0 +1,14 @@
{ lib, config, ... }:
let
cfg = config.homeModules.desktop.wayland.windowManager.hyprland;
in
{
config = lib.mkIf cfg.enable {
wayland.windowManager.hyprland.settings.gestures = {
workspace_swipe = true;
workspace_swipe_forever = true;
};
};
}

View file

@ -0,0 +1,16 @@
{ lib, config, ... }:
let
cfg = config.homeModules.desktop.wayland.windowManager.hyprland;
in
{
config = lib.mkIf cfg.enable {
wayland.windowManager.hyprland.settings.input = {
kb_layout = "us";
follow_mouse = 1;
touchpad.natural_scroll = "no";
};
};
}

View file

@ -0,0 +1,21 @@
{ lib, config, ... }:
let
cfg = config.homeModules.desktop.wayland.windowManager.hyprland;
in
{
config = lib.mkIf cfg.enable {
wayland.windowManager.hyprland.settings.misc = {
mouse_move_enables_dpms = true;
key_press_enables_dpms = true;
disable_hyprland_logo = true;
disable_splash_rendering = true;
enable_swallow = true;
swallow_regex = "foot|nemo";
focus_on_activate = true;
};
};
}

View file

@ -0,0 +1,20 @@
{ lib, config, ... }:
let
cfg = config.homeModules.desktop.wayland.windowManager.hyprland;
in
{
config = lib.mkIf cfg.enable {
wayland.windowManager.hyprland.settings = {
monitor = lib.concatMap (m: let
resolution = "${toString m.width}x${toString m.height}@${toString m.refreshRate}";
position = "${toString m.x}x${toString m.y}";
basicConfig = "${m.name},${if m.enabled then "${resolution},${position},1" else "disable"}";
in
[ basicConfig ] ++ (if m.transform != 0 then ["${m.name},transform,${toString m.transform}"] else [])
) (config.monitors);
};
};
}