Skip to content

Instantly share code, notes, and snippets.

@ashnur
Created April 11, 2023 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashnur/90354b04acb434d203beb097c109e230 to your computer and use it in GitHub Desktop.
Save ashnur/90354b04acb434d203beb097c109e230 to your computer and use it in GitHub Desktop.
#!/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