From c6e05ba9b0ee4b72415d77c836014ed26873292b Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Wed, 28 Aug 2024 13:52:43 +0200 Subject: [PATCH] hyprland: move to individual files for config --- modules/wms/wayland/hypr/land.nix | 16 +-- modules/wms/wayland/hyprland/binds.nix | 108 +++++++++++++++++++ modules/wms/wayland/hyprland/decorations.nix | 72 +++++++++++++ modules/wms/wayland/hyprland/exec.nix | 30 ++++++ modules/wms/wayland/hyprland/module.nix | 66 ++++++++++++ modules/wms/wayland/hyprland/settings.nix | 73 +++++++++++++ modules/wms/wayland/hyprland/workspaces.nix | 57 ++++++++++ 7 files changed, 414 insertions(+), 8 deletions(-) create mode 100644 modules/wms/wayland/hyprland/workspaces.nix diff --git a/modules/wms/wayland/hypr/land.nix b/modules/wms/wayland/hypr/land.nix index 2da1207..d31162f 100644 --- a/modules/wms/wayland/hypr/land.nix +++ b/modules/wms/wayland/hypr/land.nix @@ -9,7 +9,6 @@ inherit (config.modules.other.system) username; inherit (config.modules.style) cursor; inherit (config.modules.system.hardware) monitors; - inherit (inputs'.split-monitor-workspaces.packages) split-monitor-workspaces @@ -17,25 +16,29 @@ inherit (lib) imap0 flatten optionalString mkIf mkDefault mapAttrsToList; inherit (builtins) map genList attrNames toString; in { + # we disable the default hyprland module + disabledModules = ["programs/hyprland.nix"]; + config = mkIf cfg.enable { programs.hyprland = { - enable = false; + enable = true; inherit (cfg) package portalPackage; }; # xdg Portal xdg.portal = { enable = true; configPackages = mkDefault [ - inputs'.hyprland.packages.xdg-desktop-portal-hyprland + cfg.portalPackage ]; extraPortals = [ pkgs.xdg-desktop-portal-gtk - inputs'.hyprland.packages.xdg-desktop-portal-hyprland + cfg.portalPackage ]; config = { common.default = ["hyprland"]; }; }; + home-manager.users.${username} = { wayland.windowManager.hyprland = { enable = true; @@ -68,7 +71,7 @@ in { # "Unknown-1,disable" # ]; - # Thanks Poz for inspiration, using an attrset is actually much smarter + # Thanks Poz for inspiration, using an attrSet is actually much smarter # than using a normal list. monitor = mapAttrsToList ( @@ -317,9 +320,6 @@ in { "${pkgs.wlsunset}/bin/wlsunset -S 06:00 -s 20:00" ]; - exec = [ - ]; - plugin = { split-monitor-workspaces = { keep-focued = true; diff --git a/modules/wms/wayland/hyprland/binds.nix b/modules/wms/wayland/hyprland/binds.nix index e69de29..ddaa2aa 100644 --- a/modules/wms/wayland/hyprland/binds.nix +++ b/modules/wms/wayland/hyprland/binds.nix @@ -0,0 +1,108 @@ +{ + config, + pkgs, +}: let + cfg = config.modules.usrEnv.desktops.hyprland; + inherit (config.modules.other.system) username; + inherit (builtins) map genList toString; +in { + home-manager.users.${username}.wayland.windowManager.hyprland.settings = { + # Keybinds + bind = + # workspaces + # split-workspace is because of the split-workspace plugin + map ( + i: let + mod = a: b: a - (b * (a / b)); + key = toString (mod i 10); + workspace = toString i; + in "$mainMod, ${key}, split-workspace, ${workspace}" + ) (genList (i: i + 1) 10) + # split-movetoworkspacesilent + ++ map ( + i: let + mod = a: b: a - (b * (a / b)); + key = toString (mod i 10); + workspace = toString i; + in "$mainMod SHIFT, ${key}, split-movetoworkspacesilent, ${workspace}" + ) (genList (i: i + 1) 10) + ++ [ + "$mainMod, RETURN, exec, ${pkgs.foot}/bin/foot" + "$mainMod, Q, killactive" + "$mainMod, F, fullscreen, 0" + "$mainMod, D, exec, ${pkgs.procps}/bin/pkill fuzzel || ${pkgs.fuzzel}/bin/fuzzel" + "$mainMod, SPACE, togglefloating, active" + + # Move Windows + "$mainMod SHIFT, H, movewindow, l" + "$mainMod SHIFT, J, movewindow, d" + "$mainMod SHIFT, K, movewindow, u" + "$mainMod SHIFT, L, movewindow, r" + + # Screenshotting + "$mainMod, S, exec, ${pkgs.grimblast}/bin/grimblast copy area" + + # File manager + "$mainMod, E, exec, ${pkgs.xfce.thunar}/bin/thunar" + + # Toggle the three different special workspaces. + "$mainMod, N, togglespecialworkspace, nixos" + "$mainMod, X, togglespecialworkspace, keepassxc" + + # Reload hyprland + "$mainMod, R, exec, ${cfg.package}/bin/hyprctl reload" + + # Restart waybar + "$mainMod CONTROL, B, exec, ${pkgs.procps}/bin/pkill waybar || ${pkgs.waybar}/bin/waybar" + ]; + + binde = [ + # window focus + "$mainMod, H, movefocus, l" + "$mainMod, J, movefocus, d" + "$mainMod, K, movefocus, u" + "$mainMod, L, movefocus, r" + ]; + + # Media controls + bindl = let + play-pause = "${pkgs.playerctl}/bin/playerctl play-pause"; + stop = "${pkgs.playerctl}/bin/playerctl stop"; + prev = "${pkgs.playerctl}/bin/playerctl previous"; + next = "${pkgs.playerctl}/bin/playerctl next"; + toggle-mute = "${pkgs.pamixer}/bin/pamixer --toggle-mute"; + in [ + ", XF86AudioMedia, exec, ${play-pause}" + ", XF86AudioPlay, exec, ${play-pause}" + ", XF86AudioStop, exec, ${stop}" + ", XF86AudioPrev, exec, ${prev}" + ", XF86AudioNext, exec, ${next}" + ", XF86AudioMute, exec, ${toggle-mute}" + ]; + + # locked + repeat + bindle = let + volume_up = "${pkgs.pamixer}/bin/pamixer -ui 5"; + volume_down = "${pkgs.pamixer}/bin/pamixer -ud 5"; + brightness_up = "${pkgs.brightnessctl}/bin/brightnessctl set +10%"; + brightness_down = "${pkgs.brightnessctl}/bin/brightnessctl set 10%-"; + in [ + ", XF86AudioRaiseVolume, exec, ${volume_up}" + ", XF86AudioLowerVolume, exec, ${volume_down}" + ", XF86MonBrightnessUp, exec, ${brightness_up}" + ", XF86MonBrightnessDown, exec, ${brightness_down}" + ]; + + # Mouse settings + bindm = [ + "$mainMod, mouse:272, movewindow" + "$mainMod, mouse:273, resizewindow" + ]; + + # Some more movement-related settings + binds = { + pass_mouse_when_bound = false; + movefocus_cycles_fullscreen = false; + }; + }; +} diff --git a/modules/wms/wayland/hyprland/decorations.nix b/modules/wms/wayland/hyprland/decorations.nix index e69de29..4ae7739 100644 --- a/modules/wms/wayland/hyprland/decorations.nix +++ b/modules/wms/wayland/hyprland/decorations.nix @@ -0,0 +1,72 @@ +{config, ...}: let + inherit (config.modules.other.system) username; +in { + home-manager.users.${username} = { + wayland.windowManager.hyprland.settings = { + #Decoration settings + decoration = { + rounding = 0; + blur = { + enabled = true; + size = 3; + passes = 2; + }; + drop_shadow = 1; + shadow_range = 15; + shadow_render_power = 2; + shadow_ignore_window = 1; + shadow_offset = "2 4"; + shadow_scale = 1; + }; + # Bezier curves for aninmations. + # Generate your own at https://www.cssportal.com/css-cubic-bezier-generator/ + bezier = [ + "dupa, 0.1, 0.9, 0.1, 1.05" + ]; + # Hyprland anomations, using the above bezier curves + animations = { + enabled = false; + animation = [ + "windows, 1, 4, dupa, popin" + "windowsOut, 1, 4, dupa, slide" + "border, 1, 15, default" + "fade, 1, 10, default" + "workspaces, 1, 5, dupa, slidevert" + ]; + }; + + dwindle = {no_gaps_when_only = true;}; + + cursor = { + hide_on_key_press = true; + no_hardware_cursors = true; + }; + + misc = { + enable_swallow = true; + swallow_regex = "foot"; + focus_on_activate = true; + vrr = 1; + vfr = true; + animate_manual_resizes = false; + animate_mouse_windowdragging = false; + force_default_wallpaper = 0; + }; + + # Window rules for some programs. + windowrulev2 = [ + "float, class:^(Tor Browser)$" + "float, class:^(mpv)$" + "float, class:^(imv)$" + "float, title:^(Picture-in-Picture)$" + "float, title:^(.*)(Choose User Profile)(.*)$" + "float, title:^(blob:null/)(.*)$" + "float, class:^(xdg-desktop-portal-gtk)$" + "float, class:^(code), title: ^(Open*)" + "size 70% 70%, class:^(code), title: ^(Open*)" + "center, class: ^(code), title: ^(Open*)" + "float, class:^(org.keepassxc.KeePassXC)$" + ]; + }; + }; +} diff --git a/modules/wms/wayland/hyprland/exec.nix b/modules/wms/wayland/hyprland/exec.nix index e69de29..1cb92b9 100644 --- a/modules/wms/wayland/hyprland/exec.nix +++ b/modules/wms/wayland/hyprland/exec.nix @@ -0,0 +1,30 @@ +{ + config, + pkgs, + ... +}: let + inherit (config.modules.other.system) username; + inherit (config.modules.style) cursor; + inherit (builtins) toString; +in { + home-manager.users.${username} = { + wayland.windowManager.hyprland.settings = { + # Hyprland settings + # Programs which get executed at Hyprland start. + exec-once = [ + "hyprctl setcursor ${cursor.name} ${toString cursor.size}" + #start waybar + "${pkgs.waybar}/bin/waybar" + + # run persistent special workspace windows + "[workspace special:nixos; silent;tile] ${pkgs.foot}/bin/foot -D ~/projects/nichts" + + "[workspace special:keepassxc; silent;tile] ${pkgs.keepassxc}/bin/keepassxc" + + "${pkgs.swww}/bin/swww-daemon" + + "${pkgs.wlsunset}/bin/wlsunset -S 06:00 -s 20:00" + ]; + }; + }; +} diff --git a/modules/wms/wayland/hyprland/module.nix b/modules/wms/wayland/hyprland/module.nix index e69de29..be06f8b 100644 --- a/modules/wms/wayland/hyprland/module.nix +++ b/modules/wms/wayland/hyprland/module.nix @@ -0,0 +1,66 @@ +{ + config, + pkgs, + lib, + inputs', + ... +}: let + cfg = config.modules.usrEnv.desktops.hyprland; + inherit (config.modules.other.system) username; + inherit + (inputs'.split-monitor-workspaces.packages) + split-monitor-workspaces + ; + inherit (lib) mkIf mkDefault; +in { + imports = [ + ./binds.nix + ./decorations.nix + ./exec.nix + ./settings.nix + ./workspaces.nix + ]; + # we disable the default hyprland module + disabledModules = ["programs/hyprland.nix"]; + + config = mkIf cfg.enable { + programs.hyprland = { + enable = true; + inherit (cfg) package portalPackage; + }; + # xdg Portal + xdg.portal = { + enable = true; + configPackages = mkDefault [ + cfg.portalPackage + ]; + extraPortals = [ + pkgs.xdg-desktop-portal-gtk + cfg.portalPackage + ]; + config = { + common.default = ["hyprland"]; + }; + }; + + home-manager.users.${username} = { + wayland.windowManager.hyprland = { + enable = true; + inherit (cfg) package; + + # Split-monitor-workspaces provides awesome-like workspace behaviour + plugins = [ + split-monitor-workspaces + ]; + + # Xwayland for X applications + xwayland.enable = true; + # No idea why I set this + systemd = { + enable = true; + variables = ["--all"]; + }; + }; + }; + }; +} diff --git a/modules/wms/wayland/hyprland/settings.nix b/modules/wms/wayland/hyprland/settings.nix index e69de29..061b79a 100644 --- a/modules/wms/wayland/hyprland/settings.nix +++ b/modules/wms/wayland/hyprland/settings.nix @@ -0,0 +1,73 @@ +{ + config, + lib, + ... +}: let + inherit (config.modules.other.system) username; + inherit (config.modules.system.hardware) monitors; + inherit (lib) mapAttrsToList; + inherit (builtins) toString; +in { + home-manager.users.${username} = { + wayland.windowManager.hyprland.settings = { + # Hyprland settings + "$mainMod" = "SUPER"; + + # Monitor config + # monitor = [ + # "eDP-1,1920x1080,0x0,1" + # # "DP-2,1920x1080,0x0,1" + # # "HDMI-A-2,1920x1080,1920x0,1" + # # "HDMI-A-1,1920x1080,3840x0,1" + # # Had the shadow monitor bug, so had to disable all unknown monitors. + # "Unknown-1,disable" + # ]; + + # Thanks Poz for inspiration, using an attrSet is actually much smarter + # than using a normal list. + monitor = + mapAttrsToList ( + name: m: let + w = toString m.resolution.x; + h = toString m.resolution.y; + refreshRate = toString m.refreshRate; + x = toString m.position.x; + y = toString m.position.y; + scale = toString m.scale; + in "${name},${w}x${h}@${refreshRate},${x}x${y},${scale}" + ) + monitors; + + # Input settings + input = { + kb_layout = "de,us"; + kb_variant = ",colemak_dh_wide"; + kb_options = "grp:rctrl_rshift_toggle"; + + follow_mouse = true; + + repeat_rate = 50; + repeat_delay = 200; + + touchpad = { + disable_while_typing = true; + }; + }; + + general = { + gaps_in = 0; + gaps_out = 0; + border_size = 2; + + no_border_on_floating = true; + }; + + plugin = { + split-monitor-workspaces = { + keep-focued = true; + count = 10; + }; + }; + }; + }; +} diff --git a/modules/wms/wayland/hyprland/workspaces.nix b/modules/wms/wayland/hyprland/workspaces.nix new file mode 100644 index 0000000..55e9b99 --- /dev/null +++ b/modules/wms/wayland/hyprland/workspaces.nix @@ -0,0 +1,57 @@ +{ + config, + lib, + ... +}: let + inherit (config.modules.other.system) username; + inherit (config.modules.system.hardware) monitors; + inherit (lib) imap0 flatten optionalString; + inherit (builtins) map genList attrNames toString; +in { + home-manager.users.${username} = { + wayland.windowManager.hyprland = { + settings = { + # Monitor config + # monitor = [ + # "eDP-1,1920x1080,0x0,1" + # # "DP-2,1920x1080,0x0,1" + # # "HDMI-A-2,1920x1080,1920x0,1" + # # "HDMI-A-1,1920x1080,3840x0,1" + # # Had the shadow monitor bug, so had to disable all unknown monitors. + # "Unknown-1,disable" + # ]; + + # INFO: This is a custom function to map all of my monitors to workspaces. + # Since I use split-monitor-workspaces, I map 10 workspaces to each monitor + # and set the first one to be the default one. + # To be able to use this for a varying amount of monitors we do some nasty trickery: + workspace = + # We're creating several lists of workspace assignments, one for each monitor, + # and have to merge them into one big list. + (flatten + # We then use imap0 insted of map because imap0 starts indexing at zero as oppsed to one with map. + (imap0 (monitorIndex: monitorName: ( + map ( + i: let + # we define our own modulo operation for this, + # since only the first workspace on each monitor is the default workspace. + mod = a: b: a - (b * (a / b)); + workspace = toString i; + isDefault = (mod i 10) == 1; # 11, 21, 31, ... + in "${workspace}, monitor:${monitorName}${optionalString isDefault ", default:true"}" + ) + # we generate a list of 10 elements for each monitor. We have to add 1 each time since genList starts indexing at 0. + # also, we add the monitorIndex * 10 to get 10 workspaces for each individual monitor. + (genList (i: i + 1 + (10 * monitorIndex)) 10) + )) + # our attrSet of different monitors + (attrNames monitors))) + # These are my two special workspaces + ++ [ + "special:nixos, decorate:false" + "special:keepassxc, decorate:false" + ]; + }; + }; + }; +}