]> Pileus Git - ~andy/gtk/blob - gtk/gtksettings.c
Bug 536185 – monitor font configuration
[~andy/gtk] / gtk / gtksettings.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2000 Red Hat, Inc.
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 Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
20
21 #include <config.h>
22
23 #include <string.h>
24
25 #include "gtkmodules.h"
26 #include "gtksettings.h"
27 #include "gtkrc.h"
28 #include "gtkintl.h"
29 #include "gtkwidget.h"
30 #include "gtkprivate.h"
31 #include "gtkalias.h"
32
33 #ifdef GDK_WINDOWING_X11
34 #include "x11/gdkx.h"
35 #include <pango/pangofc-fontmap.h>
36 #endif
37
38 #define DEFAULT_TIMEOUT_INITIAL 200
39 #define DEFAULT_TIMEOUT_REPEAT   20
40 #define DEFAULT_TIMEOUT_EXPAND  500
41
42 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
43
44 typedef enum
45 {
46   GTK_SETTINGS_SOURCE_DEFAULT,
47   GTK_SETTINGS_SOURCE_RC_FILE,
48   GTK_SETTINGS_SOURCE_XSETTING,
49   GTK_SETTINGS_SOURCE_APPLICATION
50 } GtkSettingsSource;
51
52 struct _GtkSettingsValuePrivate
53 {
54   GtkSettingsValue public;
55   GtkSettingsSource source;
56 };
57
58 struct _GtkSettingsPropertyValue
59 {
60   GValue value;
61   GtkSettingsSource source;
62 };
63
64 enum {
65   PROP_0,
66   PROP_DOUBLE_CLICK_TIME,
67   PROP_DOUBLE_CLICK_DISTANCE,
68   PROP_CURSOR_BLINK,
69   PROP_CURSOR_BLINK_TIME,
70   PROP_CURSOR_BLINK_TIMEOUT,
71   PROP_SPLIT_CURSOR,
72   PROP_THEME_NAME,
73   PROP_ICON_THEME_NAME,
74   PROP_FALLBACK_ICON_THEME,
75   PROP_KEY_THEME_NAME,
76   PROP_MENU_BAR_ACCEL,
77   PROP_DND_DRAG_THRESHOLD,
78   PROP_FONT_NAME,
79   PROP_ICON_SIZES,
80   PROP_MODULES,
81 #ifdef GDK_WINDOWING_X11
82   PROP_XFT_ANTIALIAS,
83   PROP_XFT_HINTING,
84   PROP_XFT_HINTSTYLE,
85   PROP_XFT_RGBA,
86   PROP_XFT_DPI,
87   PROP_CURSOR_THEME_NAME,
88   PROP_CURSOR_THEME_SIZE,
89 #endif
90   PROP_ALTERNATIVE_BUTTON_ORDER,
91   PROP_ALTERNATIVE_SORT_ARROWS,
92   PROP_SHOW_INPUT_METHOD_MENU,
93   PROP_SHOW_UNICODE_MENU,
94   PROP_TIMEOUT_INITIAL,
95   PROP_TIMEOUT_REPEAT,
96   PROP_TIMEOUT_EXPAND,
97   PROP_COLOR_SCHEME,
98   PROP_ENABLE_ANIMATIONS,
99   PROP_TOUCHSCREEN_MODE,
100   PROP_TOOLTIP_TIMEOUT,
101   PROP_TOOLTIP_BROWSE_TIMEOUT,
102   PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
103   PROP_KEYNAV_CURSOR_ONLY,
104   PROP_KEYNAV_WRAP_AROUND,
105   PROP_ERROR_BELL,
106   PROP_COLOR_HASH,
107   PROP_FILE_CHOOSER_BACKEND,
108   PROP_PRINT_BACKENDS,
109   PROP_PRINT_PREVIEW_COMMAND,
110   PROP_ENABLE_MNEMONICS,
111   PROP_ENABLE_ACCELS,
112   PROP_RECENT_FILES_LIMIT,
113   PROP_IM_MODULE,
114   PROP_RECENT_FILES_MAX_AGE,
115   PROP_FONTCONFIG_TIMESTAMP
116 };
117
118
119 /* --- prototypes --- */
120 static void     gtk_settings_finalize            (GObject               *object);
121 static void     gtk_settings_get_property        (GObject               *object,
122                                                   guint                  property_id,
123                                                   GValue                *value,
124                                                   GParamSpec            *pspec);
125 static void     gtk_settings_set_property        (GObject               *object,
126                                                   guint                  property_id,
127                                                   const GValue          *value,
128                                                   GParamSpec            *pspec);
129 static void     gtk_settings_notify              (GObject               *object,
130                                                   GParamSpec            *pspec);
131 static guint    settings_install_property_parser (GtkSettingsClass      *class,
132                                                   GParamSpec            *pspec,
133                                                   GtkRcPropertyParser    parser);
134 static void    settings_update_double_click      (GtkSettings           *settings);
135 static void    settings_update_modules           (GtkSettings           *settings);
136
137 #ifdef GDK_WINDOWING_X11
138 static void    settings_update_cursor_theme      (GtkSettings           *settings);
139 static void    settings_update_resolution        (GtkSettings           *settings);
140 static void    settings_update_font_options      (GtkSettings           *settings);
141 static gboolean settings_update_fontconfig       (GtkSettings           *settings);
142 #endif
143 static void    settings_update_color_scheme      (GtkSettings *settings);
144
145 static void    merge_color_scheme                (GtkSettings           *settings, 
146                                                   const GValue          *value, 
147                                                   GtkSettingsSource      source);
148 static gchar  *get_color_scheme                  (GtkSettings           *settings);
149 static GHashTable *get_color_hash                (GtkSettings           *settings);
150
151
152 /* --- variables --- */
153 static GQuark            quark_property_parser = 0;
154 static GSList           *object_list = NULL;
155 static guint             class_n_properties = 0;
156
157
158 G_DEFINE_TYPE (GtkSettings, gtk_settings, G_TYPE_OBJECT)
159
160 /* --- functions --- */
161 static void
162 gtk_settings_init (GtkSettings *settings)
163 {
164   GParamSpec **pspecs, **p;
165   guint i = 0;
166   
167   g_datalist_init (&settings->queued_settings);
168   object_list = g_slist_prepend (object_list, settings);
169
170   /* build up property array for all yet existing properties and queue
171    * notification for them (at least notification for internal properties
172    * will instantly be caught)
173    */
174   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
175   for (p = pspecs; *p; p++)
176     if ((*p)->owner_type == G_OBJECT_TYPE (settings))
177       i++;
178   settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
179   i = 0;
180   g_object_freeze_notify (G_OBJECT (settings));
181   for (p = pspecs; *p; p++)
182     {
183       GParamSpec *pspec = *p;
184
185       if (pspec->owner_type != G_OBJECT_TYPE (settings))
186         continue;
187       g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
188       g_param_value_set_default (pspec, &settings->property_values[i].value);
189       g_object_notify (G_OBJECT (settings), pspec->name);
190       settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
191       i++;
192     }
193   g_object_thaw_notify (G_OBJECT (settings));
194   g_free (pspecs);
195 }
196
197 static void
198 gtk_settings_class_init (GtkSettingsClass *class)
199 {
200   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
201   guint result;
202   
203   gobject_class->finalize = gtk_settings_finalize;
204   gobject_class->get_property = gtk_settings_get_property;
205   gobject_class->set_property = gtk_settings_set_property;
206   gobject_class->notify = gtk_settings_notify;
207
208   quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
209   result = settings_install_property_parser (class,
210                                              g_param_spec_int ("gtk-double-click-time",
211                                                                P_("Double Click Time"),
212                                                                P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
213                                                                0, G_MAXINT, 250,
214                                                                GTK_PARAM_READWRITE),
215                                              NULL);
216   g_assert (result == PROP_DOUBLE_CLICK_TIME);
217   result = settings_install_property_parser (class,
218                                              g_param_spec_int ("gtk-double-click-distance",
219                                                                P_("Double Click Distance"),
220                                                                P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
221                                                                0, G_MAXINT, 5,
222                                                                GTK_PARAM_READWRITE),
223                                              NULL);
224   g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
225
226   /**
227    * GtkSettings:gtk-cursor-blink:
228    *
229    * Whether the cursor should blink. 
230    *
231    * Also see the #GtkSettings:gtk-cursor-blink-timeout setting, 
232    * which allows more flexible control over cursor blinking.
233    */
234   result = settings_install_property_parser (class,
235                                              g_param_spec_boolean ("gtk-cursor-blink",
236                                                                    P_("Cursor Blink"),
237                                                                    P_("Whether the cursor should blink"),
238                                                                    TRUE,
239                                                                    GTK_PARAM_READWRITE),
240                                              NULL);
241   g_assert (result == PROP_CURSOR_BLINK);
242   result = settings_install_property_parser (class,
243                                              g_param_spec_int ("gtk-cursor-blink-time",
244                                                                P_("Cursor Blink Time"),
245                                                                P_("Length of the cursor blink cycle, in milliseconds"),
246                                                                100, G_MAXINT, 1200,
247                                                                GTK_PARAM_READWRITE),
248                                              NULL);
249   g_assert (result == PROP_CURSOR_BLINK_TIME);
250  
251   /**
252    * GtkSettings:gtk-cursor-blink-timeout:
253    *
254    * Time after which the cursor stops blinking, in seconds.
255    * The timer is reset after each user interaction.
256    *
257    * Setting this to zero has the same effect as setting
258    * #GtkSettings:gtk-cursor-blink to %FALSE. 
259    *
260    * Since: 2.12
261    */
262   result = settings_install_property_parser (class,
263                                              g_param_spec_int ("gtk-cursor-blink-timeout",
264                                                                P_("Cursor Blink Timeout"),
265                                                                P_("Time after which the cursor stops blinking, in seconds"),
266                                                                1, G_MAXINT, G_MAXINT,
267                                                                GTK_PARAM_READWRITE),
268                                              NULL);
269   g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
270   result = settings_install_property_parser (class,
271                                              g_param_spec_boolean ("gtk-split-cursor",
272                                                                    P_("Split Cursor"),
273                                                                    P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
274                                                                    TRUE,
275                                                                    GTK_PARAM_READWRITE),
276                                              NULL);
277   g_assert (result == PROP_SPLIT_CURSOR);
278   result = settings_install_property_parser (class,
279                                              g_param_spec_string ("gtk-theme-name",
280                                                                    P_("Theme Name"),
281                                                                    P_("Name of theme RC file to load"),
282                                                                   "Raleigh",
283                                                                   GTK_PARAM_READWRITE),
284                                              NULL);
285   g_assert (result == PROP_THEME_NAME);
286
287   result = settings_install_property_parser (class,
288                                              g_param_spec_string ("gtk-icon-theme-name",
289                                                                   P_("Icon Theme Name"),
290                                                                   P_("Name of icon theme to use"),
291                                                                   "hicolor",
292                                                                   GTK_PARAM_READWRITE),
293                                              NULL);
294   g_assert (result == PROP_ICON_THEME_NAME);
295
296   result = settings_install_property_parser (class,
297                                              g_param_spec_string ("gtk-fallback-icon-theme",
298                                                                   P_("Fallback Icon Theme Name"),
299                                                                   P_("Name of a icon theme to fall back to"),
300                                                                   NULL,
301                                                                   GTK_PARAM_READWRITE),
302                                              NULL);
303   g_assert (result == PROP_FALLBACK_ICON_THEME);
304   
305   result = settings_install_property_parser (class,
306                                              g_param_spec_string ("gtk-key-theme-name",
307                                                                   P_("Key Theme Name"),
308                                                                   P_("Name of key theme RC file to load"),
309                                                                   NULL,
310                                                                   GTK_PARAM_READWRITE),
311                                              NULL);
312   g_assert (result == PROP_KEY_THEME_NAME);    
313
314   result = settings_install_property_parser (class,
315                                              g_param_spec_string ("gtk-menu-bar-accel",
316                                                                   P_("Menu bar accelerator"),
317                                                                   P_("Keybinding to activate the menu bar"),
318                                                                   "F10",
319                                                                   GTK_PARAM_READWRITE),
320                                              NULL);
321   g_assert (result == PROP_MENU_BAR_ACCEL);
322
323   result = settings_install_property_parser (class,
324                                              g_param_spec_int ("gtk-dnd-drag-threshold",
325                                                                P_("Drag threshold"),
326                                                                P_("Number of pixels the cursor can move before dragging"),
327                                                                1, G_MAXINT, 8,
328                                                                GTK_PARAM_READWRITE),
329                                              NULL);
330   g_assert (result == PROP_DND_DRAG_THRESHOLD);
331
332   result = settings_install_property_parser (class,
333                                              g_param_spec_string ("gtk-font-name",
334                                                                    P_("Font Name"),
335                                                                    P_("Name of default font to use"),
336                                                                   "Sans 10",
337                                                                   GTK_PARAM_READWRITE),
338                                              NULL);
339   g_assert (result == PROP_FONT_NAME);
340
341   result = settings_install_property_parser (class,
342                                              g_param_spec_string ("gtk-icon-sizes",
343                                                                    P_("Icon Sizes"),
344                                                                    P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
345                                                                   NULL,
346                                                                   GTK_PARAM_READWRITE),
347                                              NULL);
348   g_assert (result == PROP_ICON_SIZES);
349
350   result = settings_install_property_parser (class,
351                                              g_param_spec_string ("gtk-modules",
352                                                                   P_("GTK Modules"),
353                                                                   P_("List of currently active GTK modules"),
354                                                                   NULL,
355                                                                   GTK_PARAM_READWRITE),
356                                              NULL);
357   g_assert (result == PROP_MODULES);
358
359 #ifdef GDK_WINDOWING_X11
360   result = settings_install_property_parser (class,
361                                              g_param_spec_int ("gtk-xft-antialias",
362                                                                P_("Xft Antialias"),
363                                                                P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
364                                                                -1, 1, -1,
365                                                                GTK_PARAM_READWRITE),
366                                              NULL);
367  
368   g_assert (result == PROP_XFT_ANTIALIAS);
369   
370   result = settings_install_property_parser (class,
371                                              g_param_spec_int ("gtk-xft-hinting",
372                                                                P_("Xft Hinting"),
373                                                                P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
374                                                                -1, 1, -1,
375                                                                GTK_PARAM_READWRITE),
376                                              NULL);
377   
378   g_assert (result == PROP_XFT_HINTING);
379   
380   result = settings_install_property_parser (class,
381                                              g_param_spec_string ("gtk-xft-hintstyle",
382                                                                   P_("Xft Hint Style"),
383                                                                   P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
384                                                                   NULL,
385                                                                   GTK_PARAM_READWRITE),
386                                               NULL);
387   
388   g_assert (result == PROP_XFT_HINTSTYLE);
389   
390   result = settings_install_property_parser (class,
391                                              g_param_spec_string ("gtk-xft-rgba",
392                                                                   P_("Xft RGBA"),
393                                                                   P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
394                                                                   NULL,
395                                                                   GTK_PARAM_READWRITE),
396                                              NULL);
397   
398   g_assert (result == PROP_XFT_RGBA);
399   
400   result = settings_install_property_parser (class,
401                                              g_param_spec_int ("gtk-xft-dpi",
402                                                                P_("Xft DPI"),
403                                                                P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
404                                                                -1, 1024*1024, -1,
405                                                                GTK_PARAM_READWRITE),
406                                              NULL);
407   
408   g_assert (result == PROP_XFT_DPI);
409
410   result = settings_install_property_parser (class,
411                                              g_param_spec_string ("gtk-cursor-theme-name",
412                                                                   P_("Cursor theme name"),
413                                                                   P_("Name of the cursor theme to use, or NULL to use the default theme"),
414                                                                   NULL,
415                                                                   GTK_PARAM_READWRITE),
416                                              NULL);
417   g_assert (result == PROP_CURSOR_THEME_NAME);
418
419   result = settings_install_property_parser (class,
420                                              g_param_spec_int ("gtk-cursor-theme-size",
421                                                                P_("Cursor theme size"),
422                                                                P_("Size to use for cursors, or 0 to use the default size"),
423                                                                0, 128, 0,
424                                                                GTK_PARAM_READWRITE),
425                                              NULL);
426   
427   g_assert (result == PROP_CURSOR_THEME_SIZE);
428
429 #endif  /* GDK_WINDOWING_X11 */
430   result = settings_install_property_parser (class,
431                                              g_param_spec_boolean ("gtk-alternative-button-order",
432                                                                    P_("Alternative button order"),
433                                                                    P_("Whether buttons in dialogs should use the alternative button order"),
434                                                                    FALSE,
435                                                                    GTK_PARAM_READWRITE),
436                                              NULL);
437   g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
438
439   /**
440    * GtkSettings:gtk-alternative-sort-arrows:
441    *
442    * Controls the direction of the sort indicators in sorted list and tree
443    * views. By default an arrow pointing down means the column is sorted
444    * in ascending order. When set to %TRUE, this order will be inverted.
445    *
446    * Since: 2.12
447    */
448   result = settings_install_property_parser (class,
449                                              g_param_spec_boolean ("gtk-alternative-sort-arrows",
450                                                                    P_("Alternative sort indicator direction"),
451                                                                    P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
452                                                                    FALSE,
453                                                                    GTK_PARAM_READWRITE),
454                                              NULL);
455   g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
456
457   result = settings_install_property_parser (class,
458                                              g_param_spec_boolean ("gtk-show-input-method-menu",
459                                                                    P_("Show the 'Input Methods' menu"),
460                                                                    P_("Whether the context menus of entries and text views should offer to change the input method"),
461                                                                    TRUE,
462                                                                    GTK_PARAM_READWRITE),
463                                              NULL);
464   g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
465
466   result = settings_install_property_parser (class,
467                                              g_param_spec_boolean ("gtk-show-unicode-menu",
468                                                                    P_("Show the 'Insert Unicode Control Character' menu"),
469                                                                    P_("Whether the context menus of entries and text views should offer to insert control characters"),
470                                                                    TRUE,
471                                                                    GTK_PARAM_READWRITE),
472                                              NULL);
473   g_assert (result == PROP_SHOW_UNICODE_MENU);
474
475   result = settings_install_property_parser (class,
476                                              g_param_spec_int ("gtk-timeout-initial",
477                                                                P_("Start timeout"),
478                                                                P_("Starting value for timeouts, when button is pressed"),
479                                                                0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
480                                                                GTK_PARAM_READWRITE),
481                                              NULL);
482
483   g_assert (result == PROP_TIMEOUT_INITIAL);
484
485   result = settings_install_property_parser (class,
486                                              g_param_spec_int ("gtk-timeout-repeat",
487                                                                P_("Repeat timeout"),
488                                                                P_("Repeat value for timeouts, when button is pressed"),
489                                                                0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
490                                                                GTK_PARAM_READWRITE),
491                                              NULL);
492
493   g_assert (result == PROP_TIMEOUT_REPEAT);
494
495   result = settings_install_property_parser (class,
496                                              g_param_spec_int ("gtk-timeout-expand",
497                                                                P_("Expand timeout"),
498                                                                P_("Expand value for timeouts, when a widget is expanding a new region"),
499                                                                0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
500                                                                GTK_PARAM_READWRITE),
501                                              NULL);
502
503   g_assert (result == PROP_TIMEOUT_EXPAND);
504
505   /**
506    * GtkSettings:gtk-color-scheme:
507    *
508    * A palette of named colors for use in themes. The format of the string is
509    * <programlisting>
510    * name1: color1
511    * name2: color2
512    * ...
513    * </programlisting>
514    * Color names must be acceptable as identifiers in the 
515    * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
516    * color specifications must be in the format accepted by
517    * gdk_color_parse().
518    * 
519    * Note that due to the way the color tables from different sources are
520    * merged, color specifications will be converted to hexadecimal form
521    * when getting this property.
522    *
523    * Starting with GTK+ 2.12, the entries can alternatively be separated
524    * by ';' instead of newlines:
525    * <programlisting>
526    * name1: color1; name2: color2; ...
527    * </programlisting>
528    *
529    * Since: 2.10
530    */
531   result = settings_install_property_parser (class,
532                                              g_param_spec_string ("gtk-color-scheme",
533                                                                   P_("Color scheme"),
534                                                                   P_("A palette of named colors for use in themes"),
535                                                                   "",
536                                                                   GTK_PARAM_READWRITE),
537                                              NULL);
538
539   g_assert (result == PROP_COLOR_SCHEME);
540
541   result = settings_install_property_parser (class,
542                                              g_param_spec_boolean ("gtk-enable-animations",
543                                                                    P_("Enable Animations"),
544                                                                    P_("Whether to enable toolkit-wide animations."),
545                                                                    TRUE,
546                                                                    GTK_PARAM_READWRITE),
547                                              NULL);
548
549   g_assert (result == PROP_ENABLE_ANIMATIONS);
550
551   /**
552    * GtkSettings:gtk-touchscreen-mode:
553    *
554    * When %TRUE, there are no motion notify events delivered on this screen,
555    * and widgets can't use the pointer hovering them for any essential
556    * functionality.
557    *
558    * Since: 2.10
559    */
560   result = settings_install_property_parser (class,
561                                              g_param_spec_boolean ("gtk-touchscreen-mode",
562                                                                    P_("Enable Touchscreen Mode"),
563                                                                    P_("When TRUE, there are no motion notify events delivered on this screen"),
564                                                                    FALSE,
565                                                                    GTK_PARAM_READWRITE),
566                                              NULL);
567
568   g_assert (result == PROP_TOUCHSCREEN_MODE);
569
570   /**
571    * GtkSettings:gtk-tooltip-timeout:
572    *
573    * Time, in milliseconds, after which a tooltip could appear if the
574    * cursor is hovering on top of a widget.
575    *
576    * Since: 2.12
577    */
578   result = settings_install_property_parser (class,
579                                              g_param_spec_int ("gtk-tooltip-timeout",
580                                                                P_("Tooltip timeout"),
581                                                                P_("Timeout before tooltip is shown"),
582                                                                0, G_MAXINT,
583                                                                500,
584                                                                GTK_PARAM_READWRITE),
585                                              NULL);
586
587   g_assert (result == PROP_TOOLTIP_TIMEOUT);
588
589   /**
590    * GtkSettings:gtk-tooltip-browse-timeout:
591    *
592    * Controls the time after which tooltips will appear when
593    * browse mode is enabled, in milliseconds.
594    *
595    * Browse mode is enabled when the mouse pointer moves off an object
596    * where a tooltip was currently being displayed. If the mouse pointer
597    * hits another object before the browse mode timeout expires (see
598    * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the 
599    * amount of milliseconds specified by this setting to popup the tooltip
600    * for the new object.
601    *
602    * Since: 2.12
603    */
604   result = settings_install_property_parser (class,
605                                              g_param_spec_int ("gtk-tooltip-browse-timeout",
606                                                                P_("Tooltip browse timeout"),
607                                                                P_("Timeout before tooltip is shown when browse mode is enabled"),
608                                                                0, G_MAXINT,
609                                                                60,
610                                                                GTK_PARAM_READWRITE),
611                                              NULL);
612
613   g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
614
615   /**
616    * GtkSettings:gtk-tooltip-browse-mode-timeout:
617    *
618    * Amount of time, in milliseconds, after which the browse mode
619    * will be disabled.
620    *
621    * See #GtkSettings:gtk-tooltip-browse-timeout for more information
622    * about browse mode.
623    *
624    * Since: 2.12
625    */
626   result = settings_install_property_parser (class,
627                                              g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
628                                                                P_("Tooltip browse mode timeout"),
629                                                                P_("Timeout after which browse mode is disabled"),
630                                                                0, G_MAXINT,
631                                                                500,
632                                                                GTK_PARAM_READWRITE),
633                                              NULL);
634
635   g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
636
637   /**
638    * GtkSettings:gtk-keynav-cursor-only:
639    *
640    * When %TRUE, keyboard navigation should be able to reach all widgets
641    * by using the cursor keys only. Tab, Shift etc. keys can't be expected
642    * to be present on the used input device.
643    *
644    * Since: 2.12
645    */
646   result = settings_install_property_parser (class,
647                                              g_param_spec_boolean ("gtk-keynav-cursor-only",
648                                                                    P_("Keynav Cursor Only"),
649                                                                    P_("When TRUE, there are only cursor keys available to navigate widgets"),
650                                                                    FALSE,
651                                                                    GTK_PARAM_READWRITE),
652                                              NULL);
653
654   g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
655
656   /**
657    * GtkSettings:gtk-keynav-wrap-around:
658    *
659    * When %TRUE, some widgets will wrap around when doing keyboard
660    * navigation, such as menus, menubars and notebooks.
661    *
662    * Since: 2.12
663    */
664   result = settings_install_property_parser (class,
665                                              g_param_spec_boolean ("gtk-keynav-wrap-around",
666                                                                    P_("Keynav Wrap Around"),
667                                                                    P_("Whether to wrap around when keyboard-navigating widgets"),
668                                                                    TRUE,
669                                                                    GTK_PARAM_READWRITE),
670                                              NULL);
671
672   g_assert (result == PROP_KEYNAV_WRAP_AROUND);
673
674   /**
675    * GtkSettings:gtk-error-bell:
676    *
677    * When %TRUE, keyboard navigation and other input-related errors
678    * will cause a beep. Since the error bell is implemented using
679    * gdk_window_beep(), the windowing system may offer ways to
680    * configure the error bell in many ways, such as flashing the
681    * window or similar visual effects.
682    *
683    * Since: 2.12
684    */
685   result = settings_install_property_parser (class,
686                                              g_param_spec_boolean ("gtk-error-bell",
687                                                                    P_("Error Bell"),
688                                                                    P_("When TRUE, keyboard navigation and other errors will cause a beep"),
689                                                                    TRUE,
690                                                                    GTK_PARAM_READWRITE),
691                                              NULL);
692
693   g_assert (result == PROP_ERROR_BELL);
694
695   /**
696    * GtkSettings:color-hash:
697    *
698    * Holds a hash table representation of the #GtkSettings:gtk-color-scheme 
699    * setting, mapping color names to #GdkColor<!-- -->s. 
700    *
701    * Since: 2.10
702    */
703   result = settings_install_property_parser (class, 
704                                              g_param_spec_boxed ("color-hash",
705                                                                  P_("Color Hash"),
706                                                                  P_("A hash table representation of the color scheme."),
707                                                                  G_TYPE_HASH_TABLE,
708                                                                  GTK_PARAM_READABLE),
709                                              NULL);
710   g_assert (result == PROP_COLOR_HASH);
711
712   result = settings_install_property_parser (class, 
713                                              g_param_spec_string ("gtk-file-chooser-backend",
714                                                                   P_("Default file chooser backend"),
715                                                                   P_("Name of the GtkFileChooser backend to use by default"),
716                                                                   NULL,
717                                                                   GTK_PARAM_READWRITE),
718                                              NULL);
719   g_assert (result == PROP_FILE_CHOOSER_BACKEND);
720
721   /**
722    * GtkSettings:gtk-print-backends:
723    *
724    * A comma-separated list of print backends to use in the print
725    * dialog. Available print backends depend on the GTK+ installation,
726    * and may include "pdf", "cups" or "lpr".
727    *
728    * Since: 2.10
729    */
730   result = settings_install_property_parser (class,
731                                              g_param_spec_string ("gtk-print-backends",
732                                                                   P_("Default print backend"),
733                                                                   P_("List of the GtkPrintBackend backends to use by default"),
734                                                                   GTK_PRINT_BACKENDS,
735                                                                   GTK_PARAM_READWRITE),
736                                              NULL);
737   g_assert (result == PROP_PRINT_BACKENDS);
738
739   /**
740    * GtkSettings:gtk-print-preview-command:
741    *
742    * A command to run for displaying the print preview. The command
743    * should contain a %f placeholder, which will get replaced by
744    * the path to the pdf file. The command may also contain a %s
745    * placeholder, which will get replaced by the path to a file
746    * containing the print settings in the format produced by 
747    * gtk_print_settings_to_file().
748    *
749    * The preview application is responsible for removing the pdf file
750    * and the print settings file when it is done.
751    *
752    * Since: 2.10
753    */
754   result = settings_install_property_parser (class,
755                                              g_param_spec_string ("gtk-print-preview-command",
756                                                                   P_("Default command to run when displaying a print preview"),
757                                                                   P_("Command to run when displaying a print preview"),
758                                                                   GTK_PRINT_PREVIEW_COMMAND,
759                                                                   GTK_PARAM_READWRITE),
760                                              NULL); 
761   g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
762
763   /**
764    * GtkSettings:gtk-enable-mnemonics:
765    *
766    * Whether labels and menu items should have visible mnemonics which
767    * can be activated.
768    *
769    * Since: 2.12
770    */
771   result = settings_install_property_parser (class,
772                                              g_param_spec_boolean ("gtk-enable-mnemonics",
773                                                                    P_("Enable Mnemonics"),
774                                                                    P_("Whether labels should have mnemonics"),
775                                                                    TRUE,
776                                                                    GTK_PARAM_READWRITE),
777                                              NULL);
778   g_assert (result == PROP_ENABLE_MNEMONICS);
779
780   /**
781    * GtkSettings:gtk-enable-accels:
782    *
783    * Whether menu items should have visible accelerators which can be
784    * activated.
785    *
786    * Since: 2.12
787    */
788   result = settings_install_property_parser (class,
789                                              g_param_spec_boolean ("gtk-enable-accels",
790                                                                    P_("Enable Accelerators"),
791                                                                    P_("Whether menu items should have accelerators"),
792                                                                    TRUE,
793                                                                    GTK_PARAM_READWRITE),
794                                              NULL);
795   g_assert (result == PROP_ENABLE_ACCELS);
796
797   /**
798    * GtkSettings:gtk-recent-files-limit:
799    *
800    * The number of recently used files that should be displayed by default by
801    * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
802    * -1 means every recently used file stored.
803    *
804    * Since: 2.12
805    */
806   result = settings_install_property_parser (class,
807                                              g_param_spec_int ("gtk-recent-files-limit",
808                                                                P_("Recent Files Limit"),
809                                                                P_("Number of recently used files"),
810                                                                -1, G_MAXINT,
811                                                                50,
812                                                                GTK_PARAM_READWRITE),
813                                              NULL);
814   g_assert (result == PROP_RECENT_FILES_LIMIT);
815
816   /**
817    * GtkSettings:gtk-im-module:
818    *
819    * Which IM module should be used by default.
820    */
821   result = settings_install_property_parser (class,
822                                              g_param_spec_string ("gtk-im-module",
823                                                                   P_("Default IM module"),
824                                                                   P_("Which IM module should be used by default"),
825                                                                   NULL,
826                                                                   GTK_PARAM_READWRITE),
827                                              NULL);
828   g_assert (result == PROP_IM_MODULE);
829
830   /**
831    * GtkSettings:gtk-recent-files-max-age:
832    *
833    * The maximum age, in days, of the items inside the recently used
834    * resources list. Items older than this setting will be excised
835    * from the list. If set to 0, the list will always be empty; if
836    * set to -1, no item will be removed.
837    *
838    * Since: 2.14
839    */
840   result = settings_install_property_parser (class,
841                                              g_param_spec_int ("gtk-recent-files-max-age",
842                                                                P_("Recent Files Max Age"),
843                                                                P_("Maximum age of recently used files, in days"),
844                                                                -1, G_MAXINT,
845                                                                30,
846                                                                GTK_PARAM_READWRITE),
847                                              NULL);
848   g_assert (result == PROP_RECENT_FILES_MAX_AGE);
849
850   result = settings_install_property_parser (class,
851                                              g_param_spec_int ("gtk-fontconfig-timestamp",
852                                                                P_("Fontconfig configuration timestamp"),
853                                                                P_("Timestamp of current fontconfig configuration"),
854                                                                G_MININT, G_MAXINT, 0,
855                                                                GTK_PARAM_READWRITE),
856                                              NULL);
857   
858   g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
859   
860 }
861
862 static void
863 gtk_settings_finalize (GObject *object)
864 {
865   GtkSettings *settings = GTK_SETTINGS (object);
866   guint i;
867
868   object_list = g_slist_remove (object_list, settings);
869
870   _gtk_rc_context_destroy (settings);
871
872   for (i = 0; i < class_n_properties; i++)
873     g_value_unset (&settings->property_values[i].value);
874   g_free (settings->property_values);
875   
876   g_datalist_clear (&settings->queued_settings);
877
878   G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
879 }
880
881 /**
882  * gtk_settings_get_for_screen:
883  * @screen : a #GdkScreen.
884  * 
885  * Gets the #GtkSettings object for @screen, creating it if necessary.
886  *
887  * Return value: a #GtkSettings object.
888  *
889  * Since: 2.2
890  */
891 GtkSettings*
892 gtk_settings_get_for_screen (GdkScreen *screen)
893 {
894   GtkSettings *settings;
895   
896   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
897   
898   settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
899   if (!settings)
900     {
901       settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
902       settings->screen = screen;
903       g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"), 
904                               settings, g_object_unref);
905
906       gtk_rc_reparse_all_for_settings (settings, TRUE);
907       settings_update_double_click (settings);
908 #ifdef GDK_WINDOWING_X11
909       settings_update_cursor_theme (settings);
910       settings_update_resolution (settings);
911       settings_update_font_options (settings);
912 #endif
913       settings_update_color_scheme (settings);
914     }
915   
916   return settings;
917 }
918
919 /**
920  * gtk_settings_get_default:
921  * 
922  * Gets the #GtkSettings object for the default GDK screen, creating
923  * it if necessary. See gtk_settings_get_for_screen().
924  * 
925  * Return value: a #GtkSettings object. If there is no default
926  *  screen, then returns %NULL.
927  **/
928 GtkSettings*
929 gtk_settings_get_default (void)
930 {
931   GdkScreen *screen = gdk_screen_get_default ();
932
933   if (screen)
934     return gtk_settings_get_for_screen (screen);
935   else
936     return NULL;
937 }
938
939 static void
940 gtk_settings_set_property (GObject      *object,
941                            guint         property_id,
942                            const GValue *value,
943                            GParamSpec   *pspec)
944 {
945   GtkSettings *settings = GTK_SETTINGS (object);
946
947   g_value_copy (value, &settings->property_values[property_id - 1].value);
948   settings->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
949   
950   if (pspec->param_id == PROP_COLOR_SCHEME)
951     merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
952 }
953
954 static void
955 gtk_settings_get_property (GObject     *object,
956                            guint        property_id,
957                            GValue      *value,
958                            GParamSpec  *pspec)
959 {
960   GtkSettings *settings = GTK_SETTINGS (object);
961   GType value_type = G_VALUE_TYPE (value);
962   GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
963
964   /* handle internal properties */
965   switch (property_id)
966     {
967     case PROP_COLOR_HASH:
968       g_value_set_boxed (value, get_color_hash (settings));
969       return;
970     case PROP_COLOR_SCHEME:
971       g_value_take_string (value, get_color_scheme (settings));
972       return;
973     default: ;
974     }
975
976   /* For enums and strings, we need to get the value as a string,
977    * not as an int, since we support using names/nicks as the setting
978    * value.
979    */
980   if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
981        !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
982       g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
983       g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
984     {
985       if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
986           !gdk_screen_get_setting (settings->screen, pspec->name, value))
987         g_value_copy (&settings->property_values[property_id - 1].value, value);
988       else 
989         g_param_value_validate (pspec, value);
990     }
991   else
992     {
993       GValue val = { 0, };
994
995       /* Try to get xsetting as a string and parse it. */
996       
997       g_value_init (&val, G_TYPE_STRING);
998
999       if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1000           !gdk_screen_get_setting (settings->screen, pspec->name, &val))
1001         {
1002           g_value_copy (&settings->property_values[property_id - 1].value, value);
1003         }
1004       else
1005         {
1006           GValue tmp_value = { 0, };
1007           GValue gstring_value = { 0, };
1008           GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1009           
1010           g_value_init (&gstring_value, G_TYPE_GSTRING);
1011           g_value_take_boxed (&gstring_value,
1012                               g_string_new (g_value_get_string (&val)));
1013
1014           g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1015
1016           if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1017                                                      pspec, &tmp_value))
1018             {
1019               g_value_copy (&tmp_value, value);
1020               g_param_value_validate (pspec, value);
1021             }
1022           else
1023             {
1024               g_value_copy (&settings->property_values[property_id - 1].value, value);
1025             }
1026
1027           g_value_unset (&gstring_value);
1028           g_value_unset (&tmp_value);
1029         }
1030
1031       g_value_unset (&val);
1032     }
1033 }
1034
1035 static void
1036 gtk_settings_notify (GObject    *object,
1037                      GParamSpec *pspec)
1038 {
1039   GtkSettings *settings = GTK_SETTINGS (object);
1040   guint property_id = pspec->param_id;
1041
1042   if (settings->screen == NULL) /* initialization */
1043     return;
1044
1045   switch (property_id)
1046     {
1047     case PROP_MODULES:
1048       settings_update_modules (settings);
1049       break;
1050     case PROP_DOUBLE_CLICK_TIME:
1051     case PROP_DOUBLE_CLICK_DISTANCE:
1052       settings_update_double_click (settings);
1053       break;
1054     case PROP_COLOR_SCHEME:
1055       settings_update_color_scheme (settings);
1056       break;
1057 #ifdef GDK_WINDOWING_X11
1058     case PROP_XFT_DPI:
1059       settings_update_resolution (settings);
1060       /* This is a hack because with gtk_rc_reset_styles() doesn't get
1061        * widgets with gtk_widget_style_set(), and also causes more
1062        * recomputation than necessary.
1063        */
1064       gtk_rc_reset_styles (GTK_SETTINGS (object));
1065       break;
1066     case PROP_XFT_ANTIALIAS:
1067     case PROP_XFT_HINTING:
1068     case PROP_XFT_HINTSTYLE:
1069     case PROP_XFT_RGBA:
1070       settings_update_font_options (settings);
1071       gtk_rc_reset_styles (GTK_SETTINGS (object));
1072       break;
1073     case PROP_FONTCONFIG_TIMESTAMP:
1074       if (settings_update_fontconfig (settings))
1075         gtk_rc_reset_styles (GTK_SETTINGS (object));
1076       break;
1077     case PROP_CURSOR_THEME_NAME:
1078     case PROP_CURSOR_THEME_SIZE:
1079       settings_update_cursor_theme (settings);
1080       break;
1081 #endif /* GDK_WINDOWING_X11 */
1082     }
1083 }
1084
1085 gboolean
1086 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1087                              const GValue       *src_value,
1088                              GParamSpec         *pspec,
1089                              GValue             *dest_value)
1090 {
1091   gboolean success = FALSE;
1092
1093   g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1094
1095   if (parser)
1096     {
1097       GString *gstring;
1098       gboolean free_gstring = TRUE;
1099       
1100       if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1101         {
1102           gstring = g_value_get_boxed (src_value);
1103           free_gstring = FALSE;
1104         }
1105       else if (G_VALUE_HOLDS_LONG (src_value))
1106         {
1107           gstring = g_string_new (NULL);
1108           g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1109         }
1110       else if (G_VALUE_HOLDS_DOUBLE (src_value))
1111         {
1112           gstring = g_string_new (NULL);
1113           g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1114         }
1115       else if (G_VALUE_HOLDS_STRING (src_value))
1116         {
1117           gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1118           
1119           gstring = g_string_new ("\"");
1120           g_string_append (gstring, tstr);
1121           g_string_append_c (gstring, '\"');
1122           g_free (tstr);
1123         }
1124       else
1125         {
1126           g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1127           gstring = NULL; /* silence compiler */
1128         }
1129
1130       success = (parser (pspec, gstring, dest_value) &&
1131                  !g_param_value_validate (pspec, dest_value));
1132
1133       if (free_gstring)
1134         g_string_free (gstring, TRUE);
1135     }
1136   else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1137     {
1138       if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1139         {
1140           GString *gstring = g_value_get_boxed (src_value);
1141
1142           g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1143           success = !g_param_value_validate (pspec, dest_value);
1144         }
1145     }
1146   else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1147     success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1148
1149   return success;
1150 }
1151
1152 static void
1153 apply_queued_setting (GtkSettings             *data,
1154                       GParamSpec              *pspec,
1155                       GtkSettingsValuePrivate *qvalue)
1156 {
1157   GValue tmp_value = { 0, };
1158   GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1159
1160   g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1161   if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1162                                    pspec, &tmp_value))
1163     {
1164       if (pspec->param_id == PROP_COLOR_SCHEME) 
1165         merge_color_scheme (data, &tmp_value, qvalue->source);
1166
1167       if (data->property_values[pspec->param_id - 1].source <= qvalue->source)
1168         {
1169           g_value_copy (&tmp_value, &data->property_values[pspec->param_id - 1].value);
1170           data->property_values[pspec->param_id - 1].source = qvalue->source;
1171           g_object_notify (G_OBJECT (data), g_param_spec_get_name (pspec));
1172         }
1173
1174     }
1175   else
1176     {
1177       gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1178       
1179       g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1180                  qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1181                  pspec->name,
1182                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1183                  debug,
1184                  G_VALUE_TYPE_NAME (&tmp_value));
1185       g_free (debug);
1186     }
1187   g_value_unset (&tmp_value);
1188 }
1189
1190 static guint
1191 settings_install_property_parser (GtkSettingsClass   *class,
1192                                   GParamSpec         *pspec,
1193                                   GtkRcPropertyParser parser)
1194 {
1195   GSList *node, *next;
1196
1197   switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1198     {
1199     case G_TYPE_BOOLEAN:
1200     case G_TYPE_UCHAR:
1201     case G_TYPE_CHAR:
1202     case G_TYPE_UINT:
1203     case G_TYPE_INT:
1204     case G_TYPE_ULONG:
1205     case G_TYPE_LONG:
1206     case G_TYPE_FLOAT:
1207     case G_TYPE_DOUBLE:
1208     case G_TYPE_STRING:
1209       break;
1210     case G_TYPE_BOXED:
1211       if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1212         {
1213           break;
1214         }
1215       /* fall through */
1216     default:
1217       if (!parser)
1218         {
1219           g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1220                      pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1221           return 0;
1222         }
1223     }
1224   if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1225     {
1226       g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1227                  pspec->name);
1228       return 0;
1229     }
1230   
1231   for (node = object_list; node; node = node->next)
1232     g_object_freeze_notify (node->data);
1233
1234   g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1235   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1236
1237   for (node = object_list; node; node = node->next)
1238     {
1239       GtkSettings *settings = node->data;
1240       GtkSettingsValuePrivate *qvalue;
1241       
1242       settings->property_values = g_renew (GtkSettingsPropertyValue, settings->property_values, class_n_properties);
1243       settings->property_values[class_n_properties - 1].value.g_type = 0;
1244       g_value_init (&settings->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1245       g_param_value_set_default (pspec, &settings->property_values[class_n_properties - 1].value);
1246       settings->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1247       g_object_notify (G_OBJECT (settings), pspec->name);
1248       
1249       qvalue = g_datalist_get_data (&settings->queued_settings, pspec->name);
1250       if (qvalue)
1251         apply_queued_setting (settings, pspec, qvalue);
1252     }
1253
1254   for (node = object_list; node; node = next)
1255     {
1256       next = node->next;
1257       g_object_thaw_notify (node->data);
1258     }
1259
1260   return class_n_properties;
1261 }
1262
1263 GtkRcPropertyParser
1264 _gtk_rc_property_parser_from_type (GType type)
1265 {
1266   if (type == GDK_TYPE_COLOR)
1267     return gtk_rc_property_parse_color;
1268   else if (type == GTK_TYPE_REQUISITION)
1269     return gtk_rc_property_parse_requisition;
1270   else if (type == GTK_TYPE_BORDER)
1271     return gtk_rc_property_parse_border;
1272   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1273     return gtk_rc_property_parse_enum;
1274   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1275     return gtk_rc_property_parse_flags;
1276   else
1277     return NULL;
1278 }
1279
1280 void
1281 gtk_settings_install_property (GParamSpec *pspec)
1282 {
1283   GtkRcPropertyParser parser;
1284
1285   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1286
1287   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1288
1289   settings_install_property_parser (gtk_type_class (GTK_TYPE_SETTINGS), pspec, parser);
1290 }
1291
1292 void
1293 gtk_settings_install_property_parser (GParamSpec          *pspec,
1294                                       GtkRcPropertyParser  parser)
1295 {
1296   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1297   g_return_if_fail (parser != NULL);
1298   
1299   settings_install_property_parser (gtk_type_class (GTK_TYPE_SETTINGS), pspec, parser);
1300 }
1301
1302 static void
1303 free_value (gpointer data)
1304 {
1305   GtkSettingsValuePrivate *qvalue = data;
1306   
1307   g_value_unset (&qvalue->public.value);
1308   g_free (qvalue->public.origin);
1309   g_slice_free (GtkSettingsValuePrivate, qvalue);
1310 }
1311
1312 static void
1313 gtk_settings_set_property_value_internal (GtkSettings            *settings,
1314                                           const gchar            *prop_name,
1315                                           const GtkSettingsValue *new_value,
1316                                           GtkSettingsSource       source)
1317 {
1318   GtkSettingsValuePrivate *qvalue;
1319   GParamSpec *pspec;
1320   gchar *name;
1321   GQuark name_quark;
1322
1323   if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1324       !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1325       !G_VALUE_HOLDS_STRING (&new_value->value) &&
1326       !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1327     {
1328       g_warning (G_STRLOC ": value type invalid");
1329       return;
1330     }
1331   
1332   name = g_strdup (prop_name);
1333   g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1334   name_quark = g_quark_from_string (name);
1335   g_free (name);
1336
1337   qvalue = g_datalist_id_get_data (&settings->queued_settings, name_quark);
1338   if (!qvalue)
1339     {
1340       qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1341       g_datalist_id_set_data_full (&settings->queued_settings, name_quark, qvalue, free_value);
1342     }
1343   else
1344     {
1345       g_free (qvalue->public.origin);
1346       g_value_unset (&qvalue->public.value);
1347     }
1348   qvalue->public.origin = g_strdup (new_value->origin);
1349   g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1350   g_value_copy (&new_value->value, &qvalue->public.value);
1351   qvalue->source = source;
1352   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1353   if (pspec)
1354     apply_queued_setting (settings, pspec, qvalue);
1355 }
1356
1357 void
1358 gtk_settings_set_property_value (GtkSettings            *settings,
1359                                  const gchar            *prop_name,
1360                                  const GtkSettingsValue *new_value)
1361 {
1362   g_return_if_fail (GTK_SETTINGS (settings));
1363   g_return_if_fail (prop_name != NULL);
1364   g_return_if_fail (new_value != NULL);
1365
1366   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1367                                             GTK_SETTINGS_SOURCE_APPLICATION);
1368 }
1369
1370 void
1371 _gtk_settings_set_property_value_from_rc (GtkSettings            *settings,
1372                                           const gchar            *prop_name,
1373                                           const GtkSettingsValue *new_value)
1374 {
1375   g_return_if_fail (GTK_SETTINGS (settings));
1376   g_return_if_fail (prop_name != NULL);
1377   g_return_if_fail (new_value != NULL);
1378
1379   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1380                                             GTK_SETTINGS_SOURCE_RC_FILE);
1381 }
1382
1383 void
1384 gtk_settings_set_string_property (GtkSettings *settings,
1385                                   const gchar *name,
1386                                   const gchar *v_string,
1387                                   const gchar *origin)
1388 {
1389   GtkSettingsValue svalue = { NULL, { 0, }, };
1390
1391   g_return_if_fail (GTK_SETTINGS (settings));
1392   g_return_if_fail (name != NULL);
1393   g_return_if_fail (v_string != NULL);
1394
1395   svalue.origin = (gchar*) origin;
1396   g_value_init (&svalue.value, G_TYPE_STRING);
1397   g_value_set_static_string (&svalue.value, v_string);
1398   gtk_settings_set_property_value (settings, name, &svalue);
1399   g_value_unset (&svalue.value);
1400 }
1401
1402 void
1403 gtk_settings_set_long_property (GtkSettings *settings,
1404                                 const gchar *name,
1405                                 glong        v_long,
1406                                 const gchar *origin)
1407 {
1408   GtkSettingsValue svalue = { NULL, { 0, }, };
1409   
1410   g_return_if_fail (GTK_SETTINGS (settings));
1411   g_return_if_fail (name != NULL);
1412
1413   svalue.origin = (gchar*) origin;
1414   g_value_init (&svalue.value, G_TYPE_LONG);
1415   g_value_set_long (&svalue.value, v_long);
1416   gtk_settings_set_property_value (settings, name, &svalue);
1417   g_value_unset (&svalue.value);
1418 }
1419
1420 void
1421 gtk_settings_set_double_property (GtkSettings *settings,
1422                                   const gchar *name,
1423                                   gdouble      v_double,
1424                                   const gchar *origin)
1425 {
1426   GtkSettingsValue svalue = { NULL, { 0, }, };
1427
1428   g_return_if_fail (GTK_SETTINGS (settings));
1429   g_return_if_fail (name != NULL);
1430
1431   svalue.origin = (gchar*) origin;
1432   g_value_init (&svalue.value, G_TYPE_DOUBLE);
1433   g_value_set_double (&svalue.value, v_double);
1434   gtk_settings_set_property_value (settings, name, &svalue);
1435   g_value_unset (&svalue.value);
1436 }
1437
1438 /**
1439  * gtk_rc_property_parse_color:
1440  * @pspec: a #GParamSpec
1441  * @gstring: the #GString to be parsed
1442  * @property_value: a #GValue which must hold #GdkColor values.
1443  * 
1444  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1445  * or gtk_widget_class_install_style_property_parser() which parses a
1446  * color given either by its name or in the form 
1447  * <literal>{ red, green, blue }</literal> where %red, %green and
1448  * %blue are integers between 0 and 65535 or floating-point numbers
1449  * between 0 and 1.
1450  * 
1451  * Return value: %TRUE if @gstring could be parsed and @property_value
1452  * has been set to the resulting #GdkColor.
1453  **/
1454 gboolean
1455 gtk_rc_property_parse_color (const GParamSpec *pspec,
1456                              const GString    *gstring,
1457                              GValue           *property_value)
1458 {
1459   GdkColor color = { 0, 0, 0, 0, };
1460   GScanner *scanner;
1461   gboolean success;
1462
1463   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1464   g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
1465
1466   scanner = gtk_rc_scanner_new ();
1467   g_scanner_input_text (scanner, gstring->str, gstring->len);
1468   if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
1469       g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
1470     {
1471       g_value_set_boxed (property_value, &color);
1472       success = TRUE;
1473     }
1474   else
1475     success = FALSE;
1476   g_scanner_destroy (scanner);
1477
1478   return success;
1479 }
1480
1481 /**
1482  * gtk_rc_property_parse_enum:
1483  * @pspec: a #GParamSpec
1484  * @gstring: the #GString to be parsed
1485  * @property_value: a #GValue which must hold enum values.
1486  * 
1487  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1488  * or gtk_widget_class_install_style_property_parser() which parses a single
1489  * enumeration value.
1490  *
1491  * The enumeration value can be specified by its name, its nickname or
1492  * its numeric value. For consistency with flags parsing, the value
1493  * may be surrounded by parentheses.
1494  * 
1495  * Return value: %TRUE if @gstring could be parsed and @property_value
1496  * has been set to the resulting #GEnumValue.
1497  **/
1498 gboolean
1499 gtk_rc_property_parse_enum (const GParamSpec *pspec,
1500                             const GString    *gstring,
1501                             GValue           *property_value)
1502 {
1503   gboolean need_closing_brace = FALSE, success = FALSE;
1504   GScanner *scanner;
1505   GEnumValue *enum_value = NULL;
1506
1507   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1508   g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
1509
1510   scanner = gtk_rc_scanner_new ();
1511   g_scanner_input_text (scanner, gstring->str, gstring->len);
1512
1513   /* we just want to parse _one_ value, but for consistency with flags parsing
1514    * we support optional parenthesis
1515    */
1516   g_scanner_get_next_token (scanner);
1517   if (scanner->token == '(')
1518     {
1519       need_closing_brace = TRUE;
1520       g_scanner_get_next_token (scanner);
1521     }
1522   if (scanner->token == G_TOKEN_IDENTIFIER)
1523     {
1524       GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
1525       
1526       enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
1527       if (!enum_value)
1528         enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
1529       if (enum_value)
1530         {
1531           g_value_set_enum (property_value, enum_value->value);
1532           success = TRUE;
1533         }
1534     }
1535   else if (scanner->token == G_TOKEN_INT)
1536     {
1537       g_value_set_enum (property_value, scanner->value.v_int);
1538       success = TRUE;
1539     }
1540   if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
1541     success = FALSE;
1542   if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
1543     success = FALSE;
1544
1545   g_scanner_destroy (scanner);
1546
1547   return success;
1548 }
1549
1550 static guint
1551 parse_flags_value (GScanner    *scanner,
1552                    GFlagsClass *class,
1553                    guint       *number)
1554 {
1555   g_scanner_get_next_token (scanner);
1556   if (scanner->token == G_TOKEN_IDENTIFIER)
1557     {
1558       GFlagsValue *flags_value;
1559
1560       flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
1561       if (!flags_value)
1562         flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
1563       if (flags_value)
1564         {
1565           *number |= flags_value->value;
1566           return G_TOKEN_NONE;
1567         }
1568     }
1569   else if (scanner->token == G_TOKEN_INT)
1570     {
1571       *number |= scanner->value.v_int;
1572       return G_TOKEN_NONE;
1573     }
1574   return G_TOKEN_IDENTIFIER;
1575 }
1576
1577 /**
1578  * gtk_rc_property_parse_flags:
1579  * @pspec: a #GParamSpec
1580  * @gstring: the #GString to be parsed
1581  * @property_value: a #GValue which must hold flags values.
1582  * 
1583  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1584  * or gtk_widget_class_install_style_property_parser() which parses flags. 
1585  * 
1586  * Flags can be specified by their name, their nickname or
1587  * numerically. Multiple flags can be specified in the form 
1588  * <literal>"( flag1 | flag2 | ... )"</literal>.
1589  * 
1590  * Return value: %TRUE if @gstring could be parsed and @property_value
1591  * has been set to the resulting flags value.
1592  **/
1593 gboolean
1594 gtk_rc_property_parse_flags (const GParamSpec *pspec,
1595                              const GString    *gstring,
1596                              GValue           *property_value)
1597 {
1598   GFlagsClass *class;
1599    gboolean success = FALSE;
1600   GScanner *scanner;
1601
1602   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1603   g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
1604
1605   class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
1606   scanner = gtk_rc_scanner_new ();
1607   g_scanner_input_text (scanner, gstring->str, gstring->len);
1608
1609   /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
1610   if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
1611       scanner->next_token == G_TOKEN_INT)
1612     {
1613       guint token, flags_value = 0;
1614       
1615       token = parse_flags_value (scanner, class, &flags_value);
1616
1617       if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1618         {
1619           success = TRUE;
1620           g_value_set_flags (property_value, flags_value);
1621         }
1622       
1623     }
1624   else if (g_scanner_get_next_token (scanner) == '(')
1625     {
1626       guint token, flags_value = 0;
1627
1628       /* parse first value */
1629       token = parse_flags_value (scanner, class, &flags_value);
1630
1631       /* parse nth values, preceeded by '|' */
1632       while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
1633         token = parse_flags_value (scanner, class, &flags_value);
1634
1635       /* done, last token must have closed expression */
1636       if (token == G_TOKEN_NONE && scanner->token == ')' &&
1637           g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1638         {
1639           g_value_set_flags (property_value, flags_value);
1640           success = TRUE;
1641         }
1642     }
1643   g_scanner_destroy (scanner);
1644
1645   return success;
1646 }
1647
1648 static gboolean
1649 get_braced_int (GScanner *scanner,
1650                 gboolean  first,
1651                 gboolean  last,
1652                 gint     *value)
1653 {
1654   if (first)
1655     {
1656       g_scanner_get_next_token (scanner);
1657       if (scanner->token != '{')
1658         return FALSE;
1659     }
1660
1661   g_scanner_get_next_token (scanner);
1662   if (scanner->token != G_TOKEN_INT)
1663     return FALSE;
1664
1665   *value = scanner->value.v_int;
1666
1667   if (last)
1668     {
1669       g_scanner_get_next_token (scanner);
1670       if (scanner->token != '}')
1671         return FALSE;
1672     }
1673   else
1674     {
1675       g_scanner_get_next_token (scanner);
1676       if (scanner->token != ',')
1677         return FALSE;
1678     }
1679
1680   return TRUE;
1681 }
1682
1683 /**
1684  * gtk_rc_property_parse_requisition:
1685  * @pspec: a #GParamSpec
1686  * @gstring: the #GString to be parsed
1687  * @property_value: a #GValue which must hold boxed values.
1688  * 
1689  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1690  * or gtk_widget_class_install_style_property_parser() which parses a
1691  * requisition in the form 
1692  * <literal>"{ width, height }"</literal> for integers %width and %height.
1693  * 
1694  * Return value: %TRUE if @gstring could be parsed and @property_value
1695  * has been set to the resulting #GtkRequisition.
1696  **/
1697 gboolean
1698 gtk_rc_property_parse_requisition  (const GParamSpec *pspec,
1699                                     const GString    *gstring,
1700                                     GValue           *property_value)
1701 {
1702   GtkRequisition requisition;
1703   GScanner *scanner;
1704   gboolean success = FALSE;
1705
1706   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1707   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1708
1709   scanner = gtk_rc_scanner_new ();
1710   g_scanner_input_text (scanner, gstring->str, gstring->len);
1711
1712   if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
1713       get_braced_int (scanner, FALSE, TRUE, &requisition.height))
1714     {
1715       g_value_set_boxed (property_value, &requisition);
1716       success = TRUE;
1717     }
1718
1719   g_scanner_destroy (scanner);
1720
1721   return success;
1722 }
1723
1724 /**
1725  * gtk_rc_property_parse_border:
1726  * @pspec: a #GParamSpec
1727  * @gstring: the #GString to be parsed
1728  * @property_value: a #GValue which must hold boxed values.
1729  * 
1730  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1731  * or gtk_widget_class_install_style_property_parser() which parses
1732  * borders in the form 
1733  * <literal>"{ left, right, top, bottom }"</literal> for integers 
1734  * %left, %right, %top and %bottom.
1735  * 
1736  * Return value: %TRUE if @gstring could be parsed and @property_value
1737  * has been set to the resulting #GtkBorder.
1738  **/
1739 gboolean
1740 gtk_rc_property_parse_border (const GParamSpec *pspec,
1741                               const GString    *gstring,
1742                               GValue           *property_value)
1743 {
1744   GtkBorder border;
1745   GScanner *scanner;
1746   gboolean success = FALSE;
1747
1748   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1749   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1750
1751   scanner = gtk_rc_scanner_new ();
1752   g_scanner_input_text (scanner, gstring->str, gstring->len);
1753
1754   if (get_braced_int (scanner, TRUE, FALSE, &border.left) &&
1755       get_braced_int (scanner, FALSE, FALSE, &border.right) &&
1756       get_braced_int (scanner, FALSE, FALSE, &border.top) &&
1757       get_braced_int (scanner, FALSE, TRUE, &border.bottom))
1758     {
1759       g_value_set_boxed (property_value, &border);
1760       success = TRUE;
1761     }
1762
1763   g_scanner_destroy (scanner);
1764
1765   return success;
1766 }
1767
1768 void
1769 _gtk_settings_handle_event (GdkEventSetting *event)
1770 {
1771   GtkSettings *settings;
1772   GParamSpec *pspec;
1773   guint property_id;
1774
1775   settings = gtk_settings_get_for_screen (gdk_drawable_get_screen (event->window));
1776   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
1777  
1778   if (pspec) 
1779     {
1780       property_id = pspec->param_id;
1781
1782       if (property_id == PROP_COLOR_SCHEME)
1783         {
1784           GValue value = { 0, };
1785
1786           g_value_init (&value, G_TYPE_STRING);
1787           if (!gdk_screen_get_setting (settings->screen, pspec->name, &value))
1788             g_value_set_static_string (&value, "");
1789           merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
1790           g_value_unset (&value);
1791         }
1792
1793       g_object_notify (G_OBJECT (settings), pspec->name);
1794    }
1795 }
1796
1797 static void
1798 reset_rc_values_foreach (GQuark    key_id,
1799                          gpointer  data,
1800                          gpointer  user_data)
1801 {
1802   GtkSettingsValuePrivate *qvalue = data;
1803   GSList **to_reset = user_data;
1804
1805   if (qvalue->source == GTK_SETTINGS_SOURCE_RC_FILE)
1806     *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
1807 }
1808
1809 void
1810 _gtk_settings_reset_rc_values (GtkSettings *settings)
1811 {
1812   GSList *to_reset = NULL;
1813   GSList *tmp_list;
1814   GParamSpec **pspecs, **p;
1815   gint i;
1816
1817   /* Remove any queued settings
1818    */
1819   g_datalist_foreach (&settings->queued_settings,
1820                       reset_rc_values_foreach,
1821                       &to_reset);
1822
1823   for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
1824     {
1825       GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
1826       g_datalist_id_remove_data (&settings->queued_settings, key_id);
1827     }
1828
1829    g_slist_free (to_reset);
1830
1831   /* Now reset the active settings
1832    */
1833   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
1834   i = 0;
1835
1836   g_object_freeze_notify (G_OBJECT (settings));
1837   for (p = pspecs; *p; p++)
1838     {
1839       if (settings->property_values[i].source == GTK_SETTINGS_SOURCE_RC_FILE)
1840         {
1841           GParamSpec *pspec = *p;
1842
1843           g_param_value_set_default (pspec, &settings->property_values[i].value);
1844           g_object_notify (G_OBJECT (settings), pspec->name);
1845         }
1846       i++;
1847     }
1848   g_object_thaw_notify (G_OBJECT (settings));
1849   g_free (pspecs);
1850 }
1851
1852 static void
1853 settings_update_double_click (GtkSettings *settings)
1854 {
1855   if (gdk_screen_get_number (settings->screen) == 0)
1856     {
1857       GdkDisplay *display = gdk_screen_get_display (settings->screen);
1858       gint double_click_time;
1859       gint double_click_distance;
1860   
1861       g_object_get (settings, 
1862                     "gtk-double-click-time", &double_click_time, 
1863                     "gtk-double-click-distance", &double_click_distance,
1864                     NULL);
1865       
1866       gdk_display_set_double_click_time (display, double_click_time);
1867       gdk_display_set_double_click_distance (display, double_click_distance);
1868     }
1869 }
1870
1871 static void
1872 settings_update_modules (GtkSettings *settings)
1873 {
1874   gchar *modules;
1875   
1876   g_object_get (settings, 
1877                 "gtk-modules", &modules,
1878                 NULL);
1879   
1880   _gtk_modules_settings_changed (settings, modules);
1881   
1882   g_free (modules);
1883 }
1884
1885 #ifdef GDK_WINDOWING_X11
1886 static void
1887 settings_update_cursor_theme (GtkSettings *settings)
1888 {
1889   GdkDisplay *display = gdk_screen_get_display (settings->screen);
1890   gchar *theme = NULL;
1891   gint size = 0;
1892   
1893   g_object_get (settings, 
1894                 "gtk-cursor-theme-name", &theme,
1895                 "gtk-cursor-theme-size", &size,
1896                 NULL);
1897   
1898   gdk_x11_display_set_cursor_theme (display, theme, size);
1899
1900   g_free (theme);
1901 }
1902
1903 static void
1904 settings_update_font_options (GtkSettings *settings)
1905 {
1906   gint hinting;
1907   gchar *hint_style_str;
1908   cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_DEFAULT;
1909   gint antialias;
1910   cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_DEFAULT;
1911   gchar *rgba_str;
1912   cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
1913   cairo_font_options_t *options;
1914   
1915   g_object_get (settings,
1916                 "gtk-xft-antialias", &antialias,
1917                 "gtk-xft-hinting", &hinting,
1918                 "gtk-xft-hintstyle", &hint_style_str,
1919                 "gtk-xft-rgba", &rgba_str,
1920                 NULL);
1921
1922   options = cairo_font_options_create ();
1923   
1924   if (hinting >= 0 && !hinting)
1925     {
1926       hint_style = CAIRO_HINT_STYLE_NONE;
1927     }
1928   else if (hint_style_str)
1929     {
1930       if (strcmp (hint_style_str, "hintnone") == 0)
1931         hint_style = CAIRO_HINT_STYLE_NONE;
1932       else if (strcmp (hint_style_str, "hintslight") == 0)
1933         hint_style = CAIRO_HINT_STYLE_SLIGHT;
1934       else if (strcmp (hint_style_str, "hintmedium") == 0)
1935         hint_style = CAIRO_HINT_STYLE_MEDIUM;
1936       else if (strcmp (hint_style_str, "hintfull") == 0)
1937         hint_style = CAIRO_HINT_STYLE_FULL;
1938     }
1939
1940   g_free (hint_style_str);
1941
1942   cairo_font_options_set_hint_style (options, hint_style);
1943
1944   if (rgba_str)
1945     {
1946       if (strcmp (rgba_str, "rgb") == 0)
1947         subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
1948       else if (strcmp (rgba_str, "bgr") == 0)
1949         subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
1950       else if (strcmp (rgba_str, "vrgb") == 0)
1951         subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
1952       else if (strcmp (rgba_str, "vbgr") == 0)
1953         subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
1954
1955       g_free (rgba_str);
1956     }
1957
1958   cairo_font_options_set_subpixel_order (options, subpixel_order);
1959   
1960   if (antialias >= 0 && !antialias)
1961     antialias_mode = CAIRO_ANTIALIAS_NONE;
1962   else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
1963     antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
1964   else if (antialias >= 0)
1965     antialias_mode = CAIRO_ANTIALIAS_GRAY;
1966   
1967   cairo_font_options_set_antialias (options, antialias_mode);
1968
1969   gdk_screen_set_font_options (settings->screen, options);
1970   
1971   cairo_font_options_destroy (options);
1972 }
1973
1974 #ifdef GDK_WINDOWING_X11
1975 static gboolean
1976 settings_update_fontconfig (GtkSettings *settings)
1977 {
1978   static guint    last_update_timestamp;
1979   static gboolean last_update_needed;
1980
1981   gint timestamp;
1982
1983   g_object_get (settings,
1984                 "gtk-fontconfig-timestamp", &timestamp,
1985                 NULL);
1986
1987   /* if timestamp is the same as last_update_timestamp, we already have
1988    * updated fontconig on this timestamp (another screen requested it perhaps?),
1989    * just return the cached result.*/
1990
1991   if (timestamp != last_update_timestamp)
1992     {
1993       PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
1994       gboolean update_needed = FALSE;
1995
1996       if (PANGO_IS_FC_FONT_MAP (fontmap) &&
1997           !FcConfigUptoDate (NULL) && FcInitReinitialize ())
1998         {
1999           update_needed = TRUE;
2000           pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2001         }
2002
2003       last_update_timestamp = timestamp;
2004       last_update_needed = update_needed;
2005     }
2006
2007   return last_update_needed;
2008 }
2009 #endif /* GDK_WINDOWING_X11 */
2010
2011 static void
2012 settings_update_resolution (GtkSettings *settings)
2013 {
2014   gint dpi_int;
2015   double dpi;
2016   
2017   g_object_get (settings,
2018                 "gtk-xft-dpi", &dpi_int,
2019                 NULL);
2020
2021   if (dpi_int > 0)
2022     dpi = dpi_int / 1024.;
2023   else
2024     dpi = -1.;
2025
2026   gdk_screen_set_resolution (settings->screen, dpi);
2027 }
2028 #endif
2029
2030 typedef struct {
2031   GHashTable *color_hash;
2032   GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2033   gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2034 } ColorSchemeData;
2035
2036 static void
2037 color_scheme_data_free (ColorSchemeData *data)
2038 {
2039   gint i;
2040
2041   g_hash_table_unref (data->color_hash);
2042
2043   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2044     {
2045       if (data->tables[i])
2046         g_hash_table_unref (data->tables[i]);
2047       g_free (data->lastentry[i]);
2048     }
2049
2050   g_slice_free (ColorSchemeData, data);
2051 }
2052
2053 static void
2054 settings_update_color_scheme (GtkSettings *settings)
2055 {
2056   if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2057     {
2058       ColorSchemeData *data;
2059       GValue value = { 0, };
2060
2061       data = g_slice_new0 (ColorSchemeData);
2062       data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2063                                                 (GDestroyNotify) gdk_color_free);
2064       g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2065                               data, (GDestroyNotify) color_scheme_data_free); 
2066
2067       g_value_init (&value, G_TYPE_STRING);
2068       if (gdk_screen_get_setting (settings->screen, "gtk-color-scheme", &value))
2069         {
2070           merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2071           g_value_unset (&value);
2072         }
2073    }
2074 }
2075
2076 static gboolean
2077 add_color_to_hash (gchar      *name, 
2078                    GdkColor   *color, 
2079                    GHashTable *target)
2080 {
2081   GdkColor *old;
2082
2083   old = g_hash_table_lookup (target, name);
2084   if (!old || !gdk_color_equal (old, color))
2085     {
2086       g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2087       
2088       return TRUE;
2089     }
2090
2091   return FALSE;
2092 }
2093
2094 static gboolean
2095 add_colors_to_hash_from_string (GHashTable  *hash, 
2096                                 const gchar *colors)
2097 {
2098   gchar *s, *p, *name;
2099   GdkColor color;
2100   gboolean changed = FALSE;
2101   gchar *copy;
2102
2103   copy = g_strdup (colors);
2104   s = copy;
2105   while (s && *s)
2106     {
2107       name = s;
2108       p = strchr (s, ':');
2109       if (p)
2110         {
2111           *p = '\0';
2112           p++;
2113         }
2114       else
2115         break;
2116
2117       while (*p == ' ')
2118         p++;
2119
2120       s = p;
2121       while (*s) 
2122         {
2123           if (*s == '\n' || *s == ';')
2124             {
2125               *s = '\0';
2126               s++;
2127               break;
2128             }
2129           s++;
2130         }
2131
2132       if (gdk_color_parse (p, &color))
2133         changed |= add_color_to_hash (name, &color, hash);
2134     }
2135
2136   g_free (copy);
2137
2138   return changed;
2139 }
2140
2141 static gboolean
2142 update_color_hash (ColorSchemeData   *data,
2143                    const gchar       *str, 
2144                    GtkSettingsSource  source)
2145 {
2146   gboolean changed = FALSE;
2147   gint i;
2148
2149   if ((str == NULL || *str == '\0') && 
2150       (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2151     return FALSE;
2152
2153   if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2154     return FALSE;
2155
2156   /* For the RC_FILE source we merge the values rather than over-writing 
2157    * them, since multiple rc files might define independent sets of colors
2158    */
2159   if ((source != GTK_SETTINGS_SOURCE_RC_FILE) && 
2160       data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2161     {
2162       g_hash_table_unref (data->tables[source]);
2163       data->tables[source] = NULL;
2164       changed = TRUE; /* We can't rely on the code below since str might be "" */
2165     }
2166
2167   if (data->tables[source] == NULL)
2168     data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal, 
2169                                                   g_free,
2170                                                   (GDestroyNotify) gdk_color_free);
2171
2172   g_free (data->lastentry[source]);
2173   data->lastentry[source] = g_strdup (str);
2174   
2175   changed |= add_colors_to_hash_from_string (data->tables[source], str);
2176
2177   if (!changed)
2178     return FALSE;
2179     
2180   /* Rebuild the merged hash table. */
2181   if (data->color_hash)
2182     g_hash_table_unref (data->color_hash);
2183   data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2184                                             (GDestroyNotify) gdk_color_free);
2185   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2186     {
2187       if (data->tables[i])
2188         g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2189                               data->color_hash);
2190     }
2191
2192   return TRUE;
2193 }
2194
2195 static void
2196 merge_color_scheme (GtkSettings       *settings, 
2197                     const GValue      *value, 
2198                     GtkSettingsSource  source)
2199 {
2200   ColorSchemeData *data;
2201   const gchar *colors;
2202
2203   g_object_freeze_notify (G_OBJECT (settings));
2204
2205   colors = g_value_get_string (value);
2206
2207   settings_update_color_scheme (settings);
2208
2209   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2210                                                 "gtk-color-scheme");
2211   
2212   if (update_color_hash (data, colors, source))
2213     g_object_notify (G_OBJECT (settings), "color-hash");
2214
2215   g_object_thaw_notify (G_OBJECT (settings));
2216 }
2217
2218 static GHashTable *
2219 get_color_hash (GtkSettings *settings)
2220 {
2221   ColorSchemeData *data;
2222
2223   settings_update_color_scheme (settings);
2224   
2225   data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings), 
2226                                                "gtk-color-scheme");
2227
2228   return data->color_hash;
2229 }
2230
2231 static void 
2232 append_color_scheme (gpointer key,
2233                      gpointer value,
2234                      gpointer data)
2235 {
2236   gchar *name = (gchar *)key;
2237   GdkColor *color = (GdkColor *)value;
2238   GString *string = (GString *)data;
2239
2240   g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2241                           name, color->red, color->green, color->blue);
2242 }
2243
2244 static gchar *
2245 get_color_scheme (GtkSettings *settings)
2246 {
2247   ColorSchemeData *data;
2248   GString *string;
2249   
2250   settings_update_color_scheme (settings);
2251
2252   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2253                                                 "gtk-color-scheme");
2254
2255   string = g_string_new ("");
2256
2257   g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2258
2259   return g_string_free (string, FALSE);
2260 }
2261
2262
2263 #define __GTK_SETTINGS_C__
2264 #include "gtkaliasdef.c"