1use crate::{ffi, Display, Rectangle, SubpixelLayout};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GdkMonitor")]
118 pub struct Monitor(Object<ffi::GdkMonitor, ffi::GdkMonitorClass>);
119
120 match fn {
121 type_ => || ffi::gdk_monitor_get_type(),
122 }
123}
124
125impl Monitor {
126 pub const NONE: Option<&'static Monitor> = None;
127}
128
129mod sealed {
130 pub trait Sealed {}
131 impl<T: super::IsA<super::Monitor>> Sealed for T {}
132}
133
134pub trait MonitorExt: IsA<Monitor> + sealed::Sealed + 'static {
140 #[doc(alias = "gdk_monitor_get_connector")]
150 #[doc(alias = "get_connector")]
151 fn connector(&self) -> Option<glib::GString> {
152 unsafe {
153 from_glib_none(ffi::gdk_monitor_get_connector(
154 self.as_ref().to_glib_none().0,
155 ))
156 }
157 }
158
159 #[cfg(feature = "v4_10")]
167 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
168 #[doc(alias = "gdk_monitor_get_description")]
169 #[doc(alias = "get_description")]
170 fn description(&self) -> Option<glib::GString> {
171 unsafe {
172 from_glib_none(ffi::gdk_monitor_get_description(
173 self.as_ref().to_glib_none().0,
174 ))
175 }
176 }
177
178 #[doc(alias = "gdk_monitor_get_display")]
184 #[doc(alias = "get_display")]
185 fn display(&self) -> Display {
186 unsafe { from_glib_none(ffi::gdk_monitor_get_display(self.as_ref().to_glib_none().0)) }
187 }
188
189 #[doc(alias = "gdk_monitor_get_geometry")]
201 #[doc(alias = "get_geometry")]
202 fn geometry(&self) -> Rectangle {
203 unsafe {
204 let mut geometry = Rectangle::uninitialized();
205 ffi::gdk_monitor_get_geometry(
206 self.as_ref().to_glib_none().0,
207 geometry.to_glib_none_mut().0,
208 );
209 geometry
210 }
211 }
212
213 #[doc(alias = "gdk_monitor_get_height_mm")]
219 #[doc(alias = "get_height_mm")]
220 #[doc(alias = "height-mm")]
221 fn height_mm(&self) -> i32 {
222 unsafe { ffi::gdk_monitor_get_height_mm(self.as_ref().to_glib_none().0) }
223 }
224
225 #[doc(alias = "gdk_monitor_get_manufacturer")]
237 #[doc(alias = "get_manufacturer")]
238 fn manufacturer(&self) -> Option<glib::GString> {
239 unsafe {
240 from_glib_none(ffi::gdk_monitor_get_manufacturer(
241 self.as_ref().to_glib_none().0,
242 ))
243 }
244 }
245
246 #[doc(alias = "gdk_monitor_get_model")]
252 #[doc(alias = "get_model")]
253 fn model(&self) -> Option<glib::GString> {
254 unsafe { from_glib_none(ffi::gdk_monitor_get_model(self.as_ref().to_glib_none().0)) }
255 }
256
257 #[doc(alias = "gdk_monitor_get_refresh_rate")]
266 #[doc(alias = "get_refresh_rate")]
267 #[doc(alias = "refresh-rate")]
268 fn refresh_rate(&self) -> i32 {
269 unsafe { ffi::gdk_monitor_get_refresh_rate(self.as_ref().to_glib_none().0) }
270 }
271
272 #[cfg(feature = "v4_14")]
283 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
284 #[doc(alias = "gdk_monitor_get_scale")]
285 #[doc(alias = "get_scale")]
286 fn scale(&self) -> f64 {
287 unsafe { ffi::gdk_monitor_get_scale(self.as_ref().to_glib_none().0) }
288 }
289
290 #[doc(alias = "gdk_monitor_get_scale_factor")]
304 #[doc(alias = "get_scale_factor")]
305 #[doc(alias = "scale-factor")]
306 fn scale_factor(&self) -> i32 {
307 unsafe { ffi::gdk_monitor_get_scale_factor(self.as_ref().to_glib_none().0) }
308 }
309
310 #[doc(alias = "gdk_monitor_get_subpixel_layout")]
317 #[doc(alias = "get_subpixel_layout")]
318 #[doc(alias = "subpixel-layout")]
319 fn subpixel_layout(&self) -> SubpixelLayout {
320 unsafe {
321 from_glib(ffi::gdk_monitor_get_subpixel_layout(
322 self.as_ref().to_glib_none().0,
323 ))
324 }
325 }
326
327 #[doc(alias = "gdk_monitor_get_width_mm")]
333 #[doc(alias = "get_width_mm")]
334 #[doc(alias = "width-mm")]
335 fn width_mm(&self) -> i32 {
336 unsafe { ffi::gdk_monitor_get_width_mm(self.as_ref().to_glib_none().0) }
337 }
338
339 #[doc(alias = "gdk_monitor_is_valid")]
349 #[doc(alias = "valid")]
350 fn is_valid(&self) -> bool {
351 unsafe { from_glib(ffi::gdk_monitor_is_valid(self.as_ref().to_glib_none().0)) }
352 }
353
354 #[doc(alias = "invalidate")]
356 fn connect_invalidate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
357 unsafe extern "C" fn invalidate_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
358 this: *mut ffi::GdkMonitor,
359 f: glib::ffi::gpointer,
360 ) {
361 let f: &F = &*(f as *const F);
362 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
363 }
364 unsafe {
365 let f: Box_<F> = Box_::new(f);
366 connect_raw(
367 self.as_ptr() as *mut _,
368 b"invalidate\0".as_ptr() as *const _,
369 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
370 invalidate_trampoline::<Self, F> as *const (),
371 )),
372 Box_::into_raw(f),
373 )
374 }
375 }
376
377 #[doc(alias = "connector")]
378 fn connect_connector_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
379 unsafe extern "C" fn notify_connector_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
380 this: *mut ffi::GdkMonitor,
381 _param_spec: glib::ffi::gpointer,
382 f: glib::ffi::gpointer,
383 ) {
384 let f: &F = &*(f as *const F);
385 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
386 }
387 unsafe {
388 let f: Box_<F> = Box_::new(f);
389 connect_raw(
390 self.as_ptr() as *mut _,
391 b"notify::connector\0".as_ptr() as *const _,
392 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
393 notify_connector_trampoline::<Self, F> as *const (),
394 )),
395 Box_::into_raw(f),
396 )
397 }
398 }
399
400 #[cfg(feature = "v4_10")]
401 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
402 #[doc(alias = "description")]
403 fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
404 unsafe extern "C" fn notify_description_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
405 this: *mut ffi::GdkMonitor,
406 _param_spec: glib::ffi::gpointer,
407 f: glib::ffi::gpointer,
408 ) {
409 let f: &F = &*(f as *const F);
410 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
411 }
412 unsafe {
413 let f: Box_<F> = Box_::new(f);
414 connect_raw(
415 self.as_ptr() as *mut _,
416 b"notify::description\0".as_ptr() as *const _,
417 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
418 notify_description_trampoline::<Self, F> as *const (),
419 )),
420 Box_::into_raw(f),
421 )
422 }
423 }
424
425 #[doc(alias = "geometry")]
426 fn connect_geometry_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
427 unsafe extern "C" fn notify_geometry_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
428 this: *mut ffi::GdkMonitor,
429 _param_spec: glib::ffi::gpointer,
430 f: glib::ffi::gpointer,
431 ) {
432 let f: &F = &*(f as *const F);
433 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
434 }
435 unsafe {
436 let f: Box_<F> = Box_::new(f);
437 connect_raw(
438 self.as_ptr() as *mut _,
439 b"notify::geometry\0".as_ptr() as *const _,
440 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
441 notify_geometry_trampoline::<Self, F> as *const (),
442 )),
443 Box_::into_raw(f),
444 )
445 }
446 }
447
448 #[doc(alias = "height-mm")]
449 fn connect_height_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
450 unsafe extern "C" fn notify_height_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
451 this: *mut ffi::GdkMonitor,
452 _param_spec: glib::ffi::gpointer,
453 f: glib::ffi::gpointer,
454 ) {
455 let f: &F = &*(f as *const F);
456 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
457 }
458 unsafe {
459 let f: Box_<F> = Box_::new(f);
460 connect_raw(
461 self.as_ptr() as *mut _,
462 b"notify::height-mm\0".as_ptr() as *const _,
463 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
464 notify_height_mm_trampoline::<Self, F> as *const (),
465 )),
466 Box_::into_raw(f),
467 )
468 }
469 }
470
471 #[doc(alias = "manufacturer")]
472 fn connect_manufacturer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
473 unsafe extern "C" fn notify_manufacturer_trampoline<
474 P: IsA<Monitor>,
475 F: Fn(&P) + 'static,
476 >(
477 this: *mut ffi::GdkMonitor,
478 _param_spec: glib::ffi::gpointer,
479 f: glib::ffi::gpointer,
480 ) {
481 let f: &F = &*(f as *const F);
482 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
483 }
484 unsafe {
485 let f: Box_<F> = Box_::new(f);
486 connect_raw(
487 self.as_ptr() as *mut _,
488 b"notify::manufacturer\0".as_ptr() as *const _,
489 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
490 notify_manufacturer_trampoline::<Self, F> as *const (),
491 )),
492 Box_::into_raw(f),
493 )
494 }
495 }
496
497 #[doc(alias = "model")]
498 fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
499 unsafe extern "C" fn notify_model_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
500 this: *mut ffi::GdkMonitor,
501 _param_spec: glib::ffi::gpointer,
502 f: glib::ffi::gpointer,
503 ) {
504 let f: &F = &*(f as *const F);
505 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
506 }
507 unsafe {
508 let f: Box_<F> = Box_::new(f);
509 connect_raw(
510 self.as_ptr() as *mut _,
511 b"notify::model\0".as_ptr() as *const _,
512 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
513 notify_model_trampoline::<Self, F> as *const (),
514 )),
515 Box_::into_raw(f),
516 )
517 }
518 }
519
520 #[doc(alias = "refresh-rate")]
521 fn connect_refresh_rate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
522 unsafe extern "C" fn notify_refresh_rate_trampoline<
523 P: IsA<Monitor>,
524 F: Fn(&P) + 'static,
525 >(
526 this: *mut ffi::GdkMonitor,
527 _param_spec: glib::ffi::gpointer,
528 f: glib::ffi::gpointer,
529 ) {
530 let f: &F = &*(f as *const F);
531 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
532 }
533 unsafe {
534 let f: Box_<F> = Box_::new(f);
535 connect_raw(
536 self.as_ptr() as *mut _,
537 b"notify::refresh-rate\0".as_ptr() as *const _,
538 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
539 notify_refresh_rate_trampoline::<Self, F> as *const (),
540 )),
541 Box_::into_raw(f),
542 )
543 }
544 }
545
546 #[cfg(feature = "v4_14")]
547 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
548 #[doc(alias = "scale")]
549 fn connect_scale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
550 unsafe extern "C" fn notify_scale_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
551 this: *mut ffi::GdkMonitor,
552 _param_spec: glib::ffi::gpointer,
553 f: glib::ffi::gpointer,
554 ) {
555 let f: &F = &*(f as *const F);
556 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
557 }
558 unsafe {
559 let f: Box_<F> = Box_::new(f);
560 connect_raw(
561 self.as_ptr() as *mut _,
562 b"notify::scale\0".as_ptr() as *const _,
563 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
564 notify_scale_trampoline::<Self, F> as *const (),
565 )),
566 Box_::into_raw(f),
567 )
568 }
569 }
570
571 #[doc(alias = "scale-factor")]
572 fn connect_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
573 unsafe extern "C" fn notify_scale_factor_trampoline<
574 P: IsA<Monitor>,
575 F: Fn(&P) + 'static,
576 >(
577 this: *mut ffi::GdkMonitor,
578 _param_spec: glib::ffi::gpointer,
579 f: glib::ffi::gpointer,
580 ) {
581 let f: &F = &*(f as *const F);
582 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
583 }
584 unsafe {
585 let f: Box_<F> = Box_::new(f);
586 connect_raw(
587 self.as_ptr() as *mut _,
588 b"notify::scale-factor\0".as_ptr() as *const _,
589 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
590 notify_scale_factor_trampoline::<Self, F> as *const (),
591 )),
592 Box_::into_raw(f),
593 )
594 }
595 }
596
597 #[doc(alias = "subpixel-layout")]
598 fn connect_subpixel_layout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
599 unsafe extern "C" fn notify_subpixel_layout_trampoline<
600 P: IsA<Monitor>,
601 F: Fn(&P) + 'static,
602 >(
603 this: *mut ffi::GdkMonitor,
604 _param_spec: glib::ffi::gpointer,
605 f: glib::ffi::gpointer,
606 ) {
607 let f: &F = &*(f as *const F);
608 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
609 }
610 unsafe {
611 let f: Box_<F> = Box_::new(f);
612 connect_raw(
613 self.as_ptr() as *mut _,
614 b"notify::subpixel-layout\0".as_ptr() as *const _,
615 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
616 notify_subpixel_layout_trampoline::<Self, F> as *const (),
617 )),
618 Box_::into_raw(f),
619 )
620 }
621 }
622
623 #[doc(alias = "valid")]
624 fn connect_valid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
625 unsafe extern "C" fn notify_valid_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
626 this: *mut ffi::GdkMonitor,
627 _param_spec: glib::ffi::gpointer,
628 f: glib::ffi::gpointer,
629 ) {
630 let f: &F = &*(f as *const F);
631 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
632 }
633 unsafe {
634 let f: Box_<F> = Box_::new(f);
635 connect_raw(
636 self.as_ptr() as *mut _,
637 b"notify::valid\0".as_ptr() as *const _,
638 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
639 notify_valid_trampoline::<Self, F> as *const (),
640 )),
641 Box_::into_raw(f),
642 )
643 }
644 }
645
646 #[doc(alias = "width-mm")]
647 fn connect_width_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
648 unsafe extern "C" fn notify_width_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
649 this: *mut ffi::GdkMonitor,
650 _param_spec: glib::ffi::gpointer,
651 f: glib::ffi::gpointer,
652 ) {
653 let f: &F = &*(f as *const F);
654 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
655 }
656 unsafe {
657 let f: Box_<F> = Box_::new(f);
658 connect_raw(
659 self.as_ptr() as *mut _,
660 b"notify::width-mm\0".as_ptr() as *const _,
661 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
662 notify_width_mm_trampoline::<Self, F> as *const (),
663 )),
664 Box_::into_raw(f),
665 )
666 }
667 }
668}
669
670impl<O: IsA<Monitor>> MonitorExt for O {}