gdk/auto/
device.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use gdk_sys;
6use glib::object::IsA;
7use glib::object::ObjectType as ObjectType_;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::GString;
12use glib::StaticType;
13use glib::Value;
14use glib_sys;
15use gobject_sys;
16use std::boxed::Box as Box_;
17use std::fmt;
18use std::mem;
19use std::mem::transmute;
20use std::ptr;
21use Atom;
22#[cfg(any(feature = "v3_22", feature = "dox"))]
23use AxisFlags;
24use AxisUse;
25use Cursor;
26use DeviceManager;
27#[cfg(any(feature = "v3_22", feature = "dox"))]
28use DeviceTool;
29use DeviceType;
30use Display;
31use EventMask;
32use GrabOwnership;
33use GrabStatus;
34use InputMode;
35use InputSource;
36use ModifierType;
37use Screen;
38#[cfg(any(feature = "v3_20", feature = "dox"))]
39use Seat;
40use Window;
41
42glib_wrapper! {
43    pub struct Device(Object<gdk_sys::GdkDevice, DeviceClass>);
44
45    match fn {
46        get_type => || gdk_sys::gdk_device_get_type(),
47    }
48}
49
50impl Device {
51    pub fn get_associated_device(&self) -> Option<Device> {
52        unsafe {
53            from_glib_none(gdk_sys::gdk_device_get_associated_device(
54                self.to_glib_none().0,
55            ))
56        }
57    }
58
59    #[cfg(any(feature = "v3_22", feature = "dox"))]
60    pub fn get_axes(&self) -> AxisFlags {
61        unsafe { from_glib(gdk_sys::gdk_device_get_axes(self.to_glib_none().0)) }
62    }
63
64    //pub fn get_axis(&self, axes: &[f64], use_: AxisUse) -> Option<f64> {
65    //    unsafe { TODO: call gdk_sys:gdk_device_get_axis() }
66    //}
67
68    pub fn get_axis_use(&self, index_: u32) -> AxisUse {
69        unsafe {
70            from_glib(gdk_sys::gdk_device_get_axis_use(
71                self.to_glib_none().0,
72                index_,
73            ))
74        }
75    }
76
77    //pub fn get_axis_value(&self, axes: &[f64], axis_label: &Atom) -> Option<f64> {
78    //    unsafe { TODO: call gdk_sys:gdk_device_get_axis_value() }
79    //}
80
81    pub fn get_device_type(&self) -> DeviceType {
82        unsafe { from_glib(gdk_sys::gdk_device_get_device_type(self.to_glib_none().0)) }
83    }
84
85    pub fn get_display(&self) -> Display {
86        unsafe { from_glib_none(gdk_sys::gdk_device_get_display(self.to_glib_none().0)) }
87    }
88
89    pub fn get_has_cursor(&self) -> bool {
90        unsafe { from_glib(gdk_sys::gdk_device_get_has_cursor(self.to_glib_none().0)) }
91    }
92
93    //pub fn get_history<P: IsA<Window>>(&self, window: &P, start: u32, stop: u32, events: /*Ignored*/Vec<TimeCoord>) -> Option<i32> {
94    //    unsafe { TODO: call gdk_sys:gdk_device_get_history() }
95    //}
96
97    pub fn get_key(&self, index_: u32) -> Option<(u32, ModifierType)> {
98        unsafe {
99            let mut keyval = mem::uninitialized();
100            let mut modifiers = mem::uninitialized();
101            let ret = from_glib(gdk_sys::gdk_device_get_key(
102                self.to_glib_none().0,
103                index_,
104                &mut keyval,
105                &mut modifiers,
106            ));
107            if ret {
108                Some((keyval, from_glib(modifiers)))
109            } else {
110                None
111            }
112        }
113    }
114
115    pub fn get_last_event_window(&self) -> Option<Window> {
116        unsafe {
117            from_glib_none(gdk_sys::gdk_device_get_last_event_window(
118                self.to_glib_none().0,
119            ))
120        }
121    }
122
123    pub fn get_mode(&self) -> InputMode {
124        unsafe { from_glib(gdk_sys::gdk_device_get_mode(self.to_glib_none().0)) }
125    }
126
127    pub fn get_n_axes(&self) -> i32 {
128        unsafe { gdk_sys::gdk_device_get_n_axes(self.to_glib_none().0) }
129    }
130
131    pub fn get_n_keys(&self) -> i32 {
132        unsafe { gdk_sys::gdk_device_get_n_keys(self.to_glib_none().0) }
133    }
134
135    pub fn get_name(&self) -> Option<GString> {
136        unsafe { from_glib_none(gdk_sys::gdk_device_get_name(self.to_glib_none().0)) }
137    }
138
139    pub fn get_position(&self) -> (Screen, i32, i32) {
140        unsafe {
141            let mut screen = ptr::null_mut();
142            let mut x = mem::uninitialized();
143            let mut y = mem::uninitialized();
144            gdk_sys::gdk_device_get_position(self.to_glib_none().0, &mut screen, &mut x, &mut y);
145            (from_glib_none(screen), x, y)
146        }
147    }
148
149    pub fn get_position_double(&self) -> (Screen, f64, f64) {
150        unsafe {
151            let mut screen = ptr::null_mut();
152            let mut x = mem::uninitialized();
153            let mut y = mem::uninitialized();
154            gdk_sys::gdk_device_get_position_double(
155                self.to_glib_none().0,
156                &mut screen,
157                &mut x,
158                &mut y,
159            );
160            (from_glib_none(screen), x, y)
161        }
162    }
163
164    #[cfg(any(feature = "v3_16", feature = "dox"))]
165    pub fn get_product_id(&self) -> Option<GString> {
166        unsafe { from_glib_none(gdk_sys::gdk_device_get_product_id(self.to_glib_none().0)) }
167    }
168
169    #[cfg(any(feature = "v3_20", feature = "dox"))]
170    pub fn get_seat(&self) -> Option<Seat> {
171        unsafe { from_glib_none(gdk_sys::gdk_device_get_seat(self.to_glib_none().0)) }
172    }
173
174    pub fn get_source(&self) -> InputSource {
175        unsafe { from_glib(gdk_sys::gdk_device_get_source(self.to_glib_none().0)) }
176    }
177
178    //pub fn get_state<P: IsA<Window>>(&self, window: &P, axes: &[f64]) -> ModifierType {
179    //    unsafe { TODO: call gdk_sys:gdk_device_get_state() }
180    //}
181
182    #[cfg(any(feature = "v3_16", feature = "dox"))]
183    pub fn get_vendor_id(&self) -> Option<GString> {
184        unsafe { from_glib_none(gdk_sys::gdk_device_get_vendor_id(self.to_glib_none().0)) }
185    }
186
187    pub fn get_window_at_position(&self) -> (Option<Window>, i32, i32) {
188        unsafe {
189            let mut win_x = mem::uninitialized();
190            let mut win_y = mem::uninitialized();
191            let ret = from_glib_none(gdk_sys::gdk_device_get_window_at_position(
192                self.to_glib_none().0,
193                &mut win_x,
194                &mut win_y,
195            ));
196            (ret, win_x, win_y)
197        }
198    }
199
200    pub fn get_window_at_position_double(&self) -> (Option<Window>, f64, f64) {
201        unsafe {
202            let mut win_x = mem::uninitialized();
203            let mut win_y = mem::uninitialized();
204            let ret = from_glib_none(gdk_sys::gdk_device_get_window_at_position_double(
205                self.to_glib_none().0,
206                &mut win_x,
207                &mut win_y,
208            ));
209            (ret, win_x, win_y)
210        }
211    }
212
213    #[cfg_attr(feature = "v3_20", deprecated)]
214    pub fn grab<P: IsA<Window>>(
215        &self,
216        window: &P,
217        grab_ownership: GrabOwnership,
218        owner_events: bool,
219        event_mask: EventMask,
220        cursor: Option<&Cursor>,
221        time_: u32,
222    ) -> GrabStatus {
223        unsafe {
224            from_glib(gdk_sys::gdk_device_grab(
225                self.to_glib_none().0,
226                window.as_ref().to_glib_none().0,
227                grab_ownership.to_glib(),
228                owner_events.to_glib(),
229                event_mask.to_glib(),
230                cursor.to_glib_none().0,
231                time_,
232            ))
233        }
234    }
235
236    pub fn list_axes(&self) -> Vec<Atom> {
237        unsafe {
238            FromGlibPtrContainer::from_glib_container(gdk_sys::gdk_device_list_axes(
239                self.to_glib_none().0,
240            ))
241        }
242    }
243
244    pub fn list_slave_devices(&self) -> Vec<Device> {
245        unsafe {
246            FromGlibPtrContainer::from_glib_container(gdk_sys::gdk_device_list_slave_devices(
247                self.to_glib_none().0,
248            ))
249        }
250    }
251
252    pub fn set_axis_use(&self, index_: u32, use_: AxisUse) {
253        unsafe {
254            gdk_sys::gdk_device_set_axis_use(self.to_glib_none().0, index_, use_.to_glib());
255        }
256    }
257
258    pub fn set_key(&self, index_: u32, keyval: u32, modifiers: ModifierType) {
259        unsafe {
260            gdk_sys::gdk_device_set_key(self.to_glib_none().0, index_, keyval, modifiers.to_glib());
261        }
262    }
263
264    pub fn set_mode(&self, mode: InputMode) -> bool {
265        unsafe {
266            from_glib(gdk_sys::gdk_device_set_mode(
267                self.to_glib_none().0,
268                mode.to_glib(),
269            ))
270        }
271    }
272
273    #[cfg_attr(feature = "v3_20", deprecated)]
274    pub fn ungrab(&self, time_: u32) {
275        unsafe {
276            gdk_sys::gdk_device_ungrab(self.to_glib_none().0, time_);
277        }
278    }
279
280    pub fn warp(&self, screen: &Screen, x: i32, y: i32) {
281        unsafe {
282            gdk_sys::gdk_device_warp(self.to_glib_none().0, screen.to_glib_none().0, x, y);
283        }
284    }
285
286    pub fn get_property_device_manager(&self) -> Option<DeviceManager> {
287        unsafe {
288            let mut value = Value::from_type(<DeviceManager as StaticType>::static_type());
289            gobject_sys::g_object_get_property(
290                self.as_ptr() as *mut gobject_sys::GObject,
291                b"device-manager\0".as_ptr() as *const _,
292                value.to_glib_none_mut().0,
293            );
294            value.get()
295        }
296    }
297
298    pub fn get_property_input_mode(&self) -> InputMode {
299        unsafe {
300            let mut value = Value::from_type(<InputMode as StaticType>::static_type());
301            gobject_sys::g_object_get_property(
302                self.as_ptr() as *mut gobject_sys::GObject,
303                b"input-mode\0".as_ptr() as *const _,
304                value.to_glib_none_mut().0,
305            );
306            value.get().unwrap()
307        }
308    }
309
310    pub fn set_property_input_mode(&self, input_mode: InputMode) {
311        unsafe {
312            gobject_sys::g_object_set_property(
313                self.as_ptr() as *mut gobject_sys::GObject,
314                b"input-mode\0".as_ptr() as *const _,
315                Value::from(&input_mode).to_glib_none().0,
316            );
317        }
318    }
319
320    pub fn get_property_input_source(&self) -> InputSource {
321        unsafe {
322            let mut value = Value::from_type(<InputSource as StaticType>::static_type());
323            gobject_sys::g_object_get_property(
324                self.as_ptr() as *mut gobject_sys::GObject,
325                b"input-source\0".as_ptr() as *const _,
326                value.to_glib_none_mut().0,
327            );
328            value.get().unwrap()
329        }
330    }
331
332    #[cfg(any(feature = "v3_20", feature = "dox"))]
333    pub fn get_property_num_touches(&self) -> u32 {
334        unsafe {
335            let mut value = Value::from_type(<u32 as StaticType>::static_type());
336            gobject_sys::g_object_get_property(
337                self.as_ptr() as *mut gobject_sys::GObject,
338                b"num-touches\0".as_ptr() as *const _,
339                value.to_glib_none_mut().0,
340            );
341            value.get().unwrap()
342        }
343    }
344
345    #[cfg(any(feature = "v3_20", feature = "dox"))]
346    pub fn set_property_seat(&self, seat: Option<&Seat>) {
347        unsafe {
348            gobject_sys::g_object_set_property(
349                self.as_ptr() as *mut gobject_sys::GObject,
350                b"seat\0".as_ptr() as *const _,
351                Value::from(seat).to_glib_none().0,
352            );
353        }
354    }
355
356    #[cfg(any(feature = "v3_22", feature = "dox"))]
357    pub fn get_property_tool(&self) -> Option<DeviceTool> {
358        unsafe {
359            let mut value = Value::from_type(<DeviceTool as StaticType>::static_type());
360            gobject_sys::g_object_get_property(
361                self.as_ptr() as *mut gobject_sys::GObject,
362                b"tool\0".as_ptr() as *const _,
363                value.to_glib_none_mut().0,
364            );
365            value.get()
366        }
367    }
368
369    pub fn get_property_type(&self) -> DeviceType {
370        unsafe {
371            let mut value = Value::from_type(<DeviceType as StaticType>::static_type());
372            gobject_sys::g_object_get_property(
373                self.as_ptr() as *mut gobject_sys::GObject,
374                b"type\0".as_ptr() as *const _,
375                value.to_glib_none_mut().0,
376            );
377            value.get().unwrap()
378        }
379    }
380
381    //pub fn free_history(events: /*Ignored*/&[&TimeCoord]) {
382    //    unsafe { TODO: call gdk_sys:gdk_device_free_history() }
383    //}
384
385    #[cfg_attr(feature = "v3_16", deprecated)]
386    pub fn grab_info_libgtk_only(display: &Display, device: &Device) -> Option<(Window, bool)> {
387        skip_assert_initialized!();
388        unsafe {
389            let mut grab_window = ptr::null_mut();
390            let mut owner_events = mem::uninitialized();
391            let ret = from_glib(gdk_sys::gdk_device_grab_info_libgtk_only(
392                display.to_glib_none().0,
393                device.to_glib_none().0,
394                &mut grab_window,
395                &mut owner_events,
396            ));
397            if ret {
398                Some((from_glib_none(grab_window), from_glib(owner_events)))
399            } else {
400                None
401            }
402        }
403    }
404
405    pub fn connect_changed<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
406        unsafe extern "C" fn changed_trampoline<F: Fn(&Device) + 'static>(
407            this: *mut gdk_sys::GdkDevice,
408            f: glib_sys::gpointer,
409        ) {
410            let f: &F = &*(f as *const F);
411            f(&from_glib_borrow(this))
412        }
413        unsafe {
414            let f: Box_<F> = Box_::new(f);
415            connect_raw(
416                self.as_ptr() as *mut _,
417                b"changed\0".as_ptr() as *const _,
418                Some(transmute(changed_trampoline::<F> as usize)),
419                Box_::into_raw(f),
420            )
421        }
422    }
423
424    #[cfg(any(feature = "v3_22", feature = "dox"))]
425    pub fn connect_tool_changed<F: Fn(&Device, &DeviceTool) + 'static>(
426        &self,
427        f: F,
428    ) -> SignalHandlerId {
429        unsafe extern "C" fn tool_changed_trampoline<F: Fn(&Device, &DeviceTool) + 'static>(
430            this: *mut gdk_sys::GdkDevice,
431            tool: *mut gdk_sys::GdkDeviceTool,
432            f: glib_sys::gpointer,
433        ) {
434            let f: &F = &*(f as *const F);
435            f(&from_glib_borrow(this), &from_glib_borrow(tool))
436        }
437        unsafe {
438            let f: Box_<F> = Box_::new(f);
439            connect_raw(
440                self.as_ptr() as *mut _,
441                b"tool-changed\0".as_ptr() as *const _,
442                Some(transmute(tool_changed_trampoline::<F> as usize)),
443                Box_::into_raw(f),
444            )
445        }
446    }
447
448    pub fn connect_property_associated_device_notify<F: Fn(&Device) + 'static>(
449        &self,
450        f: F,
451    ) -> SignalHandlerId {
452        unsafe extern "C" fn notify_associated_device_trampoline<F: Fn(&Device) + 'static>(
453            this: *mut gdk_sys::GdkDevice,
454            _param_spec: glib_sys::gpointer,
455            f: glib_sys::gpointer,
456        ) {
457            let f: &F = &*(f as *const F);
458            f(&from_glib_borrow(this))
459        }
460        unsafe {
461            let f: Box_<F> = Box_::new(f);
462            connect_raw(
463                self.as_ptr() as *mut _,
464                b"notify::associated-device\0".as_ptr() as *const _,
465                Some(transmute(notify_associated_device_trampoline::<F> as usize)),
466                Box_::into_raw(f),
467            )
468        }
469    }
470
471    #[cfg(any(feature = "v3_22", feature = "dox"))]
472    pub fn connect_property_axes_notify<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
473        unsafe extern "C" fn notify_axes_trampoline<F: Fn(&Device) + 'static>(
474            this: *mut gdk_sys::GdkDevice,
475            _param_spec: glib_sys::gpointer,
476            f: glib_sys::gpointer,
477        ) {
478            let f: &F = &*(f as *const F);
479            f(&from_glib_borrow(this))
480        }
481        unsafe {
482            let f: Box_<F> = Box_::new(f);
483            connect_raw(
484                self.as_ptr() as *mut _,
485                b"notify::axes\0".as_ptr() as *const _,
486                Some(transmute(notify_axes_trampoline::<F> as usize)),
487                Box_::into_raw(f),
488            )
489        }
490    }
491
492    pub fn connect_property_input_mode_notify<F: Fn(&Device) + 'static>(
493        &self,
494        f: F,
495    ) -> SignalHandlerId {
496        unsafe extern "C" fn notify_input_mode_trampoline<F: Fn(&Device) + 'static>(
497            this: *mut gdk_sys::GdkDevice,
498            _param_spec: glib_sys::gpointer,
499            f: glib_sys::gpointer,
500        ) {
501            let f: &F = &*(f as *const F);
502            f(&from_glib_borrow(this))
503        }
504        unsafe {
505            let f: Box_<F> = Box_::new(f);
506            connect_raw(
507                self.as_ptr() as *mut _,
508                b"notify::input-mode\0".as_ptr() as *const _,
509                Some(transmute(notify_input_mode_trampoline::<F> as usize)),
510                Box_::into_raw(f),
511            )
512        }
513    }
514
515    pub fn connect_property_n_axes_notify<F: Fn(&Device) + 'static>(
516        &self,
517        f: F,
518    ) -> SignalHandlerId {
519        unsafe extern "C" fn notify_n_axes_trampoline<F: Fn(&Device) + 'static>(
520            this: *mut gdk_sys::GdkDevice,
521            _param_spec: glib_sys::gpointer,
522            f: glib_sys::gpointer,
523        ) {
524            let f: &F = &*(f as *const F);
525            f(&from_glib_borrow(this))
526        }
527        unsafe {
528            let f: Box_<F> = Box_::new(f);
529            connect_raw(
530                self.as_ptr() as *mut _,
531                b"notify::n-axes\0".as_ptr() as *const _,
532                Some(transmute(notify_n_axes_trampoline::<F> as usize)),
533                Box_::into_raw(f),
534            )
535        }
536    }
537
538    #[cfg(any(feature = "v3_20", feature = "dox"))]
539    pub fn connect_property_seat_notify<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
540        unsafe extern "C" fn notify_seat_trampoline<F: Fn(&Device) + 'static>(
541            this: *mut gdk_sys::GdkDevice,
542            _param_spec: glib_sys::gpointer,
543            f: glib_sys::gpointer,
544        ) {
545            let f: &F = &*(f as *const F);
546            f(&from_glib_borrow(this))
547        }
548        unsafe {
549            let f: Box_<F> = Box_::new(f);
550            connect_raw(
551                self.as_ptr() as *mut _,
552                b"notify::seat\0".as_ptr() as *const _,
553                Some(transmute(notify_seat_trampoline::<F> as usize)),
554                Box_::into_raw(f),
555            )
556        }
557    }
558
559    #[cfg(any(feature = "v3_22", feature = "dox"))]
560    pub fn connect_property_tool_notify<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
561        unsafe extern "C" fn notify_tool_trampoline<F: Fn(&Device) + 'static>(
562            this: *mut gdk_sys::GdkDevice,
563            _param_spec: glib_sys::gpointer,
564            f: glib_sys::gpointer,
565        ) {
566            let f: &F = &*(f as *const F);
567            f(&from_glib_borrow(this))
568        }
569        unsafe {
570            let f: Box_<F> = Box_::new(f);
571            connect_raw(
572                self.as_ptr() as *mut _,
573                b"notify::tool\0".as_ptr() as *const _,
574                Some(transmute(notify_tool_trampoline::<F> as usize)),
575                Box_::into_raw(f),
576            )
577        }
578    }
579
580    pub fn connect_property_type_notify<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
581        unsafe extern "C" fn notify_type_trampoline<F: Fn(&Device) + 'static>(
582            this: *mut gdk_sys::GdkDevice,
583            _param_spec: glib_sys::gpointer,
584            f: glib_sys::gpointer,
585        ) {
586            let f: &F = &*(f as *const F);
587            f(&from_glib_borrow(this))
588        }
589        unsafe {
590            let f: Box_<F> = Box_::new(f);
591            connect_raw(
592                self.as_ptr() as *mut _,
593                b"notify::type\0".as_ptr() as *const _,
594                Some(transmute(notify_type_trampoline::<F> as usize)),
595                Box_::into_raw(f),
596            )
597        }
598    }
599}
600
601impl fmt::Display for Device {
602    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
603        write!(f, "Device")
604    }
605}