gdk/auto/screen.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, Visual, Window, 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 /// [`Screen`][crate::Screen] objects are the GDK representation of the screen on
16 /// which windows can be displayed and on which the pointer moves.
17 /// X originally identified screens with physical screens, but
18 /// nowadays it is more common to have a single [`Screen`][crate::Screen] which
19 /// combines several physical monitors (see `gdk_screen_get_n_monitors()`).
20 ///
21 /// GdkScreen is used throughout GDK and GTK+ to specify which screen
22 /// the top level windows are to be displayed on. it is also used to
23 /// query the screen specification and default settings such as
24 /// the default visual ([`system_visual()`][Self::system_visual()]), the dimensions
25 /// of the physical monitors (`gdk_screen_get_monitor_geometry()`), etc.
26 ///
27 /// ## Properties
28 ///
29 ///
30 /// #### `font-options`
31 /// Readable | Writable
32 ///
33 ///
34 /// #### `resolution`
35 /// Readable | Writable
36 ///
37 /// ## Signals
38 ///
39 ///
40 /// #### `composited-changed`
41 /// The ::composited-changed signal is emitted when the composited
42 /// status of the screen changes
43 ///
44 ///
45 ///
46 ///
47 /// #### `monitors-changed`
48 /// The ::monitors-changed signal is emitted when the number, size
49 /// or position of the monitors attached to the screen change.
50 ///
51 /// Only for X11 and OS X for now. A future implementation for Win32
52 /// may be a possibility.
53 ///
54 ///
55 ///
56 ///
57 /// #### `size-changed`
58 /// The ::size-changed signal is emitted when the pixel width or
59 /// height of a screen changes.
60 ///
61 ///
62 #[doc(alias = "GdkScreen")]
63 pub struct Screen(Object<ffi::GdkScreen>);
64
65 match fn {
66 type_ => || ffi::gdk_screen_get_type(),
67 }
68}
69
70impl Screen {
71 /// Gets the display to which the `self` belongs.
72 ///
73 /// # Returns
74 ///
75 /// the display to which `self` belongs
76 #[doc(alias = "gdk_screen_get_display")]
77 #[doc(alias = "get_display")]
78 pub fn display(&self) -> Display {
79 unsafe { from_glib_none(ffi::gdk_screen_get_display(self.to_glib_none().0)) }
80 }
81
82 /// Gets the resolution for font handling on the screen; see
83 /// [`set_resolution()`][Self::set_resolution()] for full details.
84 ///
85 /// # Returns
86 ///
87 /// the current resolution, or -1 if no resolution
88 /// has been set.
89 #[doc(alias = "gdk_screen_get_resolution")]
90 #[doc(alias = "get_resolution")]
91 pub fn resolution(&self) -> f64 {
92 unsafe { ffi::gdk_screen_get_resolution(self.to_glib_none().0) }
93 }
94
95 /// Gets a visual to use for creating windows with an alpha channel.
96 /// The windowing system on which GTK+ is running
97 /// may not support this capability, in which case [`None`] will
98 /// be returned. Even if a non-[`None`] value is returned, its
99 /// possible that the window’s alpha channel won’t be honored
100 /// when displaying the window on the screen: in particular, for
101 /// X an appropriate windowing manager and compositing manager
102 /// must be running to provide appropriate display.
103 ///
104 /// This functionality is not implemented in the Windows backend.
105 ///
106 /// For setting an overall opacity for a top-level window, see
107 /// [`Window::set_opacity()`][crate::Window::set_opacity()].
108 ///
109 /// # Returns
110 ///
111 /// a visual to use for windows
112 /// with an alpha channel or [`None`] if the capability is not
113 /// available.
114 #[doc(alias = "gdk_screen_get_rgba_visual")]
115 #[doc(alias = "get_rgba_visual")]
116 pub fn rgba_visual(&self) -> Option<Visual> {
117 unsafe { from_glib_none(ffi::gdk_screen_get_rgba_visual(self.to_glib_none().0)) }
118 }
119
120 /// Gets the root window of `self`.
121 ///
122 /// # Returns
123 ///
124 /// the root window
125 #[doc(alias = "gdk_screen_get_root_window")]
126 #[doc(alias = "get_root_window")]
127 pub fn root_window(&self) -> Option<Window> {
128 unsafe { from_glib_none(ffi::gdk_screen_get_root_window(self.to_glib_none().0)) }
129 }
130
131 /// Get the system’s default visual for `self`.
132 /// This is the visual for the root window of the display.
133 /// The return value should not be freed.
134 ///
135 /// # Returns
136 ///
137 /// the system visual
138 #[doc(alias = "gdk_screen_get_system_visual")]
139 #[doc(alias = "get_system_visual")]
140 pub fn system_visual(&self) -> Option<Visual> {
141 unsafe { from_glib_none(ffi::gdk_screen_get_system_visual(self.to_glib_none().0)) }
142 }
143
144 /// Obtains a list of all toplevel windows known to GDK on the screen `self`.
145 /// A toplevel window is a child of the root window (see
146 /// `gdk_get_default_root_window()`).
147 ///
148 /// The returned list should be freed with `g_list_free()`, but
149 /// its elements need not be freed.
150 ///
151 /// # Returns
152 ///
153 ///
154 /// list of toplevel windows, free with `g_list_free()`
155 #[doc(alias = "gdk_screen_get_toplevel_windows")]
156 #[doc(alias = "get_toplevel_windows")]
157 pub fn toplevel_windows(&self) -> Vec<Window> {
158 unsafe {
159 FromGlibPtrContainer::from_glib_container(ffi::gdk_screen_get_toplevel_windows(
160 self.to_glib_none().0,
161 ))
162 }
163 }
164
165 /// Returns a `GList` of `GdkWindows` representing the current
166 /// window stack.
167 ///
168 /// On X11, this is done by inspecting the _NET_CLIENT_LIST_STACKING
169 /// property on the root window, as described in the
170 /// [Extended Window Manager Hints](http://www.freedesktop.org/Standards/wm-spec).
171 /// If the window manager does not support the
172 /// _NET_CLIENT_LIST_STACKING hint, this function returns [`None`].
173 ///
174 /// On other platforms, this function may return [`None`], depending on whether
175 /// it is implementable on that platform.
176 ///
177 /// The returned list is newly allocated and owns references to the
178 /// windows it contains, so it should be freed using `g_list_free()` and
179 /// its windows unrefed using `g_object_unref()` when no longer needed.
180 ///
181 /// # Returns
182 ///
183 /// a
184 /// list of `GdkWindows` for the current window stack, or [`None`].
185 #[doc(alias = "gdk_screen_get_window_stack")]
186 #[doc(alias = "get_window_stack")]
187 pub fn window_stack(&self) -> Vec<Window> {
188 unsafe {
189 FromGlibPtrContainer::from_glib_full(ffi::gdk_screen_get_window_stack(
190 self.to_glib_none().0,
191 ))
192 }
193 }
194
195 /// Returns whether windows with an RGBA visual can reasonably
196 /// be expected to have their alpha channel drawn correctly on
197 /// the screen.
198 ///
199 /// On X11 this function returns whether a compositing manager is
200 /// compositing `self`.
201 ///
202 /// # Returns
203 ///
204 /// Whether windows with RGBA visuals can reasonably be
205 /// expected to have their alpha channels drawn correctly on the screen.
206 #[doc(alias = "gdk_screen_is_composited")]
207 pub fn is_composited(&self) -> bool {
208 unsafe { from_glib(ffi::gdk_screen_is_composited(self.to_glib_none().0)) }
209 }
210
211 /// Lists the available visuals for the specified `self`.
212 /// A visual describes a hardware image data format.
213 /// For example, a visual might support 24-bit color, or 8-bit color,
214 /// and might expect pixels to be in a certain format.
215 ///
216 /// Call `g_list_free()` on the return value when you’re finished with it.
217 ///
218 /// # Returns
219 ///
220 ///
221 /// a list of visuals; the list must be freed, but not its contents
222 #[doc(alias = "gdk_screen_list_visuals")]
223 pub fn list_visuals(&self) -> Vec<Visual> {
224 unsafe {
225 FromGlibPtrContainer::from_glib_container(ffi::gdk_screen_list_visuals(
226 self.to_glib_none().0,
227 ))
228 }
229 }
230
231 /// Sets the default font options for the screen. These
232 /// options will be set on any [`pango::Context`][crate::pango::Context]’s newly created
233 /// with [`pango_context_get_for_screen()`][crate::pango_context_get_for_screen()]. Changing the
234 /// default set of font options does not affect contexts that
235 /// have already been created.
236 /// ## `options`
237 /// a [`cairo::FontOptions`][crate::cairo::FontOptions], or [`None`] to unset any
238 /// previously set default font options.
239 #[doc(alias = "gdk_screen_set_font_options")]
240 #[doc(alias = "font-options")]
241 pub fn set_font_options(&self, options: Option<&cairo::FontOptions>) {
242 unsafe {
243 ffi::gdk_screen_set_font_options(self.to_glib_none().0, options.to_glib_none().0);
244 }
245 }
246
247 /// Sets the resolution for font handling on the screen. This is a
248 /// scale factor between points specified in a `PangoFontDescription`
249 /// and cairo units. The default value is 96, meaning that a 10 point
250 /// font will be 13 units high. (10 * 96. / 72. = 13.3).
251 /// ## `dpi`
252 /// the resolution in “dots per inch”. (Physical inches aren’t actually
253 /// involved; the terminology is conventional.)
254 #[doc(alias = "gdk_screen_set_resolution")]
255 #[doc(alias = "resolution")]
256 pub fn set_resolution(&self, dpi: f64) {
257 unsafe {
258 ffi::gdk_screen_set_resolution(self.to_glib_none().0, dpi);
259 }
260 }
261
262 /// Gets the default screen for the default display. (See
263 /// gdk_display_get_default ()).
264 ///
265 /// # Returns
266 ///
267 /// a [`Screen`][crate::Screen], or [`None`] if
268 /// there is no default display.
269 #[doc(alias = "gdk_screen_get_default")]
270 #[doc(alias = "get_default")]
271 #[allow(clippy::should_implement_trait)]
272 pub fn default() -> Option<Screen> {
273 assert_initialized_main_thread!();
274 unsafe { from_glib_none(ffi::gdk_screen_get_default()) }
275 }
276
277 /// The ::composited-changed signal is emitted when the composited
278 /// status of the screen changes
279 #[doc(alias = "composited-changed")]
280 pub fn connect_composited_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
281 unsafe extern "C" fn composited_changed_trampoline<F: Fn(&Screen) + 'static>(
282 this: *mut ffi::GdkScreen,
283 f: glib::ffi::gpointer,
284 ) {
285 unsafe {
286 let f: &F = &*(f as *const F);
287 f(&from_glib_borrow(this))
288 }
289 }
290 unsafe {
291 let f: Box_<F> = Box_::new(f);
292 connect_raw(
293 self.as_ptr() as *mut _,
294 c"composited-changed".as_ptr(),
295 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
296 composited_changed_trampoline::<F> as *const (),
297 )),
298 Box_::into_raw(f),
299 )
300 }
301 }
302
303 /// The ::monitors-changed signal is emitted when the number, size
304 /// or position of the monitors attached to the screen change.
305 ///
306 /// Only for X11 and OS X for now. A future implementation for Win32
307 /// may be a possibility.
308 #[doc(alias = "monitors-changed")]
309 pub fn connect_monitors_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
310 unsafe extern "C" fn monitors_changed_trampoline<F: Fn(&Screen) + 'static>(
311 this: *mut ffi::GdkScreen,
312 f: glib::ffi::gpointer,
313 ) {
314 unsafe {
315 let f: &F = &*(f as *const F);
316 f(&from_glib_borrow(this))
317 }
318 }
319 unsafe {
320 let f: Box_<F> = Box_::new(f);
321 connect_raw(
322 self.as_ptr() as *mut _,
323 c"monitors-changed".as_ptr(),
324 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
325 monitors_changed_trampoline::<F> as *const (),
326 )),
327 Box_::into_raw(f),
328 )
329 }
330 }
331
332 /// The ::size-changed signal is emitted when the pixel width or
333 /// height of a screen changes.
334 #[doc(alias = "size-changed")]
335 pub fn connect_size_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
336 unsafe extern "C" fn size_changed_trampoline<F: Fn(&Screen) + 'static>(
337 this: *mut ffi::GdkScreen,
338 f: glib::ffi::gpointer,
339 ) {
340 unsafe {
341 let f: &F = &*(f as *const F);
342 f(&from_glib_borrow(this))
343 }
344 }
345 unsafe {
346 let f: Box_<F> = Box_::new(f);
347 connect_raw(
348 self.as_ptr() as *mut _,
349 c"size-changed".as_ptr(),
350 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
351 size_changed_trampoline::<F> as *const (),
352 )),
353 Box_::into_raw(f),
354 )
355 }
356 }
357
358 #[doc(alias = "font-options")]
359 pub fn connect_font_options_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
360 unsafe extern "C" fn notify_font_options_trampoline<F: Fn(&Screen) + 'static>(
361 this: *mut ffi::GdkScreen,
362 _param_spec: glib::ffi::gpointer,
363 f: glib::ffi::gpointer,
364 ) {
365 unsafe {
366 let f: &F = &*(f as *const F);
367 f(&from_glib_borrow(this))
368 }
369 }
370 unsafe {
371 let f: Box_<F> = Box_::new(f);
372 connect_raw(
373 self.as_ptr() as *mut _,
374 c"notify::font-options".as_ptr(),
375 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
376 notify_font_options_trampoline::<F> as *const (),
377 )),
378 Box_::into_raw(f),
379 )
380 }
381 }
382
383 #[doc(alias = "resolution")]
384 pub fn connect_resolution_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
385 unsafe extern "C" fn notify_resolution_trampoline<F: Fn(&Screen) + 'static>(
386 this: *mut ffi::GdkScreen,
387 _param_spec: glib::ffi::gpointer,
388 f: glib::ffi::gpointer,
389 ) {
390 unsafe {
391 let f: &F = &*(f as *const F);
392 f(&from_glib_borrow(this))
393 }
394 }
395 unsafe {
396 let f: Box_<F> = Box_::new(f);
397 connect_raw(
398 self.as_ptr() as *mut _,
399 c"notify::resolution".as_ptr(),
400 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
401 notify_resolution_trampoline::<F> as *const (),
402 )),
403 Box_::into_raw(f),
404 )
405 }
406 }
407}