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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// 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;
use crate::Device;
#[cfg(any(feature = "v3_22", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_22")))]
use crate::DeviceTool;
use crate::Display;
use crate::Event;
use crate::GrabStatus;
use crate::SeatCapabilities;
use crate::Window;
use glib::object::ObjectType as ObjectType_;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    /// The [`Seat`][crate::Seat] object represents a collection of input devices
    /// that belong to a user.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    #[doc(alias = "GdkSeat")]
    pub struct Seat(Object<ffi::GdkSeat>);

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

impl Seat {
    /// Returns the capabilities this [`Seat`][crate::Seat] currently has.
    ///
    /// # Returns
    ///
    /// the seat capabilities
    #[doc(alias = "gdk_seat_get_capabilities")]
    #[doc(alias = "get_capabilities")]
    pub fn capabilities(&self) -> SeatCapabilities {
        unsafe { from_glib(ffi::gdk_seat_get_capabilities(self.to_glib_none().0)) }
    }

    /// Returns the [`Display`][crate::Display] this seat belongs to.
    ///
    /// # Returns
    ///
    /// a [`Display`][crate::Display]. This object is owned by GTK+
    ///  and must not be freed.
    #[doc(alias = "gdk_seat_get_display")]
    #[doc(alias = "get_display")]
    pub fn display(&self) -> Option<Display> {
        unsafe { from_glib_none(ffi::gdk_seat_get_display(self.to_glib_none().0)) }
    }

    /// Returns the master device that routes keyboard events.
    ///
    /// # Returns
    ///
    /// a master [`Device`][crate::Device] with keyboard
    ///  capabilities. This object is owned by GTK+ and must not be freed.
    #[doc(alias = "gdk_seat_get_keyboard")]
    #[doc(alias = "get_keyboard")]
    pub fn keyboard(&self) -> Option<Device> {
        unsafe { from_glib_none(ffi::gdk_seat_get_keyboard(self.to_glib_none().0)) }
    }

    /// Returns the master device that routes pointer events.
    ///
    /// # Returns
    ///
    /// a master [`Device`][crate::Device] with pointer
    ///  capabilities. This object is owned by GTK+ and must not be freed.
    #[doc(alias = "gdk_seat_get_pointer")]
    #[doc(alias = "get_pointer")]
    pub fn pointer(&self) -> Option<Device> {
        unsafe { from_glib_none(ffi::gdk_seat_get_pointer(self.to_glib_none().0)) }
    }

