gtkmm 3.24.7
Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::Application Class Reference

The Gtk::Application class handles many important aspects of a GTK+ application in a convenient fashion, without enforcing a one-size-fits-all application model. More...

#include <gtkmm/application.h>

Inherits Gio::Application.

Public Member Functions

 Application (Application && src) noexcept
 
Applicationoperator= (Application && src) noexcept
 
 ~Application () noexcept override
 
GtkApplication * gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkApplication * gobj () const
 Provides access to the underlying C GObject. More...
 
GtkApplication * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
std::vector< Window * > get_windows ()
 Gets a list of the Gtk::Windows associated with application. More...
 
std::vector< const Window * > get_windows () const
 Gets a list of the Gtk::Windows associated with application. More...
 
void add_window (Window & window)
 Adds a window to the Gtk::Application. More...
 
void remove_window (Window & window)
 Remove a window from application. More...
 
int run (int argc, char ** argv)
 Starts the application. More...
 
int run (Window & window, int argc, char ** argv)
 Starts the application. More...
 
int run (Window & window)
 Starts the application. More...
 
int run ()
 Starts the application. More...
 
Glib::RefPtr< Gio::MenuModel > get_app_menu ()
 Returns the menu model that has been set with set_app_menu(). More...
 
Glib::RefPtr< const Gio::MenuModel > get_app_menu () const
 Returns the menu model that has been set with set_app_menu(). More...
 
void set_app_menu (const Glib::RefPtr< Gio::MenuModel > & app_menu)
 Sets or unsets the application menu for application. More...
 
Glib::RefPtr< Gio::MenuModel > get_menubar ()
 Returns the menu model that has been set with set_menubar(). More...
 
Glib::RefPtr< const Gio::MenuModel > get_menubar () const
 Returns the menu model that has been set with set_menubar(). More...
 
void set_menubar (const Glib::RefPtr< Gio::MenuModel > & menubar)
 Sets or unsets the menubar for windows of application. More...
 
void add_accelerator (const Glib::ustring & accelerator, const Glib::ustring & action_name, GVariant * parameter)
 Installs an accelerator that will cause the named action to be activated when the key combination specificed by accelerator is pressed. More...
 
void add_accelerator (const Glib::ustring & accelerator, const Glib::ustring & action_name)
 A add_accelerator() convenience overload. More...
 
void remove_accelerator (const Glib::ustring & action_name, GVariant * parameter)
 Removes an accelerator that has been previously added with add_accelerator(). More...
 
void remove_accelerator (const Glib::ustring & action_name)
 A remove_accelerator() convenience overload. More...
 
guint inhibit (Window & window, ApplicationInhibitFlags flags, const Glib::ustring & reason)
 Inform the session manager that certain types of actions should be inhibited. More...
 
void uninhibit (guint cookie)
 Removes an inhibitor that has been established with inhibit(). More...
 
bool is_inhibited (ApplicationInhibitFlags flags) const
 Determines if any of the actions specified in flags are currently inhibited (possibly by another application). More...
 
Windowget_window_by_id (guint id)
 Returns the Gtk::ApplicationWindow with the given ID. More...
 
const Windowget_window_by_id (guint id) const
 Returns the Gtk::ApplicationWindow with the given ID. More...
 
Windowget_active_window ()
 Gets the “active” window for the application. More...
 
const Windowget_active_window () const
 Gets the “active” window for the application. More...
 
std::vector< Glib::ustring > list_action_descriptions () const
 Lists the detailed action names which have associated accelerators. More...
 
std::vector< Glib::ustring > get_accels_for_action (const Glib::ustring & detailed_action_name) const
 Gets the accelerators that are currently associated with the given action. More...
 
std::vector< Glib::ustring > get_actions_for_accel (const Glib::ustring & accel) const
 Returns the list of actions (possibly empty) that accel maps to. More...
 
void set_accels_for_action (const Glib::ustring & detailed_action_name, const std::vector< Glib::ustring > & accels)
 Sets zero or more keyboard accelerators that will trigger the given action. More...
 
void set_accel_for_action (const Glib::ustring & detailed_action_name, const Glib::ustring & accel)
 Sets a keyboard accelerator that will trigger the given action. More...
 
void unset_accels_for_action (const Glib::ustring & detailed_action_name)
 Unsets a keyboard accelerator that will trigger the given action. More...
 
bool prefers_app_menu () const
 Determines if the desktop environment in which the application is running would prefer an application menu be shown. More...
 
