From 8cbadb61604667b407b53ee1258433994fa4765a Mon Sep 17 00:00:00 2001 From: coasteen Date: Thu, 9 Jul 2026 10:42:28 +0330 Subject: init --- config/waybar-2/waybar/window.sh | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 config/waybar-2/waybar/window.sh (limited to 'config/waybar-2/waybar/window.sh') diff --git a/config/waybar-2/waybar/window.sh b/config/waybar-2/waybar/window.sh new file mode 100755 index 0000000..abf1e39 --- /dev/null +++ b/config/waybar-2/waybar/window.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +MAX_TITLE_LEN=20 + +print_status() { + window=$(hyprctl activewindow -j 2>/dev/null) + address=$(jq -r '.address // empty' <<< "$window") + + # No active window → show Desktop + Workspace + if [[ -z "$address" || "$address" == "null" ]]; then + ws=$(hyprctl activeworkspace -j | jq -r '.id') + + top_line="Desktop" + bottom_line="Workspace $ws" + + esc_top=$(sed 's/&/&/g; s//>/g' <<< "$top_line") + esc_bottom=$(sed 's/&/&/g; s//>/g' <<< "$bottom_line") + + text="$esc_top +$esc_bottom" + + jq -nc \ + --arg text "$text" \ + --arg tooltip "$bottom_line" \ + '{ text: $text, class: "custom-window", tooltip: $tooltip }' + return + fi + + class=$(jq -r '.class // "Unknown"' <<< "$window") + title=$(jq -r '.title // ""' <<< "$window") + + app_class="${class,,}" + + # Discord / Vesktop cleanup + if [[ "$app_class" == *discord* || "$app_class" == *vesktop* ]]; then + title=$(sed -E 's/^\([0-9]+\)[[:space:]]*//' <<< "$title") + title=$(sed -E 's/^Discord[[:space:]]*\|[[:space:]]*//' <<< "$title") + fi + + # Truncate title + if (( ${#title} > MAX_TITLE_LEN )); then + title="${title:0:$((MAX_TITLE_LEN-3))}..." + fi + + esc_top=$(sed 's/&/&/g; s//>/g' <<< "$class") + esc_bottom=$(sed 's/&/&/g; s//>/g' <<< "$title") + + text="$esc_top +$esc_bottom" + + tooltip="$class: $title" + + jq -nc \ + --arg text "$text" \ + --arg tooltip "$tooltip" \ + '{ text: $text, class: "custom-window", tooltip: $tooltip }' +} + +# Initial output +print_status + +last="" + +# Update only when state changes +while true; do + current_window=$(hyprctl activewindow -j 2>/dev/null) + current_ws=$(hyprctl activeworkspace -j 2>/dev/null) + + current="$current_window$current_ws" + + if [[ "$current" != "$last" ]]; then + print_status + last="$current" + fi + + sleep 0.5 +done -- cgit v1.2.3