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