Skip to main content

gdk4/auto/
display.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#![allow(deprecated)]
5
6#[cfg(target_os = "linux")]
7#[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
8#[cfg(feature = "v4_14")]
9#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
10use crate::DmabufFormats;
11#[cfg(feature = "v4_6")]
12#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
13use crate::GLContext;
14use crate::{AppLaunchContext, Clipboard, Device, Event, Monitor, Seat, Surface, ffi};
15use glib::{
16    object::ObjectType as _,
17    prelude::*,
18    signal::{SignalHandlerId, connect_raw},
19    translate::*,
20};
21use std::boxed::Box as Box_;
22
23glib::wrapper! {
24    #[doc(alias = "GdkDisplay")]
25    pub struct Display(Object<ffi::GdkDisplay>);
26
27    match fn {
28        type_ => || ffi::gdk_display_get_type(),
29    }
30}
31
32impl Display {
33    pub const NONE: Option<&'static Display> = None;
34
35    #[doc(alias = "gdk_display_get_default")]
36    #[doc(alias = "get_default")]
37    #[allow(clippy::should_implement_trait)]
38    pub fn default() -> Option<Display> {
39        assert_initialized_main_thread!();
40        unsafe { from_glib_none(ffi::gdk_display_get_default()) }
41    }
42
43    #[doc(alias = "gdk_display_open")]
44    pub fn open(display_name: Option<&str>) -> Option<Display> {
45        assert_initialized_main_thread!();
46        unsafe { from_glib_none(ffi::gdk_display_open(display_name.to_glib_none().0)) }
47    }
48}
49
50impl std::fmt::Display for Display {
51    #[inline]
52    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
53        f.write_str(&DisplayExt::name(self))
54    }
55}
56
57pub trait DisplayExt: IsA<Display> + 'static {
58    #[doc(alias = "gdk_display_beep")]
59    fn beep(&self) {
60        unsafe {
61            ffi::gdk_display_beep(self.as_ref().to_glib_none().0);
62        }
63    }
64
65    #[doc(alias = "gdk_display_close")]
66    fn close(&self) {
67        unsafe {
68            ffi::gdk_display_close(self.as_ref().to_glib_none().0);
69        }
70    }
71
72    #[cfg(feature = "v4_6")]
73    #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
74    #[doc(alias = "gdk_display_create_gl_context")]
75    fn create_gl_context(&self) -> Result<GLContext, glib::Error> {
76        unsafe {
77            let mut error = std::ptr::null_mut();
78            let ret =
79                ffi::gdk_display_create_gl_context(self.as_ref().to_glib_none().0, &mut error);
80            if error.is_null() {
81                Ok(from_glib_full(ret))
82            } else {
83                Err(from_glib_full(error))
84            }
85        }
86    }
87
88    #[doc(alias = "gdk_display_device_is_grabbed")]
89    fn device_is_grabbed(&self, device: &impl IsA<Device>) -> bool {
90        unsafe {
91            from_glib(ffi::gdk_display_device_is_grabbed(
92                self.as_ref().to_glib_none().0,
93                device.as_ref().to_glib_none().0,
94            ))
95        }
96    }
97
98    #[doc(alias = "gdk_display_flush")]
99    fn flush(&self) {
100        unsafe {
101            ffi::gdk_display_flush(self.as_ref().to_glib_none().0);
102        }
103    }
104
105    #[doc(alias = "gdk_display_get_app_launch_context")]
106    #[doc(alias = "get_app_launch_context")]
107    fn app_launch_context(&self) -> AppLaunchContext {
108        unsafe {
109            from_glib_full(ffi::gdk_display_get_app_launch_context(
110                self.as_ref().to_glib_none().0,
111            ))
112        }
113    }
114
115    #[doc(alias = "gdk_display_get_clipboard")]
116    #[doc(alias = "get_clipboard")]
117    fn clipboard(&self) -> Clipboard {
118        unsafe {
119            from_glib_none(ffi::gdk_display_get_clipboard(
120                self.as_ref().to_glib_none().0,
121            ))
122        }
123    }
124
125    #[doc(alias = "gdk_display_get_default_seat")]
126    #[doc(alias = "get_default_seat")]
127    fn default_seat(&self) -> Option<Seat> {
128        unsafe {
129            from_glib_none(ffi::gdk_display_get_default_seat(
130                self.as_ref().to_glib_none().0,
131            ))
132        }
133    }
134
135    #[cfg(target_os = "linux")]
136    #[cfg_attr(docsrs, doc(cfg(target_os = "linux")))]
137    #[cfg(feature = "v4_14")]
138    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
139    #[doc(alias = "gdk_display_get_dmabuf_formats")]
140    #[doc(alias = "get_dmabuf_formats")]
141    #[doc(alias = "dmabuf-formats")]
142    fn dmabuf_formats(&self) -> DmabufFormats {
143        unsafe {
144            from_glib_none(ffi::gdk_display_get_dmabuf_formats(
145                self.as_ref().to_glib_none().0,
146            ))
147        }
148    }
149
150    #[doc(alias = "gdk_display_get_monitor_at_surface")]
151    #[doc(alias = "get_monitor_at_surface")]
152    fn monitor_at_surface(&self, surface: &impl IsA<Surface>) -> Option<Monitor> {
153        unsafe {
154            from_glib_none(ffi::gdk_display_get_monitor_at_surface(
155                self.as_ref().to_glib_none().0,
156                surface.as_ref().to_glib_none().0,
157            ))
158        }
159    }
160
161    #[doc(alias = "gdk_display_get_monitors")]
162    #[doc(alias = "get_monitors")]
163    fn monitors(&self) -> gio::ListModel {
164        unsafe {
165            from_glib_none(ffi::gdk_display_get_monitors(
166                self.as_ref().to_glib_none().0,
167            ))
168        }
169    }
170
171    #[doc(alias = "gdk_display_get_name")]
172    #[doc(alias = "get_name")]
173    fn name(&self) -> glib::GString {
174        unsafe { from_glib_none(ffi::gdk_display_get_name(self.as_ref().to_glib_none().0)) }
175    }
176
177    #[doc(alias = "gdk_display_get_primary_clipboard")]
178    #[doc(alias = "get_primary_clipboard")]
179    fn primary_clipboard(&self) -> Clipboard {
180        unsafe {
181            from_glib_none(ffi::gdk_display_get_primary_clipboard(
182                self.as_ref().to_glib_none().0,
183            ))
184        }
185    }
186
187    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
188    #[allow(deprecated)]
189    #[doc(alias = "gdk_display_get_startup_notification_id")]
190    #[doc(alias = "get_startup_notification_id")]
191    fn startup_notification_id(&self) -> Option<glib::GString> {
192        unsafe {
193            from_glib_none(ffi::gdk_display_get_startup_notification_id(
194                self.as_ref().to_glib_none().0,
195            ))
196        }
197    }
198
199    #[doc(alias = "gdk_display_is_closed")]
200    fn is_closed(&self) -> bool {
201        unsafe { from_glib(ffi::gdk_display_is_closed(self.as_ref().to_glib_none().0)) }
202    }
203
204    #[doc(alias = "gdk_display_is_composited")]
205    #[doc(alias = "composited")]
206    fn is_composited(&self) -> bool {
207        unsafe {
208            from_glib(ffi::gdk_display_is_composited(
209                self.as_ref().to_glib_none().0,
210            ))
211        }
212    }
213
214    #[doc(alias = "gdk_display_is_rgba")]
215    #[doc(alias = "rgba")]
216    fn is_rgba(&self) -> bool {
217        unsafe { from_glib(ffi::gdk_display_is_rgba(self.as_ref().to_glib_none().0)) }
218    }
219
220    #[doc(alias = "gdk_display_list_seats")]
221    fn list_seats(&self) -> Vec<Seat> {
222        unsafe {
223            FromGlibPtrContainer::from_glib_container(ffi::gdk_display_list_seats(
224                self.as_ref().to_glib_none().0,
225            ))
226        }
227    }
228
229    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
230    #[allow(deprecated)]
231    #[doc(alias = "gdk_display_notify_startup_complete")]
232    fn notify_startup_complete(&self, startup_id: &str) {
233        unsafe {
234            ffi::gdk_display_notify_startup_complete(
235                self.as_ref().to_glib_none().0,
236                startup_id.to_glib_none().0,
237            );
238        }
239    }
240
241    #[cfg(feature = "v4_4")]
242    #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
243    #[doc(alias = "gdk_display_prepare_gl")]
244    fn prepare_gl(&self) -> Result<(), glib::Error> {
245        unsafe {
246            let mut error = std::ptr::null_mut();
247            let is_ok = ffi::gdk_display_prepare_gl(self.as_ref().to_glib_none().0, &mut error);
248            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
249            if error.is_null() {
250                Ok(())
251            } else {
252                Err(from_glib_full(error))
253            }
254        }
255    }
256
257    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
258    #[allow(deprecated)]
259    #[doc(alias = "gdk_display_put_event")]
260    fn put_event(&self, event: impl AsRef<Event>) {
261        unsafe {
262            ffi::gdk_display_put_event(
263                self.as_ref().to_glib_none().0,
264                event.as_ref().to_glib_none().0,
265            );
266        }
267    }
268
269    #[doc(alias = "gdk_display_supports_input_shapes")]
270    #[doc(alias = "input-shapes")]
271    fn supports_input_shapes(&self) -> bool {
272        unsafe {
273            from_glib(ffi::gdk_display_supports_input_shapes(
274                self.as_ref().to_glib_none().0,
275            ))
276        }
277    }
278
279    #[cfg(feature = "v4_14")]
280    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
281    #[doc(alias = "gdk_display_supports_shadow_width")]
282    #[doc(alias = "shadow-width")]
283    fn supports_shadow_width(&self) -> bool {
284        unsafe {
285            from_glib(ffi::gdk_display_supports_shadow_width(
286                self.as_ref().to_glib_none().0,
287            ))
288        }
289    }
290
291    #[doc(alias = "gdk_display_sync")]
292    fn sync(&self) {
293        unsafe {
294            ffi::gdk_display_sync(self.as_ref().to_glib_none().0);
295        }
296    }
297
298    #[doc(alias = "closed")]
299    fn connect_closed<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId {
300        unsafe extern "C" fn closed_trampoline<P: IsA<Display>, F: Fn(&P, bool) + 'static>(
301            this: *mut ffi::GdkDisplay,
302            is_error: glib::ffi::gboolean,
303            f: glib::ffi::gpointer,
304        ) {
305            unsafe {
306                let f: &F = &*(f as *const F);
307                f(
308                    Display::from_glib_borrow(this).unsafe_cast_ref(),
309                    from_glib(is_error),
310                )
311            }
312        }
313        unsafe {
314            let f: Box_<F> = Box_::new(f);
315            connect_raw(
316                self.as_ptr() as *mut _,
317                c"closed".as_ptr(),
318                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
319                    closed_trampoline::<Self, F> as *const (),
320                )),
321                Box_::into_raw(f),
322            )
323        }
324    }
325
326    #[doc(alias = "opened")]
327    fn connect_opened<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
328        unsafe extern "C" fn opened_trampoline<P: IsA<Display>, F: Fn(&P) + 'static>(
329            this: *mut ffi::GdkDisplay,
330            f: glib::ffi::gpointer,
331        ) {
332            unsafe {
333                let f: &F = &*(f as *const F);
334                f(Display::from_glib_borrow(this).unsafe_cast_ref())
335            }
336        }
337        unsafe {
338            let f: Box_<F> = Box_::new(f);
339            connect_raw(
340                self.as_ptr() as *mut _,
341                c"opened".as_ptr(),
342                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
343                    opened_trampoline::<Self, F> as *const (),
344                )),
345                Box_::into_raw(f),
346            )
347        }
348    }
349
350    #[doc(alias = "seat-added")]
351    fn connect_seat_added<F: Fn(&Self, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
352        unsafe extern "C" fn seat_added_trampoline<P: IsA<Display>, F: Fn(&P, &Seat) + 'static>(
353            this: *mut ffi::GdkDisplay,
354            seat: *mut ffi::GdkSeat,
355            f: glib::ffi::gpointer,
356        ) {
357            unsafe {
358                let f: &F = &*(f as *const F);
359                f(
360                    Display::from_glib_borrow(this).unsafe_cast_ref(),
361                    &from_glib_borrow(seat),
362                )
363            }
364        }
365        unsafe {
366            let f: Box_<F> = Box_::new(f);
367            connect_raw(
368                self.as_ptr() as *mut _,
369                c"seat-added".as_ptr(),
370                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
371                    seat_added_trampoline::<Self, F> as *const (),
372                )),
373                Box_::into_raw(f),
374            )
375        }
376    }
377
378    #[doc(alias = "seat-removed")]
379    fn connect_seat_removed<F: Fn(&Self, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
380        unsafe extern "C" fn seat_removed_trampoline<
381            P: IsA<Display>,
382            F: Fn(&P, &Seat) + 'static,
383        >(
384            this: *mut ffi::GdkDisplay,
385            seat: *mut ffi::GdkSeat,
386            f: glib::ffi::gpointer,
387        ) {
388            unsafe {
389                let f: &F = &*(f as *const F);
390                f(
391                    Display::from_glib_borrow(this).unsafe_cast_ref(),
392                    &from_glib_borrow(seat),
393                )
394            }
395        }
396        unsafe {
397            let f: Box_<F> = Box_::new(f);
398            connect_raw(
399                self.as_ptr() as *mut _,
400                c"seat-removed".as_ptr(),
401                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
402                    seat_removed_trampoline::<Self, F> as *const (),
403                )),
404                Box_::into_raw(f),
405            )
406        }
407    }
408
409    #[doc(alias = "setting-changed")]
410    fn connect_setting_changed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
411        unsafe extern "C" fn setting_changed_trampoline<
412            P: IsA<Display>,
413            F: Fn(&P, &str) + 'static,
414        >(
415            this: *mut ffi::GdkDisplay,
416            setting: *mut std::ffi::c_char,
417            f: glib::ffi::gpointer,
418        ) {
419            unsafe {
420                let f: &F = &*(f as *const F);
421                f(
422                    Display::from_glib_borrow(this).unsafe_cast_ref(),
423                    &glib::GString::from_glib_borrow(setting),
424                )
425            }
426        }
427        unsafe {
428            let f: Box_<F> = Box_::new(f);
429            connect_raw(
430                self.as_ptr() as *mut _,
431                c"setting-changed".as_ptr(),
432                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
433                    setting_changed_trampoline::<Self, F> as *const (),
434                )),
435                Box_::into_raw(f),
436            )
437        }
438    }
439
440    #[doc(alias = "composited")]
441    fn connect_composited_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
442        unsafe extern "C" fn notify_composited_trampoline<P: IsA<Display>, F: Fn(&P) + 'static>(
443            this: *mut ffi::GdkDisplay,
444            _param_spec: glib::ffi::gpointer,
445            f: glib::ffi::gpointer,
446        ) {
447            unsafe {
448                let f: &F = &*(f as *const F);
449                f(Display::from_glib_borrow(this).unsafe_cast_ref())
450            }
451        }
452        unsafe {
453            let f: Box_<F> = Box_::new(f);
454            connect_raw(
455                self.as_ptr() as *mut _,
456                c"notify::composited".as_ptr(),
457                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
458                    notify_composited_trampoline::<Self, F> as *const (),
459                )),
460                Box_::into_raw(f),
461            )
462        }
463    }
464
465    #[cfg(feature = "v4_14")]
466    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
467    #[doc(alias = "dmabuf-formats")]
468    fn connect_dmabuf_formats_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
469        unsafe extern "C" fn notify_dmabuf_formats_trampoline<
470            P: IsA<Display>,
471            F: Fn(&P) + 'static,
472        >(
473            this: *mut ffi::GdkDisplay,
474            _param_spec: glib::ffi::gpointer,
475            f: glib::ffi::gpointer,
476        ) {
477            unsafe {
478                let f: &F = &*(f as *const F);
479                f(Display::from_glib_borrow(this).unsafe_cast_ref())
480            }
481        }
482        unsafe {
483            let f: Box_<F> = Box_::new(f);
484            connect_raw(
485                self.as_ptr() as *mut _,
486                c"notify::dmabuf-formats".as_ptr(),
487                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
488                    notify_dmabuf_formats_trampoline::<Self, F> as *const (),
489                )),
490                Box_::into_raw(f),
491            )
492        }
493    }
494
495    #[doc(alias = "input-shapes")]
496    fn connect_input_shapes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
497        unsafe extern "C" fn notify_input_shapes_trampoline<
498            P: IsA<Display>,
499            F: Fn(&P) + 'static,
500        >(
501            this: *mut ffi::GdkDisplay,
502            _param_spec: glib::ffi::gpointer,
503            f: glib::ffi::gpointer,
504        ) {
505            unsafe {
506                let f: &F = &*(f as *const F);
507                f(Display::from_glib_borrow(this).unsafe_cast_ref())
508            }
509        }
510        unsafe {
511            let f: Box_<F> = Box_::new(f);
512            connect_raw(
513                self.as_ptr() as *mut _,
514                c"notify::input-shapes".as_ptr(),
515                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
516                    notify_input_shapes_trampoline::<Self, F> as *const (),
517                )),
518                Box_::into_raw(f),
519            )
520        }
521    }
522
523    #[doc(alias = "rgba")]
524    fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
525        unsafe extern "C" fn notify_rgba_trampoline<P: IsA<Display>, F: Fn(&P) + 'static>(
526            this: *mut ffi::GdkDisplay,
527            _param_spec: glib::ffi::gpointer,
528            f: glib::ffi::gpointer,
529        ) {
530            unsafe {
531                let f: &F = &*(f as *const F);
532                f(Display::from_glib_borrow(this).unsafe_cast_ref())
533            }
534        }
535        unsafe {
536            let f: Box_<F> = Box_::new(f);
537            connect_raw(
538                self.as_ptr() as *mut _,
539                c"notify::rgba".as_ptr(),
540                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
541                    notify_rgba_trampoline::<Self, F> as *const (),
542                )),
543                Box_::into_raw(f),
544            )
545        }
546    }
547
548    #[cfg(feature = "v4_14")]
549    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
550    #[doc(alias = "shadow-width")]
551    fn connect_shadow_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
552        unsafe extern "C" fn notify_shadow_width_trampoline<
553            P: IsA<Display>,
554            F: Fn(&P) + 'static,
555        >(
556            this: *mut ffi::GdkDisplay,
557            _param_spec: glib::ffi::gpointer,
558            f: glib::ffi::gpointer,
559        ) {
560            unsafe {
561                let f: &F = &*(f as *const F);
562                f(Display::from_glib_borrow(this).unsafe_cast_ref())
563            }
564        }
565        unsafe {
566            let f: Box_<F> = Box_::new(f);
567            connect_raw(
568                self.as_ptr() as *mut _,
569                c"notify::shadow-width".as_ptr(),
570                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
571                    notify_shadow_width_trampoline::<Self, F> as *const (),
572                )),
573                Box_::into_raw(f),
574            )
575        }
576    }
577}
578
579impl<O: IsA<Display>> DisplayExt for O {}