gtkmm: Gtk::Application Class Reference

gtkmm 4.7.1

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

Application class. More...

`#include <gtkmm/application.h>`

Inheritance diagram for Gtk::Application:
[legend]

## Public Types
enum class | InhibitFlags { LOGOUT = (1 << 0) , SWITCH = (1 << 1) , SUSPEND = (1 << 2) , IDLE = (1 << 3) }
| Types of user actions that may be blocked by `Gtk::Application`. More...
Public Types inherited from Gio::Application
enum class | Flags { NONE , IS_SERVICE , IS_LAUNCHER , HANDLES_OPEN , HANDLES_COMMAND_LINE , SEND_ENVIRONMENT , NON_UNIQUE , CAN_OVERRIDE_APP_ID , ALLOW_REPLACEMENT , REPLACE }
enum class | OptionType { BOOL , STRING , INT , FILENAME , STRING_VECTOR , FILENAME_VECTOR , DOUBLE , INT64 }
typedef std::vector< Glib::RefPtr< File > > | type_vec_files
Public Types inherited from Glib::Object
typedef void(*)(gpointer data | DestroyNotify)
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify
Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify | func_destroy_notify
Public Types inherited from Gio::ActionMap
typedef sigc::slot< void()> | ActivateSlot
typedef sigc::slot< void(const Glib::VariantBase &)> | ActivateWithParameterSlot
typedef sigc::slot< void(const Glib::ustring &)> | ActivateWithStringParameterSlot
typedef sigc::slot< void(int)> | ActivateWithIntParameterSlot

