diff --git a/modules/services/window-managers/herbstluftwm.nix b/modules/services/window-managers/herbstluftwm.nix index a407da6c..8062ef2a 100644 --- a/modules/services/window-managers/herbstluftwm.nix +++ b/modules/services/window-managers/herbstluftwm.nix @@ -117,6 +117,22 @@ in { {file}`$XDG_CONFIG_HOME/herbstluftwm/autostart`. ''; }; + + herbstclientAlias = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + Set an alias for the {command}`herbstclient` command in the + {file}`autostart` script that only stores its arguments and executes + them all at once at the end of the {file}`autostart` script. + + This reduces the amount of flickering you get while all options are + being applied and improves the performance. + + On the other hand, this makes it impossible to write bash functions + that call {command}`herbstclient`. + ''; + }; }; config = lib.mkIf cfg.enable { @@ -131,11 +147,13 @@ in { xdg.configFile."herbstluftwm/autostart".source = pkgs.writeShellScript "herbstluftwm-autostart" '' - shopt -s expand_aliases + ${lib.optionalString cfg.herbstclientAlias '' + shopt -s expand_aliases - # shellcheck disable=SC2142 - alias herbstclient='set -- "$@" ";"' - set -- + # shellcheck disable=SC2142 + alias herbstclient='set -- "$@" ";"' + set -- + ''} herbstclient emit_hook reload @@ -169,7 +187,9 @@ in { herbstclient unlock - ${cfg.package}/bin/herbstclient chain ";" "$@" + ${lib.optionalString cfg.herbstclientAlias '' + ${cfg.package}/bin/herbstclient chain ";" "$@" + ''} ''; }; } diff --git a/tests/modules/services/window-managers/herbstluftwm/default.nix b/tests/modules/services/window-managers/herbstluftwm/default.nix index 31e73365..3b464f96 100644 --- a/tests/modules/services/window-managers/herbstluftwm/default.nix +++ b/tests/modules/services/window-managers/herbstluftwm/default.nix @@ -1,4 +1,5 @@ { herbstluftwm-simple-config = ./herbstluftwm-simple-config.nix; herbstluftwm-no-tags = ./herbstluftwm-no-tags.nix; + herbstluftwm-alias-enabled = ./herbstluftwm-alias-enabled.nix; } diff --git a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-alias-enabled-autostart b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-alias-enabled-autostart new file mode 100644 index 00000000..69d48c34 --- /dev/null +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-alias-enabled-autostart @@ -0,0 +1,53 @@ +#!/nix/store/00000000000000000000000000000000-bash/bin/bash +shopt -s expand_aliases + +# shellcheck disable=SC2142 +alias herbstclient='set -- "$@" ";"' +set -- + + +herbstclient emit_hook reload + +# Reset everything. +herbstclient attr theme.tiling.reset 1 +herbstclient attr theme.floating.reset 1 +herbstclient keyunbind --all +herbstclient mouseunbind --all +herbstclient unrule --all + +herbstclient set always_show_frame true +herbstclient set default_frame_layout 'max' +herbstclient set frame_bg_active_color '#000000' +herbstclient set frame_gap '12' +herbstclient set frame_padding '-12' + +for tag in '1' 'with space' 'wə1rd#ch@rs'\'''; do + herbstclient add "$tag" +done + +if @herbstluftwm@/bin/herbstclient object_tree tags.by-name.default &>/dev/null; then + herbstclient use '1' + herbstclient merge_tag default '1' +fi + + +herbstclient keybind Mod4-1 use 1 +herbstclient keybind Mod4-2 use 2 +herbstclient keybind Mod4-Alt-Tab cycle -1 +herbstclient keybind Mod4-Tab cycle 1 + +herbstclient mousebind Mod4-B1 move +herbstclient mousebind Mod4-B3 resize + +herbstclient rule focus=on +herbstclient rule windowtype~'_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)' focus=on pseudotile=on +herbstclient rule class~'[Pp]inentry' instance=pinentry focus=on floating=on floatplacement=center keys_inactive='.*' + +herbstclient use 1 + + +herbstclient unlock + +@herbstluftwm@/bin/herbstclient chain ";" "$@" + + diff --git a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-alias-enabled.nix b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-alias-enabled.nix new file mode 100644 index 00000000..de69c13c --- /dev/null +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-alias-enabled.nix @@ -0,0 +1,47 @@ +{ lib, pkgs, ... }: + +{ + xsession.windowManager.herbstluftwm = { + enable = true; + settings = { + always_show_frame = true; + default_frame_layout = "max"; + frame_bg_active_color = "#000000"; + frame_gap = 12; + frame_padding = -12; + }; + keybinds = { + "Mod4-1" = "use 1"; + "Mod4-2" = "use 2"; + "Mod4-Tab" = "cycle 1"; + "Mod4-Alt-Tab" = "cycle -1"; + }; + mousebinds = { + "Mod4-B1" = "move"; + "Mod4-B3" = "resize"; + }; + rules = [ + "focus=on" + "windowtype~'_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)' focus=on pseudotile=on" + "class~'[Pp]inentry' instance=pinentry focus=on floating=on floatplacement=center keys_inactive='.*'" + ]; + tags = [ "1" "with space" "wə1rd#ch@rs'" ]; + extraConfig = '' + herbstclient use 1 + ''; + herbstclientAlias = true; + }; + + test.stubs.herbstluftwm = { }; + + nmt.script = '' + autostart=home-files/.config/herbstluftwm/autostart + assertFileExists "$autostart" + assertFileIsExecutable "$autostart" + + normalizedAutostart=$(normalizeStorePaths "$autostart") + assertFileContent "$normalizedAutostart" ${ + ./herbstluftwm-alias-enabled-autostart + } + ''; +} diff --git a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart index 9e8cd78a..384d6d8b 100644 --- a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart @@ -1,9 +1,5 @@ #!/nix/store/00000000000000000000000000000000-bash/bin/bash -shopt -s expand_aliases -# shellcheck disable=SC2142 -alias herbstclient='set -- "$@" ";"' -set -- herbstclient emit_hook reload @@ -28,5 +24,5 @@ herbstclient unrule --all herbstclient unlock -@herbstluftwm@/bin/herbstclient chain ";" "$@" + diff --git a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart index 78d4d7d5..010c1577 100644 --- a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart @@ -1,9 +1,5 @@ #!/nix/store/00000000000000000000000000000000-bash/bin/bash -shopt -s expand_aliases -# shellcheck disable=SC2142 -alias herbstclient='set -- "$@" ";"' -set -- herbstclient emit_hook reload @@ -47,5 +43,5 @@ herbstclient use 1 herbstclient unlock -@herbstluftwm@/bin/herbstclient chain ";" "$@" +