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
// Copyright 2013-2015, The Gtk-rs 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>
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::GdkDeviceType;
/// Object representing an input device
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 {
/// Determines the name of the device.
pub fn get_name(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gdk_device_get_name(self.to_glib_none().0))
}
}
/// Returns the vendor ID of this device, or NULL if this information couldn't be obtained. This
/// ID is retrieved from the device, and is thus constant for it.
///
/// This function, together with gdk_device_get_product_id(), can be used to eg. compose GSettings
/// paths to store settings for this device.
///
/// ```ignore
/// fn get_device_settings(device: &Device) -> GSettings {
/// GSettings *settings;
/// GdkDevice *device;
/// gchar *path;
///
/// let vendor = device.get_vendor_id().unwrap();
/// let product = device.get_product_id().unwrap();
///
/// let path = format!("/org/example/app/devices/{}:{}/", vendor, product);
/// g_settings_new_with_path(DEVICE_SCHEMA, path);
/// }
/// ```
#[cfg(gdk_3_16)]
pub fn get_vendor_id(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gdk_device_get_vendor_id(self.to_glib_none().0))
}
}
/// Returns the product ID of this device, or None if this information couldn't be obtained. This
/// ID is retrieved from the device, and is thus constant for it. See Device::get_vendor_id() for
/// more information.
#[cfg(gdk_3_16)]
pub fn get_product_id(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::gdk_device_get_product_id(self.to_glib_none().0))
}
}
/// Determines the type of the device.
pub fn get_source(&self) -> ::InputSource {
unsafe { ffi::gdk_device_get_source(self.to_glib_none().0) }
}
/// Sets a the mode of an input device. The mode controls if the device is active and whether the
/// device’s range is mapped to the entire screen or to a single window.
///
/// Note: This is only meaningful for floating devices, master devices (and slaves connected to
/// these) drive the pointer cursor, which is not limited by the input mode.
pub fn set_mode(&self, mode: ::InputMode) {
unsafe { ffi::gdk_device_set_mode(self.to_glib_none().0, mode); }
}
/// Determines the mode of the device.
pub fn get_mode(&self) -> ::InputMode {
unsafe { ffi::gdk_device_get_mode(self.to_glib_none().0) }
}
/// Specifies the X key event to generate when a macro button of a device is pressed.
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) }
}
/// If `index_` has a valid keyval, this function will return true and fill in `keyval` and
/// `modifiers` with the keyval settings.
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)) }
}
/// Specifies how an axis of a device is used.
pub fn set_axis_use(&self, index_: u32, use_: ::AxisUse) {
unsafe { ffi::gdk_device_set_axis_use(self.to_glib_none().0, index_, use_) }
}
/// Returns the axis use for `index_`.
pub fn get_axis_use(&self, index_: u32) -> ::AxisUse {
unsafe { ffi::gdk_device_get_axis_use(self.to_glib_none().0, index_) }
}
/// Returns the associated `self` to `self` , if `self` is of type DeviceType::Master, it
/// will return the paired pointer or keyboard.
///
/// If `self` is of type DeviceType::Slave, it will return the master device to which `self`
/// is attached to.
///
/// If `self` is of type DeviceType::Floating, None will be returned, as there is no
/// associated device.
pub fn get_associated_device(&self) -> Option<Device> {
unsafe { from_glib_none(ffi::gdk_device_get_associated_device(self.to_glib_none().0)) }
}
/// Returns the device type for `self`.
pub fn get_device_type(&self) -> Type {
unsafe { ffi::gdk_device_get_device_type(self.to_glib_none().0) }
}
/// Returns the Display to which `self` pertains.
pub fn get_display(&self) -> Display {
unsafe { from_glib_none(ffi::gdk_device_get_display(self.to_glib_none().0)) }
}
/// Determines whether the pointer follows device motion. This is not meaningful for
/// keyboard devices, which don't have a pointer.
pub fn get_has_cursor(&self) -> bool {
unsafe { from_glib(ffi::gdk_device_get_has_cursor(self.to_glib_none().0)) }
}
/// Returns the number of axes the device currently has.
pub fn get_n_axes(&self) -> i32 {
unsafe { ffi::gdk_device_get_n_axes(self.to_glib_none().0) }
}
/// Returns the number of keys the device currently has.
pub fn get_n_keys(&self) -> i32 {
unsafe { ffi::gdk_device_get_n_keys(self.to_glib_none().0) }
}
/// Warps `self` in display to the point `x`, `y` on the screen `screen`, unless the device
/// is confined to a window by a grab, in which case it will be moved as far as allowed by
/// the grab. Warping the pointer creates events as if the user had moved the mouse
/// instantaneously to the destination.
///
/// Note that the pointer should normally be under the control of the user. This function
/// was added to cover some rare use cases like keyboard navigation support for the color
/// picker in the gtk::ColorSelectionDialog.
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) }
}
/// Grabs the device so that all events coming from this device are passed to this
/// application until the device is ungrabbed with Device::ungrab(), or the window becomes
/// unviewable. This overrides any previous grab on the device by this client.
///
/// Note that `self` and `window` need to be on the same display.
///
/// Device grabs are used for operations which need complete control over the given device
/// events (either pointer or keyboard). For example in GTK+ this is used for Drag and Drop
/// operations, popup menus and such.
///
/// Note that if the event mask of an X window has selected both button press and button
/// release events, then a button press event will cause an automatic pointer grab until
/// the button is released. X does this automatically since most applications expect to
/// receive button press and release events in pairs. It is equivalent to a pointer grab
/// on the window with `owner_events` set to true.
///
/// 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 GdkEventGrabBroken events that are emitted when
/// the grab ends unvoluntarily.
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_)
}
}
/// Release any grab on `self`.
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()) }
}*/
/// Interprets an array of double as axis values for a given device, and locates the value
/// in the array for a given axis use.
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))
}
}*/
}