About all my projects
Gnome::Gtk4::Window

Gnome::Gtk4::Window

Description

A Gnome::Gtk4::Window is a toplevel window which can contain other widgets.

No caption

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 Gnome::Gtk4::Window implementation of the Gnome::Gtk4::R-Buildable interface supports setting a child as the titlebar by specifying “titlebar” as the “type” attribute of a `<child>` element.

CSS nodes

Gnome::Gtk4::Window 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: .maximized, .fullscreen, .tiled (when supported, also .tiled-top, .tiled-left, .tiled-right, .tiled-bottom).

Gnome::Gtk4::Window subclasses often add their own discriminating style classes, such as .dialog, .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.

Gnome::Gtk4::Window adds the .titlebar and .default-decoration style classes to the widget that is added as a titlebar child.

Accessibility

Until GTK 4.10, Gnome::Gtk4::Window used the GTK_ACCESSIBLE_ROLE_WINDOW role.

Since GTK 4.12, Gnome::Gtk4::Window uses the GTK_ACCESSIBLE_ROLE_APPLICATION role.

Actions

Gnome::Gtk4::Window defines a set of built-in actions:

  • default.activate`: Activate the default widget.

  • window.minimize`: Minimize the window.

  • window.toggle-maximized`: Maximize or restore the window.

  • window.close`: Close the window.

Class initialization

new

:native-object

Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.

multi method new ( N-Object :$native-object! )

new-window

Creates a new Gnome::Gtk4::Window.

To get an undecorated window (no window borders), use .set-decorated().

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

To delete a Gnome::Gtk4::Window, call .destroy().

method new-window ( --> Gnome::Gtk4::Window \)

Methods

close

Requests that the window is closed.

This is similar to what happens when a window manager close button is clicked.

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

method close ( )

destroy

Drop the internal reference GTK holds on toplevel windows.

method destroy ( )

fullscreen

Asks to place $window in the fullscreen state.

Note that you shouldn’t assume the window is definitely fullscreen afterward, because other entities (e.g. the user or window manager) unfullscreen it again, and not all window managers honor requests to fullscreen windows.

You can track the result of this operation via the state defined in Gnome::Gdk4::R-Toplevel property, or by listening to notifications of the fullscreened property.

method fullscreen ( )

fullscreen-on-monitor

Asks to place $window in the fullscreen state on the given $monitor.

Note that you shouldn't assume the window is definitely fullscreen afterward, or that the windowing system allows fullscreen windows on any given monitor.

You can track the result of this operation via the state defined in Gnome::Gdk4::R-Toplevel property, or by listening to notifications of the fullscreened property.

method fullscreen-on-monitor ( N-Object() $monitor )
  • $monitor; which monitor to go fullscreen on.

get-application

Gets the Gnome::Gtk4::Application associated with the window.

method get-application (--> N-Object )

Return value; a Gnome::Gtk4::Application.

get-child

Gets the child widget of $window.

method get-child (--> N-Object )

Return value; the child widget of $window.

get-decorated

Returns whether the window has been set to have decorations.

method get-decorated (--> Bool )

Return value; True if the window has been set to have decorations.

get-default-size

Gets the default size of the window.

A value of 0 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.

