]> Pileus Git - ~andy/gtk/blob - gdk/gdk.c
Merge branch 'windows_list'
[~andy/gtk] / gdk / gdk.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "config.h"
28
29 #include <string.h>
30 #include <stdlib.h>
31
32 #include "gdk.h"
33 #include "gdkinternals.h"
34 #include "gdkintl.h"
35
36 #ifndef HAVE_XCONVERTCASE
37 #include "gdkkeysyms.h"
38 #endif
39
40 typedef struct _GdkPredicate  GdkPredicate;
41
42 struct _GdkPredicate
43 {
44   GdkEventFunc func;
45   gpointer data;
46 };
47
48 typedef struct _GdkThreadsDispatch GdkThreadsDispatch;
49
50 struct _GdkThreadsDispatch
51 {
52   GSourceFunc func;
53   gpointer data;
54   GDestroyNotify destroy;
55 };
56
57
58 /* Private variable declarations
59  */
60 static int gdk_initialized = 0;                     /* 1 if the library is initialized,
61                                                      * 0 otherwise.
62                                                      */
63
64 static gchar  *gdk_progclass = NULL;
65
66 #ifdef G_ENABLE_DEBUG
67 static const GDebugKey gdk_debug_keys[] = {
68   {"events",        GDK_DEBUG_EVENTS},
69   {"misc",          GDK_DEBUG_MISC},
70   {"dnd",           GDK_DEBUG_DND},
71   {"xim",           GDK_DEBUG_XIM},
72   {"nograbs",       GDK_DEBUG_NOGRABS},
73   {"colormap",      GDK_DEBUG_COLORMAP},
74   {"gdkrgb",        GDK_DEBUG_GDKRGB},
75   {"gc",            GDK_DEBUG_GC},
76   {"pixmap",        GDK_DEBUG_PIXMAP},
77   {"image",         GDK_DEBUG_IMAGE},
78   {"input",         GDK_DEBUG_INPUT},
79   {"cursor",        GDK_DEBUG_CURSOR},
80   {"multihead",     GDK_DEBUG_MULTIHEAD},
81   {"xinerama",      GDK_DEBUG_XINERAMA},
82   {"draw",          GDK_DEBUG_DRAW},
83   {"eventloop",     GDK_DEBUG_EVENTLOOP}
84 };
85
86 static const int gdk_ndebug_keys = G_N_ELEMENTS (gdk_debug_keys);
87
88 #endif /* G_ENABLE_DEBUG */
89
90 #ifdef G_ENABLE_DEBUG
91 static gboolean
92 gdk_arg_debug_cb (const char *key, const char *value, gpointer user_data, GError **error)
93 {
94   guint debug_value = g_parse_debug_string (value,
95                                             (GDebugKey *) gdk_debug_keys,
96                                             gdk_ndebug_keys);
97
98   if (debug_value == 0 && value != NULL && strcmp (value, "") != 0)
99     {
100       g_set_error (error, 
101                    G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
102                    _("Error parsing option --gdk-debug"));
103       return FALSE;
104     }
105
106   _gdk_debug_flags |= debug_value;
107
108   return TRUE;
109 }
110
111 static gboolean
112 gdk_arg_no_debug_cb (const char *key, const char *value, gpointer user_data, GError **error)
113 {
114   guint debug_value = g_parse_debug_string (value,
115                                             (GDebugKey *) gdk_debug_keys,
116                                             gdk_ndebug_keys);
117
118   if (debug_value == 0 && value != NULL && strcmp (value, "") != 0)
119     {
120       g_set_error (error, 
121                    G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
122                    _("Error parsing option --gdk-no-debug"));
123       return FALSE;
124     }
125
126   _gdk_debug_flags &= ~debug_value;
127
128   return TRUE;
129 }
130 #endif /* G_ENABLE_DEBUG */
131
132 static gboolean
133 gdk_arg_class_cb (const char *key, const char *value, gpointer user_data, GError **error)
134 {
135   gdk_set_program_class (value);
136
137   return TRUE;
138 }
139
140 static gboolean
141 gdk_arg_name_cb (const char *key, const char *value, gpointer user_data, GError **error)
142 {
143   g_set_prgname (value);
144
145   return TRUE;
146 }
147
148 static const GOptionEntry gdk_args[] = {
149   { "class",        0, 0,                     G_OPTION_ARG_CALLBACK, gdk_arg_class_cb,
150     /* Description of --class=CLASS in --help output */        N_("Program class as used by the window manager"),
151     /* Placeholder in --class=CLASS in --help output */        N_("CLASS") },
152   { "name",         0, 0,                     G_OPTION_ARG_CALLBACK, gdk_arg_name_cb,
153     /* Description of --name=NAME in --help output */          N_("Program name as used by the window manager"),
154     /* Placeholder in --name=NAME in --help output */          N_("NAME") },
155   { "display",      0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,   &_gdk_display_name,
156     /* Description of --display=DISPLAY in --help output */    N_("X display to use"),
157     /* Placeholder in --display=DISPLAY in --help output */    N_("DISPLAY") },
158   { "screen",       0, 0, G_OPTION_ARG_INT,      &_gdk_screen_number,
159     /* Description of --screen=SCREEN in --help output */      N_("X screen to use"),
160     /* Placeholder in --screen=SCREEN in --help output */      N_("SCREEN") },
161 #ifdef G_ENABLE_DEBUG
162   { "gdk-debug",    0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_debug_cb,  
163     /* Description of --gdk-debug=FLAGS in --help output */    N_("Gdk debugging flags to set"),
164     /* Placeholder in --gdk-debug=FLAGS in --help output */    N_("FLAGS") },
165   { "gdk-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, gdk_arg_no_debug_cb, 
166     /* Description of --gdk-no-debug=FLAGS in --help output */ N_("Gdk debugging flags to unset"), 
167     /* Placeholder in --gdk-no-debug=FLAGS in --help output */ N_("FLAGS") },
168 #endif 
169   { NULL }
170 };
171
172 /**
173  * gdk_add_option_entries_libgtk_only:
174  * @group: An option group.
175  * 
176  * Appends gdk option entries to the passed in option group. This is
177  * not public API and must not be used by applications.
178  **/
179 void
180 gdk_add_option_entries_libgtk_only (GOptionGroup *group)
181 {
182   g_option_group_add_entries (group, gdk_args);
183   g_option_group_add_entries (group, _gdk_windowing_args);
184 }
185
186 void
187 gdk_pre_parse_libgtk_only (void)
188 {
189   gdk_initialized = TRUE;
190
191   /* We set the fallback program class here, rather than lazily in
192    * gdk_get_program_class, since we don't want -name to override it.
193    */
194   gdk_progclass = g_strdup (g_get_prgname ());
195   if (gdk_progclass && gdk_progclass[0])
196     gdk_progclass[0] = g_ascii_toupper (gdk_progclass[0]);
197   
198 #ifdef G_ENABLE_DEBUG
199   {
200     gchar *debug_string = getenv("GDK_DEBUG");
201     if (debug_string != NULL)
202       _gdk_debug_flags = g_parse_debug_string (debug_string,
203                                               (GDebugKey *) gdk_debug_keys,
204                                               gdk_ndebug_keys);
205   }
206 #endif  /* G_ENABLE_DEBUG */
207
208   if (getenv ("GDK_NATIVE_WINDOWS"))
209     {
210       _gdk_native_windows = TRUE;
211       /* Ensure that this is not propagated
212          to spawned applications */
213       g_unsetenv ("GDK_NATIVE_WINDOWS");
214     }
215
216   g_type_init ();
217
218   /* Do any setup particular to the windowing system
219    */
220   _gdk_windowing_init ();  
221 }
222
223   
224 /**
225  * gdk_parse_args:
226  * @argc: the number of command line arguments.
227  * @argv: the array of command line arguments.
228  * 
229  * Parse command line arguments, and store for future
230  * use by calls to gdk_display_open().
231  *
232  * Any arguments used by GDK are removed from the array and @argc and @argv are
233  * updated accordingly.
234  *
235  * You shouldn't call this function explicitely if you are using
236  * gtk_init(), gtk_init_check(), gdk_init(), or gdk_init_check().
237  *
238  * Since: 2.2
239  **/
240 void
241 gdk_parse_args (int    *argc,
242                 char ***argv)
243 {
244   GOptionContext *option_context;
245   GOptionGroup *option_group;
246   GError *error = NULL;
247
248   if (gdk_initialized)
249     return;
250
251   gdk_pre_parse_libgtk_only ();
252   
253   option_context = g_option_context_new (NULL);
254   g_option_context_set_ignore_unknown_options (option_context, TRUE);
255   g_option_context_set_help_enabled (option_context, FALSE);
256   option_group = g_option_group_new (NULL, NULL, NULL, NULL, NULL);
257   g_option_context_set_main_group (option_context, option_group);
258   
259   g_option_group_add_entries (option_group, gdk_args);
260   g_option_group_add_entries (option_group, _gdk_windowing_args);
261
262   if (!g_option_context_parse (option_context, argc, argv, &error))
263     {
264       g_warning ("%s", error->message);
265       g_error_free (error);
266     }
267   g_option_context_free (option_context);
268
269   if (_gdk_debug_flags && GDK_DEBUG_GDKRGB)
270     gdk_rgb_set_verbose (TRUE);
271
272   GDK_NOTE (MISC, g_message ("progname: \"%s\"", g_get_prgname ()));
273 }
274
275 /** 
276  * gdk_get_display_arg_name:
277  *
278  * Gets the display name specified in the command line arguments passed
279  * to gdk_init() or gdk_parse_args(), if any.
280  *
281  * Returns: the display name, if specified explicitely, otherwise %NULL
282  *   this string is owned by GTK+ and must not be modified or freed.
283  *
284  * Since: 2.2
285  */
286 G_CONST_RETURN gchar *
287 gdk_get_display_arg_name (void)
288 {
289   if (!_gdk_display_arg_name)
290     {
291       if (_gdk_screen_number >= 0)
292         _gdk_display_arg_name = _gdk_windowing_substitute_screen_number (_gdk_display_name, _gdk_screen_number);
293       else
294         _gdk_display_arg_name = g_strdup (_gdk_display_name);
295    }
296
297    return _gdk_display_arg_name;
298 }
299
300 /**
301  * gdk_display_open_default_libgtk_only:
302  * 
303  * Opens the default display specified by command line arguments or
304  * environment variables, sets it as the default display, and returns
305  * it.  gdk_parse_args must have been called first. If the default
306  * display has previously been set, simply returns that. An internal
307  * function that should not be used by applications.
308  * 
309  * Return value: the default display, if it could be opened,
310  *   otherwise %NULL.
311  **/
312 GdkDisplay *
313 gdk_display_open_default_libgtk_only (void)
314 {
315   GdkDisplay *display;
316
317   g_return_val_if_fail (gdk_initialized, NULL);
318   
319   display = gdk_display_get_default ();
320   if (display)
321     return display;
322
323   display = gdk_display_open (gdk_get_display_arg_name ());
324
325   if (!display && _gdk_screen_number >= 0)
326     {
327       g_free (_gdk_display_arg_name);
328       _gdk_display_arg_name = g_strdup (_gdk_display_name);
329       
330       display = gdk_display_open (_gdk_display_name);
331     }
332   
333   if (display)
334     gdk_display_manager_set_default_display (gdk_display_manager_get (),
335                                              display);
336   
337   return display;
338 }
339
340 /**
341  * gdk_init_check:
342  * @argc: (inout):
343  * @argv: (array length=argc) (inout):
344  *
345  *   Initialize the library for use.
346  *
347  * Arguments:
348  *   "argc" is the number of arguments.
349  *   "argv" is an array of strings.
350  *
351  * Results:
352  *   "argc" and "argv" are modified to reflect any arguments
353  *   which were not handled. (Such arguments should either
354  *   be handled by the application or dismissed). If initialization
355  *   fails, returns FALSE, otherwise TRUE.
356  *
357  * Side effects:
358  *   The library is initialized.
359  *
360  *--------------------------------------------------------------
361  */
362 gboolean
363 gdk_init_check (int    *argc,
364                 char ***argv)
365 {
366   gdk_parse_args (argc, argv);
367
368   return gdk_display_open_default_libgtk_only () != NULL;
369 }
370
371
372 /**
373  * gdk_init:
374  * @argc: (inout):
375  * @argv: (array length=argc) (inout):
376  */
377 void
378 gdk_init (int *argc, char ***argv)
379 {
380   if (!gdk_init_check (argc, argv))
381     {
382       const char *display_name = gdk_get_display_arg_name ();
383       g_warning ("cannot open display: %s", display_name ? display_name : "");
384       exit(1);
385     }
386 }
387
388 void
389 gdk_threads_enter (void)
390 {
391   GDK_THREADS_ENTER ();
392 }
393
394 void
395 gdk_threads_leave (void)
396 {
397   GDK_THREADS_LEAVE ();
398 }
399
400 static void
401 gdk_threads_impl_lock (void)
402 {
403   if (gdk_threads_mutex)
404     g_mutex_lock (gdk_threads_mutex);
405 }
406
407 static void
408 gdk_threads_impl_unlock (void)
409 {
410   if (gdk_threads_mutex)
411     g_mutex_unlock (gdk_threads_mutex);
412 }
413
414 /**
415  * gdk_threads_init:
416  * 
417  * Initializes GDK so that it can be used from multiple threads
418  * in conjunction with gdk_threads_enter() and gdk_threads_leave().
419  * g_thread_init() must be called previous to this function.
420  *
421  * This call must be made before any use of the main loop from
422  * GTK+; to be safe, call it before gtk_init().
423  **/
424 void
425 gdk_threads_init (void)
426 {
427   if (!g_thread_supported ())
428     g_error ("g_thread_init() must be called before gdk_threads_init()");
429
430   gdk_threads_mutex = g_mutex_new ();
431   if (!gdk_threads_lock)
432     gdk_threads_lock = gdk_threads_impl_lock;
433   if (!gdk_threads_unlock)
434     gdk_threads_unlock = gdk_threads_impl_unlock;
435 }
436
437 /**
438  * gdk_threads_set_lock_functions:
439  * @enter_fn:   function called to guard GDK
440  * @leave_fn: function called to release the guard
441  *
442  * Allows the application to replace the standard method that
443  * GDK uses to protect its data structures. Normally, GDK
444  * creates a single #GMutex that is locked by gdk_threads_enter(),
445  * and released by gdk_threads_leave(); using this function an
446  * application provides, instead, a function @enter_fn that is
447  * called by gdk_threads_enter() and a function @leave_fn that is
448  * called by gdk_threads_leave().
449  *
450  * The functions must provide at least same locking functionality
451  * as the default implementation, but can also do extra application
452  * specific processing.
453  *
454  * As an example, consider an application that has its own recursive
455  * lock that when held, holds the GTK+ lock as well. When GTK+ unlocks
456  * the GTK+ lock when entering a recursive main loop, the application
457  * must temporarily release its lock as well.
458  *
459  * Most threaded GTK+ apps won't need to use this method.
460  *
461  * This method must be called before gdk_threads_init(), and cannot
462  * be called multiple times.
463  *
464  * Since: 2.4
465  **/
466 void
467 gdk_threads_set_lock_functions (GCallback enter_fn,
468                                 GCallback leave_fn)
469 {
470   g_return_if_fail (gdk_threads_lock == NULL &&
471                     gdk_threads_unlock == NULL);
472
473   gdk_threads_lock = enter_fn;
474   gdk_threads_unlock = leave_fn;
475 }
476
477 static gboolean
478 gdk_threads_dispatch (gpointer data)
479 {
480   GdkThreadsDispatch *dispatch = data;
481   gboolean ret = FALSE;
482
483   GDK_THREADS_ENTER ();
484
485   if (!g_source_is_destroyed (g_main_current_source ()))
486     ret = dispatch->func (dispatch->data);
487
488   GDK_THREADS_LEAVE ();
489
490   return ret;
491 }
492
493 static void
494 gdk_threads_dispatch_free (gpointer data)
495 {
496   GdkThreadsDispatch *dispatch = data;
497
498   if (dispatch->destroy && dispatch->data)
499     dispatch->destroy (dispatch->data);
500
501   g_slice_free (GdkThreadsDispatch, data);
502 }
503
504
505 /**
506  * gdk_threads_add_idle_full:
507  * @priority: the priority of the idle source. Typically this will be in the
508  *            range btweeen #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE
509  * @function: function to call
510  * @data:     data to pass to @function
511  * @notify: (allow-none):   function to call when the idle is removed, or %NULL
512  *
513  * Adds a function to be called whenever there are no higher priority
514  * events pending.  If the function returns %FALSE it is automatically
515  * removed from the list of event sources and will not be called again.
516  *
517  * This variant of g_idle_add_full() calls @function with the GDK lock
518  * held. It can be thought of a MT-safe version for GTK+ widgets for the 
519  * following use case, where you have to worry about idle_callback()
520  * running in thread A and accessing @self after it has been finalized
521  * in thread B:
522  *
523  * |[
524  * static gboolean
525  * idle_callback (gpointer data)
526  * {
527  *    /&ast; gdk_threads_enter(); would be needed for g_idle_add() &ast;/
528  *
529  *    SomeWidget *self = data;
530  *    /&ast; do stuff with self &ast;/
531  *
532  *    self->idle_id = 0;
533  *
534  *    /&ast; gdk_threads_leave(); would be needed for g_idle_add() &ast;/
535  *    return FALSE;
536  * }
537  *
538  * static void
539  * some_widget_do_stuff_later (SomeWidget *self)
540  * {
541  *    self->idle_id = gdk_threads_add_idle (idle_callback, self)
542  *    /&ast; using g_idle_add() here would require thread protection in the callback &ast;/
543  * }
544  *
545  * static void
546  * some_widget_finalize (GObject *object)
547  * {
548  *    SomeWidget *self = SOME_WIDGET (object);
549  *    if (self->idle_id)
550  *      g_source_remove (self->idle_id);
551  *    G_OBJECT_CLASS (parent_class)->finalize (object);
552  * }
553  * ]|
554  *
555  * Return value: the ID (greater than 0) of the event source.
556  *
557  * Since: 2.12
558  */
559 guint
560 gdk_threads_add_idle_full (gint           priority,
561                            GSourceFunc    function,
562                            gpointer       data,
563                            GDestroyNotify notify)
564 {
565   GdkThreadsDispatch *dispatch;
566
567   g_return_val_if_fail (function != NULL, 0);
568
569   dispatch = g_slice_new (GdkThreadsDispatch);
570   dispatch->func = function;
571   dispatch->data = data;
572   dispatch->destroy = notify;
573
574   return g_idle_add_full (priority,
575                           gdk_threads_dispatch,
576                           dispatch,
577                           gdk_threads_dispatch_free);
578 }
579
580 /**
581  * gdk_threads_add_idle:
582  * @function: function to call
583  * @data:     data to pass to @function
584  *
585  * A wrapper for the common usage of gdk_threads_add_idle_full() 
586  * assigning the default priority, #G_PRIORITY_DEFAULT_IDLE.
587  *
588  * See gdk_threads_add_idle_full().
589  *
590  * Return value: the ID (greater than 0) of the event source.
591  * 
592  * Since: 2.12
593  */
594 guint
595 gdk_threads_add_idle (GSourceFunc    function,
596                       gpointer       data)
597 {
598   return gdk_threads_add_idle_full (G_PRIORITY_DEFAULT_IDLE,
599                                     function, data, NULL);
600 }
601
602
603 /**
604  * gdk_threads_add_timeout_full:
605  * @priority: the priority of the timeout source. Typically this will be in the
606  *            range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
607  * @interval: the time between calls to the function, in milliseconds
608  *             (1/1000ths of a second)
609  * @function: function to call
610  * @data:     data to pass to @function
611  * @notify: (allow-none):   function to call when the timeout is removed, or %NULL
612  *
613  * Sets a function to be called at regular intervals holding the GDK lock,
614  * with the given priority.  The function is called repeatedly until it 
615  * returns %FALSE, at which point the timeout is automatically destroyed 
616  * and the function will not be called again.  The @notify function is
617  * called when the timeout is destroyed.  The first call to the
618  * function will be at the end of the first @interval.
619  *
620  * Note that timeout functions may be delayed, due to the processing of other
621  * event sources. Thus they should not be relied on for precise timing.
622  * After each call to the timeout function, the time of the next
623  * timeout is recalculated based on the current time and the given interval
624  * (it does not try to 'catch up' time lost in delays).
625  *
626  * This variant of g_timeout_add_full() can be thought of a MT-safe version 
627  * for GTK+ widgets for the following use case:
628  *
629  * |[
630  * static gboolean timeout_callback (gpointer data)
631  * {
632  *    SomeWidget *self = data;
633  *    
634  *    /&ast; do stuff with self &ast;/
635  *    
636  *    self->timeout_id = 0;
637  *    
638  *    return FALSE;
639  * }
640  *  
641  * static void some_widget_do_stuff_later (SomeWidget *self)
642  * {
643  *    self->timeout_id = g_timeout_add (timeout_callback, self)
644  * }
645  *  
646  * static void some_widget_finalize (GObject *object)
647  * {
648  *    SomeWidget *self = SOME_WIDGET (object);
649  *    
650  *    if (self->timeout_id)
651  *      g_source_remove (self->timeout_id);
652  *    
653  *    G_OBJECT_CLASS (parent_class)->finalize (object);
654  * }
655  * ]|
656  *
657  * Return value: the ID (greater than 0) of the event source.
658  * 
659  * Since: 2.12
660  */
661 guint
662 gdk_threads_add_timeout_full (gint           priority,
663                               guint          interval,
664                               GSourceFunc    function,
665                               gpointer       data,
666                               GDestroyNotify notify)
667 {
668   GdkThreadsDispatch *dispatch;
669
670   g_return_val_if_fail (function != NULL, 0);
671
672   dispatch = g_slice_new (GdkThreadsDispatch);
673   dispatch->func = function;
674   dispatch->data = data;
675   dispatch->destroy = notify;
676
677   return g_timeout_add_full (priority, 
678                              interval,
679                              gdk_threads_dispatch, 
680                              dispatch, 
681                              gdk_threads_dispatch_free);
682 }
683
684 /**
685  * gdk_threads_add_timeout:
686  * @interval: the time between calls to the function, in milliseconds
687  *             (1/1000ths of a second)
688  * @function: function to call
689  * @data:     data to pass to @function
690  *
691  * A wrapper for the common usage of gdk_threads_add_timeout_full() 
692  * assigning the default priority, #G_PRIORITY_DEFAULT.
693  *
694  * See gdk_threads_add_timeout_full().
695  * 
696  * Return value: the ID (greater than 0) of the event source.
697  *
698  * Since: 2.12
699  */
700 guint
701 gdk_threads_add_timeout (guint       interval,
702                          GSourceFunc function,
703                          gpointer    data)
704 {
705   return gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT,
706                                        interval, function, data, NULL);
707 }
708
709
710 /**
711  * gdk_threads_add_timeout_seconds_full:
712  * @priority: the priority of the timeout source. Typically this will be in the
713  *            range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
714  * @interval: the time between calls to the function, in seconds
715  * @function: function to call
716  * @data:     data to pass to @function
717  * @notify: (allow-none):   function to call when the timeout is removed, or %NULL
718  *
719  * A variant of gdk_threads_add_timout_full() with second-granularity.
720  * See g_timeout_add_seconds_full() for a discussion of why it is
721  * a good idea to use this function if you don't need finer granularity.
722  *
723  *  Return value: the ID (greater than 0) of the event source.
724  * 
725  * Since: 2.14
726  */
727 guint
728 gdk_threads_add_timeout_seconds_full (gint           priority,
729                                       guint          interval,
730                                       GSourceFunc    function,
731                                       gpointer       data,
732                                       GDestroyNotify notify)
733 {
734   GdkThreadsDispatch *dispatch;
735
736   g_return_val_if_fail (function != NULL, 0);
737
738   dispatch = g_slice_new (GdkThreadsDispatch);
739   dispatch->func = function;
740   dispatch->data = data;
741   dispatch->destroy = notify;
742
743   return g_timeout_add_seconds_full (priority, 
744                                      interval,
745                                      gdk_threads_dispatch, 
746                                      dispatch, 
747                                      gdk_threads_dispatch_free);
748 }
749
750 /**
751  * gdk_threads_add_timeout_seconds:
752  * @interval: the time between calls to the function, in seconds
753  * @function: function to call
754  * @data:     data to pass to @function
755  *
756  * A wrapper for the common usage of gdk_threads_add_timeout_seconds_full() 
757  * assigning the default priority, #G_PRIORITY_DEFAULT.
758  *
759  * For details, see gdk_threads_add_timeout_full().
760  * 
761  * Return value: the ID (greater than 0) of the event source.
762  *
763  * Since: 2.14
764  */
765 guint
766 gdk_threads_add_timeout_seconds (guint       interval,
767                                  GSourceFunc function,
768                                  gpointer    data)
769 {
770   return gdk_threads_add_timeout_seconds_full (G_PRIORITY_DEFAULT,
771                                                interval, function, data, NULL);
772 }
773
774
775 G_CONST_RETURN char *
776 gdk_get_program_class (void)
777 {
778   return gdk_progclass;
779 }
780
781 void
782 gdk_set_program_class (const char *program_class)
783 {
784   g_free (gdk_progclass);
785
786   gdk_progclass = g_strdup (program_class);
787 }
788
789 /**
790  * gdk_enable_multidevice:
791  *
792  * Enables multidevice support in GDK. This call must happen prior
793  * to gdk_display_open(), gtk_init(), gtk_init_with_args() or
794  * gtk_init_check() in order to take effect.
795  *
796  * Note that individual #GdkWindow<!-- -->s still need to explicitly
797  * enable multidevice awareness through gdk_window_set_support_multidevice().
798  *
799  * This function must be called before initializing GDK.
800  *
801  * Since: 3.0
802  **/
803 void
804 gdk_enable_multidevice (void)
805 {
806   if (gdk_initialized)
807     return;
808
809   _gdk_enable_multidevice = TRUE;
810 }