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