1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::ApplicationInhibitFlags;
use crate::Window;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    /// [`Application`][crate::Application] is a high-level API for writing applications.
    ///
    /// It supports many aspects of writing a GTK application in a convenient
    /// fashion, without enforcing a one-size-fits-all model.
    ///
    /// Currently, [`Application`][crate::Application] handles GTK initialization, application
    /// uniqueness, session management, provides some basic scriptability and
    /// desktop shell integration by exporting actions and menus and manages a
    /// list of toplevel windows whose life-cycle is automatically tied to the
    /// life-cycle of your application.
    ///
    /// While [`Application`][crate::Application] works fine with plain [`Window`][crate::Window]s, it is
    /// recommended to use it together with [`ApplicationWindow`][crate::ApplicationWindow].
    ///
    /// ## Automatic resources
    ///
    /// [`Application`][crate::Application] will automatically load menus from the [`Builder`][crate::Builder]
    /// resource located at "gtk/menus.ui", relative to the application's
    /// resource base path (see [`ApplicationExtManual::set_resource_base_path()`][crate::gio::prelude::ApplicationExtManual::set_resource_base_path()]).
    /// The menu with the ID "menubar" is taken as the application's
    /// menubar. Additional menus (most interesting submenus) can be named
    /// and accessed via [`GtkApplicationExt::menu_by_id()`][crate::prelude::GtkApplicationExt::menu_by_id()] which allows for
    /// dynamic population of a part of the menu structure.
    ///
    /// Note that automatic resource loading uses the resource base path
    /// that is set at construction time and will not work if the resource
    /// base path is changed at a later time.
    ///
    /// It is also possible to provide the menubar manually using
    /// [`GtkApplicationExt::set_menubar()`][crate::prelude::GtkApplicationExt::set_menubar()].
    ///
    /// [`Application`][crate::Application] will also automatically setup an icon search path for
    /// the default icon theme by appending "icons" to the resource base
    /// path. This allows your application to easily store its icons as
    /// resources. See [`IconTheme::add_resource_path()`][crate::IconTheme::add_resource_path()] for more
    /// information.
    ///
    /// If there is a resource located at `gtk/help-overlay.ui` which
    /// defines a [`ShortcutsWindow`][crate::ShortcutsWindow] with ID `help_overlay` then
    /// [`Application`][crate::Application] associates an instance of this shortcuts window with
    /// each [`ApplicationWindow`][crate::ApplicationWindow] and sets up the keyboard accelerator
    /// <kbd>Control</kbd>+<kbd>?</kbd> to open it. To create a menu item that
    /// displays the shortcuts window, associate the item with the action
    /// `win.show-help-overlay`.
    ///
    /// ## A simple application
    ///
    /// [A simple example](https://gitlab.gnome.org/GNOME/gtk/tree/main/examples/bp/bloatpad.c)
    /// is available in the GTK source code repository
    ///
    /// [`Application`][crate::Application] optionally registers with a session manager of the
    /// users session (if you set the `property::Application::register-session`
    /// property) and offers various functionality related to the session
    /// life-cycle.
    ///
    /// An application can block various ways to end the session with
    /// the [`GtkApplicationExt::inhibit()`][crate::prelude::GtkApplicationExt::inhibit()] function. Typical use cases for
    /// this kind of inhibiting are long-running, uninterruptible operations,
    /// such as burning a CD or performing a disk backup. The session
    /// manager may not honor the inhibitor, but it can be expected to
    /// inform the user about the negative consequences of ending the
    /// session while inhibitors are present.
    ///
    /// ## See Also
    ///
    /// [HowDoI: Using GtkApplication](https://wiki.gnome.org/HowDoI/GtkApplication),
    /// [Getting Started with GTK: Basics](getting_started.html#basics)
    ///
    /// # Implements
    ///
    /// [`GtkApplicationExt`][trait@crate::prelude::GtkApplicationExt], [`trait@gio::prelude::ApplicationExt`], [`trait@glib::ObjectExt`], [`trait@gio::prelude::ActionGroupExt`], [`trait@gio::prelude::ActionMapExt`]
    #[doc(alias = "GtkApplication")]
    pub struct Application(Object<ffi::GtkApplication, ffi::GtkApplicationClass>) @extends gio::Application, @implements gio::ActionGroup, gio::ActionMap;

    match fn {
        type_ => || ffi::gtk_application_get_type(),
    }
}

impl Application {
    pub const NONE: Option<&'static Application> = None;

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`Application`] objects.
    ///
    /// This method returns an instance of [`ApplicationBuilder`](crate::builders::ApplicationBuilder) which can be used to create [`Application`] objects.
    pub fn builder() -> ApplicationBuilder {
        ApplicationBuilder::default()
    }
}

#[derive(Clone, Default)]
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Application`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct ApplicationBuilder {
    menubar: Option<gio::MenuModel>,
    register_session: Option<bool>,
    action_group: Option<gio::ActionGroup>,
    application_id: Option<String>,
    flags: Option<gio::ApplicationFlags>,
    inactivity_timeout: Option<u32>,
    resource_base_path: Option<String>,
}

impl ApplicationBuilder {
    // rustdoc-stripper-ignore-next
    /// Create a new [`ApplicationBuilder`].
    pub fn new() -> Self {
        Self::default()
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`Application`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> Application {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        if let Some(ref menubar) = self.menubar {
            properties.push(("menubar", menubar));
        }
        if let Some(ref register_session) = self.register_session {
            properties.push(("register-session", register_session));
        }
        if let Some(ref action_group) = self.action_group {
            properties.push(("action-group", action_group));
        }
        if let Some(ref application_id) = self.application_id {
            properties.push(("application-id", application_id));
        }
        if let Some(ref flags) = self.flags {
            properties.push(("flags", flags));
        }
        if let Some(ref inactivity_timeout) = self.inactivity_timeout {
            properties.push(("inactivity-timeout", inactivity_timeout));
        }
        if let Some(ref resource_base_path) = self.resource_base_path {
            properties.push(("resource-base-path", resource_base_path));
        }
        let ret = glib::Object::new::<Application>(&properties);
        {
            Application::register_startup_hook(&ret);
        }
        ret
    }

    /// The `GMenuModel` to be used for the application's menu bar.
    pub fn menubar(mut self, menubar: &impl IsA<gio::MenuModel>) -> Self {
        self.menubar = Some(menubar.clone().upcast());
        self
    }

    /// Set this property to `TRUE` to register with the session manager.
    ///
    /// This will make GTK track the session state (such as the
    /// `property::Application::screensaver-active` property).
    pub fn register_session(mut self, register_session: bool) -> Self {
        self.register_session = Some(register_session);
        self
    }

    pub fn action_group(mut self, action_group: &impl IsA<gio::ActionGroup>) -> Self {
        self.action_group = Some(action_group.clone().upcast());
        self
    }

    pub fn application_id(mut self, application_id: &str) -> Self {
        self.application_id = Some(application_id.to_string());
        self
    }

    pub fn flags(mut self, flags: gio::ApplicationFlags) -> Self {
        self.flags = Some(flags);
        self
    }

    pub fn inactivity_timeout(mut self, inactivity_timeout: u32) -> Self {
        self.inactivity_timeout = Some(inactivity_timeout);
        self
    }

    pub fn resource_base_path(mut self, resource_base_path: &str) -> Self {
        self.resource_base_path = Some(resource_base_path.to_string());
        self
    }
}

/// Trait containing all [`struct@Application`] methods.
///
/// # Implementors
///
/// [`Application`][struct@crate::Application]
pub trait GtkApplicationExt: 'static {
    /// Adds a window to `application`.
    ///
    /// This call can only happen after the `application` has started;
    /// typically, you should add new application windows in response
    /// to the emission of the `GApplication::activate` signal.
    ///
    /// This call is equivalent to setting the `property::Window::application`
    /// property of `window` to `application`.
    ///
    /// Normally, the connection between the application and the window
    /// will remain until the window is destroyed, but you can explicitly
    /// remove it with [`remove_window()`][Self::remove_window()].
    ///
    /// GTK will keep the `application` running as long as it has
    /// any windows.
    /// ## `window`
    /// a [`Window`][crate::Window]
    #[doc(alias = "gtk_application_add_window")]
    fn add_window(&self, window: &impl IsA<Window>);

    /// Gets the accelerators that are currently associated with
    /// the given action.
    /// ## `detailed_action_name`
    /// a detailed action name, specifying an action
    ///   and target to obtain accelerators for
    ///
    /// # Returns
    ///
    ///
    ///   accelerators for `detailed_action_name`
    #[doc(alias = "gtk_application_get_accels_for_action")]
    #[doc(alias = "get_accels_for_action")]
    fn accels_for_action(&self, detailed_action_name: &str) -> Vec<glib::GString>;

    /// Returns the list of actions (possibly empty) that `accel` maps to.
    ///
    /// Each item in the list is a detailed action name in the usual form.
    ///
    /// This might be useful to discover if an accel already exists in
    /// order to prevent installation of a conflicting accelerator (from
    /// an accelerator editor or a plugin system, for example). Note that
    /// having more than one action per accelerator may not be a bad thing
    /// and might make sense in cases where the actions never appear in the
    /// same context.
    ///
    /// In case there are no actions for a given accelerator, an empty array
    /// is returned. `NULL` is never returned.
    ///
    /// It is a programmer error to pass an invalid accelerator string.
    ///
    /// If you are unsure, check it with [`accelerator_parse()`][crate::accelerator_parse()] first.
    /// ## `accel`
    /// an accelerator that can be parsed by [`accelerator_parse()`][crate::accelerator_parse()]
    ///
    /// # Returns
    ///
    /// a [`None`]-terminated array of actions for `accel`
    #[doc(alias = "gtk_application_get_actions_for_accel")]
    #[doc(alias = "get_actions_for_accel")]
    fn actions_for_accel(&self, accel: &str) -> Vec<glib::GString>;

    /// Gets the “active” window for the application.
    ///
    /// The active window is the one that was most recently focused (within
    /// the application).  This window may not have the focus at the moment
    /// if another application has it — this is just the most
    /// recently-focused window within this application.
    ///
    /// # Returns
    ///
    /// the active window
    #[doc(alias = "gtk_application_get_active_window")]
    #[doc(alias = "get_active_window")]
    fn active_window(&self) -> Option<Window>;

    /// Gets a menu from automatically loaded resources.
    ///
    /// See [the section on Automatic resources](class.Application.html#automatic-resources)
    /// for more information.
    /// ## `id`
    /// the id of the menu to look up
    ///
    /// # Returns
    ///
    /// Gets the menu with the
    ///   given id from the automatically loaded resources
    #[doc(alias = "gtk_application_get_menu_by_id")]
    #[doc(alias = "get_menu_by_id")]
    fn menu_by_id(&self, id: &str) -> Option<gio::Menu>;

    /// Returns the menu model that has been set with
    /// [`set_menubar()`][Self::set_menubar()].
    ///
    /// # Returns
    ///
    /// the menubar for windows of `application`
    #[doc(alias = "gtk_application_get_menubar")]
    #[doc(alias = "get_menubar")]
    fn menubar(&self) -> Option<gio::MenuModel>;

    /// Returns the [`ApplicationWindow`][crate::ApplicationWindow] with the given ID.
    ///
    /// The ID of a [`ApplicationWindow`][crate::ApplicationWindow] can be retrieved with
    /// [`ApplicationWindowExt::id()`][crate::prelude::ApplicationWindowExt::id()].
    /// ## `id`
    /// an identifier number
    ///
    /// # Returns
    ///
    /// the window for the given `id`
    #[doc(alias = "gtk_application_get_window_by_id")]
    #[doc(alias = "get_window_by_id")]
    fn window_by_id(&self, id: u32) -> Option<Window>;

    /// Gets a list of the [`Window`][crate::Window] instances associated with `application`.
    ///
    /// The list is sorted by most recently focused window, such that the first
    /// element is the currently focused window. (Useful for choosing a parent
    /// for a transient window.)
    ///
    /// The list that is returned should not be modified in any way. It will
    /// only remain valid until the next focus change or window creation or
    /// deletion.
    ///
    /// # Returns
    ///
    /// a `GList` of [`Window`][crate::Window]
    ///   instances
    #[doc(alias = "gtk_application_get_windows")]
    #[doc(alias = "get_windows")]
    fn windows(&self) -> Vec<Window>;

    /// Inform the session manager that certain types of actions should be
    /// inhibited.
    ///
    /// This is not guaranteed to work on all platforms and for all types of
    /// actions.
    ///
    /// Applications should invoke this method when they begin an operation
    /// that should not be interrupted, such as creating a CD or DVD. The
    /// types of actions that may be blocked are specified by the `flags`
    /// parameter. When the application completes the operation it should
    /// call [`uninhibit()`][Self::uninhibit()] to remove the inhibitor. Note
    /// that an application can have multiple inhibitors, and all of them must
    /// be individually removed. Inhibitors are also cleared when the
    /// application exits.
    ///
    /// Applications should not expect that they will always be able to block
    /// the action. In most cases, users will be given the option to force
    /// the action to take place.
    ///
    /// The `reason` message should be short and to the point.
    ///
    /// If `window` is given, the session manager may point the user to
    /// this window to find out more about why the action is inhibited.
    /// ## `window`
    /// a [`Window`][crate::Window]
    /// ## `flags`
    /// what types of actions should be inhibited
    /// ## `reason`
    /// a short, human-readable string that explains
    ///   why these operations are inhibited
    ///
    /// # Returns
    ///
    /// A non-zero cookie that is used to uniquely identify this
    ///   request. It should be used as an argument to [`uninhibit()`][Self::uninhibit()]
    ///   in order to remove the request. If the platform does not support
    ///   inhibiting or the request failed for some reason, 0 is returned.
    #[doc(alias = "gtk_application_inhibit")]
    fn inhibit(
        &self,
        window: Option<&impl IsA<Window>>,
        flags: ApplicationInhibitFlags,
        reason: Option<&str>,
    ) -> u32;

    /// Lists the detailed action names which have associated accelerators.
    ///
    /// See [`set_accels_for_action()`][Self::set_accels_for_action()].
    ///
    /// # Returns
    ///
    /// the detailed action names
    #[doc(alias = "gtk_application_list_action_descriptions")]
    fn list_action_descriptions(&self) -> Vec<glib::GString>;

    /// Remove a window from `application`.
    ///
    /// If `window` belongs to `application` then this call is equivalent to
    /// setting the `property::Window::application` property of `window` to
    /// `NULL`.
    ///
    /// The application may stop running as a result of a call to this
    /// function, if `window` was the last window of the `application`.
    /// ## `window`
    /// a [`Window`][crate::Window]
    #[doc(alias = "gtk_application_remove_window")]
    fn remove_window(&self, window: &impl IsA<Window>);

    /// Sets zero or more keyboard accelerators that will trigger the
    /// given action.
    ///
    /// The first item in `accels` will be the primary accelerator, which may be
    /// displayed in the UI.
    ///
    /// To remove all accelerators for an action, use an empty, zero-terminated
    /// array for `accels`.
    ///
    /// For the `detailed_action_name`, see `g_action_parse_detailed_name()` and
    /// `g_action_print_detailed_name()`.
    /// ## `detailed_action_name`
    /// a detailed action name, specifying an action
    ///   and target to associate accelerators with
    /// ## `accels`
    /// a list of accelerators in the format
    ///   understood by [`accelerator_parse()`][crate::accelerator_parse()]
    #[doc(alias = "gtk_application_set_accels_for_action")]
    fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str]);

    /// Sets or unsets the menubar for windows of `application`.
    ///
    /// This is a menubar in the traditional sense.
    ///
    /// This can only be done in the primary instance of the application,
    /// after it has been registered. `GApplication::startup` is a good place
    /// to call this.
    ///
    /// Depending on the desktop environment, this may appear at the top of
    /// each window, or at the top of the screen.  In some environments, if
    /// both the application menu and the menubar are set, the application
    /// menu will be presented as if it were the first item of the menubar.
    /// Other environments treat the two as completely separate — for example,
    /// the application menu may be rendered by the desktop shell while the
    /// menubar (if set) remains in each individual window.
    ///
    /// Use the base `GActionMap` interface to add actions, to respond to the
    /// user selecting these menu items.
    /// ## `menubar`
    /// a `GMenuModel`
    #[doc(alias = "gtk_application_set_menubar")]
    fn set_menubar(&self, menubar: Option<&impl IsA<gio::MenuModel>>);

    /// Removes an inhibitor that has been previously established.
    ///
    /// See [`inhibit()`][Self::inhibit()].
    ///
    /// Inhibitors are also cleared when the application exits.
    /// ## `cookie`
    /// a cookie that was returned by [`inhibit()`][Self::inhibit()]
    #[doc(alias = "gtk_application_uninhibit")]
    fn uninhibit(&self, cookie: u32);

    /// Set this property to `TRUE` to register with the session manager.
    ///
    /// This will make GTK track the session state (such as the
    /// `property::Application::screensaver-active` property).
    #[doc(alias = "register-session")]
    fn is_register_session(&self) -> bool;

    /// Set this property to `TRUE` to register with the session manager.
    ///
    /// This will make GTK track the session state (such as the
    /// `property::Application::screensaver-active` property).
    #[doc(alias = "register-session")]
    fn set_register_session(&self, register_session: bool);

    /// This property is `TRUE` if GTK believes that the screensaver is
    /// currently active.
    ///
    /// GTK only tracks session state (including this) when
    /// `property::Application::register-session` is set to [`true`].
    ///
    /// Tracking the screensaver state is currently only supported on
    /// Linux.
    #[doc(alias = "screensaver-active")]
    fn is_screensaver_active(&self) -> bool;

    /// Emitted when the session manager is about to end the session.
    ///
    /// This signal is only emitted if `property::Application::register-session`
    /// is `TRUE`. Applications can connect to this signal and call
    /// [`inhibit()`][Self::inhibit()] with `GTK_APPLICATION_INHIBIT_LOGOUT`
    /// to delay the end of the session until state has been saved.
    #[doc(alias = "query-end")]
    fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    /// Emitted when a [`Window`][crate::Window] is added to `application` through
    /// [`add_window()`][Self::add_window()].
    /// ## `window`
    /// the newly-added [`Window`][crate::Window]
    #[doc(alias = "window-added")]
    fn connect_window_added<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId;

    /// Emitted when a [`Window`][crate::Window] is removed from `application`.
    ///
    /// This can happen as a side-effect of the window being destroyed
    /// or explicitly through [`remove_window()`][Self::remove_window()].
    /// ## `window`
    /// the [`Window`][crate::Window] that is being removed
    #[doc(alias = "window-removed")]
    fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "active-window")]
    fn connect_active_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "menubar")]
    fn connect_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "register-session")]
    fn connect_register_session_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "screensaver-active")]
    fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Application>> GtkApplicationExt for O {
    fn add_window(&self, window: &impl IsA<Window>) {
        unsafe {
            ffi::gtk_application_add_window(
                self.as_ref().to_glib_none().0,
                window.as_ref().to_glib_none().0,
            );
        }
    }

    fn accels_for_action(&self, detailed_action_name: &str) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_accels_for_action(
                self.as_ref().to_glib_none().0,
                detailed_action_name.to_glib_none().0,
            ))
        }
    }

    fn actions_for_accel(&self, accel: &str) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_actions_for_accel(
                self.as_ref().to_glib_none().0,
                accel.to_glib_none().0,
            ))
        }
    }

    fn active_window(&self) -> Option<Window> {
        unsafe {
            from_glib_none(ffi::gtk_application_get_active_window(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn menu_by_id(&self, id: &str) -> Option<gio::Menu> {
        unsafe {
            from_glib_none(ffi::gtk_application_get_menu_by_id(
                self.as_ref().to_glib_none().0,
                id.to_glib_none().0,
            ))
        }
    }

    fn menubar(&self) -> Option<gio::MenuModel> {
        unsafe {
            from_glib_none(ffi::gtk_application_get_menubar(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn window_by_id(&self, id: u32) -> Option<Window> {
        unsafe {
            from_glib_none(ffi::gtk_application_get_window_by_id(
                self.as_ref().to_glib_none().0,
                id,
            ))
        }
    }

    fn windows(&self) -> Vec<Window> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(ffi::gtk_application_get_windows(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn inhibit(
        &self,
        window: Option<&impl IsA<Window>>,
        flags: ApplicationInhibitFlags,
        reason: Option<&str>,
    ) -> u32 {
        unsafe {
            ffi::gtk_application_inhibit(
                self.as_ref().to_glib_none().0,
                window.map(|p| p.as_ref()).to_glib_none().0,
                flags.into_glib(),
                reason.to_glib_none().0,
            )
        }
    }

    fn list_action_descriptions(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_list_action_descriptions(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn remove_window(&self, window: &impl IsA<Window>) {
        unsafe {
            ffi::gtk_application_remove_window(
                self.as_ref().to_glib_none().0,
                window.as_ref().to_glib_none().0,
            );
        }
    }

    fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str]) {
        unsafe {
            ffi::gtk_application_set_accels_for_action(
                self.as_ref().to_glib_none().0,
                detailed_action_name.to_glib_none().0,
                accels.to_glib_none().0,
            );
        }
    }

    fn set_menubar(&self, menubar: Option<&impl IsA<gio::MenuModel>>) {
        unsafe {
            ffi::gtk_application_set_menubar(
                self.as_ref().to_glib_none().0,
                menubar.map(|p| p.as_ref()).to_glib_none().0,
            );
        }
    }

    fn uninhibit(&self, cookie: u32) {
        unsafe {
            ffi::gtk_application_uninhibit(self.as_ref().to_glib_none().0, cookie);
        }
    }

    fn is_register_session(&self) -> bool {
        glib::ObjectExt::property(self.as_ref(), "register-session")
    }

    fn set_register_session(&self, register_session: bool) {
        glib::ObjectExt::set_property(self.as_ref(), "register-session", &register_session)
    }

    fn is_screensaver_active(&self) -> bool {
        glib::ObjectExt::property(self.as_ref(), "screensaver-active")
    }

    fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn query_end_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkApplication,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Application::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"query-end\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    query_end_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_window_added<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn window_added_trampoline<
            P: IsA<Application>,
            F: Fn(&P, &Window) + 'static,
        >(
            this: *mut ffi::GtkApplication,
            window: *mut ffi::GtkWindow,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Application::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(window),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"window-added\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    window_added_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn window_removed_trampoline<
            P: IsA<Application>,
            F: Fn(&P, &Window) + 'static,
        >(
            this: *mut ffi::GtkApplication,
            window: *mut ffi::GtkWindow,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Application::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(window),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"window-removed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    window_removed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_active_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_active_window_trampoline<
            P: IsA<Application>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkApplication,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Application::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::active-window\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_active_window_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_menubar_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
            this: *mut ffi::GtkApplication,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Application::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::menubar\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_menubar_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_register_session_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_register_session_trampoline<
            P: IsA<Application>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkApplication,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Application::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::register-session\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_register_session_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_screensaver_active_trampoline<
            P: IsA<Application>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkApplication,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Application::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::screensaver-active\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_screensaver_active_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Application {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Application")
    }
}