Created
April 11, 2023 09:04
-
-
Save ashnur/6e8de1c636d6319832546bf4bb8a800c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# swaykill: Kill a window with a click in Sway | |
set -e | |
if ! command -v slurp jq >/dev/null 2>&1; then | |
echo "Please install slurp and jq" >&2 | |
exit 1 | |
fi | |
coords_and_size=$(slurp -p) | |
coords=$(echo "$coords_and_size" | cut -d ' ' -f 1) | |
coords_x=$(echo "$coords" | cut -d ',' -f 1) | |
coords_y=$(echo "$coords" | cut -d ',' -f 2) | |
window_data=$(swaymsg -t get_tree | jq -r --arg x "$coords_x" --arg y "$coords_y" 'recurse(.nodes[]?) | select(.visible and (.rect | (($x | tonumber) >= .x and ($x | tonumber) + .width > .x ) ))') | |
window_id=$(echo "$window_data" | jq -r '.id') | |
window_pid=$(echo "$window_data" | jq -r '.pid') | |
if [ -n "$window_id" ]; then | |
swaymsg "[con_id=$window_id]" move scratchpad | |
swaymsg "[con_id=$window_id]" kill | |
else | |
echo "No window found at the selected position" >&2 | |
exit 1 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment