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
// 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
#![allow(deprecated)]

#[cfg(feature = "v4_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
use crate::GLContext;
use crate::{AppLaunchContext, Clipboard, Device, Event, Monitor, Seat, Surface};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
#[cfg(feature = "v4_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
use std::ptr;
use std::{boxed::Box as Box_, fmt, mem::transmute};

glib::wrapper! {
    /// [`Display`][crate::Display] objects are the GDK representation of a workstation.
    ///
    /// Their purpose are two-fold:
    ///
    /// - To manage and provide information about input devices (pointers, keyboards, etc)
    /// - To manage and provide information about output devices (monitors, projectors, etc)
    ///
    /// Most of the input device handling has been factored out into separate
    /// [`Seat`][crate::Seat] objects. Every display has a one or more seats, which
    /// can be accessed with [`DisplayExt::default_seat()`][crate::prelude::DisplayExt::default_seat()] and
    /// [`DisplayExt::list_seats()`][crate::prelude::DisplayExt::list_seats()].
    ///
    /// Output devices are represented by [`Monitor`][crate::Monitor] objects, which can
    /// be accessed with [`DisplayExt::monitor_at_surface()`][crate::prelude::DisplayExt::monitor_at_surface()] and similar APIs.
    ///
    /// ## Properties
    ///
    ///
    /// #### `composited`
    ///  [`true`] if the display properly composites the alpha channel.
    ///
    /// Readable
    ///
    ///
    /// #### `input-shapes`
    ///  [`true`] if the display supports input shapes.
    ///
    /// Readable
    ///
    ///
    /// #### `rgba`
    ///  [`true`] if the display supports an alpha channel.
    ///
    /// Readable
    ///
    /// ## Signals
    ///
    ///
    /// #### `closed`
    ///  Emitted when the connection to the windowing system for @display is closed.
    ///
    ///
    ///
    ///
    /// #### `opened`
    ///  Emitted when the connection to the windowing system for @display is opened.
    ///
    ///
    ///
    ///
    /// #### `seat-added`
    ///  Emitted whenever a new seat is made known to the windowing system.
    ///
    ///
    ///
    ///
    /// #### `seat-removed`
    ///  Emitted whenever a seat is removed by the windowing system.
    ///
    ///
    ///
    ///
    /// #### `setting-changed`
    ///  Emitted whenever a setting changes its value.
    ///
    ///
    ///
    /// # Implements
    ///
    /// [`DisplayExt`][trait@crate::prelude::DisplayExt], [`DisplayExtManual`][trait@crate::prelude::DisplayExtManual]
    #[doc(alias = "GdkDisplay")]
    pub struct Display(Object<ffi::GdkDisplay>);

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

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

    /// Gets the default [`Display`][crate::Display].
    ///
    /// This is a convenience function for:
    ///
    ///     gdk_display_manager_get_default_display (gdk_display_manager_get ())
    ///
    /// # Returns
    ///
    /// a [`Display`][crate::Display], or [`None`] if
    ///   there is no default display
    #[doc(alias = "gdk_display_get_default")]
    #[doc(alias = "get_default")]
    #[allow(clippy::should_implement_trait)]
    pub fn default() -> Option<Display> {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::gdk_display_get_default()) }
    }

    /// Opens a display.
    ///
    /// If opening the display fails, `NULL` is returned.
    /// ## `display_name`
    /// the name of the display to open
    ///
    /// # Returns
    ///
    /// a [`Display`][crate::Display]
    #[doc(alias = "gdk_display_open")]
    pub fn open(display_name: Option<&str>) -> Option<Display> {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::gdk_display_open(display_name.to_glib_none().0)) }
    }
}

impl fmt::Display for Display {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(&DisplayExt::name(self))
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Display>> Sealed for T {}
}

/// Trait containing all [`struct@Display`] methods.
///
/// # Implementors
///
/// [`Display`][struct@crate::Display]
pub trait DisplayExt: IsA<Display> + sealed::Sealed + 'static {
    /// Emits a short beep on @self
    #[doc(alias = "gdk_display_beep")]
    fn beep(&self) {
        unsafe {
            ffi::gdk_display_beep(self.as_ref().to_glib_none().0);
        }
    }

    /// Closes the connection to the windowing system for the given display.
    ///
    /// This cleans up associated resources.
    #[doc(alias = "gdk_display_close")]
    fn close(&self) {
        unsafe {
            ffi::gdk_display_close(self.as_ref().to_glib_none().0);
        }
    }

    /// Creates a new [`GLContext`][crate::GLContext] for the [`Display`][crate::Display].
    ///
    /// The context is disconnected from any particular surface or surface
    /// and cannot be used to draw to any surface. It can only be used to
    /// draw to non-surface framebuffers like textures.
    ///
    /// If the creation of the [`GLContext`][crate::GLContext] failed, @error will be set.
    /// Before using the returned [`GLContext`][crate::GLContext], you will need to
    /// call [`GLContextExt::make_current()`][crate::prelude::GLContextExt::make_current()] or [`GLContextExt::realize()`][crate::prelude::GLContextExt::realize()].
    ///
    /// # Returns
    ///
    /// the newly created [`GLContext`][crate::GLContext]
    #[cfg(feature = "v4_6")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
    #[doc(alias = "gdk_display_create_gl_context")]
    fn create_gl_context(&self) -> Result<GLContext, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret =
                ffi::gdk_display_create_gl_context(self.as_ref().to_glib_none().0, &mut error);
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Returns [`true`] if there is an ongoing grab on @device for @self.
    /// ## `device`
    /// a [`Device`][crate::Device]
    ///
    /// # Returns
    ///
    /// [`true`] if there is a grab in effect for @device.
    #[doc(alias = "gdk_display_device_is_grabbed")]
    fn device_is_grabbed(&self, device: &impl IsA<Device>) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_device_is_grabbed(
                self.as_ref().to_glib_none().0,
                device.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Flushes any requests queued for the windowing system.
    ///
    /// This happens automatically when the main loop blocks waiting for new events,
    /// but if your application is drawing without returning control to the main loop,
    /// you may need to call this function explicitly. A common case where this function
    /// needs to be called is when an application is executing drawing commands
    /// from a thread other than the thread where the main loop is running.
    ///
    /// This is most useful for X11. On windowing systems where requests are
    /// handled synchronously, this function will do nothing.
    #[doc(alias = "gdk_display_flush")]
    fn flush(&self) {
        unsafe {
            ffi::gdk_display_flush(self.as_ref().to_glib_none().0);
        }
    }

    /// Returns a [`AppLaunchContext`][crate::AppLaunchContext] suitable for launching
    /// applications on the given display.
    ///
    /// # Returns
    ///
    /// a new [`AppLaunchContext`][crate::AppLaunchContext] for @self
    #[doc(alias = "gdk_display_get_app_launch_context")]
    #[doc(alias = "get_app_launch_context")]
    fn app_launch_context(&self) -> AppLaunchContext {
        unsafe {
            from_glib_full(ffi::gdk_display_get_app_launch_context(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the clipboard used for copy/paste operations.
    ///
    /// # Returns
    ///
    /// the display's clipboard
    #[doc(alias = "gdk_display_get_clipboard")]
    #[doc(alias = "get_clipboard")]
    fn clipboard(&self) -> Clipboard {
        unsafe {
            from_glib_none(ffi::gdk_display_get_clipboard(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Returns the default [`Seat`][crate::Seat] for this display.
    ///
    /// Note that a display may not have a seat. In this case,
    /// this function will return [`None`].
    ///
    /// # Returns
    ///
    /// the default seat.
    #[doc(alias = "gdk_display_get_default_seat")]
    #[doc(alias = "get_default_seat")]
    fn default_seat(&self) -> Option<Seat> {
        unsafe {
            from_glib_none(ffi::gdk_display_get_default_seat(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the monitor in which the largest area of @surface
    /// resides.
    /// ## `surface`
    /// a [`Surface`][crate::Surface]
    ///
    /// # Returns
    ///
    /// the monitor with the largest
    ///   overlap with @surface
    #[doc(alias = "gdk_display_get_monitor_at_surface")]
    #[doc(alias = "get_monitor_at_surface")]
    fn monitor_at_surface(&self, surface: &impl IsA<Surface>) -> Option<Monitor> {
        unsafe {
            from_glib_none(ffi::gdk_display_get_monitor_at_surface(
                self.as_ref().to_glib_none().0,
                surface.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the list of monitors associated with this display.
    ///
    /// Subsequent calls to this function will always return the
    /// same list for the same display.
    ///
    /// You can listen to the GListModel::items-changed signal on
    /// this list to monitor changes to the monitor of this display.
    ///
    /// # Returns
    ///
    /// a `GListModel` of [`Monitor`][crate::Monitor]
    #[doc(alias = "gdk_display_get_monitors")]
    #[doc(alias = "get_monitors")]
    fn monitors(&self) -> gio::ListModel {
        unsafe {
            from_glib_none(ffi::gdk_display_get_monitors(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the name of the display.
    ///
    /// # Returns
    ///
    /// a string representing the display name. This string is owned
    ///   by GDK and should not be modified or freed.
    #[doc(alias = "gdk_display_get_name")]
    #[doc(alias = "get_name")]
    fn name(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::gdk_display_get_name(self.as_ref().to_glib_none().0)) }
    }

    /// Gets the clipboard used for the primary selection.
    ///
    /// On backends where the primary clipboard is not supported natively,
    /// GDK emulates this clipboard locally.
    ///
    /// # Returns
    ///
    /// the primary clipboard
    #[doc(alias = "gdk_display_get_primary_clipboard")]
    #[doc(alias = "get_primary_clipboard")]
    fn primary_clipboard(&self) -> Clipboard {
        unsafe {
            from_glib_none(ffi::gdk_display_get_primary_clipboard(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the startup notification ID for a Wayland display, or [`None`]
    /// if no ID has been defined.
    ///
    /// # Deprecated since 4.10
    ///
    ///
    /// # Returns
    ///
    /// the startup notification ID for @self
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gdk_display_get_startup_notification_id")]
    #[doc(alias = "get_startup_notification_id")]
    fn startup_notification_id(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gdk_display_get_startup_notification_id(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Finds out if the display has been closed.
    ///
    /// # Returns
    ///
    /// [`true`] if the display is closed.
    #[doc(alias = "gdk_display_is_closed")]
    fn is_closed(&self) -> bool {
        unsafe { from_glib(ffi::gdk_display_is_closed(self.as_ref().to_glib_none().0)) }
    }

    /// Returns whether surfaces can reasonably be expected to have
    /// their alpha channel drawn correctly on the screen.
    ///
    /// Check [`is_rgba()`][Self::is_rgba()] for whether the display
    /// supports an alpha channel.
    ///
    /// On X11 this function returns whether a compositing manager is
    /// compositing on @self.
    ///
    /// On modern displays, this value is always [`true`].
    ///
    /// # Returns
    ///
    /// Whether surfaces with RGBA visuals can reasonably
    ///   be expected to have their alpha channels drawn correctly
    ///   on the screen.
    #[doc(alias = "gdk_display_is_composited")]
    fn is_composited(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_is_composited(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Returns whether surfaces on this @self are created with an
    /// alpha channel.
    ///
    /// Even if a [`true`] is returned, it is possible that the
    /// surface’s alpha channel won’t be honored when displaying the
    /// surface on the screen: in particular, for X an appropriate
    /// windowing manager and compositing manager must be running to
    /// provide appropriate display. Use [`is_composited()`][Self::is_composited()]
    /// to check if that is the case.
    ///
    /// On modern displays, this value is always [`true`].
    ///
    /// # Returns
    ///
    /// [`true`] if surfaces are created with an alpha channel or
    ///   [`false`] if the display does not support this functionality.
    #[doc(alias = "gdk_display_is_rgba")]
    fn is_rgba(&self) -> bool {
        unsafe { from_glib(ffi::gdk_display_is_rgba(self.as_ref().to_glib_none().0)) }
    }

    /// Returns the list of seats known to @self.
    ///
    /// # Returns
    ///
    /// the
    ///   list of seats known to the [`Display`][crate::Display]
    #[doc(alias = "gdk_display_list_seats")]
    fn list_seats(&self) -> Vec<Seat> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gdk_display_list_seats(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Indicates to the GUI environment that the application has
    /// finished loading, using a given identifier.
    ///
    /// GTK will call this function automatically for `Gtk::Window`
    /// with custom startup-notification identifier unless
    /// `Gtk::Window::set_auto_startup_notification()`
    /// is called to disable that feature.
    ///
    /// # Deprecated since 4.10
    ///
    /// Using [`ToplevelExt::set_startup_id()`][crate::prelude::ToplevelExt::set_startup_id()] is sufficient
    /// ## `startup_id`
    /// a startup-notification identifier, for which
    ///   notification process should be completed
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gdk_display_notify_startup_complete")]
    fn notify_startup_complete(&self, startup_id: &str) {
        unsafe {
            ffi::gdk_display_notify_startup_complete(
                self.as_ref().to_glib_none().0,
                startup_id.to_glib_none().0,
            );
        }
    }

    /// Checks that OpenGL is available for @self and ensures that it is
    /// properly initialized.
    /// When this fails, an @error will be set describing the error and this
    /// function returns [`false`].
    ///
    /// Note that even if this function succeeds, creating a [`GLContext`][crate::GLContext]
    /// may still fail.
    ///
    /// This function is idempotent. Calling it multiple times will just
    /// return the same value or error.
    ///
    /// You never need to call this function, GDK will call it automatically
    /// as needed. But you can use it as a check when setting up code that
    /// might make use of OpenGL.
    ///
    /// # Returns
    ///
    /// [`true`] if the display supports OpenGL
    #[cfg(feature = "v4_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
    #[doc(alias = "gdk_display_prepare_gl")]
    fn prepare_gl(&self) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let is_ok = ffi::gdk_display_prepare_gl(self.as_ref().to_glib_none().0, &mut error);
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Adds the given event to the event queue for @self.
    ///
    /// # Deprecated since 4.10
    ///
    /// This function is only useful in very
    /// special situations and should not be used by applications.
    /// ## `event`
    /// a [`Event`][crate::Event]
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gdk_display_put_event")]
    fn put_event(&self, event: impl AsRef<Event>) {
        unsafe {
            ffi::gdk_display_put_event(
                self.as_ref().to_glib_none().0,
                event.as_ref().to_glib_none().0,
            );
        }
    }

    /// Returns [`true`] if the display supports input shapes.
    ///
    /// This means that [`SurfaceExt::set_input_region()`][crate::prelude::SurfaceExt::set_input_region()] can
    /// be used to modify the input shape of surfaces on @self.
    ///
    /// On modern displays, this value is always [`true`].
    ///
    /// # Returns
    ///
    /// [`true`] if surfaces with modified input shape are supported
    #[doc(alias = "gdk_display_supports_input_shapes")]
    fn supports_input_shapes(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_supports_input_shapes(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Flushes any requests queued for the windowing system and waits until all
    /// requests have been handled.
    ///
    /// This is often used for making sure that the display is synchronized
    /// with the current state of the program. Calling [`sync()`][Self::sync()]
    /// before `GdkX11::Display::error_trap_pop()` makes sure that any errors
    /// generated from earlier requests are handled before the error trap is removed.
    ///
    /// This is most useful for X11. On windowing systems where requests are
    /// handled synchronously, this function will do nothing.
    #[doc(alias = "gdk_display_sync")]
    fn sync(&self) {
        unsafe {
            ffi::gdk_display_sync(self.as_ref().to_glib_none().0);
        }
    }

    /// [`true`] if the display supports input shapes.
    #[doc(alias = "input-shapes")]
    fn is_input_shapes(&self) -> bool {
        ObjectExt::property(self.as_ref(), "input-shapes")
    }

    /// Emitted when the connection to the windowing system for @display is closed.
    /// ## `is_error`
    /// [`true`] if the display was closed due to an error
    #[doc(alias = "closed")]
    fn connect_closed<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn closed_trampoline<P: IsA<Display>, F: Fn(&P, bool) + 'static>(
            this: *mut ffi::GdkDisplay,
            is_error: glib::ffi::gboolean,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Display::from_glib_borrow(this).unsafe_cast_ref(),
                from_glib(is_error),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"closed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    closed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when the connection to the windowing system for @display is opened.
    #[doc(alias = "opened")]
    fn connect_opened<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn opened_trampoline<P: IsA<Display>, F: Fn(&P) + 'static>(
            this: *mut ffi::GdkDisplay,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Display::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"opened\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    opened_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted whenever a new seat is made known to the windowing system.
    /// ## `seat`
    /// the seat that was just added
    #[doc(alias = "seat-added")]
    fn connect_seat_added<F: Fn(&Self, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn seat_added_trampoline<P: IsA<Display>, F: Fn(&P, &Seat) + 'static>(
            this: *mut ffi::GdkDisplay,
            seat: *mut ffi::GdkSeat,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Display::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(seat),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"seat-added\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    seat_added_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted whenever a seat is removed by the windowing system.
    /// ## `seat`
    /// the seat that was just removed
    #[doc(alias = "seat-removed")]
    fn connect_seat_removed<F: Fn(&Self, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn seat_removed_trampoline<
            P: IsA<Display>,
            F: Fn(&P, &Seat) + 'static,
        >(
            this: *mut ffi::GdkDisplay,
            seat: *mut ffi::GdkSeat,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Display::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(seat),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"seat-removed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    seat_removed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted whenever a setting changes its value.
    /// ## `setting`
    /// the name of the setting that changed
    #[doc(alias = "setting-changed")]
    fn connect_setting_changed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn setting_changed_trampoline<
            P: IsA<Display>,
            F: Fn(&P, &str) + 'static,
        >(
            this: *mut ffi::GdkDisplay,
            setting: *mut libc::c_char,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Display::from_glib_borrow(this).unsafe_cast_ref(),
                &glib::GString::from_glib_borrow(setting),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"setting-changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    setting_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "composited")]
    fn connect_composited_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_composited_trampoline<P: IsA<Display>, F: Fn(&P) + 'static>(
            this: *mut ffi::GdkDisplay,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Display::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::composited\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_composited_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "input-shapes")]
    fn connect_input_shapes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_input_shapes_trampoline<
            P: IsA<Display>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GdkDisplay,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Display::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::input-shapes\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_input_shapes_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "rgba")]
    fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_rgba_trampoline<P: IsA<Display>, F: Fn(&P) + 'static>(
            this: *mut ffi::GdkDisplay,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Display::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::rgba\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_rgba_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<Display>> DisplayExt for O {}