Skip to content

Instantly share code, notes, and snippets.

@kraftwerk28
Created August 19, 2021 19:28
Show Gist options
  • Save kraftwerk28/f6087783be1306907f81f958a114b2eb to your computer and use it in GitHub Desktop.
Save kraftwerk28/f6087783be1306907f81f958a114b2eb to your computer and use it in GitHub Desktop.
Move floating window towards edges of workspace

Usage:

./push-window.sh <top|right|bottom|left>...

for example

$ ./push-window top right
$ ./push-window left
#!/usr/bin/env bash
raw=$(swaymsg -t get_tree)
read wx wy ww wh < <(jq -r '..
| (.floating_nodes? // empty)[]
| select(.focused==true)
| .rect
| "\(.x) \(.y) \(.width) \(.height)"' <<< $raw)
read wsx wsy wsw wsh < <(jq -r '..
| (.nodes? // empty)[]
| select(.type=="workspace")
| select(.. | .focused?==true)
| .rect
| "\(.x) \(.y) \(.width) \(.height)"' <<< $raw)
if [[ -z $wx ]]; then
echo "Focused window is not floating"
exit 1
fi
x=$(($wx-$wsx))
y=$(($wy-$wsy))
while (($#)); do
case $1 in
left) x=0;;
top) y=0;;
right) x=$(($wsw-$ww));;
bottom) y=$(($wsh-$wh));;
*) echo "Unrecognized direction" >&2; exit 1;;
esac
shift
done
swaymsg move position $x $y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment