Package: gtk

Function gtk-window-position

Lambda List

gtk-window-position (window)

Arguments

window -- a gtk-window widget

Return Value

x -- an integer with the x coordinate of gravity determined reference point or nil
y -- an integer with the y coordinate of gravity determined reference point, or nil

Details

This function returns the position you need to pass to the gtk-window-move function to keep the window in its current position. This means that the meaning of the returned value varies with window gravity. See the gtk-window-move function for more details.

If you have not changed the window gravity, its gravity will be the :north-west value of the gdk-gravity enumeration. This means that the gtk-window-position function gets the position of the top-left corner of the window manager frame for the window. The gtk-window-move function sets the position of this same top-left corner.

The gtk-window-position function is not 100 % reliable because the X Window System does not specify a way to obtain the geometry of the decorations placed on a window by the window manager. Thus GTK is using a "best guess" that works with most window managers.

Moreover, nearly all window managers are historically broken with respect to their handling of window gravity. So moving a window to its current position as returned by the gtk-window-position function tends to result in moving the window slightly. Window managers are slowly getting better over time.

If a window has :static gravity the window manager frame is not relevant, and thus the gtk-window-position function will always produce accurate results. However you can not use static gravity to do things like place a window in a corner of the screen, because static gravity ignores the window manager decorations.

If you are saving and restoring your application's window positions, you should know that it is impossible for applications to do this without getting it somewhat wrong because applications do not have sufficient knowledge of window manager state. The Correct Mechanism is to support the session management protocol, see the "GnomeClient" object in the GNOME libraries for example, and allow the window manager to save your window sizes and positions.
 

See also

2021-9-12