Causes of Deviation in wmctrl Window Move Command

command lineunitywindow-managerwmctrl

About wmctrl

With wmctrl (not installed by default), we can get information on windows, their id, their geometry, the pid they belong to etc. We can also move or resize windows with several commands. However, in some respects, its behaviour seems not logical. My question is about moving windows by wmctrl:

Getting information

When I run the command:

wmctrl -lG

I get (a.o.) the following information about the window in the picture(s)below:

0x04200085  0 746  443  468  205  jacob-System-Product-Name Niet-opgeslagen document 1 - gedit

In column 3-5, the geometry information tells us the x/y coordinates and the width/height.

Moving/resizing the window

When I put these coordinates in the wmctrl command to move/resize a window, it should do nothing, since the coordinates are unchanged:

wmctrl -ir 0x04200085 -e 0,746,443,468,205

Deviation

However, the pictures below show the window is moved downwards (28px to be precise). I assumed the reason was that the wmctrl window move command calculated with the working area (screen minus panel height), while the wmctrl -lG command calculated with the total screen size. Then still 4px is unexplained however (the panel is 24px high).

Although the deviation can very well be compensated in scripts, the fact that I don't understand the cause is not satisfying, so the question is:

What is exactly the cause for this deviation?

Moving a window with the exact coordinates in the output of wmctrl -lG should not move the window, but it does

enter image description here

enter image description here

Best Answer

What's happening is that wmctrl is returning the geometry of the window inside the decorations (i.e. not including the title bar and borders) but is using the larger window position for the move.

(Some command output lines removed : xdotool might not be installed)

$ wmctrl -lG
0x04000040  0 702  23   900  950  KMatrix dave@KMatrix: test – Konsole

$ xdotool getwindowgeometry 0x04000040
Window 67108928
  Position: 702,23 (screen: 0)
  Geometry: 900x950

The next command prompts for the window of interest and returns the parent window which includes all the decorations and varies depending on the window theme in use.

$ xdotool selectwindow
25166060

$ xdotool getwindowgeometry 0x18000ec
Window 25166060
  Position: 700,0 (screen: 0)
  Geometry: 904x977

As you can see, it's a different window; the X position starts 2px to the left (702-2) and the total width is larger by 4px (900+2+2) because the right border is also 2px. Y is higher (above the top border, if any, and the title bar); height is larger because of all of that plus the bottom border.

wmctrl moves the parent window to the desired [X,Y] position of the child window; width and height are applied correctly to the child, as shown in the "before & after" below.

$ wmctrl -lG
0x04000040  0 702  23   900  950  KMatrix dave@KMatrix: test – Konsole

$ xdotool getwindowgeometry 0x18000ec   # (PARENT)
Window 25166060
  Position: 700,0 (screen: 0)
  Geometry: 904x977

$ xdotool getwindowgeometry 0x04000040  # (CHILD)
Window 67108928
  Position: 702,23 (screen: 0)
  Geometry: 900x950

$ wmctrl -ir 0x04000040 -e 0,702,23,900,950   # <----- "MOVE/RESIZE" *****

$ wmctrl -lG
0x04000040  0 704  46   900  950  KMatrix dave@KMatrix: test – Konsole

$ xdotool getwindowgeometry 0x18000ec   # (PARENT)
Window 25166060
  Position: 702,23 (screen: 0)    <----- Desired [X,Y] applied to parent
  Geometry: 904x977

$ xdotool getwindowgeometry 0x04000040  # (CHILD)
Window 67108928
  Position: 704,46 (screen: 0)
  Geometry: 900x950               <----- Desired [W,H] applied to child

Edit: additional info.

Desktop geometry, Viewport & Workarea

$ wmctrl -d    # (KDE)
0  * DG: 1680x1050  VP: 0,0  WA: 0,0 1680x1015  Desktop 1
$ xdotool -v
xdotool version 3.20140217.1

https://github.com/jordansissel/xdotool

Re: @Sneetsher tip in comments

$ xprop | grep FRAME
_KDE_NET_WM_FRAME_STRUT(CARDINAL) = 2, 2, 23, 4
_NET_FRAME_EXTENTS(CARDINAL) = 2, 2, 23, 4