get_size


Description:

public void get_size (out int width, out int height)

Obtains the current size of this.

If this is not visible on screen, this function return the size GTK+ will suggest to the window manager for the initial window size (but this is not reliably the same as the size the window manager will actually select). See: set_default_size.

Depending on the windowing system and the window manager constraints, the size returned by this function may not match the size set using resize; additionally, since resize may be implemented as an asynchronous operation, GTK+ cannot guarantee in any way that this code:

	// width and height are set elsewhere
gtk_window_resize (window, width, height);

int new_width, new_height;
gtk_window_get_size (window, &new_width, &new_height);

will result in `new_width` and `new_height` matching `width` and `height`, respectively.

This function will return the logical size of the Window, excluding the widgets used in client side decorations; there is, however, no guarantee that the result will be completely accurate because client side decoration may include widgets that depend on the user preferences and that may not be visibile at the time you call this function.

The dimensions returned by this function are suitable for being stored across sessions; use set_default_size to restore them when before showing the window.

To avoid potential race conditions, you should only call this function in response to a size change notification, for instance inside a handler for the size_allocate signal, or inside a handler for the configure_event signal:

static void
on_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
int new_width, new_height;

gtk_window_get_size (GTK_WINDOW (widget), &new_width, &new_height);

...
}

Note that, if you connect to the size_allocate signal, you should not use the dimensions of the Allocation passed to the signal handler, as the allocation may contain client side decorations added by GTK+, depending on the windowing system in use.

If you are getting a window size in order to position the window on the screen, you should, instead, simply set the window’s semantic type with set_type_hint, which allows the window manager to e.g. center dialogs. Also, if you set the transient parent of dialogs with set_transient_for window managers will often center the dialog over its parent window. It's much preferred to let the window manager handle these cases rather than doing it yourself, because all apps will behave consistently and according to user or system preferences, if the window manager handles it. Also, the window manager can take into account the size of the window decorations and border that it may add, and of which GTK+ has no knowledge. Additionally, positioning windows in global screen coordinates may not be allowed by the windowing system. For more information, see: set_position.

Parameters:

this

a Window

width

return location for width, or null

height

return location for height, or null




2022 vala-language.org