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