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