[Xcb] how to get window dimensions?

Uli Schlachter psychon at znc.in
Sat Jul 4 06:43:54 PDT 2015


Hi,

Am 03.07.2015 um 11:30 schrieb Cosmin Apreutesei:
> Is there a reliable way to get the inner and outer rectangle of a top
> level window? (IOW frame and client rectangle).

as was already mentioned by Sam in his reply, EWMH specifies _NET_FRAME_EXTENTS
for this. Quoting the spec:

  _NET_FRAME_EXTENTS, left, right, top, bottom, CARDINAL[4]/32

  The Window Manager MUST set _NET_FRAME_EXTENTS to the extents of the window's
  frame. left, right, top and bottom are widths of the respective borders added
  by the Window Manager.

(Note that nothing requires the WM to implement EWMH)

> Here's what I tried:
> 
> - xcb_get_geometry always returns the initial dimensions even after
> the window gets resized (what gives?)

That makes no sense at all. Do you have a small example on this?

> - I figured I would call xcb_query_tree repeatedly until I find the
> window's frame window - is this the way to do it?

Well, if your window is reparented into window A which itself is in parent B and
which then is part of the root window, whose window extents do you want to use?

> I figure ICCCM/EWMH
> should provide this but couldn't find anything. Is there any other
> standard/non-standard for this?

EWMH specifies _NET_FRAME_EXTENTS, see above.

> Anyway that doesn't work with
> compiz/ubuntu10 because xcb_query_tree reports the client window as
> having root = parent (under normal ubuntu wm the window gets properly
> reparented).

Nothing requires a WM to reparent windows, but I would expect compiz to be
reparenting. Are you sure you do this test after the WM "did its job"?

> - xcb_translate_coordinates() seemed to be the only reliable way to
> get root-based coords[1] in 2007 -- is this still the case? I.e. is
> XCB_CONFIGURE_NOTIFY non-standard with WMs?

The X11 server will send you a ConfigureNotify on resize and ICCCM § 4.1.5,
4.2.3, 4.2.4 requires the WM to send a synthetic ConfigureNotify on moves.

§ 4.1.5 has this advice / algorithm:

Clients cannot distinguish between the case where a top-level window is resized
and moved from the case where the window is resized but not moved, since a real
ConfigureNotify event will be received in both cases. Clients that are concerned
with keeping track of the absolute position of a top-level window should keep a
piece of state indicating whether they are certain of its position. Upon receipt
of a real ConfigureNotify event on the top-level window, the client should note
that the position is unknown. Upon receipt of a synthetic ConfigureNotify event,
the client should note the position as known, using the position in this event.
If the client receives a KeyPress , KeyRelease , ButtonPress , ButtonRelease ,
MotionNotify , EnterNotify , or LeaveNotify event on the window (or on any
descendant), the client can deduce the top-level window's position from the
difference between the (event-x, event-y) and (root-x, root-y) coordinates in
these events. Only when the position is unknown does the client need to use the
TranslateCoordinates request to find the position of a top-level window.

[...]
> [1] http://fixunix.com/xwindows/91652-finding-position-top-level-windows.html

This is from 2009, not 2007. And the first post already shows "I have not read
the relevant part of ICCCM" (it says you which ConfigureNotify events have
position relative to parent window and which in root coordinates). I did not
read more than this and I doubt your claim that this was the only reliable way
in 2007. All the relevant specs are way older.

Cheers,
Uli
-- 
A normal person is just someone you don't know well enough yet.
 - Nettie Wiebe


More information about the Xcb mailing list