1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 11:39:46 +01:00

herbstluftwm: Make herbstclient alias optional

The `herbstclient` alias in the generated `autostart` made it impossible
to use bash functions.

This makes the `herbstclient` alias optional by adding an extra
`herbstclientAlias` option on the herbstluftwm configuration. The new
option defaults to `false` as to not confuse newcomers to the
herbstluftwm module, which is not a breaking change because it was only
an optimization.
This commit is contained in:
Olmo Kramer 2024-06-22 10:37:42 +02:00
parent 509dbf8d45
commit 1874860d37
No known key found for this signature in database
6 changed files with 128 additions and 15 deletions

View file

@ -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 more difficult 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 ";" "$@"
''}
'';
};
}

View file

@ -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;
}

View file

@ -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 ";" "$@"

View file

@ -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
}
'';
}

View file

@ -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 ";" "$@"

View file

@ -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 ";" "$@"