Get window position and size in python using Xlib

I need to find the position and size of the window, but I cannot figure out how to do this. For example, if I try:

id.get_geometry() # "id" is Xlib.display.Window 

I get something like this:

 data = {'height': 2540, 'width': 1440, 'depth': 24, 'y': 0, 'x': 0, 'border_width': 0 'root': <Xlib.display.Window 0x0000026a> 'sequence_number': 63} 

I need to find the position and size of the window, so my problem is: "y", "x" and "border_width" are always 0; even worse, "height" and "width" return without a window frame.

In this case, on my X-screen (its dimensions are 4400x2560) I expected x = 1280, y = 0, width = 1440, height = 2560.

In other words, I'm looking for the python equivalent for:

 #!/bin/bash id=$1 wmiface framePosition $id wmiface frameSize $id 

If you think that Xlib is not what I want, feel free to suggest a non-Xlib solution in python if it can take a window id as an argument (e.g. bash script above). The obvious workaround for using bash script output in python code doesn't seem right.

+4
source share
2 answers

You are probably using the reparenting window manager, and because of this window, id has zero x and y. Check the coordinates of the parent window (which is the window manager frame)

+1
source

Liss posted the following solution as a comment :

 from ewmh import EWMH ewmh = EWMH() def frame(client): frame = client while frame.query_tree().parent != ewmh.root: frame = frame.query_tree().parent return frame for client in ewmh.getClientList(): print frame(client).get_geometry() 

I copy it here because the answers must contain the actual answer as well as to prevent link rot .

0
source

Source: https://habr.com/ru/post/1438337/


All Articles