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
// Copyright 2013-2015, The Rust-GNOME Project Developers.
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
//! GdkDevice — Object representing an input device
use glib::translate::*;
use glib::types;
use cursor::Cursor;
use display::Display;
use object::Object;
use screen::Screen;
use window::Window;
use ffi;
pub type Type = ffi::enums::DeviceType;
pub type Device = Object<ffi::GdkDevice>;
impl types::StaticType for Device {
fn static_type() -> types::Type { unsafe { from_glib(ffi::gdk_device_get_type()) } }
}
impl Device {
pub fn get_name(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gdk_device_get_name(self.to_glib_none().0))
}
}
pub fn get_source(&self) -> ::InputSource {
unsafe { ffi::gdk_device_get_source(self.to_glib_none().0) }
}
pub fn set_mode(&self, mode: ::InputMode) {
unsafe { ffi::gdk_device_set_mode(self.to_glib_none().0, mode) }
}
pub fn get_mode(&self) -> ::InputMode {
unsafe { ffi::gdk_device_get_mode(self.to_glib_none().0) }
}
pub fn set_key(&self, index_: u32, keyval: u32, modifiers: ::ModifierType) {
unsafe { ffi::gdk_device_set_key(self.to_glib_none().0, index_, keyval, modifiers) }
}
pub fn get_key(&self, index_: u32, keyval: &mut u32, modifiers: &mut ::ModifierType) -> bool {
unsafe { from_glib(ffi::gdk_device_get_key(self.to_glib_none().0, index_, keyval, modifiers)) }
}
pub fn set_axis_use(&self, index_: u32, use_: ::AxisUse) {
unsafe { ffi::gdk_device_set_axis_use(self.to_glib_none().0, index_, use_) }
}
pub fn get_axis_use(&self, index_: u32) -> ::AxisUse {
unsafe { ffi::gdk_device_get_axis_use(self.to_glib_none().0, index_) }
}
pub fn get_associated_device(&self) -> Option<Device> {
unsafe { from_glib_none(ffi::gdk_device_get_associated_device(self.to_glib_none().0)) }
}
pub fn get_device_type(&self) -> Type {
unsafe { ffi::gdk_device_get_device_type(self.to_glib_none().0) }
}
pub fn get_display(&self) -> Display {
unsafe { from_glib_none(ffi::gdk_device_get_display(self.to_glib_none().0)) }
}
pub fn get_has_cursor(&self) -> bool {
unsafe { from_glib(ffi::gdk_device_get_has_cursor(self.to_glib_none().0)) }
}
pub fn get_n_axes(&self) -> i32 {
unsafe { ffi::gdk_device_get_n_axes(self.to_glib_none().0) }
}
pub fn get_n_keys(&self) -> i32 {
unsafe { ffi::gdk_device_get_n_keys(self.to_glib_none().0) }
}
pub fn warp(&self, screen: &Screen, x: i32, y: i32) {
unsafe { ffi::gdk_device_warp(self.to_glib_none().0, screen.to_glib_none().0, x, y) }
}
pub fn grab(&self, window: &Window, grab_ownership: ::GrabOwnership, owner_events: bool,
event_mask: ::EventMask, cursor: &Cursor, time_: u32) -> ::GrabStatus {
unsafe {
ffi::gdk_device_grab(self.to_glib_none().0, window.to_glib_none().0, grab_ownership,
owner_events.to_glib(), event_mask, cursor.to_glib_none().0, time_)
}
}
pub fn ungrab(&self, time_: u32) {
unsafe { ffi::gdk_device_ungrab(self.to_glib_none().0, time_) }
}
/*pub fn get_state(&self, window: &::Window, axes: &mut [f64], mask: &mut gdk;:ModifierType) {
unsafe { ffi::gdk_device_get_state(self.to_glib_none().0, window.unwrap_pointer(), axes.as_mut_ptr(), mask) }
}
pub fn get_position(&self, x: &mut i32, y: &mut i32) -> Option<::Screen> {
let mut ptr = ::std::ptr::null_mut();
unsafe { ffi::gdk_device_get_position(self.to_glib_none().0, &mut ptr, x as *mut c_int, y as *mut c_int) };
if ptr.is_null() {
None
} else {
Some(::Screen::wrap_pointer(ptr))
}
}
pub fn get_position_double(&self, x: &mut f64, y: &mut f64) -> Option<::Screen> {
let mut ptr = ::std::ptr::null_mut();
unsafe { ffi::gdk_device_get_position_double(self.to_glib_none().0, &mut ptr, x as *mut c_double, y as *mut c_double) };
if ptr.is_null() {
None
} else {
Some(::Screen::wrap_pointer(ptr))
}
}
pub fn get_window_at_position(&self, x: &mut i32, y: &mut i32) -> Option<::Window> {
let mut ptr = ::std::ptr::null_mut();
unsafe { ffi::gdk_device_get_window_at_position(self.to_glib_none().0, &mut ptr, x as *mut c_int, y as *mut c_int) };
if ptr.is_null() {
None
} else {
Some(::Window::wrap_pointer(ptr))
}
}
pub fn get_window_at_position_double(&self, x: &mut f64, y: &mut f64) -> Option<::Window> {
let mut ptr = ::std::ptr::null_mut();
unsafe { ffi::gdk_device_get_window_at_position_double(self.to_glib_none().0, &mut ptr, x as *mut c_double, y as *mut c_double) };
if ptr.is_null() {
None
} else {
Some(::Window::wrap_pointer(ptr))
}
}
pub fn get_history(&self, window: &::Window, start: u32, stop: u32) -> Vec<::TimeCoord> {
let mut ptr = ::std::ptr::null_mut();
let mut n_events : c_int = 0;
unsafe { ffi::gdk_device_get_history(self.to_glib_none().0, window.unwrap_pointer(), start, stop, &mut ptr, &mut n_events) };
let mut ret = Vec::with_capacity(n_events as uint);
for i in range(0, n_events) {
ret.push(::TimeCoord::wrap_pointer(::std::ptr::read(ptr.offset(i))));
}
ret
}
pub fn free_history(events: &[::TimeCoord]) {
let mut tmp = Vec::with_capacity(events.len());
for i in range(0, events.len()) {
tmp.push(events[i].unwrap_pointer());
}
unsafe { ffi::gdk_device_free_history(events.as_mut_ptr(), events.len()) }
}*/
pub fn get_axis(&self, axes: &mut [f64], use_: ::AxisUse, value: &mut f64) -> bool {
unsafe { from_glib(ffi::gdk_device_get_axis(self.to_glib_none().0, axes.as_mut_ptr(), use_, value)) }
}
/*pub fn get_axis_value(&self, axes: &mut [f64], label: &mut ::Atom, value: &mut f64) -> bool {
unsafe { from_glib(ffi::gdk_device_get_axis_value(self.to_glib_none().0, axes.as_mut_ptr(), label.unwrap_pointer(), value)) }
}*/
/*pub fn get_last_event_window(&self) -> Option<::Window> {
let ptr = unsafe { ffi::gdk_device_get_last_event_window(self.to_glib_none().0) };
if ptr.is_null() {
None
} else {
Some(::Window::wrap_pointer(ptr))
}
}*/
}