How to get window decoration sizes?

This has been discussed here:

I am looking for an easier solution than sending X events.

Does gtk have a way to handle this?


Hi Thiago! You might want to use gdk_window_get_frame_extents. As written in the stackoverflow post, together with gdk_window_get_origin and gtk_widget_get_allocation you can get the window decoration size.

it works only after window appeared on the screen. I need it before that - to calculate initial window position

If you need it at startup, first call gtk_widget_realize(window) so that the window is realized and the functions work, then, at the end, call gtk_widget_show_all(window) to show the window on the screen.

That said, It’s unclear whether gdk_window_get_frame_extents does also take in account decoration shadows or not. At least on Windows, it does not (with SSD)

Hi. Tried that, but it only works after map-event signal. Even if calling gtk_widget_realize().

1 Like

On X11, the decoration for a top-level is only ever added by the window manager after a MapEvent; it cannot be queried beforehand because it doesn’t exist until the top-level is mapped. Additionally, not every window manager is a reparenting window manager, so you might not know the size of the decoration at all.

In general, if you’re asking what’s the size of the decoration, you’re doing something dodgy to begin with.

I went with asking X for _NET_FRAME_EXTENTS (not sure it will work on Wayland).

I will try to work around this requirement and not have to deal with it.


It will only work for applications using X11 under XWayland, assuming the Wayland compositor can also act as a reparenting X11 window manager.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.