Class: Gtk::Application

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#active_windowGtk::Window

Returns active-window.

Returns:

#active_window=(active_window) ⇒ Gtk::Window

Parameters:

Returns:

#add_accelerator(accelerator, action_name, parameter) ⇒ nil

Installs an accelerator that will cause the named action to be activated when the key combination specificed by accelerator is pressed.

accelerator must be a string that can be parsed by gtk_accelerator_parse(), e.g. “<Primary>q” or “<Control><Alt>p”.

action_name must be the name of an action as it would be used in the app menu, i.e. actions that have been added to the application are referred to with an “app.” prefix, and window-specific actions with a “win.” prefix.

GtkApplication also extracts accelerators out of “accel” attributes in the GMenu::Models passed to gtk_application_set_app_menu() and gtk_application_set_menubar(), which is usually more convenient than calling this function for each accelerator.

Parameters:

  • accelerator (String)

    accelerator string

  • action_name (String)

    the name of the action to activate

  • parameter (GLib::Variant)

    parameter to pass when activating the action, or nil if the action does not accept an activation parameter

Returns:

  • (nil)

#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 Gtk::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 gtk_application_remove_window().

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

Parameters:

Returns:

  • (nil)

#app_menuGio::MenuModel

Returns app-menu.

Returns:

#app_menu=(app_menu) ⇒ Gio::MenuModel

Parameters:

Returns:

#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, as an array. Free with g_strfreev() when no longer needed

#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. nil is never returned.

It is a programmer error to pass an invalid accelerator string. If you are unsure, check it with gtk_accelerator_parse() first.

Parameters:

  • accel (String)

    an accelerator that can be parsed by gtk_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 [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 Gtk::ApplicationWindow with the given ID.

The ID of a Gtk::ApplicationWindow can be retrieved with gtk_application_window_get_id().

Parameters:

  • id (Integer)

    an identifier number

Returns:

  • (Gtk::Window)

    the window with ID id, or nil if there is no window with this ID

#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 gtk_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.

Reasons 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 Gtk::Window, or nil

  • 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 gtk_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.

#is_inhibited(flags) ⇒ TrueClass

Determines if any of the actions specified in flags are currently inhibited (possibly by another application).

Note that this information may not be available (for example when the application is running in a sandbox).

Parameters:

Returns:

  • (TrueClass)

    true if any of the actions specified in flags are inhibited

#list_action_descriptionsArray<String>

Lists the detailed action names which have associated accelerators. See gtk_application_set_accels_for_action().

Returns:

  • (Array<String>)

    an array of strings, free with g_strfreev() when done

Returns menubar.

Returns:

Parameters:

Returns:

#new(application_id, flags) ⇒ Gtk::Application

Creates a new Gtk::Application instance.

When using Gtk::Application, it is not necessary to call gtk_init() manually. It is called as soon as the application gets registered as the primary instance.

Concretely, gtk_init() is called in the default handler for the #GApplication::startup signal. Therefore, Gtk::Application subclasses should chain up in their #GApplication::startup handler before using any GTK+ API.

Note that commandline arguments are not passed to gtk_init(). All GTK+ functionality that is available via commandline arguments can also be achieved by setting suitable environment variables such as ‘G_DEBUG`, so this should not be a big problem. If you absolutely must support GTK+ commandline arguments, you can explicitly call gtk_init() before creating the application instance.

If non-nil, the application ID 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. A null application ID is only allowed with GTK+ 3.6 or later.

Parameters:

  • application_id (String)

    The application ID.

  • flags (Gio::ApplicationFlags)

    the application flags

Returns:

#prefers_app_menuTrueClass

Determines if the desktop environment in which the application is running would prefer an application menu be shown.

If this function returns true then the application should call gtk_application_set_app_menu() with the contents of an application menu, which will be shown by the desktop environment. If it returns false then you should consider using an alternate approach, such as a menubar.

The value returned by this function is purely advisory and you are free to ignore it. If you call gtk_application_set_app_menu() even if the desktop environment doesn’t support app menus, then a fallback will be provided.

Applications are similarly free not to set an app menu even if the desktop environment wants to show one. In that case, a fallback will also be created by the desktop environment (GNOME, for example, uses a menu with only a “Quit” item in it).

The value returned by this function never changes. Once it returns a particular value, it is guaranteed to always return the same value.

You may only call this function after the application has been registered and after the base startup handler has run. You’re most likely to want to use this from your own startup handler. It may also make sense to consult this function while constructing UI (in activate, open or an action activation handler) in order to determine if you should show a gear menu or not.

This function will return false on Mac OS and a default app menu will be created automatically with the “usual” contents of that menu typical to most Mac OS applications. If you call gtk_application_set_app_menu() anyway, then this menu will be replaced with your own.

Returns:

  • (TrueClass)

    true if you should set an app menu

#register_session=(register_session) ⇒ TrueClass

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

Parameters:

  • register_session (TrueClass)

Returns:

  • (TrueClass)

    register-session

  • (TrueClass)

    register-session

#register_session?TrueClass

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

Returns:

  • (TrueClass)

    register-session

#remove_accelerator(action_name, parameter) ⇒ nil

Removes an accelerator that has been previously added with gtk_application_add_accelerator().

Parameters:

  • action_name (String)

    the name of the action to activate

  • parameter (GLib::Variant)

    parameter to pass when activating the action, or nil if the action does not accept an activation parameter

Returns:

  • (nil)

#remove_window(window) ⇒ nil

Remove a window from application.

If window belongs to application then this call is equivalent to setting the Gtk::Window:application property of window to nil.

The application may stop running as a result of a call to this function.

Parameters:

Returns:

  • (nil)

#screensaver_active=(screensaver_active) ⇒ TrueClass

This property is true if GTK+ believes that the screensaver is currently active. GTK+ only tracks session state (including this) when Gtk::Application::register-session is set to true.

Tracking the screensaver state is supported on Linux.

Parameters:

  • screensaver_active (TrueClass)

Returns:

  • (TrueClass)

    screensaver-active

  • (TrueClass)

    screensaver-active

#screensaver_active?TrueClass

This property is true if GTK+ believes that the screensaver is currently active. GTK+ only tracks session state (including this) when Gtk::Application::register-session is set to true.

Tracking the screensaver state is supported on Linux.

Returns:

  • (TrueClass)

    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 gtk_accelerator_parse()

Returns:

  • (nil)

#uninhibit(cookie) ⇒ nil

Removes an inhibitor that has been established with gtk_application_inhibit(). Inhibitors are also cleared when the application exits.

Parameters:

  • cookie (Integer)

    a cookie that was returned by gtk_application_inhibit()

Returns:

  • (nil)

#windowsGLib::List

Gets a list of the Gtk::Windows 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)

    a #GList of Gtk::Window