From 7a0a094a00ddb790bc4e7d7da9c8f81bc5b64e8e Mon Sep 17 00:00:00 2001 From: Quinn Unger Date: Fri, 13 Jun 2025 10:31:03 +0100 Subject: [PATCH] use DE agnostic keybind config --- config/graphical/core/bemenu.nix | 32 +++---- config/graphical/core/foot.nix | 8 +- config/graphical/core/hyprland.nix | 84 +----------------- config/graphical/core/idleLock.nix | 9 +- config/graphical/optional/hyprswitch.nix | 34 +++----- hosts/kaoru/default.nix | 2 +- hosts/yure/default.nix | 2 +- module.nix | 106 +++++++++++++++++++++++ 8 files changed, 152 insertions(+), 125 deletions(-) diff --git a/config/graphical/core/bemenu.nix b/config/graphical/core/bemenu.nix index 2840dcd..5a7b0fa 100644 --- a/config/graphical/core/bemenu.nix +++ b/config/graphical/core/bemenu.nix @@ -28,19 +28,21 @@ let ]; in lib.mkIf (cfg.graphics.enable) { - home-manager.users.${cfg.userName} = { - programs.bemenu.enable = true; - wayland.windowManager.hyprland.settings.bind = - [ - "SUPER, P, exec, uwsm app -- $(bemenu-run --no-exec ${opts})" - ] - ++ ( - if config.hardware.nvidia.prime.offload.enableOffloadCmd then - [ - "SUPERSHIFT, P, exec, uwsm app -- nvidia-offload $(LIBVA_DRIVER_NAME=nvidia VDPAU_NAME=nvidia bemenu-run --no-exec ${opts})" - ] - else - [ ] - ); - }; + home-manager.users.${cfg.userName}.programs.bemenu.enable = true; + sidonia.desktop.keybinds = + [ + { + mod = [ "super" ]; + key = "p"; + exec = "uwsm app -- $(bemenu-run --no-exec ${opts})"; + } + ] + ++ (lib.optional config.hardware.nvidia.prime.offload.enableOffloadCmd { + mod = [ + "super" + "shift" + ]; + key = "p"; + exec = "uwsm app -- nvidia-offload $(LIBVA_DRIVER_NAME=nvidia VDPAU_NAME=nvidia bemenu-run --no-exec ${opts})"; + }); } diff --git a/config/graphical/core/foot.nix b/config/graphical/core/foot.nix index 90660a6..bbd946c 100644 --- a/config/graphical/core/foot.nix +++ b/config/graphical/core/foot.nix @@ -9,6 +9,11 @@ let cfg = config.sidonia; in lib.mkIf (cfg.graphics.enable) { + sidonia.desktop.keybinds = [{ + mod = ["super" "shift"]; + key = "return"; + exec = "uwsm app -- foot"; + }]; home-manager.users.${config.sidonia.userName} = { catppuccin.foot.enable = true; programs.foot = { @@ -26,9 +31,6 @@ lib.mkIf (cfg.graphics.enable) { "size ${cfg.window.float.wh}, class:(foot), title:(foot)" "${cfg.window.float.onCursor}, class:(foot), title:(foot)" ]; - bind = [ - "SUPERSHIFT, Return, exec, uwsm app -- foot" - ]; }; }; } diff --git a/config/graphical/core/hyprland.nix b/config/graphical/core/hyprland.nix index ad277b5..bbb80df 100644 --- a/config/graphical/core/hyprland.nix +++ b/config/graphical/core/hyprland.nix @@ -15,85 +15,6 @@ in type = types.bool; default = cfg.graphics.enable; }; - monitors = mkOption { - description = "List of monitor configurations ( see https://wiki.hyprland.org/Configuring/Monitors/ )"; - type = - with types; - listOf (submodule { - options = { - name = mkOption { - description = "Name of monitor"; - type = str; - }; - resolution = mkOption { - description = "Resolution in the format WIDTHxHEIGHT. Default is highest available resolution."; - type = str; - default = "highres"; - }; - position = mkOption { - description = "Monitor position in scaled pixels WIDTHxHEIGHT"; - type = str; - default = "auto"; - }; - refresh = mkOption { - description = "Monitor refresh rate"; - type = float; - default = 0.0; - }; - scale = mkOption { - description = "Monitor scale factor"; - type = float; - default = 0.0; - }; - extraArgs = mkOption { - description = "Extra comma-separated monitor properties"; - type = str; - default = ""; - }; - }; - }); - default = [ ]; - apply = - x: - builtins.map - ( - monitor: - let - hasHz = monitor.refresh != 0.0; - scaleAuto = monitor.scale == 0.0; - hasXtra = monitor.extraArgs != ""; - args = concatStringsSep ", " ( - [ - (concatStringsSep "@" ( - [ monitor.resolution ] ++ (optional hasHz (strings.floatToString monitor.refresh)) - )) - monitor.position - (if scaleAuto then "auto" else strings.floatToString monitor.scale) - ] - ++ (optional hasXtra monitor.extraArgs) - ); - in - rec { - inherit (monitor) name; - enable = "${name},${args}"; - disable = "${name},disable"; - } - ) - ( - x - ++ [ - # Make sure to automatically find any unconfigured monitors - { - name = ""; - resolution = "highres"; - position = "auto"; - scale = 0.0; - refresh = 0.0; - extraArgs = ""; - } - ] - ); - }; }; config = lib.mkIf (cfg.programs.hyprland.enable) { @@ -137,7 +58,7 @@ in home-manager.users.${cfg.userName} = let - inherit (cfg.programs.hyprland) monitors; + inherit (cfg.desktop) monitors; in { home.packages = [ @@ -372,7 +293,8 @@ in "SUPERALT, L, resizeactive, 10 0" # resize right ]; bind = - [ + (builtins.map (x: "${lib.concatStrings x.mod}, ${x.key}, exec, ${x.exec}") cfg.desktop.keybinds) + ++ [ "SUPERSHIFT, C, killactive," "SUPERSHIFT, Q, exec, uwsm stop" "SUPER, V, togglefloating," diff --git a/config/graphical/core/idleLock.nix b/config/graphical/core/idleLock.nix index afc4ae5..e0e5221 100644 --- a/config/graphical/core/idleLock.nix +++ b/config/graphical/core/idleLock.nix @@ -19,10 +19,13 @@ in { hyprlock.enableGnomeKeyring = true; } ); + sidonia.desktop.keybinds = [{ + mod = ["super"]; + key = "x"; + exec = lock_cmd; + }]; + home-manager.users.${cfg.userName} = { - wayland.windowManager.hyprland.settings.bind = [ - "SUPER, X, exec, ${lock_cmd}" - ]; catppuccin.hyprlock.enable = !cfg.graphics.legacyGpu; programs.hyprlock = { diff --git a/config/graphical/optional/hyprswitch.nix b/config/graphical/optional/hyprswitch.nix index 6dec7a6..89b9dfe 100644 --- a/config/graphical/optional/hyprswitch.nix +++ b/config/graphical/optional/hyprswitch.nix @@ -13,30 +13,22 @@ in { options.sidonia.services.hyprswitch.enable = lib.mkEnableOption "Enable Hyprswitch"; config = lib.mkIf (cfg.services.hyprswitch.enable) { + sidonia.desktop.keybinds = [ + (rec { + mod = ["super"]; + key = "tab"; + exec = lib.concatStringsSep " " [ + "uwsm app --" + "hyprswitch gui" + "--mod-key ${lib.concatStrings mod}" + "--key ${key}" + "--close mod-key-release" + ]; + }) + ]; home-manager.users.${config.sidonia.userName} = { home.packages = [ hyprswitch ]; - wayland.windowManager.hyprland.settings = - let - mod = "super"; - key = "tab"; - in - { - env = [ - "WORKSPACES_PER_ROW,3" - ]; - bind = [ - (lib.concatStringsSep " " [ - "${mod}, ${key}, exec," - "uwsm app --" - "hyprswitch gui" - "--mod-key ${mod}" - "--key ${key}" - "--close mod-key-release" - ]) - ]; - }; - home.file.hyprswitch = { enable = true; executable = false; diff --git a/hosts/kaoru/default.nix b/hosts/kaoru/default.nix index 06f6775..44ef597 100644 --- a/hosts/kaoru/default.nix +++ b/hosts/kaoru/default.nix @@ -26,7 +26,7 @@ graphics.enable = true; tweaks.withBehringerAudioInterface = true; programs.gtkwave.enable = true; - programs.hyprland.monitors = [ + desktop.monitors = [ { name = "eDP-1"; resolution = "2560x1600"; diff --git a/hosts/yure/default.nix b/hosts/yure/default.nix index 6d05576..155e384 100644 --- a/hosts/yure/default.nix +++ b/hosts/yure/default.nix @@ -26,7 +26,7 @@ input.sensitivity = -0.1; input.keyLayout = "gb"; isLaptop = true; - programs.hyprland.monitors = [ + desktop.monitors = [ { name = "LVDS-1"; scale = 1.0; diff --git a/module.nix b/module.nix index 0f14e35..a00bc47 100644 --- a/module.nix +++ b/module.nix @@ -237,6 +237,112 @@ in default = "us"; }; }; + desktop = { + monitors = mkOption { + description = "List of monitor configurations ( see https://wiki.hyprland.org/Configuring/Monitors/ )"; + type = + with types; + listOf (submodule { + options = { + name = mkOption { + description = "Name of monitor"; + type = str; + }; + resolution = mkOption { + description = "Resolution in the format WIDTHxHEIGHT. Default is highest available resolution."; + type = str; + default = "highres"; + }; + position = mkOption { + description = "Monitor position in scaled pixels WIDTHxHEIGHT"; + type = str; + default = "auto"; + }; + refresh = mkOption { + description = "Monitor refresh rate"; + type = float; + default = 0.0; + }; + scale = mkOption { + description = "Monitor scale factor"; + type = float; + default = 0.0; + }; + extraArgs = mkOption { + description = "Extra comma-separated monitor properties"; + type = str; + default = ""; + }; + }; + }); + default = [ ]; + apply = + x: + builtins.map + ( + monitor: + let + hasHz = monitor.refresh != 0.0; + scaleAuto = monitor.scale == 0.0; + hasXtra = monitor.extraArgs != ""; + args = concatStringsSep ", " ( + [ + (concatStringsSep "@" ( + [ monitor.resolution ] ++ (optional hasHz (strings.floatToString monitor.refresh)) + )) + monitor.position + (if scaleAuto then "auto" else strings.floatToString monitor.scale) + ] + ++ (optional hasXtra monitor.extraArgs) + ); + in + rec { + inherit (monitor) name; + enable = "${name},${args}"; + disable = "${name},disable"; + } + ) + ( + x + ++ [ + # Make sure to automatically find any unconfigured monitors + { + name = ""; + resolution = "highres"; + position = "auto"; + scale = 0.0; + refresh = 0.0; + extraArgs = ""; + } + ] + ); + }; + keybinds = mkOption { + description = "List of keybinds to add to the desktop environment"; + type = + with types; + listOf (submodule { + options = { + mod = mkOption { + description = "Modifier keys"; + type = listOf (enum [ + "super" + "shift" + "alt" + ]); + }; + key = mkOption { + description = "Key"; + type = str; + }; + exec = mkOption { + description = "Command to execute"; + type = str; + }; + }; + }); + }; + }; }; }; -- knotmirror 0.0.1