From 1a0a5f50376e2c3b0df9728befc59f07da44be21 Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Mon, 19 Dec 2022 22:08:33 +0100 Subject: [PATCH 1/2] herbstluftwm: Fix error when no tags set The default value for `xsession.windowManager.herbstluftwm.tags` is an empty list, but the config file uses `builtins.head` on it, which causes an error upon evaluation. With this change the tags configuration is skipped if the list is empty. --- .../services/window-managers/herbstluftwm.nix | 18 ++++++----- .../window-managers/herbstluftwm/default.nix | 5 ++- .../herbstluftwm-no-tags-autostart | 31 +++++++++++++++++++ .../herbstluftwm/herbstluftwm-no-tags.nix | 16 ++++++++++ ...t => herbstluftwm-simple-config-autostart} | 3 +- .../herbstluftwm-simple-config.nix | 4 ++- 6 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart create mode 100644 tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags.nix rename tests/modules/services/window-managers/herbstluftwm/{autostart => herbstluftwm-simple-config-autostart} (89%) mode change 100755 => 100644 diff --git a/modules/services/window-managers/herbstluftwm.nix b/modules/services/window-managers/herbstluftwm.nix index cbbe3cefd..e826100d8 100644 --- a/modules/services/window-managers/herbstluftwm.nix +++ b/modules/services/window-managers/herbstluftwm.nix @@ -145,15 +145,17 @@ in { ${renderSettings cfg.settings} - if ${cfg.package}/bin/herbstclient object_tree tags.by-name | ${pkgs.gnugrep}/bin/grep default; then - herbstclient rename default ${ - lib.escapeShellArg (builtins.head cfg.tags) - } - fi + ${lib.optionalString (cfg.tags != [ ]) '' + if ${cfg.package}/bin/herbstclient object_tree tags.default &>/dev/null; then + herbstclient rename default ${ + lib.escapeShellArg (builtins.head cfg.tags) + } + fi - for tag in ${lib.escapeShellArgs cfg.tags}; do - herbstclient add "$tag" - done + for tag in ${lib.escapeShellArgs cfg.tags}; do + herbstclient add "$tag" + done + ''} ${renderKeybinds cfg.keybinds} diff --git a/tests/modules/services/window-managers/herbstluftwm/default.nix b/tests/modules/services/window-managers/herbstluftwm/default.nix index 04b9f89c7..31e73365f 100644 --- a/tests/modules/services/window-managers/herbstluftwm/default.nix +++ b/tests/modules/services/window-managers/herbstluftwm/default.nix @@ -1 +1,4 @@ -{ herbstluftwm-simple-config = ./herbstluftwm-simple-config.nix; } +{ + herbstluftwm-simple-config = ./herbstluftwm-simple-config.nix; + herbstluftwm-no-tags = ./herbstluftwm-no-tags.nix; +} diff --git a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart new file mode 100644 index 000000000..642d66cda --- /dev/null +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart @@ -0,0 +1,31 @@ +#!/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 unrule --all + + + + + + + + + + + + + +herbstclient unlock + +@herbstluftwm@/bin/herbstclient chain ";" "$@" + diff --git a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags.nix b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags.nix new file mode 100644 index 000000000..bd7fb4881 --- /dev/null +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags.nix @@ -0,0 +1,16 @@ +{ lib, pkgs, ... }: + +{ + xsession.windowManager.herbstluftwm = { enable = true; }; + + test.stubs.herbstluftwm = { }; + + nmt.script = '' + autostart=home-files/.config/herbstluftwm/autostart + assertFileExists "$autostart" + assertFileIsExecutable "$autostart" + + normalizedAutostart=$(normalizeStorePaths "$autostart") + assertFileContent "$normalizedAutostart" ${./herbstluftwm-no-tags-autostart} + ''; +} diff --git a/tests/modules/services/window-managers/herbstluftwm/autostart b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart old mode 100755 new mode 100644 similarity index 89% rename from tests/modules/services/window-managers/herbstluftwm/autostart rename to tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart index d59da4bae..31eb17502 --- a/tests/modules/services/window-managers/herbstluftwm/autostart +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart @@ -19,7 +19,7 @@ herbstclient set frame_bg_active_color '#000000' herbstclient set frame_gap '12' herbstclient set frame_padding '-12' -if @herbstluftwm@/bin/herbstclient object_tree tags.by-name | /nix/store/00000000000000000000000000000000-gnugrep/bin/grep default; then +if @herbstluftwm@/bin/herbstclient object_tree tags.default &>/dev/null; then herbstclient rename default '1' fi @@ -27,6 +27,7 @@ for tag in '1' 'with space' 'wə1rd#ch@rs'\'''; do herbstclient add "$tag" done + herbstclient keybind Mod4-1 use 1 herbstclient keybind Mod4-2 use 2 herbstclient keybind Mod4-Alt-Tab cycle -1 diff --git a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config.nix b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config.nix index 27e871505..e351e78f9 100644 --- a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config.nix +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config.nix @@ -39,6 +39,8 @@ assertFileIsExecutable "$autostart" normalizedAutostart=$(normalizeStorePaths "$autostart") - assertFileContent "$normalizedAutostart" ${./autostart} + assertFileContent "$normalizedAutostart" ${ + ./herbstluftwm-simple-config-autostart + } ''; } From 47bb9e756937a2609a62b192ba06780f865f7e03 Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Mon, 19 Dec 2022 22:12:34 +0100 Subject: [PATCH 2/2] herbstluftwm: Reset mousebinds on (re)load Keybinds and rules were already reset, but now also the mousebinds are. --- modules/services/window-managers/herbstluftwm.nix | 1 + .../window-managers/herbstluftwm/herbstluftwm-no-tags-autostart | 1 + .../herbstluftwm/herbstluftwm-simple-config-autostart | 1 + 3 files changed, 3 insertions(+) diff --git a/modules/services/window-managers/herbstluftwm.nix b/modules/services/window-managers/herbstluftwm.nix index e826100d8..67457e95a 100644 --- a/modules/services/window-managers/herbstluftwm.nix +++ b/modules/services/window-managers/herbstluftwm.nix @@ -141,6 +141,7 @@ in { herbstclient attr theme.tiling.reset 1 herbstclient attr theme.floating.reset 1 herbstclient keyunbind --all + herbstclient mouseunbind --all herbstclient unrule --all ${renderSettings cfg.settings} 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 642d66cda..9e8cd78a0 100644 --- a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-no-tags-autostart @@ -11,6 +11,7 @@ herbstclient emit_hook reload herbstclient attr theme.tiling.reset 1 herbstclient attr theme.floating.reset 1 herbstclient keyunbind --all +herbstclient mouseunbind --all herbstclient unrule --all 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 31eb17502..5f101e0bb 100644 --- a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart @@ -11,6 +11,7 @@ herbstclient emit_hook reload 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