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