Glib::RefPtr< Gio::Menu > get_menu_by_id (const Glib::ustring & id)
 Gets a menu from automatically loaded resources. More...
 
Glib::RefPtr< const Gio::Menu > get_menu_by_id (const Glib::ustring & id) const
 Gets a menu from automatically loaded resources. More...
 
Glib::PropertyProxy< Glib::RefPtr< Gio::MenuModel > > property_app_menu ()
 The GMenuModel for the application menu. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gio::MenuModel > > property_app_menu () const
 The GMenuModel for the application menu. More...
 
Glib::PropertyProxy< Glib::RefPtr< Gio::MenuModel > > property_menubar ()
 The GMenuModel for the menubar. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gio::MenuModel > > property_menubar () const
 The GMenuModel for the menubar. More...
 
Glib::PropertyProxy< bool > property_register_session ()
 Set this property to true to register with the session manager. More...
 
Glib::PropertyProxy_ReadOnly< bool > property_register_session () const
 Set this property to true to register with the session manager. More...
 
Glib::PropertyProxy_ReadOnly< Window * > property_active_window () const
 The window which most recently had focus. More...
 
Glib::SignalProxy< void, Window * > signal_window_added ()
 
Glib::SignalProxy< void, Window * > signal_window_removed ()
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< Applicationcreate (const Glib::ustring & application_id=Glib::ustring(), Gio::ApplicationFlags flags=Gio::APPLICATION_FLAGS_NONE)
 Creates a new Application instance. More...
 
static Glib::RefPtr< Applicationcreate (int & argc, char **& argv, const Glib::ustring & application_id=Glib::ustring(), Gio::ApplicationFlags flags=Gio::APPLICATION_FLAGS_NONE)
 Creates a new Application instance. More...
 

Protected Member Functions

 Application (const Glib::ustring & application_id=Glib::ustring(), Gio::ApplicationFlags flags=Gio::APPLICATION_FLAGS_NONE)
 Creates a new Application instance. More...
 
 Application (int & argc, char **& argv, const Glib::ustring & application_id=Glib::ustring(), Gio::ApplicationFlags flags=Gio::APPLICATION_FLAGS_NONE)
 Creates a new Application instance. More...
 
virtual void on_window_added (Window * window)
 This is a default handler for the signal signal_window_added(). More...
 
