From cf5ce8202f1eda6cc4f69a2ce255c1c1c9568126 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Fri, 19 Jul 2024 12:50:03 -0400 Subject: [PATCH] home/hyprland: add options for default workspaces and window manager binds --- .../desktop/hyprland/default.nix | 9 +-- .../desktop/hyprland/helpers.nix | 63 ------------------- .../desktop/hyprland/scripts.nix | 12 ++-- homeManagerModules/desktop/hyprland/vars.nix | 62 +++++++++++++----- homeManagerModules/options.nix | 21 +++++++ 5 files changed, 76 insertions(+), 91 deletions(-) delete mode 100644 homeManagerModules/desktop/hyprland/helpers.nix diff --git a/homeManagerModules/desktop/hyprland/default.nix b/homeManagerModules/desktop/hyprland/default.nix index 86ff5be7..e66ed2dc 100644 --- a/homeManagerModules/desktop/hyprland/default.nix +++ b/homeManagerModules/desktop/hyprland/default.nix @@ -9,13 +9,10 @@ in { config = lib.mkIf cfg.desktop.hyprland.enable { wayland.windowManager.hyprland = { enable = true; - settings = import ./vars.nix {inherit config lib pkgs;}; - extraConfig = let - inherit (import ./helpers.nix {inherit config lib pkgs;}) defaultWorkspaces windowManagerBinds; - in '' + extraConfig = '' submap=resize binde=,down,resizeactive,0 10 binde=,left,resizeactive,-10 0 @@ -38,7 +35,7 @@ in { bind = , ${key}, movewindow, ${direction} bind = CONTROL, ${key}, movecurrentworkspacetomonitor, ${direction} '') - windowManagerBinds + cfg.desktop.hyprland.windowManagerBinds ) } @@ -46,7 +43,7 @@ in { ${ lib.strings.concatMapStringsSep "\n" (x: "bind = , ${toString x}, movetoworkspace, ${toString x}") - defaultWorkspaces + cfg.desktop.hyprland.workspaces } # hyprnome diff --git a/homeManagerModules/desktop/hyprland/helpers.nix b/homeManagerModules/desktop/hyprland/helpers.nix deleted file mode 100644 index d92c68e1..00000000 --- a/homeManagerModules/desktop/hyprland/helpers.nix +++ /dev/null @@ -1,63 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: let - cfg = config.ar.home; -in { - # Media/hardware commands - brightness = rec { - bin = lib.getExe' pkgs.swayosd "swayosd-client"; - up = "${bin} --brightness=raise"; - down = "${bin} --brightness=lower"; - }; - - # Default apps - defaultApps = { - browser = lib.getExe cfg.defaultApps.webBrowser; - editor = lib.getExe cfg.defaultApps.editor; - fileManager = lib.getExe cfg.defaultApps.fileManager; - launcher = lib.getExe pkgs.fuzzel; - lock = lib.getExe pkgs.swaylock; - logout = lib.getExe pkgs.wlogout; - terminal = lib.getExe cfg.defaultApps.terminal; - virtKeyboard = lib.getExe' pkgs.squeekboard "squeekboard"; - }; - - defaultWorkspaces = [1 2 3 4 5 6 7 8 9]; - - media = rec { - bin = lib.getExe pkgs.playerctl; - play = "${bin} play-pause"; - paus = "${bin} pause"; - next = "${bin} next"; - prev = "${bin} previous"; - }; - - screenshot = rec { - bin = lib.getExe pkgs.hyprshot; - folder = "${config.xdg.userDirs.pictures}/screenshots"; - screen = "${bin} -m output -o ${folder}"; - region = "${bin} -m region -o ${folder}"; - }; - - volume = rec { - bin = lib.getExe' pkgs.swayosd "swayosd-client"; - up = "${bin} --output-volume=raise"; - down = "${bin} --output-volume=lower"; - mute = "${bin} --output-volume=mute-toggle"; - micMute = "${bin} --input-volume=mute-toggle"; - }; - - windowManagerBinds = { - down = "d"; - left = "l"; - right = "r"; - up = "u"; - h = "l"; - j = "d"; - k = "u"; - l = "r"; - }; -} diff --git a/homeManagerModules/desktop/hyprland/scripts.nix b/homeManagerModules/desktop/hyprland/scripts.nix index e6f18bc8..ec081a0a 100644 --- a/homeManagerModules/desktop/hyprland/scripts.nix +++ b/homeManagerModules/desktop/hyprland/scripts.nix @@ -6,7 +6,7 @@ }: let cfg = config.ar.home; hyprctl = lib.getExe' config.wayland.windowManager.hyprland.package "hyprctl"; - inherit (import ./helpers.nix {inherit config lib pkgs;}) defaultApps media; + virtKeyboard = lib.getExe' pkgs.squeekboard "squeekboard"; in { clamshell = pkgs.writeShellScript "hyprland-clamshell" '' NUM_MONITORS=$(${hyprctl} monitors all | grep Monitor | wc --lines) @@ -25,11 +25,11 @@ in { idleD = pkgs.writeShellScript "hyprland-idled" '' ${lib.getExe pkgs.swayidle} -w \ - before-sleep '${media.paus}' \ - before-sleep '${defaultApps.lock}' \ + before-sleep '${lib.getExe pkgs.playerctl} play-pause' \ + before-sleep '${lib.getExe pkgs.swaylock}' \ timeout 240 '${lib.getExe pkgs.brightnessctl} -s set 10' \ resume '${lib.getExe pkgs.brightnessctl} -r' \ - timeout 300 '${defaultApps.lock}' \ + timeout 300 '${lib.getExe pkgs.swaylock}' \ timeout 330 '${hyprctl} dispatch dpms off' \ resume '${hyprctl} dispatch dpms on' \ ${ @@ -43,8 +43,8 @@ in { STATE=`${lib.getExe pkgs.dconf} read /org/gnome/desktop/a11y/applications/screen-keyboard-enabled` if [ $STATE -z ] || [ $STATE == "false" ]; then - if ! [ `pgrep -f ${defaultApps.virtKeyboard}` ]; then - ${defaultApps.virtKeyboard} & + if ! [ `pgrep -f ${virtKeyboard}` ]; then + ${virtKeyboard} & fi ${lib.getExe pkgs.dconf} write /org/gnome/desktop/a11y/applications/screen-keyboard-enabled true elif [ $STATE == "true" ]; then diff --git a/homeManagerModules/desktop/hyprland/vars.nix b/homeManagerModules/desktop/hyprland/vars.nix index a2ffd12b..2b29d2ac 100644 --- a/homeManagerModules/desktop/hyprland/vars.nix +++ b/homeManagerModules/desktop/hyprland/vars.nix @@ -6,16 +6,46 @@ }: let cfg = config.ar.home; inherit (import ./scripts.nix {inherit config lib pkgs;}) clamshell idleD tablet wallpaperD; - inherit - (import ./helpers.nix {inherit config lib pkgs;}) - brightness - defaultApps - defaultWorkspaces - media - screenshot - volume - windowManagerBinds - ; + + # Media/hardware commands + brightness = rec { + bin = lib.getExe' pkgs.swayosd "swayosd-client"; + up = "${bin} --brightness=raise"; + down = "${bin} --brightness=lower"; + }; + + # Default apps + defaultApps = { + browser = lib.getExe cfg.defaultApps.webBrowser; + editor = lib.getExe cfg.defaultApps.editor; + fileManager = lib.getExe cfg.defaultApps.fileManager; + launcher = lib.getExe pkgs.fuzzel; + logout = lib.getExe pkgs.wlogout; + terminal = lib.getExe cfg.defaultApps.terminal; + }; + + media = rec { + bin = lib.getExe pkgs.playerctl; + play = "${bin} play-pause"; + paus = "${bin} pause"; + next = "${bin} next"; + prev = "${bin} previous"; + }; + + screenshot = rec { + bin = lib.getExe pkgs.hyprshot; + folder = "${config.xdg.userDirs.pictures}/screenshots"; + screen = "${bin} -m output -o ${folder}"; + region = "${bin} -m region -o ${folder}"; + }; + + volume = rec { + bin = lib.getExe' pkgs.swayosd "swayosd-client"; + up = "${bin} --output-volume=raise"; + down = "${bin} --output-volume=lower"; + mute = "${bin} --output-volume=mute-toggle"; + micMute = "${bin} --input-volume=mute-toggle"; + }; in { "$mod" = "SUPER"; @@ -37,7 +67,7 @@ in { bind = [ "$mod CONTROL, F12, exec, ${screenshot.region}" - "$mod CONTROL, L, exec, ${defaultApps.lock}" + "$mod CONTROL, L, exec, ${lib.getExe pkgs.swaylock}" "$mod SHIFT, S, movetoworkspace, special:magic" "$mod SHIFT, V, togglefloating" "$mod SHIFT, W, fullscreen" @@ -63,11 +93,11 @@ in { "CTRL ALT,M,submap,move" "CTRL ALT,R,submap,resize" ] - ++ builtins.map (x: "$mod, ${toString x}, workspace, ${toString x}") defaultWorkspaces - ++ builtins.map (x: "$mod SHIFT, ${toString x}, movetoworkspace, ${toString x}") defaultWorkspaces - ++ lib.attrsets.mapAttrsToList (key: direction: "$mod, ${key}, movefocus, ${direction}") windowManagerBinds - ++ lib.attrsets.mapAttrsToList (key: direction: "$mod SHIFT, ${key}, movewindow, ${direction}") windowManagerBinds - ++ lib.attrsets.mapAttrsToList (key: direction: "$mod CONTROL SHIFT, ${key}, movecurrentworkspacetomonitor, ${direction}") windowManagerBinds; + ++ builtins.map (x: "$mod, ${toString x}, workspace, ${toString x}") cfg.desktop.hyprland.workspaces + ++ builtins.map (x: "$mod SHIFT, ${toString x}, movetoworkspace, ${toString x}") cfg.desktop.hyprland.workspaces + ++ lib.attrsets.mapAttrsToList (key: direction: "$mod, ${key}, movefocus, ${direction}") cfg.desktop.hyprland.windowManagerBinds + ++ lib.attrsets.mapAttrsToList (key: direction: "$mod SHIFT, ${key}, movewindow, ${direction}") cfg.desktop.hyprland.windowManagerBinds + ++ lib.attrsets.mapAttrsToList (key: direction: "$mod CONTROL SHIFT, ${key}, movecurrentworkspacetomonitor, ${direction}") cfg.desktop.hyprland.windowManagerBinds; bindm = [ # Move/resize windows with mainMod + LMB/RMB and dragging diff --git a/homeManagerModules/options.nix b/homeManagerModules/options.nix index 775d9f03..97863a30 100644 --- a/homeManagerModules/options.nix +++ b/homeManagerModules/options.nix @@ -151,6 +151,27 @@ in { type = lib.types.bool; }; + workspaces = lib.mkOption { + description = "Default numbered workspaces to create."; + default = [1 2 3 4 5 6 7 8 9]; + type = lib.types.listOf lib.types.int; + }; + + windowManagerBinds = lib.mkOption { + description = "Default binds for window management."; + default = { + down = "d"; + left = "l"; + right = "r"; + up = "u"; + h = "l"; + j = "d"; + k = "u"; + l = "r"; + }; + type = lib.types.attrs; + }; + tabletMode = { enable = lib.mkEnableOption "Tablet mode for hyprland.";