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.Display;
26 
27 private import gdk.AppLaunchContext;
28 private import gdk.Clipboard;
29 private import gdk.Device;
30 private import gdk.Event;
31 private import gdk.MonitorGdk;
32 private import gdk.Seat;
33 private import gdk.Surface;
34 private import gdk.c.functions;
35 public  import gdk.c.types;
36 private import gio.ListModelIF;
37 private import glib.ListG;
38 private import glib.Str;
39 private import glib.c.functions;
40 private import gobject.ObjectG;
41 private import gobject.Signals;
42 private import gobject.Value;
43 private import std.algorithm;
44 
45 
46 /**
47  * `GdkDisplay` objects are the GDK representation of a workstation.
48  * 
49  * Their purpose are two-fold:
50  * 
51  * - To manage and provide information about input devices (pointers, keyboards, etc)
52  * - To manage and provide information about output devices (monitors, projectors, etc)
53  * 
54  * Most of the input device handling has been factored out into separate
55  * [class@Gdk.Seat] objects. Every display has a one or more seats, which
56  * can be accessed with [method@Gdk.Display.get_default_seat] and
57  * [method@Gdk.Display.list_seats].
58  * 
59  * Output devices are represented by [class@Gdk.Monitor] objects, which can
60  * be accessed with [method@Gdk.Display.get_monitor_at_surface] and similar APIs.
61  */
62 public class Display : ObjectG
63 {
64 	/** the main Gtk struct */
65 	protected GdkDisplay* gdkDisplay;
66 
67 	/** Get the main Gtk struct */
68 	public GdkDisplay* getDisplayStruct(bool transferOwnership = false)
69 	{
70 		if (transferOwnership)
71 			ownedRef = false;
72 		return gdkDisplay;
73 	}
74 
75 	/** the main Gtk struct as a void* */
76 	protected override void* getStruct()
77 	{
78 		return cast(void*)gdkDisplay;
79 	}
80 
81 	/**
82 	 * Sets our main struct and passes it to the parent class.
83 	 */
84 	public this (GdkDisplay* gdkDisplay, bool ownedRef = false)
85 	{
86 		this.gdkDisplay = gdkDisplay;
87 		super(cast(GObject*)gdkDisplay, ownedRef);
88 	}
89 
90 
91 	/** */
92 	public static GType getType()
93 	{
94 		return gdk_display_get_type();
95 	}
96 
97 	/**
98 	 * Gets the default `GdkDisplay`.
99 	 *
100 	 * This is a convenience function for:
101 	 * `gdk_display_manager_get_default_display (gdk_display_manager_get ())`.
102 	 *
103 	 * Returns: a `GdkDisplay`, or %NULL if
104 	 *     there is no default display
105 	 */
106 	public static Display getDefault()
107 	{
108 		auto __p = gdk_display_get_default();
109 
110 		if(__p is null)
111 		{
112 			return null;
113 		}
114 
115 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
116 	}
117 
118 	/**
119 	 * Opens a display.
120 	 *
121 	 * Params:
122 	 *     displayName = the name of the display to open
123 	 *
124 	 * Returns: a `GdkDisplay`, or %NULL if the
125 	 *     display could not be opened
126 	 */
127 	public static Display open(string displayName)
128 	{
129 		auto __p = gdk_display_open(Str.toStringz(displayName));
130 
131 		if(__p is null)
132 		{
133 			return null;
134 		}
135 
136 		return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p);
137 	}
138 
139 	/**
140 	 * Emits a short beep on @display
141 	 */
142 	public void beep()
143 	{
144 		gdk_display_beep(gdkDisplay);
145 	}
146 
147 	/**
148 	 * Closes the connection to the windowing system for the given display.
149 	 *
150 	 * This cleans up associated resources.
151 	 */
152 	public void close()
153 	{
154 		gdk_display_close(gdkDisplay);
155 	}
156 
157 	/**
158 	 * Returns %TRUE if there is an ongoing grab on @device for @display.
159 	 *
160 	 * Params:
161 	 *     device = a `GdkDevice`
162 	 *
163 	 * Returns: %TRUE if there is a grab in effect for @device.
164 	 */
165 	public bool deviceIsGrabbed(Device device)
166 	{
167 		return gdk_display_device_is_grabbed(gdkDisplay, (device is null) ? null : device.getDeviceStruct()) != 0;
168 	}
169 
170 	/**
171 	 * Flushes any requests queued for the windowing system.
172 	 *
173 	 * This happens automatically when the main loop blocks waiting for new events,
174 	 * but if your application is drawing without returning control to the main loop,
175 	 * you may need to call this function explicitly. A common case where this function
176 	 * needs to be called is when an application is executing drawing commands
177 	 * from a thread other than the thread where the main loop is running.
178 	 *
179 	 * This is most useful for X11. On windowing systems where requests are
180 	 * handled synchronously, this function will do nothing.
181 	 */
182 	public void flush()
183 	{
184 		gdk_display_flush(gdkDisplay);
185 	}
186 
187 	/**
188 	 * Returns a `GdkAppLaunchContext` suitable for launching
189 	 * applications on the given display.
190 	 *
191 	 * Returns: a new `GdkAppLaunchContext` for @display.
192 	 *     Free with g_object_unref() when done
193 	 */
194 	public AppLaunchContext getAppLaunchContext()
195 	{
196 		auto __p = gdk_display_get_app_launch_context(gdkDisplay);
197 
198 		if(__p is null)
199 		{
200 			return null;
201 		}
202 
203 		return ObjectG.getDObject!(AppLaunchContext)(cast(GdkAppLaunchContext*) __p, true);
204 	}
205 
206 	/**
207 	 * Gets the clipboard used for copy/paste operations.
208 	 *
209 	 * Returns: the display's clipboard
210 	 */
211 	public Clipboard getClipboard()
212 	{
213 		auto __p = gdk_display_get_clipboard(gdkDisplay);
214 
215 		if(__p is null)
216 		{
217 			return null;
218 		}
219 
220 		return ObjectG.getDObject!(Clipboard)(cast(GdkClipboard*) __p);
221 	}
222 
223 	/**
224 	 * Returns the default `GdkSeat` for this display.
225 	 *
226 	 * Note that a display may not have a seat. In this case,
227 	 * this function will return %NULL.
228 	 *
229 	 * Returns: the default seat.
230 	 */
231 	public Seat getDefaultSeat()
232 	{
233 		auto __p = gdk_display_get_default_seat(gdkDisplay);
234 
235 		if(__p is null)
236 		{
237 			return null;
238 		}
239 
240 		return ObjectG.getDObject!(Seat)(cast(GdkSeat*) __p);
241 	}
242 
243 	/**
244 	 * Gets the monitor in which the largest area of @surface
245 	 * resides.
246 	 *
247 	 * Returns a monitor close to @surface if it is outside
248 	 * of all monitors.
249 	 *
250 	 * Params:
251 	 *     surface = a `GdkSurface`
252 	 *
253 	 * Returns: the monitor with the largest
254 	 *     overlap with @surface
255 	 */
256 	public MonitorGdk getMonitorAtSurface(Surface surface)
257 	{
258 		auto __p = gdk_display_get_monitor_at_surface(gdkDisplay, (surface is null) ? null : surface.getSurfaceStruct());
259 
260 		if(__p is null)
261 		{
262 			return null;
263 		}
264 
265 		return ObjectG.getDObject!(MonitorGdk)(cast(GdkMonitor*) __p);
266 	}
267 
268 	/**
269 	 * Gets the list of monitors associated with this display.
270 	 *
271 	 * Subsequent calls to this function will always return the
272 	 * same list for the same display.
273 	 *
274 	 * You can listen to the GListModel::items-changed signal on
275 	 * this list to monitor changes to the monitor of this display.
276 	 *
277 	 * Returns: a #GListModel of `GdkMonitor`
278 	 */
279 	public ListModelIF getMonitors()
280 	{
281 		auto __p = gdk_display_get_monitors(gdkDisplay);
282 
283 		if(__p is null)
284 		{
285 			return null;
286 		}
287 
288 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p);
289 	}
290 
291 	/**
292 	 * Gets the name of the display.
293 	 *
294 	 * Returns: a string representing the display name. This string is owned
295 	 *     by GDK and should not be modified or freed.
296 	 */
297 	public string getName()
298 	{
299 		return Str.toString(gdk_display_get_name(gdkDisplay));
300 	}
301 
302 	/**
303 	 * Gets the clipboard used for the primary selection.
304 	 *
305 	 * On backends where the primary clipboard is not supported natively,
306 	 * GDK emulates this clipboard locally.
307 	 *
308 	 * Returns: the primary clipboard
309 	 */
310 	public Clipboard getPrimaryClipboard()
311 	{
312 		auto __p = gdk_display_get_primary_clipboard(gdkDisplay);
313 
314 		if(__p is null)
315 		{
316 			return null;
317 		}
318 
319 		return ObjectG.getDObject!(Clipboard)(cast(GdkClipboard*) __p);
320 	}
321 
322 	/**
323 	 * Retrieves a desktop-wide setting such as double-click time
324 	 * for the @display.
325 	 *
326 	 * Params:
327 	 *     name = the name of the setting
328 	 *     value = location to store the value of the setting
329 	 *
330 	 * Returns: %TRUE if the setting existed and a value was stored
331 	 *     in @value, %FALSE otherwise
332 	 */
333 	public bool getSetting(string name, Value value)
334 	{
335 		return gdk_display_get_setting(gdkDisplay, Str.toStringz(name), (value is null) ? null : value.getValueStruct()) != 0;
336 	}
337 
338 	/**
339 	 * Gets the startup notification ID for a Wayland display, or %NULL
340 	 * if no ID has been defined.
341 	 *
342 	 * Returns: the startup notification ID for @display, or %NULL
343 	 */
344 	public string getStartupNotificationId()
345 	{
346 		return Str.toString(gdk_display_get_startup_notification_id(gdkDisplay));
347 	}
348 
349 	/**
350 	 * Finds out if the display has been closed.
351 	 *
352 	 * Returns: %TRUE if the display is closed.
353 	 */
354 	public bool isClosed()
355 	{
356 		return gdk_display_is_closed(gdkDisplay) != 0;
357 	}
358 
359 	/**
360 	 * Returns whether surfaces can reasonably be expected to have
361 	 * their alpha channel drawn correctly on the screen.
362 	 *
363 	 * Check [method@Gdk.Display.is_rgba] for whether the display
364 	 * supports an alpha channel.
365 	 *
366 	 * On X11 this function returns whether a compositing manager is
367 	 * compositing on @display.
368 	 *
369 	 * On modern displays, this value is always %TRUE.
370 	 *
371 	 * Returns: Whether surfaces with RGBA visuals can reasonably
372 	 *     be expected to have their alpha channels drawn correctly
373 	 *     on the screen.
374 	 */
375 	public bool isComposited()
376 	{
377 		return gdk_display_is_composited(gdkDisplay) != 0;
378 	}
379 
380 	/**
381 	 * Returns whether surfaces on this @display are created with an
382 	 * alpha channel.
383 	 *
384 	 * Even if a %TRUE is returned, it is possible that the
385 	 * surface’s alpha channel won’t be honored when displaying the
386 	 * surface on the screen: in particular, for X an appropriate
387 	 * windowing manager and compositing manager must be running to
388 	 * provide appropriate display. Use [method@Gdk.Display.is_composited]
389 	 * to check if that is the case.
390 	 *
391 	 * On modern displays, this value is always %TRUE.
392 	 *
393 	 * Returns: %TRUE if surfaces are created with an alpha channel or
394 	 *     %FALSE if the display does not support this functionality.
395 	 */
396 	public bool isRgba()
397 	{
398 		return gdk_display_is_rgba(gdkDisplay) != 0;
399 	}
400 
401 	/**
402 	 * Returns the list of seats known to @display.
403 	 *
404 	 * Returns: the
405 	 *     list of seats known to the `GdkDisplay`
406 	 */
407 	public ListG listSeats()
408 	{
409 		auto __p = gdk_display_list_seats(gdkDisplay);
410 
411 		if(__p is null)
412 		{
413 			return null;
414 		}
415 
416 		return new ListG(cast(GList*) __p);
417 	}
418 
419 	/**
420 	 * Returns the keyvals bound to @keycode.
421 	 *
422 	 * The Nth `GdkKeymapKey` in @keys is bound to the Nth keyval in @keyvals.
423 	 *
424 	 * When a keycode is pressed by the user, the keyval from
425 	 * this list of entries is selected by considering the effective
426 	 * keyboard group and level.
427 	 *
428 	 * Free the returned arrays with g_free().
429 	 *
430 	 * Params:
431 	 *     keycode = a keycode
432 	 *     keys = return
433 	 *         location for array of `GdkKeymapKey`, or %NULL
434 	 *     keyvals = return
435 	 *         location for array of keyvals, or %NULL
436 	 *
437 	 * Returns: %TRUE if there were any entries
438 	 */
439 	public bool mapKeycode(uint keycode, out GdkKeymapKey[] keys, out uint[] keyvals)
440 	{
441 		GdkKeymapKey* outkeys;
442 		uint* outkeyvals;
443 		int nEntries;
444 
445 		auto __p = gdk_display_map_keycode(gdkDisplay, keycode, &outkeys, &outkeyvals, &nEntries) != 0;
446 
447 		keys = outkeys[0 .. nEntries];
448 		keyvals = outkeyvals[0 .. nEntries];
449 
450 		return __p;
451 	}
452 
453 	/**
454 	 * Obtains a list of keycode/group/level combinations that will
455 	 * generate @keyval.
456 	 *
457 	 * Groups and levels are two kinds of keyboard mode; in general, the level
458 	 * determines whether the top or bottom symbol on a key is used, and the
459 	 * group determines whether the left or right symbol is used.
460 	 *
461 	 * On US keyboards, the shift key changes the keyboard level, and there
462 	 * are no groups. A group switch key might convert a keyboard between
463 	 * Hebrew to English modes, for example.
464 	 *
465 	 * `GdkEventKey` contains a %group field that indicates the active
466 	 * keyboard group. The level is computed from the modifier mask.
467 	 *
468 	 * The returned array should be freed with g_free().
469 	 *
470 	 * Params:
471 	 *     keyval = a keyval, such as %GDK_KEY_a, %GDK_KEY_Up, %GDK_KEY_Return, etc.
472 	 *     keys = return location
473 	 *         for an array of `GdkKeymapKey`
474 	 *
475 	 * Returns: %TRUE if keys were found and returned
476 	 */
477 	public bool mapKeyval(uint keyval, out GdkKeymapKey[] keys)
478 	{
479 		GdkKeymapKey* outkeys;
480 		int nKeys;
481 
482 		auto __p = gdk_display_map_keyval(gdkDisplay, keyval, &outkeys, &nKeys) != 0;
483 
484 		keys = outkeys[0 .. nKeys];
485 
486 		return __p;
487 	}
488 
489 	/**
490 	 * Indicates to the GUI environment that the application has
491 	 * finished loading, using a given identifier.
492 	 *
493 	 * GTK will call this function automatically for [class@Gtk.Window]
494 	 * with custom startup-notification identifier unless
495 	 * [method@Gtk.Window.set_auto_startup_notification]
496 	 * is called to disable that feature.
497 	 *
498 	 * Params:
499 	 *     startupId = a startup-notification identifier, for which
500 	 *         notification process should be completed
501 	 */
502 	public void notifyStartupComplete(string startupId)
503 	{
504 		gdk_display_notify_startup_complete(gdkDisplay, Str.toStringz(startupId));
505 	}
506 
507 	/**
508 	 * Appends the given event onto the front of the event
509 	 * queue for @display.
510 	 *
511 	 * This function is only useful in very special situations
512 	 * and should not be used by applications.
513 	 *
514 	 * Params:
515 	 *     event = a `GdkEvent`
516 	 */
517 	public void putEvent(Event event)
518 	{
519 		gdk_display_put_event(gdkDisplay, (event is null) ? null : event.getEventStruct());
520 	}
521 
522 	/**
523 	 * Returns %TRUE if the display supports input shapes.
524 	 *
525 	 * This means that [method@Gdk.Surface.set_input_region] can
526 	 * be used to modify the input shape of surfaces on @display.
527 	 *
528 	 * On modern displays, this value is always %TRUE.
529 	 *
530 	 * Returns: %TRUE if surfaces with modified input shape are supported
531 	 */
532 	public bool supportsInputShapes()
533 	{
534 		return gdk_display_supports_input_shapes(gdkDisplay) != 0;
535 	}
536 
537 	/**
538 	 * Flushes any requests queued for the windowing system and waits until all
539 	 * requests have been handled.
540 	 *
541 	 * This is often used for making sure that the display is synchronized
542 	 * with the current state of the program. Calling [method@Gdk.Display.sync]
543 	 * before [method@GdkX11.Display.error_trap_pop] makes sure that any errors
544 	 * generated from earlier requests are handled before the error trap is removed.
545 	 *
546 	 * This is most useful for X11. On windowing systems where requests are
547 	 * handled synchronously, this function will do nothing.
548 	 */
549 	public void sync()
550 	{
551 		gdk_display_sync(gdkDisplay);
552 	}
553 
554 	/**
555 	 * Translates the contents of a `GdkEventKey` into a keyval, effective group,
556 	 * and level.
557 	 *
558 	 * Modifiers that affected the translation and are thus unavailable for
559 	 * application use are returned in @consumed_modifiers.
560 	 *
561 	 * The @effective_group is the group that was actually used for the
562 	 * translation; some keys such as Enter are not affected by the active
563 	 * keyboard group. The @level is derived from @state.
564 	 *
565 	 * @consumed_modifiers gives modifiers that should be masked out
566 	 * from @state when comparing this key press to a keyboard shortcut.
567 	 * For instance, on a US keyboard, the `plus` symbol is shifted, so
568 	 * when comparing a key press to a `<Control>plus` accelerator `<Shift>`
569 	 * should be masked out.
570 	 *
571 	 * This function should rarely be needed, since `GdkEventKey` already
572 	 * contains the translated keyval. It is exported for the benefit of
573 	 * virtualized test environments.
574 	 *
575 	 * Params:
576 	 *     keycode = a keycode
577 	 *     state = a modifier state
578 	 *     group = active keyboard group
579 	 *     keyval = return location for keyval, or %NULL
580 	 *     effectiveGroup = return location for effective
581 	 *         group, or %NULL
582 	 *     level = return location for level, or %NULL
583 	 *     consumed = return location for modifiers
584 	 *         that were used to determine the group or level, or %NULL
585 	 *
586 	 * Returns: %TRUE if there was a keyval bound to keycode/state/group.
587 	 */
588 	public bool translateKey(uint keycode, GdkModifierType state, int group, out uint keyval, out int effectiveGroup, out int level, out GdkModifierType consumed)
589 	{
590 		return gdk_display_translate_key(gdkDisplay, keycode, state, group, &keyval, &effectiveGroup, &level, &consumed) != 0;
591 	}
592 
593 	/**
594 	 * Emitted when the connection to the windowing system for @display is closed.
595 	 *
596 	 * Params:
597 	 *     isError = %TRUE if the display was closed due to an error
598 	 */
599 	gulong addOnClosed(void delegate(bool, Display) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
600 	{
601 		return Signals.connect(this, "closed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
602 	}
603 
604 	/**
605 	 * Emitted when the connection to the windowing system for @display is opened.
606 	 */
607 	gulong addOnOpened(void delegate(Display) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
608 	{
609 		return Signals.connect(this, "opened", dlg, connectFlags ^ ConnectFlags.SWAPPED);
610 	}
611 
612 	/**
613 	 * Emitted whenever a new seat is made known to the windowing system.
614 	 *
615 	 * Params:
616 	 *     seat = the seat that was just added
617 	 */
618 	gulong addOnSeatAdded(void delegate(Seat, Display) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
619 	{
620 		return Signals.connect(this, "seat-added", dlg, connectFlags ^ ConnectFlags.SWAPPED);
621 	}
622 
623 	/**
624 	 * Emitted whenever a seat is removed by the windowing system.
625 	 *
626 	 * Params:
627 	 *     seat = the seat that was just removed
628 	 */
629 	gulong addOnSeatRemoved(void delegate(Seat, Display) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
630 	{
631 		return Signals.connect(this, "seat-removed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
632 	}
633 
634 	/**
635 	 * Emitted whenever a setting changes its value.
636 	 *
637 	 * Params:
638 	 *     setting = the name of the setting that changed
639 	 */
640 	gulong addOnSettingChanged(void delegate(string, Display) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
641 	{
642 		return Signals.connect(this, "setting-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
643 	}
644 }