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.
61 * GDK_WINDOWING_WIN32:
63 * The #GDK_WINDOWING_WIN32 macro is defined if the Win32 backend
66 * Use this macro to guard code that is specific to the Win32 backend.
70 * GDK_WINDOWING_QUARTZ:
72 * The #GDK_WINDOWING_QUARTZ macro is defined if the Quartz backend
75 * Use this macro to guard code that is specific to the Quartz backend.
78 typedef struct _GdkPredicate GdkPredicate;
86 typedef struct _GdkThreadsDispatch GdkThreadsDispatch;
88 struct _GdkThreadsDispatch
92 GDestroyNotify destroy;
96 /* Private variable declarations
98 static int gdk_initialized = 0; /* 1 if the library is initialized,
102 static gchar *gdk_progclass = NULL;
104 static GMutex gdk_threads_mutex;
106 static GCallback gdk_threads_lock = NULL;
107 static GCallback gdk_threads_unlock = NULL;
109 #ifdef G_ENABLE_DEBUG
110 static const GDebugKey gdk_debug_keys[] = {
111 {"events", GDK_DEBUG_EVENTS},
112 {"misc", GDK_DEBUG_MISC},
113 {"dnd", GDK_DEBUG_DND},
114 {"xim", GDK_DEBUG_XIM},
115 {"nograbs", GDK_DEBUG_NOGRABS},
116 {"input", GDK_DEBUG_INPUT},
117 {"cursor", GDK_DEBUG_CURSOR},
118 {"multihead", GDK_DEBUG_MULTIHEAD},
119 {"xinerama", GDK_DEBUG_XINERAMA},
120 {"draw", GDK_DEBUG_DRAW},
121 {"eventloop", GDK_DEBUG_EVENTLOOP}
125 gdk_arg_debug_cb (const char *key, const char *value, gpointer user_data, GError **error)
127 guint debug_value = g_parse_debug_string (value,
128 (GDebugKey *) gdk_debug_keys,
129 G_N_ELEMENTS (gdk_debug_keys));
131 if (debug_value == 0 && value != NULL && strcmp (value, "") != 0)
134 G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
135 _("Error parsing option --gdk-debug"));
139 _gdk_debug_flags |= debug_value;
145 gdk_arg_no_debug_cb (const char *key, const char *value, gpointer user_data, GError **error)
147 guint debug_value = g_parse_debug_string (value,
148 (GDebugKey *) gdk_debug_keys,
149 G_N_ELEMENTS (gdk_debug_keys));
151 if (debug_value == 0 && value != NULL && strcmp (value, "") != 0)
154 G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
155 _("Error parsing option --gdk-no-debug"));
159 _gdk_debug_flags &= ~debug_value;
163 #endif /* G_ENABLE_DEBUG */
166 gdk_arg_class_cb (const char *key, const char *value, gpointer user_data, GError **error)
168 gdk_set_program_class (value);
174 gdk_arg_name_cb (const char *key, const char *value, gpointer user_data, GError **error)
176 g_set_prgname (value);
181 static const GOptionEntry gdk_args[] = {
182 { "class", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_class_cb,
183 /* Description of --class=CLASS in --help output */ N_("Program class as used by the window manager"),
184 /* Placeholder in --class=CLASS in --help output */ N_("CLASS") },
185 { "name", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_name_cb,
186 /* Description of --name=NAME in --help output */ N_("Program name as used by the window manager"),
187 /* Placeholder in --name=NAME in --help output */ N_("NAME") },
188 { "display", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &_gdk_display_name,
189 /* Description of --display=DISPLAY in --help output */ N_("X display to use"),
190 /* Placeholder in --display=DISPLAY in --help output */ N_("DISPLAY") },
191 #ifdef G_ENABLE_DEBUG
192 { "gdk-debug", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_debug_cb,
193 /* Description of --gdk-debug=FLAGS in --help output */ N_("GDK debugging flags to set"),
194 /* Placeholder in --gdk-debug=FLAGS in --help output */ N_("FLAGS") },
195 { "gdk-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_no_debug_cb,
196 /* Description of --gdk-no-debug=FLAGS in --help output */ N_("GDK debugging flags to unset"),
197 /* Placeholder in --gdk-no-debug=FLAGS in --help output */ N_("FLAGS") },
203 * gdk_add_option_entries_libgtk_only:
204 * @group: An option group.
206 * Appends gdk option entries to the passed in option group. This is
207 * not public API and must not be used by applications.
210 gdk_add_option_entries_libgtk_only (GOptionGroup *group)
212 g_option_group_add_entries (group, gdk_args);
216 gdk_pre_parse_libgtk_only (void)
218 const char *rendering_mode;
220 gdk_initialized = TRUE;
222 /* We set the fallback program class here, rather than lazily in
223 * gdk_get_program_class, since we don't want -name to override it.
225 gdk_progclass = g_strdup (g_get_prgname ());
226 if (gdk_progclass && gdk_progclass[0])
227 gdk_progclass[0] = g_ascii_toupper (gdk_progclass[0]);
229 #ifdef G_ENABLE_DEBUG
231 gchar *debug_string = getenv("GDK_DEBUG");
232 if (debug_string != NULL)
233 _gdk_debug_flags = g_parse_debug_string (debug_string,
234 (GDebugKey *) gdk_debug_keys,
235 G_N_ELEMENTS (gdk_debug_keys));
237 #endif /* G_ENABLE_DEBUG */
239 if (getenv ("GDK_NATIVE_WINDOWS"))
241 g_warning ("The GDK_NATIVE_WINDOWS environment variable is not supported in GTK3.\n"
242 "See the documentation for gdk_window_ensure_native() on how to get native windows.");
243 g_unsetenv ("GDK_NATIVE_WINDOWS");
246 rendering_mode = g_getenv ("GDK_RENDERING");
249 if (g_str_equal (rendering_mode, "similar"))
250 _gdk_rendering_mode = GDK_RENDERING_MODE_SIMILAR;
251 else if (g_str_equal (rendering_mode, "image"))
252 _gdk_rendering_mode = GDK_RENDERING_MODE_IMAGE;
253 else if (g_str_equal (rendering_mode, "recording"))
254 _gdk_rendering_mode = GDK_RENDERING_MODE_RECORDING;
259 /* Do any setup particular to the windowing system */
260 gdk_display_manager_get ();
266 * @argc: the number of command line arguments.
267 * @argv: (inout) (array length=argc): the array of command line arguments.
269 * Parse command line arguments, and store for future
270 * use by calls to gdk_display_open().
272 * Any arguments used by GDK are removed from the array and @argc and @argv are
273 * updated accordingly.
275 * You shouldn't call this function explicitely if you are using
276 * gtk_init(), gtk_init_check(), gdk_init(), or gdk_init_check().
281 gdk_parse_args (int *argc,
284 GOptionContext *option_context;
285 GOptionGroup *option_group;
286 GError *error = NULL;
291 gdk_pre_parse_libgtk_only ();
293 option_context = g_option_context_new (NULL);
294 g_option_context_set_ignore_unknown_options (option_context, TRUE);
295 g_option_context_set_help_enabled (option_context, FALSE);
296 option_group = g_option_group_new (NULL, NULL, NULL, NULL, NULL);
297 g_option_context_set_main_group (option_context, option_group);
299 g_option_group_add_entries (option_group, gdk_args);
301 if (!g_option_context_parse (option_context, argc, argv, &error))
303 g_warning ("%s", error->message);
304 g_error_free (error);
306 g_option_context_free (option_context);
308 GDK_NOTE (MISC, g_message ("progname: \"%s\"", g_get_prgname ()));
312 * gdk_get_display_arg_name:
314 * Gets the display name specified in the command line arguments passed
315 * to gdk_init() or gdk_parse_args(), if any.
317 * Returns: the display name, if specified explicitely, otherwise %NULL
318 * this string is owned by GTK+ and must not be modified or freed.
323 gdk_get_display_arg_name (void)
325 if (!_gdk_display_arg_name)
326 _gdk_display_arg_name = g_strdup (_gdk_display_name);
328 return _gdk_display_arg_name;
332 * gdk_display_open_default_libgtk_only:
334 * Opens the default display specified by command line arguments or
335 * environment variables, sets it as the default display, and returns
336 * it. gdk_parse_args must have been called first. If the default
337 * display has previously been set, simply returns that. An internal
338 * function that should not be used by applications.
340 * Return value: (transfer none): the default display, if it could be
341 * opened, otherwise %NULL.
344 gdk_display_open_default_libgtk_only (void)
348 g_return_val_if_fail (gdk_initialized, NULL);
350 display = gdk_display_get_default ();
354 display = gdk_display_open (gdk_get_display_arg_name ());
361 * @argc: (inout): the number of command line arguments.
362 * @argv: (array length=argc) (inout): the array of command line arguments.
364 * Initializes the GDK library and connects to the windowing system,
365 * returning %TRUE on success.
367 * Any arguments used by GDK are removed from the array and @argc and @argv
368 * are updated accordingly.
370 * GTK+ initializes GDK in gtk_init() and so this function is not usually
371 * needed by GTK+ applications.
373 * Returns: %TRUE if initialization succeeded.
376 gdk_init_check (int *argc,
379 gdk_parse_args (argc, argv);
381 return gdk_display_open_default_libgtk_only () != NULL;
387 * @argc: (inout): the number of command line arguments.
388 * @argv: (array length=argc) (inout): the array of command line arguments.
390 * Initializes the GDK library and connects to the windowing system.
391 * If initialization fails, a warning message is output and the application
392 * terminates with a call to <literal>exit(1)</literal>.
394 * Any arguments used by GDK are removed from the array and @argc and @argv
395 * are updated accordingly.
397 * GTK+ initializes GDK in gtk_init() and so this function is not usually
398 * needed by GTK+ applications.
401 gdk_init (int *argc, char ***argv)
403 if (!gdk_init_check (argc, argv))
405 const char *display_name = gdk_get_display_arg_name ();
406 g_warning ("cannot open display: %s", display_name ? display_name : "");
415 * @Short_description: Functions for using GDK in multi-threaded programs
418 * For thread safety, GDK relies on the thread primitives in GLib,
419 * and on the thread-safe GLib main loop.
421 * GLib is completely thread safe (all global data is automatically
422 * locked), but individual data structure instances are not automatically
423 * locked for performance reasons. So e.g. you must coordinate
424 * accesses to the same #GHashTable from multiple threads.
426 * GTK+ is "thread aware" but not thread safe — it provides a
427 * global lock controlled by gdk_threads_enter()/gdk_threads_leave()
428 * which protects all use of GTK+. That is, only one thread can use GTK+
431 * Unfortunately the above holds with the X11 backend only. With the
432 * Win32 backend, GDK calls should not be attempted from multiple threads
435 * You must call gdk_threads_init() before executing any other GTK+ or
436 * GDK functions in a threaded GTK+ program.
438 * Idles, timeouts, and input functions from GLib, such as g_idle_add(),
439 * are executed outside of the main GTK+ lock. So, if you need to call
440 * GTK+ inside of such a callback, you must surround the callback with
441 * a gdk_threads_enter()/gdk_threads_leave() pair or use
442 * gdk_threads_add_idle_full() which does this for you.
443 * However, event dispatching from the mainloop is still executed within
444 * the main GTK+ lock, so callback functions connected to event signals
445 * like #GtkWidget::button-press-event, do not need thread protection.
447 * In particular, this means, if you are writing widgets that might
448 * be used in threaded programs, you <emphasis>must</emphasis> surround
449 * timeouts and idle functions in this matter.
451 * As always, you must also surround any calls to GTK+ not made within
452 * a signal handler with a gdk_threads_enter()/gdk_threads_leave() pair.
454 * Before calling gdk_threads_leave() from a thread other
455 * than your main thread, you probably want to call gdk_flush()
456 * to send all pending commands to the windowing system.
457 * (The reason you don't need to do this from the main thread
458 * is that GDK always automatically flushes pending commands
459 * when it runs out of incoming events to process and has
460 * to sleep while waiting for more events.)
462 * A minimal main program for a threaded GTK+ application
465 * <programlisting role="C">
467 * main (int argc, char *argv[])
471 * gdk_threads_init (<!-- -->);
472 * gdk_threads_enter (<!-- -->);
474 * gtk_init (&argc, &argv);
476 * window = create_window (<!-- -->);
477 * gtk_widget_show (window);
479 * gtk_main (<!-- -->);
480 * gdk_threads_leave (<!-- -->);
487 * Callbacks require a bit of attention. Callbacks from GTK+ signals
488 * are made within the GTK+ lock. However callbacks from GLib (timeouts,
489 * IO callbacks, and idle functions) are made outside of the GTK+
490 * lock. So, within a signal handler you do not need to call
491 * gdk_threads_enter(), but within the other types of callbacks, you
494 * Erik Mouw contributed the following code example to
495 * illustrate how to use threads within GTK+ programs.
497 * <programlisting role="C">
498 * /<!---->*-------------------------------------------------------------------------
499 * * Filename: gtk-thread.c
501 * * Copyright: Copyright (C) 1999, Erik Mouw
502 * * Author: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
503 * * Description: GTK threads example.
504 * * Created at: Sun Oct 17 21:27:09 1999
505 * * Modified by: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
506 * * Modified at: Sun Oct 24 17:21:41 1999
507 * *-----------------------------------------------------------------------*<!---->/
511 * * cc -o gtk-thread gtk-thread.c `gtk-config --cflags --libs gthread`
513 * * Thanks to Sebastian Wilhelmi and Owen Taylor for pointing out some
519 * #include <stdlib.h>
520 * #include <unistd.h>
522 * #include <gtk/gtk.h>
524 * #include <pthread.h>
526 * #define YES_IT_IS (1)
527 * #define NO_IT_IS_NOT (0)
535 * G_LOCK_DEFINE_STATIC (yes_or_no);
536 * static volatile int yes_or_no = YES_IT_IS;
538 * void destroy (GtkWidget *widget, gpointer data)
540 * gtk_main_quit (<!-- -->);
543 * void *argument_thread (void *args)
545 * yes_or_no_args *data = (yes_or_no_args *)args;
546 * gboolean say_something;
550 * /<!---->* sleep a while *<!---->/
551 * sleep(rand(<!-- -->) / (RAND_MAX / 3) + 1);
553 * /<!---->* lock the yes_or_no_variable *<!---->/
556 * /<!---->* do we have to say something? *<!---->/
557 * say_something = (yes_or_no != data->what);
561 * /<!---->* set the variable *<!---->/
562 * yes_or_no = data->what;
565 * /<!---->* Unlock the yes_or_no variable *<!---->/
566 * G_UNLOCK (yes_or_no);
570 * /<!---->* get GTK thread lock *<!---->/
571 * gdk_threads_enter (<!-- -->);
573 * /<!---->* set label text *<!---->/
574 * if(data->what == YES_IT_IS)
575 * gtk_label_set_text (GTK_LABEL (data->label), "O yes, it is!");
577 * gtk_label_set_text (GTK_LABEL (data->label), "O no, it isn't!");
579 * /<!---->* release GTK thread lock *<!---->/
580 * gdk_threads_leave (<!-- -->);
587 * int main (int argc, char *argv[])
591 * yes_or_no_args yes_args, no_args;
592 * pthread_t no_tid, yes_tid;
594 * /<!---->* init threads *<!---->/
595 * gdk_threads_init (<!-- -->);
596 * gdk_threads_enter (<!-- -->);
598 * /<!---->* init gtk *<!---->/
599 * gtk_init(&argc, &argv);
601 * /<!---->* init random number generator *<!---->/
602 * srand ((unsigned int) time (NULL));
604 * /<!---->* create a window *<!---->/
605 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
607 * g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
609 * gtk_container_set_border_width (GTK_CONTAINER (window), 10);
611 * /<!---->* create a label *<!---->/
612 * label = gtk_label_new ("And now for something completely different ...");
613 * gtk_container_add (GTK_CONTAINER (window), label);
615 * /<!---->* show everything *<!---->/
616 * gtk_widget_show (label);
617 * gtk_widget_show (window);
619 * /<!---->* create the threads *<!---->/
620 * yes_args.label = label;
621 * yes_args.what = YES_IT_IS;
622 * pthread_create (&yes_tid, NULL, argument_thread, &yes_args);
624 * no_args.label = label;
625 * no_args.what = NO_IT_IS_NOT;
626 * pthread_create (&no_tid, NULL, argument_thread, &no_args);
628 * /<!---->* enter the GTK main loop *<!---->/
629 * gtk_main (<!-- -->);
630 * gdk_threads_leave (<!-- -->);
642 * This function marks the beginning of a critical section in which
643 * GDK and GTK+ functions can be called safely and without causing race
644 * conditions. Only one thread at a time can be in such a critial
648 gdk_threads_enter (void)
650 if (gdk_threads_lock)
651 (*gdk_threads_lock) ();
657 * Leaves a critical region begun with gdk_threads_enter().
660 gdk_threads_leave (void)
662 if (gdk_threads_unlock)
663 (*gdk_threads_unlock) ();
667 gdk_threads_impl_lock (void)
669 g_mutex_lock (&gdk_threads_mutex);
673 gdk_threads_impl_unlock (void)
675 g_mutex_unlock (&gdk_threads_mutex);
681 * Initializes GDK so that it can be used from multiple threads
682 * in conjunction with gdk_threads_enter() and gdk_threads_leave().
684 * This call must be made before any use of the main loop from
685 * GTK+; to be safe, call it before gtk_init().
688 gdk_threads_init (void)
690 if (!gdk_threads_lock)
691 gdk_threads_lock = gdk_threads_impl_lock;
692 if (!gdk_threads_unlock)
693 gdk_threads_unlock = gdk_threads_impl_unlock;
697 * gdk_threads_set_lock_functions: (skip)
698 * @enter_fn: function called to guard GDK
699 * @leave_fn: function called to release the guard
701 * Allows the application to replace the standard method that
702 * GDK uses to protect its data structures. Normally, GDK
703 * creates a single #GMutex that is locked by gdk_threads_enter(),
704 * and released by gdk_threads_leave(); using this function an
705 * application provides, instead, a function @enter_fn that is
706 * called by gdk_threads_enter() and a function @leave_fn that is
707 * called by gdk_threads_leave().
709 * The functions must provide at least same locking functionality
710 * as the default implementation, but can also do extra application
711 * specific processing.
713 * As an example, consider an application that has its own recursive
714 * lock that when held, holds the GTK+ lock as well. When GTK+ unlocks
715 * the GTK+ lock when entering a recursive main loop, the application
716 * must temporarily release its lock as well.
718 * Most threaded GTK+ apps won't need to use this method.
720 * This method must be called before gdk_threads_init(), and cannot
721 * be called multiple times.
726 gdk_threads_set_lock_functions (GCallback enter_fn,
729 g_return_if_fail (gdk_threads_lock == NULL &&
730 gdk_threads_unlock == NULL);
732 gdk_threads_lock = enter_fn;
733 gdk_threads_unlock = leave_fn;
737 gdk_threads_dispatch (gpointer data)
739 GdkThreadsDispatch *dispatch = data;
740 gboolean ret = FALSE;
742 GDK_THREADS_ENTER ();
744 if (!g_source_is_destroyed (g_main_current_source ()))
745 ret = dispatch->func (dispatch->data);
747 GDK_THREADS_LEAVE ();
753 gdk_threads_dispatch_free (gpointer data)
755 GdkThreadsDispatch *dispatch = data;
757 if (dispatch->destroy && dispatch->data)
758 dispatch->destroy (dispatch->data);
760 g_slice_free (GdkThreadsDispatch, data);
765 * gdk_threads_add_idle_full:
766 * @priority: the priority of the idle source. Typically this will be in the
767 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE
768 * @function: function to call
769 * @data: data to pass to @function
770 * @notify: (allow-none): function to call when the idle is removed, or %NULL
772 * Adds a function to be called whenever there are no higher priority
773 * events pending. If the function returns %FALSE it is automatically
774 * removed from the list of event sources and will not be called again.
776 * This variant of g_idle_add_full() calls @function with the GDK lock
777 * held. It can be thought of a MT-safe version for GTK+ widgets for the
778 * following use case, where you have to worry about idle_callback()
779 * running in thread A and accessing @self after it has been finalized
784 * idle_callback (gpointer data)
786 * /* gdk_threads_enter(); would be needed for g_idle_add() */
788 * SomeWidget *self = data;
789 * /* do stuff with self */
793 * /* gdk_threads_leave(); would be needed for g_idle_add() */
798 * some_widget_do_stuff_later (SomeWidget *self)
800 * self->idle_id = gdk_threads_add_idle (idle_callback, self)
801 * /* using g_idle_add() here would require thread protection in the callback */
805 * some_widget_finalize (GObject *object)
807 * SomeWidget *self = SOME_WIDGET (object);
809 * g_source_remove (self->idle_id);
810 * G_OBJECT_CLASS (parent_class)->finalize (object);
814 * Return value: the ID (greater than 0) of the event source.
817 * Rename to: gdk_threads_add_idle
820 gdk_threads_add_idle_full (gint priority,
821 GSourceFunc function,
823 GDestroyNotify notify)
825 GdkThreadsDispatch *dispatch;
827 g_return_val_if_fail (function != NULL, 0);
829 dispatch = g_slice_new (GdkThreadsDispatch);
830 dispatch->func = function;
831 dispatch->data = data;
832 dispatch->destroy = notify;
834 return g_idle_add_full (priority,
835 gdk_threads_dispatch,
837 gdk_threads_dispatch_free);
841 * gdk_threads_add_idle: (skip)
842 * @function: function to call
843 * @data: data to pass to @function
845 * A wrapper for the common usage of gdk_threads_add_idle_full()
846 * assigning the default priority, #G_PRIORITY_DEFAULT_IDLE.
848 * See gdk_threads_add_idle_full().
850 * Return value: the ID (greater than 0) of the event source.
855 gdk_threads_add_idle (GSourceFunc function,
858 return gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE,
859 function, data, NULL);
864 * gdk_threads_add_timeout_full:
865 * @priority: the priority of the timeout source. Typically this will be in the
866 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
867 * @interval: the time between calls to the function, in milliseconds
868 * (1/1000ths of a second)
869 * @function: function to call
870 * @data: data to pass to @function
871 * @notify: (allow-none): function to call when the timeout is removed, or %NULL
873 * Sets a function to be called at regular intervals holding the GDK lock,
874 * with the given priority. The function is called repeatedly until it
875 * returns %FALSE, at which point the timeout is automatically destroyed
876 * and the function will not be called again. The @notify function is
877 * called when the timeout is destroyed. The first call to the
878 * function will be at the end of the first @interval.
880 * Note that timeout functions may be delayed, due to the processing of other
881 * event sources. Thus they should not be relied on for precise timing.
882 * After each call to the timeout function, the time of the next
883 * timeout is recalculated based on the current time and the given interval
884 * (it does not try to 'catch up' time lost in delays).
886 * This variant of g_timeout_add_full() can be thought of a MT-safe version
887 * for GTK+ widgets for the following use case:
890 * static gboolean timeout_callback (gpointer data)
892 * SomeWidget *self = data;
894 * /* do stuff with self */
896 * self->timeout_id = 0;
901 * static void some_widget_do_stuff_later (SomeWidget *self)
903 * self->timeout_id = g_timeout_add (timeout_callback, self)
906 * static void some_widget_finalize (GObject *object)
908 * SomeWidget *self = SOME_WIDGET (object);
910 * if (self->timeout_id)
911 * g_source_remove (self->timeout_id);
913 * G_OBJECT_CLASS (parent_class)->finalize (object);
917 * Return value: the ID (greater than 0) of the event source.
920 * Rename to: gdk_threads_add_timeout
923 gdk_threads_add_timeout_full (gint priority,
925 GSourceFunc function,
927 GDestroyNotify notify)
929 GdkThreadsDispatch *dispatch;
931 g_return_val_if_fail (function != NULL, 0);
933 dispatch = g_slice_new (GdkThreadsDispatch);
934 dispatch->func = function;
935 dispatch->data = data;
936 dispatch->destroy = notify;
938 return g_timeout_add_full (priority,
940 gdk_threads_dispatch,
942 gdk_threads_dispatch_free);
946 * gdk_threads_add_timeout: (skip)
947 * @interval: the time between calls to the function, in milliseconds
948 * (1/1000ths of a second)
949 * @function: function to call
950 * @data: data to pass to @function
952 * A wrapper for the common usage of gdk_threads_add_timeout_full()
953 * assigning the default priority, #G_PRIORITY_DEFAULT.
955 * See gdk_threads_add_timeout_full().
957 * Return value: the ID (greater than 0) of the event source.
962 gdk_threads_add_timeout (guint interval,
963 GSourceFunc function,
966 return gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT,
967 interval, function, data, NULL);
972 * gdk_threads_add_timeout_seconds_full:
973 * @priority: the priority of the timeout source. Typically this will be in the
974 * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
975 * @interval: the time between calls to the function, in seconds
976 * @function: function to call
977 * @data: data to pass to @function
978 * @notify: (allow-none): function to call when the timeout is removed, or %NULL
980 * A variant of gdk_threads_add_timeout_full() with second-granularity.
981 * See g_timeout_add_seconds_full() for a discussion of why it is
982 * a good idea to use this function if you don't need finer granularity.
984 * Return value: the ID (greater than 0) of the event source.
987 * Rename to: gdk_threads_add_timeout_seconds
990 gdk_threads_add_timeout_seconds_full (gint priority,
992 GSourceFunc function,
994 GDestroyNotify notify)
996 GdkThreadsDispatch *dispatch;
998 g_return_val_if_fail (function != NULL, 0);
1000 dispatch = g_slice_new (GdkThreadsDispatch);
1001 dispatch->func = function;
1002 dispatch->data = data;
1003 dispatch->destroy = notify;
1005 return g_timeout_add_seconds_full (priority,
1007 gdk_threads_dispatch,
1009 gdk_threads_dispatch_free);
1013 * gdk_threads_add_timeout_seconds: (skip)
1014 * @interval: the time between calls to the function, in seconds
1015 * @function: function to call
1016 * @data: data to pass to @function
1018 * A wrapper for the common usage of gdk_threads_add_timeout_seconds_full()
1019 * assigning the default priority, #G_PRIORITY_DEFAULT.
1021 * For details, see gdk_threads_add_timeout_full().
1023 * Return value: the ID (greater than 0) of the event source.
1028 gdk_threads_add_timeout_seconds (guint interval,
1029 GSourceFunc function,
1032 return gdk_threads_add_timeout_seconds_full (G_PRIORITY_DEFAULT,
1033 interval, function, data, NULL);
1037 * gdk_get_program_class:
1039 * Gets the program class. Unless the program class has explicitly
1040 * been set with gdk_set_program_class() or with the <option>--class</option>
1041 * commandline option, the default value is the program name (determined
1042 * with g_get_prgname()) with the first character converted to uppercase.
1044 * Returns: the program class.
1047 gdk_get_program_class (void)
1049 return gdk_progclass;
1053 * gdk_set_program_class:
1054 * @program_class: a string.
1056 * Sets the program class. The X11 backend uses the program class to set
1057 * the class name part of the <literal>WM_CLASS</literal> property on
1058 * toplevel windows; see the ICCCM.
1061 gdk_set_program_class (const char *program_class)
1063 g_free (gdk_progclass);
1065 gdk_progclass = g_strdup (program_class);
1069 * gdk_disable_multidevice:
1071 * Disables multidevice support in GDK. This call must happen prior
1072 * to gdk_display_open(), gtk_init(), gtk_init_with_args() or
1073 * gtk_init_check() in order to take effect.
1075 * Most common GTK+ applications won't ever need to call this. Only
1076 * applications that do mixed GDK/Xlib calls could want to disable
1077 * multidevice support if such Xlib code deals with input devices in
1078 * any way and doesn't observe the presence of XInput 2.
1083 gdk_disable_multidevice (void)
1085 if (gdk_initialized)
1088 _gdk_disable_multidevice = TRUE;