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
Take a "snapshot" of the window arrangement and restore it
The script below can be used to get the current window positions of all "normal" windows (run with the argument -get
), or restore the last window arrangement (run with the argument -restore
).
As explained here, using wmctrl
i.c.w. Unity has some issues. If it is satisfying in your situation is to decide.
How to use
The script uses wmctrl
:
sudo apt-get install wmctrl
Then:
- Copy the script into an empty file, save it as
window_arrange.py
Run it by:
python3 /path/to/window_arrange.py -get
to "record" the current window arrangement, and
python3 /path/to/window_arrange.py -restore
to restore the last "recorded" window arrangement
The script:
#!/usr/bin/env python3
import subprocess
import os
import sys
wfile = os.environ["HOME"]+"/.windowlist"
arg = sys.argv[1]
def get(command):
return subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")
def check_window(w_id):
w_type = get("xprop -id "+w_id)
if " _NET_WM_WINDOW_TYPE_NORMAL" in w_type:
return True
else:
return False
def read_windows():
w_list = [l.split()[:6] for l in get("wmctrl -lG").splitlines()]
relevant = [(" ").join(w) for w in w_list if check_window(w[0]) == True]
with open(wfile, "wt") as out:
for item in relevant:
out.write(item+"\n")
def restore_windows():
try:
wlist = [l.split() for l in open(wfile).read().splitlines()]
except FileNotFoundError:
pass
else:
for w in wlist:
try:
cmd = "wmctrl -ir "+w[0]+" -e 0,"+(",").join(w[2:])
subprocess.Popen(["/bin/bash", "-c", cmd])
except:
pass
if arg == "-restore":
restore_windows()
elif arg == "-get":
read_windows()
Best Answer
I was just resizing my windows -
wmctrl
was the last command I ran!I ran:
and you ran:
My suggestion would be to lose the
""
around the sizes, and (maybe) add quotes to the window name:Just realised your program is a calculator. I doubt you can resize it - I can move mine but not shrink it or enlarge it.
This is standard with most calculator applications (and I wish it wasn't).
You said your main project is a Web Browser - it should work with that.