gdk 0.19.0

Rust bindings for the GDK 3 library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{
    Cursor, Device, DeviceTool, Display, Event, GrabStatus, SeatCapabilities, Window, ffi,
};
use glib::{
    object::ObjectType as _,
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "GdkSeat")]
    pub struct Seat(Object<ffi::GdkSeat>);

    match fn {
        type_ => || ffi::gdk_seat_get_type(),
    }
}

impl Seat {
    pub const NONE: Option<&'static Seat> = None;
}

pub trait SeatExt: IsA<Seat> + 'static {
    #[doc(alias = "gdk_seat_get_capabilities")]
    #[doc(alias = "get_capabilities")]
    fn capabilities(&self) -> SeatCapabilities {
        unsafe {
            from_glib(ffi::gdk_seat_get_capabilities(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gdk_seat_get_display")]
    #[doc(alias = "get_display")]
    fn display(&self) -> Option<Display> {
        unsafe { from_glib_none(ffi::gdk_seat_get_display(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "gdk_seat_get_keyboard")]
    #[doc(alias = "get_keyboard")]
    fn keyboard(&self) -> Option<Device> {
        unsafe { from_glib_none(ffi::gdk_seat_get_keyboard(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "gdk_seat_get_pointer")]
    #[doc(alias = "get_pointer")]
    fn pointer(&self) -> Option<Device> {
        unsafe { from_glib_none(ffi::gdk_seat_get_pointer(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "gdk_seat_get_slaves")]
    #[doc(alias = "get_slaves")]
    fn slaves(&self, capabilities: SeatCapabilities) -> Vec<Device> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gdk_seat_get_slaves(
                self.as_ref().to_glib_none().0,
                capabilities.into_glib(),
            ))
        }
    }

    #[doc(alias = "gdk_seat_grab")]
    fn grab(
        &self,
        window: &Window,
        capabilities: SeatCapabilities,
        owner_events: bool,
        cursor: Option<&Cursor>,
        event: Option<&Event>,
        prepare_func: Option<&mut dyn FnMut(&Seat, &Window)>,
    ) -> GrabStatus {
        let mut prepare_func_data: Option<&mut dyn FnMut(&Seat, &Window)> = prepare_func;
        unsafe extern "C" fn prepare_func_func(
            seat: *mut ffi::GdkSeat,
            window: *mut ffi::GdkWindow,
            user_data: glib::ffi::gpointer,
        ) {
            unsafe {
                let seat = from_glib_borrow(seat);
                let window = from_glib_borrow(window);
                let callback = user_data as *mut Option<&mut dyn FnMut(&Seat, &Window)>;
                if let Some(ref mut callback) = *callback {
                    callback(&seat, &window)
                } else {
                    panic!("cannot get closure...")
                }
            }
        }
        let prepare_func = if prepare_func_data.is_some() {
            Some(prepare_func_func as _)
        } else {
            None
        };
        let super_callback0: &mut Option<&mut dyn FnMut(&Seat, &Window)> = &mut prepare_func_data;
        unsafe {
            from_glib(ffi::gdk_seat_grab(
                self.as_ref().to_glib_none().0,
                window.to_glib_none().0,
                capabilities.into_glib(),
                owner_events.into_glib(),
                cursor.to_glib_none().0,
                event.to_glib_none().0,
                prepare_func,
                super_callback0 as *mut _ as *mut _,
            ))
        }
    }

    #[doc(alias = "gdk_seat_ungrab")]
    fn ungrab(&self) {
        unsafe {
            ffi::gdk_seat_ungrab(self.as_ref().to_glib_none().0);
        }
    }

    #[doc(alias = "device-added")]
    fn connect_device_added<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn device_added_trampoline<P: IsA<Seat>, F: Fn(&P, &Device) + 'static>(
            this: *mut ffi::GdkSeat,
            device: *mut ffi::GdkDevice,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(
                    Seat::from_glib_borrow(this).unsafe_cast_ref(),
                    &from_glib_borrow(device),
                )
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"device-added".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    device_added_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "device-removed")]
    fn connect_device_removed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn device_removed_trampoline<
            P: IsA<Seat>,
            F: Fn(&P, &Device) + 'static,
        >(
            this: *mut ffi::GdkSeat,
            device: *mut ffi::GdkDevice,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(
                    Seat::from_glib_borrow(this).unsafe_cast_ref(),
                    &from_glib_borrow(device),
                )
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"device-removed".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    device_removed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "tool-added")]
    fn connect_tool_added<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn tool_added_trampoline<
            P: IsA<Seat>,
            F: Fn(&P, &DeviceTool) + 'static,
        >(
            this: *mut ffi::GdkSeat,
            tool: *mut ffi::GdkDeviceTool,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(
                    Seat::from_glib_borrow(this).unsafe_cast_ref(),
                    &from_glib_borrow(tool),
                )
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"tool-added".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    tool_added_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "tool-removed")]
    fn connect_tool_removed<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn tool_removed_trampoline<
            P: IsA<Seat>,
            F: Fn(&P, &DeviceTool) + 'static,
        >(
            this: *mut ffi::GdkSeat,
            tool: *mut ffi::GdkDeviceTool,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(
                    Seat::from_glib_borrow(this).unsafe_cast_ref(),
                    &from_glib_borrow(tool),
                )
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"tool-removed".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    tool_removed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<Seat>> SeatExt for O {}