Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GTK window, how to get window decoration sizes?

Tags:

window

widget

gtk

I am looking for an equivalent of AdjustWindowRect function that allows to get widths/heights of window caption and borders.

Do we have this functionality in GTK 3 at all? Seems like not. I've looked through all gtk_window_xxx, gtk_widget_xxx and gdk_window_xxx* functions...

Update:

In principle I am able to determine window-chrome/decoration dimensions as a delta of gdk_window_get_frame_extents() and gtk_widget_get_allocation() / gdk_window_get_origin() but

  1. it works only after window appeared on the screen. I need it before that - to calculate initial window position.
  2. it is really a hack.
like image 895
c-smile Avatar asked Mar 10 '16 05:03

c-smile


1 Answers

It's up to Window Manager to decide. You can request it by sending a message _NET_REQUEST_FRAME_EXTENTS as explained in the specification of EWMH (Extended Window Manager Hints):

_NET_REQUEST_FRAME_EXTENTS
  window = window for which to set _NET_FRAME_EXTENTS
  message_type = _NET_REQUEST_FRAME_EXTENTS

A Client whose window has not yet been mapped can request of the Window Manager an estimate of the frame extents it will be given upon mapping. To retrieve such an estimate, the Client MUST send a _NET_REQUEST_FRAME_EXTENTS message to the root window. The Window Manager MUST respond by estimating the prospective frame extents and setting the window's _NET_FRAME_EXTENTS property accordingly. The Client MUST handle the resulting _NET_FRAME_EXTENTS PropertyNotify event. So that the Window Manager has a good basis for estimation, the Client MUST set any window properties it intends to set before sending this message. The Client MUST be able to cope with imperfect estimates.

Rationale: A client cannot calculate the dimensions of its window's frame before the window is mapped, but some toolkits need this information. Asking the window manager for an estimate of the extents is a workable solution. The estimate may depend on the current theme, font sizes or other window properties. The client can track changes to the frame's dimensions by listening for _NET_FRAME_EXTENTS PropertyNotify events.

https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472648576

So, in two words, you send a _NET_REQUEST_FRAME_EXTENTS msg to WM (to the root window - it's gdk_get_default_root_window() in case of gdk), then wait for the reply (_NET_FRAME_EXTENTS PropertyNotify), and get the desired data from your window's _NET_FRAME_EXTENTS property.

like image 101
Maxim Yanchenko Avatar answered Sep 28 '22 22:09

Maxim Yanchenko