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")]
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 let f: &F = &*(f as *const F);
356 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
357 }
358 unsafe {
359 let f: Box_<F> = Box_::new(f);
360 connect_raw(
361 self.as_ptr() as *mut _,
362 c"invalidate".as_ptr() as *const _,
363 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
364 invalidate_trampoline::<Self, F> as *const (),
365 )),
366 Box_::into_raw(f),
367 )
368 }
369 }
370
371 #[doc(alias = "connector")]
372 fn connect_connector_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
373 unsafe extern "C" fn notify_connector_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
374 this: *mut ffi::GdkMonitor,
375 _param_spec: glib::ffi::gpointer,
376 f: glib::ffi::gpointer,
377 ) {
378 let f: &F = &*(f as *const F);
379 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
380 }
381 unsafe {
382 let f: Box_<F> = Box_::new(f);
383 connect_raw(
384 self.as_ptr() as *mut _,
385 c"notify::connector".as_ptr() as *const _,
386 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
387 notify_connector_trampoline::<Self, F> as *const (),
388 )),
389 Box_::into_raw(f),
390 )
391 }
392 }
393
394 #[cfg(feature = "v4_10")]
395 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
396 #[doc(alias = "description")]
397 fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
398 unsafe extern "C" fn notify_description_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
399 this: *mut ffi::GdkMonitor,
400 _param_spec: glib::ffi::gpointer,
401 f: glib::ffi::gpointer,
402 ) {
403 let f: &F = &*(f as *const F);
404 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
405 }
406 unsafe {
407 let f: Box_<F> = Box_::new(f);
408 connect_raw(
409 self.as_ptr() as *mut _,
410 c"notify::description".as_ptr() as *const _,
411 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
412 notify_description_trampoline::<Self, F> as *const (),
413 )),
414 Box_::into_raw(f),
415 )
416 }
417 }
418
419 #[doc(alias = "geometry")]
420 fn connect_geometry_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
421 unsafe extern "C" fn notify_geometry_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
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 c"notify::geometry".as_ptr() as *const _,
434 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
435 notify_geometry_trampoline::<Self, F> as *const (),
436 )),
437 Box_::into_raw(f),
438 )
439 }
440 }
441
442 #[doc(alias = "height-mm")]
443 fn connect_height_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
444 unsafe extern "C" fn notify_height_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
445 this: *mut ffi::GdkMonitor,
446 _param_spec: glib::ffi::gpointer,
447 f: glib::ffi::gpointer,
448 ) {
449 let f: &F = &*(f as *const F);
450 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
451 }
452 unsafe {
453 let f: Box_<F> = Box_::new(f);
454 connect_raw(
455 self.as_ptr() as *mut _,
456 c"notify::height-mm".as_ptr() as *const _,
457 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
458 notify_height_mm_trampoline::<Self, F> as *const (),
459 )),
460 Box_::into_raw(f),
461 )
462 }
463 }
464
465 #[doc(alias = "manufacturer")]
466 fn connect_manufacturer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
467 unsafe extern "C" fn notify_manufacturer_trampoline<
468 P: IsA<Monitor>,
469 F: Fn(&P) + 'static,
470 >(
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 c"notify::manufacturer".as_ptr() as *const _,
483 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
484 notify_manufacturer_trampoline::<Self, F> as *const (),
485 )),
486 Box_::into_raw(f),
487 )
488 }
489 }
490
491 #[doc(alias = "model")]
492 fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
493 unsafe extern "C" fn notify_model_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 c"notify::model".as_ptr() as *const _,
506 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
507 notify_model_trampoline::<Self, F> as *const (),
508 )),
509 Box_::into_raw(f),
510 )
511 }
512 }
513
514 #[doc(alias = "refresh-rate")]
515 fn connect_refresh_rate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
516 unsafe extern "C" fn notify_refresh_rate_trampoline<
517 P: IsA<Monitor>,
518 F: Fn(&P) + 'static,
519 >(
520 this: *mut ffi::GdkMonitor,
521 _param_spec: glib::ffi::gpointer,
522 f: glib::ffi::gpointer,
523 ) {
524 let f: &F = &*(f as *const F);
525 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
526 }
527 unsafe {
528 let f: Box_<F> = Box_::new(f);
529 connect_raw(
530 self.as_ptr() as *mut _,
531 c"notify::refresh-rate".as_ptr() as *const _,
532 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
533 notify_refresh_rate_trampoline::<Self, F> as *const (),
534 )),
535 Box_::into_raw(f),
536 )
537 }
538 }
539
540 #[cfg(feature = "v4_14")]
541 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
542 #[doc(alias = "scale")]
543 fn connect_scale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
544 unsafe extern "C" fn notify_scale_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
545 this: *mut ffi::GdkMonitor,
546 _param_spec: glib::ffi::gpointer,
547 f: glib::ffi::gpointer,
548 ) {
549 let f: &F = &*(f as *const F);
550 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
551 }
552 unsafe {
553 let f: Box_<F> = Box_::new(f);
554 connect_raw(
555 self.as_ptr() as *mut _,
556 c"notify::scale".as_ptr() as *const _,
557 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
558 notify_scale_trampoline::<Self, F> as *const (),
559 )),
560 Box_::into_raw(f),
561 )
562 }
563 }
564
565 #[doc(alias = "scale-factor")]
566 fn connect_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
567 unsafe extern "C" fn notify_scale_factor_trampoline<
568 P: IsA<Monitor>,
569 F: Fn(&P) + 'static,
570 >(
571 this: *mut ffi::GdkMonitor,
572 _param_spec: glib::ffi::gpointer,
573 f: glib::ffi::gpointer,
574 ) {
575 let f: &F = &*(f as *const F);
576 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
577 }
578 unsafe {
579 let f: Box_<F> = Box_::new(f);
580 connect_raw(
581 self.as_ptr() as *mut _,
582 c"notify::scale-factor".as_ptr() as *const _,
583 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
584 notify_scale_factor_trampoline::<Self, F> as *const (),
585 )),
586 Box_::into_raw(f),
587 )
588 }
589 }
590
591 #[doc(alias = "subpixel-layout")]
592 fn connect_subpixel_layout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
593 unsafe extern "C" fn notify_subpixel_layout_trampoline<
594 P: IsA<Monitor>,
595 F: Fn(&P) + 'static,
596 >(
597 this: *mut ffi::GdkMonitor,
598 _param_spec: glib::ffi::gpointer,
599 f: glib::ffi::gpointer,
600 ) {
601 let f: &F = &*(f as *const F);
602 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
603 }
604 unsafe {
605 let f: Box_<F> = Box_::new(f);
606 connect_raw(
607 self.as_ptr() as *mut _,
608 c"notify::subpixel-layout".as_ptr() as *const _,
609 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
610 notify_subpixel_layout_trampoline::<Self, F> as *const (),
611 )),
612 Box_::into_raw(f),
613 )
614 }
615 }
616
617 #[doc(alias = "valid")]
618 fn connect_valid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
619 unsafe extern "C" fn notify_valid_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
620 this: *mut ffi::GdkMonitor,
621 _param_spec: glib::ffi::gpointer,
622 f: glib::ffi::gpointer,
623 ) {
624 let f: &F = &*(f as *const F);
625 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
626 }
627 unsafe {
628 let f: Box_<F> = Box_::new(f);
629 connect_raw(
630 self.as_ptr() as *mut _,
631 c"notify::valid".as_ptr() as *const _,
632 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
633 notify_valid_trampoline::<Self, F> as *const (),
634 )),
635 Box_::into_raw(f),
636 )
637 }
638 }
639
640 #[doc(alias = "width-mm")]
641 fn connect_width_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
642 unsafe extern "C" fn notify_width_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
643 this: *mut ffi::GdkMonitor,
644 _param_spec: glib::ffi::gpointer,
645 f: glib::ffi::gpointer,
646 ) {
647 let f: &F = &*(f as *const F);
648 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
649 }
650 unsafe {
651 let f: Box_<F> = Box_::new(f);
652 connect_raw(
653 self.as_ptr() as *mut _,
654 c"notify::width-mm".as_ptr() as *const _,
655 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
656 notify_width_mm_trampoline::<Self, F> as *const (),
657 )),
658 Box_::into_raw(f),
659 )
660 }
661 }
662}
663
664impl<O: IsA<Monitor>> MonitorExt for O {}