Skip to main content

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