refactor: use helper funcs for hyprland conf
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-11-20 20:12:24 -05:00
parent 318ccef645
commit 85348d1a6c
13 changed files with 414 additions and 173 deletions

View file

@ -3,15 +3,15 @@
inputs, inputs,
}: let }: let
flake = import ./flake inputs; flake = import ./flake inputs;
hypr = import ./hypr inputs.nixpkgs.lib;
strings = import ./strings inputs.nixpkgs.lib; strings = import ./strings inputs.nixpkgs.lib;
lib = flake // strings; lib = flake // hypr // strings;
in in
# Expose main attrs # Expose main attrs
lib lib
# Expose all funcs # Expose all funcs
// strings // {inherit flake hypr strings;}
// flake
# Expose funcs that require pkgs # Expose funcs that require pkgs
// perSystem ( // perSystem (
pkgs: pkgs:

57
lib/hypr/default.nix Normal file
View file

@ -0,0 +1,57 @@
{
concatStringsSep,
elemAt,
optionals,
...
}: rec {
pointToStr = p: "${toString (elemAt p 0)}, ${toString (elemAt p 1)}";
mkBezier = {
name,
p0,
p1,
}:
concatStringsSep "," [name (pointToStr p0) (pointToStr p1)];
mkAnimation = {
name,
enable ? true,
duration ? 0, # in ds (100ms)
bezier ? "default",
style ? null,
}:
concatStringsSep "," (
[
name
(
if enable
then "1"
else "0"
)
]
++ optionals enable (
[
(toString duration)
bezier
]
++ optionals (style != null) [style]
)
);
mkLayerRule = {
rule,
namespace,
}:
concatStringsSep "," [rule namespace];
mkBind = {
modifier ? "",
key,
dispatcher ? "exec",
command ? null,
}:
concatStringsSep "," (
[modifier key dispatcher]
++ optionals (command != null) [command]
);
}

View file

@ -1,5 +1,5 @@
{ {
concatStringsSep, concatStrings,
stringToCharacters, stringToCharacters,
substring, substring,
tail, tail,
@ -7,5 +7,5 @@
... ...
}: { }: {
mkVersion = src: "0.0.0+" + src.shortRev; mkVersion = src: "0.0.0+" + src.shortRev;
capitalise = str: (toUpper (substring 0 1 str) + (concatStringsSep "" (tail (stringToCharacters str)))); capitalise = str: (toUpper (substring 0 1 str) + (concatStrings (tail (stringToCharacters str))));
} }

View file

@ -53,7 +53,7 @@ in {
home-manager.users.${cfgDesktop.user}.imports = [ home-manager.users.${cfgDesktop.user}.imports = [
hmOpts hmOpts
(import ./packages.nix self) (import ./packages.nix self)
./hyprland.nix (import ./hyprland.nix self)
]; ];
}; };

View file

