Skip to main content

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