aboutsummaryrefslogtreecommitdiff
path: root/title-bar
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2023-12-20 23:55:36 +0200
committersrdusr <trevorgray@srdusr.com>2023-12-20 23:55:36 +0200
commit8531b174f8aa642d7fbc3cde6cf85cf90943b07c (patch)
tree894536ab310a3b70bcd16ec042bd63f88f0b22df /title-bar
parentf821051a3b74623f8f2875969f3777f69e3f2c64 (diff)
downloaddotfiles-8531b174f8aa642d7fbc3cde6cf85cf90943b07c.tar.gz
dotfiles-8531b174f8aa642d7fbc3cde6cf85cf90943b07c.zip
Add title-bar
Diffstat (limited to 'title-bar')
-rwxr-xr-xtitle-bar124
1 files changed, 124 insertions, 0 deletions
diff --git a/title-bar b/title-bar
new file mode 100755
index 0000000..4eabd74
--- /dev/null
+++ b/title-bar
@@ -0,0 +1,124 @@
+#!/bin/bash
+
+# Debug log file
+DEBUG_LOG="/tmp/title-bar_debug.log"
+
+# Debug function
+debug_echo() {
+ echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >>"$DEBUG_LOG"
+}
+
+debug_echo "Script execution started."
+
+# Background image path
+bg_path="/tmp/bg_${bgw}.png"
+
+# Function to create background images
+create_background_image() {
+ # local bgw="$1"
+ #
+ # debug_echo "Creating background image with size ${bgw}x13 and color #77dd77"
+ #
+ # if [ ! -e "$bg_path" ]; then
+ # convert -size "${bgw}"x13 xc:"#77dd77" "$bg_path" 2>>"$DEBUG_LOG"
+ # convert_status=$?
+ #
+ # if [ "$convert_status" -ne 0 ]; then
+ # debug_echo "Error creating background image. Convert command exit status: $convert_status"
+ # else
+ # debug_echo "Background image created at: $bg_path"
+ # fi
+ # fi
+ local r="$1"
+ local g="$2"
+ local b="$3"
+ #echo -e "\e[48;2;${r};${g};${b}m"
+ echo -e "\e[48;2;119;221;119m"
+
+}
+
+# Kill existing lemonbar instances and update script
+pkill -f "lemonbar"
+pkill -f "update-title"
+
+# Get the focused window information
+focused_info="$(bspc query -T --names -d focused --node)"
+
+# Get the focused window ID
+focused_id="$(bspc query -N -n focused)"
+
+# Check if the window ID is empty
+if [ "$focused_id" = "" ]; then
+ echo "No focused window found."
+ exit
+fi
+
+# Get the WM_CLASS of the focused window
+focused_class="$(xprop WM_CLASS -id "$focused_id" | awk -F '"' '{print $2}')"
+
+debug_echo "Focused Class: $focused_class"
+
+# Exclude certain window classes
+case "$focused_class" in
+ "Steam" | "Qmmp" | "Wrapper-1.0" | "xfce4-panel")
+ debug_echo "Excluded window class: $focused_class. Exiting script."
+ exit
+ ;;
+esac
+
+# Get focused window geometry
+read -r x y w h < <(xwininfo -id "$focused_id" |
+ awk '/Absolute upper-left X:/ { x=$4 }
+ /Absolute upper-left Y:/ { y=$4 }
+ /Width:/ { w=$2 }
+ /Height:/ { h=$2 }
+END { print x, y, w, h }')
+
+geoBar=$(echo "$w 13 $x $y" | awk '{print $1+4"x13+"$3"+"$4-8}')
+#geoBar=$(echo "$w 10 $x $y" | awk '{print $1+4"x10+"$3"+"$4+2}')
+
+# Create background image based on window width
+create_background_image $(($w - 116))
+
+# Launch lemonbar
+echo -e "%{c}%{I:${bg_path}:}%{l}%{I:$HOME/.scripts/assests/corner.png:}%{r}%{I:$HOME/.scripts/assests/corner.png:}" |
+lemonbar -d -p -B "$HOME/.scripts/assests/trans.png" -U "#77dd77" -F "#4e585d" -f "Terminus:size=1" -g "$geoBar" &
+#lemonbar -d -p -B "#77dd77" -U "#77dd77" -F "#4e585d" -f "Terminus:size=1" -g "$geoBar" &
+sleep 0.05
+
+# Launch update-title for the focused window
+~/.scripts/update-title "$focused_id" | lemonbar -d -g "$geoBar" -f "Jetbrains Mono:size=6" -f "Jetbrains Mono:size=6" -p | bash &
+
+# Wait for lemonbar to start
+sleep 0.1
+
+# Adjust stacking order for the focused window
+barinfos="$(xwininfo -tree -root | grep "$focused_id")"
+bgid="$(echo "$barinfos" | tail -n 1 | awk '{print $1}')"
+xdo below -t "$focused_id" "$bgid"
+xdo above -t "$bgid" "$(echo "$barinfos" | head -n 1 | awk '{print $1}')"
+
+debug_echo "Script execution completed."
+
+# Function to handle updates triggered by BSPWM events
+handle_bspwm_events() {
+ while read -r line; do
+ event_type=$(echo "$line" | jq -r '.type')
+
+ case "$event_type" in
+ focus_changed)
+ focused_node=$(echo "$line" | jq -r '.node')
+ ~/.scripts/update-title "$focused_node" | lemonbar -p -g "$geoBar" -f "Jetbrains Mono:size=6" -f "Jetbrains Mono:size=6" | bash &
+ ;;
+ node_add | node_remove | node_flag)
+ # Handle other node-related events
+ ;;
+ *)
+ # Handle other events as needed
+ ;;
+ esac
+ done
+}
+
+# Subscribe to BSPWM events and pass them to the handler function
+bspc subscribe | handle_bspwm_events &