Skip to content

Instantly share code, notes, and snippets.

@mmguero
Last active October 20, 2022 21:19
Show Gist options
  • Save mmguero/4afe9db7d9da60c89b5145a60ba669e8 to your computer and use it in GitHub Desktop.
Save mmguero/4afe9db7d9da60c89b5145a60ba669e8 to your computer and use it in GitHub Desktop.
Get the coordinates of the active window's top-left corner, and the window's size
#!/usr/bin/env bash
# https://gist.github.com/mmguero/4afe9db7d9da60c89b5145a60ba669e8
# Get the coordinates of the active window's
# top-left corner, and the window's size.
# This excludes the window decoration.
unset x y w h
eval $(xwininfo -id $(xdotool getactivewindow) |
sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \
-e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \
-e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \
-e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" )
echo -n "$x $y $w $h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment