Class: Gtk::Application

Inherits:
Gio::Application
  • Object
show all
Defined in:
lib/gtk4/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Gtk::Application

Creates a new GtkApplication instance.

When using GtkApplication, it is not necessary to call [funcGtk.init] manually. It is called as soon as the application gets registered as the primary instance.

Concretely, [funcGtk.init] is called in the default handler for the GApplication::startup signal. Therefore, GtkApplication subclasses should always chain up in their GApplication::startup handler before using any GTK API.

Note that commandline arguments are not passed to [funcGtk.init].

If application_id is not nil, then it must be valid. See g_application_id_is_valid().

If no application ID is given then some features (most notably application uniqueness) will be disabled.

Parameters:

  • application_id (String)

    The application ID

  • flags (Gio::ApplicationFlags)

    the application flags



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gtk4/application.rb', line 20

def initialize(*args)
  case args.size
  when 0
    initialize_raw(nil, :flags_none)
  when 1
    if args[0].is_a?(String)
      initialize_raw(args[0], :flags_none)
    else
      initialize_raw(nil, args[0])
    end
  else
    initialize_raw(*args)
  end
end

Instance Method Details

#active_windowGtk::Window

The currently focused window of the application.

Returns:

#active_window=(active_window) ⇒ Gtk::Window

The currently focused window of the application.

Parameters:

Returns:

#add_window(window) ⇒ nil

Adds a window to application.

This call can only happen after the application has started; typically, you should add new application windows in response to the emission of the GApplication::activate signal.

This call is equivalent to setting the [propertyGtk.Window:application] property of window to application.

Normally, the connection between the application and the window will remain until the window is destroyed, but you can explicitly remove it with [methodGtk.Application.remove_window].

GTK will keep the application running as long as it has any windows.

Parameters:

Returns:

  • (nil)

#get_accels_for_action(detailed_action_name) ⇒ Array<String>

Gets the accelerators that are currently associated with the given action.

Parameters:

  • detailed_action_name (String)

    a detailed action name, specifying an action and target to obtain accelerators for

Returns:

  • (Array<String>)

    accelerators for detailed_action_name

#get_actions_for_accel(accel) ⇒ Array<String>

Returns the list of actions (possibly empty) that accel maps to.

Each item in the list is a detailed action name in the usual form.

This might be useful to discover if an accel already exists in order to prevent installation of a conflicting accelerator (from an accelerator editor or a plugin system, for example). Note that having more than one action per accelerator may not be a bad thing and might make sense in cases where the actions never appear in the same context.

In case there are no actions for a given accelerator, an empty array is returned. NULL is never returned.

It is a programmer error to pass an invalid accelerator string.

If you are unsure, check it with [funcGtk.accelerator_parse] first.

Parameters:

  • accel (String)

    an accelerator that can be parsed by [funcGtk.accelerator_parse]

Returns:

  • (Array<String>)

    an array of actions for accel

#get_menu_by_id(id) ⇒ Gio::Menu

Gets a menu from automatically loaded resources.

See the section on Automatic resources for more information.

Parameters:

  • id (String)

    the id of the menu to look up

Returns:

  • (Gio::Menu)

    Gets the menu with the given id from the automatically loaded resources

#get_window_by_id(id) ⇒ Gtk::Window

Returns the [classGtk.ApplicationWindow] with the given ID.

The ID of a GtkApplicationWindow can be retrieved with [methodGtk.ApplicationWindow.get_id].

Parameters:

  • id (Integer)

    an identifier number

Returns:

#inhibit(window, flags, reason) ⇒ Integer

Inform the session manager that certain types of actions should be inhibited.

This is not guaranteed to work on all platforms and for all types of actions.

Applications should invoke this method when they begin an operation that should not be interrupted, such as creating a CD or DVD. The types of actions that may be blocked are specified by the flags parameter. When the application completes the operation it should call [methodGtk.Application.uninhibit] to remove the inhibitor. Note that an application can have multiple inhibitors, and all of them must be individually removed. Inhibitors are also cleared when the application exits.

Applications should not expect that they will always be able to block the action. In most cases, users will be given the option to force the action to take place.

The reason message should be short and to the point.

If window is given, the session manager may point the user to this window to find out more about why the action is inhibited.

Parameters:

  • window (Gtk::Window)

    a GtkWindow

  • flags (Gtk::ApplicationInhibitFlags)

    what types of actions should be inhibited

  • reason (String)

    a short, human-readable string that explains why these operations are inhibited

