From 1ead947d065e8ca141a48743b7158ab2c1339336 Mon Sep 17 00:00:00 2001 From: jteijema Date: Wed, 23 Jul 2025 13:44:50 +0200 Subject: feat: Add selected config highlighting for waybar --- config/hypr/scripts/WaybarLayout.sh | 50 ++++++++++++++++++++++++------------- config/hypr/scripts/WaybarStyles.sh | 49 +++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 36 deletions(-) diff --git a/config/hypr/scripts/WaybarLayout.sh b/config/hypr/scripts/WaybarLayout.sh index 0bea6ffe..88267cdb 100755 --- a/config/hypr/scripts/WaybarLayout.sh +++ b/config/hypr/scripts/WaybarLayout.sh @@ -9,17 +9,6 @@ waybar_layouts="$HOME/.config/waybar/configs" waybar_config="$HOME/.config/waybar/config" SCRIPTSDIR="$HOME/.config/hypr/scripts" rofi_config="$HOME/.config/rofi/config-waybar-layout.rasi" -msg=' 🎌 NOTE: Some waybar LAYOUT NOT fully compatible with some STYLES' - -# Function to display menu options -menu() { - options=() - while IFS= read -r file; do - options+=("$(basename "$file")") - done < <(find -L "$waybar_layouts" -maxdepth 1 -type f -exec basename {} \; | sort ) - - printf '%s\n' "${options[@]}" -} # Apply selected configuration apply_config() { @@ -27,16 +16,41 @@ apply_config() { "${SCRIPTSDIR}/Refresh.sh" & } -# Main function main() { - choice=$(menu | rofi -i -dmenu -config "$rofi_config" -mesg "$msg") + # Resolve current symlink target and basename + current_target=$(readlink -f "$waybar_config") + current_name=$(basename "$current_target") + + # Build sorted list of available layouts + mapfile -t options < <( + find -L "$waybar_layouts" -maxdepth 1 -type f -printf '%f\n' | sort + ) + + # Mark and locate the active layout + default_row=0 + for i in "${!options[@]}"; do + if [[ "${options[i]}" == "$current_name" ]]; then + options[i]="${options[i]} ⮕" + default_row=$i + break + fi + done + + # Launch rofi with the annotated list, pre‑selecting the active row + choice=$(printf '%s\n' "${options[@]}" \ + | rofi -i -dmenu \ + -config "$rofi_config" \ + -mesg "$msg" \ + -selected-row "$default_row" + ) + + # Exit if nothing chosen + [[ -z "$choice" ]] && { echo "No option selected. Exiting."; exit 0; } - if [[ -z "$choice" ]]; then - echo "No option selected. Exiting." - exit 0 - fi + # Strip marker before applying + choice=${choice% ⮕} - case $choice in + case "$choice" in "no panel") pgrep -x "waybar" && pkill waybar || true ;; diff --git a/config/hypr/scripts/WaybarStyles.sh b/config/hypr/scripts/WaybarStyles.sh index 246a66a2..61b278e5 100755 --- a/config/hypr/scripts/WaybarStyles.sh +++ b/config/hypr/scripts/WaybarStyles.sh @@ -11,33 +11,46 @@ SCRIPTSDIR="$HOME/.config/hypr/scripts" rofi_config="$HOME/.config/rofi/config-waybar-style.rasi" msg=' 🎌 NOTE: Some waybar STYLES NOT fully compatible with some LAYOUTS' -# Function to display menu options -menu() { - options=() - while IFS= read -r file; do - if [ -f "$waybar_styles/$file" ]; then - options+=("$(basename "$file" .css)") - fi - done < <(find -L "$waybar_styles" -maxdepth 1 -type f -name '*.css' -exec basename {} \; | sort ) - - printf '%s\n' "${options[@]}" -} - # Apply selected style apply_style() { ln -sf "$waybar_styles/$1.css" "$waybar_style" "${SCRIPTSDIR}/Refresh.sh" & } -# Main function main() { - choice=$(menu | rofi -i -dmenu -config "$rofi_config" -mesg "$msg") + # resolve current symlink and strip .css + current_target=$(readlink -f "$waybar_style") + current_name=$(basename "$current_target" .css) + + # gather all style names (without .css) into an array + mapfile -t options < <( + find -L "$waybar_styles" -maxdepth 1 -type f -name '*.css' \ + -exec basename {} .css \; \ + | sort + ) + + # mark the active style and record its index + default_row=0 + for i in "${!options[@]}"; do + if [[ "${options[i]}" == "$current_name" ]]; then + options[i]="${options[i]} ⮕" + default_row=$i + break + fi + done + + # launch rofi with the annotated list and pre‑selected row + choice=$(printf '%s\n' "${options[@]}" \ + | rofi -i -dmenu \ + -config "$rofi_config" \ + -mesg "$msg" \ + -selected-row "$default_row" + ) - if [[ -z "$choice" ]]; then - echo "No option selected. Exiting." - exit 0 - fi + [[ -z "$choice" ]] && { echo "No option selected. Exiting."; exit 0; } + # remove annotation and apply + choice=${choice% ⮕} apply_style "$choice" } -- cgit v1.2.3 From 11236530437df615d3bb3005d0c5ba386af084b9 Mon Sep 17 00:00:00 2001 From: Jelle Teijema Date: Wed, 23 Jul 2025 23:21:11 +0200 Subject: revert: removal of NOTE --- config/hypr/scripts/WaybarLayout.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/config/hypr/scripts/WaybarLayout.sh b/config/hypr/scripts/WaybarLayout.sh index 88267cdb..3529a082 100755 --- a/config/hypr/scripts/WaybarLayout.sh +++ b/config/hypr/scripts/WaybarLayout.sh @@ -9,6 +9,7 @@ waybar_layouts="$HOME/.config/waybar/configs" waybar_config="$HOME/.config/waybar/config" SCRIPTSDIR="$HOME/.config/hypr/scripts" rofi_config="$HOME/.config/rofi/config-waybar-layout.rasi" +msg=' 🎌 NOTE: Some waybar LAYOUT NOT fully compatible with some STYLES' # Apply selected configuration apply_config() { -- cgit v1.2.3 From 43c7521efba41ce8430bc9a6825acc5a0147cbd3 Mon Sep 17 00:00:00 2001 From: "Ja.KooLit" <85185940+JaKooLit@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:20:05 +0900 Subject: Update WaybarLayout.sh --- config/hypr/scripts/WaybarLayout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/hypr/scripts/WaybarLayout.sh b/config/hypr/scripts/WaybarLayout.sh index 3529a082..955432fc 100755 --- a/config/hypr/scripts/WaybarLayout.sh +++ b/config/hypr/scripts/WaybarLayout.sh @@ -31,7 +31,7 @@ main() { default_row=0 for i in "${!options[@]}"; do if [[ "${options[i]}" == "$current_name" ]]; then - options[i]="${options[i]} ⮕" + options[i]="👉 ${options[i]}" default_row=$i break fi -- cgit v1.2.3 From 028bc0a1fdc6b9b4fc132684e2552afc7336a5b6 Mon Sep 17 00:00:00 2001 From: "Ja.KooLit" <85185940+JaKooLit@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:20:24 +0900 Subject: Update WaybarStyles.sh --- config/hypr/scripts/WaybarStyles.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/hypr/scripts/WaybarStyles.sh b/config/hypr/scripts/WaybarStyles.sh index 61b278e5..20f0873b 100755 --- a/config/hypr/scripts/WaybarStyles.sh +++ b/config/hypr/scripts/WaybarStyles.sh @@ -33,7 +33,7 @@ main() { default_row=0 for i in "${!options[@]}"; do if [[ "${options[i]}" == "$current_name" ]]; then - options[i]="${options[i]} ⮕" + options[i]="👉 ${options[i]}" default_row=$i break fi -- cgit v1.2.3