@ -1,5 +1,8 @@
{...}: { self: {lib, ...}: let
wayland.windowManager.hyprland = { inherit (lib) map;
inherit (self.lib.hypr) mkAnimation mkBezier mkBind mkLayerRule;
in {
config.wayland.windowManager.hyprland = {
settings = { settings = {
general = { general = {
gaps_in = 5; gaps_in = 5;
@ -22,35 +25,95 @@
animations = { animations = {
enabled = true; enabled = true;
bezier = [ bezier = map mkBezier [
"easeInQuart , 0.895, 0.03, 0.685, 0.22" {
"easeOutQuart , 0.165, 0.84, 0.44 , 1" name = "easeInQuart";
"easeInOutQuart, 0.77, 0 , 0.175, 1" p0 = [0.895 0.030];
p1 = [0.685 0.220];
}
{
name = "easeOutQuart";
p0 = [0.165 0.840];
p1 = [0.440 1.000];
}
{
name = "easeInOutQuart";
p0 = [0.770 0.000];
p1 = [0.175 1.000];
}
# Fade out # fade out
"easeInExpo , 0.95, 0.05, 0.795, 0.035" {
name = "easeInExpo";
p0 = [0.950 0.050];
p1 = [0.795 0.035];
}
]; ];
animation = [ animation = map mkAnimation [
"workspaces, 1, 6, easeOutQuart, slide" {
name = "workspaces";
duration = 6;
bezier = "easeOutQuart";
style = "slide";
}
"windows, 1, 4, easeOutQuart, slide" {
"fadeIn , 0" name = "windows";
"fadeOut, 1, 3000, easeInExpo" duration = 4;
bezier = "easeOutQuart";
style = "slide";
}
{
name = "fadeIn";
enable = false;
}
{
name = "fadeOut";
duration = 4;
bezier = "easeInExpo";
}
"fadeLayersIn , 0" {
"fadeLayersOut, 1, 3000, easeInExpo" name = "fadeLayersIn";
"layers , 1, 4 , easeInOutQuart, slide left" enable = false;
}
{
name = "fadeLayersOut";
duration = 4;
bezier = "easeInExpo";
}
{
name = "layers";
duration = 4;
bezier = "easeInOutQuart";
style = "fade";
}
]; ];
}; };
layerrule = [ layerrule = map mkLayerRule [
"animation popin, ^(hyprpaper.*)" {
"animation fade, ^(bg-layer.*)" rule = "animation popin";
namespace = "^(hyprpaper.*)";
}
{
rule = "animation fade";
namespace = "^(bg-layer.*)";
}
{
rule = "noanim";
namespace = "^(noanim-.*)";
}
# Lockscreen blur {
"blur, ^(blur-bg.*)" rule = "blur";
"ignorealpha 0.19, ^(blur-bg.*)" namespace = "^(blur-bg.*)";
}
{
rule = "ignorealpha 0.19";
namespace = "^(blur-bg.*)";
}
]; ];
exec-once = [ exec-once = [
@ -58,23 +121,79 @@
"sleep 3; ags request 'open win-applauncher'" "sleep 3; ags request 'open win-applauncher'"
]; ];
bind = [ bind = map mkBind [
"$mainMod SHIFT, E , exec, ags toggle win-powermenu" {
"$mainMod , D , exec, ags toggle win-applauncher" modifier = "$mainMod SHIFT";
"$mainMod , V , exec, ags toggle win-clipboard" key = "E";
" , Print, exec, ags toggle win-screenshot" command = "ags toggle win-powermenu";
]; }
binde = [ {
## Brightness control modifier = "$mainMod";
", XF86MonBrightnessUp , exec, ags request 'Brightness.screen +0.05'" key = "D";
", XF86MonBrightnessDown, exec, ags request 'Brightness.screen -0.05'" command = "ags toggle win-applauncher";
}
## Volume control {
", XF86AudioRaiseVolume , exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+ & ags request 'popup speaker' &" modifier = "$mainMod";
", XF86AudioLowerVolume , exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- & ags request 'popup speaker' &" key = "V";
]; command = "ags toggle win-clipboard";
bindn = [" , Escape , exec, ags request closeAll"]; }
bindr = ["CAPS, Caps_Lock, exec, ags request fetchCapsState"]; {
}; key = "Print";
}; command = "ags toggle win-screenshot";
}
{
key = "XF86AudioMute";
command = "pactl set-sink-mute @DEFAULT_SINK@ toggle";
}
{
key = "XF86AudioMicMute";
command = "pactl set-source-mute @DEFAULT_SOURCE@ toggle";
}
{
modifier = "$mainMod";
key = "Print";
command = "bash -c \"grim -g \\\"$(slurp)\\\" - | satty -f -\"";
}
];
binde = map mkBind [
{
key = "XF86MonBrightnessUp";
command = "ags request 'Brightness.screen +0.05'";
}
{
key = "XF86MonBrightnessDown";
command = "ags request 'Brightness.screen -0.05'";
}
{
key = "XF86AudioRaiseVolume";
command = "wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+ & ags request 'popup speaker' &";
}
{
key = "XF86AudioLowerVolume";
command = "wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- & ags request 'popup speaker' &";
}
];
bindn = map mkBind [
{
key = "Escape";
command = "ags request closeAll";
}
];
bindr = map mkBind [
{
modifier = "CAPS";
key = "Caps_Lock";
command = "ags request fetchCapsState";
}
];
};
};
# For accurate stack trace
_file = ./default.nix;
} }

View file

