I need a tool to get the width and height of an arbitrary window.
Ideally, that tool would deduct the size of the Ubuntu's menu bar.
layoutsoftware-recommendationwindow
I need a tool to get the width and height of an arbitrary window.
Ideally, that tool would deduct the size of the Ubuntu's menu bar.
Best Answer
From your own answer, I understand you are looking for a convenient GUI tool, so:
Small GUI tool to get both the net size and the real size of a window (dynamically updated)
As explained further below in "Explanation", both
wmctrl
andxdotool
return a slightly incorrect windowsize.The script (indicator) below will show both the "real" size and the net size of a window in the panel.
The script
How to use
The script needs xdotool to be installed:
Copy the script into an empty file, save it as
getwindowsize.py
Test- run the script from a terminal window by the command:
The script picks the focussed window to dynamically show the net windowsize (as in the output of both
wmctrl
andxdotool
) and the real window size, including decorators etc.If you close the targeted window, the indicator shows a message:
If all works fine, add it to a shortcut key: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
Explanation
The window size, as it is displayed by both wmctrl and xdotool
...is slightly incorrect
You mention:
Ideally, that tool would deduct the size of the Ubuntu's menu bar
The complete story is that both
wmctrl -lG
andxdotool getwindowgeometry
return the size of the window without menu bar, or, as it is explained in this 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)
How to get the correct, "real" size
To get the information correctly, we can run
This will output like:
Here we get the values we need to add to the window's size, as output from
wmctrl
andxdotool
, to the left, right, top and bottom of the window.In other words, in this case, if a
wmctrl
shows a size of 200x100, the real size is 200x128.Note
As suggested by OP, the user can also pick a window after the indicator was started, by replacing:
by:
In the script, either one of these lines can be uncommented.