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.Gdk;
26 
27 private import gdk.Cursor;
28 private import gdk.Window;
29 private import gdk.c.functions;
30 public  import gdk.c.types;
31 private import glib.Str;
32 public  import gtkc.gdktypes;
33 
34 
35 /** */
36 public struct Gdk
37 {
38 
39 	/**
40 	 * Emits a short beep on the default display.
41 	 */
42 	public static void beep()
43 	{
44 		gdk_beep();
45 	}
46 
47 	/**
48 	 * Removes an error trap pushed with gdk_error_trap_push().
49 	 * May block until an error has been definitively received
50 	 * or not received from the X server. gdk_error_trap_pop_ignored()
51 	 * is preferred if you don’t need to know whether an error
52 	 * occurred, because it never has to block. If you don't
53 	 * need the return value of gdk_error_trap_pop(), use
54 	 * gdk_error_trap_pop_ignored().
55 	 *
56 	 * Prior to GDK 3.0, this function would not automatically
57 	 * sync for you, so you had to gdk_flush() if your last
58 	 * call to Xlib was not a blocking round trip.
59 	 *
60 	 * Returns: X error code or 0 on success
61 	 */
62 	public static int errorTrapPop()
63 	{
64 		return gdk_error_trap_pop();
65 	}
66 
67 	/**
68 	 * Removes an error trap pushed with gdk_error_trap_push(), but
69 	 * without bothering to wait and see whether an error occurred.  If an
70 	 * error arrives later asynchronously that was triggered while the
71 	 * trap was pushed, that error will be ignored.
72 	 *
73 	 * Since: 3.0
74 	 */
75 	public static void errorTrapPopIgnored()
76 	{
77 		gdk_error_trap_pop_ignored();
78 	}
79 
80 	/**
81 	 * This function allows X errors to be trapped instead of the normal
82 	 * behavior of exiting the application. It should only be used if it
83 	 * is not possible to avoid the X error in any other way. Errors are
84 	 * ignored on all #GdkDisplay currently known to the
85 	 * #GdkDisplayManager. If you don’t care which error happens and just
86 	 * want to ignore everything, pop with gdk_error_trap_pop_ignored().
87 	 * If you need the error code, use gdk_error_trap_pop() which may have
88 	 * to block and wait for the error to arrive from the X server.
89 	 *
90 	 * This API exists on all platforms but only does anything on X.
91 	 *
92 	 * You can use gdk_x11_display_error_trap_push() to ignore errors
93 	 * on only a single display.
94 	 *
95 	 * ## Trapping an X error
96 	 *
97 	 * |[<!-- language="C" -->
98 	 * gdk_error_trap_push ();
99 	 *
100 	 * // ... Call the X function which may cause an error here ...
101 	 *
102 	 *
103 	 * if (gdk_error_trap_pop ())
104 	 * {
105 	 * // ... Handle the error here ...
106 	 * }
107 	 * ]|
108 	 */
109 	public static void errorTrapPush()
110 	{
111 		gdk_error_trap_push();
112 	}
113 
114 	/**
115 	 * Flushes the output buffers of all display connections and waits
116 	 * until all requests have been processed.
117 	 * This is rarely needed by applications.
118 	 */
119 	public static void flush()
120 	{
121 		gdk_flush();
122 	}
123 
124 	/**
125 	 * Gets the name of the display, which usually comes from the
126 	 * `DISPLAY` environment variable or the
127 	 * `--display` command line option.
128 	 *
129 	 * Deprecated: Call gdk_display_get_name (gdk_display_get_default ()))
130 	 * instead.
131 	 *
132 	 * Returns: the name of the display.
133 	 */
134 	public static string getDisplay()
135 	{
136 		auto retStr = gdk_get_display();
137 
138 		scope(exit) Str.freeString(retStr);
139 		return Str.toString(retStr);
140 	}
141 
142 	/**
143 	 * Gets the display name specified in the command line arguments passed
144 	 * to gdk_init() or gdk_parse_args(), if any.
145 	 *
146 	 * Returns: the display name, if specified explicitly,
147 	 *     otherwise %NULL this string is owned by GTK+ and must not be
148 	 *     modified or freed.
149 	 *
150 	 * Since: 2.2
151 	 */
152 	public static string getDisplayArgName()
153 	{
154 		return Str.toString(gdk_get_display_arg_name());
155 	}
156 
157 	/**
158 	 * Gets the program class. Unless the program class has explicitly
159 	 * been set with gdk_set_program_class() or with the `--class`
160 	 * commandline option, the default value is the program name (determined
161 	 * with g_get_prgname()) with the first character converted to uppercase.
162 	 *
163 	 * Returns: the program class.
164 	 */
165 	public static string getProgramClass()
166 	{
167 		return Str.toString(gdk_get_program_class());
168 	}
169 
170 	/**
171 	 * Initializes the GDK library and connects to the windowing system.
172 	 * If initialization fails, a warning message is output and the application
173 	 * terminates with a call to `exit(1)`.
174 	 *
175 	 * Any arguments used by GDK are removed from the array and @argc and @argv
176 	 * are updated accordingly.
177 	 *
178 	 * GTK+ initializes GDK in gtk_init() and so this function is not usually
179 	 * needed by GTK+ applications.
180 	 *
181 	 * Params:
182 	 *     argv = the array of command line arguments.
183 	 */
184 	public static void init(ref string[] argv)
185 	{
186 		int argc = cast(int)argv.length;
187 		char** outargv = Str.toStringzArray(argv);
188 
189 		gdk_init(&argc, &outargv);
190 
191 		argv = Str.toStringArray(outargv, argc);
192 	}
193 
194 	/**
195 	 * Initializes the GDK library and connects to the windowing system,
196 	 * returning %TRUE on success.
197 	 *
198 	 * Any arguments used by GDK are removed from the array and @argc and @argv
199 	 * are updated accordingly.
200 	 *
201 	 * GTK+ initializes GDK in gtk_init() and so this function is not usually
202 	 * needed by GTK+ applications.
203 	 *
204 	 * Params:
205 	 *     argv = the array of command line arguments.
206 	 *
207 	 * Returns: %TRUE if initialization succeeded.
208 	 */
209 	public static bool initCheck(ref string[] argv)
210 	{
211 		int argc = cast(int)argv.length;
212 		char** outargv = Str.toStringzArray(argv);
213 
214 		auto p = gdk_init_check(&argc, &outargv) != 0;
215 
216 		argv = Str.toStringArray(outargv, argc);
217 
218 		return p;
219 	}
220 
221 	/**
222 	 * Grabs the keyboard so that all events are passed to this
223 	 * application until the keyboard is ungrabbed with gdk_keyboard_ungrab().
224 	 * This overrides any previous keyboard grab by this client.
225 	 *
226 	 * If you set up anything at the time you take the grab that needs to be cleaned
227 	 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
228 	 * are emitted when the grab ends unvoluntarily.
229 	 *
230 	 * Deprecated: Use gdk_device_grab() instead.
231 	 *
232 	 * Params:
233 	 *     window = the #GdkWindow which will own the grab (the grab window).
234 	 *     ownerEvents = if %FALSE then all keyboard events are reported with respect to
235 	 *         @window. If %TRUE then keyboard events for this application are
236 	 *         reported as normal, but keyboard events outside this application
237 	 *         are reported with respect to @window. Both key press and key
238 	 *         release events are always reported, independant of the event mask
239 	 *         set by the application.
240 	 *     time = a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
241 	 *         available.
242 	 *
243 	 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
244 	 */
245 	public static GdkGrabStatus keyboardGrab(Window window, bool ownerEvents, uint time)
246 	{
247 		return gdk_keyboard_grab((window is null) ? null : window.getWindowStruct(), ownerEvents, time);
248 	}
249 
250 	/**
251 	 * Ungrabs the keyboard on the default display, if it is grabbed by this
252 	 * application.
253 	 *
254 	 * Deprecated: Use gdk_device_ungrab(), together with gdk_device_grab()
255 	 * instead.
256 	 *
257 	 * Params:
258 	 *     time = a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
259 	 *         timestamp is available.
260 	 */
261 	public static void keyboardUngrab(uint time)
262 	{
263 		gdk_keyboard_ungrab(time);
264 	}
265 
266 	/**
267 	 * Indicates to the GUI environment that the application has finished
268 	 * loading. If the applications opens windows, this function is
269 	 * normally called after opening the application’s initial set of
270 	 * windows.
271 	 *
272 	 * GTK+ will call this function automatically after opening the first
273 	 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
274 	 * to disable that feature.
275 	 *
276 	 * Since: 2.2
277 	 */
278 	public static void notifyStartupComplete()
279 	{
280 		gdk_notify_startup_complete();
281 	}
282 
283 	/**
284 	 * Indicates to the GUI environment that the application has
285 	 * finished loading, using a given identifier.
286 	 *
287 	 * GTK+ will call this function automatically for #GtkWindow
288 	 * with custom startup-notification identifier unless
289 	 * gtk_window_set_auto_startup_notification() is called to
290 	 * disable that feature.
291 	 *
292 	 * Params:
293 	 *     startupId = a startup-notification identifier, for which
294 	 *         notification process should be completed
295 	 *
296 	 * Since: 2.12
297 	 */
298 	public static void notifyStartupCompleteWithId(string startupId)
299 	{
300 		gdk_notify_startup_complete_with_id(Str.toStringz(startupId));
301 	}
302 
303 	/**
304 	 * Parse command line arguments, and store for future
305 	 * use by calls to gdk_display_open().
306 	 *
307 	 * Any arguments used by GDK are removed from the array and @argc and @argv are
308 	 * updated accordingly.
309 	 *
310 	 * You shouldn’t call this function explicitly if you are using
311 	 * gtk_init(), gtk_init_check(), gdk_init(), or gdk_init_check().
312 	 *
313 	 * Params:
314 	 *     argv = the array of command line arguments.
315 	 *
316 	 * Since: 2.2
317 	 */
318 	public static void parseArgs(ref string[] argv)
319 	{
320 		int argc = cast(int)argv.length;
321 		char** outargv = Str.toStringzArray(argv);
322 
323 		gdk_parse_args(&argc, &outargv);
324 
325 		argv = Str.toStringArray(outargv, argc);
326 	}
327 
328 	/**
329 	 * Grabs the pointer (usually a mouse) so that all events are passed to this
330 	 * application until the pointer is ungrabbed with gdk_pointer_ungrab(), or
331 	 * the grab window becomes unviewable.
332 	 * This overrides any previous pointer grab by this client.
333 	 *
334 	 * Pointer grabs are used for operations which need complete control over mouse
335 	 * events, even if the mouse leaves the application.
336 	 * For example in GTK+ it is used for Drag and Drop, for dragging the handle in
337 	 * the #GtkHPaned and #GtkVPaned widgets.
338 	 *
339 	 * Note that if the event mask of an X window has selected both button press and
340 	 * button release events, then a button press event will cause an automatic
341 	 * pointer grab until the button is released.
342 	 * X does this automatically since most applications expect to receive button
343 	 * press and release events in pairs.
344 	 * It is equivalent to a pointer grab on the window with @owner_events set to
345 	 * %TRUE.
346 	 *
347 	 * If you set up anything at the time you take the grab that needs to be cleaned
348 	 * up when the grab ends, you should handle the #GdkEventGrabBroken events that
349 	 * are emitted when the grab ends unvoluntarily.
350 	 *
351 	 * Deprecated: Use gdk_device_grab() instead.
352 	 *
353 	 * Params:
354 	 *     window = the #GdkWindow which will own the grab (the grab window).
355 	 *     ownerEvents = if %FALSE then all pointer events are reported with respect to
356 	 *         @window and are only reported if selected by @event_mask. If %TRUE then pointer
357 	 *         events for this application are reported as normal, but pointer events outside
358 	 *         this application are reported with respect to @window and only if selected by
359 	 *         @event_mask. In either mode, unreported events are discarded.
360 	 *     eventMask = specifies the event mask, which is used in accordance with
361 	 *         @owner_events. Note that only pointer events (i.e. button and motion events)
362 	 *         may be selected.
363 	 *     confineTo = If non-%NULL, the pointer will be confined to this
364 	 *         window during the grab. If the pointer is outside @confine_to, it will
365 	 *         automatically be moved to the closest edge of @confine_to and enter
366 	 *         and leave events will be generated as necessary.
367 	 *     cursor = the cursor to display while the grab is active. If this is %NULL then
368 	 *         the normal cursors are used for @window and its descendants, and the cursor
369 	 *         for @window is used for all other windows.
370 	 *     time = the timestamp of the event which led to this pointer grab. This usually
371 	 *         comes from a #GdkEventButton struct, though %GDK_CURRENT_TIME can be used if
372 	 *         the time isn’t known.
373 	 *
374 	 * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
375 	 */
376 	public static GdkGrabStatus pointerGrab(Window window, bool ownerEvents, GdkEventMask eventMask, Window confineTo, Cursor cursor, uint time)
377 	{
378 		return gdk_pointer_grab((window is null) ? null : window.getWindowStruct(), ownerEvents, eventMask, (confineTo is null) ? null : confineTo.getWindowStruct(), (cursor is null) ? null : cursor.getCursorStruct(), time);
379 	}
380 
381 	/**
382 	 * Returns %TRUE if the pointer on the default display is currently
383 	 * grabbed by this application.
384 	 *
385 	 * Note that this does not take the inmplicit pointer grab on button
386 	 * presses into account.
387 	 *
388 	 * Deprecated: Use gdk_display_device_is_grabbed() instead.
389 	 *
390 	 * Returns: %TRUE if the pointer is currently grabbed by this application.
391 	 */
392 	public static bool pointerIsGrabbed()
393 	{
394 		return gdk_pointer_is_grabbed() != 0;
395 	}
396 
397 	/**
398 	 * Ungrabs the pointer on the default display, if it is grabbed by this
399 	 * application.
400 	 *
401 	 * Deprecated: Use gdk_device_ungrab(), together with gdk_device_grab()
402 	 * instead.
403 	 *
404 	 * Params:
405 	 *     time = a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
406 	 *         timestamp is available.
407 	 */
408 	public static void pointerUngrab(uint time)
409 	{
410 		gdk_pointer_ungrab(time);
411 	}
412 
413 	/**
414 	 * Sets a list of backends that GDK should try to use.
415 	 *
416 	 * This can be be useful if your application does not
417 	 * work with certain GDK backends.
418 	 *
419 	 * By default, GDK tries all included backends.
420 	 *
421 	 * For example,
422 	 * |[<!-- language="C" -->
423 	 * gdk_set_allowed_backends ("wayland,quartz,*");
424 	 * ]|
425 	 * instructs GDK to try the Wayland backend first,
426 	 * followed by the Quartz backend, and then all
427 	 * others.
428 	 *
429 	 * If the `GDK_BACKEND` environment variable
430 	 * is set, it determines what backends are tried in what
431 	 * order, while still respecting the set of allowed backends
432 	 * that are specified by this function.
433 	 *
434 	 * The possible backend names are x11, win32, quartz,
435 	 * broadway, wayland. You can also include a * in the
436 	 * list to try all remaining backends.
437 	 *
438 	 * This call must happen prior to gdk_display_open(),
439 	 * gtk_init(), gtk_init_with_args() or gtk_init_check()
440 	 * in order to take effect.
441 	 *
442 	 * Params:
443 	 *     backends = a comma-separated list of backends
444 	 *
445 	 * Since: 3.10
446 	 */
447 	public static void setAllowedBackends(string backends)
448 	{
449 		gdk_set_allowed_backends(Str.toStringz(backends));
450 	}
451 
452 	/**
453 	 * Set the double click time for the default display. See
454 	 * gdk_display_set_double_click_time().
455 	 * See also gdk_display_set_double_click_distance().
456 	 * Applications should not set this, it is a
457 	 * global user-configured setting.
458 	 *
459 	 * Params:
460 	 *     msec = double click time in milliseconds (thousandths of a second)
461 	 */
462 	public static void setDoubleClickTime(uint msec)
463 	{
464 		gdk_set_double_click_time(msec);
465 	}
466 
467 	/**
468 	 * Sets the program class. The X11 backend uses the program class to set
469 	 * the class name part of the `WM_CLASS` property on
470 	 * toplevel windows; see the ICCCM.
471 	 *
472 	 * The program class can still be overridden with the --class command
473 	 * line option.
474 	 *
475 	 * Params:
476 	 *     programClass = a string.
477 	 */
478 	public static void setProgramClass(string programClass)
479 	{
480 		gdk_set_program_class(Str.toStringz(programClass));
481 	}
482 }