Skip to main content

gtk/auto/
application.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ApplicationInhibitFlags, Window, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// [`Application`][crate::Application] is a class that handles many important aspects
16    /// of a GTK+ application in a convenient fashion, without enforcing
17    /// a one-size-fits-all application model.
18    ///
19    /// Currently, GtkApplication handles GTK+ initialization, application
20    /// uniqueness, session management, provides some basic scriptability and
21    /// desktop shell integration by exporting actions and menus and manages a
22    /// list of toplevel windows whose life-cycle is automatically tied to the
23    /// life-cycle of your application.
24    ///
25    /// While GtkApplication works fine with plain `GtkWindows`, it is recommended
26    /// to use it together with [`ApplicationWindow`][crate::ApplicationWindow].
27    ///
28    /// When GDK threads are enabled, GtkApplication will acquire the GDK
29    /// lock when invoking actions that arrive from other processes. The GDK
30    /// lock is not touched for local action invocations. In order to have
31    /// actions invoked in a predictable context it is therefore recommended
32    /// that the GDK lock be held while invoking actions locally with
33    /// [`ActionGroupExtManual::activate_action()`][crate::gio::prelude::ActionGroupExtManual::activate_action()]. The same applies to actions
34    /// associated with [`ApplicationWindow`][crate::ApplicationWindow] and to the “activate” and
35    /// “open” [`gio::Application`][crate::gio::Application] methods.
36    ///
37    /// ## Automatic resources ## {`automatic`-resources}
38    ///
39    /// [`Application`][crate::Application] will automatically load menus from the [`Builder`][crate::Builder]
40    /// resource located at "gtk/menus.ui", relative to the application's
41    /// resource base path (see [`ApplicationExtManual::set_resource_base_path()`][crate::gio::prelude::ApplicationExtManual::set_resource_base_path()]). The
42    /// menu with the ID "app-menu" is taken as the application's app menu
43    /// and the menu with the ID "menubar" is taken as the application's
44    /// menubar. Additional menus (most interesting submenus) can be named
45    /// and accessed via [`GtkApplicationExt::menu_by_id()`][crate::prelude::GtkApplicationExt::menu_by_id()] which allows for
46    /// dynamic population of a part of the menu structure.
47    ///
48    /// If the resources "gtk/menus-appmenu.ui" or "gtk/menus-traditional.ui" are
49    /// present then these files will be used in preference, depending on the value
50    /// of [`GtkApplicationExt::prefers_app_menu()`][crate::prelude::GtkApplicationExt::prefers_app_menu()]. If the resource "gtk/menus-common.ui"
51    /// is present it will be loaded as well. This is useful for storing items that
52    /// are referenced from both "gtk/menus-appmenu.ui" and
53    /// "gtk/menus-traditional.ui".
54    ///
55    /// It is also possible to provide the menus manually using
56    /// [`GtkApplicationExt::set_app_menu()`][crate::prelude::GtkApplicationExt::set_app_menu()] and [`GtkApplicationExt::set_menubar()`][crate::prelude::GtkApplicationExt::set_menubar()].
57    ///
58    /// [`Application`][crate::Application] will also automatically setup an icon search path for
59    /// the default icon theme by appending "icons" to the resource base
60    /// path. This allows your application to easily store its icons as
61    /// resources. See [`IconThemeExt::add_resource_path()`][crate::prelude::IconThemeExt::add_resource_path()] for more
62    /// information.
63    ///
64    /// If there is a resource located at "gtk/help-overlay.ui" which
65    /// defines a [`ShortcutsWindow`][crate::ShortcutsWindow] with ID "help_overlay" then GtkApplication
66    /// associates an instance of this shortcuts window with each
67    /// [`ApplicationWindow`][crate::ApplicationWindow] and sets up keyboard accelerators (Control-F1
68    /// and Control-?) to open it. To create a menu item that displays the
69    /// shortcuts window, associate the item with the action win.show-help-overlay.
70    ///
71    /// ## A simple application ## {`gtkapplication`}
72    ///
73    /// [A simple example](https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/examples/bp/bloatpad.c)
74    ///
75    /// GtkApplication optionally registers with a session manager
76    /// of the users session (if you set the [`register-session`][struct@crate::Application#register-session]
77    /// property) and offers various functionality related to the session
78    /// life-cycle.
79    ///
80    /// An application can block various ways to end the session with
81    /// the [`GtkApplicationExt::inhibit()`][crate::prelude::GtkApplicationExt::inhibit()] function. Typical use cases for
82    /// this kind of inhibiting are long-running, uninterruptible operations,
83    /// such as burning a CD or performing a disk backup. The session
84    /// manager may not honor the inhibitor, but it can be expected to
85    /// inform the user about the negative consequences of ending the
86    /// session while inhibitors are present.
87    ///
88    /// ## See Also ## {`seealso`}
89    /// [HowDoI: Using GtkApplication](https://wiki.gnome.org/HowDoI/GtkApplication),
90    /// [Getting Started with GTK+: Basics](https://developer.gnome.org/gtk3/stable/gtk-getting-started.html`id`-1.2.3.3)
91    ///
92    /// ## Properties
93    ///
94    ///
95    /// #### `active-window`
96    ///  Readable
97    ///
98    ///
99    /// #### `app-menu`
100    ///  Readable | Writable
101    ///
102    ///
103    /// #### `menubar`
104    ///  Readable | Writable
105    ///
106    ///
107    /// #### `register-session`
108    ///  Set this property to [`true`] to register with the session manager.
109    ///
110    /// Readable | Writable
111    ///
112    ///
113    /// #### `screensaver-active`
114    ///  This property is [`true`] if GTK+ believes that the screensaver is
115    /// currently active. GTK+ only tracks session state (including this)
116    /// when [`register-session`][struct@crate::Application#register-session] is set to [`true`].
117    ///
118    /// Tracking the screensaver state is supported on Linux.
119    ///
120    /// Readable
121    /// <details><summary><h4>Application</h4></summary>
122    ///
123    ///
124    /// #### `action-group`
125    ///  The group of actions that the application exports.
126    ///
127    /// Writable
128    ///
129    ///
130    /// #### `application-id`
131    ///  The unique identifier for the application.
132    ///
133    /// Readable | Writable | Construct
134    ///
135    ///
136    /// #### `flags`
137    ///  Flags specifying the behaviour of the application.
138    ///
139    /// Readable | Writable
140    ///
141    ///
142    /// #### `inactivity-timeout`
143    ///  Time (in milliseconds) to stay alive after becoming idle.
144    ///
145    /// Readable | Writable
146    ///
147    ///
148    /// #### `is-busy`
149    ///  Whether the application is currently marked as busy through
150    /// [`ApplicationExtManual::mark_busy()`][crate::gio::prelude::ApplicationExtManual::mark_busy()] or [`ApplicationExtManual::bind_busy_property()`][crate::gio::prelude::ApplicationExtManual::bind_busy_property()].
151    ///
152    /// Readable
153    ///
154    ///
155    /// #### `is-registered`
156    ///  Whether [method`Gio`.register] has been called.
157    ///
158    /// Readable
159    ///
160    ///
161    /// #### `is-remote`
162    ///  Whether this application instance is remote.
163    ///
164    /// Readable
165    ///
166    ///
167    /// #### `resource-base-path`
168    ///  The base resource path for the application.
169    ///
170    /// Readable | Writable
171    ///
172    ///
173    /// #### `version`
174    ///  The human-readable version number of the application.
175    ///
176    /// Readable | Writable
177    /// </details>
178    ///
179    /// ## Signals
180    ///
181    ///
182    /// #### `query-end`
183    ///  Emitted when the session manager is about to end the session, only
184    /// if [`register-session`][struct@crate::Application#register-session] is [`true`]. Applications can
185    /// connect to this signal and call [`GtkApplicationExt::inhibit()`][crate::prelude::GtkApplicationExt::inhibit()] with
186    /// [`ApplicationInhibitFlags::LOGOUT`][crate::ApplicationInhibitFlags::LOGOUT] to delay the end of the session
187    /// until state has been saved.
188    ///
189    ///
190    ///
191    ///
192    /// #### `window-added`
193    ///  Emitted when a [`Window`][crate::Window] is added to `application` through
194    /// [`GtkApplicationExt::add_window()`][crate::prelude::GtkApplicationExt::add_window()].
195    ///
196    ///
197    ///
198    ///
199    /// #### `window-removed`
200    ///  Emitted when a [`Window`][crate::Window] is removed from `application`,
201    /// either as a side-effect of being destroyed or explicitly
202    /// through [`GtkApplicationExt::remove_window()`][crate::prelude::GtkApplicationExt::remove_window()].
203    ///
204    ///
205    /// <details><summary><h4>Application</h4></summary>
206    ///
207    ///
208    /// #### `activate`
209    ///  The ::activate signal is emitted on the primary instance when an
210    /// activation occurs. See [`ApplicationExtManual::activate()`][crate::gio::prelude::ApplicationExtManual::activate()].
211    ///
212    ///
213    ///
214    ///
215    /// #### `command-line`
216    ///  The ::command-line signal is emitted on the primary instance when
217    /// a commandline is not handled locally. See [`ApplicationExtManual::run()`][crate::gio::prelude::ApplicationExtManual::run()] and
218    /// the `GApplicationCommandLine` documentation for more information.
219    ///
220    ///
221    ///
222    ///
223    /// #### `handle-local-options`
224    ///  The ::handle-local-options signal is emitted on the local instance
225    /// after the parsing of the commandline options has occurred.
226    ///
227    /// You can add options to be recognised during commandline option
228    /// parsing using [`ApplicationExtManual::add_main_option_entries()`][crate::gio::prelude::ApplicationExtManual::add_main_option_entries()] and
229    /// [`ApplicationExtManual::add_option_group()`][crate::gio::prelude::ApplicationExtManual::add_option_group()].
230    ///
231    /// Signal handlers can inspect `options` (along with values pointed to
232    /// from the `arg_data` of an installed `GOptionEntrys`) in order to
233    /// decide to perform certain actions, including direct local handling
234    /// (which may be useful for options like --version).
235    ///
236    /// In the event that the application is marked
237    /// [`gio::ApplicationFlags::HANDLES_COMMAND_LINE`][crate::gio::ApplicationFlags::HANDLES_COMMAND_LINE] the "normal processing" will
238    /// send the `options` dictionary to the primary instance where it can be
239    /// read with `g_application_command_line_get_options_dict()`. The signal
240    /// handler can modify the dictionary before returning, and the
241    /// modified dictionary will be sent.
242    ///
243    /// In the event that [`gio::ApplicationFlags::HANDLES_COMMAND_LINE`][crate::gio::ApplicationFlags::HANDLES_COMMAND_LINE] is not set,
244    /// "normal processing" will treat the remaining uncollected command
245    /// line arguments as filenames or URIs. If there are no arguments,
246    /// the application is activated by [`ApplicationExtManual::activate()`][crate::gio::prelude::ApplicationExtManual::activate()]. One or
247    /// more arguments results in a call to [`ApplicationExtManual::open()`][crate::gio::prelude::ApplicationExtManual::open()].
248    ///
249    /// If you want to handle the local commandline arguments for yourself
250    /// by converting them to calls to [`ApplicationExtManual::open()`][crate::gio::prelude::ApplicationExtManual::open()] or
251    /// [`ActionGroupExtManual::activate_action()`][crate::gio::prelude::ActionGroupExtManual::activate_action()] then you must be sure to register
252    /// the application first. You should probably not call
253    /// [`ApplicationExtManual::activate()`][crate::gio::prelude::ApplicationExtManual::activate()] for yourself, however: just return -1 and
254    /// allow the default handler to do it for you. This will ensure that
255    /// the `--gapplication-service` switch works properly (i.e. no activation
256    /// in that case).
257    ///
258    /// Note that this signal is emitted from the default implementation of
259    /// `local_command_line()`. If you override that function and don't
260    /// chain up then this signal will never be emitted.
261    ///
262    /// You can override `local_command_line()` if you need more powerful
263    /// capabilities than what is provided here, but this should not
264    /// normally be required.
265    ///
266    ///
267    ///
268    ///
269    /// #### `name-lost`
270    ///  The ::name-lost signal is emitted only on the registered primary instance
271    /// when a new instance has taken over. This can only happen if the application
272    /// is using the [`gio::ApplicationFlags::ALLOW_REPLACEMENT`][crate::gio::ApplicationFlags::ALLOW_REPLACEMENT] flag.
273    ///
274    /// The default handler for this signal calls [`ApplicationExtManual::quit()`][crate::gio::prelude::ApplicationExtManual::quit()].
275    ///
276    ///
277    ///
278    ///
279    /// #### `open`
280    ///  The ::open signal is emitted on the primary instance when there are
281    /// files to open. See [`ApplicationExtManual::open()`][crate::gio::prelude::ApplicationExtManual::open()] for more information.
282    ///
283    ///
284    ///
285    ///
286    /// #### `shutdown`
287    ///  The ::shutdown signal is emitted only on the registered primary instance
288    /// immediately after the main loop terminates.
289    ///
290    ///
291    ///
292    ///
293    /// #### `startup`
294    ///  The ::startup signal is emitted on the primary instance immediately
295    /// after registration. See [`ApplicationExtManual::register()`][crate::gio::prelude::ApplicationExtManual::register()].
296    ///
297    ///
298    /// </details>
299    /// <details><summary><h4>ActionGroup</h4></summary>
300    ///
301    ///
302    /// #### `action-added`
303    ///  Signals that a new action was just added to the group.
304    ///
305    /// This signal is emitted after the action has been added
306    /// and is now visible.
307    ///
308    /// Detailed
309    ///
310    ///
311    /// #### `action-enabled-changed`
312    ///  Signals that the enabled status of the named action has changed.
313    ///
314    /// Detailed
315    ///
316    ///
317    /// #### `action-removed`
318    ///  Signals that an action is just about to be removed from the group.
319    ///
320    /// This signal is emitted before the action is removed, so the action
321    /// is still visible and can be queried from the signal handler.
322    ///
323    /// Detailed
324    ///
325    ///
326    /// #### `action-state-changed`
327    ///  Signals that the state of the named action has changed.
328    ///
329    /// Detailed
330    /// </details>
331    ///
332    /// # Implements
333    ///
334    /// [`GtkApplicationExt`][trait@crate::prelude::GtkApplicationExt], [`trait@gio::prelude::ApplicationExt`], [`trait@glib::ObjectExt`], [`trait@gio::prelude::ActionGroupExt`], [`trait@gio::prelude::ActionMapExt`], [`gio::ApplicationExtManual`][trait@crate::prelude::gio::ApplicationExtManual]
335    #[doc(alias = "GtkApplication")]
336    pub struct Application(Object<ffi::GtkApplication, ffi::GtkApplicationClass>) @extends gio::Application, @implements gio::ActionGroup, gio::ActionMap;
337
338    match fn {
339        type_ => || ffi::gtk_application_get_type(),
340    }
341}
342
343impl Application {
344    pub const NONE: Option<&'static Application> = None;
345
346    // rustdoc-stripper-ignore-next
347    /// Creates a new builder-pattern struct instance to construct [`Application`] objects.
348    ///
349    /// This method returns an instance of [`ApplicationBuilder`](crate::builders::ApplicationBuilder) which can be used to create [`Application`] objects.
350    pub fn builder() -> ApplicationBuilder {
351        ApplicationBuilder::new()
352    }
353}
354
355// rustdoc-stripper-ignore-next
356/// A [builder-pattern] type to construct [`Application`] objects.
357///
358/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
359#[must_use = "The builder must be built to be used"]
360pub struct ApplicationBuilder {
361    builder: glib::object::ObjectBuilder<'static, Application>,
362}
363
364impl ApplicationBuilder {
365    fn new() -> Self {
366        Self {
367            builder: glib::object::Object::builder(),
368        }
369    }
370
371    pub fn app_menu(self, app_menu: &impl IsA<gio::MenuModel>) -> Self {
372        Self {
373            builder: self.builder.property("app-menu", app_menu.clone().upcast()),
374        }
375    }
376
377    pub fn menubar(self, menubar: &impl IsA<gio::MenuModel>) -> Self {
378        Self {
379            builder: self.builder.property("menubar", menubar.clone().upcast()),
380        }
381    }
382
383    /// Set this property to [`true`] to register with the session manager.
384    pub fn register_session(self, register_session: bool) -> Self {
385        Self {
386            builder: self.builder.property("register-session", register_session),
387        }
388    }
389
390    /// The unique identifier for the application.
391    pub fn application_id(self, application_id: impl Into<glib::GString>) -> Self {
392        Self {
393            builder: self
394                .builder
395                .property("application-id", application_id.into()),
396        }
397    }
398
399    /// Flags specifying the behaviour of the application.
400    pub fn flags(self, flags: gio::ApplicationFlags) -> Self {
401        Self {
402            builder: self.builder.property("flags", flags),
403        }
404    }
405
406    /// Time (in milliseconds) to stay alive after becoming idle.
407    pub fn inactivity_timeout(self, inactivity_timeout: u32) -> Self {
408        Self {
409            builder: self
410                .builder
411                .property("inactivity-timeout", inactivity_timeout),
412        }
413    }
414
415    /// The base resource path for the application.
416    pub fn resource_base_path(self, resource_base_path: impl Into<glib::GString>) -> Self {
417        Self {
418            builder: self
419                .builder
420                .property("resource-base-path", resource_base_path.into()),
421        }
422    }
423
424    /// The human-readable version number of the application.
425    #[cfg(feature = "gio_v2_80")]
426    #[cfg_attr(docsrs, doc(cfg(feature = "gio_v2_80")))]
427    pub fn version(self, version: impl Into<glib::GString>) -> Self {
428        Self {
429            builder: self.builder.property("version", version.into()),
430        }
431    }
432
433    // rustdoc-stripper-ignore-next
434    /// Build the [`Application`].
435    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
436    pub fn build(self) -> Application {
437        let ret = self.builder.build();
438        {
439            Application::register_startup_hook(&ret);
440        }
441        ret
442    }
443}
444
445/// Trait containing all [`struct@Application`] methods.
446///
447/// # Implementors
448///
449/// [`Application`][struct@crate::Application]
450pub trait GtkApplicationExt: IsA<Application> + 'static {
451    /// Adds a window to `self`.
452    ///
453    /// This call can only happen after the `self` has started;
454    /// typically, you should add new application windows in response
455    /// to the emission of the [`activate`][struct@crate::gio::Application#activate] signal.
456    ///
457    /// This call is equivalent to setting the [`application`][struct@crate::Window#application]
458    /// property of `window` to `self`.
459    ///
460    /// Normally, the connection between the application and the window
461    /// will remain until the window is destroyed, but you can explicitly
462    /// remove it with [`remove_window()`][Self::remove_window()].
463    ///
464    /// GTK+ will keep the `self` running as long as it has
465    /// any windows.
466    /// ## `window`
467    /// a [`Window`][crate::Window]
468    #[doc(alias = "gtk_application_add_window")]
469    fn add_window(&self, window: &impl IsA<Window>) {
470        unsafe {
471            ffi::gtk_application_add_window(
472                self.as_ref().to_glib_none().0,
473                window.as_ref().to_glib_none().0,
474            );
475        }
476    }
477
478    /// Gets the accelerators that are currently associated with
479    /// the given action.
480    /// ## `detailed_action_name`
481    /// a detailed action name, specifying an action
482    ///  and target to obtain accelerators for
483    ///
484    /// # Returns
485    ///
486    /// accelerators for `detailed_action_name`, as
487    ///  a [`None`]-terminated array. Free with `g_strfreev()` when no longer needed
488    #[doc(alias = "gtk_application_get_accels_for_action")]
489    #[doc(alias = "get_accels_for_action")]
490    fn accels_for_action(&self, detailed_action_name: &str) -> Vec<glib::GString> {
491        unsafe {
492            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_accels_for_action(
493                self.as_ref().to_glib_none().0,
494                detailed_action_name.to_glib_none().0,
495            ))
496        }
497    }
498
499    /// Returns the list of actions (possibly empty) that `accel` maps to.
500    /// Each item in the list is a detailed action name in the usual form.
501    ///
502    /// This might be useful to discover if an accel already exists in
503    /// order to prevent installation of a conflicting accelerator (from
504    /// an accelerator editor or a plugin system, for example). Note that
505    /// having more than one action per accelerator may not be a bad thing
506    /// and might make sense in cases where the actions never appear in the
507    /// same context.
508    ///
509    /// In case there are no actions for a given accelerator, an empty array
510    /// is returned. [`None`] is never returned.
511    ///
512    /// It is a programmer error to pass an invalid accelerator string.
513    /// If you are unsure, check it with [`accelerator_parse()`][crate::accelerator_parse()] first.
514    /// ## `accel`
515    /// an accelerator that can be parsed by [`accelerator_parse()`][crate::accelerator_parse()]
516    ///
517    /// # Returns
518    ///
519    /// a [`None`]-terminated array of actions for `accel`
520    #[doc(alias = "gtk_application_get_actions_for_accel")]
521    #[doc(alias = "get_actions_for_accel")]
522    fn actions_for_accel(&self, accel: &str) -> Vec<glib::GString> {
523        unsafe {
524            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_actions_for_accel(
525                self.as_ref().to_glib_none().0,
526                accel.to_glib_none().0,
527            ))
528        }
529    }
530
531    /// Gets the “active” window for the application.
532    ///
533    /// The active window is the one that was most recently focused (within
534    /// the application). This window may not have the focus at the moment
535    /// if another application has it — this is just the most
536    /// recently-focused window within this application.
537    ///
538    /// # Returns
539    ///
540    /// the active window, or [`None`] if
541    ///  there isn't one.
542    #[doc(alias = "gtk_application_get_active_window")]
543    #[doc(alias = "get_active_window")]
544    #[doc(alias = "active-window")]
545    fn active_window(&self) -> Option<Window> {
546        unsafe {
547            from_glib_none(ffi::gtk_application_get_active_window(
548                self.as_ref().to_glib_none().0,
549            ))
550        }
551    }
552
553    /// Returns the menu model that has been set with
554    /// [`set_app_menu()`][Self::set_app_menu()].
555    ///
556    /// # Returns
557    ///
558    /// the application menu of `self`
559    ///  or [`None`] if no application menu has been set.
560    #[doc(alias = "gtk_application_get_app_menu")]
561    #[doc(alias = "get_app_menu")]
562    #[doc(alias = "app-menu")]
563    fn app_menu(&self) -> Option<gio::MenuModel> {
564        unsafe {
565            from_glib_none(ffi::gtk_application_get_app_menu(
566                self.as_ref().to_glib_none().0,
567            ))
568        }
569    }
570
571    /// Gets a menu from automatically loaded resources.
572    /// See [Automatic resources][automatic-resources]
573    /// for more information.
574    /// ## `id`
575    /// the id of the menu to look up
576    ///
577    /// # Returns
578    ///
579    /// Gets the menu with the
580    ///  given id from the automatically loaded resources
581    #[doc(alias = "gtk_application_get_menu_by_id")]
582    #[doc(alias = "get_menu_by_id")]
583    fn menu_by_id(&self, id: &str) -> Option<gio::Menu> {
584        unsafe {
585            from_glib_none(ffi::gtk_application_get_menu_by_id(
586                self.as_ref().to_glib_none().0,
587                id.to_glib_none().0,
588            ))
589        }
590    }
591
592    /// Returns the menu model that has been set with
593    /// [`set_menubar()`][Self::set_menubar()].
594    ///
595    /// # Returns
596    ///
597    /// the menubar for windows of `self`
598    #[doc(alias = "gtk_application_get_menubar")]
599    #[doc(alias = "get_menubar")]
600    fn menubar(&self) -> Option<gio::MenuModel> {
601        unsafe {
602            from_glib_none(ffi::gtk_application_get_menubar(
603                self.as_ref().to_glib_none().0,
604            ))
605        }
606    }
607
608    /// Returns the [`ApplicationWindow`][crate::ApplicationWindow] with the given ID.
609    ///
610    /// The ID of a [`ApplicationWindow`][crate::ApplicationWindow] can be retrieved with
611    /// [`ApplicationWindowExt::id()`][crate::prelude::ApplicationWindowExt::id()].
612    /// ## `id`
613    /// an identifier number
614    ///
615    /// # Returns
616    ///
617    /// the window with ID `id`, or
618    ///  [`None`] if there is no window with this ID
619    #[doc(alias = "gtk_application_get_window_by_id")]
620    #[doc(alias = "get_window_by_id")]
621    fn window_by_id(&self, id: u32) -> Option<Window> {
622        unsafe {
623            from_glib_none(ffi::gtk_application_get_window_by_id(
624                self.as_ref().to_glib_none().0,
625                id,
626            ))
627        }
628    }
629
630    /// Gets a list of the `GtkWindows` associated with `self`.
631    ///
632    /// The list is sorted by most recently focused window, such that the first
633    /// element is the currently focused window. (Useful for choosing a parent
634    /// for a transient window.)
635    ///
636    /// The list that is returned should not be modified in any way. It will
637    /// only remain valid until the next focus change or window creation or
638    /// deletion.
639    ///
640    /// # Returns
641    ///
642    /// a `GList` of [`Window`][crate::Window]
643    #[doc(alias = "gtk_application_get_windows")]
644    #[doc(alias = "get_windows")]
645    fn windows(&self) -> Vec<Window> {
646        unsafe {
647            FromGlibPtrContainer::from_glib_none(ffi::gtk_application_get_windows(
648                self.as_ref().to_glib_none().0,
649            ))
650        }
651    }
652
653    /// Inform the session manager that certain types of actions should be
654    /// inhibited. This is not guaranteed to work on all platforms and for
655    /// all types of actions.
656    ///
657    /// Applications should invoke this method when they begin an operation
658    /// that should not be interrupted, such as creating a CD or DVD. The
659    /// types of actions that may be blocked are specified by the `flags`
660    /// parameter. When the application completes the operation it should
661    /// call [`uninhibit()`][Self::uninhibit()] to remove the inhibitor. Note that
662    /// an application can have multiple inhibitors, and all of them must
663    /// be individually removed. Inhibitors are also cleared when the
664    /// application exits.
665    ///
666    /// Applications should not expect that they will always be able to block
667    /// the action. In most cases, users will be given the option to force
668    /// the action to take place.
669    ///
670    /// Reasons should be short and to the point.
671    ///
672    /// If `window` is given, the session manager may point the user to
673    /// this window to find out more about why the action is inhibited.
674    /// ## `window`
675    /// a [`Window`][crate::Window], or [`None`]
676    /// ## `flags`
677    /// what types of actions should be inhibited
678    /// ## `reason`
679    /// a short, human-readable string that explains
680    ///  why these operations are inhibited
681    ///
682    /// # Returns
683    ///
684    /// A non-zero cookie that is used to uniquely identify this
685    ///  request. It should be used as an argument to [`uninhibit()`][Self::uninhibit()]
686    ///  in order to remove the request. If the platform does not support
687    ///  inhibiting or the request failed for some reason, 0 is returned.
688    #[doc(alias = "gtk_application_inhibit")]
689    fn inhibit(
690        &self,
691        window: Option<&impl IsA<Window>>,
692        flags: ApplicationInhibitFlags,
693        reason: Option<&str>,
694    ) -> u32 {
695        unsafe {
696            ffi::gtk_application_inhibit(
697                self.as_ref().to_glib_none().0,
698                window.map(|p| p.as_ref()).to_glib_none().0,
699                flags.into_glib(),
700                reason.to_glib_none().0,
701            )
702        }
703    }
704
705    /// Determines if any of the actions specified in `flags` are
706    /// currently inhibited (possibly by another application).
707    ///
708    /// Note that this information may not be available (for example
709    /// when the application is running in a sandbox).
710    /// ## `flags`
711    /// what types of actions should be queried
712    ///
713    /// # Returns
714    ///
715    /// [`true`] if any of the actions specified in `flags` are inhibited
716    #[doc(alias = "gtk_application_is_inhibited")]
717    fn is_inhibited(&self, flags: ApplicationInhibitFlags) -> bool {
718        unsafe {
719            from_glib(ffi::gtk_application_is_inhibited(
720                self.as_ref().to_glib_none().0,
721                flags.into_glib(),
722            ))
723        }
724    }
725
726    /// Lists the detailed action names which have associated accelerators.
727    /// See [`set_accels_for_action()`][Self::set_accels_for_action()].
728    ///
729    /// # Returns
730    ///
731    /// a [`None`]-terminated array of strings,
732    ///  free with `g_strfreev()` when done
733    #[doc(alias = "gtk_application_list_action_descriptions")]
734    fn list_action_descriptions(&self) -> Vec<glib::GString> {
735        unsafe {
736            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_list_action_descriptions(
737                self.as_ref().to_glib_none().0,
738            ))
739        }
740    }
741
742    /// Determines if the desktop environment in which the application is
743    /// running would prefer an application menu be shown.
744    ///
745    /// If this function returns [`true`] then the application should call
746    /// [`set_app_menu()`][Self::set_app_menu()] with the contents of an application
747    /// menu, which will be shown by the desktop environment. If it returns
748    /// [`false`] then you should consider using an alternate approach, such as
749    /// a menubar.
750    ///
751    /// The value returned by this function is purely advisory and you are
752    /// free to ignore it. If you call [`set_app_menu()`][Self::set_app_menu()] even
753    /// if the desktop environment doesn't support app menus, then a fallback
754    /// will be provided.
755    ///
756    /// Applications are similarly free not to set an app menu even if the
757    /// desktop environment wants to show one. In that case, a fallback will
758    /// also be created by the desktop environment (GNOME, for example, uses
759    /// a menu with only a "Quit" item in it).
760    ///
761    /// The value returned by this function never changes. Once it returns a
762    /// particular value, it is guaranteed to always return the same value.
763    ///
764    /// You may only call this function after the application has been
765    /// registered and after the base startup handler has run. You're most
766    /// likely to want to use this from your own startup handler. It may
767    /// also make sense to consult this function while constructing UI (in
768    /// activate, open or an action activation handler) in order to determine
769    /// if you should show a gear menu or not.
770    ///
771    /// This function will return [`false`] on Mac OS and a default app menu
772    /// will be created automatically with the "usual" contents of that menu
773    /// typical to most Mac OS applications. If you call
774    /// [`set_app_menu()`][Self::set_app_menu()] anyway, then this menu will be
775    /// replaced with your own.
776    ///
777    /// # Returns
778    ///
779    /// [`true`] if you should set an app menu
780    #[doc(alias = "gtk_application_prefers_app_menu")]
781    fn prefers_app_menu(&self) -> bool {
782        unsafe {
783            from_glib(ffi::gtk_application_prefers_app_menu(
784                self.as_ref().to_glib_none().0,
785            ))
786        }
787    }
788
789    /// Remove a window from `self`.
790    ///
791    /// If `window` belongs to `self` then this call is equivalent to
792    /// setting the [`application`][struct@crate::Window#application] property of `window` to
793    /// [`None`].
794    ///
795    /// The application may stop running as a result of a call to this
796    /// function.
797    /// ## `window`
798    /// a [`Window`][crate::Window]
799    #[doc(alias = "gtk_application_remove_window")]
800    fn remove_window(&self, window: &impl IsA<Window>) {
801        unsafe {
802            ffi::gtk_application_remove_window(
803                self.as_ref().to_glib_none().0,
804                window.as_ref().to_glib_none().0,
805            );
806        }
807    }
808
809    /// Sets zero or more keyboard accelerators that will trigger the
810    /// given action. The first item in `accels` will be the primary
811    /// accelerator, which may be displayed in the UI.
812    ///
813    /// To remove all accelerators for an action, use an empty, zero-terminated
814    /// array for `accels`.
815    ///
816    /// For the `detailed_action_name`, see `g_action_parse_detailed_name()` and
817    /// `g_action_print_detailed_name()`.
818    /// ## `detailed_action_name`
819    /// a detailed action name, specifying an action
820    ///  and target to associate accelerators with
821    /// ## `accels`
822    /// a list of accelerators in the format
823    ///  understood by [`accelerator_parse()`][crate::accelerator_parse()]
824    #[doc(alias = "gtk_application_set_accels_for_action")]
825    fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str]) {
826        unsafe {
827            ffi::gtk_application_set_accels_for_action(
828                self.as_ref().to_glib_none().0,
829                detailed_action_name.to_glib_none().0,
830                accels.to_glib_none().0,
831            );
832        }
833    }
834
835    /// Sets or unsets the application menu for `self`.
836    ///
837    /// This can only be done in the primary instance of the application,
838    /// after it has been registered. [`startup`][struct@crate::gio::Application#startup] is a good place
839    /// to call this.
840    ///
841    /// The application menu is a single menu containing items that typically
842    /// impact the application as a whole, rather than acting on a specific
843    /// window or document. For example, you would expect to see
844    /// “Preferences” or “Quit” in an application menu, but not “Save” or
845    /// “Print”.
846    ///
847    /// If supported, the application menu will be rendered by the desktop
848    /// environment.
849    ///
850    /// Use the base [`gio::ActionMap`][crate::gio::ActionMap] interface to add actions, to respond to the user
851    /// selecting these menu items.
852    /// ## `app_menu`
853    /// a [`gio::MenuModel`][crate::gio::MenuModel], or [`None`]
854    #[doc(alias = "gtk_application_set_app_menu")]
855    #[doc(alias = "app-menu")]
856    fn set_app_menu(&self, app_menu: Option<&impl IsA<gio::MenuModel>>) {
857        unsafe {
858            ffi::gtk_application_set_app_menu(
859                self.as_ref().to_glib_none().0,
860                app_menu.map(|p| p.as_ref()).to_glib_none().0,
861            );
862        }
863    }
864
865    /// Sets or unsets the menubar for windows of `self`.
866    ///
867    /// This is a menubar in the traditional sense.
868    ///
869    /// This can only be done in the primary instance of the application,
870    /// after it has been registered. [`startup`][struct@crate::gio::Application#startup] is a good place
871    /// to call this.
872    ///
873    /// Depending on the desktop environment, this may appear at the top of
874    /// each window, or at the top of the screen. In some environments, if
875    /// both the application menu and the menubar are set, the application
876    /// menu will be presented as if it were the first item of the menubar.
877    /// Other environments treat the two as completely separate — for example,
878    /// the application menu may be rendered by the desktop shell while the
879    /// menubar (if set) remains in each individual window.
880    ///
881    /// Use the base [`gio::ActionMap`][crate::gio::ActionMap] interface to add actions, to respond to the
882    /// user selecting these menu items.
883    /// ## `menubar`
884    /// a [`gio::MenuModel`][crate::gio::MenuModel], or [`None`]
885    #[doc(alias = "gtk_application_set_menubar")]
886    #[doc(alias = "menubar")]
887    fn set_menubar(&self, menubar: Option<&impl IsA<gio::MenuModel>>) {
888        unsafe {
889            ffi::gtk_application_set_menubar(
890                self.as_ref().to_glib_none().0,
891                menubar.map(|p| p.as_ref()).to_glib_none().0,
892            );
893        }
894    }
895
896    /// Removes an inhibitor that has been established with [`inhibit()`][Self::inhibit()].
897    /// Inhibitors are also cleared when the application exits.
898    /// ## `cookie`
899    /// a cookie that was returned by [`inhibit()`][Self::inhibit()]
900    #[doc(alias = "gtk_application_uninhibit")]
901    fn uninhibit(&self, cookie: u32) {
902        unsafe {
903            ffi::gtk_application_uninhibit(self.as_ref().to_glib_none().0, cookie);
904        }
905    }
906
907    /// Set this property to [`true`] to register with the session manager.
908    #[doc(alias = "register-session")]
909    fn is_register_session(&self) -> bool {
910        ObjectExt::property(self.as_ref(), "register-session")
911    }
912
913    /// Set this property to [`true`] to register with the session manager.
914    #[doc(alias = "register-session")]
915    fn set_register_session(&self, register_session: bool) {
916        ObjectExt::set_property(self.as_ref(), "register-session", register_session)
917    }
918
919    /// This property is [`true`] if GTK+ believes that the screensaver is
920    /// currently active. GTK+ only tracks session state (including this)
921    /// when [`register-session`][struct@crate::Application#register-session] is set to [`true`].
922    ///
923    /// Tracking the screensaver state is supported on Linux.
924    #[cfg(feature = "v3_24")]
925    #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
926    #[doc(alias = "screensaver-active")]
927    fn is_screensaver_active(&self) -> bool {
928        ObjectExt::property(self.as_ref(), "screensaver-active")
929    }
930
931    /// Emitted when the session manager is about to end the session, only
932    /// if [`register-session`][struct@crate::Application#register-session] is [`true`]. Applications can
933    /// connect to this signal and call [`inhibit()`][Self::inhibit()] with
934    /// [`ApplicationInhibitFlags::LOGOUT`][crate::ApplicationInhibitFlags::LOGOUT] to delay the end of the session
935    /// until state has been saved.
936    #[cfg(feature = "v3_24_8")]
937    #[cfg_attr(docsrs, doc(cfg(feature = "v3_24_8")))]
938    #[doc(alias = "query-end")]
939    fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
940        unsafe extern "C" fn query_end_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
941            this: *mut ffi::GtkApplication,
942            f: glib::ffi::gpointer,
943        ) {
944            unsafe {
945                let f: &F = &*(f as *const F);
946                f(Application::from_glib_borrow(this).unsafe_cast_ref())
947            }
948        }
949        unsafe {
950            let f: Box_<F> = Box_::new(f);
951            connect_raw(
952                self.as_ptr() as *mut _,
953                c"query-end".as_ptr(),
954                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
955                    query_end_trampoline::<Self, F> as *const (),
956                )),
957                Box_::into_raw(f),
958            )
959        }
960    }
961
962    /// Emitted when a [`Window`][crate::Window] is added to `application` through
963    /// [`add_window()`][Self::add_window()].
964    /// ## `window`
965    /// the newly-added [`Window`][crate::Window]
966    #[doc(alias = "window-added")]
967    fn connect_window_added<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
968        unsafe extern "C" fn window_added_trampoline<
969            P: IsA<Application>,
970            F: Fn(&P, &Window) + 'static,
971        >(
972            this: *mut ffi::GtkApplication,
973            window: *mut ffi::GtkWindow,
974            f: glib::ffi::gpointer,
975        ) {
976            unsafe {
977                let f: &F = &*(f as *const F);
978                f(
979                    Application::from_glib_borrow(this).unsafe_cast_ref(),
980                    &from_glib_borrow(window),
981                )
982            }
983        }
984        unsafe {
985            let f: Box_<F> = Box_::new(f);
986            connect_raw(
987                self.as_ptr() as *mut _,
988                c"window-added".as_ptr(),
989                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
990                    window_added_trampoline::<Self, F> as *const (),
991                )),
992                Box_::into_raw(f),
993            )
994        }
995    }
996
997    /// Emitted when a [`Window`][crate::Window] is removed from `application`,
998    /// either as a side-effect of being destroyed or explicitly
999    /// through [`remove_window()`][Self::remove_window()].
1000    /// ## `window`
1001    /// the [`Window`][crate::Window] that is being removed
1002    #[doc(alias = "window-removed")]
1003    fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
1004        unsafe extern "C" fn window_removed_trampoline<
1005            P: IsA<Application>,
1006            F: Fn(&P, &Window) + 'static,
1007        >(
1008            this: *mut ffi::GtkApplication,
1009            window: *mut ffi::GtkWindow,
1010            f: glib::ffi::gpointer,
1011        ) {
1012            unsafe {
1013                let f: &F = &*(f as *const F);
1014                f(
1015                    Application::from_glib_borrow(this).unsafe_cast_ref(),
1016                    &from_glib_borrow(window),
1017                )
1018            }
1019        }
1020        unsafe {
1021            let f: Box_<F> = Box_::new(f);
1022            connect_raw(
1023                self.as_ptr() as *mut _,
1024                c"window-removed".as_ptr(),
1025                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1026                    window_removed_trampoline::<Self, F> as *const (),
1027                )),
1028                Box_::into_raw(f),
1029            )
1030        }
1031    }
1032
1033    #[doc(alias = "active-window")]
1034    fn connect_active_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1035        unsafe extern "C" fn notify_active_window_trampoline<
1036            P: IsA<Application>,
1037            F: Fn(&P) + 'static,
1038        >(
1039            this: *mut ffi::GtkApplication,
1040            _param_spec: glib::ffi::gpointer,
1041            f: glib::ffi::gpointer,
1042        ) {
1043            unsafe {
1044                let f: &F = &*(f as *const F);
1045                f(Application::from_glib_borrow(this).unsafe_cast_ref())
1046            }
1047        }
1048        unsafe {
1049            let f: Box_<F> = Box_::new(f);
1050            connect_raw(
1051                self.as_ptr() as *mut _,
1052                c"notify::active-window".as_ptr(),
1053                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1054                    notify_active_window_trampoline::<Self, F> as *const (),
1055                )),
1056                Box_::into_raw(f),
1057            )
1058        }
1059    }
1060
1061    #[doc(alias = "app-menu")]
1062    fn connect_app_menu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1063        unsafe extern "C" fn notify_app_menu_trampoline<
1064            P: IsA<Application>,
1065            F: Fn(&P) + 'static,
1066        >(
1067            this: *mut ffi::GtkApplication,
1068            _param_spec: glib::ffi::gpointer,
1069            f: glib::ffi::gpointer,
1070        ) {
1071            unsafe {
1072                let f: &F = &*(f as *const F);
1073                f(Application::from_glib_borrow(this).unsafe_cast_ref())
1074            }
1075        }
1076        unsafe {
1077            let f: Box_<F> = Box_::new(f);
1078            connect_raw(
1079                self.as_ptr() as *mut _,
1080                c"notify::app-menu".as_ptr(),
1081                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1082                    notify_app_menu_trampoline::<Self, F> as *const (),
1083                )),
1084                Box_::into_raw(f),
1085            )
1086        }
1087    }
1088
1089    #[doc(alias = "menubar")]
1090    fn connect_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1091        unsafe extern "C" fn notify_menubar_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
1092            this: *mut ffi::GtkApplication,
1093            _param_spec: glib::ffi::gpointer,
1094            f: glib::ffi::gpointer,
1095        ) {
1096            unsafe {
1097                let f: &F = &*(f as *const F);
1098                f(Application::from_glib_borrow(this).unsafe_cast_ref())
1099            }
1100        }
1101        unsafe {
1102            let f: Box_<F> = Box_::new(f);
1103            connect_raw(
1104                self.as_ptr() as *mut _,
1105                c"notify::menubar".as_ptr(),
1106                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1107                    notify_menubar_trampoline::<Self, F> as *const (),
1108                )),
1109                Box_::into_raw(f),
1110            )
1111        }
1112    }
1113
1114    #[doc(alias = "register-session")]
1115    fn connect_register_session_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1116        unsafe extern "C" fn notify_register_session_trampoline<
1117            P: IsA<Application>,
1118            F: Fn(&P) + 'static,
1119        >(
1120            this: *mut ffi::GtkApplication,
1121            _param_spec: glib::ffi::gpointer,
1122            f: glib::ffi::gpointer,
1123        ) {
1124            unsafe {
1125                let f: &F = &*(f as *const F);
1126                f(Application::from_glib_borrow(this).unsafe_cast_ref())
1127            }
1128        }
1129        unsafe {
1130            let f: Box_<F> = Box_::new(f);
1131            connect_raw(
1132                self.as_ptr() as *mut _,
1133                c"notify::register-session".as_ptr(),
1134                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1135                    notify_register_session_trampoline::<Self, F> as *const (),
1136                )),
1137                Box_::into_raw(f),
1138            )
1139        }
1140    }
1141
1142    #[cfg(feature = "v3_24")]
1143    #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
1144    #[doc(alias = "screensaver-active")]
1145    fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1146        unsafe extern "C" fn notify_screensaver_active_trampoline<
1147            P: IsA<Application>,
1148            F: Fn(&P) + 'static,
1149        >(
1150            this: *mut ffi::GtkApplication,
1151            _param_spec: glib::ffi::gpointer,
1152            f: glib::ffi::gpointer,
1153        ) {
1154            unsafe {
1155                let f: &F = &*(f as *const F);
1156                f(Application::from_glib_borrow(this).unsafe_cast_ref())
1157            }
1158        }
1159        unsafe {
1160            let f: Box_<F> = Box_::new(f);
1161            connect_raw(
1162                self.as_ptr() as *mut _,
1163                c"notify::screensaver-active".as_ptr(),
1164                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1165                    notify_screensaver_active_trampoline::<Self, F> as *const (),
1166                )),
1167                Box_::into_raw(f),
1168            )
1169        }
1170    }
1171}
1172
1173impl<O: IsA<Application>> GtkApplicationExt for O {}