Skip to main content

gdk/auto/
monitor.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, Rectangle, SubpixelLayout, 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    /// GdkMonitor objects represent the individual outputs that are
16    /// associated with a [`Display`][crate::Display]. GdkDisplay has APIs to enumerate
17    /// monitors with [`Display::n_monitors()`][crate::Display::n_monitors()] and [`Display::monitor()`][crate::Display::monitor()], and
18    /// to find particular monitors with [`Display::primary_monitor()`][crate::Display::primary_monitor()] or
19    /// [`Display::monitor_at_window()`][crate::Display::monitor_at_window()].
20    ///
21    /// GdkMonitor was introduced in GTK+ 3.22 and supersedes earlier
22    /// APIs in GdkScreen to obtain monitor-related information.
23    ///
24    /// ## Properties
25    ///
26    ///
27    /// #### `display`
28    ///  Readable | Writable | Construct Only
29    ///
30    ///
31    /// #### `geometry`
32    ///  Readable
33    ///
34    ///
35    /// #### `height-mm`
36    ///  Readable
37    ///
38    ///
39    /// #### `manufacturer`
40    ///  Readable
41    ///
42    ///
43    /// #### `model`
44    ///  Readable
45    ///
46    ///
47    /// #### `refresh-rate`
48    ///  Readable
49    ///
50    ///
51    /// #### `scale-factor`
52    ///  Readable
53    ///
54    ///
55    /// #### `subpixel-layout`
56    ///  Readable
57    ///
58    ///
59    /// #### `width-mm`
60    ///  Readable
61    ///
62    ///
63    /// #### `workarea`
64    ///  Readable
65    ///
66    /// ## Signals
67    ///
68    ///
69    /// #### `invalidate`
70    ///
71    ///
72    /// # Implements
73    ///
74    /// [`MonitorExt`][trait@crate::prelude::MonitorExt]
75    #[doc(alias = "GdkMonitor")]
76    pub struct Monitor(Object<ffi::GdkMonitor, ffi::GdkMonitorClass>);
77
78    match fn {
79        type_ => || ffi::gdk_monitor_get_type(),
80    }
81}
82
83impl Monitor {
84    pub const NONE: Option<&'static Monitor> = None;
85}
86
87/// Trait containing all [`struct@Monitor`] methods.
88///
89/// # Implementors
90///
91/// [`Monitor`][struct@crate::Monitor]
92pub trait MonitorExt: IsA<Monitor> + 'static {
93    /// Gets the display that this monitor belongs to.
94    ///
95    /// # Returns
96    ///
97    /// the display
98    #[doc(alias = "gdk_monitor_get_display")]
99    #[doc(alias = "get_display")]
100    fn display(&self) -> Option<Display> {
101        unsafe { from_glib_none(ffi::gdk_monitor_get_display(self.as_ref().to_glib_none().0)) }
102    }
103
104    /// Retrieves the size and position of an individual monitor within the
105    /// display coordinate space. The returned geometry is in ”application pixels”,
106    /// not in ”device pixels” (see [`scale_factor()`][Self::scale_factor()]).
107    ///
108    /// # Returns
109    ///
110    ///
111    /// ## `geometry`
112    /// a [`Rectangle`][crate::Rectangle] to be filled with the monitor geometry
113    #[doc(alias = "gdk_monitor_get_geometry")]
114    #[doc(alias = "get_geometry")]
115    fn geometry(&self) -> Rectangle {
116        unsafe {
117            let mut geometry = Rectangle::uninitialized();
118            ffi::gdk_monitor_get_geometry(
119                self.as_ref().to_glib_none().0,
120                geometry.to_glib_none_mut().0,
121            );
122            geometry
123        }
124    }
125
126    /// Gets the height in millimeters of the monitor.
127    ///
128    /// # Returns
129    ///
130    /// the physical height of the monitor
131    #[doc(alias = "gdk_monitor_get_height_mm")]
132    #[doc(alias = "get_height_mm")]
133    #[doc(alias = "height-mm")]
134    fn height_mm(&self) -> i32 {
135        unsafe { ffi::gdk_monitor_get_height_mm(self.as_ref().to_glib_none().0) }
136    }
137
138    /// Gets the name or PNP ID of the monitor's manufacturer, if available.
139    ///
140    /// Note that this value might also vary depending on actual
141    /// display backend.
142    ///
143    /// PNP ID registry is located at https://uefi.org/pnp_id_list
144    ///
145    /// # Returns
146    ///
147    /// the name of the manufacturer, or [`None`]
148    #[doc(alias = "gdk_monitor_get_manufacturer")]
149    #[doc(alias = "get_manufacturer")]
150    fn manufacturer(&self) -> Option<glib::GString> {
151        unsafe {
152            from_glib_none(ffi::gdk_monitor_get_manufacturer(
153                self.as_ref().to_glib_none().0,
154            ))
155        }
156    }
157
158    /// Gets the a string identifying the monitor model, if available.
159    ///
160    /// # Returns
161    ///
162    /// the monitor model, or [`None`]
163    #[doc(alias = "gdk_monitor_get_model")]
164    #[doc(alias = "get_model")]
165    fn model(&self) -> Option<glib::GString> {
166        unsafe { from_glib_none(ffi::gdk_monitor_get_model(self.as_ref().to_glib_none().0)) }
167    }
168
169    /// Gets the refresh rate of the monitor, if available.
170    ///
171    /// The value is in milli-Hertz, so a refresh rate of 60Hz
172    /// is returned as 60000.
173    ///
174    /// # Returns
175    ///
176    /// the refresh rate in milli-Hertz, or 0
177    #[doc(alias = "gdk_monitor_get_refresh_rate")]
178    #[doc(alias = "get_refresh_rate")]
179    #[doc(alias = "refresh-rate")]
180    fn refresh_rate(&self) -> i32 {
181        unsafe { ffi::gdk_monitor_get_refresh_rate(self.as_ref().to_glib_none().0) }
182    }
183
184    /// Gets the internal scale factor that maps from monitor coordinates
185    /// to the actual device pixels. On traditional systems this is 1, but
186    /// on very high density outputs this can be a higher value (often 2).
187    ///
188    /// This can be used if you want to create pixel based data for a
189    /// particular monitor, but most of the time you’re drawing to a window
190    /// where it is better to use [`Window::scale_factor()`][crate::Window::scale_factor()] instead.
191    ///
192    /// # Returns
193    ///
194    /// the scale factor
195    #[doc(alias = "gdk_monitor_get_scale_factor")]
196    #[doc(alias = "get_scale_factor")]
197    #[doc(alias = "scale-factor")]
198    fn scale_factor(&self) -> i32 {
199        unsafe { ffi::gdk_monitor_get_scale_factor(self.as_ref().to_glib_none().0) }
200    }
201
202    /// Gets information about the layout of red, green and blue
203    /// primaries for each pixel in this monitor, if available.
204    ///
205    /// # Returns
206    ///
207    /// the subpixel layout
208    #[doc(alias = "gdk_monitor_get_subpixel_layout")]
209    #[doc(alias = "get_subpixel_layout")]
210    #[doc(alias = "subpixel-layout")]
211    fn subpixel_layout(&self) -> SubpixelLayout {
212        unsafe {
213            from_glib(ffi::gdk_monitor_get_subpixel_layout(
214                self.as_ref().to_glib_none().0,
215            ))
216        }
217    }
218
219    /// Gets the width in millimeters of the monitor.
220    ///
221    /// # Returns
222    ///
223    /// the physical width of the monitor
224    #[doc(alias = "gdk_monitor_get_width_mm")]
225    #[doc(alias = "get_width_mm")]
226    #[doc(alias = "width-mm")]
227    fn width_mm(&self) -> i32 {
228        unsafe { ffi::gdk_monitor_get_width_mm(self.as_ref().to_glib_none().0) }
229    }
230
231    /// Retrieves the size and position of the “work area” on a monitor
232    /// within the display coordinate space. The returned geometry is in
233    /// ”application pixels”, not in ”device pixels” (see
234    /// [`scale_factor()`][Self::scale_factor()]).
235    ///
236    /// The work area should be considered when positioning menus and
237    /// similar popups, to avoid placing them below panels, docks or other
238    /// desktop components.
239    ///
240    /// Note that not all backends may have a concept of workarea. This
241    /// function will return the monitor geometry if a workarea is not
242    /// available, or does not apply.
243    ///
244    /// # Returns
245    ///
246    ///
247    /// ## `workarea`
248    /// a [`Rectangle`][crate::Rectangle] to be filled with
249    ///  the monitor workarea
250    #[doc(alias = "gdk_monitor_get_workarea")]
251    #[doc(alias = "get_workarea")]
252    fn workarea(&self) -> Rectangle {
253        unsafe {
254            let mut workarea = Rectangle::uninitialized();
255            ffi::gdk_monitor_get_workarea(
256                self.as_ref().to_glib_none().0,
257                workarea.to_glib_none_mut().0,
258            );
259            workarea
260        }
261    }
262
263    /// Gets whether this monitor should be considered primary
264    /// (see [`Display::primary_monitor()`][crate::Display::primary_monitor()]).
265    ///
266    /// # Returns
267    ///
268    /// [`true`] if `self` is primary
269    #[doc(alias = "gdk_monitor_is_primary")]
270    fn is_primary(&self) -> bool {
271        unsafe { from_glib(ffi::gdk_monitor_is_primary(self.as_ref().to_glib_none().0)) }
272    }
273
274    #[doc(alias = "invalidate")]
275    fn connect_invalidate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
276        unsafe extern "C" fn invalidate_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
277            this: *mut ffi::GdkMonitor,
278            f: glib::ffi::gpointer,
279        ) {
280            unsafe {
281                let f: &F = &*(f as *const F);
282                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
283            }
284        }
285        unsafe {
286            let f: Box_<F> = Box_::new(f);
287            connect_raw(
288                self.as_ptr() as *mut _,
289                c"invalidate".as_ptr(),
290                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291                    invalidate_trampoline::<Self, F> as *const (),
292                )),
293                Box_::into_raw(f),
294            )
295        }
296    }
297
298    #[doc(alias = "geometry")]
299    fn connect_geometry_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
300        unsafe extern "C" fn notify_geometry_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
301            this: *mut ffi::GdkMonitor,
302            _param_spec: glib::ffi::gpointer,
303            f: glib::ffi::gpointer,
304        ) {
305            unsafe {
306                let f: &F = &*(f as *const F);
307                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
308            }
309        }
310        unsafe {
311            let f: Box_<F> = Box_::new(f);
312            connect_raw(
313                self.as_ptr() as *mut _,
314                c"notify::geometry".as_ptr(),
315                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
316                    notify_geometry_trampoline::<Self, F> as *const (),
317                )),
318                Box_::into_raw(f),
319            )
320        }
321    }
322
323    #[doc(alias = "height-mm")]
324    fn connect_height_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
325        unsafe extern "C" fn notify_height_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
326            this: *mut ffi::GdkMonitor,
327            _param_spec: glib::ffi::gpointer,
328            f: glib::ffi::gpointer,
329        ) {
330            unsafe {
331                let f: &F = &*(f as *const F);
332                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
333            }
334        }
335        unsafe {
336            let f: Box_<F> = Box_::new(f);
337            connect_raw(
338                self.as_ptr() as *mut _,
339                c"notify::height-mm".as_ptr(),
340                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
341                    notify_height_mm_trampoline::<Self, F> as *const (),
342                )),
343                Box_::into_raw(f),
344            )
345        }
346    }
347
348    #[doc(alias = "manufacturer")]
349    fn connect_manufacturer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
350        unsafe extern "C" fn notify_manufacturer_trampoline<
351            P: IsA<Monitor>,
352            F: Fn(&P) + 'static,
353        >(
354            this: *mut ffi::GdkMonitor,
355            _param_spec: glib::ffi::gpointer,
356            f: glib::ffi::gpointer,
357        ) {
358            unsafe {
359                let f: &F = &*(f as *const F);
360                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
361            }
362        }
363        unsafe {
364            let f: Box_<F> = Box_::new(f);
365            connect_raw(
366                self.as_ptr() as *mut _,
367                c"notify::manufacturer".as_ptr(),
368                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
369                    notify_manufacturer_trampoline::<Self, F> as *const (),
370                )),
371                Box_::into_raw(f),
372            )
373        }
374    }
375
376    #[doc(alias = "model")]
377    fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
378        unsafe extern "C" fn notify_model_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
379            this: *mut ffi::GdkMonitor,
380            _param_spec: glib::ffi::gpointer,
381            f: glib::ffi::gpointer,
382        ) {
383            unsafe {
384                let f: &F = &*(f as *const F);
385                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
386            }
387        }
388        unsafe {
389            let f: Box_<F> = Box_::new(f);
390            connect_raw(
391                self.as_ptr() as *mut _,
392                c"notify::model".as_ptr(),
393                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
394                    notify_model_trampoline::<Self, F> as *const (),
395                )),
396                Box_::into_raw(f),
397            )
398        }
399    }
400
401    #[doc(alias = "refresh-rate")]
402    fn connect_refresh_rate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
403        unsafe extern "C" fn notify_refresh_rate_trampoline<
404            P: IsA<Monitor>,
405            F: Fn(&P) + 'static,
406        >(
407            this: *mut ffi::GdkMonitor,
408            _param_spec: glib::ffi::gpointer,
409            f: glib::ffi::gpointer,
410        ) {
411            unsafe {
412                let f: &F = &*(f as *const F);
413                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
414            }
415        }
416        unsafe {
417            let f: Box_<F> = Box_::new(f);
418            connect_raw(
419                self.as_ptr() as *mut _,
420                c"notify::refresh-rate".as_ptr(),
421                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
422                    notify_refresh_rate_trampoline::<Self, F> as *const (),
423                )),
424                Box_::into_raw(f),
425            )
426        }
427    }
428
429    #[doc(alias = "scale-factor")]
430    fn connect_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
431        unsafe extern "C" fn notify_scale_factor_trampoline<
432            P: IsA<Monitor>,
433            F: Fn(&P) + 'static,
434        >(
435            this: *mut ffi::GdkMonitor,
436            _param_spec: glib::ffi::gpointer,
437            f: glib::ffi::gpointer,
438        ) {
439            unsafe {
440                let f: &F = &*(f as *const F);
441                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
442            }
443        }
444        unsafe {
445            let f: Box_<F> = Box_::new(f);
446            connect_raw(
447                self.as_ptr() as *mut _,
448                c"notify::scale-factor".as_ptr(),
449                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
450                    notify_scale_factor_trampoline::<Self, F> as *const (),
451                )),
452                Box_::into_raw(f),
453            )
454        }
455    }
456
457    #[doc(alias = "subpixel-layout")]
458    fn connect_subpixel_layout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
459        unsafe extern "C" fn notify_subpixel_layout_trampoline<
460            P: IsA<Monitor>,
461            F: Fn(&P) + 'static,
462        >(
463            this: *mut ffi::GdkMonitor,
464            _param_spec: glib::ffi::gpointer,
465            f: glib::ffi::gpointer,
466        ) {
467            unsafe {
468                let f: &F = &*(f as *const F);
469                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
470            }
471        }
472        unsafe {
473            let f: Box_<F> = Box_::new(f);
474            connect_raw(
475                self.as_ptr() as *mut _,
476                c"notify::subpixel-layout".as_ptr(),
477                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
478                    notify_subpixel_layout_trampoline::<Self, F> as *const (),
479                )),
480                Box_::into_raw(f),
481            )
482        }
483    }
484
485    #[doc(alias = "width-mm")]
486    fn connect_width_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
487        unsafe extern "C" fn notify_width_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
488            this: *mut ffi::GdkMonitor,
489            _param_spec: glib::ffi::gpointer,
490            f: glib::ffi::gpointer,
491        ) {
492            unsafe {
493                let f: &F = &*(f as *const F);
494                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
495            }
496        }
497        unsafe {
498            let f: Box_<F> = Box_::new(f);
499            connect_raw(
500                self.as_ptr() as *mut _,
501                c"notify::width-mm".as_ptr(),
502                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
503                    notify_width_mm_trampoline::<Self, F> as *const (),
504                )),
505                Box_::into_raw(f),
506            )
507        }
508    }
509
510    #[doc(alias = "workarea")]
511    fn connect_workarea_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
512        unsafe extern "C" fn notify_workarea_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
513            this: *mut ffi::GdkMonitor,
514            _param_spec: glib::ffi::gpointer,
515            f: glib::ffi::gpointer,
516        ) {
517            unsafe {
518                let f: &F = &*(f as *const F);
519                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
520            }
521        }
522        unsafe {
523            let f: Box_<F> = Box_::new(f);
524            connect_raw(
525                self.as_ptr() as *mut _,
526                c"notify::workarea".as_ptr(),
527                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
528                    notify_workarea_trampoline::<Self, F> as *const (),
529                )),
530                Box_::into_raw(f),
531            )
532        }
533    }
534}
535
536impl<O: IsA<Monitor>> MonitorExt for O {}