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::{ffi, AppLaunchContext, Clipboard, Device, Event, Monitor, Seat, Surface};
15use glib::{
16    object::ObjectType as _,
17    prelude::*,
18    signal::{connect_raw, SignalHandlerId},
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            let f: &F = &*(f as *const F);
306            f(
307                Display::from_glib_borrow(this).unsafe_cast_ref(),
308                from_glib(is_error),
309            )
310        }
311        unsafe {
312            let f: Box_<F> = Box_::new(f);
313            connect_raw(
314                self.as_ptr() as *mut _,
315                c"closed".as_ptr() as *const _,
316                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
317                    closed_trampoline::<Self, F> as *const (),
318                )),
319                Box_::into_raw(f),
320            )
321        }
322    }
323
324    #[doc(alias = "opened")]
325    fn connect_opened<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
326        unsafe extern "C" fn opened_trampoline<P: IsA<Display>, F: Fn(&P) + 'static>(
327            this: *mut ffi::GdkDisplay,
328            f: glib::ffi::gpointer,
329        ) {
330            let f: &F = &*(f as *const F);
331            f(Display::from_glib_borrow(this).unsafe_cast_ref())
332        }
333        unsafe {
334            let f: Box_<F> = Box_::new(f);
335            connect_raw(
336                self.as_ptr() as *mut _,
337                c"opened".as_ptr() as *const _,
338                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
339                    opened_trampoline::<Self, F> as *const (),
340                )),
341                Box_::into_raw(f),
342            )
343        }
344    }
345
346    #[doc(alias = "seat-added")]
347    fn connect_seat_added<F: Fn(&Self, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
348        unsafe extern "C" fn seat_added_trampoline<P: IsA<Display>, F: Fn(&P, &Seat) + 'static>(
349            this: *mut ffi::GdkDisplay,
350            seat: *mut ffi::GdkSeat,
351            f: glib::ffi::gpointer,
352        ) {
353            let f: &F = &*(f as *const F);
354            f(
355                Display::from_glib_borrow(this).unsafe_cast_ref(),
356                &from_glib_borrow(seat),
357            )
358        }
359        unsafe {
360            let f: Box_<F> = Box_::new(f);
361            connect_raw(
362                self.as_ptr() as *mut _,
363                c"seat-added".as_ptr() as *const _,
364                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
365                    seat_added_trampoline::<Self, F> as *const (),
366                )),
367                Box_::into_raw(f),
368            )
369        }
370    }
371
372    #[doc(alias = "seat-removed")]
373    fn connect_seat_removed<F: Fn(&Self, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
374        unsafe extern "C" fn seat_removed_trampoline<
375            P: IsA<Display>,
376            F: Fn(&P, &Seat) + 'static,
377        >(
378            this: *mut ffi::GdkDisplay,
379            seat: *mut ffi::GdkSeat,
380            f: glib::ffi::gpointer,
381        ) {
382            let f: &F = &*(f as *const F);
383            f(
384                Display::from_glib_borrow(this).unsafe_cast_ref(),
385                &from_glib_borrow(seat),
386            )
387        }
388        unsafe {
389            let f: Box_<F> = Box_::new(f);
390            connect_raw(
391                self.as_ptr() as *mut _,
392                c"seat-removed".as_ptr() as *const _,
393                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
394                    seat_removed_trampoline::<Self, F> as *const (),
395                )),
396                Box_::into_raw(f),
397            )
398        }
399    }
400
401    #[doc(alias = "setting-changed")]
402    fn connect_setting_changed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
403        unsafe extern "C" fn setting_changed_trampoline<
404            P: IsA<Display>,
405            F: Fn(&P, &str) + 'static,
406        >(
407            this: *mut ffi::GdkDisplay,
408            setting: *mut std::ffi::c_char,
409            f: glib::ffi::gpointer,
410        ) {
411            let f: &F = &*(f as *const F);
412            f(
413                Display::from_glib_borrow(this).unsafe_cast_ref(),
414                &glib::GString::from_glib_borrow(setting),
415            )
416        }
417        unsafe {
418            let f: Box_<F> = Box_::new(f);
419            connect_raw(
420                self.as_ptr() as *mut _,
421                c"setting-changed".as_ptr() as *const _,
422                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
423                    setting_changed_trampoline::<Self, F> as *const (),
424                )),
425                Box_::into_raw(f),
426            )
427        }
428    }
429
430    #[doc(alias = "composited")]
431    fn connect_composited_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
432        unsafe extern "C" fn notify_composited_trampoline<P: IsA<Display>, F: Fn(&P) + 'static>(
433            this: *mut ffi::GdkDisplay,
434            _param_spec: glib::ffi::gpointer,
435            f: glib::ffi::gpointer,
436        ) {
437            let f: &F = &*(f as *const F);
438            f(Display::from_glib_borrow(this).unsafe_cast_ref())
439        }
440        unsafe {
441            let f: Box_<F> = Box_::new(f);
442            connect_raw(
443                self.as_ptr() as *mut _,
444                c"notify::composited".as_ptr() as *const _,
445                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
446                    notify_composited_trampoline::<Self, F> as *const (),
447                )),
448                Box_::into_raw(f),
449            )
450        }
451    }
452
453    #[cfg(feature = "v4_14")]
454    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
455    #[doc(alias = "dmabuf-formats")]
456    fn connect_dmabuf_formats_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
457        unsafe extern "C" fn notify_dmabuf_formats_trampoline<
458            P: IsA<Display>,
459            F: Fn(&P) + 'static,
460        >(
461            this: *mut ffi::GdkDisplay,
462            _param_spec: glib::ffi::gpointer,
463            f: glib::ffi::gpointer,
464        ) {
465            let f: &F = &*(f as *const F);
466            f(Display::from_glib_borrow(this).unsafe_cast_ref())
467        }
468        unsafe {
469            let f: Box_<F> = Box_::new(f);
470            connect_raw(
471                self.as_ptr() as *mut _,
472                c"notify::dmabuf-formats".as_ptr() as *const _,
473                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
474                    notify_dmabuf_formats_trampoline::<Self, F> as *const (),
475                )),
476                Box_::into_raw(f),
477            )
478        }
479    }
480
481    #[doc(alias = "input-shapes")]
482    fn connect_input_shapes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
483        unsafe extern "C" fn notify_input_shapes_trampoline<
484            P: IsA<Display>,
485            F: Fn(&P) + 'static,
486        >(
487            this: *mut ffi::GdkDisplay,
488            _param_spec: glib::ffi::gpointer,
489            f: glib::ffi::gpointer,
490        ) {
491            let f: &F = &*(f as *const F);
492            f(Display::from_glib_borrow(this).unsafe_cast_ref())
493        }
494        unsafe {
495            let f: Box_<F> = Box_::new(f);
496            connect_raw(
497                self.as_ptr() as *mut _,
498                c"notify::input-shapes".as_ptr() as *const _,
499                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
500                    notify_input_shapes_trampoline::<Self, F> as *const (),
501                )),
502                Box_::into_raw(f),
503            )
504        }
505    }
506
507    #[doc(alias = "rgba")]
508    fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
509        unsafe extern "C" fn notify_rgba_trampoline<P: IsA<Display>, F: Fn(&P) + 'static>(
510            this: *mut ffi::GdkDisplay,
511            _param_spec: glib::ffi::gpointer,
512            f: glib::ffi::gpointer,
513        ) {
514            let f: &F = &*(f as *const F);
515            f(Display::from_glib_borrow(this).unsafe_cast_ref())
516        }
517        unsafe {
518            let f: Box_<F> = Box_::new(f);
519            connect_raw(
520                self.as_ptr() as *mut _,
521                c"notify::rgba".as_ptr() as *const _,
522                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
523                    notify_rgba_trampoline::<Self, F> as *const (),
524                )),
525                Box_::into_raw(f),
526            )
527        }
528    }
529
530    #[cfg(feature = "v4_14")]
531    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
532    #[doc(alias = "shadow-width")]
533    fn connect_shadow_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
534        unsafe extern "C" fn notify_shadow_width_trampoline<
535            P: IsA<Display>,
536            F: Fn(&P) + 'static,
537        >(
538            this: *mut ffi::GdkDisplay,
539            _param_spec: glib::ffi::gpointer,
540            f: glib::ffi::gpointer,
541        ) {
542            let f: &F = &*(f as *const F);
543            f(Display::from_glib_borrow(this).unsafe_cast_ref())
544        }
545        unsafe {
546            let f: Box_<F> = Box_::new(f);
547            connect_raw(
548                self.as_ptr() as *mut _,
549                c"notify::shadow-width".as_ptr() as *const _,
550                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
551                    notify_shadow_width_trampoline::<Self, F> as *const (),
552                )),
553                Box_::into_raw(f),
554            )
555        }
556    }
557}
558
559impl<O: IsA<Display>> DisplayExt for O {}