Skip to main content

gdk4/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    /// Represents the individual outputs that are associated with a [`Display`][crate::Display].
16    ///
17    /// [`Display`][crate::Display] keeps a `GListModel` to enumerate and monitor
18    /// monitors with [`DisplayExt::monitors()`][crate::prelude::DisplayExt::monitors()]. You can use
19    /// [`DisplayExt::monitor_at_surface()`][crate::prelude::DisplayExt::monitor_at_surface()] to find a particular
20    /// monitor.
21    ///
22    /// ## Properties
23    ///
24    ///
25    /// #### `connector`
26    ///  The connector name.
27    ///
28    /// Readable
29    ///
30    ///
31    /// #### `description`
32    ///  A short description of the monitor, meant for display to the user.
33    ///
34    /// Readable
35    ///
36    ///
37    /// #### `display`
38    ///  The [`Display`][crate::Display] of the monitor.
39    ///
40    /// Readable | Writable | Construct Only
41    ///
42    ///
43    /// #### `geometry`
44    ///  The geometry of the monitor.
45    ///
46    /// Readable
47    ///
48    ///
49    /// #### `height-mm`
50    ///  The height of the monitor, in millimeters.
51    ///
52    /// Readable
53    ///
54    ///
55    /// #### `manufacturer`
56    ///  The manufacturer name.
57    ///
58    /// Readable
59    ///
60    ///
61    /// #### `model`
62    ///  The model name.
63    ///
64    /// Readable
65    ///
66    ///
67    /// #### `refresh-rate`
68    ///  The refresh rate, in milli-Hertz.
69    ///
70    /// Readable
71    ///
72    ///
73    /// #### `scale`
74    ///  The scale of the monitor.
75    ///
76    /// Readable
77    ///
78    ///
79    /// #### `scale-factor`
80    ///  The scale factor.
81    ///
82    /// The scale factor is the next larger integer,
83    /// compared to [`scale`][struct@crate::Surface#scale].
84    ///
85    /// Readable
86    ///
87    ///
88    /// #### `subpixel-layout`
89    ///  The subpixel layout.
90    ///
91    /// Readable
92    ///
93    ///
94    /// #### `valid`
95    ///  Whether the object is still valid.
96    ///
97    /// Readable
98    ///
99    ///
100    /// #### `width-mm`
101    ///  The width of the monitor, in millimeters.
102    ///
103    /// Readable
104    ///
105    /// ## Signals
106    ///
107    ///
108    /// #### `invalidate`
109    ///  Emitted when the output represented by @monitor gets disconnected.
110    ///
111    ///
112    ///
113    /// # Implements
114    ///
115    /// [`MonitorExt`][trait@crate::prelude::MonitorExt]
116    #[doc(alias = "GdkMonitor")]
117    pub struct Monitor(Object<ffi::GdkMonitor, ffi::GdkMonitorClass>);
118
119    match fn {
120        type_ => || ffi::gdk_monitor_get_type(),
121    }
122}
123
124impl Monitor {
125    pub const NONE: Option<&'static Monitor> = None;
126}
127
128/// Trait containing all [`struct@Monitor`] methods.
129///
130/// # Implementors
131///
132/// [`Monitor`][struct@crate::Monitor]
133pub trait MonitorExt: IsA<Monitor> + 'static {
134    /// Gets the name of the monitor's connector, if available.
135    ///
136    /// These are strings such as "eDP-1", or "HDMI-2". They depend
137    /// on software and hardware configuration, and should not be
138    /// relied on as stable identifiers of a specific monitor.
139    ///
140    /// # Returns
141    ///
142    /// the name of the connector
143    #[doc(alias = "gdk_monitor_get_connector")]
144    #[doc(alias = "get_connector")]
145    fn connector(&self) -> Option<glib::GString> {
146        unsafe {
147            from_glib_none(ffi::gdk_monitor_get_connector(
148                self.as_ref().to_glib_none().0,
149            ))
150        }
151    }
152
153    /// Gets a string describing the monitor, if available.
154    ///
155    /// This can be used to identify a monitor in the UI.
156    ///
157    /// # Returns
158    ///
159    /// the monitor description
160    #[cfg(feature = "v4_10")]
161    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
162    #[doc(alias = "gdk_monitor_get_description")]
163    #[doc(alias = "get_description")]
164    fn description(&self) -> Option<glib::GString> {
165        unsafe {
166            from_glib_none(ffi::gdk_monitor_get_description(
167                self.as_ref().to_glib_none().0,
168            ))
169        }
170    }
171
172    /// Gets the display that this monitor belongs to.
173    ///
174    /// # Returns
175    ///
176    /// the display
177    #[doc(alias = "gdk_monitor_get_display")]
178    #[doc(alias = "get_display")]
179    fn display(&self) -> Display {
180        unsafe { from_glib_none(ffi::gdk_monitor_get_display(self.as_ref().to_glib_none().0)) }
181    }
182
183    ///  (see [`scale()`][Self::scale()]).
184    ///
185    /// # Returns
186    ///
187    ///
188    /// ## `geometry`
189    /// a [`Rectangle`][crate::Rectangle] to be filled with the monitor geometry
190    #[doc(alias = "gdk_monitor_get_geometry")]
191    #[doc(alias = "get_geometry")]
192    fn geometry(&self) -> Rectangle {
193        unsafe {
194            let mut geometry = Rectangle::uninitialized();
195            ffi::gdk_monitor_get_geometry(
196                self.as_ref().to_glib_none().0,
197                geometry.to_glib_none_mut().0,
198            );
199            geometry
200        }
201    }
202
203    /// Gets the height in millimeters of the monitor.
204    ///
205    /// # Returns
206    ///
207    /// the physical height of the monitor
208    #[doc(alias = "gdk_monitor_get_height_mm")]
209    #[doc(alias = "get_height_mm")]
210    #[doc(alias = "height-mm")]
211    fn height_mm(&self) -> i32 {
212        unsafe { ffi::gdk_monitor_get_height_mm(self.as_ref().to_glib_none().0) }
213    }
214
215    /// Gets the name or PNP ID of the monitor's manufacturer.
216    ///
217    /// Note that this value might also vary depending on actual
218    /// display backend.
219    ///
220    /// The PNP ID registry is located at
221    /// [https://uefi.org/pnp_id_list](https://uefi.org/pnp_id_list).
222    ///
223    /// # Returns
224    ///
225    /// the name of the manufacturer
226    #[doc(alias = "gdk_monitor_get_manufacturer")]
227    #[doc(alias = "get_manufacturer")]
228    fn manufacturer(&self) -> Option<glib::GString> {
229        unsafe {
230            from_glib_none(ffi::gdk_monitor_get_manufacturer(
231                self.as_ref().to_glib_none().0,
232            ))
233        }
234    }
235
236    /// Gets the string identifying the monitor model, if available.
237    ///
238    /// # Returns
239    ///
240    /// the monitor model
241    #[doc(alias = "gdk_monitor_get_model")]
242    #[doc(alias = "get_model")]
243    fn model(&self) -> Option<glib::GString> {
244        unsafe { from_glib_none(ffi::gdk_monitor_get_model(self.as_ref().to_glib_none().0)) }
245    }
246
247    /// Gets the refresh rate of the monitor, if available.
248    ///
249    /// The value is in milli-Hertz, so a refresh rate of 60Hz
250    /// is returned as 60000.
251    ///
252    /// # Returns
253    ///
254    /// the refresh rate in milli-Hertz, or 0
255    #[doc(alias = "gdk_monitor_get_refresh_rate")]
256    #[doc(alias = "get_refresh_rate")]
257    #[doc(alias = "refresh-rate")]
258    fn refresh_rate(&self) -> i32 {
259        unsafe { ffi::gdk_monitor_get_refresh_rate(self.as_ref().to_glib_none().0) }
260    }
261
262    /// re drawing to a surface
263    /// where it is better to use [`SurfaceExt::scale()`][crate::prelude::SurfaceExt::scale()] instead.
264    ///
265    /// # Returns
266    ///
267    /// the scale
268    #[cfg(feature = "v4_14")]
269    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
270    #[doc(alias = "gdk_monitor_get_scale")]
271    #[doc(alias = "get_scale")]
272    fn scale(&self) -> f64 {
273        unsafe { ffi::gdk_monitor_get_scale(self.as_ref().to_glib_none().0) }
274    }
275
276    /// re drawing to a surface
277    /// where it is better to use [`SurfaceExt::scale_factor()`][crate::prelude::SurfaceExt::scale_factor()] instead.
278    ///
279    /// # Returns
280    ///
281    /// the scale factor
282    #[doc(alias = "gdk_monitor_get_scale_factor")]
283    #[doc(alias = "get_scale_factor")]
284    #[doc(alias = "scale-factor")]
285    fn scale_factor(&self) -> i32 {
286        unsafe { ffi::gdk_monitor_get_scale_factor(self.as_ref().to_glib_none().0) }
287    }
288
289    /// Gets information about the layout of red, green and blue
290    /// primaries for pixels.
291    ///
292    /// # Returns
293    ///
294    /// the subpixel layout
295    #[doc(alias = "gdk_monitor_get_subpixel_layout")]
296    #[doc(alias = "get_subpixel_layout")]
297    #[doc(alias = "subpixel-layout")]
298    fn subpixel_layout(&self) -> SubpixelLayout {
299        unsafe {
300            from_glib(ffi::gdk_monitor_get_subpixel_layout(
301                self.as_ref().to_glib_none().0,
302            ))
303        }
304    }
305
306    /// Gets the width in millimeters of the monitor.
307    ///
308    /// # Returns
309    ///
310    /// the physical width of the monitor
311    #[doc(alias = "gdk_monitor_get_width_mm")]
312    #[doc(alias = "get_width_mm")]
313    #[doc(alias = "width-mm")]
314    fn width_mm(&self) -> i32 {
315        unsafe { ffi::gdk_monitor_get_width_mm(self.as_ref().to_glib_none().0) }
316    }
317
318    /// Returns [`true`] if the @self object corresponds to a
319    /// physical monitor.
320    ///
321    /// The @self becomes invalid when the physical monitor
322    /// is unplugged or removed.
323    ///
324    /// # Returns
325    ///
326    /// [`true`] if the object corresponds to a physical monitor
327    #[doc(alias = "gdk_monitor_is_valid")]
328    #[doc(alias = "valid")]
329    fn is_valid(&self) -> bool {
330        unsafe { from_glib(ffi::gdk_monitor_is_valid(self.as_ref().to_glib_none().0)) }
331    }
332
333    /// Emitted when the output represented by @monitor gets disconnected.
334    #[doc(alias = "invalidate")]
335    fn connect_invalidate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
336        unsafe extern "C" fn invalidate_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
337            this: *mut ffi::GdkMonitor,
338            f: glib::ffi::gpointer,
339        ) {
340            unsafe {
341                let f: &F = &*(f as *const F);
342                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
343            }
344        }
345        unsafe {
346            let f: Box_<F> = Box_::new(f);
347            connect_raw(
348                self.as_ptr() as *mut _,
349                c"invalidate".as_ptr(),
350                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
351                    invalidate_trampoline::<Self, F> as *const (),
352                )),
353                Box_::into_raw(f),
354            )
355        }
356    }
357
358    #[doc(alias = "connector")]
359    fn connect_connector_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
360        unsafe extern "C" fn notify_connector_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
361            this: *mut ffi::GdkMonitor,
362            _param_spec: glib::ffi::gpointer,
363            f: glib::ffi::gpointer,
364        ) {
365            unsafe {
366                let f: &F = &*(f as *const F);
367                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
368            }
369        }
370        unsafe {
371            let f: Box_<F> = Box_::new(f);
372            connect_raw(
373                self.as_ptr() as *mut _,
374                c"notify::connector".as_ptr(),
375                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
376                    notify_connector_trampoline::<Self, F> as *const (),
377                )),
378                Box_::into_raw(f),
379            )
380        }
381    }
382
383    #[cfg(feature = "v4_10")]
384    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
385    #[doc(alias = "description")]
386    fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
387        unsafe extern "C" fn notify_description_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
388            this: *mut ffi::GdkMonitor,
389            _param_spec: glib::ffi::gpointer,
390            f: glib::ffi::gpointer,
391        ) {
392            unsafe {
393                let f: &F = &*(f as *const F);
394                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
395            }
396        }
397        unsafe {
398            let f: Box_<F> = Box_::new(f);
399            connect_raw(
400                self.as_ptr() as *mut _,
401                c"notify::description".as_ptr(),
402                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
403                    notify_description_trampoline::<Self, F> as *const (),
404                )),
405                Box_::into_raw(f),
406            )
407        }
408    }
409
410    #[doc(alias = "geometry")]
411    fn connect_geometry_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
412        unsafe extern "C" fn notify_geometry_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
413            this: *mut ffi::GdkMonitor,
414            _param_spec: glib::ffi::gpointer,
415            f: glib::ffi::gpointer,
416        ) {
417            unsafe {
418                let f: &F = &*(f as *const F);
419                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
420            }
421        }
422        unsafe {
423            let f: Box_<F> = Box_::new(f);
424            connect_raw(
425                self.as_ptr() as *mut _,
426                c"notify::geometry".as_ptr(),
427                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
428                    notify_geometry_trampoline::<Self, F> as *const (),
429                )),
430                Box_::into_raw(f),
431            )
432        }
433    }
434
435    #[doc(alias = "height-mm")]
436    fn connect_height_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
437        unsafe extern "C" fn notify_height_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
438            this: *mut ffi::GdkMonitor,
439            _param_spec: glib::ffi::gpointer,
440            f: glib::ffi::gpointer,
441        ) {
442            unsafe {
443                let f: &F = &*(f as *const F);
444                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
445            }
446        }
447        unsafe {
448            let f: Box_<F> = Box_::new(f);
449            connect_raw(
450                self.as_ptr() as *mut _,
451                c"notify::height-mm".as_ptr(),
452                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
453                    notify_height_mm_trampoline::<Self, F> as *const (),
454                )),
455                Box_::into_raw(f),
456            )
457        }
458    }
459
460    #[doc(alias = "manufacturer")]
461    fn connect_manufacturer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
462        unsafe extern "C" fn notify_manufacturer_trampoline<
463            P: IsA<Monitor>,
464            F: Fn(&P) + 'static,
465        >(
466            this: *mut ffi::GdkMonitor,
467            _param_spec: glib::ffi::gpointer,
468            f: glib::ffi::gpointer,
469        ) {
470            unsafe {
471                let f: &F = &*(f as *const F);
472                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
473            }
474        }
475        unsafe {
476            let f: Box_<F> = Box_::new(f);
477            connect_raw(
478                self.as_ptr() as *mut _,
479                c"notify::manufacturer".as_ptr(),
480                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
481                    notify_manufacturer_trampoline::<Self, F> as *const (),
482                )),
483                Box_::into_raw(f),
484            )
485        }
486    }
487
488    #[doc(alias = "model")]
489    fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
490        unsafe extern "C" fn notify_model_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
491            this: *mut ffi::GdkMonitor,
492            _param_spec: glib::ffi::gpointer,
493            f: glib::ffi::gpointer,
494        ) {
495            unsafe {
496                let f: &F = &*(f as *const F);
497                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
498            }
499        }
500        unsafe {
501            let f: Box_<F> = Box_::new(f);
502            connect_raw(
503                self.as_ptr() as *mut _,
504                c"notify::model".as_ptr(),
505                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
506                    notify_model_trampoline::<Self, F> as *const (),
507                )),
508                Box_::into_raw(f),
509            )
510        }
511    }
512
513    #[doc(alias = "refresh-rate")]
514    fn connect_refresh_rate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
515        unsafe extern "C" fn notify_refresh_rate_trampoline<
516            P: IsA<Monitor>,
517            F: Fn(&P) + 'static,
518        >(
519            this: *mut ffi::GdkMonitor,
520            _param_spec: glib::ffi::gpointer,
521            f: glib::ffi::gpointer,
522        ) {
523            unsafe {
524                let f: &F = &*(f as *const F);
525                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
526            }
527        }
528        unsafe {
529            let f: Box_<F> = Box_::new(f);
530            connect_raw(
531                self.as_ptr() as *mut _,
532                c"notify::refresh-rate".as_ptr(),
533                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
534                    notify_refresh_rate_trampoline::<Self, F> as *const (),
535                )),
536                Box_::into_raw(f),
537            )
538        }
539    }
540
541    #[cfg(feature = "v4_14")]
542    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
543    #[doc(alias = "scale")]
544    fn connect_scale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
545        unsafe extern "C" fn notify_scale_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
546            this: *mut ffi::GdkMonitor,
547            _param_spec: glib::ffi::gpointer,
548            f: glib::ffi::gpointer,
549        ) {
550            unsafe {
551                let f: &F = &*(f as *const F);
552                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
553            }
554        }
555        unsafe {
556            let f: Box_<F> = Box_::new(f);
557            connect_raw(
558                self.as_ptr() as *mut _,
559                c"notify::scale".as_ptr(),
560                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
561                    notify_scale_trampoline::<Self, F> as *const (),
562                )),
563                Box_::into_raw(f),
564            )
565        }
566    }
567
568    #[doc(alias = "scale-factor")]
569    fn connect_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
570        unsafe extern "C" fn notify_scale_factor_trampoline<
571            P: IsA<Monitor>,
572            F: Fn(&P) + 'static,
573        >(
574            this: *mut ffi::GdkMonitor,
575            _param_spec: glib::ffi::gpointer,
576            f: glib::ffi::gpointer,
577        ) {
578            unsafe {
579                let f: &F = &*(f as *const F);
580                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
581            }
582        }
583        unsafe {
584            let f: Box_<F> = Box_::new(f);
585            connect_raw(
586                self.as_ptr() as *mut _,
587                c"notify::scale-factor".as_ptr(),
588                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
589                    notify_scale_factor_trampoline::<Self, F> as *const (),
590                )),
591                Box_::into_raw(f),
592            )
593        }
594    }
595
596    #[doc(alias = "subpixel-layout")]
597    fn connect_subpixel_layout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
598        unsafe extern "C" fn notify_subpixel_layout_trampoline<
599            P: IsA<Monitor>,
600            F: Fn(&P) + 'static,
601        >(
602            this: *mut ffi::GdkMonitor,
603            _param_spec: glib::ffi::gpointer,
604            f: glib::ffi::gpointer,
605        ) {
606            unsafe {
607                let f: &F = &*(f as *const F);
608                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
609            }
610        }
611        unsafe {
612            let f: Box_<F> = Box_::new(f);
613            connect_raw(
614                self.as_ptr() as *mut _,
615                c"notify::subpixel-layout".as_ptr(),
616                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
617                    notify_subpixel_layout_trampoline::<Self, F> as *const (),
618                )),
619                Box_::into_raw(f),
620            )
621        }
622    }
623
624    #[doc(alias = "valid")]
625    fn connect_valid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
626        unsafe extern "C" fn notify_valid_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
627            this: *mut ffi::GdkMonitor,
628            _param_spec: glib::ffi::gpointer,
629            f: glib::ffi::gpointer,
630        ) {
631            unsafe {
632                let f: &F = &*(f as *const F);
633                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
634            }
635        }
636        unsafe {
637            let f: Box_<F> = Box_::new(f);
638            connect_raw(
639                self.as_ptr() as *mut _,
640                c"notify::valid".as_ptr(),
641                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
642                    notify_valid_trampoline::<Self, F> as *const (),
643                )),
644                Box_::into_raw(f),
645            )
646        }
647    }
648
649    #[doc(alias = "width-mm")]
650    fn connect_width_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
651        unsafe extern "C" fn notify_width_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
652            this: *mut ffi::GdkMonitor,
653            _param_spec: glib::ffi::gpointer,
654            f: glib::ffi::gpointer,
655        ) {
656            unsafe {
657                let f: &F = &*(f as *const F);
658                f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
659            }
660        }
661        unsafe {
662            let f: Box_<F> = Box_::new(f);
663            connect_raw(
664                self.as_ptr() as *mut _,
665                c"notify::width-mm".as_ptr(),
666                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
667                    notify_width_mm_trampoline::<Self, F> as *const (),
668                )),
669                Box_::into_raw(f),
670            )
671        }
672    }
673}
674
675impl<O: IsA<Monitor>> MonitorExt for O {}