From bc42c4dc77e6f5284cb25aea3aab0f7a92751dca Mon Sep 17 00:00:00 2001 From: John Ogle Date: Thu, 4 Dec 2025 16:31:44 -0800 Subject: [PATCH] Fix SketchyBar workspace indicators not reappearing The aerospace workspace plugin had two issues preventing workspace indicators from properly showing/hiding: 1. The script expected workspace number as $1 but update_freq routine calls only provide $NAME environment variable. Now extracts from either source. 2. Using drawing=off to hide workspaces was unreliable - items wouldn't consistently reappear. Now uses width=0 with cleared icon/label content to collapse items instead. Workspaces now properly appear within 2 seconds when windows are created or moved, without requiring manual sketchybar --update. --- home/roles/aerospace/default.nix | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/home/roles/aerospace/default.nix b/home/roles/aerospace/default.nix index f15c3a9..b456ad1 100644 --- a/home/roles/aerospace/default.nix +++ b/home/roles/aerospace/default.nix @@ -539,8 +539,15 @@ in # Get list of empty workspaces EMPTY_WORKSPACES=$(${pkgs.aerospace}/bin/aerospace list-workspaces --monitor all --empty) - # Clean up the workspace number parameter - WORKSPACE_NUM=$(echo "$1" | tr -d ' \n\r') + # Get workspace number - from $1 if provided (event-triggered), otherwise extract from $NAME (routine update) + # $NAME is always available (e.g., "space.1", "space.2", etc.) + # $1 is only available when called via event trigger with positional argument + if [ -n "$1" ]; then + WORKSPACE_NUM=$(echo "$1" | tr -d ' \n\r') + else + # Extract number from item name: "space.1" -> "1", "space.10" -> "10" + WORKSPACE_NUM=$(echo "$NAME" | sed 's/space\.//') + fi # Check if workspace has windows (is NOT empty) IS_EMPTY=false @@ -554,6 +561,13 @@ in IS_FOCUSED=true fi + # Determine display value (workspace 10 displays as "0") + if [ "$WORKSPACE_NUM" = "10" ]; then + DISPLAY="0" + else + DISPLAY="$WORKSPACE_NUM" + fi + # Determine visibility and styling # Always show focused workspace (even if empty) with fixed width # Hide non-focused empty workspaces by setting width to 0 (collapsed) @@ -562,7 +576,7 @@ in if [ "$IS_FOCUSED" = "true" ]; then # Focused workspace - always show with focused styling ${pkgs.sketchybar}/bin/sketchybar --set space.$WORKSPACE_NUM \ - drawing=on \ + icon="$DISPLAY" \ width=32 \ icon.padding_left=13 \ icon.padding_right=11 \ @@ -571,13 +585,19 @@ in background.drawing=on \ icon.color=$TEXT elif [ "$IS_EMPTY" = "true" ]; then - # Empty workspace (not focused) - hide by turning off drawing + # Empty workspace (not focused) - hide by collapsing width and clearing content + # Using width=0 + empty icon/label instead of drawing=off because drawing=off doesn't reliably re-show items ${pkgs.sketchybar}/bin/sketchybar --set space.$WORKSPACE_NUM \ - drawing=off + icon="" \ + label="" \ + width=0 \ + icon.padding_left=0 \ + icon.padding_right=0 \ + background.drawing=off else # Non-empty workspace (not focused) - show with inactive styling ${pkgs.sketchybar}/bin/sketchybar --set space.$WORKSPACE_NUM \ - drawing=on \ + icon="$DISPLAY" \ width=32 \ icon.padding_left=13 \ icon.padding_right=11 \