home-manager icon indicating copy to clipboard operation
home-manager copied to clipboard

hyprland: submaps cannot be configured with nix syntax

Open 0x57e11a opened this issue 1 year ago • 11 comments

hyprland does an odd thing in its usage of hyprlang with submap = ..., which switches into different submaps when binding keys (ideally this would've been implemented as different submap:xyz { ... } sections, but they Decided To Do It That Way for some reason)

# other keybinds

submap = something

bindm = , mouse:272, movewindow
bind = , escape, submap, reset

submap = reset

# other keybinds

because this specific section of keybinds needs to be surrounded by submap boundaries, it's not possible to do this with wayland.windowManagers.hyprland.settings

solution

the proposal is to add wayland.windowManagers.hyprland.submaps, like so:

wayland.windowManager.hyprland.submaps = {
    something = {
        bindm = [ ", mouse: 272, movewindow" ];
        bind = [ ", escape, submap, reset" ];
    };
};
workaround

wayland.windowManagers.hyprland.extraConfig exists, but having part of the config in a string and the rest in nix options is frustrating

0x57e11a avatar Nov 09 '24 18:11 0x57e11a

Actually you can definie the name of the standard keymap by putting "submap" = "reset"; abouve binds =

Acisama avatar Dec 26 '24 14:12 Acisama

  1. that's... not how nix works
  2. not trying to rename the standard submap, trying to specifically define binds in a different submap, which is not possible to do with the current nix syntax

0x57e11a avatar Dec 28 '24 00:12 0x57e11a

I've suggested the change be done at the Hyprland side. No luck.

de-abreu avatar Feb 03 '25 18:02 de-abreu

a potential workaround that wouldn't be too difficult to turn into a PR (by someone with the time):

extraConfig = let
	submaps = {
		chord = {
			settings = {
				bind = [
					", escape, submap, reset"

					", q, exit,"

					",,exec,"
				];

				bindm = [
					", mouse:272, movewindow"
				];
			};

			extraConfig = "";
		};
	};
in lib.concatStringsSep "\n" (
	lib.mapAttrsToList
		(name: submap: (
			"submap = ${name}\n"
			+ lib.optionalString (submap.settings != { }) (
				inputs.home-manager.lib.hm.generators.toHyprconf {
					attrs = submap.settings;
				}
			)
			+ lib.optionalString (submap.extraConfig != "") submap.extraConfig
			+ "submap = reset"
		))
		submaps
);

0x57e11a avatar Feb 07 '25 02:02 0x57e11a

Stella, when using your method, would it be possible to interweave binds with different flags? Because, as is, the order that the binds appear in the Hyprland config matters.

de-abreu avatar Feb 07 '25 16:02 de-abreu

This might be because of my lack of experience - but so how would a simple hyprland config like this look with home manager?:

bind = MOD,KEY,submap,passthru
submap = passthru
bind = SUPER,Escape,submap,reset
submap = reset

Hailst0rm1 avatar Feb 25 '25 11:02 Hailst0rm1

Stella, when using your method, would it be possible to interweave binds with different flags? Because, as is, the order that the binds appear in the Hyprland config matters. @de-abreu

curious, could you provide an example?

This might be because of my lack of experience - but so how would a simple hyprland config like this look with home manager?:

bind = MOD,KEY,submap,passthru
submap = passthru
bind = SUPER,Escape,submap,reset
submap = reset

@Hailst0rm1

with current home-manager, you would write it in the extraConfig as a string, because there isn't a way to do this with nix syntax yet (which is what this issue is about)

0x57e11a avatar Feb 25 '25 16:02 0x57e11a

Oh I've completely missed that option, thank you!

Hailst0rm1 avatar Feb 25 '25 18:02 Hailst0rm1

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

stale[bot] avatar May 27 '25 00:05 stale[bot]

I recently started working with submaps in my config (in this commit if you're curious), and I am currently using the following helper to generate submaps:

  mkSubMap = { catchAllReset ? true, indentLevel ? 0 }: name: binds:
    assert lib.assertMsg (name != "reset") "'reset' is not a valid submap name!";
    let
      indent = lib.concatStrings (lib.replicate indentLevel "  ");
      i = indent;
    in
    ''
      ${i}submap = ${name}

      ${lib.hm.generators.toHyprconf { attrs = binds; indentLevel = indentLevel + 1; }}

      ${i}  ${lib.optionalString catchAllReset "bind = , catchall, submap, reset"}
      ${i}submap = reset
    ''
  ;

I think this could be used to implement a submap HM module, which I might give a try at in the near feature

C0Florent avatar Jun 12 '25 12:06 C0Florent

I've got something that works, I'll open a PR for it soon

I might need some help to get it mergeable in things like writing tests or checking the documentation generates correctly, this would be my first PR here

C0Florent avatar Jun 15 '25 19:06 C0Florent

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

stale[bot] avatar Sep 14 '25 01:09 stale[bot]