## Public Member Functions
| Application (Application && src) noexcept
Application & | operator= (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::Window instances associated with `application`. More...
std::vector< const Window * > | get_windows () const
| Gets a list of the Gtk::Window instances 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 ()
| Starts the application. More...
template<typename T_Window , typename... T_Args>
int | make_window_and_run (int argc, char ** argv, T_Args &&... args)
| Starts the application, creates and presents a window. More...
Window * | get_run_window ()
| Get the window, constructed by make_window_and_run(). More...
const Window * | get_run_window () const
| Get the window, constructed by make_window_and_run(). 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...
guint | inhibit (Window & window, InhibitFlags 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 previously established. More...
Window * | get_window_by_id (guint id)
| Returns the Gtk::ApplicationWindow with the given ID. More...
const Window * | get_window_by_id (guint id) const
| Returns the Gtk::ApplicationWindow with the given ID. More...
Window * | get_active_window ()
| Gets the “active” window for the application. More...
const Window * | get_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...
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_menubar ()
| The `Gio::MenuModel` to be used for the application's menu bar. More...
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gio::MenuModel > > | property_menubar () const
| The `Gio::MenuModel` to be used for the application's menu bar. 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< bool > | property_screensaver_active () const
| This property is `true` if GTK believes that the screensaver is currently active. More...
Glib::PropertyProxy_ReadOnly< Window * > | property_active_window () const
| The currently focused window of the application. More...
Glib::SignalProxy< void(Window *)> | signal_window_added ()
Glib::SignalProxy< void(Window *)> | signal_window_removed ()
Glib::SignalProxy< void()> | signal_query_end ()
Public Member Functions inherited from Gio::Application
| Application (Application &&src) noexcept
Application & | operator= (Application &&src) noexcept
| ~Application () noexcept override
GApplication * | gobj ()
const GApplication * | gobj () const
GApplication * | gobj_copy ()
Glib::ustring | get_id () const
void | set_id (const Glib::ustring &application_id)
Glib::RefPtr< DBus::Connection > | get_dbus_connection ()
Glib::RefPtr< const DBus::Connection > | get_dbus_connection () const
Glib::ustring | get_dbus_object_path () const
guint | get_inactivity_timeout () const
void | set_inactivity_timeout (guint inactivity_timeout)
Flags | get_flags () const
void | set_flags (Flags flags)
std::string | get_resource_base_path () const
void | set_resource_base_path (const std::string &resource_path)
void | unset_resource_base_path ()
void | add_main_option_entry (OptionType arg_type, const Glib::ustring &long_name, gchar short_name='\0', const Glib::ustring &description={}, const Glib::ustring &arg_description={}, Glib::OptionEntry::Flags flags=Glib::OptionEntry::Flags::NONE)
void | add_main_option_entry (const Glib::OptionGroup::SlotOptionArgString &slot, const Glib::ustring &long_name, gchar short_name='\0', const Glib::ustring &description={}, const Glib::ustring &arg_description={}, Glib::OptionEntry::Flags flags=Glib::OptionEntry::Flags::NONE)
void | add_main_option_entry_filename (const Glib::OptionGroup::SlotOptionArgFilename &slot, const Glib::ustring &long_name, gchar short_name='\0', const Glib::ustring &description={}, const Glib::ustring &arg_description={}, Glib::OptionEntry::Flags flags=Glib::OptionEntry::Flags::NONE)
void | add_option_group (Glib::OptionGroup &group)
void | set_option_context_parameter_string (const Glib::ustring &parameter_string)
void | set_option_context_summary (const Glib::ustring &summary)
void | set_option_context_description (const Glib::ustring &description)
bool | is_registered () const
bool | is_remote () const
bool | register_application (const Glib::RefPtr< Gio::Cancellable > &cancellable)
bool | register_application ()
void | hold ()
void | release ()
void | activate ()
void | open (const type_vec_files &files, const Glib::ustring &hint={})
void | open (const Glib::RefPtr< Gio::File > &file, const Glib::ustring &hint={})
int | run (int argc, char **argv)
void | quit ()
void | mark_busy ()
void | unmark_busy ()
bool | get_is_busy () const
void | send_notification (const Glib::ustring &id, const Glib::RefPtr< Notification > &notification)
void | send_notification (const Glib::RefPtr< Notification > &notification)
void | withdraw_notification (const Glib::ustring &id)
Glib::PropertyProxy< Glib::ustring > | property_application_id ()
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_application_id () const
Glib::PropertyProxy< Flags > | property_flags ()
Glib::PropertyProxy_ReadOnly< Flags > | property_flags () const
Glib::PropertyProxy< guint > | property_inactivity_timeout ()
Glib::PropertyProxy_ReadOnly< guint > | property_inactivity_timeout () const
Glib::PropertyProxy_ReadOnly< bool > | property_is_registered () const
Glib::PropertyProxy_ReadOnly< bool > | property_is_remote () const
Glib::PropertyProxy< std::string > | property_resource_base_path ()
Glib::PropertyProxy_ReadOnly< std::string > | property_resource_base_path () const
Glib::PropertyProxy_ReadOnly< bool > | property_is_busy () const
Glib::SignalProxy< void()> | signal_startup ()
Glib::SignalProxy< void()> | signal_shutdown ()
Glib::SignalProxy< void()> | signal_activate ()
Glib::SignalProxy< void(const type_vec_files &, const Glib::ustring &)> | signal_open ()
Glib::SignalProxy< int(const Glib::RefPtr< ApplicationCommandLine > &)> | signal_command_line ()
Glib::SignalProxy< int(const Glib::RefPtr< Glib::VariantDict > &)> | signal_handle_local_options ()
Glib::SignalProxy< bool()> | signal_name_lost ()
Glib::RefPtr< Gio::Application > | wrap (GApplication *object, bool take_copy=false)
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object &&src) noexcept
Object & | operator= (Object &&src) noexcept
void * | get_data (const QueryQuark &key)
void | set_data (const Quark &key, void *data)
void | set_data (const Quark &key, void *data, DestroyNotify notify)
void | remove_data (const QueryQuark &quark)
void * | steal_data (const QueryQuark &quark)
Glib::RefPtr< Glib::Object > | wrap (GObject *object, bool take_copy=false)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType | get_property (const Glib::ustring &property_name) const
sigc::connection | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection | connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src) noexcept
| ~trackable ()
void | add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src) noexcept
void | remove_destroy_notify_callback (notifiable *data) const
Public Member Functions inherited from Gio::ActionGroup
| ActionGroup (ActionGroup &&src) noexcept
ActionGroup & | operator= (ActionGroup &&src) noexcept
| ~ActionGroup () noexcept override
GActionGroup * | gobj ()
const GActionGroup * | gobj () const
bool | has_action (const Glib::ustring &action_name) const
std::vector< Glib::ustring > | list_actions () const
bool | query_action (const Glib::ustring &action_name, bool &enabled, Glib::VariantType &parameter_type, Glib::VariantBase &state_hint, Glib::VariantType &state_type, Glib::VariantBase &state)
bool | query_action (const Glib::ustring &action_name, bool &enabled, Glib::VariantType &parameter_type, Glib::VariantBase &state_hint, Glib::VariantType &state_type)
bool | query_action (const Glib::ustring &action_name, bool &enabled, Glib::VariantType &parameter_type, Glib::VariantBase &state_hint, Glib::VariantBase &state)
bool | query_action (const Glib::ustring &action_name, bool &enabled, Glib::VariantType &parameter_type, Glib::VariantBase &state_hint)
bool | query_action (const Glib::ustring &action_name, bool &enabled, Glib::VariantBase &state_hint, Glib::VariantType &state_type, Glib::VariantBase &state)
bool | query_action (const Glib::ustring &action_name, bool &enabled, Glib::VariantBase &state_hint, Glib::VariantType &state_type)
bool | query_action (const Glib::ustring &action_name, bool &enabled, Glib::VariantBase &state_hint, Glib::VariantBase &state)
bool | query_action (const Glib::ustring &action_name, bool &enabled, Glib::VariantBase &state_hint)
bool | get_action_enabled (const Glib::ustring &action_name) const
Glib::VariantType | get_action_parameter_type (const Glib::ustring &action_name) const
Glib::VariantType | get_action_state_type (const Glib::ustring &action_name) const
void | get_action_state_hint (const Glib::ustring &action_name, T_Value &value) const
Glib::VariantContainerBase | get_action_state_hint_variant (const Glib::ustring &action_name) const
void | get_action_state (const Glib::ustring &action_name, T_Value &value) const
Glib::VariantBase | get_action_state_variant (const Glib::ustring &action_name) const
void | change_action_state (const Glib::ustring &action_name, const Glib::VariantBase &value)
void | activate_action (const Glib::ustring &action_name, const Glib::VariantBase &parameter)
void | activate_action (const Glib::ustring &action_name)
void | action_added (const Glib::ustring &action_name)
void | action_removed (const Glib::ustring &action_name)
void | action_enabled_changed (const Glib::ustring &action_name, bool enabled)
void | action_state_changed (const Glib::ustring &action_name, const Glib::VariantBase &state)
Glib::SignalProxyDetailed< void(const Glib::ustring &)> | signal_action_added (const Glib::ustring &action_name={})
Glib::SignalProxyDetailed< void(const Glib::ustring &, bool)> | signal_action_enabled_changed (const Glib::ustring &action_name={})
Glib::SignalProxyDetailed< void(const Glib::ustring &)> | signal_action_removed (const Glib::ustring &action_name={})
Glib::SignalProxyDetailed< void(const Glib::ustring &, const Glib::VariantBase &)> | signal_action_state_changed (const Glib::ustring &action_name={})
Glib::RefPtr< Gio::ActionGroup > | wrap (GActionGroup *object, bool take_copy=false)
Public Member Functions inherited from Glib::Interface
| Interface ()
| Interface (Interface &&src) noexcept
Interface & | operator= (Interface &&src) noexcept
| Interface (const Glib::Interface_Class &interface_class)
| Interface (GObject *castitem)
| ~Interface () noexcept override
| Interface (const Interface &)=delete
Interface & | operator= (const Interface &)=delete
GObject * | gobj ()
const GObject * | gobj () const
Public Member Functions inherited from Gio::ActionMap
| ActionMap (ActionMap &&src) noexcept
ActionMap & | operator= (ActionMap &&src) noexcept
| ~ActionMap () noexcept override
GActionMap * | gobj ()
const GActionMap * | gobj () const
void | add_action (const Glib::RefPtr< Action > &action)
void | remove_action (const Glib::ustring &action_name)
Glib::RefPtr< Action > | lookup_action (const Glib::ustring &action_name)
Glib::RefPtr< const Action > | lookup_action (const Glib::ustring &action_name) const
Glib::RefPtr< SimpleAction > | add_action (const Glib::ustring &name)
Glib::RefPtr< SimpleAction > | add_action (const Glib::ustring &name, const ActivateSlot &slot)
Glib::RefPtr< SimpleAction > | add_action_with_parameter (const Glib::ustring &name, const Glib::VariantType &parameter_type, const ActivateWithParameterSlot &slot)
Glib::RefPtr< SimpleAction > | add_action_bool (const Glib::ustring &name, bool state=false)
Glib::RefPtr< SimpleAction > | add_action_bool (const Glib::ustring &name, const ActivateSlot &slot, bool state=false)
Glib::RefPtr< SimpleAction > | add_action_radio_string (const Glib::ustring &name, const Glib::ustring &state)
Glib::RefPtr< SimpleAction > | add_action_radio_string (const Glib::ustring &name, const ActivateWithStringParameterSlot &slot, const Glib::ustring &state)
Glib::RefPtr< SimpleAction > | add_action_radio_integer (const Glib::ustring &name, gint32 state)
Glib::RefPtr< SimpleAction > | add_action_radio_integer (const Glib::ustring &name, const ActivateWithIntParameterSlot &slot, gint32 state)
Glib::RefPtr< Gio::ActionMap > | wrap (GActionMap *object, bool take_copy=false)

