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.Seat;
26 
27 private import gdk.Cursor;
28 private import gdk.Device;
29 private import gdk.DeviceTool;
30 private import gdk.Display;
31 private import gdk.Event;
32 private import gdk.Window;
33 private import glib.ListG;
34 private import gobject.ObjectG;
35 private import gobject.Signals;
36 private import gtkc.gdk;
37 public  import gtkc.gdktypes;
38 private import std.algorithm;
39 
40 
41 /**
42  * The #GdkSeat object represents a collection of input devices
43  * that belong to a user.
44  */
45 public class Seat : ObjectG
46 {
47 	/** the main Gtk struct */
48 	protected GdkSeat* gdkSeat;
49 
50 	/** Get the main Gtk struct */
51 	public GdkSeat* getSeatStruct()
52 	{
53 		return gdkSeat;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected override void* getStruct()
58 	{
59 		return cast(void*)gdkSeat;
60 	}
61 
62 	protected override void setStruct(GObject* obj)
63 	{
64 		gdkSeat = cast(GdkSeat*)obj;
65 		super.setStruct(obj);
66 	}
67 
68 	/**
69 	 * Sets our main struct and passes it to the parent class.
70 	 */
71 	public this (GdkSeat* gdkSeat, bool ownedRef = false)
72 	{
73 		this.gdkSeat = gdkSeat;
74 		super(cast(GObject*)gdkSeat, ownedRef);
75 	}
76 
77 
78 	/** */
79 	public static GType getType()
80 	{
81 		return gdk_seat_get_type();
82 	}
83 
84 	/**
85 	 * Returns the capabilities this #GdkSeat currently has.
86 	 *
87 	 * Return: the seat capabilities
88 	 *
89 	 * Since: 3.20
90 	 */
91 	public GdkSeatCapabilities getCapabilities()
92 	{
93 		return gdk_seat_get_capabilities(gdkSeat);
94 	}
95 
96 	/**
97 	 * Returns the #GdkDisplay this seat belongs to.
98 	 *
99 	 * Return: a #GdkDisplay. This object is owned by GTK+
100 	 *     and must not be freed.
101 	 */
102 	public Display getDisplay()
103 	{
104 		auto p = gdk_seat_get_display(gdkSeat);
105 		
106 		if(p is null)
107 		{
108 			return null;
109 		}
110 		
111 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p);
112 	}
113 
114 	/**
115 	 * Returns the master device that routes keyboard events.
116 	 *
117 	 * Return: a master #GdkDevice with keyboard
118 	 *     capabilities. This object is owned by GTK+ and must not be freed.
119 	 *
120 	 * Since: 3.20
121 	 */
122 	public Device getKeyboard()
123 	{
124 		auto p = gdk_seat_get_keyboard(gdkSeat);
125 		
126 		if(p is null)
127 		{
128 			return null;
129 		}
130 		
131 		return ObjectG.getDObject!(Device)(cast(GdkDevice*) p);
132 	}
133 
134 	/**
135 	 * Returns the master device that routes pointer events.
136 	 *
137 	 * Return: a master #GdkDevice with pointer
138 	 *     capabilities. This object is owned by GTK+ and must not be freed.
139 	 *
140 	 * Since: 3.20
141 	 */
142 	public Device getPointer()
143 	{
144 		auto p = gdk_seat_get_pointer(gdkSeat);
145 		
146 		if(p is null)
147 		{
148 			return null;
149 		}
150 		
151 		return ObjectG.getDObject!(Device)(cast(GdkDevice*) p);
152 	}
153 
154 	/**
155 	 * Returns the slave devices that match the given capabilities.
156 	 *
157 	 * Params:
158 	 *     capabilities = capabilities to get devices for
159 	 *
160 	 * Return: A list of #GdkDevices.
161 	 *     The list must be freed with g_list_free(), the elements are owned
162 	 *     by GDK and must not be freed.
163 	 *
164 	 * Since: 3.20
165 	 */
166 	public ListG getSlaves(GdkSeatCapabilities capabilities)
167 	{
168 		auto p = gdk_seat_get_slaves(gdkSeat, capabilities);
169 		
170 		if(p is null)
171 		{
172 			return null;
173 		}
174 		
175 		return new ListG(cast(GList*) p);
176 	}
177 
178 	/**
179 	 * Grabs the seat so that all events corresponding to the given @capabilities
180 	 * are passed to this application until the seat is ungrabbed with gdk_seat_ungrab(),
181 	 * or the window becomes hidden. This overrides any previous grab on the
182 	 * seat by this client.
183 	 *
184 	 * As a rule of thumb, if a grab is desired over %GDK_SEAT_CAPABILITY_POINTER,
185 	 * all other "pointing" capabilities (eg. %GDK_SEAT_CAPABILITY_TOUCH) should
186 	 * be grabbed too, so the user is able to interact with all of those while
187 	 * the grab holds, you should thus use %GDK_SEAT_CAPABILITY_ALL_POINTING most
188 	 * commonly.
189 	 *
190 	 * Grabs are used for operations which need complete control over the
191 	 * events corresponding to the given capabilities. For example in GTK+ this
192 	 * is used for Drag and Drop operations, popup menus and such.
193 	 *
194 	 * Note that if the event mask of a #GdkWindow has selected both button press
195 	 * and button release events, or touch begin and touch end, then a press event
196 	 * will cause an automatic grab until the button is released, equivalent to a
197 	 * grab on the window with @owner_events set to %TRUE. This is done because most
198 	 * applications expect to receive paired press and release events.
199 	 *
200 	 * If you set up anything at the time you take the grab that needs to be
201 	 * cleaned up when the grab ends, you should handle the #GdkEventGrabBroken
202 	 * events that are emitted when the grab ends unvoluntarily.
203 	 *
204 	 * Params:
205 	 *     window = the #GdkWindow which will own the grab
206 	 *     capabilities = capabilities that will be grabbed
207 	 *     ownerEvents = if %FALSE then all device events are reported with respect to
208 	 *         @window and are only reported if selected by @event_mask. If
209 	 *         %TRUE then pointer events for this application are reported
210 	 *         as normal, but pointer events outside this application are
211 	 *         reported with respect to @window and only if selected by
212 	 *         @event_mask. In either mode, unreported events are discarded.
213 	 *     cursor = the cursor to display while the grab is active. If
214 	 *         this is %NULL then the normal cursors are used for
215 	 *         @window and its descendants, and the cursor for @window is used
216 	 *         elsewhere.
217 	 *     event = the event that is triggering the grab, or %NULL if none
218 	 *         is available.
219 	 *     prepareFunc = function to
220 	 *         prepare the window to be grabbed, it can be %NULL if @window is
221 	 *         visible before this call.
222 	 *     prepareFuncData = user data to pass to @prepare_func
223 	 *
224 	 * Return: %GDK_GRAB_SUCCESS if the grab was successful.
225 	 *
226 	 * Since: 3.20
227 	 */
228 	public GdkGrabStatus grab(Window window, GdkSeatCapabilities capabilities, bool ownerEvents, Cursor cursor, Event event, GdkSeatGrabPrepareFunc prepareFunc, void* prepareFuncData)
229 	{
230 		return gdk_seat_grab(gdkSeat, (window is null) ? null : window.getWindowStruct(), capabilities, ownerEvents, (cursor is null) ? null : cursor.getCursorStruct(), (event is null) ? null : event.getEventStruct(), prepareFunc, prepareFuncData);
231 	}
232 
233 	/**
234 	 * Releases a grab added through gdk_seat_grab().
235 	 *
236 	 * Since: 3.20
237 	 */
238 	public void ungrab()
239 	{
240 		gdk_seat_ungrab(gdkSeat);
241 	}
242 
243 	protected class OnDeviceAddedDelegateWrapper
244 	{
245 		void delegate(Device, Seat) dlg;
246 		gulong handlerId;
247 		ConnectFlags flags;
248 		this(void delegate(Device, Seat) dlg, gulong handlerId, ConnectFlags flags)
249 		{
250 			this.dlg = dlg;
251 			this.handlerId = handlerId;
252 			this.flags = flags;
253 		}
254 	}
255 	protected OnDeviceAddedDelegateWrapper[] onDeviceAddedListeners;
256 
257 	/**
258 	 * The ::device-added signal is emitted when a new input
259 	 * device is related to this seat.
260 	 *
261 	 * Params:
262 	 *     device = the newly added #GdkDevice.
263 	 *
264 	 * Since: 3.20
265 	 */
266 	gulong addOnDeviceAdded(void delegate(Device, Seat) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
267 	{
268 		onDeviceAddedListeners ~= new OnDeviceAddedDelegateWrapper(dlg, 0, connectFlags);
269 		onDeviceAddedListeners[onDeviceAddedListeners.length - 1].handlerId = Signals.connectData(
270 			this,
271 			"device-added",
272 			cast(GCallback)&callBackDeviceAdded,
273 			cast(void*)onDeviceAddedListeners[onDeviceAddedListeners.length - 1],
274 			cast(GClosureNotify)&callBackDeviceAddedDestroy,
275 			connectFlags);
276 		return onDeviceAddedListeners[onDeviceAddedListeners.length - 1].handlerId;
277 	}
278 	
279 	extern(C) static void callBackDeviceAdded(GdkSeat* seatStruct, GdkDevice* device,OnDeviceAddedDelegateWrapper wrapper)
280 	{
281 		wrapper.dlg(ObjectG.getDObject!(Device)(device), wrapper.outer);
282 	}
283 	
284 	extern(C) static void callBackDeviceAddedDestroy(OnDeviceAddedDelegateWrapper wrapper, GClosure* closure)
285 	{
286 		wrapper.outer.internalRemoveOnDeviceAdded(wrapper);
287 	}
288 
289 	protected void internalRemoveOnDeviceAdded(OnDeviceAddedDelegateWrapper source)
290 	{
291 		foreach(index, wrapper; onDeviceAddedListeners)
292 		{
293 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
294 			{
295 				onDeviceAddedListeners[index] = null;
296 				onDeviceAddedListeners = std.algorithm.remove(onDeviceAddedListeners, index);
297 				break;
298 			}
299 		}
300 	}
301 	
302 
303 	protected class OnDeviceRemovedDelegateWrapper
304 	{
305 		void delegate(Device, Seat) dlg;
306 		gulong handlerId;
307 		ConnectFlags flags;
308 		this(void delegate(Device, Seat) dlg, gulong handlerId, ConnectFlags flags)
309 		{
310 			this.dlg = dlg;
311 			this.handlerId = handlerId;
312 			this.flags = flags;
313 		}
314 	}
315 	protected OnDeviceRemovedDelegateWrapper[] onDeviceRemovedListeners;
316 
317 	/**
318 	 * The ::device-removed signal is emitted when an
319 	 * input device is removed (e.g. unplugged).
320 	 *
321 	 * Params:
322 	 *     device = the just removed #GdkDevice.
323 	 *
324 	 * Since: 3.20
325 	 */
326 	gulong addOnDeviceRemoved(void delegate(Device, Seat) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
327 	{
328 		onDeviceRemovedListeners ~= new OnDeviceRemovedDelegateWrapper(dlg, 0, connectFlags);
329 		onDeviceRemovedListeners[onDeviceRemovedListeners.length - 1].handlerId = Signals.connectData(
330 			this,
331 			"device-removed",
332 			cast(GCallback)&callBackDeviceRemoved,
333 			cast(void*)onDeviceRemovedListeners[onDeviceRemovedListeners.length - 1],
334 			cast(GClosureNotify)&callBackDeviceRemovedDestroy,
335 			connectFlags);
336 		return onDeviceRemovedListeners[onDeviceRemovedListeners.length - 1].handlerId;
337 	}
338 	
339 	extern(C) static void callBackDeviceRemoved(GdkSeat* seatStruct, GdkDevice* device,OnDeviceRemovedDelegateWrapper wrapper)
340 	{
341 		wrapper.dlg(ObjectG.getDObject!(Device)(device), wrapper.outer);
342 	}
343 	
344 	extern(C) static void callBackDeviceRemovedDestroy(OnDeviceRemovedDelegateWrapper wrapper, GClosure* closure)
345 	{
346 		wrapper.outer.internalRemoveOnDeviceRemoved(wrapper);
347 	}
348 
349 	protected void internalRemoveOnDeviceRemoved(OnDeviceRemovedDelegateWrapper source)
350 	{
351 		foreach(index, wrapper; onDeviceRemovedListeners)
352 		{
353 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
354 			{
355 				onDeviceRemovedListeners[index] = null;
356 				onDeviceRemovedListeners = std.algorithm.remove(onDeviceRemovedListeners, index);
357 				break;
358 			}
359 		}
360 	}
361 	
362 
363 	protected class OnToolAddedDelegateWrapper
364 	{
365 		void delegate(DeviceTool, Seat) dlg;
366 		gulong handlerId;
367 		ConnectFlags flags;
368 		this(void delegate(DeviceTool, Seat) dlg, gulong handlerId, ConnectFlags flags)
369 		{
370 			this.dlg = dlg;
371 			this.handlerId = handlerId;
372 			this.flags = flags;
373 		}
374 	}
375 	protected OnToolAddedDelegateWrapper[] onToolAddedListeners;
376 
377 	/**
378 	 * The ::tool-added signal is emitted whenever a new tool
379 	 * is made known to the seat. The tool may later be assigned
380 	 * to a device (i.e. on proximity with a tablet). The device
381 	 * will emit the #GdkDevice::tool-changed signal accordingly.
382 	 *
383 	 * A same tool may be used by several devices.
384 	 *
385 	 * Params:
386 	 *     tool = the new #GdkDeviceTool known to the seat
387 	 *
388 	 * Since: 3.22
389 	 */
390 	gulong addOnToolAdded(void delegate(DeviceTool, Seat) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
391 	{
392 		onToolAddedListeners ~= new OnToolAddedDelegateWrapper(dlg, 0, connectFlags);
393 		onToolAddedListeners[onToolAddedListeners.length - 1].handlerId = Signals.connectData(
394 			this,
395 			"tool-added",
396 			cast(GCallback)&callBackToolAdded,
397 			cast(void*)onToolAddedListeners[onToolAddedListeners.length - 1],
398 			cast(GClosureNotify)&callBackToolAddedDestroy,
399 			connectFlags);
400 		return onToolAddedListeners[onToolAddedListeners.length - 1].handlerId;
401 	}
402 	
403 	extern(C) static void callBackToolAdded(GdkSeat* seatStruct, GdkDeviceTool* tool,OnToolAddedDelegateWrapper wrapper)
404 	{
405 		wrapper.dlg(ObjectG.getDObject!(DeviceTool)(tool), wrapper.outer);
406 	}
407 	
408 	extern(C) static void callBackToolAddedDestroy(OnToolAddedDelegateWrapper wrapper, GClosure* closure)
409 	{
410 		wrapper.outer.internalRemoveOnToolAdded(wrapper);
411 	}
412 
413 	protected void internalRemoveOnToolAdded(OnToolAddedDelegateWrapper source)
414 	{
415 		foreach(index, wrapper; onToolAddedListeners)
416 		{
417 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
418 			{
419 				onToolAddedListeners[index] = null;
420 				onToolAddedListeners = std.algorithm.remove(onToolAddedListeners, index);
421 				break;
422 			}
423 		}
424 	}
425 	
426 
427 	protected class OnToolRemovedDelegateWrapper
428 	{
429 		void delegate(DeviceTool, Seat) dlg;
430 		gulong handlerId;
431 		ConnectFlags flags;
432 		this(void delegate(DeviceTool, Seat) dlg, gulong handlerId, ConnectFlags flags)
433 		{
434 			this.dlg = dlg;
435 			this.handlerId = handlerId;
436 			this.flags = flags;
437 		}
438 	}
439 	protected OnToolRemovedDelegateWrapper[] onToolRemovedListeners;
440 
441 	/**
442 	 * This signal is emitted whenever a tool is no longer known
443 	 * to this @seat.
444 	 *
445 	 * Params:
446 	 *     tool = the just removed #GdkDeviceTool
447 	 *
448 	 * Since: 3.22
449 	 */
450 	gulong addOnToolRemoved(void delegate(DeviceTool, Seat) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
451 	{
452 		onToolRemovedListeners ~= new OnToolRemovedDelegateWrapper(dlg, 0, connectFlags);
453 		onToolRemovedListeners[onToolRemovedListeners.length - 1].handlerId = Signals.connectData(
454 			this,
455 			"tool-removed",
456 			cast(GCallback)&callBackToolRemoved,
457 			cast(void*)onToolRemovedListeners[onToolRemovedListeners.length - 1],
458 			cast(GClosureNotify)&callBackToolRemovedDestroy,
459 			connectFlags);
460 		return onToolRemovedListeners[onToolRemovedListeners.length - 1].handlerId;
461 	}
462 	
463 	extern(C) static void callBackToolRemoved(GdkSeat* seatStruct, GdkDeviceTool* tool,OnToolRemovedDelegateWrapper wrapper)
464 	{
465 		wrapper.dlg(ObjectG.getDObject!(DeviceTool)(tool), wrapper.outer);
466 	}
467 	
468 	extern(C) static void callBackToolRemovedDestroy(OnToolRemovedDelegateWrapper wrapper, GClosure* closure)
469 	{
470 		wrapper.outer.internalRemoveOnToolRemoved(wrapper);
471 	}
472 
473 	protected void internalRemoveOnToolRemoved(OnToolRemovedDelegateWrapper source)
474 	{
475 		foreach(index, wrapper; onToolRemovedListeners)
476 		{
477 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
478 			{
479 				onToolRemovedListeners[index] = null;
480 				onToolRemovedListeners = std.algorithm.remove(onToolRemovedListeners, index);
481 				break;
482 			}
483 		}
484 	}
485 	
486 }