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")]
76 pub struct Monitor(Object<ffi::GdkMonitor, ffi::GdkMonitorClass>);
77
78 match fn {
79 type_ => || ffi::gdk_monitor_get_type(),
80 }
81}
82
83impl Monitor {
84 pub const NONE: Option<&'static Monitor> = None;
85}
86
87pub trait MonitorExt: IsA<Monitor> + 'static {
93 #[doc(alias = "gdk_monitor_get_display")]
99 #[doc(alias = "get_display")]
100 fn display(&self) -> Option<Display> {
101 unsafe { from_glib_none(ffi::gdk_monitor_get_display(self.as_ref().to_glib_none().0)) }
102 }
103
104 #[doc(alias = "gdk_monitor_get_geometry")]
114 #[doc(alias = "get_geometry")]
115 fn geometry(&self) -> Rectangle {
116 unsafe {
117 let mut geometry = Rectangle::uninitialized();
118 ffi::gdk_monitor_get_geometry(
119 self.as_ref().to_glib_none().0,
120 geometry.to_glib_none_mut().0,
121 );
122 geometry
123 }
124 }
125
126 #[doc(alias = "gdk_monitor_get_height_mm")]
132 #[doc(alias = "get_height_mm")]
133 #[doc(alias = "height-mm")]
134 fn height_mm(&self) -> i32 {
135 unsafe { ffi::gdk_monitor_get_height_mm(self.as_ref().to_glib_none().0) }
136 }
137
138 #[doc(alias = "gdk_monitor_get_manufacturer")]
149 #[doc(alias = "get_manufacturer")]
150 fn manufacturer(&self) -> Option<glib::GString> {
151 unsafe {
152 from_glib_none(ffi::gdk_monitor_get_manufacturer(
153 self.as_ref().to_glib_none().0,
154 ))
155 }
156 }
157
158 #[doc(alias = "gdk_monitor_get_model")]
164 #[doc(alias = "get_model")]
165 fn model(&self) -> Option<glib::GString> {
166 unsafe { from_glib_none(ffi::gdk_monitor_get_model(self.as_ref().to_glib_none().0)) }
167 }
168
169 #[doc(alias = "gdk_monitor_get_refresh_rate")]
178 #[doc(alias = "get_refresh_rate")]
179 #[doc(alias = "refresh-rate")]
180 fn refresh_rate(&self) -> i32 {
181 unsafe { ffi::gdk_monitor_get_refresh_rate(self.as_ref().to_glib_none().0) }
182 }
183
184 #[doc(alias = "gdk_monitor_get_scale_factor")]
196 #[doc(alias = "get_scale_factor")]
197 #[doc(alias = "scale-factor")]
198 fn scale_factor(&self) -> i32 {
199 unsafe { ffi::gdk_monitor_get_scale_factor(self.as_ref().to_glib_none().0) }
200 }
201
202 #[doc(alias = "gdk_monitor_get_subpixel_layout")]
209 #[doc(alias = "get_subpixel_layout")]
210 #[doc(alias = "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 #[doc(alias = "width-mm")]
227 fn width_mm(&self) -> i32 {
228 unsafe { ffi::gdk_monitor_get_width_mm(self.as_ref().to_glib_none().0) }
229 }
230
231 #[doc(alias = "gdk_monitor_get_workarea")]
251 #[doc(alias = "get_workarea")]
252 fn workarea(&self) -> Rectangle {
253 unsafe {
254 let mut workarea = Rectangle::uninitialized();
255 ffi::gdk_monitor_get_workarea(
256 self.as_ref().to_glib_none().0,
257 workarea.to_glib_none_mut().0,
258 );
259 workarea
260 }
261 }
262
263 #[doc(alias = "gdk_monitor_is_primary")]
270 fn is_primary(&self) -> bool {
271 unsafe { from_glib(ffi::gdk_monitor_is_primary(self.as_ref().to_glib_none().0)) }
272 }
273
274 #[doc(alias = "invalidate")]
275 fn connect_invalidate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
276 unsafe extern "C" fn invalidate_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
277 this: *mut ffi::GdkMonitor,
278 f: glib::ffi::gpointer,
279 ) {
280 unsafe {
281 let f: &F = &*(f as *const F);
282 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
283 }
284 }
285 unsafe {
286 let f: Box_<F> = Box_::new(f);
287 connect_raw(
288 self.as_ptr() as *mut _,
289 c"invalidate".as_ptr(),
290 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291 invalidate_trampoline::<Self, F> as *const (),
292 )),
293 Box_::into_raw(f),
294 )
295 }
296 }
297
298 #[doc(alias = "geometry")]
299 fn connect_geometry_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
300 unsafe extern "C" fn notify_geometry_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
301 this: *mut ffi::GdkMonitor,
302 _param_spec: glib::ffi::gpointer,
303 f: glib::ffi::gpointer,
304 ) {
305 unsafe {
306 let f: &F = &*(f as *const F);
307 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
308 }
309 }
310 unsafe {
311 let f: Box_<F> = Box_::new(f);
312 connect_raw(
313 self.as_ptr() as *mut _,
314 c"notify::geometry".as_ptr(),
315 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
316 notify_geometry_trampoline::<Self, F> as *const (),
317 )),
318 Box_::into_raw(f),
319 )
320 }
321 }
322
323 #[doc(alias = "height-mm")]
324 fn connect_height_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
325 unsafe extern "C" fn notify_height_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
326 this: *mut ffi::GdkMonitor,
327 _param_spec: glib::ffi::gpointer,
328 f: glib::ffi::gpointer,
329 ) {
330 unsafe {
331 let f: &F = &*(f as *const F);
332 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
333 }
334 }
335 unsafe {
336 let f: Box_<F> = Box_::new(f);
337 connect_raw(
338 self.as_ptr() as *mut _,
339 c"notify::height-mm".as_ptr(),
340 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
341 notify_height_mm_trampoline::<Self, F> as *const (),
342 )),
343 Box_::into_raw(f),
344 )
345 }
346 }
347
348 #[doc(alias = "manufacturer")]
349 fn connect_manufacturer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
350 unsafe extern "C" fn notify_manufacturer_trampoline<
351 P: IsA<Monitor>,
352 F: Fn(&P) + 'static,
353 >(
354 this: *mut ffi::GdkMonitor,
355 _param_spec: glib::ffi::gpointer,
356 f: glib::ffi::gpointer,
357 ) {
358 unsafe {
359 let f: &F = &*(f as *const F);
360 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
361 }
362 }
363 unsafe {
364 let f: Box_<F> = Box_::new(f);
365 connect_raw(
366 self.as_ptr() as *mut _,
367 c"notify::manufacturer".as_ptr(),
368 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
369 notify_manufacturer_trampoline::<Self, F> as *const (),
370 )),
371 Box_::into_raw(f),
372 )
373 }
374 }
375
376 #[doc(alias = "model")]
377 fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
378 unsafe extern "C" fn notify_model_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
379 this: *mut ffi::GdkMonitor,
380 _param_spec: glib::ffi::gpointer,
381 f: glib::ffi::gpointer,
382 ) {
383 unsafe {
384 let f: &F = &*(f as *const F);
385 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
386 }
387 }
388 unsafe {
389 let f: Box_<F> = Box_::new(f);
390 connect_raw(
391 self.as_ptr() as *mut _,
392 c"notify::model".as_ptr(),
393 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
394 notify_model_trampoline::<Self, F> as *const (),
395 )),
396 Box_::into_raw(f),
397 )
398 }
399 }
400
401 #[doc(alias = "refresh-rate")]
402 fn connect_refresh_rate_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
403 unsafe extern "C" fn notify_refresh_rate_trampoline<
404 P: IsA<Monitor>,
405 F: Fn(&P) + 'static,
406 >(
407 this: *mut ffi::GdkMonitor,
408 _param_spec: glib::ffi::gpointer,
409 f: glib::ffi::gpointer,
410 ) {
411 unsafe {
412 let f: &F = &*(f as *const F);
413 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
414 }
415 }
416 unsafe {
417 let f: Box_<F> = Box_::new(f);
418 connect_raw(
419 self.as_ptr() as *mut _,
420 c"notify::refresh-rate".as_ptr(),
421 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
422 notify_refresh_rate_trampoline::<Self, F> as *const (),
423 )),
424 Box_::into_raw(f),
425 )
426 }
427 }
428
429 #[doc(alias = "scale-factor")]
430 fn connect_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
431 unsafe extern "C" fn notify_scale_factor_trampoline<
432 P: IsA<Monitor>,
433 F: Fn(&P) + 'static,
434 >(
435 this: *mut ffi::GdkMonitor,
436 _param_spec: glib::ffi::gpointer,
437 f: glib::ffi::gpointer,
438 ) {
439 unsafe {
440 let f: &F = &*(f as *const F);
441 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
442 }
443 }
444 unsafe {
445 let f: Box_<F> = Box_::new(f);
446 connect_raw(
447 self.as_ptr() as *mut _,
448 c"notify::scale-factor".as_ptr(),
449 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
450 notify_scale_factor_trampoline::<Self, F> as *const (),
451 )),
452 Box_::into_raw(f),
453 )
454 }
455 }
456
457 #[doc(alias = "subpixel-layout")]
458 fn connect_subpixel_layout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
459 unsafe extern "C" fn notify_subpixel_layout_trampoline<
460 P: IsA<Monitor>,
461 F: Fn(&P) + 'static,
462 >(
463 this: *mut ffi::GdkMonitor,
464 _param_spec: glib::ffi::gpointer,
465 f: glib::ffi::gpointer,
466 ) {
467 unsafe {
468 let f: &F = &*(f as *const F);
469 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
470 }
471 }
472 unsafe {
473 let f: Box_<F> = Box_::new(f);
474 connect_raw(
475 self.as_ptr() as *mut _,
476 c"notify::subpixel-layout".as_ptr(),
477 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
478 notify_subpixel_layout_trampoline::<Self, F> as *const (),
479 )),
480 Box_::into_raw(f),
481 )
482 }
483 }
484
485 #[doc(alias = "width-mm")]
486 fn connect_width_mm_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
487 unsafe extern "C" fn notify_width_mm_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
488 this: *mut ffi::GdkMonitor,
489 _param_spec: glib::ffi::gpointer,
490 f: glib::ffi::gpointer,
491 ) {
492 unsafe {
493 let f: &F = &*(f as *const F);
494 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
495 }
496 }
497 unsafe {
498 let f: Box_<F> = Box_::new(f);
499 connect_raw(
500 self.as_ptr() as *mut _,
501 c"notify::width-mm".as_ptr(),
502 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
503 notify_width_mm_trampoline::<Self, F> as *const (),
504 )),
505 Box_::into_raw(f),
506 )
507 }
508 }
509
510 #[doc(alias = "workarea")]
511 fn connect_workarea_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
512 unsafe extern "C" fn notify_workarea_trampoline<P: IsA<Monitor>, F: Fn(&P) + 'static>(
513 this: *mut ffi::GdkMonitor,
514 _param_spec: glib::ffi::gpointer,
515 f: glib::ffi::gpointer,
516 ) {
517 unsafe {
518 let f: &F = &*(f as *const F);
519 f(Monitor::from_glib_borrow(this).unsafe_cast_ref())
520 }
521 }
522 unsafe {
523 let f: Box_<F> = Box_::new(f);
524 connect_raw(
525 self.as_ptr() as *mut _,
526 c"notify::workarea".as_ptr(),
527 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
528 notify_workarea_trampoline::<Self, F> as *const (),
529 )),
530 Box_::into_raw(f),
531 )
532 }
533 }
534}
535
536impl<O: IsA<Monitor>> MonitorExt for O {}