@ -4,17 +4,18 @@ self: {
pkgs, pkgs,
... ...
}: let }: let
inherit (self.inputs) hyprgrass hyprland hyprland-plugins; inherit (self.inputs) hyprland;
inherit (self.lib.hypr) mkBind;
in { in {
imports = [ imports = [
(import ../../ags self) (import ../../ags self)
./modules/dconf.nix ./modules/dconf.nix
./modules/printer.nix ./modules/printer.nix
./modules/security.nix
(import ./modules/audio.nix self) (import ./modules/audio.nix self)
(import ./modules/packages.nix self) (import ./modules/packages.nix self)
(import ./modules/ratbag-mice.nix self) (import ./modules/ratbag-mice.nix self)
(import ./modules/security.nix self)
]; ];
config = let config = let
@ -73,10 +74,10 @@ in {
./home/dev.nix ./home/dev.nix
# Plugins # Plugins
(import ./home/hyprexpo.nix hyprland-plugins) (import ./home/hyprexpo.nix self)
(import ./home/hyprgrass.nix hyprgrass) (import ./home/hyprgrass.nix self)
./home/inputs.nix (import ./home/inputs.nix self)
(import ../theme self) (import ../theme self)
]; ];
@ -179,16 +180,20 @@ in {
"$mainMod SHIFT, 8, movetoworkspace, 8" "$mainMod SHIFT, 8, movetoworkspace, 8"
"$mainMod SHIFT, 9, movetoworkspace, 9" "$mainMod SHIFT, 9, movetoworkspace, 9"
"$mainMod SHIFT, 0, movetoworkspace, 10" "$mainMod SHIFT, 0, movetoworkspace, 10"
",XF86AudioMute, exec, pactl set-sink-mute @DEFAULT_SINK@ toggle"
",XF86AudioMicMute, exec, pactl set-source-mute @DEFAULT_SOURCE@ toggle"
"$mainMod, Print, exec, bash -c \"grim -g \\\"$(slurp)\\\" - | satty -f -\""
]; ];
# Mouse Binds # Mouse Binds
bindm = [ bindm = map mkBind [
"$mainMod, mouse:272, movewindow" {
"$mainMod, mouse:273, resizewindow" modifier = "$mainMod";
key = "mouse:272";
dispatcher = "movewindow";
}
{
modifier = "$mainMod";
key = "mouse:273";
dispatcher = "resizewindow";
}
]; ];
misc = { misc = {

View file

@ -1,11 +1,12 @@
hyprland-plugins: {pkgs, ...}: { self: {pkgs, ...}: let
inherit (self.lib.hypr) mkBind;
in {
config = { config = {
wayland.windowManager.hyprland = { wayland.windowManager.hyprland = {
plugins = [hyprland-plugins.packages.${pkgs.system}.hyprexpo]; plugins = [self.inputs.hyprland-plugins.packages.${pkgs.system}.hyprexpo];
settings = { settings = {
plugin = { plugin.hyprexpo = {
hyprexpo = {
columns = 3; columns = 3;
gap_size = 5; gap_size = 5;
bg_col = "rgb(111111)"; bg_col = "rgb(111111)";
@ -16,10 +17,14 @@ hyprland-plugins: {pkgs, ...}: {
gesture_distance = 300; # how far is the "max" gesture_distance = 300; # how far is the "max"
gesture_positive = true; # positive = swipe down. Negative = swipe up. gesture_positive = true; # positive = swipe down. Negative = swipe up.
}; };
};
bind = [ bind = [
"ALT, tab, hyprexpo:expo, toggle" # can be: toggle, off/disable or on/enable (mkBind {
modifier = "ALT";
key = "tab";
dispatcher = "hyprexpo:expo";
command = "toggle"; # can be: toggle, off/disable or on/enable
})
]; ];
}; };
}; };

View file

@ -1,20 +1,20 @@
hyprgrass: { self: {
lib, lib,
osConfig, osConfig,
pkgs, pkgs,
... ...
}: let }: let
inherit (lib) mkIf; inherit (lib) map mkIf;
inherit (self.lib.hypr) mkBind;
cfg = osConfig.roles.desktop; cfg = osConfig.roles.desktop;
in { in {
config = mkIf cfg.isTouchscreen { config = mkIf cfg.isTouchscreen {
wayland.windowManager.hyprland = { wayland.windowManager.hyprland = {
plugins = [hyprgrass.packages.${pkgs.system}.default]; plugins = [self.inputs.hyprgrass.packages.${pkgs.system}.default];
settings = { settings = {
plugin = { plugin.touch_gestures = {
touch_gestures = {
# The default sensitivity is probably too low on tablet screens, # The default sensitivity is probably too low on tablet screens,
# I recommend turning it up to 4.0 # I recommend turning it up to 4.0
sensitivity = 4.0; sensitivity = 4.0;
@ -43,12 +43,23 @@ in {
# NOT recommended as it crashed a few times, once it's stabilized I'll make it the default # NOT recommended as it crashed a few times, once it's stabilized I'll make it the default
experimental.send_cancel = 0; experimental.send_cancel = 0;
hyprgrass-bind = [ hyprgrass-bind = map mkBind [
", edge:u:d, exec, ags request 'open win-applauncher'" {
", edge:d:u, exec, ags request 'osk open'" key = "edge:u:d";
command = "ags request 'open win-applauncher'";
}
{
key = "edge:d:u";
command = "ags request 'osk open'";
}
];
hyprgrass-bindm = map mkBind [
{
key = "longpress:2";
dispatcher = "movewindow";
}
]; ];
hyprgrass-bindm = [", longpress:2, movewindow"];
};
}; };
gestures = { gestures = {

View file

@ -1,5 +1,12 @@
{osConfig, ...}: { self: {
osConfig,
lib,
...
}: {
config = let config = let
inherit (lib) map;
inherit (self.lib.hypr) mkBind;
inherit (osConfig.services.xserver) xkb; inherit (osConfig.services.xserver) xkb;
inherit (osConfig.roles.desktop) mainMonitor; inherit (osConfig.roles.desktop) mainMonitor;
@ -16,7 +23,7 @@
in { in {
wayland.windowManager.hyprland = { wayland.windowManager.hyprland = {
settings = { settings = {
device = map (d: (mkConf d)) miceNames; device = map mkConf miceNames;
cursor = { cursor = {
no_hardware_cursors = osConfig.nvidia.enable; no_hardware_cursors = osConfig.nvidia.enable;
@ -47,11 +54,23 @@
}; };
}; };
bind = [ bind = map mkBind [
",XF86AudioPlay, exec, playerctl play-pause" {
",XF86AudioStop, exec, playerctl stop" key = "XF86AudioPlay";
",XF86AudioNext, exec, playerctl next" command = "playerctl play-pause";
",XF86AudioPrev, exec, playerctl previous" }
{
key = "XF86AudioStop";
command = "playerctl stop";
}
{
key = "XF86AudioNext";
command = "playerctl next";
}
{
key = "XF86AudioPrev";
command = "playerctl previous";
}
]; ];
}; };
}; };

View file

@ -4,12 +4,13 @@ self: {
pkgs, pkgs,
... ...
}: let }: let
inherit (self.lib.hypr) mkBind;
inherit (self.inputs) jellyfin-flake; inherit (self.inputs) jellyfin-flake;
in { in {
imports = [./dolphin.nix]; imports = [./dolphin.nix];
config = let config = let
inherit (lib) getExe optionals; inherit (lib) getExe map optionals;
inherit (pkgs.writers) writeTOML; inherit (pkgs.writers) writeTOML;
flakeDir = config.environment.variables.FLAKE; flakeDir = config.environment.variables.FLAKE;
@ -187,13 +188,31 @@ in {
"workspace special:spot silent,^(Spotify)$" "workspace special:spot silent,^(Spotify)$"
]; ];
bind = [ bind = map mkBind [
"$mainMod, Q, exec, foot" {
modifier = "$mainMod";
key = "Q";
command = "foot";
}
"$mainMod SHIFT, C, exec, wl-color-picker" {
modifier = "$mainMod SHIFT";
key = "C";
command = "wl-color-picker";
}
"$mainMod, P, togglespecialworkspace, protonmail" {
"$mainMod, S, togglespecialworkspace, spot" modifier = "$mainMod";
key = "P";
dispatcher = "togglespecialworkspace";
command = "protonmail";
}
{
modifier = "$mainMod";
key = "S";
dispatcher = "togglespecialworkspace";
command = "spot";
}
]; ];
}; };
}; };

View file

@ -1,11 +1,12 @@
{ self: {
config, config,
lib, lib,
pkgs, pkgs,
... ...
}: { }: {
config = let config = let
inherit (lib) getExe mkIf; inherit (self.lib.hypr) mkBind;
inherit (lib) getExe map mkIf;
cfg = config.roles.desktop; cfg = config.roles.desktop;
@ -71,8 +72,7 @@
lockPkg lockPkg
]; ];
wayland.windowManager.hyprland = { wayland.windowManager.hyprland.settings = {
settings = {
exec-once = [ exec-once = [
"gnome-keyring-daemon --start --components=secrets" "gnome-keyring-daemon --start --components=secrets"
"${pkgs.plasma5Packages.polkit-kde-agent}/libexec/polkit-kde-authentication-agent-1" "${pkgs.plasma5Packages.polkit-kde-agent}/libexec/polkit-kde-authentication-agent-1"
@ -88,13 +88,16 @@
"move cursor -370 -144,^(org.kde.ksshaskpass)$" "move cursor -370 -144,^(org.kde.ksshaskpass)$"
]; ];
bind = [ bind = map mkBind [
"$mainMod, L, exec, ${getExe lockPkg}" {
modifier = "$mainMod";
key = "L";
command = getExe lockPkg;
}
]; ];
}; };
}; };
}; };
};
# For accurate stack trace # For accurate stack trace
_file = ./security.nix; _file = ./security.nix;

View file

@ -5,7 +5,8 @@ self: {
... ...
}: { }: {
config = let config = let
inherit (lib) filterAttrs hasPrefix optionals; inherit (lib) optionals;
inherit (self.lib.hypr) mkAnimation;
inherit (import ./setupMonitors.nix {inherit config pkgs;}) setupMonitors; inherit (import ./setupMonitors.nix {inherit config pkgs;}) setupMonitors;
@ -20,8 +21,6 @@ self: {
.wayland .wayland
.windowManager .windowManager
.hyprland; .hyprland;
devices = filterAttrs (n: v: hasPrefix "device:" n) cfgHypr.settings;
in { in {
home-manager.users.greeter = { home-manager.users.greeter = {
imports = [ imports = [
@ -30,12 +29,12 @@ self: {
wayland.windowManager.hyprland = { wayland.windowManager.hyprland = {
enable = true; enable = true;
package = cfgHypr.finalPackage;
systemd.enable = false; systemd.enable = false;
settings = package = cfgHypr.finalPackage;
{
inherit (cfgHypr.settings) cursor input misc monitor; settings = {
inherit (cfgHypr.settings) cursor device input misc monitor;
envd = optionals (config.nvidia.enable) [ envd = optionals (config.nvidia.enable) [
"LIBVA_DRIVER_NAME, nvidia" "LIBVA_DRIVER_NAME, nvidia"
@ -52,17 +51,23 @@ self: {
shadow.enabled = false; shadow.enabled = false;
}; };
animation = [ animation = map mkAnimation [
"fadeLayersIn, 0" {
"layers, 1, 4, default, popin 0%" name = "fadeLayersIn";
enable = false;
}
{
name = "layers";
duration = 4;
style = "popin";
}
]; ];
exec-once = [ exec-once = [
setupMonitors setupMonitors
"agsGreeter &> /tmp/ags-greetd.log; hyprctl dispatch exit" "agsGreeter &> /tmp/ags-greetd.log; hyprctl dispatch exit"
]; ];
} };
// devices;
}; };
}; };
}; };

View file

@ -22,8 +22,7 @@ self: {pkgs, ...}: {
home.file.".local/share/icons/${hyprcursorThemeName}".source = cursorTheme; home.file.".local/share/icons/${hyprcursorThemeName}".source = cursorTheme;
wayland.windowManager.hyprland = { wayland.windowManager.hyprland.settings = {
settings = {
envd = [ envd = [
"XCURSOR_THEME, ${cursorThemeName}" "XCURSOR_THEME, ${cursorThemeName}"
"XCURSOR_SIZE, ${toString cursorSize}" "XCURSOR_SIZE, ${toString cursorSize}"
@ -34,7 +33,6 @@ self: {pkgs, ...}: {
]; ];
}; };
}; };
};
# For accurate stack trace # For accurate stack trace
_file = ./cursors.nix; _file = ./cursors.nix;