home-manager
home-manager copied to clipboard
hyprland: submaps cannot be configured with nix syntax
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
Actually you can definie the name of the standard keymap by putting "submap" = "reset"; abouve binds =
- that's... not how nix works
- 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
I've suggested the change be done at the Hyprland side. No luck.
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
);
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.
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
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)
Oh I've completely missed that option, thank you!
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.
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
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
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.