GtkWindow

GtkWindow — Toplevel which can contain other widgets

Functions

GtkWidget * gtk_window_new ()
void gtk_window_destroy ()
GtkWidget * gtk_window_get_child ()
void gtk_window_set_child ()
void gtk_window_set_title ()
void gtk_window_set_resizable ()
gboolean gtk_window_get_resizable ()
void gtk_window_set_modal ()
void gtk_window_set_default_size ()
void gtk_window_set_hide_on_close ()
gboolean gtk_window_get_hide_on_close ()
void gtk_window_set_transient_for ()
void gtk_window_set_destroy_with_parent ()
void gtk_window_set_display ()
gboolean gtk_window_is_active ()
gboolean gtk_window_is_maximized ()
GListModel * gtk_window_get_toplevels ()
GList * gtk_window_list_toplevels ()
GtkWidget * gtk_window_get_focus ()
void gtk_window_set_focus ()
GtkWidget * gtk_window_get_default_widget ()
void gtk_window_set_default_widget ()
void gtk_window_present ()
void gtk_window_present_with_time ()
void gtk_window_close ()
void gtk_window_minimize ()
void gtk_window_unminimize ()
void gtk_window_maximize ()
void gtk_window_unmaximize ()
void gtk_window_fullscreen ()
void gtk_window_fullscreen_on_monitor ()
void gtk_window_unfullscreen ()
void gtk_window_set_decorated ()
void gtk_window_set_deletable ()
void gtk_window_set_startup_id ()
gboolean gtk_window_get_decorated ()
gboolean gtk_window_get_deletable ()
const gchar * gtk_window_get_default_icon_name ()
void gtk_window_get_default_size ()
gboolean gtk_window_get_destroy_with_parent ()
const gchar * gtk_window_get_icon_name ()
gboolean gtk_window_get_modal ()
void gtk_window_get_size ()
const gchar * gtk_window_get_title ()
GtkWindow * gtk_window_get_transient_for ()
GtkWindowGroup * gtk_window_get_group ()
gboolean gtk_window_has_group ()
void gtk_window_resize ()
void gtk_window_set_default_icon_name ()
void gtk_window_set_icon_name ()
void gtk_window_set_auto_startup_notification ()
gboolean gtk_window_get_mnemonics_visible ()
void gtk_window_set_mnemonics_visible ()
gboolean gtk_window_get_focus_visible ()
void gtk_window_set_focus_visible ()
GtkApplication * gtk_window_get_application ()
void gtk_window_set_application ()
void gtk_window_set_titlebar ()
GtkWidget * gtk_window_get_titlebar ()
void gtk_window_set_interactive_debugging ()

Properties

GtkApplication * application Read / Write
GtkWidget * child Read / Write
gboolean decorated Read / Write
gint default-height Read / Write
GtkWidget * default-widget Read / Write
gint default-width Read / Write
gboolean deletable Read / Write
gboolean destroy-with-parent Read / Write
GdkDisplay * display Read / Write
gboolean focus-visible Read / Write
GtkWidget * focus-widget Read / Write
gboolean hide-on-close Read / Write
gchar * icon-name Read / Write
gboolean is-active Read
gboolean is-maximized Read
gboolean mnemonics-visible Read / Write
gboolean modal Read / Write
gboolean resizable Read / Write
gchar * startup-id Write
gchar * title Read / Write
GtkWindow * transient-for Read / Write / Construct

Signals

void activate-default Action
void activate-focus Action
gboolean close-request Run Last
gboolean enable-debugging Action
void keys-changed Run First

Actions

  window.close  
  window.toggle-maximized  
  window.minimize  
  default.activate  

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GtkWidget
            ╰── GtkWindow
                ├── GtkDialog
                ├── GtkApplicationWindow
                ├── GtkAssistant
                ╰── GtkShortcutsWindow

Implemented Interfaces

GtkWindow implements AtkImplementorIface, GtkBuildable, GtkConstraintTarget, GtkNative, GtkShortcutManager and GtkRoot.

Includes

#include <gtk/gtk.h>

Description

A GtkWindow is a toplevel window which can contain other widgets. Windows normally have decorations that are under the control of the windowing system and allow the user to manipulate the window (resize it, move it, close it,...).

GtkWindow as GtkBuildable

