Skip to main content

xquartz-window-resize

· 2 min read

If you're running MacOS and using XQuartz in order to transport app GUI display over SSH from a remote system you may run into an issue with XQuartz displayed window sizes not being adjustable beyond maximising it to the fill the screen or returning it to the initial size.

Normally each window is resized via the very bottom right corner however the initial display of the app may result in that corner being outside the size of your actually display.

After a little bit of time on Google I came across a script that uses xwininfo to identify the window to resize and then xdotool to actually resize it.

Unfortunately that script didn't work straight out of the box.

Some slight modifications led me to creating a working version as below.

Here it is in action,

user@mbp ~ % x11_resize 1920 1080
Click on the target window
info_id='xwininfo: Window id: 0x600003 "New Tab - Chromium"'
id=0x600003
title=New Tab - Chromium
Resize "New Tab - Chromium" (1905 x 2114) to 1920 x 1080? [y / n] y
Warning: XTEST extension unavailable on '(null)'. Some functionality may be disabled; See 'man xdotool' for more info.
user@mbp ~ %

Once adjusted to the size you want maximising it to your full display size will still work, and unmaximising it will return it to your custom adjusted size.

Post adjustment each XQuartz displayed app appears to retain the custom sizing.

The script itself,

#!/bin/bash

# Use xwininfo to get the id (and name) of a window (click to select)
# Use xdotool to resize the window to a specific size

if [[ $# -ne 2 ]]; then
echo "Usage $0 width height"
exit 0
fi

w=$1
h=$2

echo "Click on the target window"

info=$(xwininfo)

info_id=`echo "$info" | grep 'Window id:'`
info_w=`echo "$info" | grep 'Width:'`
info_h=`echo "$info" | grep 'Height:'`

echo "info_id='${info_id}'"

if [[ "$info_id" =~ ^.+Window\ id:\ (.+)\ \"(.+)\"$ ]]; then
id="${BASH_REMATCH[1]}"
title="${BASH_REMATCH[2]}"
fi

echo "id=${id}"
echo "title=${title}"

if [[ "$info_w" =~ "Width: "(.+) ]]; then
window_w=${BASH_REMATCH[1]}
fi
if [[ "$info_h" =~ "Height: "(.+) ]]; then
window_h=${BASH_REMATCH[1]}
fi

read -p "Resize \"$title\" ($window_w x $window_h) to $w x $h? [y / n] " answer

if ! [[ "$answer" == "" || "${answer}" == "y" ]]; then
exit 0
fi

xdotool windowsize $id $w $h

# EOF

Welcome

· One min read
Colin Stubbs
Space Monkey Meat Popsicle

This is a new site and a new attempt to invigorate what was once a passion for blogging and sharing solutions to technology problems.