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