1use 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 #[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
91pub trait MonitorExt: IsA<Monitor> + sealed::Sealed + 'static {
97 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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}