blob: 4eabd7499b530bb763994ec724418c9ef4612c44 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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 &
|