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