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 ///
16 /// `ifdef` GDK_WINDOWING_X11
17 /// if (GDK_IS_X11_DISPLAY (display))
18 /// {
19 /// // make X11-specific calls here
20 /// }
21 /// else
22 /// `endif`
23 /// `ifdef` GDK_WINDOWING_QUARTZ
24 /// if (GDK_IS_QUARTZ_DISPLAY (display))
25 /// {
26 /// // make Quartz-specific calls here
27 /// }
28 /// else
29 /// `endif`
30 /// g_error ("Unsupported GDK backend");
31 /// ]|
32 ///
33 /// ## Properties
34 ///
35 ///
36 /// #### `default-display`
37 /// Readable | Writable
38 ///
39 /// ## Signals
40 ///
41 ///
42 /// #### `display-opened`
43 /// The ::display-opened signal is emitted when a display is opened.
44 ///
45 ///
46 #[doc(alias = "GdkDisplayManager")]
47 pub struct DisplayManager(Object<ffi::GdkDisplayManager>);
48
49 match fn {
50 type_ => || ffi::gdk_display_manager_get_type(),
51 }
52}
53
54impl DisplayManager {
55 /// Gets the default [`Display`][crate::Display].
56 ///
57 /// # Returns
58 ///
59 /// a [`Display`][crate::Display], or [`None`] if
60 /// there is no default display.
61 #[doc(alias = "gdk_display_manager_get_default_display")]
62 #[doc(alias = "get_default_display")]
63 #[doc(alias = "default-display")]
64 pub fn default_display(&self) -> Option<Display> {
65 unsafe {
66 from_glib_none(ffi::gdk_display_manager_get_default_display(
67 self.to_glib_none().0,
68 ))
69 }
70 }
71
72 /// List all currently open displays.
73 ///
74 /// # Returns
75 ///
76 /// a newly
77 /// allocated `GSList` of [`Display`][crate::Display] objects. Free with `g_slist_free()`
78 /// when you are done with it.
79 #[doc(alias = "gdk_display_manager_list_displays")]
80 pub fn list_displays(&self) -> Vec<Display> {
81 unsafe {
82 FromGlibPtrContainer::from_glib_container(ffi::gdk_display_manager_list_displays(
83 self.to_glib_none().0,
84 ))
85 }
86 }
87
88 /// Opens a display.
89 /// ## `name`
90 /// the name of the display to open
91 ///
92 /// # Returns
93 ///
94 /// a [`Display`][crate::Display], or [`None`] if the
95 /// display could not be opened
96 #[doc(alias = "gdk_display_manager_open_display")]
97 pub fn open_display(&self, name: &str) -> Option<Display> {
98 unsafe {
99 from_glib_none(ffi::gdk_display_manager_open_display(
100 self.to_glib_none().0,
101 name.to_glib_none().0,
102 ))
103 }
104 }
105
106 /// Sets `display` as the default display.
107 /// ## `display`
108 /// a [`Display`][crate::Display]
109 #[doc(alias = "gdk_display_manager_set_default_display")]
110 #[doc(alias = "default-display")]
111 pub fn set_default_display(&self, display: &Display) {
112 unsafe {
113 ffi::gdk_display_manager_set_default_display(
114 self.to_glib_none().0,
115 display.to_glib_none().0,
116 );
117 }
118 }
119
120 /// Gets the singleton [`DisplayManager`][crate::DisplayManager] object.
121 ///
122 /// When called for the first time, this function consults the
123 /// `GDK_BACKEND` environment variable to find out which
124 /// of the supported GDK backends to use (in case GDK has been compiled
125 /// with multiple backends). Applications can use [`set_allowed_backends()`][crate::set_allowed_backends()]
126 /// to limit what backends can be used.
127 ///
128 /// # Returns
129 ///
130 /// The global [`DisplayManager`][crate::DisplayManager] singleton;
131 /// `gdk_parse_args()`, `gdk_init()`, or `gdk_init_check()` must have
132 /// been called first.
133 #[doc(alias = "gdk_display_manager_get")]
134 pub fn get() -> DisplayManager {
135 assert_initialized_main_thread!();
136 unsafe { from_glib_none(ffi::gdk_display_manager_get()) }
137 }
138
139 /// The ::display-opened signal is emitted when a display is opened.
140 /// ## `display`
141 /// the opened display
142 #[doc(alias = "display-opened")]
143 pub fn connect_display_opened<F: Fn(&Self, &Display) + 'static>(
144 &self,
145 f: F,
146 ) -> SignalHandlerId {
147 unsafe extern "C" fn display_opened_trampoline<
148 F: Fn(&DisplayManager, &Display) + 'static,
149 >(
150 this: *mut ffi::GdkDisplayManager,
151 display: *mut ffi::GdkDisplay,
152 f: glib::ffi::gpointer,
153 ) {
154 unsafe {
155 let f: &F = &*(f as *const F);
156 f(&from_glib_borrow(this), &from_glib_borrow(display))
157 }
158 }
159 unsafe {
160 let f: Box_<F> = Box_::new(f);
161 connect_raw(
162 self.as_ptr() as *mut _,
163 c"display-opened".as_ptr(),
164 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
165 display_opened_trampoline::<F> as *const (),
166 )),
167 Box_::into_raw(f),
168 )
169 }
170 }
171
172 #[doc(alias = "default-display")]
173 pub fn connect_default_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
174 unsafe extern "C" fn notify_default_display_trampoline<F: Fn(&DisplayManager) + 'static>(
175 this: *mut ffi::GdkDisplayManager,
176 _param_spec: glib::ffi::gpointer,
177 f: glib::ffi::gpointer,
178 ) {
179 unsafe {
180 let f: &F = &*(f as *const F);
181 f(&from_glib_borrow(this))
182 }
183 }
184 unsafe {
185 let f: Box_<F> = Box_::new(f);
186 connect_raw(
187 self.as_ptr() as *mut _,
188 c"notify::default-display".as_ptr(),
189 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
190 notify_default_display_trampoline::<F> as *const (),
191 )),
192 Box_::into_raw(f),
193 )
194 }
195 }
196}