## 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< Application > | create (const Glib::ustring & application_id={}, Gio::Application::Flags flags=Gio::Application::Flags::NONE)
| Creates a new Application instance. More...
Static Public Member Functions inherited from Gio::Application
static GType | get_type ()
static Glib::RefPtr< Application > | create (const Glib::ustring &application_id={}, Flags flags=Flags::NONE)
static bool | id_is_valid (const Glib::ustring &application_id)
static void | set_default (const Glib::RefPtr< Application > &application)
static void | unset_default ()
static Glib::RefPtr< Application > | get_default ()
Static Public Member Functions inherited from Gio::ActionGroup
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
Static Public Member Functions inherited from Gio::ActionMap
static void | add_interface (GType gtype_implementer)
static GType | get_type ()

## Protected Member Functions
| Application (const Glib::ustring & application_id={}, Gio::Application::Flags 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...
Protected Member Functions inherited from Gio::Application
| Application (const Glib::ustring &application_id={}, Flags flags=Flags::NONE)
virtual void | on_open (const type_vec_files &files, const Glib::ustring &hint)
virtual bool | local_command_line_vfunc (char **&arguments, int &exit_status)
virtual void | before_emit_vfunc (const Glib::VariantBase &platform_data)
virtual void | after_emit_vfunc (const Glib::VariantBase &platform_data)
virtual void | quit_mainloop_vfunc ()
virtual void | run_mainloop_vfunc ()
virtual bool | dbus_register_vfunc (const Glib::RefPtr< DBus::Connection > &connection, const Glib::ustring &object_path)
virtual void | dbus_unregister_vfunc (const Glib::RefPtr< DBus::Connection > &connection, const Glib::ustring &object_path)
virtual void | on_startup ()
virtual void | on_shutdown ()
virtual void | on_activate ()
virtual int | on_command_line (const Glib::RefPtr< ApplicationCommandLine > &command_line)
virtual int | on_handle_local_options (const Glib::RefPtr< Glib::VariantDict > &options)
virtual bool | on_name_lost ()
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams &construct_params)
| Object (GObject *castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)
Protected Member Functions inherited from Gio::ActionGroup
| ActionGroup ()
virtual bool | has_action_vfunc (const Glib::ustring &name) const
virtual std::vector< Glib::ustring > | list_actions_vfunc () const
virtual bool | get_action_enabled_vfunc (const Glib::ustring &name) const
virtual Glib::VariantType | get_action_parameter_type_vfunc (const Glib::ustring &name) const
virtual Glib::VariantType | get_action_state_type_vfunc (const Glib::ustring &name) const
virtual Glib::VariantBase | get_action_state_hint_vfunc (const Glib::ustring &name) const
virtual Glib::VariantBase | get_action_state_vfunc (const Glib::ustring &name) const
virtual void | change_action_state_vfunc (const Glib::ustring &name, const Glib::VariantBase &value)
virtual void | activate_action_vfunc (const Glib::ustring &name, const Glib::VariantBase &parameter)
virtual void | on_action_added (const Glib::ustring &action_name)
virtual void | on_action_enabled_changed (const Glib::ustring &action_name, bool enabled)
virtual void | on_action_removed (const Glib::ustring &action_name)
virtual void | on_action_state_changed (const Glib::ustring &action_name, const Glib::VariantBase &value)
Protected Member Functions inherited from Gio::ActionMap
| ActionMap ()
virtual Glib::RefPtr< Action > | lookup_action_vfunc (const Glib::ustring &name) const
virtual void | add_action_vfunc (const Glib::RefPtr< Action > &action) const
virtual void | remove_action_vfunc (const Glib::ustring &name)

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gtk::Application > | wrap (GtkApplication * object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Detailed Description

Application class.

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

Note
  Most widgets can't safely be created before the application has been registered (Gio::Application::register_application() called) or activated (Gio::Application::signal_activate() emitted). They can't safely be deleted after run() or make_window_and_run() returns.

Since gtkmm 3.4:

## Constructor & Destructor Documentation

## ◆ Application() [1/2]

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

## ◆ ~Application()

Gtk::Application::~Application | ( |  | ) |
| overridenoexcept

## ◆ Application() [2/2]

Gtk::Application::Application | ( | const Glib::ustring & | application_id = `{}`,
|  | Gio::Application::Flags | flags = `Gio::Application::Flags::NONE`
| ) |  |
| explicitprotected

Creates a new Application instance.

This initializes gtkmm (and the GObject type system) for you. The global locale is set as specified by Glib::set_init_to_users_preferred_locale().

If non-empty, the application ID must be valid. See Gio::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_id | A valid application ID.
  flags | The application flags.

Since gtkmm 3.4:

## Member Function Documentation

## ◆ 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().

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

  window | A toplevel window to add to the application.

## ◆ create()

static Glib::RefPtr<Application> Gtk::Application::create | ( | const Glib::ustring & | application_id = `{}`,
|  | Gio::Application::Flags | flags = `Gio::Application::Flags::NONE`
| ) |  |
| static

Creates a new Application instance.

This initializes gtkmm (and the GObject type system) for you. The global locale is set as specified by Glib::set_init_to_users_preferred_locale().

If non-empty, the application ID must be valid. See Gio::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_id | A valid application ID.
  flags | The 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.

Parameters

  detailed_action_name | A detailed action name, specifying an action and target to obtain accelerators for.

Returns
  Accelerators for `detailed_action_name`.

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

Parameters

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

Returns
  The active window.

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

Returns
  The active window.

## ◆ 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 the section on Automatic resources for more information.

Parameters

  id | The 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 the section on Automatic resources for more information.

Parameters

  id | The 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().

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

Returns
  The menubar for windows of `application`.

## ◆ get_run_window() [1/2]

Window* Gtk::Application::get_run_window | ( |  | ) |
| inline

Get the window, constructed by make_window_and_run().

## ◆ get_run_window() [2/2]

const Window* Gtk::Application::get_run_window | ( |  | ) | const
| inline

Get the window, constructed by make_window_and_run().

## ◆ 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().

Parameters

  id | An identifier number.

Returns
  The window for the given `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().

Parameters

  id | An identifier number.

Returns
  The window for the given `id`.

## ◆ get_windows() [1/2]

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

Gets a list of the Gtk::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
  A `GList` of `Gtk::Window` instances.

## ◆ get_windows() [2/2]

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

Gets a list of the Gtk::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
  A `GList` of `Gtk::Window` instances.

## ◆ 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,
|  | InhibitFlags | 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.

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 | A `Gtk::Window`.
  flags | What types of actions should be inhibited.
  reason | A 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.

## ◆ 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().

Returns
  The detailed action names.

## ◆ make_window_and_run()

template <typename T_Window , typename... T_Args>

int Gtk::Application::make_window_and_run | ( | int | argc,
|  | char ** | argv,
|  | T_Args &&... | args
| ) |  |

Starts the application, creates and presents a window.

A window of type T_Window is constructed and added to the application in a signal_activate() handler. The window is deleted when it is hidden or removed from the application. The method returns when the window is hidden, unless other windows have been added but not removed.

The window is only constructed on the first activate signal. Any activations thereafter only cause the window to be raised.

Template Parameters

  T_Window | The type of window to present. Must be Gtk::Window or a class type that inherits from Gtk::Window.

Parameters

  argc | The argc from main() (or 0 if argv is `nullptr`).
  argv | The argv from main(), or `nullptr`.
  args | Arguments to T_Window's constructor, if any.

Returns
  The exit status.

See also
  Gio::Application::run()

Since gtkmm 3.98:

## ◆ 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

## ◆ property_active_window()

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

The currently focused window of the application.

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 `Gio::MenuModel` to be used for the application's menu bar.

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 `Gio::MenuModel` to be used for the application's menu bar.

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.

This will make GTK track the session state (such as the property_screensaver_active() property).

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.

This will make GTK track the session state (such as the property_screensaver_active() property).

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.

## ◆ property_screensaver_active()

Glib::PropertyProxy_ReadOnly< bool > Gtk::Application::property_screensaver_active | ( |  | ) | const

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

GTK only tracks session state (including this) when property_register_session() is set to `true`.

Tracking the screensaver state is currently only supported on Linux.

Since gtkmm 3.94:

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_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, if `window` was the last window of the `application`.

Parameters

  window | A `Gtk::Window`.

## ◆ run() [1/2]

int Gtk::Application::run | ( |  | ) |

Starts the application.

Returns
  The exit status.

See also
  Gio::Application::run()

Since gtkmm 3.4:

## ◆ run() [2/2]

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

Starts the application.

Parameters

  argc | The argc from main() (or 0 if argv is `nullptr`).
  argv | The argv from main(), or `nullptr`.

Returns
  The exit status.

See also
  Gio::Application::run()

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_name | A detailed action name, specifying an action and target to associate accelerators with.
  accel | An 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()`.

Parameters

  detailed_action_name | A detailed action name, specifying an action and target to associate accelerators with.
  accels | A list of accelerators in the format understood by gtk_accelerator_parse().

## ◆ 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. `GApplication::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.

Parameters

  menubar | A `Gio::MenuModel`.

## ◆ signal_query_end()

Glib::SignalProxy<void()> Gtk::Application::signal_query_end | ( |  | ) |

Slot Prototype:
  `void on_my_query_end()`

Flags: Run First

Emitted when the session manager is about to end the session.

This signal is only emitted if property_register_session() is `true`. Applications can connect to this signal and call Gtk::Application::inhibit() with `Gtk::Application::InhibitFlags::LOGOUT` to delay the end of the session until state has been saved.

## ◆ 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().

Parameters

  window | The 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`.

This can happen as a side-effect of the window being destroyed or explicitly through Gtk::Application::remove_window().

Parameters

  window | The Gtk::Window that is being removed.

## ◆ uninhibit()

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

Removes an inhibitor that has been previously established.

See inhibit().

Inhibitors are also cleared when the application exits.

Parameters

  cookie | A 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_name | A 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

  object | The C instance.
  take_copy | False 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.