1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = gdk-Input-Devices.html
27  * outPack = gdk
28  * outFile = Device
29  * strct   = GdkDevice
30  * realStrct=
31  * ctorStrct=
32  * clss    = Device
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gdk_device_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- gdk_device_get_history
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.ListG
49  * 	- gdk.Window
50  * structWrap:
51  * 	- GList* -> ListG
52  * 	- GdkDevice* -> Device
53  * 	- GdkWindow* -> Window
54  * module aliases:
55  * local aliases:
56  * overrides:
57  */
58 
59 module gdk.Device;
60 
61 public  import gtkc.gdktypes;
62 
63 private import gtkc.gdk;
64 private import glib.ConstructionException;
65 private import gobject.ObjectG;
66 
67 
68 private import glib.Str;
69 private import glib.ListG;
70 private import gdk.Window;
71 
72 
73 
74 
75 /**
76  * Description
77  * In addition to the normal keyboard and mouse input devices, GTK+ also
78  * contains support for extended input devices. In
79  * particular, this support is targeted at graphics tablets. Graphics
80  * tablets typically return sub-pixel positioning information and possibly
81  * information about the pressure and tilt of the stylus. Under
82  * X, the support for extended devices is done through the
83  * XInput extension.
84  * Because handling extended input devices may involve considerable
85  * overhead, they need to be turned on for each GdkWindow
86  * individually using gdk_input_set_extension_events().
87  * (Or, more typically, for GtkWidgets, using gtk_widget_set_extension_events()).
88  * As an additional complication, depending on the support from
89  * the windowing system, its possible that a normal mouse
90  * cursor will not be displayed for a particular extension
91  * device. If an application does not want to deal with displaying
92  * a cursor itself, it can ask only to get extension events
93  * from devices that will display a cursor, by passing the
94  * GDK_EXTENSION_EVENTS_CURSOR value to
95  * gdk_input_set_extension_events(). Otherwise, the application
96  * must retrieve the device information using gdk_devices_list(),
97  * check the has_cursor field, and,
98  * if it is FALSE, draw a cursor itself when it receives
99  * motion events.
100  * Each pointing device is assigned a unique integer ID; events from a
101  * particular device can be identified by the
102  * deviceid field in the event structure. The
103  * events generated by pointer devices have also been extended to contain
104  * pressure, xtilt
105  * and ytilt fields which contain the extended
106  * information reported as additional valuators
107  * from the device. The pressure field is a
108  * a double value ranging from 0.0 to 1.0, while the tilt fields are
109  * double values ranging from -1.0 to 1.0. (With -1.0 representing the
110  * maximum tilt to the left or up, and 1.0 representing the maximum
111  * tilt to the right or down.)
112  * One additional field in each event is the
113  * source field, which contains an
114  * enumeration value describing the type of device; this currently
115  * can be one of GDK_SOURCE_MOUSE, GDK_SOURCE_PEN, GDK_SOURCE_ERASER,
116  * or GDK_SOURCE_CURSOR. This field is present to allow simple
117  * applications to (for instance) delete when they detect eraser
118  * devices without having to keep track of complicated per-device
119  * settings.
120  * Various aspects of each device may be configured.
121  * The configuration of devices is queried using gdk_devices_list().
122  * Each device must be activated using gdk_device_set_mode(), which
123  * also controls whether the device's range is mapped to the
124  * entire screen or to a single window. The mapping of the valuators of
125  * the device onto the predefined valuator types is set using
126  * gdk_device_set_axis_use(). And the source type for each device
127  * can be set with gdk_device_set_source().
128  * Devices may also have associated keys
129  * or macro buttons. Such keys can be globally set to map
130  * into normal X keyboard events. The mapping is set using
131  * gdk_device_set_key().
132  * The interfaces in this section will most likely be considerably
133  * modified in the future to accomodate devices that may have different
134  * sets of additional valuators than the pressure xtilt
135  * and ytilt.
136  */
137 public class Device
138 {
139 	
140 	/** the main Gtk struct */
141 	protected GdkDevice* gdkDevice;
142 	
143 	
144 	public GdkDevice* getDeviceStruct()
145 	{
146 		return gdkDevice;
147 	}
148 	
149 	
150 	/** the main Gtk struct as a void* */
151 	protected void* getStruct()
152 	{
153 		return cast(void*)gdkDevice;
154 	}
155 	
156 	/**
157 	 * Sets our main struct and passes it to the parent class
158 	 */
159 	public this (GdkDevice* gdkDevice)
160 	{
161 		this.gdkDevice = gdkDevice;
162 	}
163 	
164 	/**
165 	 * Obtains the motion history for a device; given a starting and
166 	 * ending timestamp, return all events in the motion history for
167 	 * the device in the given range of time. Some windowing systems
168 	 * do not support motion history, in which case, FALSE will
169 	 * be returned. (This is not distinguishable from the case where
170 	 * motion history is supported and no events were found.)
171 	 * Params:
172 	 * window =  the window with respect to which which the event coordinates will be reported
173 	 * start =  starting timestamp for range of events to return
174 	 * stop =  ending timestamp for the range of events to return
175 	 * events =  location to store a newly-allocated array of GdkTimeCoord, or NULL
176 	 * Returns: TRUE if the windowing system supports motion history and at least one event was found.
177 	 */
178 	public int getHistory(Window window, uint start, uint stop, out GdkTimeCoord*[] events)
179 	{
180 		int nEvents;
181 		GdkTimeCoord** coord = null;
182 		
183 		// gboolean gdk_device_get_history (GdkDevice *device,  GdkWindow *window,  guint32 start,  guint32 stop,  GdkTimeCoord ***events,  gint *n_events);
184 		int i = gdk_device_get_history(gdkDevice, (window is null) ? null : window.getWindowStruct(), start, stop, &coord, &nEvents);
185 		
186 		events = coord[0 .. nEvents];
187 		return i;
188 	}
189 	
190 	/**
191 	 */
192 	
193 	/**
194 	 * Returns the list of available input devices for the default display.
195 	 * The list is statically allocated and should not be freed.
196 	 * Returns: a list of GdkDevice
197 	 */
198 	public static ListG gdkDevicesList()
199 	{
200 		// GList * gdk_devices_list (void);
201 		auto p = gdk_devices_list();
202 		
203 		if(p is null)
204 		{
205 			return null;
206 		}
207 		
208 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
209 	}
210 	
211 	/**
212 	 * Determines the name of the device.
213 	 * Since 2.22
214 	 * Returns: a name
215 	 */
216 	public string getName()
217 	{
218 		// const gchar * gdk_device_get_name (GdkDevice *device);
219 		return Str.toString(gdk_device_get_name(gdkDevice));
220 	}
221 	
222 	/**
223 	 * Sets the source type for an input device.
224 	 * Params:
225 	 * source = the source type.
226 	 */
227 	public void setSource(GdkInputSource source)
228 	{
229 		// void gdk_device_set_source (GdkDevice *device,  GdkInputSource source);
230 		gdk_device_set_source(gdkDevice, source);
231 	}
232 	
233 	/**
234 	 * Determines the type of the device.
235 	 * Since 2.22
236 	 * Returns: a GdkInputSource
237 	 */
238 	public GdkInputSource getSource()
239 	{
240 		// GdkInputSource gdk_device_get_source (GdkDevice *device);
241 		return gdk_device_get_source(gdkDevice);
242 	}
243 	
244 	/**
245 	 * Sets a the mode of an input device. The mode controls if the
246 	 * device is active and whether the device's range is mapped to the
247 	 * entire screen or to a single window.
248 	 * Params:
249 	 * mode = the input mode.
250 	 * Returns: TRUE if the mode was successfully changed.
251 	 */
252 	public int setMode(GdkInputMode mode)
253 	{
254 		// gboolean gdk_device_set_mode (GdkDevice *device,  GdkInputMode mode);
255 		return gdk_device_set_mode(gdkDevice, mode);
256 	}
257 	
258 	/**
259 	 * Determines the mode of the device.
260 	 * Since 2.22
261 	 * Returns: a GdkInputSource
262 	 */
263 	public GdkInputMode getMode()
264 	{
265 		// GdkInputMode gdk_device_get_mode (GdkDevice *device);
266 		return gdk_device_get_mode(gdkDevice);
267 	}
268 	
269 	/**
270 	 * Specifies the X key event to generate when a macro button of a device
271 	 * is pressed.
272 	 * Params:
273 	 * index = the index of the macro button to set.
274 	 * keyval = the keyval to generate.
275 	 * modifiers = the modifiers to set.
276 	 */
277 	public void setKey(uint index, uint keyval, GdkModifierType modifiers)
278 	{
279 		// void gdk_device_set_key (GdkDevice *device,  guint index_,  guint keyval,  GdkModifierType modifiers);
280 		gdk_device_set_key(gdkDevice, index, keyval, modifiers);
281 	}
282 	
283 	/**
284 	 * If index has a valid keyval, this function will
285 	 * fill in keyval and modifiers with the keyval settings.
286 	 * Since 2.22
287 	 * Params:
288 	 * index = the index of the macro button to get.
289 	 * keyval = return value for the keyval.
290 	 * modifiers = return value for modifiers.
291 	 */
292 	public void getKey(uint index, out uint keyval, out GdkModifierType modifiers)
293 	{
294 		// void gdk_device_get_key (GdkDevice *device,  guint index,  guint *keyval,  GdkModifierType *modifiers);
295 		gdk_device_get_key(gdkDevice, index, &keyval, &modifiers);
296 	}
297 	
298 	/**
299 	 * Specifies how an axis of a device is used.
300 	 * Params:
301 	 * index = the index of the axis.
302 	 * use = specifies how the axis is used.
303 	 */
304 	public void setAxisUse(uint index, GdkAxisUse use)
305 	{
306 		// void gdk_device_set_axis_use (GdkDevice *device,  guint index_,  GdkAxisUse use);
307 		gdk_device_set_axis_use(gdkDevice, index, use);
308 	}
309 	
310 	/**
311 	 * Returns the axis use for index.
312 	 * Since 2.22
313 	 * Params:
314 	 * index = the index of the axis.
315 	 * Returns: a GdkAxisUse specifying how the axis is used.
316 	 */
317 	public GdkAxisUse getAxisUse(uint index)
318 	{
319 		// GdkAxisUse gdk_device_get_axis_use (GdkDevice *device,  guint index);
320 		return gdk_device_get_axis_use(gdkDevice, index);
321 	}
322 	
323 	/**
324 	 * Returns the core pointer device for the default display.
325 	 * Returns: the core pointer device; this is owned by the display and should not be freed.
326 	 */
327 	public static Device getCorePointer()
328 	{
329 		// GdkDevice * gdk_device_get_core_pointer (void);
330 		auto p = gdk_device_get_core_pointer();
331 		
332 		if(p is null)
333 		{
334 			return null;
335 		}
336 		
337 		return ObjectG.getDObject!(Device)(cast(GdkDevice*) p);
338 	}
339 	
340 	/**
341 	 * Gets the current state of a device.
342 	 * Params:
343 	 * window = a GdkWindow.
344 	 * axes = an array of doubles to store the values of the axes of device in,
345 	 * or NULL.
346 	 * mask = location to store the modifiers, or NULL.
347 	 */
348 	public void getState(Window window, double[] axes, out GdkModifierType mask)
349 	{
350 		// void gdk_device_get_state (GdkDevice *device,  GdkWindow *window,  gdouble *axes,  GdkModifierType *mask);
351 		gdk_device_get_state(gdkDevice, (window is null) ? null : window.getWindowStruct(), axes.ptr, &mask);
352 	}
353 	
354 	/**
355 	 * Frees an array of GdkTimeCoord that was returned by gdk_device_get_history().
356 	 * Frees an array of GdkTimeCoord that was returned by gdk_device_get_history().
357 	 * Params:
358 	 * events = an array of GdkTimeCoord. [inout][transfer none]
359 	 */
360 	public static void freeHistory(out GdkTimeCoord[] events)
361 	{
362 		// void gdk_device_free_history (GdkTimeCoord **events,  gint n_events);
363 		GdkTimeCoord* outevents = null;
364 		int nEvents;
365 		
366 		gdk_device_free_history(&outevents, nEvents);
367 		
368 		events = outevents[0 .. nEvents];
369 	}
370 	
371 	/**
372 	 * Interprets an array of double as axis values for a given device,
373 	 * and locates the value in the array for a given axis use.
374 	 * Params:
375 	 * axes = pointer to an array of axes
376 	 * use = the use to look for
377 	 * value = location to store the found value.
378 	 * Returns: TRUE if the given axis use was found, otherwise FALSE
379 	 */
380 	public int getAxis(double[] axes, GdkAxisUse use, out double value)
381 	{
382 		// gboolean gdk_device_get_axis (GdkDevice *device,  gdouble *axes,  GdkAxisUse use,  gdouble *value);
383 		return gdk_device_get_axis(gdkDevice, axes.ptr, use, &value);
384 	}
385 	
386 	/**
387 	 * Gets the number of axes of a device.
388 	 * Since 2.22
389 	 * Returns: the number of axes of device
390 	 */
391 	public int getNAxes()
392 	{
393 		// gint gdk_device_get_n_axes (GdkDevice *device);
394 		return gdk_device_get_n_axes(gdkDevice);
395 	}
396 	
397 	/**
398 	 * Turns extension events on or off for a particular window,
399 	 * and specifies the event mask for extension events.
400 	 * Params:
401 	 * window = a GdkWindow.
402 	 * mask = the event mask
403 	 * mode = the type of extension events that are desired.
404 	 */
405 	public static void gdkInputSetExtensionEvents(Window window, int mask, GdkExtensionMode mode)
406 	{
407 		// void gdk_input_set_extension_events (GdkWindow *window,  gint mask,  GdkExtensionMode mode);
408 		gdk_input_set_extension_events((window is null) ? null : window.getWindowStruct(), mask, mode);
409 	}
410 }