dotfiles/bin/executable_sway-center-window

34 lines
1.1 KiB
Bash

#!/usr/bin/env bash
client_info=$(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true)')
pid=$(echo "$client_info"| jq .id)
info_file="/dev/shm/sway-width-${pid}"
current_info_file="/dev/shm/sway-width-${pid}.current"
echo "$client_info" > "$info_file"
if [[ -f $current_info_file ]]; then
width=$(<"$current_info_file")
fi;
if [[ -z "${width}" ]]; then
echo "None" > "${current_info_file}"
elif [[ "${width}" == "None" ]]; then
echo "25ppt 50ppt" > "${current_info_file}"
swaymsg resize set 25ppt 50ppt
elif [[ "${width}" == "25ppt 50ppt" ]]; then
echo "50ppt 50ppt" > "${current_info_file}"
swaymsg resize set 50ppt 50ppt
elif [[ "${width}" == "50ppt 50ppt" ]]; then
echo "75ppt 75ppt" > "${current_info_file}"
swaymsg resize set 75ppt 75ppt
elif [[ "${width}" == "75" ]]; then
rm -f "${current_info_file}"
old_width=$(echo "$client_info"| jq .geometry.width)
old_height=$(echo "$client_info"| jq .geometry.height)
swaymsg resize set "${old_width}px" "${old_height}px"
else
echo "ui"
fi
swaymsg move position center