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  = GdkDeviceManager.html
27  * outPack = gdk
28  * outFile = DeviceManager
29  * strct   = GdkDeviceManager
30  * realStrct=
31  * ctorStrct=
32  * clss    = DeviceManager
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gdk_device_manager_
41  * 	- gdk_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- gdk.Device
48  * 	- gdk.Display
49  * structWrap:
50  * 	- GdkDevice* -> Device
51  * 	- GdkDisplay* -> Display
52  * module aliases:
53  * local aliases:
54  * overrides:
55  */
56 
57 module gdk.DeviceManager;
58 
59 public  import gtkc.gdktypes;
60 
61 private import gtkc.gdk;
62 private import glib.ConstructionException;
63 private import gobject.ObjectG;
64 
65 private import gobject.Signals;
66 public  import gtkc.gdktypes;
67 private import gdk.Device;
68 private import gdk.Display;
69 
70 
71 private import gobject.ObjectG;
72 
73 /**
74  * In addition to a single pointer and keyboard for user interface input,
75  * GDK contains support for a variety of input devices, including graphics
76  * tablets, touchscreens and multiple pointers/keyboards interacting
77  * simultaneously with the user interface. Such input devices often have
78  * additional features, such as sub-pixel positioning information and
79  * additional device-dependent information.
80  *
81  * In order to query the device hierarchy and be aware of changes in the
82  * device hierarchy (such as virtual devices being created or removed, or
83  * physical devices being plugged or unplugged), GDK provides
84  * GdkDeviceManager.
85  *
86  * By default, and if the platform supports it, GDK is aware of multiple
87  * keyboard/pointer pairs and multitouch devices. This behavior can be
88  * changed by calling gdk_disable_multidevice() before gdk_display_open().
89  * There should rarely be a need to do that though, since GDK defaults
90  * to a compatibility mode in which it will emit just one enter/leave
91  * event pair for all devices on a window. To enable per-device
92  * enter/leave events and other multi-pointer interaction features,
93  * gdk_window_set_support_multidevice() must be called on
94  * GdkWindows (or gtk_widget_set_support_multidevice() on widgets).
95  * window. See the gdk_window_set_support_multidevice() documentation
96  * for more information.
97  *
98  * On X11, multi-device support is implemented through XInput 2.
99  * Unless gdk_disable_multidevice() is called, the XInput 2
100  * GdkDeviceManager implementation will be used as the input source.
101  * Otherwise either the core or XInput 1 implementations will be used.
102  *
103  * For simple applications that don't have any special interest in
104  * input devices, the so-called client pointer
105  * provides a reasonable approximation to a simple setup with a single
106  * pointer and keyboard. The device that has been set as the client
107  * pointer can be accessed via gdk_device_manager_get_client_pointer().
108  *
109  * Conceptually, in multidevice mode there are 2 device types. Virtual
110  * devices (or master devices) are represented by the pointer cursors
111  * and keyboard foci that are seen on the screen. Physical devices (or
112  * slave devices) represent the hardware that is controlling the virtual
113  * devices, and thus have no visible cursor on the screen.
114  *
115  * Virtual devices are always paired, so there is a keyboard device for every
116  * pointer device. Associations between devices may be inspected through
117  * gdk_device_get_associated_device().
118  *
119  * There may be several virtual devices, and several physical devices could
120  * be controlling each of these virtual devices. Physical devices may also
121  * be "floating", which means they are not attached to any virtual device.
122  *
123  * $(DDOC_COMMENT example)
124  *
125  * By default, GDK will automatically listen for events coming from all
126  * master devices, setting the GdkDevice for all events coming from input
127  * devices. Events containing device information are GDK_MOTION_NOTIFY,
128  * GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_3BUTTON_PRESS,
129  * GDK_BUTTON_RELEASE, GDK_SCROLL, GDK_KEY_PRESS, GDK_KEY_RELEASE,
130  * GDK_ENTER_NOTIFY, GDK_LEAVE_NOTIFY, GDK_FOCUS_CHANGE,
131  * GDK_PROXIMITY_IN, GDK_PROXIMITY_OUT, GDK_DRAG_ENTER, GDK_DRAG_LEAVE,
132  * GDK_DRAG_MOTION, GDK_DRAG_STATUS, GDK_DROP_START, GDK_DROP_FINISHED
133  * and GDK_GRAB_BROKEN. When dealing with an event on a master device,
134  * it is possible to get the source (slave) device that the event originated
135  * from via gdk_event_get_source_device().
136  *
137  * In order to listen for events coming from devices
138  * other than a virtual device, gdk_window_set_device_events() must be
139  * called. Generally, this function can be used to modify the event mask
140  * for any given device.
141  *
142  * Input devices may also provide additional information besides X/Y.
143  * For example, graphics tablets may also provide pressure and X/Y tilt
144  * information. This information is device-dependent, and may be
145  * queried through gdk_device_get_axis(). In multidevice mode, virtual
146  * devices will change axes in order to always represent the physical
147  * device that is routing events through it. Whenever the physical device
148  * changes, the "n-axes" property will be notified, and
149  * gdk_device_list_axes() will return the new device axes.
150  *
151  * Devices may also have associated keys or
152  * macro buttons. Such keys can be globally set to map into normal X
153  * keyboard events. The mapping is set using gdk_device_set_key().
154  */
155 public class DeviceManager : ObjectG
156 {
157 	
158 	/** the main Gtk struct */
159 	protected GdkDeviceManager* gdkDeviceManager;
160 	
161 	
162 	/** Get the main Gtk struct */
163 	public GdkDeviceManager* getDeviceManagerStruct()
164 	{
165 		return gdkDeviceManager;
166 	}
167 	
168 	
169 	/** the main Gtk struct as a void* */
170 	protected override void* getStruct()
171 	{
172 		return cast(void*)gdkDeviceManager;
173 	}
174 	
175 	/**
176 	 * Sets our main struct and passes it to the parent class
177 	 */
178 	public this (GdkDeviceManager* gdkDeviceManager)
179 	{
180 		super(cast(GObject*)gdkDeviceManager);
181 		this.gdkDeviceManager = gdkDeviceManager;
182 	}
183 	
184 	protected override void setStruct(GObject* obj)
185 	{
186 		super.setStruct(obj);
187 		gdkDeviceManager = cast(GdkDeviceManager*)obj;
188 	}
189 	
190 	/**
191 	 */
192 	int[string] connectedSignals;
193 	
194 	void delegate(Device, DeviceManager)[] onDeviceAddedListeners;
195 	/**
196 	 * The ::device-added signal is emitted either when a new master
197 	 * pointer is created, or when a slave (Hardware) input device
198 	 * is plugged in.
199 	 */
200 	void addOnDeviceAdded(void delegate(Device, DeviceManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
201 	{
202 		if ( !("device-added" in connectedSignals) )
203 		{
204 			Signals.connectData(
205 			getStruct(),
206 			"device-added",
207 			cast(GCallback)&callBackDeviceAdded,
208 			cast(void*)this,
209 			null,
210 			connectFlags);
211 			connectedSignals["device-added"] = 1;
212 		}
213 		onDeviceAddedListeners ~= dlg;
214 	}
215 	extern(C) static void callBackDeviceAdded(GdkDeviceManager* deviceManagerStruct, GdkDevice* device, DeviceManager _deviceManager)
216 	{
217 		foreach ( void delegate(Device, DeviceManager) dlg ; _deviceManager.onDeviceAddedListeners )
218 		{
219 			dlg(ObjectG.getDObject!(Device)(device), _deviceManager);
220 		}
221 	}
222 	
223 	void delegate(Device, DeviceManager)[] onDeviceChangedListeners;
224 	/**
225 	 * The ::device-changed signal is emitted whenever a device
226 	 * has changed in the hierarchy, either slave devices being
227 	 * disconnected from their master device or connected to
228 	 * another one, or master devices being added or removed
229 	 * a slave device.
230 	 * If a slave device is detached from all master devices
231 	 * (gdk_device_get_associated_device() returns NULL), its
232 	 * GdkDeviceType will change to GDK_DEVICE_TYPE_FLOATING,
233 	 * if it's attached, it will change to GDK_DEVICE_TYPE_SLAVE.
234 	 */
235 	void addOnDeviceChanged(void delegate(Device, DeviceManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
236 	{
237 		if ( !("device-changed" in connectedSignals) )
238 		{
239 			Signals.connectData(
240 			getStruct(),
241 			"device-changed",
242 			cast(GCallback)&callBackDeviceChanged,
243 			cast(void*)this,
244 			null,
245 			connectFlags);
246 			connectedSignals["device-changed"] = 1;
247 		}
248 		onDeviceChangedListeners ~= dlg;
249 	}
250 	extern(C) static void callBackDeviceChanged(GdkDeviceManager* deviceManagerStruct, GdkDevice* device, DeviceManager _deviceManager)
251 	{
252 		foreach ( void delegate(Device, DeviceManager) dlg ; _deviceManager.onDeviceChangedListeners )
253 		{
254 			dlg(ObjectG.getDObject!(Device)(device), _deviceManager);
255 		}
256 	}
257 	
258 	void delegate(Device, DeviceManager)[] onDeviceRemovedListeners;
259 	/**
260 	 * The ::device-removed signal is emitted either when a master
261 	 * pointer is removed, or when a slave (Hardware) input device
262 	 * is unplugged.
263 	 * See Also
264 	 * GdkDevice, GdkEvent
265 	 */
266 	void addOnDeviceRemoved(void delegate(Device, DeviceManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
267 	{
268 		if ( !("device-removed" in connectedSignals) )
269 		{
270 			Signals.connectData(
271 			getStruct(),
272 			"device-removed",
273 			cast(GCallback)&callBackDeviceRemoved,
274 			cast(void*)this,
275 			null,
276 			connectFlags);
277 			connectedSignals["device-removed"] = 1;
278 		}
279 		onDeviceRemovedListeners ~= dlg;
280 	}
281 	extern(C) static void callBackDeviceRemoved(GdkDeviceManager* deviceManagerStruct, GdkDevice* device, DeviceManager _deviceManager)
282 	{
283 		foreach ( void delegate(Device, DeviceManager) dlg ; _deviceManager.onDeviceRemovedListeners )
284 		{
285 			dlg(ObjectG.getDObject!(Device)(device), _deviceManager);
286 		}
287 	}
288 	
289 	
290 	/**
291 	 * Disables multidevice support in GDK. This call must happen prior
292 	 * to gdk_display_open(), gtk_init(), gtk_init_with_args() or
293 	 * gtk_init_check() in order to take effect.
294 	 * Most common GTK+ applications won't ever need to call this. Only
295 	 * applications that do mixed GDK/Xlib calls could want to disable
296 	 * multidevice support if such Xlib code deals with input devices in
297 	 * any way and doesn't observe the presence of XInput 2.
298 	 * Since 3.0
299 	 */
300 	public static void disableMultidevice()
301 	{
302 		// void gdk_disable_multidevice (void);
303 		gdk_disable_multidevice();
304 	}
305 	
306 	/**
307 	 * Gets the GdkDisplay associated to device_manager.
308 	 * Returns: the GdkDisplay to which device_manager is associated to, or NULL. This memory is owned by GDK and must not be freed or unreferenced. [transfer none] Since 3.0
309 	 */
310 	public Display getDisplay()
311 	{
312 		// GdkDisplay * gdk_device_manager_get_display (GdkDeviceManager *device_manager);
313 		auto p = gdk_device_manager_get_display(gdkDeviceManager);
314 		
315 		if(p is null)
316 		{
317 			return null;
318 		}
319 		
320 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
321 	}
322 	
323 	/**
324 	 * Returns the list of devices of type type currently attached to
325 	 * device_manager.
326 	 * Params:
327 	 * type = device type to get.
328 	 * Returns: a list of GdkDevices. The returned list must be freed with g_list_free(). The list elements are owned by GTK+ and must not be freed or unreffed. [transfer container][element-type Gdk.Device] Since 3.0
329 	 */
330 	public GList* listDevices(GdkDeviceType type)
331 	{
332 		// GList * gdk_device_manager_list_devices (GdkDeviceManager *device_manager,  GdkDeviceType type);
333 		return gdk_device_manager_list_devices(gdkDeviceManager, type);
334 	}
335 	
336 	/**
337 	 * Returns the client pointer, that is, the master pointer that acts as the core pointer
338 	 * for this application. In X11, window managers may change this depending on the interaction
339 	 * pattern under the presence of several pointers.
340 	 * You should use this function seldomly, only in code that isn't triggered by a GdkEvent
341 	 * and there aren't other means to get a meaningful GdkDevice to operate on.
342 	 * Returns: The client pointer. This memory is owned by GDK and must not be freed or unreferenced. [transfer none] Since 3.0
343 	 */
344 	public Device getClientPointer()
345 	{
346 		// GdkDevice * gdk_device_manager_get_client_pointer  (GdkDeviceManager *device_manager);
347 		auto p = gdk_device_manager_get_client_pointer(gdkDeviceManager);
348 		
349 		if(p is null)
350 		{
351 			return null;
352 		}
353 		
354 		return ObjectG.getDObject!(Device)(cast(GdkDevice*) p);
355 	}
356 }