hyprland: reworked and reorganized for better code reuse

This commit is contained in:
Aly Raffauf 2024-06-01 20:43:34 -04:00
parent 6011bf86cd
commit c768eeacde
4 changed files with 188 additions and 211 deletions

View file

@ -6,8 +6,6 @@
inputs, inputs,
... ...
}: { }: {
imports = [./randomWallpaper.nix ./redShift.nix ./virtKeyboard.nix];
options = { options = {
alyraffauf.desktop.hyprland = { alyraffauf.desktop.hyprland = {
enable = enable =
@ -85,27 +83,90 @@
terminal = config.alyraffauf.desktop.defaultApps.terminal.exe; terminal = config.alyraffauf.desktop.defaultApps.terminal.exe;
# Hyprland desktop utilities # Hyprland desktop utilities
bar = lib.getExe pkgs.waybar;
hyprnome = lib.getExe inputs.nixpkgsUnstable.legacyPackages."${pkgs.system}".hyprnome; hyprnome = lib.getExe inputs.nixpkgsUnstable.legacyPackages."${pkgs.system}".hyprnome;
launcher = lib.getExe pkgs.fuzzel; launcher = lib.getExe pkgs.fuzzel;
lock = lib.getExe pkgs.swaylock; lock = lib.getExe pkgs.swaylock;
logout = lib.getExe pkgs.wlogout; logout = lib.getExe pkgs.wlogout;
notifyd = lib.getExe pkgs.mako; wallpaperd =
wallpaperd = "${lib.getExe pkgs.swaybg} -i ${config.alyraffauf.desktop.theme.wallpaper}"; if config.alyraffauf.desktop.hyprland.randomWallpaper
then
pkgs.writeShellScript "hyprland-randomWallpaper" ''
OLD_PIDS=()
directory=${config.home.homeDirectory}/.local/share/backgrounds
if [ -d "$directory" ]; then
while true; do
NEW_PIDS=()
monitor=`${config.wayland.windowManager.hyprland.package}/bin/hyprctl monitors | grep Monitor | awk '{print $2}'`
for m in ''${monitor[@]}; do
random_background=$(ls $directory/*.{png,jpg} | shuf -n 1)
${lib.getExe pkgs.swaybg} -o $m -i $random_background &
NEW_PIDS+=($!)
done
if [ ''${OLD_PIDS[@]} -gt 0 ]; then
sleep 5
for pid in ''${OLD_PIDS[@]}; do
kill $pid
done
fi
OLD_PIDS=$NEW_PIDS
sleep 895
done
fi
''
else "${lib.getExe pkgs.swaybg} -i ${config.alyraffauf.desktop.theme.wallpaper}";
startupApps =
[
wallpaperd
(lib.getExe pkgs.waybar)
"${fileManager} --daemon"
idled
(lib.getExe' pkgs.blueman "blueman-applet")
(lib.getExe' pkgs.networkmanagerapplet "nm-applet")
(lib.getExe' pkgs.playerctl "playerctld")
(lib.getExe' pkgs.swayosd "swayosd-server")
(lib.getExe pkgs.mako)
"${pkgs.mate.mate-polkit}/libexec/polkit-mate-authentication-agent-1"
]
++ (
if config.alyraffauf.desktop.hyprland.redShift
then [
"${pkgs.geoclue2}/libexec/geoclue-2.0/demos/agent"
(lib.getExe pkgs.gammastep)
]
else []
)
++ (
if config.alyraffauf.desktop.hyprland.tabletMode.virtKeyboard
then [(lib.getExe' pkgs.squeekboard "squeekboard")]
else []
);
screenshot = rec { screenshot = rec {
bin = lib.getExe inputs.nixpkgsUnstable.legacyPackages."${pkgs.system}".hyprshot; bin = lib.getExe inputs.nixpkgsUnstable.legacyPackages."${pkgs.system}".hyprshot;
folder = "~/pics/screenshots"; folder = "${config.xdg.userDirs.pictures}/screenshots";
screen = "${bin} -m output -o ${folder}"; screen = "${bin} -m output -o ${folder}";
region = "${bin} -m region -o ${folder}"; region = "${bin} -m region -o ${folder}";
}; };
defaultWorkspaces = [1 2 3 4 5 6 7 8 9];
laptopMonitors = { laptopMonitors = {
framework = "desc:BOE 0x095F,preferred,auto,1.6"; framework = "desc:BOE 0x095F,preferred,auto,1.6";
t440p = "desc:LG Display 0x0569,preferred,auto,1.2"; t440p = "desc:LG Display 0x0569,preferred,auto,1.2";
yoga9i = "desc:Samsung Display Corp. 0x4152,preferred,auto,2,transform,0"; yoga9i = "desc:Samsung Display Corp. 0x4152,preferred,auto,2,transform,0";
}; };
externalMonitors = {
homeOffice0 = "desc:LG Electronics LG ULTRAWIDE 311NTAB5M720,preferred,auto,1.25,vrr,2";
homeOffice1 = "desc:LG Electronics LG IPS QHD 109NTWG4Y865,preferred,-2560x0,auto";
workShop = "desc:Guangxi Century Innovation Display Electronics Co. Ltd 27C1U-D 0000000000001,preferred,-2400x0,1.6";
weWork = "desc:HP Inc. HP 24mh 3CM037248S,preferred,-1920x0,auto";
};
gdk_scale = "1.5"; gdk_scale = "1.5";
clamshell = pkgs.writeShellScript "hyprland-clamshell" '' clamshell = pkgs.writeShellScript "hyprland-clamshell" ''
@ -115,9 +176,13 @@
${hyprctl} keyword monitor "eDP-1, disable" ${hyprctl} keyword monitor "eDP-1, disable"
fi fi
elif [ "$1" == "off" ]; then elif [ "$1" == "off" ]; then
${hyprctl} keyword monitor "${laptopMonitors.framework}" ${
${hyprctl} keyword monitor "${laptopMonitors.t440p}" lib.strings.concatStringsSep "\n"
${hyprctl} keyword monitor "${laptopMonitors.yoga9i}" (
lib.attrsets.mapAttrsToList (name: value: ''${hyprctl} keyword monitor "${value}"'')
laptopMonitors
)
}
fi fi
''; '';
@ -160,19 +225,23 @@
} }
''; '';
in '' in ''
${
lib.strings.concatStringsSep "\n"
(
lib.attrsets.mapAttrsToList (name: value: "monitor = ${value}")
(laptopMonitors // externalMonitors)
)
}
monitor = ,preferred,auto,auto monitor = ,preferred,auto,auto
monitor = ${laptopMonitors.framework}
monitor = ${laptopMonitors.t440p}
monitor = ${laptopMonitors.yoga9i}
monitor = desc:Guangxi Century Innovation Display Electronics Co. Ltd 27C1U-D 0000000000001,preferred,-2400x0,1.6 # workshop
monitor = desc:HP Inc. HP 24mh 3CM037248S,preferred,-1920x0,auto
monitor = desc:LG Electronics LG IPS QHD 109NTWG4Y865,preferred,-2560x0,auto
monitor = desc:LG Electronics LG ULTRAWIDE 311NTAB5M720,preferred,auto,1.25,vrr,2 # mauville
# Turn off the internal display when lid is closed. # Turn off the internal display when lid is closed.
bindl=,switch:on:Lid Switch,exec,${clamshell} on bindl=,switch:on:Lid Switch,exec,${clamshell} on
bindl=,switch:off:Lid Switch,exec,${clamshell} off bindl=,switch:off:Lid Switch,exec,${clamshell} off
# Enable virtual keyboard in tablet mode
bindl=,switch:on:Lenovo Yoga Tablet Mode Control switch,exec,${lib.getExe pkgs.dconf} write /org/gnome/desktop/a11y/applications/screen-keyboard-enabled true
bindl=,switch:off:Lenovo Yoga Tablet Mode Control switch,exec,${lib.getExe pkgs.dconf} write /org/gnome/desktop/a11y/applications/screen-keyboard-enabled false
# unscale XWayland apps # unscale XWayland apps
xwayland { xwayland {
force_zero_scaling = true force_zero_scaling = true
@ -187,132 +256,125 @@
# Execute necessary apps # Execute necessary apps
${ ${
if config.alyraffauf.desktop.hyprland.randomWallpaper lib.strings.concatMapStringsSep
then "" "\n"
else "exec-once = ${wallpaperd}" (x: "exec-once = ${x}")
startupApps
} }
exec-once = ${bar}
exec-once = ${fileManager} --daemon
exec-once = ${idled}
exec-once = ${lib.getExe' pkgs.blueman "blueman-applet"}
exec-once = ${lib.getExe' pkgs.networkmanagerapplet "nm-applet"}
exec-once = ${lib.getExe' pkgs.playerctl "playerctld"}
exec-once = ${lib.getExe' pkgs.swayosd "swayosd-server"}
exec-once = ${lib.getExe' pkgs.wl-clipboard "wl-paste"} --type image --watch ${lib.getExe pkgs.cliphist} store
exec-once = ${lib.getExe' pkgs.wl-clipboard "wl-paste"} --type text --watch ${lib.getExe pkgs.cliphist} store
exec-once = ${notifyd}
exec-once = ${pkgs.mate.mate-polkit}/libexec/polkit-mate-authentication-agent-1
# For all categories, see https://wiki.hyprland.org/Configuring/Variables/ # For all categories, see https://wiki.hyprland.org/Configuring/Variables/
input { input {
kb_layout = us kb_layout = us
kb_variant = altgr-intl kb_variant = altgr-intl
follow_mouse = 1 follow_mouse = 1
sensitivity = 0 # -1.0 to 1.0, 0 means no modification. sensitivity = 0 # -1.0 to 1.0, 0 means no modification.
touchpad { touchpad {
clickfinger_behavior = true clickfinger_behavior = true
drag_lock = true drag_lock = true
middle_button_emulation = true middle_button_emulation = true
natural_scroll = yes natural_scroll = yes
tap-to-click = true tap-to-click = true
} }
} }
gestures { gestures {
workspace_swipe = true workspace_swipe = true
workspace_swipe_touch = true workspace_swipe_touch = true
} }
general { general {
gaps_in = 5 gaps_in = 5
gaps_out = 6 gaps_out = 6
border_size = 2 border_size = 2
col.active_border = rgba(${lib.strings.removePrefix "#" config.alyraffauf.desktop.theme.colors.secondary}EE) rgba(${lib.strings.removePrefix "#" config.alyraffauf.desktop.theme.colors.primary}EE) 45deg col.active_border = rgba(${lib.strings.removePrefix "#" config.alyraffauf.desktop.theme.colors.secondary}EE) rgba(${lib.strings.removePrefix "#" config.alyraffauf.desktop.theme.colors.primary}EE) 45deg
col.inactive_border = rgba(${lib.strings.removePrefix "#" config.alyraffauf.desktop.theme.colors.inactive}AA) col.inactive_border = rgba(${lib.strings.removePrefix "#" config.alyraffauf.desktop.theme.colors.inactive}AA)
layout = dwindle layout = dwindle
allow_tearing = false allow_tearing = false
} }
decoration { decoration {
rounding = 10 rounding = 10
blur { blur {
enabled = true enabled = true
size = 8 size = 8
passes = 1 passes = 1
} }
drop_shadow = yes drop_shadow = yes
shadow_range = 4 shadow_range = 4
shadow_render_power = 3 shadow_render_power = 3
col.shadow = rgba(${lib.strings.removePrefix "#" config.alyraffauf.desktop.theme.colors.shadow}EE) col.shadow = rgba(${lib.strings.removePrefix "#" config.alyraffauf.desktop.theme.colors.shadow}EE)
dim_special = 0.5 dim_special = 0.5
# Window-specific rules # Window-specific rules
layerrule = blur, waybar layerrule = blur, waybar
layerrule = ignorezero, waybar layerrule = ignorezero, waybar
layerrule = blur, launcher layerrule = blur, launcher
layerrule = blur, notifications layerrule = blur, notifications
layerrule = ignorezero, notifications layerrule = ignorezero, notifications
layerrule = blur, logout_dialog layerrule = blur, logout_dialog
layerrule = blur, swayosd layerrule = blur, swayosd
layerrule = ignorezero, swayosd layerrule = ignorezero, swayosd
} }
animations { animations {
enabled = yes enabled = yes
bezier = myBezier, 0.05, 0.9, 0.1, 1.05 bezier = myBezier, 0.05, 0.9, 0.1, 1.05
animation = border, 1, 10, default animation = border, 1, 10, default
animation = borderangle, 1, 8, default animation = borderangle, 1, 8, default
animation = fade, 1, 7, default animation = fade, 1, 7, default
animation = specialWorkspace, 1, 6, default, slidevert animation = specialWorkspace, 1, 6, default, slidevert
animation = windows, 1, 7, myBezier animation = windows, 1, 7, myBezier
animation = windowsOut, 1, 7, default, popin 80% animation = windowsOut, 1, 7, default, popin 80%
animation = workspaces, 1, 6, default animation = workspaces, 1, 6, default
} }
dwindle { dwindle {
# no_gaps_when_only = 1 # no_gaps_when_only = 1
preserve_split = yes # you probably want this preserve_split = yes # you probably want this
pseudotile = yes # master switch for pseudotiling. Enabling is bound to mainMod + P in the keybinds section below pseudotile = yes # master switch for pseudotiling. Enabling is bound to mainMod + P in the keybinds section below
} }
master { master {
always_center_master = true always_center_master = true
new_is_master = false new_is_master = false
} }
misc { misc {
disable_hyprland_logo = true disable_hyprland_logo = true
disable_splash_rendering = true disable_splash_rendering = true
focus_on_activate = true focus_on_activate = true
vfr = true vfr = true
} }
# Window Rules # Window Rules
windowrulev2 = center(1),class:(.blueman-manager-wrapped) ${
windowrulev2 = center(1),class:(blueberry.py) lib.strings.concatMapStringsSep
windowrulev2 = center(1),class:(com.github.wwmm.easyeffects) "\n"
windowrulev2 = center(1),class:(nmtui) (x: ''
windowrulev2 = center(1),class:(${x})
windowrulev2 = float,class:(${x})
windowrulev2 = size 40% 60%,class:(${x}})
'')
[
".blueman-manager-wrapped"
"blueberry.py"
"com.github.wwmm.easyeffects"
"pavucontrol"
]
}
windowrulev2 = center(1),class:(org.keepassxc.KeePassXC) windowrulev2 = center(1),class:(org.keepassxc.KeePassXC)
windowrulev2 = center(1),class:(pavucontrol)
windowrulev2 = float, class:^(firefox)$, title:^(Picture-in-Picture)$
windowrulev2 = float,class:(.blueman-manager-wrapped)
windowrulev2 = float,class:(blueberry.py)
windowrulev2 = float,class:(com.github.wwmm.easyeffects)
windowrulev2 = float,class:(nmtui)
windowrulev2 = float,class:(org.keepassxc.KeePassXC) windowrulev2 = float,class:(org.keepassxc.KeePassXC)
windowrulev2 = float,class:(pavucontrol) windowrulev2 = size 80% 80%,class:(org.keepassxc.KeePassXC)
windowrulev2 = float, class:^(firefox)$, title:^(Picture-in-Picture)$
windowrulev2 = move 70% 20%, class:^(firefox)$, title:^(Picture-in-Picture)$ windowrulev2 = move 70% 20%, class:^(firefox)$, title:^(Picture-in-Picture)$
windowrulev2 = pin, class:^(firefox)$, title:^(Picture-in-Picture)$ windowrulev2 = pin, class:^(firefox)$, title:^(Picture-in-Picture)$
windowrulev2 = size 40% 60%,class:(.blueman-manager-wrapped)
windowrulev2 = size 40% 60%,class:(blueberry.py)
windowrulev2 = size 40% 60%,class:(com.github.wwmm.easyeffects)
windowrulev2 = size 40% 60%,class:(nmtui)
windowrulev2 = size 40% 60%,class:(pavucontrol)
windowrulev2 = size 80% 80%,class:(org.keepassxc.KeePassXC)
windowrulev2 = suppressevent maximize, class:.* windowrulev2 = suppressevent maximize, class:.*
# Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more # Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more
@ -351,29 +413,21 @@
bind = ${modifier} SHIFT, comma, exec, ${hyprnome} --previous --move bind = ${modifier} SHIFT, comma, exec, ${hyprnome} --previous --move
bind = ${modifier} SHIFT, period, exec, ${hyprnome} --move bind = ${modifier} SHIFT, period, exec, ${hyprnome} --move
# Switch workspaces with mainMod + [0-9] # Switch workspaces with mainMod + [1-9]
bind = ${modifier}, 1, workspace, 1 ${
bind = ${modifier}, 2, workspace, 2 lib.strings.concatMapStringsSep
bind = ${modifier}, 3, workspace, 3 "\n"
bind = ${modifier}, 4, workspace, 4 (x: "bind = ${modifier}, ${toString x}, workspace, ${toString x}")
bind = ${modifier}, 5, workspace, 5 defaultWorkspaces
bind = ${modifier}, 6, workspace, 6 }
bind = ${modifier}, 7, workspace, 7
bind = ${modifier}, 8, workspace, 8
bind = ${modifier}, 9, workspace, 9
bind = ${modifier}, 0, workspace, 10
# Move active window to a workspace with mainMod + SHIFT + [0-9] # Move active window to a workspace with mainMod + SHIFT + [1-9]
bind = ${modifier} SHIFT, 1, movetoworkspace, 1 ${
bind = ${modifier} SHIFT, 2, movetoworkspace, 2 lib.strings.concatMapStringsSep
bind = ${modifier} SHIFT, 3, movetoworkspace, 3 "\n"
bind = ${modifier} SHIFT, 4, movetoworkspace, 4 (x: "bind = ${modifier} SHIFT, ${toString x}, movetoworkspace, ${toString x}")
bind = ${modifier} SHIFT, 5, movetoworkspace, 5 defaultWorkspaces
bind = ${modifier} SHIFT, 6, movetoworkspace, 6 }
bind = ${modifier} SHIFT, 7, movetoworkspace, 7
bind = ${modifier} SHIFT, 8, movetoworkspace, 8
bind = ${modifier} SHIFT, 9, movetoworkspace, 9
bind = ${modifier} SHIFT, 0, movetoworkspace, 10
# Move workspace to another output. # Move workspace to another output.
bind = ${modifier} CONTROL SHIFT, Left, movecurrentworkspacetomonitor, l bind = ${modifier} CONTROL SHIFT, Left, movecurrentworkspacetomonitor, l
@ -431,17 +485,13 @@
bind = , right, movewindow, r bind = , right, movewindow, r
bind = , up, movewindow, u bind = , up, movewindow, u
bind = , down, movewindow, d bind = , down, movewindow, d
# Move active window to a workspace with [0-9] # Move active window to a workspace with [1-9]
bind = , 1, movetoworkspace, 1 ${
bind = , 2, movetoworkspace, 2 lib.strings.concatMapStringsSep
bind = , 3, movetoworkspace, 3 "\n"
bind = , 4, movetoworkspace, 4 (x: "bind = , ${toString x}, movetoworkspace, ${toString x}")
bind = , 5, movetoworkspace, 5 defaultWorkspaces
bind = , 6, movetoworkspace, 6 }
bind = , 7, movetoworkspace, 7
bind = , 8, movetoworkspace, 8
bind = , 9, movetoworkspace, 9
bind = , 0, movetoworkspace, 10
# hyprnome # hyprnome
bind = , comma, exec, ${hyprnome} --previous --move bind = , comma, exec, ${hyprnome} --previous --move
bind = , period, exec, ${hyprnome} --move bind = , period, exec, ${hyprnome} --move

View file

@ -1,43 +0,0 @@
{
pkgs,
lib,
config,
...
}: let
hyprbg-randomWallpaper = pkgs.writeShellScriptBin "hyprbg-randomWallpaper" ''
kill `pidof swaybg`
OLD_PIDS=()
directory=${config.home.homeDirectory}/.local/share/backgrounds
if [ -d "$directory" ]; then
while true; do
NEW_PIDS=()
monitor=`${config.wayland.windowManager.hyprland.package}/bin/hyprctl monitors | grep Monitor | awk '{print $2}'`
for m in ''${monitor[@]}; do
random_background=$(ls $directory/*.{png,jpg} | shuf -n 1)
${lib.getExe pkgs.swaybg} -o $m -i $random_background &
NEW_PIDS+=($!)
done
if [ ''${OLD_PIDS[@]} -gt 0 ]; then
sleep 5
fi
for pid in ''${OLD_PIDS[@]}; do
kill $pid
done
OLD_PIDS=$NEW_PIDS
sleep 895
done
fi
'';
in {
config = lib.mkIf config.alyraffauf.desktop.hyprland.randomWallpaper {
home.packages = with pkgs; [swaybg hyprbg-randomWallpaper];
wayland.windowManager.hyprland.extraConfig = "exec-once = ${lib.getExe hyprbg-randomWallpaper}";
};
}

View file

@ -1,14 +0,0 @@
{
pkgs,
lib,
config,
...
}: {
config = lib.mkIf config.alyraffauf.desktop.hyprland.redShift {
home.packages = with pkgs; [gammastep];
wayland.windowManager.hyprland.extraConfig = ''
exec-once = ${pkgs.geoclue2}/libexec/geoclue-2.0/demos/agent
exec-once = ${lib.getExe pkgs.gammastep}
'';
};
}

View file

@ -1,16 +0,0 @@
{
pkgs,
lib,
config,
...
}: {
config = lib.mkIf config.alyraffauf.desktop.hyprland.tabletMode.virtKeyboard {
home.packages = with pkgs; [squeekboard];
wayland.windowManager.hyprland.extraConfig = ''
exec-once = ${lib.getExe' pkgs.squeekboard "squeekboard"}
bindl=,switch:on:Lenovo Yoga Tablet Mode Control switch,exec,${lib.getExe pkgs.dconf} write /org/gnome/desktop/a11y/applications/screen-keyboard-enabled true
bindl=,switch:off:Lenovo Yoga Tablet Mode Control switch,exec,${lib.getExe pkgs.dconf} write /org/gnome/desktop/a11y/applications/screen-keyboard-enabled false
'';
};
}