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