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