How can I get ids and geometry (size + position) of all top level windows with xdotool?

988 views
Skip to first unread message

Aaron Digulla

unread,
Jan 8, 2013, 4:37:47 AM1/8/13
to xdotoo...@googlegroups.com
I want to be able to save/restore all top level windows on my desktop. How would I do that with xdotool?

I tried

xdotool search --class InputOutput

but that doesn't find anything even though xwininfo tells me:

xwininfo -id 0x3c002ee

xwininfo: Window id: 0x3c002ee "Google Chrome"

  Absolute upper-left X:  -100
  Absolute upper-left Y:  -100
  Relative upper-left X:  -100
  Relative upper-left Y:  -100
  Width: 10
  Height: 10
  Depth: 0
  Visual: 0x21
  Visual Class: TrueColor
  Border width: 0
  Class: InputOnly

Maybe you can add a command which gives me the window IDs of all children of a certain window?

Anthony Thyssen

unread,
Jan 8, 2013, 11:29:23 PM1/8/13
to xdotoo...@googlegroups.com, adig...@gmail.com
The "xwininfo" command can do that too.
use -tree

however it can be tricky to use especially with some window managers.

With my window manager I have to go up one level then go down to find
the sub-windows (widgets) within the client itself, and not simply get
the window manager's overlay.


Anthony Thyssen ( System Programmer ) <A.Th...@griffith.edu.au>
--------------------------------------------------------------------------
Nothing Gives a Damn. Life is far too brief, existance is meaningless
and the universe has no purpose. -- Dean Alan Foster, "Glory Lane"
--------------------------------------------------------------------------
Anthony's Castle http://www.ict.griffith.edu.au/anthony/

Nazri Ramliy

unread,
Jan 9, 2013, 1:23:57 AM1/9/13
to adig...@gmail.com, xdotool-users
On Tue, Jan 8, 2013 at 5:37 PM, Aaron Digulla <adig...@gmail.com> wrote:
> I want to be able to save/restore all top level windows on my desktop. How
> would I do that with xdotool?

You might be able to do what you want using xprop:

xprop -root|grep '_NET_CLIENT_LIST_STACKING(WINDOW)'
_NET_CLIENT_LIST_STACKING(WINDOW): window id # 0x3c0008e, 0x2400024,
0x3600024, 0x3800024, 0x2800024

It gives you the window ids which you can then use in your script to
save/restore their geometries.

nazri

Aaron Digulla

unread,
Jan 9, 2013, 7:52:04 AM1/9/13
to Nazri Ramliy, xdotool-users
The output of this gem looks promising:

for id in $(xprop -root|grep '_NET_CLIENT_LIST_STACKING(WINDOW)'|cut
"-d#" -f2|sed -e 's/,//g') ; do xwininfo -id $id | gawk '/^xwininfo/ {
id=$4; title=$0; gsub(/^[^"]+/, "", title);} /-geometry/ { geo=$2; }
END { print id" "geo" "title }' ; done

I keep the title to make it easier to debug problems in the script.

2013/1/9 Nazri Ramliy <ayie...@gmail.com>:
--
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://www.pdark.de/

Anthony Thyssen

unread,
Jan 9, 2013, 9:42:27 PM1/9/13
to xdotoo...@googlegroups.com, adig...@gmail.com
On Wed, 9 Jan 2013 13:52:04 +0100
Aaron Digulla <adig...@gmail.com> wrote:
| The output of this gem looks promising:
|
| for id in $(xprop -root|grep '_NET_CLIENT_LIST_STACKING(WINDOW)'|cut
| "-d#" -f2|sed -e 's/,//g') ; do xwininfo -id $id | gawk '/^xwininfo/ {
| id=$4; title=$0; gsub(/^[^"]+/, "", title);} /-geometry/ { geo=$2; }
| END { print id" "geo" "title }' ; done
|
| I keep the title to make it easier to debug problems in the script.
|
| 2013/1/9 Nazri Ramliy <ayie...@gmail.com>:
| > On Tue, Jan 8, 2013 at 5:37 PM, Aaron Digulla <adig...@gmail.com> wrote:
| >> I want to be able to save/restore all top level windows on my desktop. How
| >> would I do that with xdotool?
| >
| > You might be able to do what you want using xprop:
| >
| > xprop -root|grep '_NET_CLIENT_LIST_STACKING(WINDOW)'
| > _NET_CLIENT_LIST_STACKING(WINDOW): window id # 0x3c0008e, 0x2400024,
| > 0x3600024, 0x3800024, 0x2800024
| >
| > It gives you the window ids which you can then use in your script to
| > save/restore their geometries.
| >
| > nazri
|
|
|


You may also like to look at my basic notes on X window ID handling
http://www.ict.griffith.edu.au/anthony/info/X/WindowID.hints

Especially note the section on 'Search Speed' which shows some very
large (order of magnitude) differences in window searches.

NOTE: the xprop search only lists the active (stacking) windows
on my current display it listed 11 windows, as did "wmctrl -l"
but "xlsclients" listed 16 windows


xlsclients -l | perl -e '
$EOR = "Window ";
local $/ = "\n$EOR";
while(<>) {
s/\A/$EOR/ unless $.==1; # clean up start of record
s/$EOR\Z//; # clean up end of record.
print "--- $. ---\n$_";
}
print "--- Total $. Windows ---\n";
'



Anthony Thyssen ( System Programmer ) <A.Th...@griffith.edu.au>
--------------------------------------------------------------------------
"You are now leaving the emergency airlock!
Thank you for observing all safety precautions." announced the computer.
"Yoh Ho Hoo" as Selby was ejected into space without a jetpack.
-- Classic SciFi Movie "DarkStar", 1974
Reply all
Reply to author
Forward
0 new messages