The GtkWindow implementation of the GtkBuildable interface supports a custom <accel-groups> element, which supports any number of <group> elements representing the GtkAccelGroup objects you want to add to your window (synonymous with gtk_window_add_accel_group().

An example of a UI definition fragment with accel groups:

1
2
3
4
5
6
7
8
9
<object class="GtkWindow">
  <accel-groups>
    <group name="accelgroup1"/>
  </accel-groups>
</object>

...

<object class="GtkAccelGroup" id="accelgroup1"/>

The GtkWindow implementation of the GtkBuildable interface supports setting a child as the titlebar by specifying “titlebar” as the “type” attribute of a <child> element.


CSS nodes

1
2
3
window.background
├── <titlebar child>.titlebar [.default-decoration]
╰── <child>

GtkWindow has a main CSS node with name window and style class .background.

Style classes that are typically used with the main CSS node are .csd (when client-side decorations are in use), .solid-csd (for client-side decorations without invisible borders), .ssd (used by mutter when rendering server-side decorations). GtkWindow also represents window states with the following style classes on the main node: .tiled, .maximized, .fullscreen. Specialized types of window often add their own discriminating style classes, such as .popup or .tooltip.

Generally, some CSS properties don't make sense on the toplevel window node, such as margins or padding. When client-side decorations without invisible borders are in use (i.e. the .solid-csd style class is added to the main window node), the CSS border of the toplevel window is used for resize drags. In the .csd case, the shadow area outside of the window can be used to resize it.

GtkWindow adds the .titlebar and .default-decoration style classes to the widget that is added as a titlebar child.

Functions

gtk_window_new ()

GtkWidget *
gtk_window_new (void);

Creates a new GtkWindow, which is a toplevel window that can contain other widgets.

To get an undecorated window (no window borders), use gtk_window_set_decorated().

All top-level windows created by gtk_window_new() are stored in an internal top-level window list. This list can be obtained from gtk_window_list_toplevels(). Due to Gtk+ keeping a reference to the window internally, gtk_window_new() does not return a reference to the caller.

To delete a GtkWindow, call gtk_window_destroy().

Returns

a new GtkWindow.


gtk_window_destroy ()

void
gtk_window_destroy (GtkWindow *window);

Drop the internal reference GTK holds on toplevel windows.

Parameters

window

The window to destroy

 

gtk_window_get_child ()

GtkWidget *
gtk_window_get_child (GtkWindow *window);

Gets the child widget of window .

Parameters

window

a GtkWindow

 

Returns

the child widget of window .

[nullable][transfer none]


gtk_window_set_child ()

void
gtk_window_set_child (GtkWindow *window,
                      GtkWidget *child);

Sets the child widget of window .

Parameters

window

a GtkWindow

 

child

the child widget.

[allow-none]

gtk_window_set_title ()

void
gtk_window_set_title (GtkWindow *window,
                      const gchar *title);

Sets the title of the GtkWindow. The title of a window will be displayed in its title bar; on the X Window System, the title bar is rendered by the window manager, so exactly how the title appears to users may vary according to a user’s exact configuration. The title should help a user distinguish this window from other windows they may have open. A good title might include the application name and current document filename, for example.

Parameters

window

a GtkWindow

 

title

title of the window

 

gtk_window_set_resizable ()

void
gtk_window_set_resizable (GtkWindow *window,
                          gboolean resizable);

Sets whether the user can resize a window. Windows are user resizable by default.

Parameters

window

a GtkWindow

 

resizable

TRUE if the user can resize this window

 

gtk_window_get_resizable ()

gboolean
gtk_window_get_resizable (GtkWindow *window);

Gets the value set by gtk_window_set_resizable().

Parameters

window

a GtkWindow

 

Returns

TRUE if the user can resize the window


gtk_window_set_modal ()

void
gtk_window_set_modal (GtkWindow *window,
                      gboolean modal);

Sets a window modal or non-modal. Modal windows prevent interaction with other windows in the same application. To keep modal dialogs on top of main application windows, use gtk_window_set_transient_for() to make the dialog transient for the parent; most window managers will then disallow lowering the dialog below the parent.

Parameters

window

a GtkWindow

 

modal

whether the window is modal

 

gtk_window_set_default_size ()

void
gtk_window_set_default_size (GtkWindow *window,
                             gint width,
                             gint height);

Sets the default size of a window. If the window’s “natural” size (its size request) is larger than the default, the default will be ignored.

Unlike gtk_widget_set_size_request(), which sets a size request for a widget and thus would keep users from shrinking the window, this function only sets the initial size, just as if the user had resized the window themselves. Users can still shrink the window again as they normally would. Setting a default size of -1 means to use the “natural” default size (the size request of the window).

For some uses, gtk_window_resize() is a more appropriate function. gtk_window_resize() changes the current size of the window, rather than the size to be used on initial display. gtk_window_resize() always affects the window itself, not the geometry widget.

The default size of a window only affects the first time a window is shown; if a window is hidden and re-shown, it will remember the size it had prior to hiding, rather than using the default size.

Windows can’t actually be 0x0 in size, they must be at least 1x1, but passing 0 for width and height is OK, resulting in a 1x1 default size.

If you use this function to reestablish a previously saved window size, note that the appropriate size to save is the one returned by gtk_window_get_size(). Using the window allocation directly will not work in all circumstances and can lead to growing or shrinking windows.

Parameters

window

a GtkWindow

 

width

width in pixels, or -1 to unset the default width

 

height

height in pixels, or -1 to unset the default height

 

gtk_window_set_hide_on_close ()

void
gtk_window_set_hide_on_close (GtkWindow *window,
                              gboolean setting);

If setting is TRUE, then clicking the close button on the window will not destroy it, but only hide it.

Parameters

window

a GtkWindow

 

setting

whether to hide the window when it is closed

 

gtk_window_get_hide_on_close ()

gboolean
gtk_window_get_hide_on_close (GtkWindow *window);

Returns whether the window will be hidden when the close button is clicked.

Parameters

window

a GtkWindow

 

Returns

TRUE if the window will be hidden


gtk_window_set_transient_for ()

void
gtk_window_set_transient_for (GtkWindow *window,
                              GtkWindow *parent);

Dialog windows should be set transient for the main application window they were spawned from. This allows window managers to e.g. keep the dialog on top of the main window, or center the dialog over the main window. gtk_dialog_new_with_buttons() and other convenience functions in GTK+ will sometimes call gtk_window_set_transient_for() on your behalf.

Passing NULL for parent unsets the current transient window.

On Windows, this function puts the child window on top of the parent, much as the window manager would have done on X.

Parameters

window

a GtkWindow

 

parent

parent window, or NULL.

[allow-none]

gtk_window_set_destroy_with_parent ()

void
gtk_window_set_destroy_with_parent (GtkWindow *window,
                                    gboolean setting);

If setting is TRUE, then destroying the transient parent of window will also destroy window itself. This is useful for dialogs that shouldn’t persist beyond the lifetime of the main window they're associated with, for example.

Parameters

window

a GtkWindow

 

setting

whether to destroy window with its transient parent

 

gtk_window_set_display ()

void
gtk_window_set_display (GtkWindow *window,
                        GdkDisplay *display);

Sets the GdkDisplay where the window is displayed; if the window is already mapped, it will be unmapped, and then remapped on the new display.

Parameters

window

a GtkWindow.

 

display

a GdkDisplay.

 

gtk_window_is_active ()

gboolean
gtk_window_is_active (GtkWindow *window);

Returns whether the window is part of the current active toplevel. (That is, the toplevel window receiving keystrokes.) The return value is TRUE if the window is active toplevel itself. You might use this function if you wanted to draw a widget differently in an active window from a widget in an inactive window.

Parameters

window

a GtkWindow

 

Returns

TRUE if the window part of the current active window.


gtk_window_is_maximized ()

gboolean
gtk_window_is_maximized (GtkWindow *window);

Retrieves the current maximized state of window .

Note that since maximization is ultimately handled by the window manager and happens asynchronously to an application request, you shouldn’t assume the return value of this function changing immediately (or at all), as an effect of calling gtk_window_maximize() or gtk_window_unmaximize().

Parameters

window

a GtkWindow

 

Returns

whether the window has a maximized state.


gtk_window_get_toplevels ()

GListModel *
gtk_window_get_toplevels (void);

Returns a list of all existing toplevel windows.

If you want to iterate through the list and perform actions involving callbacks that might destroy the widgets or add new ones, be aware that the list of toplevels will change and emit the "items-changed" signal.

Returns

the list of toplevel widgets.

[transfer none][attributes element-type=GtkWindow]


gtk_window_list_toplevels ()

GList *
gtk_window_list_toplevels (void);

Returns a list of all existing toplevel windows. The widgets in the list are not individually referenced. If you want to iterate through the list and perform actions involving callbacks that might destroy the widgets, you must call g_list_foreach (result, (GFunc)g_object_ref, NULL) first, and then unref all the widgets afterwards.

Returns

list of toplevel widgets.

[element-type GtkWidget][transfer container]


gtk_window_get_focus ()

GtkWidget *
gtk_window_get_focus (GtkWindow *window);

Retrieves the current focused widget within the window. Note that this is the widget that would have the focus if the toplevel window focused; if the toplevel window is not focused then gtk_widget_has_focus (widget) will not be TRUE for the widget.

Parameters

window

a GtkWindow

 

Returns

the currently focused widget, or NULL if there is none.

[nullable][transfer none]


gtk_window_set_focus ()

void
gtk_window_set_focus (GtkWindow *window,
                      GtkWidget *focus);

If focus is not the current focus widget, and is focusable, sets it as the focus widget for the window. If focus is NULL, unsets the focus widget for this window. To set the focus to a particular widget in the toplevel, it is usually more convenient to use gtk_widget_grab_focus() instead of this function.

Parameters

window

a GtkWindow

 

focus

widget to be the new focus widget, or NULL to unset any focus widget for the toplevel window.

[allow-none]

gtk_window_get_default_widget ()

GtkWidget *
gtk_window_get_default_widget (GtkWindow *window);

Returns the default widget for window . See gtk_window_set_default() for more details.

Parameters

window

a GtkWindow

 

Returns

the default widget, or NULL if there is none.

[nullable][transfer none]


gtk_window_set_default_widget ()

void
gtk_window_set_default_widget (GtkWindow *window,
                               GtkWidget *default_widget);

The default widget is the widget that’s activated when the user presses Enter in a dialog (for example). This function sets or unsets the default widget for a GtkWindow.

Parameters

window

a GtkWindow

 

default_widget

widget to be the default, or NULL to unset the default widget for the toplevel.

[allow-none]

gtk_window_present ()

void
gtk_window_present (GtkWindow *window);

Presents a window to the user. This function should not be used as when it is called, it is too late to gather a valid timestamp to allow focus stealing prevention to work correctly.

Parameters

window

a GtkWindow

 

gtk_window_present_with_time ()

void
gtk_window_present_with_time (GtkWindow *window,
                              guint32 timestamp);

Presents a window to the user. This may mean raising the window in the stacking order, unminimizing it, moving it to the current desktop, and/or giving it the keyboard focus, possibly dependent on the user’s platform, window manager, and preferences.

If window is hidden, this function calls gtk_widget_show() as well.

This function should be used when the user tries to open a window that’s already open. Say for example the preferences dialog is currently open, and the user chooses Preferences from the menu a second time; use gtk_window_present() to move the already-open dialog where the user can see it.

Presents a window to the user in response to a user interaction. The timestamp should be gathered when the window was requested to be shown (when clicking a link for example), rather than once the window is ready to be shown.

Parameters

window

a GtkWindow

 

timestamp

the timestamp of the user interaction (typically a button or key press event) which triggered this call

 

gtk_window_close ()

void
gtk_window_close (GtkWindow *window);

Requests that the window is closed, similar to what happens when a window manager close button is clicked.

This function can be used with close buttons in custom titlebars.

Parameters

window

a GtkWindow

 

gtk_window_minimize ()

void
gtk_window_minimize (GtkWindow *window);

Asks to minimize the specified window .

Note that you shouldn’t assume the window is definitely minimized afterward, because the windowing system might not support this functionality; other entities (e.g. the user or the window manager) could unminimize it again, or there may not be a window manager in which case minimization isn’t possible, etc.

It’s permitted to call this function before showing a window, in which case the window will be minimized before it ever appears onscreen.

You can track result of this operation via the “state” property.

Parameters

window

a GtkWindow

 

gtk_window_unminimize ()

void
gtk_window_unminimize (GtkWindow *window);

Asks to unminimize the specified window .

Note that you shouldn’t assume the window is definitely unminimized afterward, because the windowing system might not support this functionality; other entities (e.g. the user or the window manager) could minimize it again, or there may not be a window manager in which case minimization isn’t possible, etc.

You can track result of this operation via the “state” property.

Parameters

window

a GtkWindow

 

gtk_window_maximize ()

void
gtk_window_maximize (GtkWindow *window);

Asks to maximize window , so that it becomes full-screen. Note that you shouldn’t assume the window is definitely maximized afterward, because other entities (e.g. the user or window manager) could unmaximize it again, and not all window managers support maximization. But normally the window will end up maximized. Just don’t write code that crashes if not.

It’s permitted to call this function before showing a window, in which case the window will be maximized when it appears onscreen initially.

You can track the result of this operation via the “state” property, or by listening to notifications on the “is-maximized” property.

Parameters

window

a GtkWindow

 

gtk_window_unmaximize ()

void
gtk_window_unmaximize (GtkWindow *window);

Asks to unmaximize window . Note that you shouldn’t assume the window is definitely unmaximized afterward, because other entities (e.g. the user or window manager) could maximize it again, and not all window managers honor requests to unmaximize. But normally the window will end up unmaximized. Just don’t write code that crashes if not.

You can track the result of this operation via the “state” property, or by listening to notifications on the “is-maximized” property.

Parameters

window

a GtkWindow

 

gtk_window_fullscreen ()

void
gtk_window_fullscreen (GtkWindow *window);

Asks to place window in the fullscreen state. Note that you shouldn’t assume the window is definitely full screen afterward, because other entities (e.g. the user or window manager) could unfullscreen it again, and not all window managers honor requests to fullscreen windows. But normally the window will end up fullscreen. Just don’t write code that crashes if not.

You can track iconification via the “state” property

Parameters

window

a GtkWindow

 

gtk_window_fullscreen_on_monitor ()

void
gtk_window_fullscreen_on_monitor (GtkWindow *window,
                                  GdkMonitor *monitor);

Asks to place window in the fullscreen state. Note that you shouldn't assume the window is definitely full screen afterward.

You can track iconification via the “state” property

Parameters

window

a GtkWindow

 

monitor

which monitor to go fullscreen on

 

gtk_window_unfullscreen ()

void
gtk_window_unfullscreen (GtkWindow *window);

Asks to toggle off the fullscreen state for window . Note that you shouldn’t assume the window is definitely not full screen afterward, because other entities (e.g. the user or window manager) could fullscreen it again, and not all window managers honor requests to unfullscreen windows. But normally the window will end up restored to its normal state. Just don’t write code that crashes if not.

You can track iconification via the “state” property

Parameters

window

a GtkWindow

 

gtk_window_set_decorated ()

void
gtk_window_set_decorated (GtkWindow *window,
                          gboolean setting);

By default, windows are decorated with a title bar, resize controls, etc. Some window managers allow GTK+ to disable these decorations, creating a borderless window. If you set the decorated property to FALSE using this function, GTK+ will do its best to convince the window manager not to decorate the window. Depending on the system, this function may not have any effect when called on a window that is already visible, so you should call it before calling gtk_widget_show().

On Windows, this function always works, since there’s no window manager policy involved.

Parameters

window

a GtkWindow

 

setting

TRUE to decorate the window

 

gtk_window_set_deletable ()

void
gtk_window_set_deletable (GtkWindow *window,
                          gboolean setting);

By default, windows have a close button in the window frame. Some window managers allow GTK+ to disable this button. If you set the deletable property to FALSE using this function, GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible, so you should call it before calling gtk_widget_show().

On Windows, this function always works, since there’s no window manager policy involved.

Parameters

window

a GtkWindow

 

setting

TRUE to decorate the window as deletable

 

gtk_window_set_startup_id ()

void
gtk_window_set_startup_id (GtkWindow *window,
                           const gchar *startup_id);

Startup notification identifiers are used by desktop environment to track application startup, to provide user feedback and other features. This function changes the corresponding property on the underlying GdkSurface. Normally, startup identifier is managed automatically and you should only use this function in special cases like transferring focus from other processes. You should use this function before calling gtk_window_present() or any equivalent function generating a window map event.

This function is only useful on X11, not with other GTK+ targets.

Parameters

window

a GtkWindow

 

startup_id

a string with startup-notification identifier

 

gtk_window_get_decorated ()

gboolean
gtk_window_get_decorated (GtkWindow *window);

Returns whether the window has been set to have decorations such as a title bar via gtk_window_set_decorated().

Parameters

window

a GtkWindow

 

Returns

TRUE if the window has been set to have decorations


gtk_window_get_deletable ()

gboolean
gtk_window_get_deletable (GtkWindow *window);

Returns whether the window has been set to have a close button via gtk_window_set_deletable().

Parameters

window

a GtkWindow

 

Returns

TRUE if the window has been set to have a close button


gtk_window_get_default_icon_name ()

const gchar *
gtk_window_get_default_icon_name (void);

Returns the fallback icon name for windows that has been set with gtk_window_set_default_icon_name(). The returned string is owned by GTK+ and should not be modified. It is only valid until the next call to gtk_window_set_default_icon_name().

Returns

the fallback icon name for windows


gtk_window_get_default_size ()

void
gtk_window_get_default_size (GtkWindow *window,
                             gint *width,
                             gint *height);

Gets the default size of the window. A value of -1 for the width or height indicates that a default size has not been explicitly set for that dimension, so the “natural” size of the window will be used.

Parameters

window

a GtkWindow

 

width

location to store the default width, or NULL.

[out][allow-none]

height

location to store the default height, or NULL.

[out][allow-none]

gtk_window_get_destroy_with_parent ()

gboolean
gtk_window_get_destroy_with_parent (GtkWindow *window);

Returns whether the window will be destroyed with its transient parent. See gtk_window_set_destroy_with_parent().

Parameters

window

a GtkWindow

 

Returns

TRUE if the window will be destroyed with its transient parent.


gtk_window_get_icon_name ()

const gchar *
gtk_window_get_icon_name (GtkWindow *window);

Returns the name of the themed icon for the window, see gtk_window_set_icon_name().

Parameters

window

a GtkWindow

 

Returns

the icon name or NULL if the window has no themed icon.

[nullable]


gtk_window_get_modal ()

gboolean
gtk_window_get_modal (GtkWindow *window);

Returns whether the window is modal. See gtk_window_set_modal().

Parameters

window

a GtkWindow

 

Returns

TRUE if the window is set to be modal and establishes a grab when shown


gtk_window_get_size ()

void
gtk_window_get_size (GtkWindow *window,
                     gint *width,
                     gint *height);

Obtains the current size of window .

If window 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: gtk_window_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 gtk_window_resize(); additionally, since gtk_window_resize() may be implemented as an asynchronous operation, GTK+ cannot guarantee in any way that this code:

1
2
3
4
5
6
7
GtkWindow *window = GTK_WINDOW (gtk_window_new ());
int width = 500;
int height = 300;
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 GtkWindow, 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 gtk_window_set_default_size() to restore them when before showing the window.

1
2
3
4
5
6
7
8
9
10
11
static void
on_size_allocate (GtkWidget *widget,
                  const GtkAllocation *allocation,
                  int baseline)
{
  int new_width, new_height;

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

  // ...
}

If you are getting a window size in order to position the window on the screen, don't. You should, instead, simply let the window manager place windows. Also, if you set the transient parent of dialogs with gtk_window_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: gtk_window_set_position().

Parameters

window

a GtkWindow

 

width

return location for width, or NULL.

[out][optional]

height

return location for height, or NULL.

[out][optional]

gtk_window_get_title ()

const gchar *
gtk_window_get_title (GtkWindow *window);

Retrieves the title of the window. See gtk_window_set_title().

Parameters

window

a GtkWindow

 

Returns

the title of the window, or NULL if none has been set explicitly. The returned string is owned by the widget and must not be modified or freed.

[nullable]


gtk_window_get_transient_for ()

GtkWindow *
gtk_window_get_transient_for (GtkWindow *window);

Fetches the transient parent for this window. See gtk_window_set_transient_for().

Parameters

window

a GtkWindow

 

Returns

the transient parent for this window, or NULL if no transient parent has been set.

[nullable][transfer none]


gtk_window_get_group ()

GtkWindowGroup *
gtk_window_get_group (GtkWindow *window);

Returns the group for window or the default group, if window is NULL or if window does not have an explicit window group.

Parameters

window

a GtkWindow, or NULL.

[allow-none]

Returns

the GtkWindowGroup for a window or the default group.

[transfer none]


gtk_window_has_group ()

gboolean
gtk_window_has_group (GtkWindow *window);

Returns whether window has an explicit window group.

Parameters

window

a GtkWindow

 

Returns

TRUE if window has an explicit window group.


gtk_window_resize ()

void
gtk_window_resize (GtkWindow *window,
                   gint width,
                   gint height);

Resizes the window as if the user had done so, obeying geometry constraints. The default geometry constraint is that windows may not be smaller than their size request; to override this constraint, call gtk_widget_set_size_request() to set the window's request to a smaller value.

If gtk_window_resize() is called before showing a window for the first time, it overrides any default size set with gtk_window_set_default_size().

Windows may not be resized smaller than 1 by 1 pixels.

When using client side decorations, GTK+ will do its best to adjust the given size so that the resulting window size matches the requested size without the title bar, borders and shadows added for the client side decorations, but there is no guarantee that the result will be totally accurate because these widgets added for client side decorations depend on the theme and may not be realized or visible at the time gtk_window_resize() is issued.

If the GtkWindow has a titlebar widget (see gtk_window_set_titlebar()), then typically, gtk_window_resize() will compensate for the height of the titlebar widget only if the height is known when the resulting GtkWindow configuration is issued. For example, if new widgets are added after the GtkWindow configuration and cause the titlebar widget to grow in height, this will result in a window content smaller that specified by gtk_window_resize() and not a larger window.

Parameters

window

a GtkWindow

 

width

width in pixels to resize the window to

 

height

height in pixels to resize the window to

 

gtk_window_set_default_icon_name ()

void
gtk_window_set_default_icon_name (const gchar *name);

Sets an icon to be used as fallback for windows that haven't had gtk_window_set_icon_list() called on them from a named themed icon, see gtk_window_set_icon_name().

Parameters

name

the name of the themed icon

 

gtk_window_set_icon_name ()

void
gtk_window_set_icon_name (GtkWindow *window,
                          const gchar *name);

Sets the icon for the window from a named themed icon. See the docs for GtkIconTheme for more details. On some platforms, the window icon is not used at all.

Note that this has nothing to do with the WM_ICON_NAME property which is mentioned in the ICCCM.

Parameters

window

a GtkWindow

 

name

the name of the themed icon.

[allow-none]

gtk_window_set_auto_startup_notification ()

void
gtk_window_set_auto_startup_notification
                               (gboolean setting);

By default, after showing the first GtkWindow, GTK+ calls gdk_notify_startup_complete(). Call this function to disable the automatic startup notification. You might do this if your first window is a splash screen, and you want to delay notification until after your real main window has been shown, for example.

In that example, you would disable startup notification temporarily, show your splash screen, then re-enable it so that showing the main window would automatically result in notification.

Parameters

setting

TRUE to automatically do startup notification

 

gtk_window_get_mnemonics_visible ()

gboolean
gtk_window_get_mnemonics_visible (GtkWindow *window);

Gets the value of the “mnemonics-visible” property.

Parameters

window

a GtkWindow

 

Returns

TRUE if mnemonics are supposed to be visible in this window.


gtk_window_set_mnemonics_visible ()

void
gtk_window_set_mnemonics_visible (GtkWindow *window,
                                  gboolean setting);

Sets the “mnemonics-visible” property.

Parameters

window

a GtkWindow

 

setting

the new value

 

gtk_window_get_focus_visible ()

gboolean
gtk_window_get_focus_visible (GtkWindow *window);

Gets the value of the “focus-visible” property.

Parameters

window

a GtkWindow

 

Returns

TRUE if “focus rectangles” are supposed to be visible in this window.


gtk_window_set_focus_visible ()

void
gtk_window_set_focus_visible (GtkWindow *window,
                              gboolean setting);

Sets the “focus-visible” property.

Parameters

window

a GtkWindow

 

setting

the new value

 

gtk_window_get_application ()

GtkApplication *
gtk_window_get_application (GtkWindow *window);

Gets the GtkApplication associated with the window (if any).

Parameters

window

a GtkWindow

 

Returns

a GtkApplication, or NULL.

[nullable][transfer none]


gtk_window_set_application ()

void
gtk_window_set_application (GtkWindow *window,
                            GtkApplication *application);

Sets or unsets the GtkApplication associated with the window.

The application will be kept alive for at least as long as it has any windows associated with it (see g_application_hold() for a way to keep it alive without windows).

Normally, the connection between the application and the window will remain until the window is destroyed, but you can explicitly remove it by setting the application to NULL.

This is equivalent to calling gtk_application_remove_window() and/or gtk_application_add_window() on the old/new applications as relevant.

Parameters

window

a GtkWindow

 

application

a GtkApplication, or NULL to unset.

[allow-none]

gtk_window_set_titlebar ()

void
gtk_window_set_titlebar (GtkWindow *window,
                         GtkWidget *titlebar);

Sets a custom titlebar for window .

A typical widget used here is GtkHeaderBar, as it provides various features expected of a titlebar while allowing the addition of child widgets to it.

If you set a custom titlebar, GTK+ will do its best to convince the window manager not to put its own titlebar on the window. Depending on the system, this function may not work for a window that is already visible, so you set the titlebar before calling gtk_widget_show().

Parameters

window

a GtkWindow

 

titlebar

the widget to use as titlebar.

[allow-none]

gtk_window_get_titlebar ()

GtkWidget *
gtk_window_get_titlebar (GtkWindow *window);

Returns the custom titlebar that has been set with gtk_window_set_titlebar().

Parameters

window

a GtkWindow

 

Returns

the custom titlebar, or NULL.

[nullable][transfer none]


gtk_window_set_interactive_debugging ()

void
gtk_window_set_interactive_debugging (gboolean enable);

Opens or closes the interactive debugger, which offers access to the widget hierarchy of the application and to useful debugging tools.

Parameters

enable

TRUE to enable interactive debugging

 

Types and Values

GtkWindow

typedef struct _GtkWindow GtkWindow;

struct GtkWindowClass

struct GtkWindowClass {
  GtkWidgetClass parent_class;

  /* G_SIGNAL_ACTION signals for keybindings */

  void     (* activate_focus)   (GtkWindow *window);
  void     (* activate_default) (GtkWindow *window);
  void	   (* keys_changed)     (GtkWindow *window);
  gboolean (* enable_debugging) (GtkWindow *window,
                                 gboolean   toggle);
  gboolean (* close_request)    (GtkWindow *window);
};

Members

activate_focus ()

Activates the current focused widget within the window.

 

activate_default ()

Activates the default widget for the window.

 

keys_changed ()

Signal gets emitted when the set of accelerators or mnemonics that are associated with window changes.

 

enable_debugging ()

Class handler for the “enable-debugging” keybinding signal.

 

close_request ()

Class handler for the “close-request” signal.

 

Property Details

The “application” property

  “application”              GtkApplication *

The GtkApplication associated with the window.

The application will be kept alive for at least as long as it has any windows associated with it (see g_application_hold() for a way to keep it alive without windows).

Normally, the connection between the application and the window will remain until the window is destroyed, but you can explicitly remove it by setting the :application property to NULL.

Owner: GtkWindow

Flags: Read / Write


The “child” property

  “child”                    GtkWidget *

The child widget.

Owner: GtkWindow

Flags: Read / Write


The “decorated” property

  “decorated”                gboolean

Whether the window should be decorated by the window manager.

Owner: GtkWindow

Flags: Read / Write

Default value: TRUE


The “default-height” property

  “default-height”           gint

The default height of the window, used when initially showing the window.

Owner: GtkWindow

Flags: Read / Write

Allowed values: >= -1

Default value: -1


The “default-widget” property

  “default-widget”           GtkWidget *

The default widget.

Owner: GtkWindow

Flags: Read / Write


The “default-width” property

  “default-width”            gint

The default width of the window, used when initially showing the window.

Owner: GtkWindow

Flags: Read / Write

Allowed values: >= -1

Default value: -1


The “deletable” property

  “deletable”                gboolean

Whether the window frame should have a close button.

Owner: GtkWindow

Flags: Read / Write

Default value: TRUE


The “destroy-with-parent” property

  “destroy-with-parent”      gboolean

If this window should be destroyed when the parent is destroyed.

Owner: GtkWindow

Flags: Read / Write

Default value: FALSE


The “display” property

  “display”                  GdkDisplay *

The display that will display this window.

Owner: GtkWindow

Flags: Read / Write


The “focus-visible” property

  “focus-visible”            gboolean

Whether 'focus rectangles' are currently visible in this window.

This property is maintained by GTK+ based on user input and should not be set by applications.

Owner: GtkWindow

Flags: Read / Write

Default value: TRUE


The “focus-widget” property

  “focus-widget”             GtkWidget *

The focus widget.

Owner: GtkWindow

Flags: Read / Write


The “hide-on-close” property

  “hide-on-close”            gboolean

If this window should be hidden when the user clicks the close button.

Owner: GtkWindow

Flags: Read / Write

Default value: FALSE


The “icon-name” property

  “icon-name”                gchar *

The :icon-name property specifies the name of the themed icon to use as the window icon. See GtkIconTheme for more details.

Owner: GtkWindow

Flags: Read / Write

Default value: NULL


The “is-active” property

  “is-active”                gboolean

Whether the toplevel is the current active window.

Owner: GtkWindow

Flags: Read

Default value: FALSE


The “is-maximized” property

  “is-maximized”             gboolean

Whether the window is maximized.

Owner: GtkWindow

Flags: Read

Default value: FALSE


The “mnemonics-visible” property

  “mnemonics-visible”        gboolean

Whether mnemonics are currently visible in this window.

This property is maintained by GTK+ based on user input, and should not be set by applications.

Owner: GtkWindow

Flags: Read / Write

Default value: FALSE


The “modal” property

  “modal”                    gboolean

If TRUE, the window is modal (other windows are not usable while this one is up).

Owner: GtkWindow

Flags: Read / Write

Default value: FALSE


The “resizable” property

  “resizable”                gboolean

If TRUE, users can resize the window.

Owner: GtkWindow

Flags: Read / Write

Default value: TRUE


The “startup-id” property

  “startup-id”               gchar *

The :startup-id is a write-only property for setting window's startup notification identifier. See gtk_window_set_startup_id() for more details.

Owner: GtkWindow

Flags: Write

Default value: NULL


The “title” property

  “title”                    gchar *

The title of the window.

Owner: GtkWindow

Flags: Read / Write

Default value: NULL


The “transient-for” property

  “transient-for”            GtkWindow *

The transient parent of the window. See gtk_window_set_transient_for() for more details about transient windows.

Owner: GtkWindow

Flags: Read / Write / Construct

Signal Details

The “activate-default” signal

void
user_function (GtkWindow *window,
               gpointer   user_data)

The ::activate-default signal is a keybinding signal which gets emitted when the user activates the default widget of window .

Parameters

window

the window which received the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Action


The “activate-focus” signal

void
user_function (GtkWindow *window,
               gpointer   user_data)

The ::activate-focus signal is a keybinding signal which gets emitted when the user activates the currently focused widget of window .

Parameters

window

the window which received the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Action


The “close-request” signal

gboolean
user_function (GtkWindow *window,
               gpointer   user_data)

The ::close-request signal is emitted when the user clicks on the close button of the window.

Return: TRUE to stop other handlers from being invoked for the signal

Parameters

window

the window on which the signal is emitted

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last


The “enable-debugging” signal

gboolean
user_function (GtkWindow *window,
               gboolean   toggle,
               gpointer   user_data)

The ::enable-debugging signal is a keybinding signal which gets emitted when the user enables or disables interactive debugging. When toggle is TRUE, interactive debugging is toggled on or off, when it is FALSE, the debugger will be pointed at the widget under the pointer.

The default bindings for this signal are Ctrl-Shift-I and Ctrl-Shift-D.

Return: TRUE if the key binding was handled

Parameters

window

the window on which the signal is emitted

 

toggle

toggle the debugger

 

user_data

user data set when the signal handler was connected.

 

Flags: Action


The “keys-changed” signal

void
user_function (GtkWindow *window,
               gpointer   user_data)

The ::keys-changed signal gets emitted when the set of accelerators or mnemonics that are associated with window changes.

Parameters

window

the window which received the signal

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First

Action Details

The “window.close” action

Close the window.


The “window.toggle-maximized” action

Maximize or restore the window.


The “window.minimize” action

Close the window.


The “default.activate” action

Activate the default widget.