From 2b9504d5a0169d4940a312abe2df2c5658db8de9 Mon Sep 17 00:00:00 2001 From: Karun Sandhu Date: Sun, 1 Mar 2026 23:05:25 +0100 Subject: [PATCH] hyprland: allow closing submaps on dispatch This adds an 'onDispatch' option to the 'submaps' attribute set, enabling the 'submap = name, ondispatch' syntax which allows submaps to be closed automatically after a dispatch. --- modules/services/window-managers/hyprland.nix | 17 ++++++++-- tests/modules/services/hyprland/default.nix | 1 + .../services/hyprland/inconsistent-config.nix | 2 +- .../services/hyprland/submaps-on-dispatch.nix | 31 +++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 tests/modules/services/hyprland/submaps-on-dispatch.nix diff --git a/modules/services/window-managers/hyprland.nix b/modules/services/window-managers/hyprland.nix index 53593c74..88eb16ce 100644 --- a/modules/services/window-managers/hyprland.nix +++ b/modules/services/window-managers/hyprland.nix @@ -238,6 +238,14 @@ in { name, config, ... }: { options = { + onDispatch = lib.mkOption { + type = lib.types.str; + default = ""; + description = '' + Submap to use after a dispatch. Can either be a name or `reset` to disable submap after any dispatch. + ''; + example = "reset"; + }; settings = lib.mkOption { type = (with lib.types; attrsOf (listOf str)) // { description = "Hyprland binds"; @@ -348,8 +356,11 @@ in warnings = let inconsistent = - (cfg.systemd.enable || cfg.plugins != [ ]) && cfg.extraConfig == "" && cfg.settings == { }; - warning = "You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings or hyprland.extraConfig. This is almost certainly a mistake."; + (cfg.systemd.enable || cfg.plugins != [ ]) + && cfg.extraConfig == "" + && cfg.settings == { } + && cfg.submaps == { }; + warning = "You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings, hyprland.extraConfig or hyprland.submaps. This is almost certainly a mistake."; filterNonBinds = attrs: builtins.filter (n: builtins.match "bind[[:lower:]]*" n == null) (builtins.attrNames attrs); @@ -391,7 +402,7 @@ in }; mkSubMap = name: attrs: '' - submap = ${name} + submap = ${name}${lib.optionalString (attrs.onDispatch != "") ", ${attrs.onDispatch}"} ${ lib.hm.generators.toHyprconf { attrs = attrs.settings; diff --git a/tests/modules/services/hyprland/default.nix b/tests/modules/services/hyprland/default.nix index b4638b41..176e1472 100644 --- a/tests/modules/services/hyprland/default.nix +++ b/tests/modules/services/hyprland/default.nix @@ -9,4 +9,5 @@ lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { hyprland-sourceFirst-false-config = ./sourceFirst-false-config.nix; hyprland-inconsistent-config = ./inconsistent-config.nix; hyprland-submaps-config = ./submaps-config.nix; + hyprland-submaps-on-dispatch = ./submaps-on-dispatch.nix; } diff --git a/tests/modules/services/hyprland/inconsistent-config.nix b/tests/modules/services/hyprland/inconsistent-config.nix index 0c535a66..0e76513d 100644 --- a/tests/modules/services/hyprland/inconsistent-config.nix +++ b/tests/modules/services/hyprland/inconsistent-config.nix @@ -9,7 +9,7 @@ }; test.asserts.warnings.expected = [ - "You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings or hyprland.extraConfig. This is almost certainly a mistake." + "You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings, hyprland.extraConfig or hyprland.submaps. This is almost certainly a mistake." ]; test.asserts.warnings.enable = true; diff --git a/tests/modules/services/hyprland/submaps-on-dispatch.nix b/tests/modules/services/hyprland/submaps-on-dispatch.nix new file mode 100644 index 00000000..7d9ac1d0 --- /dev/null +++ b/tests/modules/services/hyprland/submaps-on-dispatch.nix @@ -0,0 +1,31 @@ +{ config, ... }: + +{ + wayland.windowManager.hyprland = { + enable = true; + submaps = { + resize = { + onDispatch = "reset"; + settings = { + binde = [ + ", right, resizeactive, 10 0" + ", left, resizeactive, -10 0" + ]; + }; + }; + other = { + onDispatch = "resize"; + settings = { + bind = [ ", a, exec, true" ]; + }; + }; + }; + }; + + nmt.script = '' + config=home-files/.config/hypr/hyprland.conf + assertFileExists "$config" + assertFileContains "$config" "submap = resize, reset" + assertFileContains "$config" "submap = other, resize" + ''; +}