Returns:

  • (Integer)

    A non-zero cookie that is used to uniquely identify this request. It should be used as an argument to [methodGtk.Application.uninhibit] in order to remove the request. If the platform does not support inhibiting or the request failed for some reason, 0 is returned.

#initialize_rawGtk::Application

Creates a new GtkApplication instance.

When using GtkApplication, it is not necessary to call [funcGtk.init] manually. It is called as soon as the application gets registered as the primary instance.

Concretely, [funcGtk.init] is called in the default handler for the GApplication::startup signal. Therefore, GtkApplication subclasses should always chain up in their GApplication::startup handler before using any GTK API.

Note that commandline arguments are not passed to [funcGtk.init].

If application_id is not nil, then it must be valid. See g_application_id_is_valid().

If no application ID is given then some features (most notably application uniqueness) will be disabled.

Parameters:

  • application_id (String)

    The application ID

  • flags (Gio::ApplicationFlags)

    the application flags

Returns:



# File 'lib/gtk4/application.rb', line 19

#list_action_descriptionsArray<String>

Lists the detailed action names which have associated accelerators.

See [methodGtk.Application.set_accels_for_action].

Returns:

  • (Array<String>)

    the detailed action names

The GMenuModel to be used for the application's menu bar.

Returns:

  • (Gio::MenuModel)

    menubar

The GMenuModel to be used for the application's menu bar.

Parameters:

  • menubar (Gio::MenuModel)

Returns:

  • (Gio::MenuModel)

    menubar

  • (Gio::MenuModel)

    menubar

#register_session=(register_session) ⇒ Boolean

Set this property to TRUE to register with the session manager.

This will make GTK track the session state (such as the [propertyGtk.Application:screensaver-active] property).

Parameters:

  • register_session (Boolean)

Returns:

  • (Boolean)

    register-session

  • (Boolean)

    register-session

#register_session?Boolean

Set this property to TRUE to register with the session manager.

This will make GTK track the session state (such as the [propertyGtk.Application:screensaver-active] property).

Returns:

  • (Boolean)

    register-session

#remove_window(window) ⇒ nil

Remove a window from application.

If window belongs to application then this call is equivalent to setting the [propertyGtk.Window:application] property of window to NULL.

The application may stop running as a result of a call to this function, if window was the last window of the application.

Parameters:

Returns:

  • (nil)

#screensaver_active=(screensaver_active) ⇒ Boolean

This property is TRUE if GTK believes that the screensaver is currently active.

GTK only tracks session state (including this) when [propertyGtk.Application:register-session] is set to true.

Tracking the screensaver state is currently only supported on Linux.

Parameters:

  • screensaver_active (Boolean)

Returns:

  • (Boolean)

    screensaver-active

  • (Boolean)

    screensaver-active

#screensaver_active?Boolean

This property is TRUE if GTK believes that the screensaver is currently active.

GTK only tracks session state (including this) when [propertyGtk.Application:register-session] is set to true.

Tracking the screensaver state is currently only supported on Linux.

Returns:

  • (Boolean)

    screensaver-active

#set_accels_for_action(detailed_action_name, accels) ⇒ nil

Sets zero or more keyboard accelerators that will trigger the given action.

The first item in accels will be the primary accelerator, which may be displayed in the UI.

To remove all accelerators for an action, use an empty, zero-terminated array for accels.

For the detailed_action_name, see g_action_parse_detailed_name() and g_action_print_detailed_name().

Parameters:

  • detailed_action_name (String)

    a detailed action name, specifying an action and target to associate accelerators with

  • accels (Array<String>)

    a list of accelerators in the format understood by [funcGtk.accelerator_parse]

Returns:

  • (nil)

#uninhibit(cookie) ⇒ nil

Removes an inhibitor that has been previously established.

See [methodGtk.Application.inhibit].

Inhibitors are also cleared when the application exits.

Parameters:

  • cookie (Integer)

    a cookie that was returned by [methodGtk.Application.inhibit]

Returns:

  • (nil)

#windowsGLib::List<Gtk::Window>

Gets a list of the [classGtk.Window] instances associated with application.

The list is sorted by most recently focused window, such that the first element is the currently focused window. (Useful for choosing a parent for a transient window.)

The list that is returned should not be modified in any way. It will only remain valid until the next focus change or window creation or deletion.

Returns:

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

    a GList of GtkWindow instances