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 module gdk.Device;
26 
27 private import gdk.DeviceTool;
28 private import gdk.Display;
29 private import gdk.Seat;
30 private import gdk.Surface;
31 private import gdk.c.functions;
32 public  import gdk.c.types;
33 private import glib.Str;
34 private import glib.c.functions;
35 private import gobject.ObjectG;
36 private import gobject.Signals;
37 private import std.algorithm;
38 
39 
40 /**
41  * The `GdkDevice` object represents an input device, such
42  * as a keyboard, a mouse, or a touchpad.
43  * 
44  * See the [class@Gdk.Seat] documentation for more information
45  * about the various kinds of devices, and their relationships.
46  */
47 public class Device : ObjectG
48 {
49 	/** the main Gtk struct */
50 	protected GdkDevice* gdkDevice;
51 
52 	/** Get the main Gtk struct */
53 	public GdkDevice* getDeviceStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gdkDevice;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gdkDevice;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GdkDevice* gdkDevice, bool ownedRef = false)
70 	{
71 		this.gdkDevice = gdkDevice;
72 		super(cast(GObject*)gdkDevice, ownedRef);
73 	}
74 
75 
76 	/** */
77 	public static GType getType()
78 	{
79 		return gdk_device_get_type();
80 	}
81 
82 	/**
83 	 * Retrieves whether the Caps Lock modifier of the keyboard is locked.
84 	 *
85 	 * This is only relevant for keyboard devices.
86 	 *
87 	 * Returns: %TRUE if Caps Lock is on for @device
88 	 */
89 	public bool getCapsLockState()
90 	{
91 		return gdk_device_get_caps_lock_state(gdkDevice) != 0;
92 	}
93 
94 	/**
95 	 * Retrieves the current tool for @device.
96 	 *
97 	 * Returns: the `GdkDeviceTool`, or %NULL
98 	 */
99 	public DeviceTool getDeviceTool()
100 	{
101 		auto __p = gdk_device_get_device_tool(gdkDevice);
102 
103 		if(__p is null)
104 		{
105 			return null;
106 		}
107 
108 		return ObjectG.getDObject!(DeviceTool)(cast(GdkDeviceTool*) __p);
109 	}
110 
111 	/**
112 	 * Returns the direction of effective layout of the keyboard.
113 	 *
114 	 * This is only relevant for keyboard devices.
115 	 *
116 	 * The direction of a layout is the direction of the majority
117 	 * of its symbols. See [func@Pango.unichar_direction].
118 	 *
119 	 * Returns: %PANGO_DIRECTION_LTR or %PANGO_DIRECTION_RTL
120 	 *     if it can determine the direction. %PANGO_DIRECTION_NEUTRAL
121 	 *     otherwise
122 	 */
123 	public PangoDirection getDirection()
124 	{
125 		return gdk_device_get_direction(gdkDevice);
126 	}
127 
128 	/**
129 	 * Returns the `GdkDisplay` to which @device pertains.
130 	 *
131 	 * Returns: a `GdkDisplay`
132 	 */
133 	public Display getDisplay()
134 	{
135 		auto __p = gdk_device_get_display(gdkDevice);
136 
137 		if(__p is null)
138 		{
139 			return null;
140 		}
141 
142 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
143 	}
144 
145 	/**
146 	 * Determines whether the pointer follows device motion.
147 	 *
148 	 * This is not meaningful for keyboard devices, which
149 	 * don't have a pointer.
150 	 *
151 	 * Returns: %TRUE if the pointer follows device motion
152 	 */
153 	public bool getHasCursor()
154 	{
155 		return gdk_device_get_has_cursor(gdkDevice) != 0;
156 	}
157 
158 	/**
159 	 * Retrieves the current modifier state of the keyboard.
160 	 *
161 	 * This is only relevant for keyboard devices.
162 	 *
163 	 * Returns: the current modifier state
164 	 */
165 	public GdkModifierType getModifierState()
166 	{
167 		return gdk_device_get_modifier_state(gdkDevice);
168 	}
169 
170 	/**
171 	 * The name of the device, suitable for showing in a user interface.
172 	 *
173 	 * Returns: a name
174 	 */
175 	public string getName()
176 	{
177 		return Str.toString(gdk_device_get_name(gdkDevice));
178 	}
179 
180 	/**
181 	 * Retrieves whether the Num Lock modifier of the keyboard is locked.
182 	 *
183 	 * This is only relevant for keyboard devices.
184 	 *
185 	 * Returns: %TRUE if Num Lock is on for @device
186 	 */
187 	public bool getNumLockState()
188 	{
189 		return gdk_device_get_num_lock_state(gdkDevice) != 0;
190 	}
191 
192 	/**
193 	 * Retrieves the number of touch points associated to @device.
194 	 *
195 	 * Returns: the number of touch points
196 	 */
197 	public uint getNumTouches()
198 	{
199 		return gdk_device_get_num_touches(gdkDevice);
200 	}
201 
202 	/**
203 	 * Returns the product ID of this device.
204 	 *
205 	 * This ID is retrieved from the device, and does not change.
206 	 * See [method@Gdk.Device.get_vendor_id] for more information.
207 	 *
208 	 * Returns: the product ID, or %NULL
209 	 */
210 	public string getProductId()
211 	{
212 		return Str.toString(gdk_device_get_product_id(gdkDevice));
213 	}
214 
215 	/**
216 	 * Retrieves whether the Scroll Lock modifier of the keyboard is locked.
217 	 *
218 	 * This is only relevant for keyboard devices.
219 	 *
220 	 * Returns: %TRUE if Scroll Lock is on for @device
221 	 */
222 	public bool getScrollLockState()
223 	{
224 		return gdk_device_get_scroll_lock_state(gdkDevice) != 0;
225 	}
226 
227 	/**
228 	 * Returns the `GdkSeat` the device belongs to.
229 	 *
230 	 * Returns: a `GdkSeat`
231 	 */
232 	public Seat getSeat()
233 	{
234 		auto __p = gdk_device_get_seat(gdkDevice);
235 
236 		if(__p is null)
237 		{
238 			return null;
239 		}
240 
241 		return ObjectG.getDObject!(Seat)(cast(GdkSeat*) __p);
242 	}
243 
244 	/**
245 	 * Determines the type of the device.
246 	 *
247 	 * Returns: a `GdkInputSource`
248 	 */
249 	public GdkInputSource getSource()
250 	{
251 		return gdk_device_get_source(gdkDevice);
252 	}
253 
254 	/**
255 	 * Obtains the surface underneath @device, returning the location of the
256 	 * device in @win_x and @win_y
257 	 *
258 	 * Returns %NULL if the surface tree under @device is not known to GDK
259 	 * (for example, belongs to another application).
260 	 *
261 	 * Params:
262 	 *     winX = return location for the X coordinate of the device location,
263 	 *         relative to the surface origin, or %NULL.
264 	 *     winY = return location for the Y coordinate of the device location,
265 	 *         relative to the surface origin, or %NULL.
266 	 *
267 	 * Returns: the `GdkSurface` under the
268 	 *     device position, or %NULL
269 	 */
270 	public Surface getSurfaceAtPosition(out double winX, out double winY)
271 	{
272 		auto __p = gdk_device_get_surface_at_position(gdkDevice, &winX, &winY);
273 
274 		if(__p is null)
275 		{
276 			return null;
277 		}
278 
279 		return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p);
280 	}
281 
282 	/**
283 	 * Returns the timestamp of the last activity for this device.
284 	 *
285 	 * In practice, this means the timestamp of the last event that was
286 	 * received from the OS for this device. (GTK may occasionally produce
287 	 * events for a device that are not received from the OS, and will not
288 	 * update the timestamp).
289 	 *
290 	 * Returns: the timestamp of the last activity for this device
291 	 *
292 	 * Since: 4.2
293 	 */
294 	public uint getTimestamp()
295 	{
296 		return gdk_device_get_timestamp(gdkDevice);
297 	}
298 
299 	/**
300 	 * Returns the vendor ID of this device.
301 	 *
302 	 * This ID is retrieved from the device, and does not change.
303 	 *
304 	 * This function, together with [method@Gdk.Device.get_product_id],
305 	 * can be used to eg. compose `GSettings` paths to store settings
306 	 * for this device.
307 	 *
308 	 * ```c
309 	 * static GSettings *
310 	 * get_device_settings (GdkDevice *device)
311 	 * {
312 	 * const char *vendor, *product;
313 	 * GSettings *settings;
314 	 * GdkDevice *device;
315 	 * char *path;
316 	 *
317 	 * vendor = gdk_device_get_vendor_id (device);
318 	 * product = gdk_device_get_product_id (device);
319 	 *
320 	 * path = g_strdup_printf ("/org/example/app/devices/%s:%s/", vendor, product);
321 	 * settings = g_settings_new_with_path (DEVICE_SCHEMA, path);
322 	 * g_free (path);
323 	 *
324 	 * return settings;
325 	 * }
326 	 * ```
327 	 *
328 	 * Returns: the vendor ID, or %NULL
329 	 */
330 	public string getVendorId()
331 	{
332 		return Str.toString(gdk_device_get_vendor_id(gdkDevice));
333 	}
334 
335 	/**
336 	 * Determines if layouts for both right-to-left and
337 	 * left-to-right languages are in use on the keyboard.
338 	 *
339 	 * This is only relevant for keyboard devices.
340 	 *
341 	 * Returns: %TRUE if there are layouts with both directions,
342 	 *     %FALSE otherwise
343 	 */
344 	public bool hasBidiLayouts()
345 	{
346 		return gdk_device_has_bidi_layouts(gdkDevice) != 0;
347 	}
348 
349 	/**
350 	 * Emitted either when the the number of either axes or keys changes.
351 	 *
352 	 * On X11 this will normally happen when the physical device
353 	 * routing events through the logical device changes (for
354 	 * example, user switches from the USB mouse to a tablet); in
355 	 * that case the logical device will change to reflect the axes
356 	 * and keys on the new physical device.
357 	 */
358 	gulong addOnChanged(void delegate(Device) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
359 	{
360 		return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
361 	}
362 
363 	/**
364 	 * Emitted on pen/eraser devices whenever tools enter or leave proximity.
365 	 *
366 	 * Params:
367 	 *     tool = The new current tool
368 	 */
369 	gulong addOnToolChanged(void delegate(DeviceTool, Device) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
370 	{
371 		return Signals.connect(this, "tool-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
372 	}
373 }