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.
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.
You can use
wmctrl -lG
to get a list of all open windows, in a table with the format:An example output could look like this:
I found
xwininfo -all
from https://unix.stackexchange.com/questions/14159/how-do-i-find-the-window-dimensions-and-position-accurately-including-decoration.It does work but I'm still open to more convenient solutions => a real-time GUI tool.
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.
One could try:
Assuming gnome-panel is ubuntu's toolbar's process name, but who knows.
(may require a
sudo apt-get install xdotool
)For an improvised GUI thing that one may want to further improve so to display just the bare essentials:
It will change the pointer to xprop's cross, then you click the window, and it will print xprop's info in a GTK dialog.
xwininfo and its advantages
The big problem with
wmctrl
andxdotool
is that those tools need to be installed - they aren't on Ubuntu by default. However, Ubuntu ships withxwininfo
. It is a simple tool that provides information about user-selected window.Simple usage would be to type in
xwininfo | awk '/Width/||/Height/'
(notice thatawk
is used for filtering the output) in terminal, and when your cursor changes tox
select any GUI window you like and it will display its info. For example:So the advantages are:
Taking xwininfo one step further - displaying properties of an active window
Of course if you have terminal open 24/7 like I do,
xwininfo
is all you need. Some users might prefer having a keyboard shortcut. The script below (which is intended to be bound to a keyboard shortcut) allows you to display a graphical popup with information about your currently active window. As can be seen in the screenshot, it displays window title,width and height info.Under the hood this doesn't do anything particularly spectacular. It uses information from
dbus
service andxwininfo
and puts it into simple popup. The source code is below. Remember, standard scripting rules apply: ensure it has executable permissions withchmod +x
and when binding to keyboard shortcut you give full path to the script file as command.Using Unity's top panel indicator for information.
When writing my answer, I've realized that this would be a very useful feature to incorporate into one of my existing projects - the Ayatana Indicator. This indicator allows showing whole range of information about GUI windows. Currently is still under active development. The geometry info feature has been added to the github repository and is on the way into my personal PPA. And of course, it uses
xwininfo
although in slightly different manner.