Improve hyprland config (env + handler)
This commit is contained in:
parent
c6267c7163
commit
b3f1045292
7 changed files with 135 additions and 99 deletions
|
@ -1,35 +1,65 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i sh -p socat jq
|
||||
|
||||
# Config
|
||||
ws_media="[08]"
|
||||
ws_voip="[09]"
|
||||
|
||||
ws_media_at="[ 0, 0 ]"
|
||||
|
||||
|
||||
# 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)
|
||||
}
|
||||
|
||||
_handler_check_ws_media_empty() {
|
||||
|
||||
# split at ">>" and get the second part and take first part of that
|
||||
event=$(echo "$1" | cut -d'>' -f1)
|
||||
win_id=$(echo "$1" | cut -d'>' -f3 | cut -d',' -f1)
|
||||
|
||||
event_on_media="false"
|
||||
win_client=$(echo "$all_clients" | jq ".[] | select(.address == \"0x$win_id\")")
|
||||
|
||||
moved_from_media=$(hyprctl clients -j | jq ".[] | select(.address == \"0x$win_id\") | .workspace.name == \"$ws_media\"")
|
||||
closed_on_media=$(hyprctl clients -j | jq ".[] | select(.address == \"0x$win_id\") | .at == $ws_media_at")
|
||||
|
||||
if [ "$moved_from_media" == "true" ] || [ "$closed_on_media" == "true" ]; then
|
||||
event_on_media="true"
|
||||
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")"
|
||||
fi
|
||||
|
||||
has_zero_windows=$(hyprctl workspaces -j | jq ".[] | select(.name == \"$ws_media\") | .windows == 0")
|
||||
|
||||
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"
|
||||
|
||||
if [ "$has_zero_windows" == "true" ] && [ "$event_on_media" == "true" ]; then
|
||||
hyprctl dispatch workspace "$ws_voip"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
handle() {
|
||||
debug "----- $1 -----"
|
||||
case $1 in
|
||||
openwindow*) _handler_update_all_clients "$1" ;;
|
||||
movewindow*) _handler_check_ws_media_empty "$1" ;;
|
||||
closewindow*) _handler_check_ws_media_empty "$1" ;;
|
||||
esac
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue