Class: Gtk::Window

Inherits:
Widget
  • Object
show all
Extended by:
GLib::Deprecatable
Defined in:
lib/gtk4/deprecated.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Widget

#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #children, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #dispose_template, #drag_check_threshold, #error_bell, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, have_template?, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_action_group_raw, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_size_request, #set_size_request_raw, #set_state_flags, #set_template, #set_template_raw, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #style_context_raw, #template=, template_children, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #translate_coordinates_raw, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=

Constructor Details

#initializeGtk::Widget

Creates a new GtkWindow.

To get an undecorated window (no window borders), use [methodGtk.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 [funcGtk.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 [methodGtk.Window.destroy].

Class Method Details

.auto_startup_notification=(setting) ⇒ nil

Sets whether the window should request startup notification.

By default, after showing the first GtkWindow, GTK calls [methodGdk.Toplevel.set_startup_id]. 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 (Boolean)

    true to automatically do startup notification

Returns:

  • (nil)

.default_icon_nameString

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 [funcGtk.Window.set_default_icon_name].

Returns:

  • (String)

    the fallback icon name for windows

.default_icon_name=(name) ⇒ nil

Sets an icon to be used as fallback.

The fallback icon is used for windows that haven't had [methodGtk.Window.set_icon_name] called on them.

Parameters:

  • name (String)

    the name of the themed icon

Returns:

  • (nil)

.interactive_debugging=(enable) ⇒ nil

Opens or closes the interactive debugger.

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

This function allows applications that already use Ctrl+Shift+I (or Ctrl+Shift+D) 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.

Parameters:

  • enable (Boolean)

    true to enable interactive debugging

Returns:

  • (nil)

.list_toplevelsGLib::List<Gtk::Widget>

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:

  • (GLib::List<Gtk::Widget>)

    list of toplevel widgets

.toplevelsGio::ListModel

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:

  • (Gio::ListModel)

    the list of toplevel widgets

Instance Method Details

#applicationGtk::Application

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 nil.

Returns:

#application=(application) ⇒ Gtk::Application

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 nil.

Parameters:

Returns:

#childGtk::Widget

The child widget.

Returns:

#child=(child) ⇒ Gtk::Widget

The child widget.

Parameters:

Returns:

#closenil

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.

Returns:

  • (nil)

#decoratedBoolean

Returns whether the window has been set to have decorations.

Returns:

  • (Boolean)

    true if the window has been set to have decorations

#decorated=(decorated) ⇒ Boolean

Whether the window should have a frame (also known as decorations).

Parameters:

  • decorated (Boolean)

Returns:

  • (Boolean)

    decorated

  • (Boolean)

    decorated

#decorated?Boolean

Whether the window should have a frame (also known as decorations).

Returns:

  • (Boolean)

    decorated

#default_heightInteger

The default height of the window.

Returns:

  • (Integer)

    default-height

#default_height=(default_height) ⇒ Integer

The default height of the window.

Parameters:

  • default_height (Integer)

Returns:

  • (Integer)

    default-height

  • (Integer)

    default-height

#default_widgetGtk::Widget

The default widget.

Returns:

#default_widget=(default_widget) ⇒ Gtk::Widget

The default widget.

Parameters:

Returns:

#default_widthInteger

The default width of the window.

Returns:

  • (Integer)

    default-width

#default_width=(default_width) ⇒ Integer

The default width of the window.

Parameters:

  • default_width (Integer)

Returns:

  • (Integer)

    default-width

  • (Integer)

    default-width

#deletableBoolean

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

Returns:

  • (Boolean)

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

#deletable=(deletable) ⇒ Boolean

Whether the window frame should have a close button.

Parameters:

  • deletable (Boolean)

Returns:

  • (Boolean)

    deletable

  • (Boolean)

    deletable

#deletable?Boolean

Whether the window frame should have a close button.

Returns:

  • (Boolean)

    deletable

#destroynil

Drop the internal reference GTK holds on toplevel windows.

Returns:

  • (nil)

#destroy_with_parentBoolean

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

Returns:

  • (Boolean)

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

#destroy_with_parent=(destroy_with_parent) ⇒ Boolean

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

Parameters:

  • destroy_with_parent (Boolean)

Returns:

  • (Boolean)

    destroy-with-parent

  • (Boolean)

    destroy-with-parent

#destroy_with_parent?Boolean

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

Returns:

  • (Boolean)

    destroy-with-parent

#displayGdk::Display

The display that will display this window.

Returns:

#display=(display) ⇒ Gdk::Display

The display that will display this window.

Parameters:

Returns:

#focusGtk::Widget

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.

Returns:

#focus=(focus) ⇒ nil

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 nil, 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 [methodGtk.Widget.grab_focus] instead of this function.

Parameters:

  • focus (Gtk::Widget)

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

Returns:

  • (nil)

#focus_visibleBoolean

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

Returns:

  • (Boolean)

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

#focus_visible=(focus_visible) ⇒ Boolean

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.

Parameters:

  • focus_visible (Boolean)

Returns:

  • (Boolean)

    focus-visible

  • (Boolean)

    focus-visible

#focus_visible?Boolean

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.

Returns:

  • (Boolean)

    focus-visible

#focus_widgetGtk::Widget

The focus widget.

Returns:

#focus_widget=(focus_widget) ⇒ Gtk::Widget

The focus widget.

Parameters:

Returns:

#fullscreennil

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 [propertyGdk.Toplevel:state] property, or by listening to notifications of the [propertyGtk.Window:fullscreened] property.

Returns:

  • (nil)

#fullscreen_on_monitor(monitor) ⇒ nil

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 [propertyGdk.Toplevel:state] property, or by listening to notifications of the [propertyGtk.Window:fullscreened] property.

Parameters:

  • monitor (Gdk::Monitor)

    which monitor to go fullscreen on

Returns:

  • (nil)

#fullscreened=(fullscreened) ⇒ Boolean

Whether the window is fullscreen.

Setting this property is the equivalent of calling [methodGtk.Window.fullscreen] or [methodGtk.Window.unfullscreen]; either operation is asynchronous, which means you will need to connect to the ::notify signal in order to know whether the operation was successful.

Parameters:

  • fullscreened (Boolean)

Returns:

  • (Boolean)

    fullscreened

  • (Boolean)

    fullscreened

#fullscreened?Boolean

Whether the window is fullscreen.

Setting this property is the equivalent of calling [methodGtk.Window.fullscreen] or [methodGtk.Window.unfullscreen]; either operation is asynchronous, which means you will need to connect to the ::notify signal in order to know whether the operation was successful.

Returns:

  • (Boolean)

    fullscreened

#get_default_size(width, height) ⇒ nil

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.

Parameters:

  • width (Integer)

    location to store the default width

  • height (Integer)

    location to store the default height

Returns:

  • (nil)

#groupGtk::WindowGroup

Returns the group for window.

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

Returns:

#handle_menubar_accelBoolean

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

Returns:

  • (Boolean)

    true if the window handles F10

#handle_menubar_accel=(handle_menubar_accel) ⇒ Boolean

Whether the window frame should handle F10 for activating menubars.

Parameters:

  • handle_menubar_accel (Boolean)

Returns:

  • (Boolean)

    handle-menubar-accel

  • (Boolean)

    handle-menubar-accel

#handle_menubar_accel?Boolean

Whether the window frame should handle F10 for activating menubars.

Returns:

  • (Boolean)

    handle-menubar-accel

#has_groupBoolean

Returns whether window has an explicit window group.

Returns:

  • (Boolean)

    true if window has an explicit window group.

#hide_on_closeBoolean

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

Returns:

  • (Boolean)

    true if the window will be hidden

#hide_on_close=(hide_on_close) ⇒ Boolean

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

Parameters:

  • hide_on_close (Boolean)

Returns:

  • (Boolean)

    hide-on-close

  • (Boolean)

    hide-on-close

#hide_on_close?Boolean

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

Returns:

  • (Boolean)

    hide-on-close

#icon_nameString

Specifies the name of the themed icon to use as the window icon.

See [classGtk.IconTheme] for more details.

Returns:

  • (String)

    icon-name

#icon_name=(icon_name) ⇒ String

Specifies the name of the themed icon to use as the window icon.

See [classGtk.IconTheme] for more details.

Parameters:

  • icon_name (String)

Returns:

  • (String)

    icon-name

  • (String)

    icon-name

#is_activeBoolean

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.

Returns:

  • (Boolean)

    true if the window part of the current active window.

#is_active=(is_active) ⇒ Boolean

Whether the toplevel is the currently active window.

Parameters:

  • is_active (Boolean)

Returns:

  • (Boolean)

    is-active

  • (Boolean)

    is-active

#is_active?Boolean

Whether the toplevel is the currently active window.

Returns:

  • (Boolean)

    is-active

#is_fullscreenBoolean

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 [methodGtk.Window.fullscreen] or [methodGtk.Window.unfullscreen].

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

Returns:

  • (Boolean)

    whether the window has a fullscreen state.

#is_maximizedBoolean

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 [methodGtk.Window.maximize] or [methodGtk.Window.unmaximize].

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

Returns:

  • (Boolean)

    whether the window has a maximized state.

#is_suspendedBoolean

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.

Returns:

  • (Boolean)

    whether the window is suspended.

#maximizenil

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 [propertyGdk.Toplevel:state] property, or by listening to notifications on the [propertyGtk.Window:maximized] property.

Returns:

  • (nil)

#maximized=(maximized) ⇒ Boolean

Whether the window is maximized.

Setting this property is the equivalent of calling [methodGtk.Window.maximize] or [methodGtk.Window.unmaximize]; either operation is asynchronous, which means you will need to connect to the ::notify signal in order to know whether the operation was successful.

Parameters:

  • maximized (Boolean)

Returns:

  • (Boolean)

    maximized

  • (Boolean)

    maximized

#maximized?Boolean

Whether the window is maximized.

Setting this property is the equivalent of calling [methodGtk.Window.maximize] or [methodGtk.Window.unmaximize]; either operation is asynchronous, which means you will need to connect to the ::notify signal in order to know whether the operation was successful.

Returns:

  • (Boolean)

    maximized

#minimizenil

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 [propertyGdk.Toplevel:state] property.

Returns:

  • (nil)

#mnemonics_visibleBoolean

Gets whether mnemonics are supposed to be visible.

Returns:

  • (Boolean)

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

#mnemonics_visible=(mnemonics_visible) ⇒ Boolean

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.

Parameters:

  • mnemonics_visible (Boolean)

Returns:

  • (Boolean)

    mnemonics-visible

  • (Boolean)

    mnemonics-visible

#mnemonics_visible?Boolean

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.

Returns:

  • (Boolean)

    mnemonics-visible

Returns whether the window is modal.

Returns:

  • (Boolean)

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

#modal=(modal) ⇒ Boolean

If true, the window is modal.

Parameters:

  • modal (Boolean)

Returns:

  • (Boolean)

    modal

  • (Boolean)

    modal

#modal?Boolean

If true, the window is modal.

Returns:

  • (Boolean)

    modal

#presentnil

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.

Returns:

  • (nil)

#present_with_time(timestamp) ⇒ nil

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

See [methodGtk.Window.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.

Parameters:

  • timestamp (Integer)

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

Returns:

  • (nil)

#resizableBoolean

Gets the value set by gtk_window_set_resizable().

Returns:

  • (Boolean)

    true if the user can resize the window

#resizable=(resizable) ⇒ Boolean

If true, users can resize the window.

Parameters:

  • resizable (Boolean)

Returns:

  • (Boolean)

    resizable

  • (Boolean)

    resizable

#resizable?Boolean

If true, users can resize the window.

Returns:

  • (Boolean)

    resizable

#set_default_size(width, height) ⇒ nil

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 [methodGtk.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).

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

Parameters:

  • width (Integer)

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

  • height (Integer)

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

Returns:

  • (nil)

#startup_id=(startup_id) ⇒ String

A write-only property for setting window's startup notification identifier.

Parameters:

  • startup_id (String)

Returns:

  • (String)

    startup-id

#suspended=(suspended) ⇒ Boolean

Whether the window is suspended.

See [methodGtk.Window.is_suspended] for details about what suspended means.

Parameters:

  • suspended (Boolean)

Returns:

  • (Boolean)

    suspended

  • (Boolean)

    suspended

#suspended?Boolean

Whether the window is suspended.

See [methodGtk.Window.is_suspended] for details about what suspended means.

Returns:

  • (Boolean)

    suspended

#titleString

The title of the window.

Returns:

  • (String)

    title

#title=(title) ⇒ String

The title of the window.

Parameters:

  • title (String)

Returns:

  • (String)

    title

  • (String)

    title

#titlebarGtk::Widget

The titlebar widget.

Returns:

#titlebar=(titlebar) ⇒ Gtk::Widget

The titlebar widget.

Parameters:

Returns:

#transient_forGtk::Window

The transient parent of the window.

Returns:

#transient_for=(transient_for) ⇒ Gtk::Window

The transient parent of the window.

Parameters:

Returns:

#unfullscreennil

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 [propertyGdk.Toplevel:state] property, or by listening to notifications of the [propertyGtk.Window:fullscreened] property.

Returns:

  • (nil)

#unmaximizenil

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 [propertyGdk.Toplevel:state] property, or by listening to notifications on the [propertyGtk.Window:maximized] property.

Returns:

  • (nil)

#unminimizenil

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 [propertyGdk.Toplevel:state] property.

Returns:

  • (nil)