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