2023-06-30 18:47:01 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -i sh -p socat jq
|
|
|
|
|
2023-07-08 10:27:08 +00:00
|
|
|
# Config
|
2023-06-30 18:47:01 +00:00
|
|
|
ws_media="[08]"
|
2023-07-15 13:22:51 +00:00
|
|
|
ws_chat="[09]"
|
2023-06-30 18:47:01 +00:00
|
|
|
|
2023-07-06 21:38:19 +00:00
|
|
|
ws_media_at="[ 0, 0 ]"
|
|
|
|
|
2023-07-08 10:27:08 +00:00
|
|
|
|
|
|
|
# Debug code
|
|
|
|
debug_enabled="false"
|
|
|
|
if [ "$1" == "--debug" ]; then
|
|
|
|
debug_enabled="true"
|
|
|
|
fi
|
|
|
|
|
|
|
|
debug() {
|
|
|
|
if [ "$debug_enabled" == "true" ]; then
|
|
|
|
echo "$1" >&2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Main code
|
|
|
|
all_clients="[]"
|
|
|
|
|
|
|
|
_handler_update_all_clients() {
|
|
|
|
all_clients=$(hyprctl clients -j)
|
|
|
|
}
|
|
|
|
|
2023-06-30 18:47:01 +00:00
|
|
|
_handler_check_ws_media_empty() {
|
|
|
|
|
2023-07-06 21:38:19 +00:00
|
|
|
# split at ">>" and get the second part and take first part of that
|
2023-07-08 10:27:08 +00:00
|
|
|
event=$(echo "$1" | cut -d'>' -f1)
|
2023-07-06 21:38:19 +00:00
|
|
|
win_id=$(echo "$1" | cut -d'>' -f3 | cut -d',' -f1)
|
|
|
|
|
2023-07-08 10:27:08 +00:00
|
|
|
win_client=$(echo "$all_clients" | jq ".[] | select(.address == \"0x$win_id\")")
|
2023-07-06 21:38:19 +00:00
|
|
|
|
2023-07-08 10:27:08 +00:00
|
|
|
if [ "$event" == "closewindow" ]; then
|
|
|
|
event_on_media="$(echo "$win_client" | jq ".workspace.name == \"$ws_media\"")"
|
|
|
|
fi
|
|
|
|
if [ "$event" == "movewindow" ]; then
|
|
|
|
event_on_media="$(echo "$win_client" | jq ".at == $ws_media_at")"
|
2023-07-06 21:38:19 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
has_zero_windows=$(hyprctl workspaces -j | jq ".[] | select(.name == \"$ws_media\") | .windows == 0")
|
|
|
|
|
2023-07-08 10:27:08 +00:00
|
|
|
debug "event: $event"
|
|
|
|
debug "win_id: $win_id"
|
|
|
|
debug "client: $win_client"
|
|
|
|
debug "event_on_media: $event_on_media"
|
|
|
|
debug "has_zero_windows: $has_zero_windows"
|
|
|
|
|
2023-07-06 22:40:25 +00:00
|
|
|
if [ "$has_zero_windows" == "true" ] && [ "$event_on_media" == "true" ]; then
|
2023-07-15 13:22:51 +00:00
|
|
|
hyprctl dispatch workspace "$ws_chat"
|
2023-06-30 18:47:01 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
handle() {
|
2023-07-08 10:27:08 +00:00
|
|
|
debug "----- $1 -----"
|
2023-06-30 18:47:01 +00:00
|
|
|
case $1 in
|
2023-07-08 10:27:08 +00:00
|
|
|
openwindow*) _handler_update_all_clients "$1" ;;
|
2023-06-30 18:47:01 +00:00
|
|
|
movewindow*) _handler_check_ws_media_empty "$1" ;;
|
|
|
|
closewindow*) _handler_check_ws_media_empty "$1" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
socat -U - "UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | while read -r line; do handle "$line"; done
|