wmctrl incorrect resize and move - application dependant

572 Views Asked by At

When resizing and moving with wmctrl, the outcome is both incorrect and depending on application.

Example: At the time of writing I have emacs, chromium, spotify and gnome-terminal running

ws=$(wmctrl -d | grep "*" | awk '{print $1}')
n=$(wmctrl -l | awk '{print $2 ";" $1}' | grep ^$ws | wc -l)
windows=$(wmctrl -l | awk '{print $2 ";" $1}' | grep ^$ws | cut -d ";" -f 2)

window1=$(echo $windows | cut -d " " -f 1)
window2=$(echo $windows | cut -d " " -f 2)
window3=$(echo $windows | cut -d " " -f 3)
window4=$(echo $windows | cut -d " " -f 4)

for i in ${windows[@]} ; do
    wmctrl -ir $i -b remove,maximized_horz,maximized_vert
done

wmctrl -ir $window1 -e 1,0,0,960,540
wmctrl -ir $window2 -e 1,0,540,960,540
wmctrl -ir $window3 -e 1,960,0,960,540
wmctrl -ir $window4 -e 1,960,540,960,540

Now, wmctrl -lG results in the following (irrelevant info removed):

width  height
952    540   emacs
960    540   chromium
954    529   gnome-terminal
960    540   Spotify

Running the exact same code for 4 terminal windows yield:

width  height
954    529   gnome-terminal
954    529   gnome-terminal
954    529   gnome-terminal
954    529   gnome-terminal

All sizes are incorrect, but also the different applications have different sizes whilst all windows of the same application has the same size.

Expected:

960    540   emacs
960    540   chromium
960    540   gnome-terminal
960    540   Spotify

I cannot seem to find any posts discussing this exact issue.

All help is much appreciated!

1

There are 1 best solutions below

2
On

Each window has decorations (ie. border). Your gnome-terminal window has 6 pixels wide border on the left and 11 pixels high border on the top (probably title bar). When you move your window, it moves the position of the window excluding the border size, but the wmctrl -G output shows the geometry including the border sizes. See this topic. You can get the border size using xwininfo magic, like here.