    /// Returns the slave devices that match the given capabilities.
    /// ## `capabilities`
    /// capabilities to get devices for
    ///
    /// # Returns
    ///
    /// A list of `GdkDevices`.
    ///  The list must be freed with `g_list_free()`, the elements are owned
    ///  by GDK and must not be freed.
    #[doc(alias = "gdk_seat_get_slaves")]
    #[doc(alias = "get_slaves")]
    pub fn slaves(&self, capabilities: SeatCapabilities) -> Vec<Device> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gdk_seat_get_slaves(
                self.to_glib_none().0,
                capabilities.into_glib(),
            ))
        }
    }

    /// Grabs the seat so that all events corresponding to the given `capabilities`
    /// are passed to this application until the seat is ungrabbed with [`ungrab()`][Self::ungrab()],
    /// or the window becomes hidden. This overrides any previous grab on the
    /// seat by this client.
    ///
    /// As a rule of thumb, if a grab is desired over [`SeatCapabilities::POINTER`][crate::SeatCapabilities::POINTER],
    /// all other "pointing" capabilities (eg. [`SeatCapabilities::TOUCH`][crate::SeatCapabilities::TOUCH]) should
    /// be grabbed too, so the user is able to interact with all of those while
    /// the grab holds, you should thus use [`SeatCapabilities::ALL_POINTING`][crate::SeatCapabilities::ALL_POINTING] most
    /// commonly.
    ///
    /// Grabs are used for operations which need complete control over the
    /// events corresponding to the given capabilities. For example in GTK+ this
    /// is used for Drag and Drop operations, popup menus and such.
    ///
    /// Note that if the event mask of a [`Window`][crate::Window] has selected both button press
    /// and button release events, or touch begin and touch end, then a press event
    /// will cause an automatic grab until the button is released, equivalent to a
    /// grab on the window with `owner_events` set to [`true`]. This is done because most
    /// applications expect to receive paired press and release events.
    ///
    /// If you set up anything at the time you take the grab that needs to be
    /// cleaned up when the grab ends, you should handle the [`EventGrabBroken`][crate::EventGrabBroken]
    /// events that are emitted when the grab ends unvoluntarily.
    /// ## `window`
    /// the [`Window`][crate::Window] which will own the grab
    /// ## `capabilities`
    /// capabilities that will be grabbed
    /// ## `owner_events`
    /// if [`false`] then all device events are reported with respect to
    ///  `window` and are only reported if selected by `event_mask`. If
    ///  [`true`] then pointer events for this application are reported
    ///  as normal, but pointer events outside this application are
    ///  reported with respect to `window` and only if selected by
    ///  `event_mask`. In either mode, unreported events are discarded.
    /// ## `cursor`
    /// the cursor to display while the grab is active. If
    ///  this is [`None`] then the normal cursors are used for
    ///  `window` and its descendants, and the cursor for `window` is used
    ///  elsewhere.
    /// ## `event`
    /// the event that is triggering the grab, or [`None`] if none
    ///  is available.
    /// ## `prepare_func`
    /// function to
    ///  prepare the window to be grabbed, it can be [`None`] if `window` is
    ///  visible before this call.
    /// ## `prepare_func_data`
    /// user data to pass to `prepare_func`
    ///
    /// # Returns
    ///
    /// [`GrabStatus::Success`][crate::GrabStatus::Success] if the grab was successful.
    #[doc(alias = "gdk_seat_grab")]
    pub 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 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,
        ) {
            let seat = from_glib_borrow(seat);
            let window = from_glib_borrow(window);
            let callback: *mut Option<&mut dyn (FnMut(&Seat, &Window))> =
                user_data as *const _ as usize 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: &Option<&mut dyn (FnMut(&Seat, &Window))> = &prepare_func_data;
        unsafe {
            from_glib(ffi::gdk_seat_grab(
                self.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 *const _ as usize as *mut _,
            ))
        }
    }

    /// Releases a grab added through [`grab()`][Self::grab()].
    #[doc(alias = "gdk_seat_ungrab")]
    pub fn ungrab(&self) {
        unsafe {
            ffi::gdk_seat_ungrab(self.to_glib_none().0);
        }
    }

    /// The ::device-added signal is emitted when a new input
    /// device is related to this seat.
    /// ## `device`
    /// the newly added [`Device`][crate::Device].
    #[cfg(any(feature = "v3_20", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
    #[doc(alias = "device-added")]
    pub fn connect_device_added<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn device_added_trampoline<F: Fn(&Seat, &Device) + 'static>(
            this: *mut ffi::GdkSeat,
            device: *mut ffi::GdkDevice,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(device))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"device-added\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    device_added_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// The ::device-removed signal is emitted when an
    /// input device is removed (e.g. unplugged).
    /// ## `device`
    /// the just removed [`Device`][crate::Device].
    #[cfg(any(feature = "v3_20", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
    #[doc(alias = "device-removed")]
    pub fn connect_device_removed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn device_removed_trampoline<F: Fn(&Seat, &Device) + 'static>(
            this: *mut ffi::GdkSeat,
            device: *mut ffi::GdkDevice,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(device))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"device-removed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    device_removed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// The ::tool-added signal is emitted whenever a new tool
    /// is made known to the seat. The tool may later be assigned
    /// to a device (i.e. on proximity with a tablet). The device
    /// will emit the `signal::Device::tool-changed` signal accordingly.
    ///
    /// A same tool may be used by several devices.
    /// ## `tool`
    /// the new [`DeviceTool`][crate::DeviceTool] known to the seat
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_22")))]
    #[doc(alias = "tool-added")]
    pub fn connect_tool_added<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn tool_added_trampoline<F: Fn(&Seat, &DeviceTool) + 'static>(
            this: *mut ffi::GdkSeat,
            tool: *mut ffi::GdkDeviceTool,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(tool))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"tool-added\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    tool_added_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// This signal is emitted whenever a tool is no longer known
    /// to this `seat`.
    /// ## `tool`
    /// the just removed [`DeviceTool`][crate::DeviceTool]
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_22")))]
    #[doc(alias = "tool-removed")]
    pub fn connect_tool_removed<F: Fn(&Self, &DeviceTool) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn tool_removed_trampoline<F: Fn(&Seat, &DeviceTool) + 'static>(
            this: *mut ffi::GdkSeat,
            tool: *mut ffi::GdkDeviceTool,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(tool))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"tool-removed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    tool_removed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Seat {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Seat")
    }
}