95 lines
2.2 KiB
Bash
Executable file
95 lines
2.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# define colors
|
|
# red peach green blue
|
|
colors=("#f38ba8" "#fab387" "#a6e3a1" "#89b4fa")
|
|
empty="rgba(30, 30, 46, 0.6)"
|
|
|
|
# get initial focused workspace
|
|
focusedws=$(hyprctl -j monitors | jaq -r '.[] | select(.focused == true) | .activeWorkspace.id')
|
|
|
|
declare -A o=([1]=0 [2]=0 [3]=0 [4]=0 [5]=0 [6]=0 [7]=0 [8]=0 [9]=0 [10]=0)
|
|
declare -A monitormap
|
|
declare -A workspaces
|
|
|
|
# set color for each workspace
|
|
status() {
|
|
if [ "${o[$1]}" -eq 1 ]; then
|
|
mon=${monitormap[${workspaces[$1]}]}
|
|
echo -n "${colors[$mon]}"
|
|
else
|
|
echo -n "$empty"
|
|
fi
|
|
}
|
|
|
|
# handle workspace create/destroy
|
|
workspace_event() {
|
|
while read -r k v; do workspaces[$k]="$v"; done < <(hyprctl -j workspaces | jaq -jr '.[] | .id, " ", .monitor, "\n"')
|
|
}
|
|
# handle monitor (dis)connects
|
|
monitor_event() {
|
|
while read -r k v; do monitormap["$k"]=$v; done < <(hyprctl -j monitors | jaq -jr '.[] | .name, " ", .id, "\n"')
|
|
}
|
|
|
|
# get all apps titles in a workspace
|
|
applist() {
|
|
ws="$1"
|
|
|
|
apps=$(hyprctl -j clients | jaq -jr '.[] | select(.workspace.id == '"$ws"') | .title + "\\n"')
|
|
echo -En "${apps%"\n"}"
|
|
}
|
|
|
|
# generate the json for eww
|
|
generate() {
|
|
echo -n '{"workspaces": ['
|
|
|
|
for i in {1..10}; do
|
|
echo -n ''"$([ "$i" -eq 1 ] || echo ,)" '{"number": '"$i"', "color": "'"$(status "$i")"'", "focused": '"$([ "$focusedws" = "$i" ] && echo "true" || echo "false")"'}' #, "tooltip": "'$(applist "$i")'" }'
|
|
done
|
|
|
|
echo '], "screencast": '"$screencast"'}'
|
|
}
|
|
|
|
# setup
|
|
|
|
# add monitors
|
|
monitor_event
|
|
|
|
# add workspaces
|
|
workspace_event
|
|
|
|
# screen is not shared by default
|
|
screencast=false
|
|
|
|
# check occupied workspaces
|
|
for num in "${!workspaces[@]}"; do
|
|
o[$num]=1
|
|
done
|
|
# generate initial widget
|
|
generate
|
|
|
|
# main loop
|
|
socat -u UNIX-CONNECT:/tmp/hypr/"$HYPRLAND_INSTANCE_SIGNATURE"/.socket2.sock - | rg --line-buffered "workspace|mon(itor)?|screencast" | while read -r line; do
|
|
case ${line%>>*} in
|
|
"workspace")
|
|
focusedws=${line#*>>}
|
|
;;
|
|
"focusedmon")
|
|
focusedws=${line#*,}
|
|
;;
|
|
"createworkspace")
|
|
o[${line#*>>}]=1
|
|
;;
|
|
"destroyworkspace")
|
|
o[${line#*>>}]=0
|
|
;;
|
|
"monitor"*)
|
|
monitor_event
|
|
;;
|
|
"screencast")
|
|
screencast=$([ "$(echo "${line#*>>}" | awk -F, '{print $1}')" -eq 1 ] && echo true || echo false)
|
|
;;
|
|
esac
|
|
generate
|
|
done
|