48 lines
1.2 KiB
Bash
Executable File
48 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# --- This file has been auto-generated. For permanent changes alter the appropriate block in the README.org. ---
|
|
# Auto-adjust scrolling column width based on window count
|
|
# Widths: 1 window = fullscreen (handled by hyprland)
|
|
# 2 windows = 0.5 each
|
|
# 3+ windows = 0.329 each
|
|
|
|
get_window_count() {
|
|
local ws_id=$1
|
|
hyprctl clients -j | jq "[.[] | select(.workspace.id == $ws_id)] | length"
|
|
}
|
|
|
|
get_active_workspace() {
|
|
hyprctl activeworkspace -j | jq -r '.id'
|
|
}
|
|
|
|
set_column_width() {
|
|
local width=$1
|
|
hyprctl dispatch layoutmsg "colresize all $width"
|
|
}
|
|
|
|
handle_event() {
|
|
local event=$1
|
|
|
|
case "$event" in
|
|
openwindow*|closewindow*|movewindow*)
|
|
ws_id=$(get_active_workspace)
|
|
count=$(get_window_count "$ws_id")
|
|
|
|
if [ "$count" -le 1 ]; then
|
|
# fullscreen_on_one_column handles this
|
|
:
|
|
elif [ "$count" -eq 2 ]; then
|
|
set_column_width 0.5
|
|
else
|
|
set_column_width 0.329
|
|
fi
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Listen to hyprland socket events
|
|
socket="/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"
|
|
|
|
socat -U - "UNIX-CONNECT:$socket" | while read -r line; do
|
|
handle_event "$line"
|
|
done
|