virtual void on_window_removed (Window * window)
 This is a default handler for the signal signal_window_removed(). More...
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gtk::Applicationwrap (GtkApplication * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Detailed Description

The Gtk::Application class handles many important aspects of a GTK+ application in a convenient fashion, without enforcing a one-size-fits-all application model.

Currently, Gtk::Application handles GTK+ and gtkmm initialization, application uniqueness, session management, provides some basic scriptability and desktop shell integration by exporting actions and menus, and manages a list of toplevel windows whose life-cycle is automatically tied to the life-cycle of your application.

While Gtk::Application works fine with plain Gtk::Windows, it is recommended to use it together with Gtk::ApplicationWindow.

When GDK threads are enabled, Gtk::Application will acquire the GDK lock when invoking actions that arrive from other processes. The GDK lock is not touched for local action invocations. In order to have actions invoked in a predictable context it is therefore recommended that the GDK lock be held while invoking actions locally with Gio::ActionGroup::activate_action(). The same applies to actions associated with Gtk::ApplicationWindow and to the Gio::Application::activate() and Gio::Application::open() methods.

To set an application menu for a Gtk::Application, use set_app_menu(). The Gio::MenuModel that this method expects is usually constructed using Gtk::Builder. To specify a menubar that will be shown by Gtk::ApplicationWindows, use set_menubar(). Use the base Gio::ActionMap interface to add actions, to respond to the user selecting these menu items.

GTK+ displays these menus as expected, depending on the platform the application is running on.

Gtk::Application optionally registers with a session manager of the users session (if you set the register-session property) and offers various functionality related to the session life-cycle.

An application can block various ways to end the session with the inhibit() method. Typical use cases for this kind of inhibiting are long-running, uninterruptible operations, such as burning a CD or performing a disk backup. The session manager may not honor the inhibitor, but it can be expected to inform the user about the negative consequences of ending the session while inhibitors are present.

Since gtkmm 3.4:

Constructor & Destructor Documentation

◆ Application() [1/3]

Gtk::Application::Application ( Application &&  src)
noexcept

◆ ~Application()

Gtk::Application::~Application ( )
overridenoexcept

◆ Application() [2/3]

Gtk::Application::Application ( const Glib::ustring &  application_id = Glib::ustring(),
Gio::ApplicationFlags  flags = Gio::APPLICATION_FLAGS_NONE 
)
explicitprotected

Creates a new Application instance.

This initializes gtkmm (and the GObject type system) for you.

If non-empty, 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 gtkmm 3.6 or later.

Parameters
application_idA valid application ID.
flagsThe application flags.
Since gtkmm 3.4:

◆ Application() [3/3]

Gtk::Application::Application ( int &  argc,
char **&  argv,
const Glib::ustring &  application_id = Glib::ustring(),
Gio::ApplicationFlags  flags = Gio::APPLICATION_FLAGS_NONE 
)
explicitprotected

Creates a new Application instance.

This initializes gtkmm (and the GObject type system) for you, parsing the standard GTK+ command line arguments.

You could instead use the constructor that takes no command line arguments and later supply the command line arguments to run().

Note that all GTK+ functionality that is available via command line arguments can instead be achieved by setting suitable environment variables such as G_DEBUG.

If non-empty, 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 gtkmm 3.6 or later.

Parameters
argcThe parameter received by your main() function.
argvThe parameter received by your main() function.
application_idA valid application ID.
flagsThe application flags.
Since gtkmm 3.4:

Member Function Documentation

◆ add_accelerator() [1/2]

void Gtk::Application::add_accelerator ( const Glib::ustring &  accelerator,
const Glib::ustring &  action_name 
)

A add_accelerator() convenience overload.

◆ add_accelerator() [2/2]

void Gtk::Application::add_accelerator ( const Glib::ustring &  accelerator,
const Glib::ustring &  action_name,
GVariant *  parameter 
)

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 MenuModels passed to set_app_menu() and set_menubar(), which is usually more convenient than calling this function for each accelerator.

Since gtkmm 3.4:

Deprecated: 3.14: Use set_accels_for_action() instead

Deprecated:
Use set_accels_for_action() instead.
Parameters
acceleratorAccelerator string.
action_nameThe name of the action to activate.
parameterParameter to pass when activating the action, or nullptr if the action does not accept an activation parameter.

◆ add_window()

void Gtk::Application::add_window ( Window window)

Adds a window to the Gtk::Application.

If all the windows managed by Gtk::Application are closed (hidden) or removed from the application then the call to run() will return, unless Gio::Application::hold() has been called.

This call is equivalent to calling Gtk::Window::set_application(), except that run() does not return when a window added with Gtk::Window::set_application() is closed (hidden).

Normally, the connection between the application and the window will remain until the window is closed (hidden) or destroyed, but you can explicitly remove it with remove_window().

Note
If you call Gio::Application::quit() while a window is connected to the application, and then return from main() without removing the window from the application, the application's destructor will not be called.
Since gtkmm 3.4:
Parameters
windowA toplevel window to add to the application.

◆ create() [1/2]

static Glib::RefPtr< Application > Gtk::Application::create ( const Glib::ustring &  application_id = Glib::ustring(),
Gio::ApplicationFlags  flags = Gio::APPLICATION_FLAGS_NONE 
)
static

Creates a new Application instance.

This initializes gtkmm (and the GObject type system) for you.

If non-empty, 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 gtkmm 3.6 or later.

Parameters
application_idA valid application ID.
flagsThe application flags.
Since gtkmm 3.4:

◆ create() [2/2]

static Glib::RefPtr< Application > Gtk::Application::create ( int &  argc,
char **&  argv,
const Glib::ustring &  application_id = Glib::ustring(),
Gio::ApplicationFlags  flags = Gio::APPLICATION_FLAGS_NONE 
)
static

Creates a new Application instance.

This initializes gtkmm (and the GObject type system) for you, parsing the standard GTK+ command line arguments.

You could instead use the constructor that takes no command line arguments and later supply the command line arguments to run().

Note that all GTK+ functionality that is available via command line arguments can instead be achieved by setting suitable environment variables such as G_DEBUG.

If non-empty, 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 gtkmm 3.6 or later.

Parameters
argcThe parameter received by your main() function.
argvThe parameter received by your main() function.
application_idA valid application ID.
flagsThe application flags.
Since gtkmm 3.4:

◆ get_accels_for_action()

std::vector< Glib::ustring > Gtk::Application::get_accels_for_action ( const Glib::ustring &  detailed_action_name) const

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

Since gtkmm 3.12:
Parameters
detailed_action_nameA detailed action name, specifying an action and target to obtain accelerators for.
Returns
Accelerators for detailed_action_name, as a nullptr-terminated array.

◆ get_actions_for_accel()

std::vector< Glib::ustring > Gtk::Application::get_actions_for_accel ( const Glib::ustring &  accel) const

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

Since gtkmm 3.14:
Parameters
accelAn accelerator that can be parsed by gtk_accelerator_parse().
Returns
A nullptr-terminated array of actions for accel.

◆ get_active_window() [1/2]

Window * Gtk::Application::get_active_window ( )

Gets the “active” window for the application.

The active window is the one that was most recently focused (within the application). This window may not have the focus at the moment if another application has it — this is just the most recently-focused window within this application.

Since gtkmm 3.6:
Returns
The active window, or nullptr if there isn't one.

◆ get_active_window() [2/2]

const Window * Gtk::Application::get_active_window ( ) const

Gets the “active” window for the application.

The active window is the one that was most recently focused (within the application). This window may not have the focus at the moment if another application has it — this is just the most recently-focused window within this application.

Since gtkmm 3.6:
Returns
The active window, or nullptr if there isn't one.

◆ get_app_menu() [1/2]

Glib::RefPtr< Gio::MenuModel > Gtk::Application::get_app_menu ( )

Returns the menu model that has been set with set_app_menu().

Since gtkmm 3.4:
Returns
The application menu of application or nullptr if no application menu has been set.

◆ get_app_menu() [2/2]

Glib::RefPtr< const Gio::MenuModel > Gtk::Application::get_app_menu ( ) const

Returns the menu model that has been set with set_app_menu().

Since gtkmm 3.4:
Returns
The application menu of application or nullptr if no application menu has been set.

◆ get_menu_by_id() [1/2]

Glib::RefPtr< Gio::Menu > Gtk::Application::get_menu_by_id ( const Glib::ustring &  id)

Gets a menu from automatically loaded resources.

See [Automatic resources][automatic-resources] for more information.

Since gtkmm 3.14:
Parameters
idThe id of the menu to look up.
Returns
Gets the menu with the given id from the automatically loaded resources.

◆ get_menu_by_id() [2/2]

Glib::RefPtr< const Gio::Menu > Gtk::Application::get_menu_by_id ( const Glib::ustring &  id) const

Gets a menu from automatically loaded resources.

See [Automatic resources][automatic-resources] for more information.

Since gtkmm 3.14:
Parameters
idThe id of the menu to look up.
Returns
Gets the menu with the given id from the automatically loaded resources.

◆ get_menubar() [1/2]

Glib::RefPtr< Gio::MenuModel > Gtk::Application::get_menubar ( )

Returns the menu model that has been set with set_menubar().

Since gtkmm 3.4:
Returns
The menubar for windows of application.

◆ get_menubar() [2/2]

Glib::RefPtr< const Gio::MenuModel > Gtk::Application::get_menubar ( ) const

Returns the menu model that has been set with set_menubar().

Since gtkmm 3.4:
Returns
The menubar for windows of application.

◆ get_type()

static GType Gtk::Application::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ get_window_by_id() [1/2]

Window * Gtk::Application::get_window_by_id ( guint  id)

Returns the Gtk::ApplicationWindow with the given ID.

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

Since gtkmm 3.6:
Parameters
idAn identifier number.
Returns
The window with ID id, or nullptr if there is no window with this ID.

◆ get_window_by_id() [2/2]

const Window * Gtk::Application::get_window_by_id ( guint  id) const

Returns the Gtk::ApplicationWindow with the given ID.

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

Since gtkmm 3.6:
Parameters
idAn identifier number.
Returns
The window with ID id, or nullptr if there is no window with this ID.

◆ get_windows() [1/2]

std::vector< Window * > Gtk::Application::get_windows ( )

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.

Since gtkmm 3.0:
Returns
A List of Gtk::Window.

◆ get_windows() [2/2]

std::vector< const Window * > Gtk::Application::get_windows ( ) const

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.

Since gtkmm 3.0:
Returns
A List of Gtk::Window.

◆ gobj() [1/2]

GtkApplication * Gtk::Application::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GtkApplication * Gtk::Application::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GtkApplication * Gtk::Application::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ inhibit()

guint Gtk::Application::inhibit ( Window window,
ApplicationInhibitFlags  flags,
const Glib::ustring &  reason 
)

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

Since gtkmm 3.4:
Parameters
windowA Gtk::Window, or nullptr.
flagsWhat types of actions should be inhibited.
reasonA short, human-readable string that explains why these operations are inhibited.
Returns
A non-zero cookie that is used to uniquely identify this request. It should be used as an argument to 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()

bool Gtk::Application::is_inhibited ( ApplicationInhibitFlags  flags) const

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

Since gtkmm 3.4:
Parameters
flagsWhat types of actions should be queried.
Returns
true if any of the actions specified in flags are inhibited.

◆ list_action_descriptions()

std::vector< Glib::ustring > Gtk::Application::list_action_descriptions ( ) const

Lists the detailed action names which have associated accelerators.

See set_accels_for_action().

Since gtkmm 3.12:
Returns
A nullptr-terminated array of strings.

◆ on_window_added()

virtual void Gtk::Application::on_window_added ( Window window)
protectedvirtual

This is a default handler for the signal signal_window_added().

◆ on_window_removed()

virtual void Gtk::Application::on_window_removed ( Window window)
protectedvirtual

This is a default handler for the signal signal_window_removed().

◆ operator=()

Application & Gtk::Application::operator= ( Application &&  src)
noexcept

◆ prefers_app_menu()

bool Gtk::Application::prefers_app_menu ( ) const

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 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 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 set_app_menu() anyway, then this menu will be replaced with your own.

Since gtkmm 3.14:
Returns
true if you should set an app menu.

◆ property_active_window()

Glib::PropertyProxy_ReadOnly< Window * > Gtk::Application::property_active_window ( ) const

The window which most recently had focus.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_app_menu() [1/2]

Glib::PropertyProxy< Glib::RefPtr< Gio::MenuModel > > Gtk::Application::property_app_menu ( )

The GMenuModel for the application menu.

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_app_menu() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gio::MenuModel > > Gtk::Application::property_app_menu ( ) const

The GMenuModel for the application menu.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_menubar() [1/2]

Glib::PropertyProxy< Glib::RefPtr< Gio::MenuModel > > Gtk::Application::property_menubar ( )

The GMenuModel for the menubar.

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_menubar() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gio::MenuModel > > Gtk::Application::property_menubar ( ) const

The GMenuModel for the menubar.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_register_session() [1/2]

Glib::PropertyProxy< bool > Gtk::Application::property_register_session ( )

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

Since gtkmm 3.4:

Default value: false

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_register_session() [2/2]

Glib::PropertyProxy_ReadOnly< bool > Gtk::Application::property_register_session ( ) const

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

Since gtkmm 3.4:

Default value: false

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ remove_accelerator() [1/2]

void Gtk::Application::remove_accelerator ( const Glib::ustring &  action_name)

A remove_accelerator() convenience overload.

◆ remove_accelerator() [2/2]

void Gtk::Application::remove_accelerator ( const Glib::ustring &  action_name,
GVariant *  parameter 
)

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

Since gtkmm 3.4:

Deprecated: 3.14: Use set_accels_for_action() instead

Deprecated:
Use set_accels_for_action() or unset_accels_for_action() instead.
Parameters
action_nameThe name of the action to activate.
parameterParameter to pass when activating the action, or nullptr if the action does not accept an activation parameter.

◆ remove_window()

void Gtk::Application::remove_window ( Window window)

Remove a window from application.

If window belongs to application then this call is equivalent to setting the Gtk::Window::property_application() property of window to nullptr.

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

Since gtkmm 3.0:
Parameters
windowA Gtk::Window.

◆ run() [1/4]

int Gtk::Application::run ( )

Starts the application.

The default implementation of this virtual function will simply run a main loop.

It is an error to call this function if application is a proxy for a remote application.

Returns
The exit status.
Since gtkmm 3.4:

◆ run() [2/4]

int Gtk::Application::run ( int  argc,
char **  argv 
)

Starts the application.

The default implementation of this virtual function will simply run a main loop.

It is an error to call this function if application is a proxy for a remote application.

Parameters
argcThe argc from main() (or 0 if argv is 0).
argvThe argv from main(), or 0.
Returns
The exit status.
Since gtkmm 3.4:

◆ run() [3/4]

int Gtk::Application::run ( Window window)

Starts the application.

The default implementation of this virtual function will simply run a main loop.

It is an error to call this function if application is a proxy for a remote application.

Note
If you call Gio::Application::quit() while a window is connected to the application, and then return from main() without removing the window from the application, the application's destructor will not be called.
Parameters
windowThe window to show. This method will return when the window is hidden.
Returns
The exit status.
Since gtkmm 3.4:

◆ run() [4/4]

int Gtk::Application::run ( Window window,
int  argc,
char **  argv 
)

Starts the application.

The default implementation of this virtual function will simply run a main loop.

It is an error to call this function if application is a proxy for a remote application.

Note
If you call Gio::Application::quit() while a window is connected to the application, and then return from main() without removing the window from the application, the application's destructor will not be called.
Parameters
windowThe window to show. This method will return when the window is hidden.
argcThe argc from main() (or 0 if argv is 0).
argvThe argv from main(), or 0.
Returns
The exit status.
Since gtkmm 3.4:

◆ set_accel_for_action()

void Gtk::Application::set_accel_for_action ( const Glib::ustring &  detailed_action_name,
const Glib::ustring &  accel 
)

Sets a keyboard accelerator that will trigger the given action.

It will be the primary accelerator, which may be displayed in the UI.

See unset_accels_for_action().

Parameters
detailed_action_nameA detailed action name, specifying an action and target to associate accelerators with.
accelAn accelerator in the format understood by gtk_accelerator_parse().
Since gtkmm 3.12:

◆ set_accels_for_action()

void Gtk::Application::set_accels_for_action ( const Glib::ustring &  detailed_action_name,
const std::vector< Glib::ustring > &  accels 
)

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 Glib::action_parse_detailed_name() and Glib::action_print_detailed_name().

Since gtkmm 3.12:
Parameters
detailed_action_nameA detailed action name, specifying an action and target to associate accelerators with.
accelsA list of accelerators in the format understood by gtk_accelerator_parse().

◆ set_app_menu()

void Gtk::Application::set_app_menu ( const Glib::RefPtr< Gio::MenuModel > &  app_menu)

Sets or unsets the application menu for application.

This can only be done in the primary instance of the application, after it has been registered. Gio::Application::signal_startup() is a good place to call this.

The application menu is a single menu containing items that typically impact the application as a whole, rather than acting on a specific window or document. For example, you would expect to see “Preferences” or “Quit” in an application menu, but not “Save” or “Print”.

If supported, the application menu will be rendered by the desktop environment.

Use the base Gio::ActionMap interface to add actions, to respond to the user selecting these menu items.

Since gtkmm 3.4:
Parameters
app_menuA Gio::MenuModel, or nullptr.

◆ set_menubar()

void Gtk::Application::set_menubar ( const Glib::RefPtr< Gio::MenuModel > &  menubar)

Sets or unsets the menubar for windows of application.

This is a menubar in the traditional sense.

This can only be done in the primary instance of the application, after it has been registered. Gio::Application::signal_startup() is a good place to call this.

Depending on the desktop environment, this may appear at the top of each window, or at the top of the screen. In some environments, if both the application menu and the menubar are set, the application menu will be presented as if it were the first item of the menubar. Other environments treat the two as completely separate — for example, the application menu may be rendered by the desktop shell while the menubar (if set) remains in each individual window.

Use the base Gio::ActionMap interface to add actions, to respond to the user selecting these menu items.

Since gtkmm 3.4:
Parameters
menubarA Gio::MenuModel, or nullptr.

◆ signal_window_added()

Glib::SignalProxy< void, Window * > Gtk::Application::signal_window_added ( )
Slot Prototype:
void on_my_window_added(Window* window)

Flags: Run First

Emitted when a Gtk::Window is added to application through Gtk::Application::add_window().

Since gtkmm 3.2:
Parameters
windowThe newly-added Gtk::Window.

◆ signal_window_removed()

Glib::SignalProxy< void, Window * > Gtk::Application::signal_window_removed ( )
Slot Prototype:
void on_my_window_removed(Window* window)

Flags: Run First

Emitted when a Gtk::Window is removed from application, either as a side-effect of being destroyed or explicitly through Gtk::Application::remove_window().

Since gtkmm 3.2:
Parameters
windowThe Gtk::Window that is being removed.

◆ uninhibit()

void Gtk::Application::uninhibit ( guint  cookie)

Removes an inhibitor that has been established with inhibit().

Inhibitors are also cleared when the application exits.

Since gtkmm 3.4:
Parameters
cookieA cookie that was returned by inhibit().

◆ unset_accels_for_action()

void Gtk::Application::unset_accels_for_action ( const Glib::ustring &  detailed_action_name)

Unsets a keyboard accelerator that will trigger the given action.

See set_accels_for_action() and set_accel_for_action().

Parameters
detailed_action_nameA detailed action name, specifying an action and target to associate accelerators with.
Since gtkmm 3.12:

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gtk::Application > wrap ( GtkApplication *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.