1use crate::{ffi, DeviceTool, Display, InputSource, ModifierType, Seat, Surface};
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 = "GdkDevice")]
182 pub struct Device(Object<ffi::GdkDevice>);
183
184 match fn {
185 type_ => || ffi::gdk_device_get_type(),
186 }
187}
188
189impl Device {
190 pub const NONE: Option<&'static Device> = None;
191}
192
193impl std::fmt::Display for Device {
194 #[inline]
195 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
196 f.write_str(&DeviceExt::name(self))
197 }
198}
199
200mod sealed {
201 pub trait Sealed {}
202 impl<T: super::IsA<super::Device>> Sealed for T {}
203}
204
205pub trait DeviceExt: IsA<Device> + sealed::Sealed + 'static {
211 #[cfg(feature = "v4_18")]
222 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
223 #[doc(alias = "gdk_device_get_active_layout_index")]
224 #[doc(alias = "get_active_layout_index")]
225 #[doc(alias = "active-layout-index")]
226 fn active_layout_index(&self) -> i32 {
227 unsafe { ffi::gdk_device_get_active_layout_index(self.as_ref().to_glib_none().0) }
228 }
229
230 #[doc(alias = "gdk_device_get_caps_lock_state")]
238 #[doc(alias = "get_caps_lock_state")]
239 #[doc(alias = "caps-lock-state")]
240 fn is_caps_locked(&self) -> bool {
241 unsafe {
242 from_glib(ffi::gdk_device_get_caps_lock_state(
243 self.as_ref().to_glib_none().0,
244 ))
245 }
246 }
247
248 #[doc(alias = "gdk_device_get_device_tool")]
254 #[doc(alias = "get_device_tool")]
255 #[doc(alias = "tool")]
256 fn device_tool(&self) -> Option<DeviceTool> {
257 unsafe {
258 from_glib_none(ffi::gdk_device_get_device_tool(
259 self.as_ref().to_glib_none().0,
260 ))
261 }
262 }
263
264 #[doc(alias = "gdk_device_get_direction")]
277 #[doc(alias = "get_direction")]
278 fn direction(&self) -> pango::Direction {
279 unsafe {
280 from_glib(ffi::gdk_device_get_direction(
281 self.as_ref().to_glib_none().0,
282 ))
283 }
284 }
285
286 #[doc(alias = "gdk_device_get_display")]
292 #[doc(alias = "get_display")]
293 fn display(&self) -> Display {
294 unsafe { from_glib_none(ffi::gdk_device_get_display(self.as_ref().to_glib_none().0)) }
295 }
296
297 #[doc(alias = "gdk_device_get_has_cursor")]
306 #[doc(alias = "get_has_cursor")]
307 #[doc(alias = "has-cursor")]
308 fn has_cursor(&self) -> bool {
309 unsafe {
310 from_glib(ffi::gdk_device_get_has_cursor(
311 self.as_ref().to_glib_none().0,
312 ))
313 }
314 }
315
316 #[cfg(feature = "v4_18")]
325 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
326 #[doc(alias = "gdk_device_get_layout_names")]
327 #[doc(alias = "get_layout_names")]
328 #[doc(alias = "layout-names")]
329 fn layout_names(&self) -> Vec<glib::GString> {
330 unsafe {
331 FromGlibPtrContainer::from_glib_full(ffi::gdk_device_get_layout_names(
332 self.as_ref().to_glib_none().0,
333 ))
334 }
335 }
336
337 #[doc(alias = "gdk_device_get_modifier_state")]
345 #[doc(alias = "get_modifier_state")]
346 #[doc(alias = "modifier-state")]
347 fn modifier_state(&self) -> ModifierType {
348 unsafe {
349 from_glib(ffi::gdk_device_get_modifier_state(
350 self.as_ref().to_glib_none().0,
351 ))
352 }
353 }
354
355 #[doc(alias = "gdk_device_get_name")]
361 #[doc(alias = "get_name")]
362 fn name(&self) -> glib::GString {
363 unsafe { from_glib_none(ffi::gdk_device_get_name(self.as_ref().to_glib_none().0)) }
364 }
365
366 #[doc(alias = "gdk_device_get_num_lock_state")]
374 #[doc(alias = "get_num_lock_state")]
375 #[doc(alias = "num-lock-state")]
376 fn is_num_locked(&self) -> bool {
377 unsafe {
378 from_glib(ffi::gdk_device_get_num_lock_state(
379 self.as_ref().to_glib_none().0,
380 ))
381 }
382 }
383
384 #[doc(alias = "gdk_device_get_num_touches")]
390 #[doc(alias = "get_num_touches")]
391 #[doc(alias = "num-touches")]
392 fn num_touches(&self) -> u32 {
393 unsafe { ffi::gdk_device_get_num_touches(self.as_ref().to_glib_none().0) }
394 }
395
396 #[doc(alias = "gdk_device_get_product_id")]
405 #[doc(alias = "get_product_id")]
406 #[doc(alias = "product-id")]
407 fn product_id(&self) -> Option<glib::GString> {
408 unsafe {
409 from_glib_none(ffi::gdk_device_get_product_id(
410 self.as_ref().to_glib_none().0,
411 ))
412 }
413 }
414
415 #[doc(alias = "gdk_device_get_scroll_lock_state")]
423 #[doc(alias = "get_scroll_lock_state")]
424 #[doc(alias = "scroll-lock-state")]
425 fn is_scroll_locked(&self) -> bool {
426 unsafe {
427 from_glib(ffi::gdk_device_get_scroll_lock_state(
428 self.as_ref().to_glib_none().0,
429 ))
430 }
431 }
432
433 #[doc(alias = "gdk_device_get_seat")]
439 #[doc(alias = "get_seat")]
440 fn seat(&self) -> Seat {
441 unsafe { from_glib_none(ffi::gdk_device_get_seat(self.as_ref().to_glib_none().0)) }
442 }
443
444 #[doc(alias = "gdk_device_get_source")]
450 #[doc(alias = "get_source")]
451 fn source(&self) -> InputSource {
452 unsafe { from_glib(ffi::gdk_device_get_source(self.as_ref().to_glib_none().0)) }
453 }
454
455 #[doc(alias = "gdk_device_get_surface_at_position")]
474 #[doc(alias = "get_surface_at_position")]
475 fn surface_at_position(&self) -> (Option<Surface>, f64, f64) {
476 unsafe {
477 let mut win_x = std::mem::MaybeUninit::uninit();
478 let mut win_y = std::mem::MaybeUninit::uninit();
479 let ret = from_glib_none(ffi::gdk_device_get_surface_at_position(
480 self.as_ref().to_glib_none().0,
481 win_x.as_mut_ptr(),
482 win_y.as_mut_ptr(),
483 ));
484 (ret, win_x.assume_init(), win_y.assume_init())
485 }
486 }
487
488 #[cfg(feature = "v4_2")]
499 #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
500 #[doc(alias = "gdk_device_get_timestamp")]
501 #[doc(alias = "get_timestamp")]
502 fn timestamp(&self) -> u32 {
503 unsafe { ffi::gdk_device_get_timestamp(self.as_ref().to_glib_none().0) }
504 }
505
506 #[doc(alias = "gdk_device_get_vendor_id")]
540 #[doc(alias = "get_vendor_id")]
541 #[doc(alias = "vendor-id")]
542 fn vendor_id(&self) -> Option<glib::GString> {
543 unsafe {
544 from_glib_none(ffi::gdk_device_get_vendor_id(
545 self.as_ref().to_glib_none().0,
546 ))
547 }
548 }
549
550 #[doc(alias = "gdk_device_has_bidi_layouts")]
559 #[doc(alias = "has-bidi-layouts")]
560 fn has_bidi_layouts(&self) -> bool {
561 unsafe {
562 from_glib(ffi::gdk_device_has_bidi_layouts(
563 self.as_ref().to_glib_none().0,
564 ))
565 }
566 }
567
568 #[doc(alias = "n-axes")]
570 fn n_axes(&self) -> u32 {
571 ObjectExt::property(self.as_ref(), "n-axes")
572 }
573
574 fn set_seat<P: IsA<Seat>>(&self, seat: Option<&P>) {
576 ObjectExt::set_property(self.as_ref(), "seat", seat)
577 }
578
579 #[doc(alias = "changed")]
587 fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
588 unsafe extern "C" fn changed_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
589 this: *mut ffi::GdkDevice,
590 f: glib::ffi::gpointer,
591 ) {
592 let f: &F = &*(f as *const F);
593 f(Device::from_glib_borrow(this).unsafe_cast_ref())
594 }
595 unsafe {
596 let f: Box_<F> = Box_::new(f);
597 connect_raw(
598 self.as_ptr() as *mut _,
599 b"changed\0".as_ptr() as *const _,
600 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
601 changed_trampoline::<Self, F> as *const (),
602 )),
603 Box_::into_raw(f),
604 )
605 }
606 }
607
608 #[doc(alias = "tool-changed")]
612 fn connect_tool_changed<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
613 unsafe extern "C" fn tool_changed_trampoline<
614 P: IsA<Device>,
615 F: Fn(&P, &DeviceTool) + 'static,
616 >(
617 this: *mut ffi::GdkDevice,
618 tool: *mut ffi::GdkDeviceTool,
619 f: glib::ffi::gpointer,
620 ) {
621 let f: &F = &*(f as *const F);
622 f(
623 Device::from_glib_borrow(this).unsafe_cast_ref(),
624 &from_glib_borrow(tool),
625 )
626 }
627 unsafe {
628 let f: Box_<F> = Box_::new(f);
629 connect_raw(
630 self.as_ptr() as *mut _,
631 b"tool-changed\0".as_ptr() as *const _,
632 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
633 tool_changed_trampoline::<Self, F> as *const (),
634 )),
635 Box_::into_raw(f),
636 )
637 }
638 }
639
640 #[cfg(feature = "v4_18")]
641 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
642 #[doc(alias = "active-layout-index")]
643 fn connect_active_layout_index_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
644 unsafe extern "C" fn notify_active_layout_index_trampoline<
645 P: IsA<Device>,
646 F: Fn(&P) + 'static,
647 >(
648 this: *mut ffi::GdkDevice,
649 _param_spec: glib::ffi::gpointer,
650 f: glib::ffi::gpointer,
651 ) {
652 let f: &F = &*(f as *const F);
653 f(Device::from_glib_borrow(this).unsafe_cast_ref())
654 }
655 unsafe {
656 let f: Box_<F> = Box_::new(f);
657 connect_raw(
658 self.as_ptr() as *mut _,
659 b"notify::active-layout-index\0".as_ptr() as *const _,
660 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
661 notify_active_layout_index_trampoline::<Self, F> as *const (),
662 )),
663 Box_::into_raw(f),
664 )
665 }
666 }
667
668 #[doc(alias = "caps-lock-state")]
669 fn connect_caps_lock_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
670 unsafe extern "C" fn notify_caps_lock_state_trampoline<
671 P: IsA<Device>,
672 F: Fn(&P) + 'static,
673 >(
674 this: *mut ffi::GdkDevice,
675 _param_spec: glib::ffi::gpointer,
676 f: glib::ffi::gpointer,
677 ) {
678 let f: &F = &*(f as *const F);
679 f(Device::from_glib_borrow(this).unsafe_cast_ref())
680 }
681 unsafe {
682 let f: Box_<F> = Box_::new(f);
683 connect_raw(
684 self.as_ptr() as *mut _,
685 b"notify::caps-lock-state\0".as_ptr() as *const _,
686 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
687 notify_caps_lock_state_trampoline::<Self, F> as *const (),
688 )),
689 Box_::into_raw(f),
690 )
691 }
692 }
693
694 #[doc(alias = "direction")]
695 fn connect_direction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
696 unsafe extern "C" fn notify_direction_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
697 this: *mut ffi::GdkDevice,
698 _param_spec: glib::ffi::gpointer,
699 f: glib::ffi::gpointer,
700 ) {
701 let f: &F = &*(f as *const F);
702 f(Device::from_glib_borrow(this).unsafe_cast_ref())
703 }
704 unsafe {
705 let f: Box_<F> = Box_::new(f);
706 connect_raw(
707 self.as_ptr() as *mut _,
708 b"notify::direction\0".as_ptr() as *const _,
709 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
710 notify_direction_trampoline::<Self, F> as *const (),
711 )),
712 Box_::into_raw(f),
713 )
714 }
715 }
716
717 #[doc(alias = "has-bidi-layouts")]
718 fn connect_has_bidi_layouts_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
719 unsafe extern "C" fn notify_has_bidi_layouts_trampoline<
720 P: IsA<Device>,
721 F: Fn(&P) + 'static,
722 >(
723 this: *mut ffi::GdkDevice,
724 _param_spec: glib::ffi::gpointer,
725 f: glib::ffi::gpointer,
726 ) {
727 let f: &F = &*(f as *const F);
728 f(Device::from_glib_borrow(this).unsafe_cast_ref())
729 }
730 unsafe {
731 let f: Box_<F> = Box_::new(f);
732 connect_raw(
733 self.as_ptr() as *mut _,
734 b"notify::has-bidi-layouts\0".as_ptr() as *const _,
735 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
736 notify_has_bidi_layouts_trampoline::<Self, F> as *const (),
737 )),
738 Box_::into_raw(f),
739 )
740 }
741 }
742
743 #[cfg(feature = "v4_18")]
744 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
745 #[doc(alias = "layout-names")]
746 fn connect_layout_names_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
747 unsafe extern "C" fn notify_layout_names_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
748 this: *mut ffi::GdkDevice,
749 _param_spec: glib::ffi::gpointer,
750 f: glib::ffi::gpointer,
751 ) {
752 let f: &F = &*(f as *const F);
753 f(Device::from_glib_borrow(this).unsafe_cast_ref())
754 }
755 unsafe {
756 let f: Box_<F> = Box_::new(f);
757 connect_raw(
758 self.as_ptr() as *mut _,
759 b"notify::layout-names\0".as_ptr() as *const _,
760 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
761 notify_layout_names_trampoline::<Self, F> as *const (),
762 )),
763 Box_::into_raw(f),
764 )
765 }
766 }
767
768 #[doc(alias = "modifier-state")]
769 fn connect_modifier_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
770 unsafe extern "C" fn notify_modifier_state_trampoline<
771 P: IsA<Device>,
772 F: Fn(&P) + 'static,
773 >(
774 this: *mut ffi::GdkDevice,
775 _param_spec: glib::ffi::gpointer,
776 f: glib::ffi::gpointer,
777 ) {
778 let f: &F = &*(f as *const F);
779 f(Device::from_glib_borrow(this).unsafe_cast_ref())
780 }
781 unsafe {
782 let f: Box_<F> = Box_::new(f);
783 connect_raw(
784 self.as_ptr() as *mut _,
785 b"notify::modifier-state\0".as_ptr() as *const _,
786 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
787 notify_modifier_state_trampoline::<Self, F> as *const (),
788 )),
789 Box_::into_raw(f),
790 )
791 }
792 }
793
794 #[doc(alias = "n-axes")]
795 fn connect_n_axes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
796 unsafe extern "C" fn notify_n_axes_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
797 this: *mut ffi::GdkDevice,
798 _param_spec: glib::ffi::gpointer,
799 f: glib::ffi::gpointer,
800 ) {
801 let f: &F = &*(f as *const F);
802 f(Device::from_glib_borrow(this).unsafe_cast_ref())
803 }
804 unsafe {
805 let f: Box_<F> = Box_::new(f);
806 connect_raw(
807 self.as_ptr() as *mut _,
808 b"notify::n-axes\0".as_ptr() as *const _,
809 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
810 notify_n_axes_trampoline::<Self, F> as *const (),
811 )),
812 Box_::into_raw(f),
813 )
814 }
815 }
816
817 #[doc(alias = "num-lock-state")]
818 fn connect_num_lock_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
819 unsafe extern "C" fn notify_num_lock_state_trampoline<
820 P: IsA<Device>,
821 F: Fn(&P) + 'static,
822 >(
823 this: *mut ffi::GdkDevice,
824 _param_spec: glib::ffi::gpointer,
825 f: glib::ffi::gpointer,
826 ) {
827 let f: &F = &*(f as *const F);
828 f(Device::from_glib_borrow(this).unsafe_cast_ref())
829 }
830 unsafe {
831 let f: Box_<F> = Box_::new(f);
832 connect_raw(
833 self.as_ptr() as *mut _,
834 b"notify::num-lock-state\0".as_ptr() as *const _,
835 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
836 notify_num_lock_state_trampoline::<Self, F> as *const (),
837 )),
838 Box_::into_raw(f),
839 )
840 }
841 }
842
843 #[doc(alias = "scroll-lock-state")]
844 fn connect_scroll_lock_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
845 unsafe extern "C" fn notify_scroll_lock_state_trampoline<
846 P: IsA<Device>,
847 F: Fn(&P) + 'static,
848 >(
849 this: *mut ffi::GdkDevice,
850 _param_spec: glib::ffi::gpointer,
851 f: glib::ffi::gpointer,
852 ) {
853 let f: &F = &*(f as *const F);
854 f(Device::from_glib_borrow(this).unsafe_cast_ref())
855 }
856 unsafe {
857 let f: Box_<F> = Box_::new(f);
858 connect_raw(
859 self.as_ptr() as *mut _,
860 b"notify::scroll-lock-state\0".as_ptr() as *const _,
861 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
862 notify_scroll_lock_state_trampoline::<Self, F> as *const (),
863 )),
864 Box_::into_raw(f),
865 )
866 }
867 }
868
869 #[doc(alias = "seat")]
870 fn connect_seat_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
871 unsafe extern "C" fn notify_seat_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
872 this: *mut ffi::GdkDevice,
873 _param_spec: glib::ffi::gpointer,
874 f: glib::ffi::gpointer,
875 ) {
876 let f: &F = &*(f as *const F);
877 f(Device::from_glib_borrow(this).unsafe_cast_ref())
878 }
879 unsafe {
880 let f: Box_<F> = Box_::new(f);
881 connect_raw(
882 self.as_ptr() as *mut _,
883 b"notify::seat\0".as_ptr() as *const _,
884 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
885 notify_seat_trampoline::<Self, F> as *const (),
886 )),
887 Box_::into_raw(f),
888 )
889 }
890 }
891
892 #[doc(alias = "tool")]
893 fn connect_tool_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
894 unsafe extern "C" fn notify_tool_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
895 this: *mut ffi::GdkDevice,
896 _param_spec: glib::ffi::gpointer,
897 f: glib::ffi::gpointer,
898 ) {
899 let f: &F = &*(f as *const F);
900 f(Device::from_glib_borrow(this).unsafe_cast_ref())
901 }
902 unsafe {
903 let f: Box_<F> = Box_::new(f);
904 connect_raw(
905 self.as_ptr() as *mut _,
906 b"notify::tool\0".as_ptr() as *const _,
907 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
908 notify_tool_trampoline::<Self, F> as *const (),
909 )),
910 Box_::into_raw(f),
911 )
912 }
913 }
914}
915
916impl<O: IsA<Device>> DeviceExt for O {}