1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// This file was generated by gir (7504fb6) from gir-files (71d73f0)
// DO NOT EDIT

#[cfg(feature = "v3_20")]
use Device;
#[cfg(feature = "v3_22")]
use DeviceTool;
use Display;
#[cfg(feature = "v3_20")]
use SeatCapabilities;
use ffi;
use glib;
#[cfg(feature = "v3_20")]
use glib::object::Downcast;
use glib::object::IsA;
#[cfg(feature = "v3_20")]
use glib::signal::connect;
use glib::translate::*;
#[cfg(feature = "v3_20")]
use glib_ffi;
#[cfg(feature = "v3_20")]
use std::boxed::Box as Box_;
#[cfg(feature = "v3_20")]
use std::mem::transmute;

glib_wrapper! {
    pub struct Seat(Object<ffi::GdkSeat>);

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

pub trait SeatExt {
    #[cfg(feature = "v3_20")]
    fn get_capabilities(&self) -> SeatCapabilities;

    fn get_display(&self) -> Option<Display>;

    #[cfg(feature = "v3_20")]
    fn get_keyboard(&self) -> Option<Device>;

    #[cfg(feature = "v3_20")]
    fn get_pointer(&self) -> Option<Device>;

    #[cfg(feature = "v3_20")]
    fn get_slaves(&self, capabilities: SeatCapabilities) -> Vec<Device>;

    //#[cfg(feature = "v3_20")]
    //fn grab<'a, 'b, 'c, P: Into<Option<&'a Cursor>>, Q: Into<Option<&'b Event>>, R: Into<Option<&'c /*Unimplemented*/SeatGrabPrepareFunc>>, S: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, window: &Window, capabilities: SeatCapabilities, owner_events: bool, cursor: P, event: Q, prepare_func: R, prepare_func_data: S) -> GrabStatus;

    #[cfg(feature = "v3_20")]
    fn ungrab(&self);

    #[cfg(feature = "v3_20")]
    fn connect_device_added<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> u64;

    #[cfg(feature = "v3_20")]
    fn connect_device_removed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> u64;

    #[cfg(feature = "v3_22")]
    fn connect_tool_added<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> u64;

    #[cfg(feature = "v3_22")]
    fn connect_tool_removed<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> u64;
}

impl<O: IsA<Seat> + IsA<glib::object::Object>> SeatExt for O {
    #[cfg(feature = "v3_20")]
    fn get_capabilities(&self) -> SeatCapabilities {
        unsafe {
            from_glib(ffi::gdk_seat_get_capabilities(self.to_glib_none().0))
        }
    }

    fn get_display(&self) -> Option<Display> {
        unsafe {
            from_glib_none(ffi::gdk_seat_get_display(self.to_glib_none().0))
        }
    }

    #[cfg(feature = "v3_20")]
    fn get_keyboard(&self) -> Option<Device> {
        unsafe {
            from_glib_none(ffi::gdk_seat_get_keyboard(self.to_glib_none().0))
        }
    }

    #[cfg(feature = "v3_20")]
    fn get_pointer(&self) -> Option<Device> {
        unsafe {
            from_glib_none(ffi::gdk_seat_get_pointer(self.to_glib_none().0))
        }
    }

    #[cfg(feature = "v3_20")]
    fn get_slaves(&self, capabilities: SeatCapabilities) -> Vec<Device> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gdk_seat_get_slaves(self.to_glib_none().0, capabilities.to_glib()))
        }
    }

    //#[cfg(feature = "v3_20")]
    //fn grab<'a, 'b, 'c, P: Into<Option<&'a Cursor>>, Q: Into<Option<&'b Event>>, R: Into<Option<&'c /*Unimplemented*/SeatGrabPrepareFunc>>, S: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, window: &Window, capabilities: SeatCapabilities, owner_events: bool, cursor: P, event: Q, prepare_func: R, prepare_func_data: S) -> GrabStatus {
    //    unsafe { TODO: call ffi::gdk_seat_grab() }
    //}

    #[cfg(feature = "v3_20")]
    fn ungrab(&self) {
        unsafe {
            ffi::gdk_seat_ungrab(self.to_glib_none().0);
        }
    }

    #[cfg(feature = "v3_20")]
    fn connect_device_added<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> u64 {
        unsafe {
            let f: Box_<Box_<Fn(&Self, &Device) + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "device-added",
                transmute(device_added_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    #[cfg(feature = "v3_20")]
    fn connect_device_removed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> u64 {
        unsafe {
            let f: Box_<Box_<Fn(&Self, &Device) + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "device-removed",
                transmute(device_removed_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    #[cfg(feature = "v3_22")]
    fn connect_tool_added<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> u64 {
        unsafe {
            let f: Box_<Box_<Fn(&Self, &DeviceTool) + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "tool-added",
                transmute(tool_added_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    #[cfg(feature = "v3_22")]
    fn connect_tool_removed<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> u64 {
        unsafe {
            let f: Box_<Box_<Fn(&Self, &DeviceTool) + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "tool-removed",
                transmute(tool_removed_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }
}

#[cfg(feature = "v3_20")]
unsafe extern "C" fn device_added_trampoline<P>(this: *mut ffi::GdkSeat, device: *mut ffi::GdkDevice, f: glib_ffi::gpointer)
where P: IsA<Seat> {
    callback_guard!();
    let f: &Box_<Fn(&P, &Device) + 'static> = transmute(f);
    f(&Seat::from_glib_none(this).downcast_unchecked(), &from_glib_none(device))
}

#[cfg(feature = "v3_20")]
unsafe extern "C" fn device_removed_trampoline<P>(this: *mut ffi::GdkSeat, device: *mut ffi::GdkDevice, f: glib_ffi::gpointer)
where P: IsA<Seat> {
    callback_guard!();
    let f: &Box_<Fn(&P, &Device) + 'static> = transmute(f);
    f(&Seat::from_glib_none(this).downcast_unchecked(), &from_glib_none(device))
}

#[cfg(feature = "v3_22")]
unsafe extern "C" fn tool_added_trampoline<P>(this: *mut ffi::GdkSeat, tool: *mut ffi::GdkDeviceTool, f: glib_ffi::gpointer)
where P: IsA<Seat> {
    callback_guard!();
    let f: &Box_<Fn(&P, &DeviceTool) + 'static> = transmute(f);
    f(&Seat::from_glib_none(this).downcast_unchecked(), &from_glib_none(tool))
}

#[cfg(feature = "v3_22")]
unsafe extern "C" fn tool_removed_trampoline<P>(this: *mut ffi::GdkSeat, tool: *mut ffi::GdkDeviceTool, f: glib_ffi::gpointer)
where P: IsA<Seat> {
    callback_guard!();
    let f: &Box_<Fn(&P, &DeviceTool) + 'static> = transmute(f);
    f(&Seat::from_glib_none(this).downcast_unchecked(), &from_glib_none(tool))
}