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
446/// Trait containing all [`struct@Application`] methods.
447///
448/// # Implementors
449///
450/// [`Application`][struct@crate::Application]
451pub trait GtkApplicationExt: IsA<Application> + 'static {
452    /// Adds a window to the application.
453    ///
454    /// This call can only happen after the application has started;
455    /// typically, you should add new application windows in response
456    /// to the emission of the [`activate`][struct@crate::GIO::Application#activate] signal.
457    ///
458    /// This call is equivalent to setting the [`application`][struct@crate::Window#application]
459    /// property of the window to @self.
460    ///
461    /// Normally, the connection between the application and the window
462    /// will remain until the window is destroyed, but you can explicitly
463    /// remove it with [`remove_window()`][Self::remove_window()].
464    ///
465    /// GTK will keep the application running as long as it has any windows.
466    /// ## `window`
467    /// a window
468    #[doc(alias = "gtk_application_add_window")]
469    fn add_window(&self, window: &impl IsA<Window>) {
470        unsafe {
471            ffi::gtk_application_add_window(
472                self.as_ref().to_glib_none().0,
473                window.as_ref().to_glib_none().0,
474            );
475        }
476    }
477
478    /// Gets the accelerators that are currently associated with
479    /// the given action.
480    /// ## `detailed_action_name`
481    /// a detailed action name, specifying an action
482    ///   and target to obtain accelerators for
483    ///
484    /// # Returns
485    ///
486    ///
487    ///   accelerators for @detailed_action_name
488    #[doc(alias = "gtk_application_get_accels_for_action")]
489    #[doc(alias = "get_accels_for_action")]
490    fn accels_for_action(&self, detailed_action_name: &str) -> Vec<glib::GString> {
491        unsafe {
492            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_accels_for_action(
493                self.as_ref().to_glib_none().0,
494                detailed_action_name.to_glib_none().0,
495            ))
496        }
497    }
498
499    /// Returns the list of actions (possibly empty) that the accelerator maps to.
500    ///
501    /// Each item in the list is a detailed action name in the usual form.
502    ///
503    /// This might be useful to discover if an accel already exists in
504    /// order to prevent installation of a conflicting accelerator (from
505    /// an accelerator editor or a plugin system, for example). Note that
506    /// having more than one action per accelerator may not be a bad thing
507    /// and might make sense in cases where the actions never appear in the
508    /// same context.
509    ///
510    /// In case there are no actions for a given accelerator, an empty array
511    /// is returned. `NULL` is never returned.
512    ///
513    /// It is a programmer error to pass an invalid accelerator string.
514    ///
515    /// If you are unsure, check it with [`accelerator_parse()`][crate::accelerator_parse()] first.
516    /// ## `accel`
517    /// an accelerator that can be parsed by [`accelerator_parse()`][crate::accelerator_parse()]
518    ///
519    /// # Returns
520    ///
521    /// actions for @accel
522    #[doc(alias = "gtk_application_get_actions_for_accel")]
523    #[doc(alias = "get_actions_for_accel")]
524    fn actions_for_accel(&self, accel: &str) -> Vec<glib::GString> {
525        unsafe {
526            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_actions_for_accel(
527                self.as_ref().to_glib_none().0,
528                accel.to_glib_none().0,
529            ))
530        }
531    }
532
533    /// Gets the “active” window for the application.
534    ///
535    /// The active window is the one that was most recently focused
536    /// (within the application). This window may not have the focus
537    /// at the moment if another application has it — this is just
538    /// the most recently-focused window within this application.
539    ///
540    /// # Returns
541    ///
542    /// the active window
543    #[doc(alias = "gtk_application_get_active_window")]
544    #[doc(alias = "get_active_window")]
545    #[doc(alias = "active-window")]
546    fn active_window(&self) -> Option<Window> {
547        unsafe {
548            from_glib_none(ffi::gtk_application_get_active_window(
549                self.as_ref().to_glib_none().0,
550            ))
551        }
552    }
553
554    /// Gets a menu from automatically loaded resources.
555    ///
556    /// See [the section on Automatic resources](class.Application.html#automatic-resources)
557    /// for more information.
558    /// ## `id`
559    /// the ID of the menu to look up
560    ///
561    /// # Returns
562    ///
563    /// Gets the menu with the
564    ///   given ID from the automatically loaded resources
565    #[doc(alias = "gtk_application_get_menu_by_id")]
566    #[doc(alias = "get_menu_by_id")]
567    fn menu_by_id(&self, id: &str) -> Option<gio::Menu> {
568        unsafe {
569            from_glib_none(ffi::gtk_application_get_menu_by_id(
570                self.as_ref().to_glib_none().0,
571                id.to_glib_none().0,
572            ))
573        }
574    }
575
576    /// Returns the menu model for the menu bar of the application.
577    ///
578    /// # Returns
579    ///
580    /// the menubar for windows of the application
581    #[doc(alias = "gtk_application_get_menubar")]
582    #[doc(alias = "get_menubar")]
583    fn menubar(&self) -> Option<gio::MenuModel> {
584        unsafe {
585            from_glib_none(ffi::gtk_application_get_menubar(
586                self.as_ref().to_glib_none().0,
587            ))
588        }
589    }
590
591    /// Returns the window with the given ID.
592    ///
593    /// The ID of a [`ApplicationWindow`][crate::ApplicationWindow] can be retrieved with
594    /// [`ApplicationWindowExt::id()`][crate::prelude::ApplicationWindowExt::id()].
595    /// ## `id`
596    /// an identifier number
597    ///
598    /// # Returns
599    ///
600    /// the window for the given ID
601    #[doc(alias = "gtk_application_get_window_by_id")]
602    #[doc(alias = "get_window_by_id")]
603    fn window_by_id(&self, id: u32) -> Option<Window> {
604        unsafe {
605            from_glib_none(ffi::gtk_application_get_window_by_id(
606                self.as_ref().to_glib_none().0,
607                id,
608            ))
609        }
610    }
611
612    /// Gets a list of the window associated with the application.
613    ///
614    /// The list is sorted by most recently focused window, such that the first
615    /// element is the currently focused window. (Useful for choosing a parent
616    /// for a transient window.)
617    ///
618    /// The list that is returned should not be modified in any way. It will
619    /// only remain valid until the next focus change or window creation or
620    /// deletion.
621    ///
622    /// # Returns
623    ///
624    /// the list of windows
625    #[doc(alias = "gtk_application_get_windows")]
626    #[doc(alias = "get_windows")]
627    fn windows(&self) -> Vec<Window> {
628        unsafe {
629            FromGlibPtrContainer::from_glib_none(ffi::gtk_application_get_windows(
630                self.as_ref().to_glib_none().0,
631            ))
632        }
633    }
634
635    /// Informs the session manager that certain types of actions should be
636    /// inhibited.
637    ///
638    /// This is not guaranteed to work on all platforms and for all types of
639    /// actions.
640    ///
641    /// Applications should invoke this method when they begin an operation
642    /// that should not be interrupted, such as creating a CD or DVD. The
643    /// types of actions that may be blocked are specified by the @flags
644    /// parameter. When the application completes the operation it should
645    /// call [`uninhibit()`][Self::uninhibit()] to remove the inhibitor. Note
646    /// that an application can have multiple inhibitors, and all of them must
647    /// be individually removed. Inhibitors are also cleared when the
648    /// application exits.
649    ///
650    /// Applications should not expect that they will always be able to block
651    /// the action. In most cases, users will be given the option to force
652    /// the action to take place.
653    ///
654    /// The @reason message should be short and to the point.
655    ///
656    /// If a window is given, the session manager may point the user to
657    /// this window to find out more about why the action is inhibited.
658    ///
659    /// The cookie that is returned by this function  should be used as an
660    /// argument to [`uninhibit()`][Self::uninhibit()] in order to remove
661    /// the request.
662    /// ## `window`
663    /// a window
664    /// ## `flags`
665    /// what types of actions should be inhibited
666    /// ## `reason`
667    /// a short, human-readable string that explains
668    ///   why these operations are inhibited
669    ///
670    /// # Returns
671    ///
672    /// A non-zero cookie that is used to uniquely identify this, or
673    ///   0 if the platform does not support inhibiting or the request failed
674    ///   for some reason
675    #[doc(alias = "gtk_application_inhibit")]
676    fn inhibit(
677        &self,
678        window: Option<&impl IsA<Window>>,
679        flags: ApplicationInhibitFlags,
680        reason: Option<&str>,
681    ) -> u32 {
682        unsafe {
683            ffi::gtk_application_inhibit(
684                self.as_ref().to_glib_none().0,
685                window.map(|p| p.as_ref()).to_glib_none().0,
686                flags.into_glib(),
687                reason.to_glib_none().0,
688            )
689        }
690    }
691
692    /// Lists the detailed action names which have associated accelerators.
693    ///
694    /// See [`set_accels_for_action()`][Self::set_accels_for_action()].
695    ///
696    /// # Returns
697    ///
698    /// the detailed action names
699    #[doc(alias = "gtk_application_list_action_descriptions")]
700    fn list_action_descriptions(&self) -> Vec<glib::GString> {
701        unsafe {
702            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_list_action_descriptions(
703                self.as_ref().to_glib_none().0,
704            ))
705        }
706    }
707
708    /// Remove a window from the application.
709    ///
710    /// If the window belongs to the application then this call is
711    /// equivalent to setting the [`application`][struct@crate::Window#application]
712    /// property of the window to `NULL`.
713    ///
714    /// The application may stop running as a result of a call to this
715    /// function, if the window was the last window of the application.
716    /// ## `window`
717    /// a window
718    #[doc(alias = "gtk_application_remove_window")]
719    fn remove_window(&self, window: &impl IsA<Window>) {
720        unsafe {
721            ffi::gtk_application_remove_window(
722                self.as_ref().to_glib_none().0,
723                window.as_ref().to_glib_none().0,
724            );
725        }
726    }
727
728    /// Sets zero or more keyboard accelerators that will trigger the
729    /// given action.
730    ///
731    /// The first item in @accels will be the primary accelerator,
732    /// which may be displayed in the UI.
733    ///
734    /// To remove all accelerators for an action, use an empty,
735    /// zero-terminated array for @accels.
736    ///
737    /// For the @detailed_action_name, see [`gio::Action::parse_detailed_name()`][crate::gio::Action::parse_detailed_name()]
738    /// and [Gio.Action.print_detailed_name].
739    /// ## `detailed_action_name`
740    /// a detailed action name, specifying an action
741    ///   and target to associate accelerators with
742    /// ## `accels`
743    /// a list of accelerators in the format
744    ///   understood by [`accelerator_parse()`][crate::accelerator_parse()]
745    #[doc(alias = "gtk_application_set_accels_for_action")]
746    fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str]) {
747        unsafe {
748            ffi::gtk_application_set_accels_for_action(
749                self.as_ref().to_glib_none().0,
750                detailed_action_name.to_glib_none().0,
751                accels.to_glib_none().0,
752            );
753        }
754    }
755
756    /// Sets or unsets the menubar for windows of the application.
757    ///
758    /// This is a menubar in the traditional sense.
759    ///
760    /// This can only be done in the primary instance of the application,
761    /// after it has been registered. `vfunc::GIO::Application::startup` is
762    /// a good place to call this.
763    ///
764    /// Depending on the desktop environment, this may appear at the top of
765    /// each window, or at the top of the screen. In some environments, if
766    /// both the application menu and the menubar are set, the application
767    /// menu will be presented as if it were the first item of the menubar.
768    /// Other environments treat the two as completely separate — for example,
769    /// the application menu may be rendered by the desktop shell while the
770    /// menubar (if set) remains in each individual window.
771    ///
772    /// Use the base `GActionMap` interface to add actions, to respond to the
773    /// user selecting these menu items.
774    /// ## `menubar`
775    /// a menu model
776    #[doc(alias = "gtk_application_set_menubar")]
777    #[doc(alias = "menubar")]
778    fn set_menubar(&self, menubar: Option<&impl IsA<gio::MenuModel>>) {
779        unsafe {
780            ffi::gtk_application_set_menubar(
781                self.as_ref().to_glib_none().0,
782                menubar.map(|p| p.as_ref()).to_glib_none().0,
783            );
784        }
785    }
786
787    /// Removes an inhibitor that has been previously established.
788    ///
789    /// See [`inhibit()`][Self::inhibit()].
790    ///
791    /// Inhibitors are also cleared when the application exits.
792    /// ## `cookie`
793    /// a cookie that was returned by [`inhibit()`][Self::inhibit()]
794    #[doc(alias = "gtk_application_uninhibit")]
795    fn uninhibit(&self, cookie: u32) {
796        unsafe {
797            ffi::gtk_application_uninhibit(self.as_ref().to_glib_none().0, cookie);
798        }
799    }
800
801    /// Set this property to true to register with the session manager.
802    ///
803    /// This will make GTK track the session state (such as the
804    /// [`screensaver-active`][struct@crate::Application#screensaver-active] property).
805    #[doc(alias = "register-session")]
806    fn is_register_session(&self) -> bool {
807        ObjectExt::property(self.as_ref(), "register-session")
808    }
809
810    /// Set this property to true to register with the session manager.
811    ///
812    /// This will make GTK track the session state (such as the
813    /// [`screensaver-active`][struct@crate::Application#screensaver-active] property).
814    #[doc(alias = "register-session")]
815    fn set_register_session(&self, register_session: bool) {
816        ObjectExt::set_property(self.as_ref(), "register-session", register_session)
817    }
818
819    /// This property is true if GTK believes that the screensaver
820    /// is currently active.
821    ///
822    /// GTK only tracks session state (including this) when
823    /// [`register-session`][struct@crate::Application#register-session] is set to true.
824    ///
825    /// Tracking the screensaver state is currently only supported on
826    /// Linux.
827    #[doc(alias = "screensaver-active")]
828    fn is_screensaver_active(&self) -> bool {
829        ObjectExt::property(self.as_ref(), "screensaver-active")
830    }
831
832    /// Emitted when the session manager is about to end the session.
833    ///
834    /// This signal is only emitted if [`register-session`][struct@crate::Application#register-session]
835    /// is true. Applications can connect to this signal and call
836    /// [`inhibit()`][Self::inhibit()] with [flags@Gtk.ApplicationInhibitFlags.logout]
837    /// to delay the end of the session until state has been saved.
838    #[doc(alias = "query-end")]
839    fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
840        unsafe extern "C" fn query_end_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
841            this: *mut ffi::GtkApplication,
842            f: glib::ffi::gpointer,
843        ) {
844            let f: &F = &*(f as *const F);
845            f(Application::from_glib_borrow(this).unsafe_cast_ref())
846        }
847        unsafe {
848            let f: Box_<F> = Box_::new(f);
849            connect_raw(
850                self.as_ptr() as *mut _,
851                c"query-end".as_ptr() as *const _,
852                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
853                    query_end_trampoline::<Self, F> as *const (),
854                )),
855                Box_::into_raw(f),
856            )
857        }
858    }
859
860    /// Emitted when a window is added to an application.
861    ///
862    /// See [`add_window()`][Self::add_window()].
863    /// ## `window`
864    /// the newly-added window
865    #[doc(alias = "window-added")]
866    fn connect_window_added<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
867        unsafe extern "C" fn window_added_trampoline<
868            P: IsA<Application>,
869            F: Fn(&P, &Window) + 'static,
870        >(
871            this: *mut ffi::GtkApplication,
872            window: *mut ffi::GtkWindow,
873            f: glib::ffi::gpointer,
874        ) {
875            let f: &F = &*(f as *const F);
876            f(
877                Application::from_glib_borrow(this).unsafe_cast_ref(),
878                &from_glib_borrow(window),
879            )
880        }
881        unsafe {
882            let f: Box_<F> = Box_::new(f);
883            connect_raw(
884                self.as_ptr() as *mut _,
885                c"window-added".as_ptr() as *const _,
886                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
887                    window_added_trampoline::<Self, F> as *const (),
888                )),
889                Box_::into_raw(f),
890            )
891        }
892    }
893
894    /// Emitted when a window is removed from an application.
895    ///
896    /// This can happen as a side-effect of the window being destroyed
897    /// or explicitly through [`remove_window()`][Self::remove_window()].
898    /// ## `window`
899    /// the window that is being removed
900    #[doc(alias = "window-removed")]
901    fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
902        unsafe extern "C" fn window_removed_trampoline<
903            P: IsA<Application>,
904            F: Fn(&P, &Window) + 'static,
905        >(
906            this: *mut ffi::GtkApplication,
907            window: *mut ffi::GtkWindow,
908            f: glib::ffi::gpointer,
909        ) {
910            let f: &F = &*(f as *const F);
911            f(
912                Application::from_glib_borrow(this).unsafe_cast_ref(),
913                &from_glib_borrow(window),
914            )
915        }
916        unsafe {
917            let f: Box_<F> = Box_::new(f);
918            connect_raw(
919                self.as_ptr() as *mut _,
920                c"window-removed".as_ptr() as *const _,
921                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
922                    window_removed_trampoline::<Self, F> as *const (),
923                )),
924                Box_::into_raw(f),
925            )
926        }
927    }
928
929    #[doc(alias = "active-window")]
930    fn connect_active_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
931        unsafe extern "C" fn notify_active_window_trampoline<
932            P: IsA<Application>,
933            F: Fn(&P) + 'static,
934        >(
935            this: *mut ffi::GtkApplication,
936            _param_spec: glib::ffi::gpointer,
937            f: glib::ffi::gpointer,
938        ) {
939            let f: &F = &*(f as *const F);
940            f(Application::from_glib_borrow(this).unsafe_cast_ref())
941        }
942        unsafe {
943            let f: Box_<F> = Box_::new(f);
944            connect_raw(
945                self.as_ptr() as *mut _,
946                c"notify::active-window".as_ptr() as *const _,
947                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
948                    notify_active_window_trampoline::<Self, F> as *const (),
949                )),
950                Box_::into_raw(f),
951            )
952        }
953    }
954
955    #[doc(alias = "menubar")]
956    fn connect_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
957        unsafe extern "C" fn notify_menubar_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
958            this: *mut ffi::GtkApplication,
959            _param_spec: glib::ffi::gpointer,
960            f: glib::ffi::gpointer,
961        ) {
962            let f: &F = &*(f as *const F);
963            f(Application::from_glib_borrow(this).unsafe_cast_ref())
964        }
965        unsafe {
966            let f: Box_<F> = Box_::new(f);
967            connect_raw(
968                self.as_ptr() as *mut _,
969                c"notify::menubar".as_ptr() as *const _,
970                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
971                    notify_menubar_trampoline::<Self, F> as *const (),
972                )),
973                Box_::into_raw(f),
974            )
975        }
976    }
977
978    #[doc(alias = "register-session")]
979    fn connect_register_session_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
980        unsafe extern "C" fn notify_register_session_trampoline<
981            P: IsA<Application>,
982            F: Fn(&P) + 'static,
983        >(
984            this: *mut ffi::GtkApplication,
985            _param_spec: glib::ffi::gpointer,
986            f: glib::ffi::gpointer,
987        ) {
988            let f: &F = &*(f as *const F);
989            f(Application::from_glib_borrow(this).unsafe_cast_ref())
990        }
991        unsafe {
992            let f: Box_<F> = Box_::new(f);
993            connect_raw(
994                self.as_ptr() as *mut _,
995                c"notify::register-session".as_ptr() as *const _,
996                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
997                    notify_register_session_trampoline::<Self, F> as *const (),
998                )),
999                Box_::into_raw(f),
1000            )
1001        }
1002    }
1003
1004    #[doc(alias = "screensaver-active")]
1005    fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1006        unsafe extern "C" fn notify_screensaver_active_trampoline<
1007            P: IsA<Application>,
1008            F: Fn(&P) + 'static,
1009        >(
1010            this: *mut ffi::GtkApplication,
1011            _param_spec: glib::ffi::gpointer,
1012            f: glib::ffi::gpointer,
1013        ) {
1014            let f: &F = &*(f as *const F);
1015            f(Application::from_glib_borrow(this).unsafe_cast_ref())
1016        }
1017        unsafe {
1018            let f: Box_<F> = Box_::new(f);
1019            connect_raw(
1020                self.as_ptr() as *mut _,
1021                c"notify::screensaver-active".as_ptr() as *const _,
1022                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1023                    notify_screensaver_active_trampoline::<Self, F> as *const (),
1024                )),
1025                Box_::into_raw(f),
1026            )
1027        }
1028    }
1029}
1030
1031impl<O: IsA<Application>> GtkApplicationExt for O {}