1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gdkinternals.h"
34 #ifndef HAVE_XCONVERTCASE
35 #include "gdkkeysyms.h"
44 * @Short_description: Library initialization and miscellaneous functions
47 * This section describes the GDK initialization functions and miscellaneous
54 * The #GDK_WINDOWING_X11 macro is defined if the X11 backend
57 * Use this macro to guard code that is specific to the X11-backend.
58 * Since GDK may be configured with multiple backends, an additional
59 * runtime check for the used backend is recommended:
62 * #ifdef GDK_WINDOWING_X11
63 * if (GDK_IS_X11_DISPLAY (display))
65 * /* make X11-specific calls here */
69 * #ifdef GDK_WINDOWING_QUARTZ
70 * if (GDK_IS_QUARTZ_DISPLAY (display))
72 * /* make Quartz-specific calls here &ast/
76 * g_error ("Unsupported GDK backend");
81 * GDK_WINDOWING_WIN32:
83 * The #GDK_WINDOWING_WIN32 macro is defined if the Win32 backend
88 * GDK_WINDOWING_QUARTZ:
90 * The #GDK_WINDOWING_QUARTZ macro is defined if the Quartz backend
94 typedef struct _GdkPredicate GdkPredicate;
102 typedef struct _GdkThreadsDispatch GdkThreadsDispatch;
104 struct _GdkThreadsDispatch
108 GDestroyNotify destroy;
112 /* Private variable declarations
114 static int gdk_initialized = 0; /* 1 if the library is initialized,
118 static gchar *gdk_progclass = NULL;
120 static GMutex *gdk_threads_mutex = NULL; /* Global GDK lock */
122 static GCallback gdk_threads_lock = NULL;
123 static GCallback gdk_threads_unlock = NULL;
125 #ifdef G_ENABLE_DEBUG
126 static const GDebugKey gdk_debug_keys[] = {
127 {"events", GDK_DEBUG_EVENTS},
128 {"misc", GDK_DEBUG_MISC},
129 {"dnd", GDK_DEBUG_DND},
130 {"xim", GDK_DEBUG_XIM},
131 {"nograbs", GDK_DEBUG_NOGRABS},
132 {"colormap", GDK_DEBUG_COLORMAP},
133 {"input", GDK_DEBUG_INPUT},
134 {"cursor", GDK_DEBUG_CURSOR},
135 {"multihead", GDK_DEBUG_MULTIHEAD},
136 {"xinerama", GDK_DEBUG_XINERAMA},
137 {"draw", GDK_DEBUG_DRAW},
138 {"eventloop", GDK_DEBUG_EVENTLOOP}
142 gdk_arg_debug_cb (const char *key, const char *value, gpointer user_data, GError **error)
144 guint debug_value = g_parse_debug_string (value,
145 (GDebugKey *) gdk_debug_keys,
146 G_N_ELEMENTS (gdk_debug_keys));
148 if (debug_value == 0 && value != NULL && strcmp (value, "") != 0)
151 G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
152 _("Error parsing option --gdk-debug"));
156 _gdk_debug_flags |= debug_value;
162 gdk_arg_no_debug_cb (const char *key, const char *value, gpointer user_data, GError **error)
164 guint debug_value = g_parse_debug_string (value,
165 (GDebugKey *) gdk_debug_keys,
166 G_N_ELEMENTS (gdk_debug_keys));
168 if (debug_value == 0 && value != NULL && strcmp (value, "") != 0)
171 G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
172 _("Error parsing option --gdk-no-debug"));
176 _gdk_debug_flags &= ~debug_value;
180 #endif /* G_ENABLE_DEBUG */
183 gdk_arg_class_cb (const char *key, const char *value, gpointer user_data, GError **error)
185 gdk_set_program_class (value);
191 gdk_arg_name_cb (const char *key, const char *value, gpointer user_data, GError **error)
193 g_set_prgname (value);
198 static const GOptionEntry gdk_args[] = {
199 { "class", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_class_cb,
200 /* Description of --class=CLASS in --help output */ N_("Program class as used by the window manager"),
201 /* Placeholder in --class=CLASS in --help output */ N_("CLASS") },
202 { "name", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_name_cb,
203 /* Description of --name=NAME in --help output */ N_("Program name as used by the window manager"),
204 /* Placeholder in --name=NAME in --help output */ N_("NAME") },
205 { "display", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &_gdk_display_name,
206 /* Description of --display=DISPLAY in --help output */ N_("X display to use"),
207 /* Placeholder in --display=DISPLAY in --help output */ N_("DISPLAY") },
208 #ifdef G_ENABLE_DEBUG
209 { "gdk-debug", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_debug_cb,
210 /* Description of --gdk-debug=FLAGS in --help output */ N_("GDK debugging flags to set"),
211 /* Placeholder in --gdk-debug=FLAGS in --help output */ N_("FLAGS") },
212 { "gdk-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_no_debug_cb,
213 /* Description of --gdk-no-debug=FLAGS in --help output */ N_("GDK debugging flags to unset"),
214 /* Placeholder in --gdk-no-debug=FLAGS in --help output */ N_("FLAGS") },
220 * gdk_add_option_entries_libgtk_only:
221 * @group: An option group.
223 * Appends gdk option entries to the passed in option group. This is
224 * not public API and must not be used by applications.
227 gdk_add_option_entries_libgtk_only (GOptionGroup *group)
229 g_option_group_add_entries (group, gdk_args);
233 gdk_pre_parse_libgtk_only (void)
235 gdk_initialized = TRUE;
237 /* We set the fallback program class here, rather than lazily in
238 * gdk_get_program_class, since we don't want -name to override it.
240 gdk_progclass = g_strdup (g_get_prgname ());
241 if (gdk_progclass && gdk_progclass[0])
242 gdk_progclass[0] = g_ascii_toupper (gdk_progclass[0]);
244 #ifdef G_ENABLE_DEBUG
246 gchar *debug_string = getenv("GDK_DEBUG");
247 if (debug_string != NULL)
248 _gdk_debug_flags = g_parse_debug_string (debug_string,
249 (GDebugKey *) gdk_debug_keys,
250 G_N_ELEMENTS (gdk_debug_keys));
252 #endif /* G_ENABLE_DEBUG */
254 if (getenv ("GDK_NATIVE_WINDOWS"))
256 _gdk_native_windows = TRUE;
257 /* Ensure that this is not propagated to spawned applications */
258 g_unsetenv ("GDK_NATIVE_WINDOWS");
263 /* Do any setup particular to the windowing system */
264 gdk_display_manager_get ();
270 * @argc: the number of command line arguments.
271 * @argv: the array of command line arguments.
273 * Parse command line arguments, and store for future
274 * use by calls to gdk_display_open().
276 * Any arguments used by GDK are removed from the array and @argc and @argv are
277 * updated accordingly.
279 * You shouldn't call this function explicitely if you are using
280 * gtk_init(), gtk_init_check(), gdk_init(), or gdk_init_check().
285 gdk_parse_args (int *argc,
288 GOptionContext *option_context;
289 GOptionGroup *option_group;
290 GError *error = NULL;
295 gdk_pre_parse_libgtk_only ();
297 option_context = g_option_context_new (NULL);
298 g_option_context_set_ignore_unknown_options (option_context, TRUE);
299 g_option_context_set_help_enabled (option_context, FALSE);
300 option_group = g_option_group_new (NULL, NULL, NULL, NULL, NULL);
301 g_option_context_set_main_group (option_context, option_group);
303 g_option_group_add_entries (option_group, gdk_args);
305 if (!g_option_context_parse (option_context, argc, argv, &error))
307 g_warning ("%s", error->message);
308 g_error_free (error);
310 g_option_context_free (option_context);
312 GDK_NOTE (MISC, g_message ("progname: \"%s\"", g_get_prgname ()));
316 * gdk_get_display_arg_name:
318 * Gets the display name specified in the command line arguments passed
319 * to gdk_init() or gdk_parse_args(), if any.
321 * Returns: the display name, if specified explicitely, otherwise %NULL
322 * this string is owned by GTK+ and must not be modified or freed.
326 G_CONST_RETURN gchar *
327 gdk_get_display_arg_name (void)
329 if (!_gdk_display_arg_name)
330 _gdk_display_arg_name = g_strdup (_gdk_display_name);
332 return _gdk_display_arg_name;
336 * gdk_display_open_default_libgtk_only:
338 * Opens the default display specified by command line arguments or
339 * environment variables, sets it as the default display, and returns
340 * it. gdk_parse_args must have been called first. If the default
341 * display has previously been set, simply returns that. An internal
342 * function that should not be used by applications.
344 * Return value: (transfer none): the default display, if it could be
345 * opened, otherwise %NULL.
348 gdk_display_open_default_libgtk_only (void)
352 g_return_val_if_fail (gdk_initialized, NULL);
354 display = gdk_display_get_default ();
358 display = gdk_display_open (gdk_get_display_arg_name ());
365 * @argc: (inout): the number of command line arguments.
366 * @argv: (array length=argc) (inout): the array of command line arguments.
368 * Initializes the GDK library and connects to the windowing system,
369 * returning %TRUE on success.
371 * Any arguments used by GDK are removed from the array and @argc and @argv
372 * are updated accordingly.
374 * GTK+ initializes GDK in gtk_init() and so this function is not usually
375 * needed by GTK+ applications.
377 * Returns: %TRUE if initialization succeeded.
380 gdk_init_check (int *argc,
383 gdk_parse_args (argc, argv);
385 return gdk_display_open_default_libgtk_only () != NULL;
391 * @argc: (inout): the number of command line arguments.
392 * @argv: (array length=argc) (inout): the array of command line arguments.
394 * Initializes the GDK library and connects to the windowing system.
395 * If initialization fails, a warning message is output and the application
396 * terminates with a call to <literal>exit(1)</literal>.
398 * Any arguments used by GDK are removed from the array and @argc and @argv
399 * are updated accordingly.
401 * GTK+ initializes GDK in gtk_init() and so this function is not usually
402 * needed by GTK+ applications.
405 gdk_init (int *argc, char ***argv)
407 if (!gdk_init_check (argc, argv))
409 const char *display_name = gdk_get_display_arg_name ();
410 g_warning ("cannot open display: %s", display_name ? display_name : "");
419 * @Short_description: Functions for using GDK in multi-threaded programs
422 * For thread safety, GDK relies on the thread primitives in GLib,
423 * and on the thread-safe GLib main loop.
425 * GLib is completely thread safe (all global data is automatically
426 * locked), but individual data structure instances are not automatically
427 * locked for performance reasons. So e.g. you must coordinate
428 * accesses to the same #GHashTable from multiple threads.
430 * GTK+ is "thread aware" but not thread safe — it provides a
431 * global lock controlled by gdk_threads_enter()/gdk_threads_leave()
432 * which protects all use of GTK+. That is, only one thread can use GTK+
435 * Unfortunately the above holds with the X11 backend only. With the
436 * Win32 backend, GDK calls should not be attempted from multiple threads
439 * You must call g_thread_init() and gdk_threads_init() before executing
440 * any other GTK+ or GDK functions in a threaded GTK+ program.
442 * Idles, timeouts, and input functions from GLib, such as g_idle_add(), are
443 * executed outside of the main GTK+ lock.
444 * So, if you need to call GTK+ inside of such a callback, you must surround
445 * the callback with a gdk_threads_enter()/gdk_threads_leave() pair or use
446 * gdk_threads_add_idle_full() which does this for you.
447 * However, event dispatching from the mainloop is still executed within
448 * the main GTK+ lock, so callback functions connected to event signals
449 * like #GtkWidget::button-press-event, do not need thread protection.
451 * In particular, this means, if you are writing widgets that might
452 * be used in threaded programs, you <emphasis>must</emphasis> surround
453 * timeouts and idle functions in this matter.
455 * As always, you must also surround any calls to GTK+ not made within
456 * a signal handler with a gdk_threads_enter()/gdk_threads_leave() pair.
458 * Before calling gdk_threads_leave() from a thread other
459 * than your main thread, you probably want to call gdk_flush()
460 * to send all pending commands to the windowing system.
461 * (The reason you don't need to do this from the main thread
462 * is that GDK always automatically flushes pending commands
463 * when it runs out of incoming events to process and has
464 * to sleep while waiting for more events.)
466 * A minimal main program for a threaded GTK+ application
469 * <programlisting role="C">
471 * main (int argc, char *argv[])
475 * g_thread_init (NULL);
476 * gdk_threads_init (<!-- -->);
477 * gdk_threads_enter (<!-- -->);
479 * gtk_init (&argc, &argv);
481 * window = create_window (<!-- -->);
482 * gtk_widget_show (window);
484 * gtk_main (<!-- -->);
485 * gdk_threads_leave (<!-- -->);
492 * Callbacks require a bit of attention. Callbacks from GTK+ signals
493 * are made within the GTK+ lock. However callbacks from GLib (timeouts,
494 * IO callbacks, and idle functions) are made outside of the GTK+
495 * lock. So, within a signal handler you do not need to call
496 * gdk_threads_enter(), but within the other types of callbacks, you
499 * Erik Mouw contributed the following code example to
500 * illustrate how to use threads within GTK+ programs.
502 * <programlisting role="C">
503 * /<!---->*-------------------------------------------------------------------------
504 * * Filename: gtk-thread.c
506 * * Copyright: Copyright (C) 1999, Erik Mouw
507 * * Author: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
508 * * Description: GTK threads example.
509 * * Created at: Sun Oct 17 21:27:09 1999
510 * * Modified by: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
511 * * Modified at: Sun Oct 24 17:21:41 1999
512 * *-----------------------------------------------------------------------*<!---->/
516 * * cc -o gtk-thread gtk-thread.c `gtk-config --cflags --libs gthread`
518 * * Thanks to Sebastian Wilhelmi and Owen Taylor for pointing out some
524 * #include <stdlib.h>
525 * #include <unistd.h>
527 * #include <gtk/gtk.h>
529 * #include <pthread.h>
531 * #define YES_IT_IS (1)
532 * #define NO_IT_IS_NOT (0)
540 * G_LOCK_DEFINE_STATIC (yes_or_no);
541 * static volatile int yes_or_no = YES_IT_IS;
543 * void destroy (GtkWidget *widget, gpointer data)
545 * gtk_main_quit (<!-- -->);
548 * void *argument_thread (void *args)
550 * yes_or_no_args *data = (yes_or_no_args *)args;
551 * gboolean say_something;
555 * /<!---->* sleep a while *<!---->/
556 * sleep(rand(<!-- -->) / (RAND_MAX / 3) + 1);
558 * /<!---->* lock the yes_or_no_variable *<!---->/
561 * /<!---->* do we have to say something? *<!---->/
562 * say_something = (yes_or_no != data->what);
566 * /<!---->* set the variable *<!---->/
567 * yes_or_no = data->what;
570 * /<!---->* Unlock the yes_or_no variable *<!---->/
571 * G_UNLOCK (yes_or_no);
575 * /<!---->* get GTK thread lock *<!---->/
576 * gdk_threads_enter (<!-- -->);
578 * /<!---->* set label text *<!---->/
579 * if(data->what == YES_IT_IS)
580 * gtk_label_set_text (GTK_LABEL (data->label), "O yes, it is!");
582 * gtk_label_set_text (GTK_LABEL (data->label), "O no, it isn't!");
584 * /<!---->* release GTK thread lock *<!---->/
585 * gdk_threads_leave (<!-- -->);
592 * int main (int argc, char *argv[])
596 * yes_or_no_args yes_args, no_args;
597 * pthread_t no_tid, yes_tid;
599 * /<!---->* init threads *<!---->/
600 * g_thread_init (NULL);
601 * gdk_threads_init (<!-- -->);
602 * gdk_threads_enter (<!-- -->);
604 * /<!---->* init gtk *<!---->/
605 * gtk_init(&argc, &argv);
607 * /<!---->* init random number generator *<!---->/
608 * srand ((unsigned int) time (NULL));
610 * /<!---->* create a window *<!---->/
611 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
613 * g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
615 * gtk_container_set_border_width (GTK_CONTAINER (window), 10);
617 * /<!---->* create a label *<!---->/
618 * label = gtk_label_new ("And now for something completely different ...");
619 * gtk_container_add (GTK_CONTAINER (window), label);
621 * /<!---->* show everything *<!---->/
622 * gtk_widget_show (label);
623 * gtk_widget_show (window);
625 * /<!---->* create the threads *<!---->/
626 * yes_args.label = label;
627 * yes_args.what = YES_IT_IS;
628 * pthread_create (&yes_tid, NULL, argument_thread, &yes_args);
630 * no_args.label = label;
631 * no_args.what = NO_IT_IS_NOT;
632 * pthread_create (&no_tid, NULL, argument_thread, &no_args);
634 * /<!---->* enter the GTK main loop *<!---->/
635 * gtk_main (<!-- -->);
636 * gdk_threads_leave (<!-- -->);
648 * This macro marks the beginning of a critical section in which GDK and
649 * GTK+ functions can be called safely and without causing race
650 * conditions. Only one thread at a time can be in such a critial
654 gdk_threads_enter (void)
656 if (gdk_threads_lock)
657 (*gdk_threads_lock) ();
663 * Leaves a critical region begun with gdk_threads_enter().
666 gdk_threads_leave (void)
668 if (gdk_threads_unlock)
669 (*gdk_threads_unlock) ();
673 gdk_threads_impl_lock (void)
675 if (gdk_threads_mutex)
676 g_mutex_lock (gdk_threads_mutex);
680 gdk_threads_impl_unlock (void)
682 if (gdk_threads_mutex)
683 g_mutex_unlock (gdk_threads_mutex);
689 * Initializes GDK so that it can be used from multiple threads
690 * in conjunction with gdk_threads_enter() and gdk_threads_leave().
691 * g_thread_init() must be called previous to this function.
693 * This call must be made before any use of the main loop from
694 * GTK+; to be safe, call it before gtk_init().
697 gdk_threads_init (void)
699 if (!g_thread_supported ())
700 g_error ("g_thread_init() must be called before gdk_threads_init()");
702 gdk_threads_mutex = g_mutex_new ();
703 if (!gdk_threads_lock)
704 gdk_threads_lock = gdk_threads_impl_lock;
705 if (!gdk_threads_unlock)
706 gdk_threads_unlock = gdk_threads_impl_unlock;
710 * gdk_threads_set_lock_functions:
711 * @enter_fn: function called to guard GDK
712 * @leave_fn: function called to release the guard
714 * Allows the application to replace the standard method that
715 * GDK uses to protect its data structures. Normally, GDK
716 * creates a single #GMutex that is locked by gdk_threads_enter(),
717 * and released by gdk_threads_leave(); using this function an
718 * application provides, instead, a function @enter_fn that is
719 * called by gdk_threads_enter() and a function @leave_fn that is
720 * called by gdk_threads_leave().
722 * The functions must provide at least same locking functionality
723 * as the default implementation, but can also do extra application
724 * specific processing.
726 * As an example, consider an application that has its own recursive
727 * lock that when held, holds the GTK+ lock as well. When GTK+ unlocks
728 * the GTK+ lock when entering a recursive main loop, the application
729 * must temporarily release its lock as well.
731 * Most threaded GTK+ apps won't need to use this method.
733 * This method must be called before gdk_threads_init(), and cannot
734 * be called multiple times.
739 gdk_threads_set_lock_functions (GCallback enter_fn,
742 g_return_if_fail (gdk_threads_lock == NULL &&
743 gdk_threads_unlock == NULL);
745 gdk_threads_lock = enter_fn;
746 gdk_threads_unlock = leave_fn;
750 gdk_threads_dispatch (gpointer data)
752 GdkThreadsDispatch *dispatch = data;
753 gboolean ret = FALSE;
755 GDK_THREADS_ENTER ();
757 if (!g_source_is_destroyed (g_main_current_source ()))
758 ret = dispatch->func (dispatch->data);
760 GDK_THREADS_LEAVE ();
766 gdk_threads_dispatch_free (gpointer data)
768 GdkThreadsDispatch *dispatch = data;
770 if (dispatch->destroy && dispatch->data)
771 dispatch->destroy (dispatch->data);
773 g_slice_free (GdkThreadsDispatch, data);
778 * gdk_threads_add_idle_full:
779 * @priority: the priority of the idle source. Typically this will be in the
780 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE
781 * @function: function to call
782 * @data: data to pass to @function
783 * @notify: (allow-none): function to call when the idle is removed, or %NULL
785 * Adds a function to be called whenever there are no higher priority
786 * events pending. If the function returns %FALSE it is automatically
787 * removed from the list of event sources and will not be called again.
789 * This variant of g_idle_add_full() calls @function with the GDK lock
790 * held. It can be thought of a MT-safe version for GTK+ widgets for the
791 * following use case, where you have to worry about idle_callback()
792 * running in thread A and accessing @self after it has been finalized
797 * idle_callback (gpointer data)
799 * /* gdk_threads_enter(); would be needed for g_idle_add() */
801 * SomeWidget *self = data;
802 * /* do stuff with self */
806 * /* gdk_threads_leave(); would be needed for g_idle_add() */
811 * some_widget_do_stuff_later (SomeWidget *self)
813 * self->idle_id = gdk_threads_add_idle (idle_callback, self)
814 * /* using g_idle_add() here would require thread protection in the callback */
818 * some_widget_finalize (GObject *object)
820 * SomeWidget *self = SOME_WIDGET (object);
822 * g_source_remove (self->idle_id);
823 * G_OBJECT_CLASS (parent_class)->finalize (object);
827 * Return value: the ID (greater than 0) of the event source.
832 gdk_threads_add_idle_full (gint priority,
833 GSourceFunc function,
835 GDestroyNotify notify)
837 GdkThreadsDispatch *dispatch;
839 g_return_val_if_fail (function != NULL, 0);
841 dispatch = g_slice_new (GdkThreadsDispatch);
842 dispatch->func = function;
843 dispatch->data = data;
844 dispatch->destroy = notify;
846 return g_idle_add_full (priority,
847 gdk_threads_dispatch,
849 gdk_threads_dispatch_free);
853 * gdk_threads_add_idle:
854 * @function: function to call
855 * @data: data to pass to @function
857 * A wrapper for the common usage of gdk_threads_add_idle_full()
858 * assigning the default priority, #G_PRIORITY_DEFAULT_IDLE.
860 * See gdk_threads_add_idle_full().
862 * Return value: the ID (greater than 0) of the event source.
867 gdk_threads_add_idle (GSourceFunc function,
870 return gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE,
871 function, data, NULL);
876 * gdk_threads_add_timeout_full:
877 * @priority: the priority of the timeout source. Typically this will be in the
878 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
879 * @interval: the time between calls to the function, in milliseconds
880 * (1/1000ths of a second)
881 * @function: function to call
882 * @data: data to pass to @function
883 * @notify: (allow-none): function to call when the timeout is removed, or %NULL
885 * Sets a function to be called at regular intervals holding the GDK lock,
886 * with the given priority. The function is called repeatedly until it
887 * returns %FALSE, at which point the timeout is automatically destroyed
888 * and the function will not be called again. The @notify function is
889 * called when the timeout is destroyed. The first call to the
890 * function will be at the end of the first @interval.
892 * Note that timeout functions may be delayed, due to the processing of other
893 * event sources. Thus they should not be relied on for precise timing.
894 * After each call to the timeout function, the time of the next
895 * timeout is recalculated based on the current time and the given interval
896 * (it does not try to 'catch up' time lost in delays).
898 * This variant of g_timeout_add_full() can be thought of a MT-safe version
899 * for GTK+ widgets for the following use case:
902 * static gboolean timeout_callback (gpointer data)
904 * SomeWidget *self = data;
906 * /* do stuff with self */
908 * self->timeout_id = 0;
913 * static void some_widget_do_stuff_later (SomeWidget *self)
915 * self->timeout_id = g_timeout_add (timeout_callback, self)
918 * static void some_widget_finalize (GObject *object)
920 * SomeWidget *self = SOME_WIDGET (object);
922 * if (self->timeout_id)
923 * g_source_remove (self->timeout_id);
925 * G_OBJECT_CLASS (parent_class)->finalize (object);
929 * Return value: the ID (greater than 0) of the event source.
934 gdk_threads_add_timeout_full (gint priority,
936 GSourceFunc function,
938 GDestroyNotify notify)
940 GdkThreadsDispatch *dispatch;
942 g_return_val_if_fail (function != NULL, 0);
944 dispatch = g_slice_new (GdkThreadsDispatch);
945 dispatch->func = function;
946 dispatch->data = data;
947 dispatch->destroy = notify;
949 return g_timeout_add_full (priority,
951 gdk_threads_dispatch,
953 gdk_threads_dispatch_free);
957 * gdk_threads_add_timeout:
958 * @interval: the time between calls to the function, in milliseconds
959 * (1/1000ths of a second)
960 * @function: function to call
961 * @data: data to pass to @function
963 * A wrapper for the common usage of gdk_threads_add_timeout_full()
964 * assigning the default priority, #G_PRIORITY_DEFAULT.
966 * See gdk_threads_add_timeout_full().
968 * Return value: the ID (greater than 0) of the event source.
973 gdk_threads_add_timeout (guint interval,
974 GSourceFunc function,
977 return gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT,
978 interval, function, data, NULL);
983 * gdk_threads_add_timeout_seconds_full:
984 * @priority: the priority of the timeout source. Typically this will be in the
985 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
986 * @interval: the time between calls to the function, in seconds
987 * @function: function to call
988 * @data: data to pass to @function
989 * @notify: (allow-none): function to call when the timeout is removed, or %NULL
991 * A variant of gdk_threads_add_timeout_full() with second-granularity.
992 * See g_timeout_add_seconds_full() for a discussion of why it is
993 * a good idea to use this function if you don't need finer granularity.
995 * Return value: the ID (greater than 0) of the event source.
1000 gdk_threads_add_timeout_seconds_full (gint priority,
1002 GSourceFunc function,
1004 GDestroyNotify notify)
1006 GdkThreadsDispatch *dispatch;
1008 g_return_val_if_fail (function != NULL, 0);
1010 dispatch = g_slice_new (GdkThreadsDispatch);
1011 dispatch->func = function;
1012 dispatch->data = data;
1013 dispatch->destroy = notify;
1015 return g_timeout_add_seconds_full (priority,
1017 gdk_threads_dispatch,
1019 gdk_threads_dispatch_free);
1023 * gdk_threads_add_timeout_seconds:
1024 * @interval: the time between calls to the function, in seconds
1025 * @function: function to call
1026 * @data: data to pass to @function
1028 * A wrapper for the common usage of gdk_threads_add_timeout_seconds_full()
1029 * assigning the default priority, #G_PRIORITY_DEFAULT.
1031 * For details, see gdk_threads_add_timeout_full().
1033 * Return value: the ID (greater than 0) of the event source.
1038 gdk_threads_add_timeout_seconds (guint interval,
1039 GSourceFunc function,
1042 return gdk_threads_add_timeout_seconds_full (G_PRIORITY_DEFAULT,
1043 interval, function, data, NULL);
1047 * gdk_get_program_class:
1049 * Gets the program class. Unless the program class has explicitly
1050 * been set with gdk_set_program_class() or with the <option>--class</option>
1051 * commandline option, the default value is the program name (determined
1052 * with g_get_prgname()) with the first character converted to uppercase.
1054 * Returns: the program class.
1056 G_CONST_RETURN char *
1057 gdk_get_program_class (void)
1059 return gdk_progclass;
1063 * gdk_set_program_class:
1064 * @program_class: a string.
1066 * Sets the program class. The X11 backend uses the program class to set
1067 * the class name part of the <literal>WM_CLASS</literal> property on
1068 * toplevel windows; see the ICCCM.
1071 gdk_set_program_class (const char *program_class)
1073 g_free (gdk_progclass);
1075 gdk_progclass = g_strdup (program_class);
1079 * gdk_disable_multidevice:
1081 * Disables multidevice support in GDK. This call must happen prior
1082 * to gdk_display_open(), gtk_init(), gtk_init_with_args() or
1083 * gtk_init_check() in order to take effect.
1085 * Most common GTK+ applications won't ever need to call this. Only
1086 * applications that do mixed GDK/Xlib calls could want to disable
1087 * multidevice support if such Xlib code deals with input devices in
1088 * any way and doesn't observe the presence of XInput 2.
1093 gdk_disable_multidevice (void)
1095 if (gdk_initialized)
1098 _gdk_disable_multidevice = TRUE;