From 64d1f75a1eda1e329f9f795578de10fad0fb82df Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Fri, 20 Jan 2023 20:17:55 +0100 Subject: [PATCH] herbstluftwm: fix default tag renaming The previous implementation tried to rename the tag named "default" to the first tag in `cfg.tags`. This was a wrong approach because if a tag with the same name already existed, the renaming failed and the default tag would continue to exist. The looking up of the default tag also contained a bug because it should have used `by-name` in the path. --- modules/services/window-managers/herbstluftwm.nix | 15 ++++++++------- .../herbstluftwm-simple-config-autostart | 9 +++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/services/window-managers/herbstluftwm.nix b/modules/services/window-managers/herbstluftwm.nix index 67457e95a..51fe22bd0 100644 --- a/modules/services/window-managers/herbstluftwm.nix +++ b/modules/services/window-managers/herbstluftwm.nix @@ -29,6 +29,8 @@ let settingType = lib.types.oneOf [ lib.types.bool lib.types.int lib.types.str ]; + escapedTags = map lib.escapeShellArg cfg.tags; + in { meta.maintainers = [ lib.hm.maintainers.olmokramer ]; @@ -147,15 +149,14 @@ in { ${renderSettings cfg.settings} ${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 + for tag in ${lib.concatStringsSep " " escapedTags}; do herbstclient add "$tag" done + + if ${cfg.package}/bin/herbstclient object_tree tags.by-name.default &>/dev/null; then + herbstclient use ${lib.head escapedTags} + herbstclient merge_tag default ${lib.head escapedTags} + fi ''} ${renderKeybinds cfg.keybinds} 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 5f101e0bb..78d4d7d56 100644 --- a/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart +++ b/tests/modules/services/window-managers/herbstluftwm/herbstluftwm-simple-config-autostart @@ -20,14 +20,15 @@ herbstclient set frame_bg_active_color '#000000' herbstclient set frame_gap '12' herbstclient set frame_padding '-12' -if @herbstluftwm@/bin/herbstclient object_tree tags.default &>/dev/null; then - herbstclient rename default '1' -fi - 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