This function is the recommended way for [saving window state across restarts of applications](https://developer.gnome.org/documentation/tutorials/save-state.html).

method get-default-size ( Array[Int] $width, Array[Int] $height )
  • $width; (transfer ownership: full) location to store the default width.

  • $height; (transfer ownership: full) location to store the default height.

get-default-widget

Returns the default widget for $window.

method get-default-widget (--> N-Object )

Return value; the default widget.

get-deletable

Returns whether the window has been set to have a close button.

method get-deletable (--> Bool )

Return value; True if the window has been set to have a close button.

get-destroy-with-parent

Returns whether the window will be destroyed with its transient parent.

method get-destroy-with-parent (--> Bool )

Return value; True if the window will be destroyed with its transient parent..

get-focus

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.

method get-focus (--> N-Object )

Return value; the currently focused widget.

get-focus-visible

Gets whether “focus rectangles” are supposed to be visible.

method get-focus-visible (--> Bool )

Return value; True if “focus rectangles” are supposed to be visible in this window..

get-group

Returns the group for $window.

If the window has no group, then the default group is returned.

method get-group (--> N-Object )

Return value; the Gnome::Gtk4::WindowGroup for a window or the default group.

get-handle-menubar-accel

Returns whether this window reacts to F10 key presses by activating a menubar it contains.

method get-handle-menubar-accel (--> Bool )

Return value; True if the window handles F10.

get-hide-on-close

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

method get-hide-on-close (--> Bool )

Return value; True if the window will be hidden.

get-icon-name

Returns the name of the themed icon for the window.

method get-icon-name (--> Str )

Return value; the icon name.

get-mnemonics-visible

Gets whether mnemonics are supposed to be visible.

method get-mnemonics-visible (--> Bool )

Return value; True if mnemonics are supposed to be visible in this window..

get-modal

Returns whether the window is modal.

method get-modal (--> Bool )

Return value; True if the window is set to be modal and establishes a grab when shown.

get-resizable

Gets the value set by .set-resizable().

method get-resizable (--> Bool )

Return value; True if the user can resize the window.

get-title

Retrieves the title of the window.

method get-title (--> Str )

Return value; the title of the window.

get-titlebar

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

method get-titlebar (--> N-Object )

Return value; the custom titlebar.

get-transient-for

Fetches the transient parent for this window.

method get-transient-for (--> N-Object )

Return value; the transient parent for this window.

has-group

Returns whether $window has an explicit window group.

method has-group (--> Bool )

Return value; True if $window has an explicit window group..

is-active

Returns whether the window is part of the current active toplevel.

The active toplevel is the 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.

method is-active (--> Bool )

Return value; True if the window part of the current active window..

is-fullscreen

Retrieves the current fullscreen state of $window.

Note that since fullscreening 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 .fullscreen() or .unfullscreen().

If the window isn't yet mapped, the value returned will whether the initial requested state is fullscreen.

method is-fullscreen (--> Bool )

Return value; whether the window has a fullscreen state..

is-maximized

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 .maximize() or .unmaximize().

If the window isn't yet mapped, the value returned will whether the initial requested state is maximized.

method is-maximized (--> Bool )

Return value; whether the window has a maximized state..

is-suspended

Retrieves the current suspended state of $window.

A window being suspended means it's currently not visible to the user, for example by being on a inactive workspace, minimized, obstructed.

method is-suspended (--> Bool )

Return value; whether the window is suspended..

maximize

Asks to maximize $window, so that it fills the 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.

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 defined in Gnome::Gdk4::R-Toplevel property, or by listening to notifications on the maximized property.

method maximize ( )

minimize

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 defined in Gnome::Gdk4::R-Toplevel property.

method minimize ( )

present

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 also makes it visible.

method present ( )

present-with-time

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.14

Presents a window to the user in response to an user interaction.

See .present() for more details.

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.

method present-with-time ( UInt() $timestamp )
  • $timestamp; the timestamp of the user interaction (typically a button or key press event) which triggered this call.

set-application

Sets or unsets the Gnome::Gtk4::Application 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 undefined.

This is equivalent to calling .remove-window() in class Gnome::Gtk4::Application and/or .add-window() in class Gnome::Gtk4::Application on the old/new applications as relevant.

method set-application ( N-Object() $application )
  • $application; a Gnome::Gtk4::Application, or undefined to unset.

set-child

Sets the child widget of $window.

method set-child ( N-Object() $child )
  • $child; the child widget.

set-decorated

Sets whether the window should be decorated.

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 .show() in class Gnome::Gtk4::Widget.

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

method set-decorated ( Bool() $setting )
  • $setting; True to decorate the window.

set-default-size

Sets the default size of a window.

The default size of a window is the size that will be used if no other constraints apply.

The default size will be updated whenever the window is resized to reflect the new size, unless the window is forced to a size, like when it is maximized or fullscreened.

If the window’s minimum size request is larger than the default, the default will be ignored.

Setting the default size to a value <= 0 will cause it to be ignored and the natural size request will be used instead. It is possible to do this while the window is showing to "reset" it to its initial size.

Unlike .set-size-request() in class Gnome::Gtk4::Widget, 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).

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

method set-default-size ( Int() $width, Int() $height )
  • $width; width in pixels, or -1 to unset the default width.

  • $height; height in pixels, or -1 to unset the default height.

set-default-widget

Sets the default widget.

The default widget is the widget that is activated when the user presses Enter in a dialog (for example).

method set-default-widget ( N-Object() $default-widget )
  • $default-widget; widget to be the default to unset the default widget for the toplevel.

set-deletable

Sets whether the window should be deletable.

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 .show() in class Gnome::Gtk4::Widget.

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

method set-deletable ( Bool() $setting )
  • $setting; True to decorate the window as deletable.

set-destroy-with-parent

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 are associated with, for example.

method set-destroy-with-parent ( Bool() $setting )
  • $setting; whether to destroy $window with its transient parent.

set-display

Sets the Gnome::Gdk4::Display where the $window is displayed.

If the window is already mapped, it will be unmapped, and then remapped on the new display.

method set-display ( N-Object() $display )
  • $display; a Gnome::Gdk4::Display.

set-focus

Sets the focus widget.

If $focus is not the current focus widget, and is focusable, sets it as the focus widget for the window. If $focus is undefined, 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 .grab-focus() in class Gnome::Gtk4::Widget instead of this function.

method set-focus ( N-Object() $focus )
  • $focus; widget to be the new focus widget, or undefined to unset any focus widget for the toplevel window..

set-focus-visible

Sets whether “focus rectangles” are supposed to be visible.

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

method set-focus-visible ( Bool() $setting )
  • $setting; the new value.

set-handle-menubar-accel

Sets whether this window should react to F10 key presses by activating a menubar it contains.

method set-handle-menubar-accel ( Bool() $handle-menubar-accel )
  • $handle-menubar-accel; True to make $window handle F10.

set-hide-on-close

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

method set-hide-on-close ( Bool() $setting )
  • $setting; whether to hide the window when it is closed.

