gtkmm 4.15.1
|
Application class. More...
#include <gtkmm/application.h>
Public Types | |
enum class | InhibitFlags { LOGOUT = (1 << 0) , SWITCH = (1 << 1) , SUSPEND = (1 << 2) , IDLE = (1 << 3) } |
Public Member Functions | |
Application (Application &&src) noexcept | |
Application & | operator= (Application &&src) noexcept |
~Application () noexcept override | |
GtkApplication * | gobj () |
Provides access to the underlying C GObject. | |
const GtkApplication * | gobj () const |
Provides access to the underlying C GObject. | |
GtkApplication * | gobj_copy () |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. | |
std::vector< Window * > | get_windows () |
Gets a list of the Gtk::Window instances associated with application . | |
std::vector< const Window * > | get_windows () const |
Gets a list of the Gtk::Window instances associated with application . | |
void | add_window (Window &window) |
Adds a window to the Gtk::Application. | |
void | remove_window (Window &window) |
Remove a window from application . | |
int | run (int argc, char **argv) |
Starts the application. | |
int | run () |
Starts the application. | |
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. | |
Window * | get_run_window () |
Get the window, constructed by make_window_and_run(). | |
const Window * | get_run_window () const |
Get the window, constructed by make_window_and_run(). | |
Glib::RefPtr< Gio::MenuModel > | get_menubar () |
Returns the menu model that has been set with set_menubar(). | |
Glib::RefPtr< const Gio::MenuModel > | get_menubar () const |
Returns the menu model that has been set with set_menubar(). | |
void | set_menubar (const Glib::RefPtr< Gio::MenuModel > &menubar) |
Sets or unsets the menubar for windows of application . | |
guint | inhibit (Window &window, InhibitFlags flags, const Glib::ustring &reason) |
Inform the session manager that certain types of actions should be inhibited. | |
void | uninhibit (guint cookie) |
Removes an inhibitor that has been previously established. | |
Window * | get_window_by_id (guint id) |
Returns the Gtk::ApplicationWindow with the given ID. | |
const Window * | get_window_by_id (guint id) const |
Returns the Gtk::ApplicationWindow with the given ID. | |
Window * | get_active_window () |
Gets the “active” window for the application. | |
const Window * | get_active_window () const |
Gets the “active” window for the application. | |
std::vector< Glib::ustring > | list_action_descriptions () const |
Lists the detailed action names which have associated accelerators. | |
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. | |
std::vector< Glib::ustring > | get_actions_for_accel (const Glib::ustring &accel) const |
Returns the list of actions (possibly empty) that accel maps to. | |
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. | |
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. | |
void | unset_accels_for_action (const Glib::ustring &detailed_action_name) |
Unsets a keyboard accelerator that will trigger the given action. | |
Glib::RefPtr< Gio::Menu > | get_menu_by_id (const Glib::ustring & id) |
Gets a menu from automatically loaded resources. | |
Glib::RefPtr< const Gio::Menu > | get_menu_by_id (const Glib::ustring & id) const |
Gets a menu from automatically loaded resources. | |
Glib::PropertyProxy< Glib::RefPtr< Gio::MenuModel > > | property_menubar () |
The Gio::MenuModel to be used for the application's menu bar. | |
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gio::MenuModel > > | property_menubar () const |
The Gio::MenuModel to be used for the application's menu bar. | |
Glib::PropertyProxy< bool > | property_register_session () |
Set this property to true to register with the session manager. | |
Glib::PropertyProxy_ReadOnly< bool > | property_register_session () const |
Set this property to true to register with the session manager. | |
Glib::PropertyProxy_ReadOnly< bool > | property_screensaver_active () const |
This property is true if GTK believes that the screensaver is currently active. | |
Glib::PropertyProxy_ReadOnly< Window * > | property_active_window () const |
The currently focused window of the application. | |
Glib::SignalProxy< void(Window *)> | signal_window_added () |
Glib::SignalProxy< void(Window *)> | signal_window_removed () |
Glib::SignalProxy< void()> | signal_query_end () |
Static Public Member Functions | |
static GType | get_type () |
Get the GType for this class, for use with the underlying GObject type system. | |
static void | wrap_in_search_entry2 (bool search_entry2=true) |
Choose which SearchEntry to use. | |
static Glib::RefPtr< Application > | create (const Glib::ustring &application_id={}, Gio::Application::Flags flags=Gio::Application::Flags::NONE) |
Creates a new Application instance. | |
Protected Member Functions | |
Application (const Glib::ustring &application_id={}, Gio::Application::Flags flags=Gio::Application::Flags::NONE) | |
Creates a new Application instance. | |
virtual void | on_window_added (Window *window) |
This is a default handler for the signal signal_window_added(). | |
virtual void | on_window_removed (Window *window) |
This is a default handler for the signal signal_window_removed(). | |
Related Symbols | |
(Note that these are not member symbols.) | |
Glib::RefPtr< Gtk::Application > | wrap (GtkApplication *object, bool take_copy=false) |
A Glib::wrap() method for this object. | |
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.
|
noexcept |
|
overridenoexcept |
|
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.
application_id | A valid application ID. |
flags | The application flags. |
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().
window | A toplevel window to add to the application. |
|
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.
application_id | A valid application ID. |
flags | The application flags. |
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.
detailed_action_name | A detailed action name, specifying an action and target to obtain accelerators for. |
detailed_action_name
. 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.
accel | An accelerator that can be parsed by gtk_accelerator_parse(). |
nullptr
-terminated array of actions for accel
. 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.
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.
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.
id | The id of the menu to look up. |
Gets a menu from automatically loaded resources.
See the section on Automatic resources for more information.
id | The id of the menu to look up. |
Glib::RefPtr< Gio::MenuModel > Gtk::Application::get_menubar | ( | ) |
Returns the menu model that has been set with set_menubar().
application
. Glib::RefPtr< const Gio::MenuModel > Gtk::Application::get_menubar | ( | ) | const |
Returns the menu model that has been set with set_menubar().
application
.
|
inline |
Get the window, constructed by make_window_and_run().
Get the window, constructed by make_window_and_run().
|
static |
Get the GType for this class, for use with the underlying GObject type system.
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().
id | An identifier number. |
id
. Returns the Gtk::ApplicationWindow with the given ID.
The ID of a Gtk::ApplicationWindow
can be retrieved with Gtk::ApplicationWindow::get_id().
id | An identifier number. |
id
. 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.
GList
of Gtk::Window
instances. 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.
GList
of Gtk::Window
instances.
|
inline |
Provides access to the underlying C GObject.
|
inline |
Provides access to the underlying C GObject.
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.
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.
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. |
std::vector< Glib::ustring > Gtk::Application::list_action_descriptions | ( | ) | const |
Lists the detailed action names which have associated accelerators.
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.
T_Window | The type of window to present. Must be Gtk::Window or a class type that inherits from Gtk::Window. |
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. |
This is a default handler for the signal signal_window_added().
This is a default handler for the signal signal_window_removed().
|
noexcept |
Glib::PropertyProxy_ReadOnly< Window * > Gtk::Application::property_active_window | ( | ) | const |
The currently focused window of the application.
Glib::PropertyProxy< Glib::RefPtr< Gio::MenuModel > > Gtk::Application::property_menubar | ( | ) |
The Gio::MenuModel
to be used for the application's menu bar.
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gio::MenuModel > > Gtk::Application::property_menubar | ( | ) | const |
The Gio::MenuModel
to be used for the application's menu bar.
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
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
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.
Default value: false
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
.
window | A Gtk::Window . |
int Gtk::Application::run | ( | ) |
int Gtk::Application::run | ( | int | argc, |
char ** | argv | ||
) |
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().
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(). |
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()
.
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(). |
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.
menubar | A Gio::MenuModel . |
Glib::SignalProxy< void()> Gtk::Application::signal_query_end | ( | ) |
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.
void on_my_window_added(Window* window)
Flags: Run First
Emitted when a Gtk::Window is added to application
through Gtk::Application::add_window().
window | The newly-added Gtk::Window. |
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().
window | The Gtk::Window that is being removed. |
void Gtk::Application::uninhibit | ( | guint | cookie | ) |
Unsets a keyboard accelerator that will trigger the given action.
See set_accels_for_action() and set_accel_for_action().
detailed_action_name | A detailed action name, specifying an action and target to associate accelerators with. |
Choose which SearchEntry to use.
There are two classes to choose from when a pointer to a GtkSearchEntry object comes from a gtk function (for instance in GtkBuilder), and a C++ wrapper shall be created: Gtk::SearchEntry or Gtk::SearchEntry2.
To have any effect, this function must be called before any Gtk::Application instance is created, typically early in the main() function. Not calling this function has the same effect as calling it with search_entry2 = false
.
This nuisance has become necessary due to a bug in gtkmm4. The bug can't be fixed by correcting SearchEntry. It would break both ABI and API, and some working applications.
search_entry2 | If true , a GtkSearchEntry will be wrapped in a Gtk::SearchEntry2. If false , a GtkSearchEntry will be wrapped in a Gtk::SearchEntry. |
|
related |
A Glib::wrap() method for this object.
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. |