1use 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 #[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
128pub trait MonitorExt: IsA<Monitor> + 'static {
134 #[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 #[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 #[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 #[doc(alias = "gdk_monitor_get_geometry")]
195 #[doc(alias = "get_geometry")]
196 fn geometry(&self) -> Rectangle {
197 unsafe {
198 let mut geometry = Rectangle::uninitialized();
199 ffi::gdk_monitor_get_geometry(
200 self.as_ref().to_glib_none().0,
201 geometry.to_glib_none_mut().0,
202 );
203 geometry
204 }
205 }
206
207 #[doc(alias = "gdk_monitor_get_height_mm")]
213 #[doc(alias = "get_height_mm")]
214 #[doc(alias = "height-mm")]
215 fn height_mm(&self) -> i32 {
216 unsafe { ffi::gdk_monitor_get_height_mm(self.as_ref().to_glib_none().0) }
217 }
218
219 #[doc(alias = "gdk_monitor_get_manufacturer")]
231 #[doc(alias = "get_manufacturer")]
232 fn manufacturer(&self) -> Option<glib::GString> {
233 unsafe {
234 from_glib_none(ffi::gdk_monitor_get_manufacturer(
235 self.as_ref().to_glib_none().0,
236 ))
237 }
238 }
239
240 #[doc(alias = "gdk_monitor_get_model")]
246 #[doc(alias = "get_model")]
247 fn model(&self) -> Option<glib::GString> {
248 unsafe { from_glib_none(ffi::gdk_monitor_get_model(self.as_ref().to_glib_none().0)) }
249 }
250
251 #[doc(alias = "gdk_monitor_get_refresh_rate")]
260 #[doc(alias = "get_refresh_rate")]
261 #[doc(alias = "refresh-rate")]
262 fn refresh_rate(&self) -> i32 {
263 unsafe { ffi::gdk_monitor_get_refresh_rate(self.as_ref().to_glib_none().0) }
264 }
265
266 #[cfg(feature = "v4_14")]
277 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
278 #[doc(alias = "gdk_monitor_get_scale")]
279 #[doc(alias = "get_scale")]
280 fn scale(&self) -> f64 {
281 unsafe { ffi::gdk_monitor_get_scale(self.as_ref().to_glib_none().0) }
282 }
283
284 #[doc(alias = "gdk_monitor_get_scale_factor")]
298 #[doc(alias = "get_scale_factor")]
299 #[doc(alias = "scale-factor")]
300 fn scale_factor(&self) -> i32 {
301 unsafe { ffi::gdk_monitor_get_scale_factor(self.as_ref().to_glib_none().0) }
302 }
303
304 #[doc(alias = "gdk_monitor_get_subpixel_layout")]
311 #[doc(alias = "get_subpixel_layout")]
312 #[doc(alias = "subpixel-layout")]
313 fn subpixel_layout(&self) -> SubpixelLayout {
314 unsafe {
315 from_glib(ffi::gdk_monitor_get_subpixel_layout(
316 self.as_ref().to_glib_none().0,
317 ))
318 }
319 }
320
321 #[doc(alias = "gdk_monitor_get_width_mm")]
327 #[doc(alias = "get_width_mm")]
328 #[doc(alias = "width-mm")]
329 fn width_mm(&self) -> i32 {
330 unsafe { ffi::gdk_monitor_get_width_mm(self.as_ref().to_glib_none().0) }
331 }
332
333 #[doc(alias = "gdk_monitor_is_valid")]
343 #[doc(alias = "valid")]
344 fn is_valid(&self) -> bool {
345 unsafe { from_glib(ffi::gdk_monitor_is_valid(self.as_ref().to_glib_none().0)) }
346 }
347
348 #[doc(alias = "invalidate")]
350 fn connect_invalidate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
351 unsafe extern "C" fn invalidate_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
352 this: *mut ffi::GdkMonitor,
353 f: glib::ffi::gpointer,
354 ) {
355 unsafe {
356 let f: &F = &*(f as *const F);
357 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
358 }
359 }
360 unsafe {
361 let f: Box_<F> = Box_::new(f);
362 connect_raw(
363 self.as_ptr() as *mut _,
364 c"invalidate".as_ptr() as *const _,
365 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
366 invalidate_trampoline::<Self, F> as *const (),
367 )),
368 Box_::into_raw(f),
369 )
370 }
371 }
372
373 #[doc(alias = "connector")]
374 fn connect_connector_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
375 unsafe extern "C" fn notify_connector_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
376 this: *mut ffi::GdkMonitor,
377 _param_spec: glib::ffi::gpointer,
378 f: glib::ffi::gpointer,
379 ) {
380 unsafe {
381 let f: &F = &*(f as *const F);
382 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
383 }
384 }
385 unsafe {
386 let f: Box_<F> = Box_::new(f);
387 connect_raw(
388 self.as_ptr() as *mut _,
389 c"notify::connector".as_ptr() as *const _,
390 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
391 notify_connector_trampoline::<Self, F> as *const (),
392 )),
393 Box_::into_raw(f),
394 )
395 }
396 }
397
398 #[cfg(feature = "v4_10")]
399 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
400 #[doc(alias = "description")]
401 fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
402 unsafe extern "C" fn notify_description_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
403 this: *mut ffi::GdkMonitor,
404 _param_spec: glib::ffi::gpointer,
405 f: glib::ffi::gpointer,
406 ) {
407 unsafe {
408 let f: &F = &*(f as *const F);
409 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
410 }
411 }
412 unsafe {
413 let f: Box_<F> = Box_::new(f);
414 connect_raw(
415 self.as_ptr() as *mut _,
416 c"notify::description".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 unsafe {
433 let f: &F = &*(f as *const F);
434 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
435 }
436 }
437 unsafe {
438 let f: Box_<F> = Box_::new(f);
439 connect_raw(
440 self.as_ptr() as *mut _,
441 c"notify::geometry".as_ptr() as *const _,
442 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
443 notify_geometry_trampoline::<Self, F> as *const (),
444 )),
445 Box_::into_raw(f),
446 )
447 }
448 }
449
450 #[doc(alias = "height-mm")]
451 fn connect_height_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
452 unsafe extern "C" fn notify_height_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
453 this: *mut ffi::GdkMonitor,
454 _param_spec: glib::ffi::gpointer,
455 f: glib::ffi::gpointer,
456 ) {
457 unsafe {
458 let f: &F = &*(f as *const F);
459 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
460 }
461 }
462 unsafe {
463 let f: Box_<F> = Box_::new(f);
464 connect_raw(
465 self.as_ptr() as *mut _,
466 c"notify::height-mm".as_ptr() as *const _,
467 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
468 notify_height_mm_trampoline::<Self, F> as *const (),
469 )),
470 Box_::into_raw(f),
471 )
472 }
473 }
474
475 #[doc(alias = "manufacturer")]
476 fn connect_manufacturer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
477 unsafe extern "C" fn notify_manufacturer_trampoline<
478 P: IsA<Monitor>,
479 F: Fn(&P) + 'static,
480 >(
481 this: *mut ffi::GdkMonitor,
482 _param_spec: glib::ffi::gpointer,
483 f: glib::ffi::gpointer,
484 ) {
485 unsafe {
486 let f: &F = &*(f as *const F);
487 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
488 }
489 }
490 unsafe {
491 let f: Box_<F> = Box_::new(f);
492 connect_raw(
493 self.as_ptr() as *mut _,
494 c"notify::manufacturer".as_ptr() as *const _,
495 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
496 notify_manufacturer_trampoline::<Self, F> as *const (),
497 )),
498 Box_::into_raw(f),
499 )
500 }
501 }
502
503 #[doc(alias = "model")]
504 fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
505 unsafe extern "C" fn notify_model_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
506 this: *mut ffi::GdkMonitor,
507 _param_spec: glib::ffi::gpointer,
508 f: glib::ffi::gpointer,
509 ) {
510 unsafe {
511 let f: &F = &*(f as *const F);
512 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
513 }
514 }
515 unsafe {
516 let f: Box_<F> = Box_::new(f);
517 connect_raw(
518 self.as_ptr() as *mut _,
519 c"notify::model".as_ptr() as *const _,
520 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
521 notify_model_trampoline::<Self, F> as *const (),
522 )),
523 Box_::into_raw(f),
524 )
525 }
526 }
527
528 #[doc(alias = "refresh-rate")]
529 fn connect_refresh_rate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
530 unsafe extern "C" fn notify_refresh_rate_trampoline<
531 P: IsA<Monitor>,
532 F: Fn(&P) + 'static,
533 >(
534 this: *mut ffi::GdkMonitor,
535 _param_spec: glib::ffi::gpointer,
536 f: glib::ffi::gpointer,
537 ) {
538 unsafe {
539 let f: &F = &*(f as *const F);
540 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
541 }
542 }
543 unsafe {
544 let f: Box_<F> = Box_::new(f);
545 connect_raw(
546 self.as_ptr() as *mut _,
547 c"notify::refresh-rate".as_ptr() as *const _,
548 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
549 notify_refresh_rate_trampoline::<Self, F> as *const (),
550 )),
551 Box_::into_raw(f),
552 )
553 }
554 }
555
556 #[cfg(feature = "v4_14")]
557 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
558 #[doc(alias = "scale")]
559 fn connect_scale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
560 unsafe extern "C" fn notify_scale_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
561 this: *mut ffi::GdkMonitor,
562 _param_spec: glib::ffi::gpointer,
563 f: glib::ffi::gpointer,
564 ) {
565 unsafe {
566 let f: &F = &*(f as *const F);
567 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
568 }
569 }
570 unsafe {
571 let f: Box_<F> = Box_::new(f);
572 connect_raw(
573 self.as_ptr() as *mut _,
574 c"notify::scale".as_ptr() as *const _,
575 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
576 notify_scale_trampoline::<Self, F> as *const (),
577 )),
578 Box_::into_raw(f),
579 )
580 }
581 }
582
583 #[doc(alias = "scale-factor")]
584 fn connect_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
585 unsafe extern "C" fn notify_scale_factor_trampoline<
586 P: IsA<Monitor>,
587 F: Fn(&P) + 'static,
588 >(
589 this: *mut ffi::GdkMonitor,
590 _param_spec: glib::ffi::gpointer,
591 f: glib::ffi::gpointer,
592 ) {
593 unsafe {
594 let f: &F = &*(f as *const F);
595 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
596 }
597 }
598 unsafe {
599 let f: Box_<F> = Box_::new(f);
600 connect_raw(
601 self.as_ptr() as *mut _,
602 c"notify::scale-factor".as_ptr() as *const _,
603 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
604 notify_scale_factor_trampoline::<Self, F> as *const (),
605 )),
606 Box_::into_raw(f),
607 )
608 }
609 }
610
611 #[doc(alias = "subpixel-layout")]
612 fn connect_subpixel_layout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
613 unsafe extern "C" fn notify_subpixel_layout_trampoline<
614 P: IsA<Monitor>,
615 F: Fn(&P) + 'static,
616 >(
617 this: *mut ffi::GdkMonitor,
618 _param_spec: glib::ffi::gpointer,
619 f: glib::ffi::gpointer,
620 ) {
621 unsafe {
622 let f: &F = &*(f as *const F);
623 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
624 }
625 }
626 unsafe {
627 let f: Box_<F> = Box_::new(f);
628 connect_raw(
629 self.as_ptr() as *mut _,
630 c"notify::subpixel-layout".as_ptr() as *const _,
631 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
632 notify_subpixel_layout_trampoline::<Self, F> as *const (),
633 )),
634 Box_::into_raw(f),
635 )
636 }
637 }
638
639 #[doc(alias = "valid")]
640 fn connect_valid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
641 unsafe extern "C" fn notify_valid_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
642 this: *mut ffi::GdkMonitor,
643 _param_spec: glib::ffi::gpointer,
644 f: glib::ffi::gpointer,
645 ) {
646 unsafe {
647 let f: &F = &*(f as *const F);
648 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
649 }
650 }
651 unsafe {
652 let f: Box_<F> = Box_::new(f);
653 connect_raw(
654 self.as_ptr() as *mut _,
655 c"notify::valid".as_ptr() as *const _,
656 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
657 notify_valid_trampoline::<Self, F> as *const (),
658 )),
659 Box_::into_raw(f),
660 )
661 }
662 }
663
664 #[doc(alias = "width-mm")]
665 fn connect_width_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
666 unsafe extern "C" fn notify_width_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
667 this: *mut ffi::GdkMonitor,
668 _param_spec: glib::ffi::gpointer,
669 f: glib::ffi::gpointer,
670 ) {
671 unsafe {
672 let f: &F = &*(f as *const F);
673 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
674 }
675 }
676 unsafe {
677 let f: Box_<F> = Box_::new(f);
678 connect_raw(
679 self.as_ptr() as *mut _,
680 c"notify::width-mm".as_ptr() as *const _,
681 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
682 notify_width_mm_trampoline::<Self, F> as *const (),
683 )),
684 Box_::into_raw(f),
685 )
686 }
687 }
688}
689
690impl<O: IsA<Monitor>> MonitorExt for O {}