set-icon-name

Sets the icon for the window from a named themed icon.

See the docs for Gnome::Gtk4::IconTheme 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.

method set-icon-name ( Str $name )
  • $name; the name of the themed icon.

set-mnemonics-visible

Sets whether mnemonics are supposed to be visible.

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

method set-mnemonics-visible ( Bool() $setting )
  • $setting; the new value.

set-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 .set-transient-for() to make the dialog transient for the parent; most window managers will then disallow lowering the dialog below the parent.

method set-modal ( Bool() $modal )
  • $modal; whether the window is modal.

set-resizable

Sets whether the user can resize a window.

Windows are user resizable by default.

method set-resizable ( Bool() $resizable )
  • $resizable; True if the user can resize this window.

set-startup-id

Sets the startup notification 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 Gnome::Gdk4::Surface.

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 .present() or any equivalent function generating a window map event.

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

method set-startup-id ( Str $startup-id )
  • $startup-id; a string with startup-notification identifier.

set-title

Sets the title of the Gnome::Gtk4::Window.

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.

Passing undefined does the same as setting the title to an empty string.

method set-title ( Str $title )
  • $title; title of the window.

set-titlebar

Sets a custom titlebar for $window.

A typical widget used here is Gnome::Gtk4::HeaderBar, 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 .show() in class Gnome::Gtk4::Widget.

method set-titlebar ( N-Object() $titlebar )
  • $titlebar; the widget to use as titlebar.

set-transient-for

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. .new-with-buttons() in class Gnome::Gtk4::Dialog and other convenience functions in GTK will sometimes call .set-transient-for() on your behalf.

Passing undefined 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.

method set-transient-for ( N-Object() $parent )
  • $parent; parent window.

unfullscreen

Asks to remove the fullscreen state for $window, and return to its previous state.

Note that you shouldn’t assume the window is definitely not fullscreen 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; normally the window will end up restored to its normal state. Just don’t write code that crashes if not.

You can track the result of this operation via the state defined in Gnome::Gdk4::R-Toplevel property, or by listening to notifications of the fullscreened property.

method unfullscreen ( )

unmaximize

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) maximize it again, and not all window managers honor requests to unmaximize.

You can track the result of this operation via the state defined in Gnome::Gdk4::R-Toplevel property, or by listening to notifications on the maximized property.

method unmaximize ( )

unminimize

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 defined in Gnome::Gdk4::R-Toplevel property.

method unminimize ( )

Functions

get-default-icon-name

Returns the fallback icon name for windows.

The returned string is owned by GTK and should not be modified. It is only valid until the next call to .Window.set-default-icon-name().

method get-default-icon-name (--> Str )

Return value; the fallback icon name for windows.

get-toplevels

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.

method get-toplevels (--> N-List )

Return value; the list of toplevel widgets.

list-toplevels

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.

method list-toplevels (--> N-List )

Return value; list of toplevel widgets.

set-auto-startup-notification

Sets whether the window should request startup notification.

By default, after showing the first Gnome::Gtk4::Window, GTK calls .set-startup-id() in class Gnome::Gdk4::R-Toplevel. 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.

method set-auto-startup-notification ( Bool() $setting )
  • $setting; True to automatically do startup notification.

set-default-icon-name

Sets an icon to be used as fallback.

The fallback icon is used for windows that haven't had .set-icon-name() called on them.

method set-default-icon-name ( Str $name )
  • $name; the name of the themed icon.

set-interactive-debugging

Opens or closes the [interactive debugger](running.html#interactive-debugging).

The debugger offers access to the widget hierarchy of the application and to useful debugging tools.

This function allows applications that already use <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>/kbd (or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd> unknown format-code D</kbd|>) for their own key shortcuts to add a different shortcut to open the Inspector.

If you are not overriding the default key shortcuts for the Inspector, you should not use this function.

method set-interactive-debugging ( Bool() $enable )
  • $enable; True to enable interactive debugging.

Signals

activate-default

Emitted when the user activates the default widget of $window.

This is a [keybinding signal](class.SignalAction.html).

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Window :$_widget,
  *C<user>-options
)
  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Window object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

activate-focus

Emitted when the user activates the currently focused widget of $window.

This is a [keybinding signal](class.SignalAction.html).

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Window :$_widget,
  *C<user>-options
)
  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Window object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

close-request

Emitted when the user clicks on the close button of the window.

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Window :$_widget,
  *C<user>-options
  --> gboolean
)
  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Window object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

Return value; True to stop other handlers from being invoked for the signal

enable-debugging

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.

This is a [keybinding signal](class.SignalAction.html).

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

method handler (
  gboolean $toggle,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Window :$_widget,
  *C<user>-options
  --> gboolean
)
  • $toggle; toggle the debugger.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Window object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.

Return value; True if the key binding was handled

keys-changed

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

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::Window :$_widget,
  *C<user>-options
)
  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Window object.

  • $_widget; The object which registered the signal. User code may have left the object going out of scope.

  • user-options; A list of named arguments provided at the .register-signal() method from Gnome::GObject::Object.