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