gdk4/auto/
display_manager.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Display};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// A singleton object that offers notification when displays appear or
16    /// disappear.
17    ///
18    /// You can use [`get()`][Self::get()] to obtain the [`DisplayManager`][crate::DisplayManager]
19    /// singleton, but that should be rarely necessary. Typically, initializing
20    /// GTK opens a display that you can work with without ever accessing the
21    /// [`DisplayManager`][crate::DisplayManager].
22    ///
23    /// The GDK library can be built with support for multiple backends.
24    /// The [`DisplayManager`][crate::DisplayManager] object determines which backend is used
25    /// at runtime.
26    ///
27    /// In the rare case that you need to influence which of the backends
28    /// is being used, you can use [`set_allowed_backends()`][crate::set_allowed_backends()]. Note
29    /// that you need to call this function before initializing GTK.
30    ///
31    /// ## Backend-specific code
32    ///
33    /// When writing backend-specific code that is supposed to work with
34    /// multiple GDK backends, you have to consider both compile time and
35    /// runtime. At compile time, use the `GDK_WINDOWING_X11`, `GDK_WINDOWING_WIN32`
36    /// macros, etc. to find out which backends are present in the GDK library
37    /// you are building your application against. At runtime, use type-check
38    /// macros like GDK_IS_X11_DISPLAY() to find out which backend is in use:
39    ///
40    /// **⚠️ The following code is in c ⚠️**
41    ///
42    /// ```c
43    /// #ifdef GDK_WINDOWING_X11
44    ///   if (GDK_IS_X11_DISPLAY (display))
45    ///     {
46    ///       // make X11-specific calls here
47    ///     }
48    ///   else
49    /// #endif
50    /// #ifdef GDK_WINDOWING_MACOS
51    ///   if (GDK_IS_MACOS_DISPLAY (display))
52    ///     {
53    ///       // make Quartz-specific calls here
54    ///     }
55    ///   else
56    /// #endif
57    ///   g_error ("Unsupported GDK backend");
58    /// ```
59    ///
60    /// ## Properties
61    ///
62    ///
63    /// #### `default-display`
64    ///  The default display.
65    ///
66    /// Readable | Writeable
67    ///
68    /// ## Signals
69    ///
70    ///
71    /// #### `display-opened`
72    ///  Emitted when a display is opened.
73    ///
74    ///
75    #[doc(alias = "GdkDisplayManager")]
76    pub struct DisplayManager(Object<ffi::GdkDisplayManager>);
77
78    match fn {
79        type_ => || ffi::gdk_display_manager_get_type(),
80    }
81}
82
83impl DisplayManager {
84    /// Gets the default [`Display`][crate::Display].
85    ///
86    /// # Returns
87    ///
88    /// a [`Display`][crate::Display]
89    #[doc(alias = "gdk_display_manager_get_default_display")]
90    #[doc(alias = "get_default_display")]
91    #[doc(alias = "default-display")]
92    pub fn default_display(&self) -> Option<Display> {
93        unsafe {
94            from_glib_none(ffi::gdk_display_manager_get_default_display(
95                self.to_glib_none().0,
96            ))
97        }
98    }
99
100    /// List all currently open displays.
101    ///
102    /// # Returns
103    ///
104    /// a newly
105    ///   allocated `GSList` of [`Display`][crate::Display] objects
106    #[doc(alias = "gdk_display_manager_list_displays")]
107    pub fn list_displays(&self) -> Vec<Display> {
108        unsafe {
109            FromGlibPtrContainer::from_glib_container(ffi::gdk_display_manager_list_displays(
110                self.to_glib_none().0,
111            ))
112        }
113    }
114
115    /// Opens a display.
116    /// ## `name`
117    /// the name of the display to open
118    ///
119    /// # Returns
120    ///
121    /// a [`Display`][crate::Display], or [`None`]
122    ///   if the display could not be opened
123    #[doc(alias = "gdk_display_manager_open_display")]
124    pub fn open_display(&self, name: Option<&str>) -> Option<Display> {
125        unsafe {
126            from_glib_none(ffi::gdk_display_manager_open_display(
127                self.to_glib_none().0,
128                name.to_glib_none().0,
129            ))
130        }
131    }
132
133    /// Sets @display as the default display.
134    /// ## `display`
135    /// a [`Display`][crate::Display]
136    #[doc(alias = "gdk_display_manager_set_default_display")]
137    #[doc(alias = "default-display")]
138    pub fn set_default_display(&self, display: &impl IsA<Display>) {
139        unsafe {
140            ffi::gdk_display_manager_set_default_display(
141                self.to_glib_none().0,
142                display.as_ref().to_glib_none().0,
143            );
144        }
145    }
146
147    /// Gets the singleton [`DisplayManager`][crate::DisplayManager] object.
148    ///
149    /// When called for the first time, this function consults the
150    /// `GDK_BACKEND` environment variable to find out which of the
151    /// supported GDK backends to use (in case GDK has been compiled
152    /// with multiple backends).
153    ///
154    /// Applications can use [`set_allowed_backends()`][crate::set_allowed_backends()] to limit what
155    /// backends will be used.
156    ///
157    /// # Returns
158    ///
159    /// The global [`DisplayManager`][crate::DisplayManager] singleton
160    #[doc(alias = "gdk_display_manager_get")]
161    pub fn get() -> DisplayManager {
162        assert_initialized_main_thread!();
163        unsafe { from_glib_none(ffi::gdk_display_manager_get()) }
164    }
165
166    /// Emitted when a display is opened.
167    /// ## `display`
168    /// the opened display
169    #[doc(alias = "display-opened")]
170    pub fn connect_display_opened<F: Fn(&Self, &Display) + 'static>(
171        &self,
172        f: F,
173    ) -> SignalHandlerId {
174        unsafe extern "C" fn display_opened_trampoline<
175            F: Fn(&DisplayManager, &Display) + 'static,
176        >(
177            this: *mut ffi::GdkDisplayManager,
178            display: *mut ffi::GdkDisplay,
179            f: glib::ffi::gpointer,
180        ) {
181            let f: &F = &*(f as *const F);
182            f(&from_glib_borrow(this), &from_glib_borrow(display))
183        }
184        unsafe {
185            let f: Box_<F> = Box_::new(f);
186            connect_raw(
187                self.as_ptr() as *mut _,
188                b"display-opened\0".as_ptr() as *const _,
189                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
190                    display_opened_trampoline::<F> as *const (),
191                )),
192                Box_::into_raw(f),
193            )
194        }
195    }
196
197    #[doc(alias = "default-display")]
198    pub fn connect_default_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
199        unsafe extern "C" fn notify_default_display_trampoline<F: Fn(&DisplayManager) + 'static>(
200            this: *mut ffi::GdkDisplayManager,
201            _param_spec: glib::ffi::gpointer,
202            f: glib::ffi::gpointer,
203        ) {
204            let f: &F = &*(f as *const F);
205            f(&from_glib_borrow(this))
206        }
207        unsafe {
208            let f: Box_<F> = Box_::new(f);
209            connect_raw(
210                self.as_ptr() as *mut _,
211                b"notify::default-display\0".as_ptr() as *const _,
212                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
213                    notify_default_display_trampoline::<F> as *const (),
214                )),
215                Box_::into_raw(f),
216            )
217        }
218    }
219}