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