]> Pileus Git - ~andy/gtk/blob - gtk/gtksettings.c
Remove dead Gtk[Rc]Style code
[~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
20 #define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
21
22 #include "config.h"
23
24 #include <string.h>
25
26 #include "gtkmodules.h"
27 #include "gtksettings.h"
28 #include "gtkrc.h"
29 #include "gtkintl.h"
30 #include "gtkwidget.h"
31 #include "gtktypeutils.h"
32 #include "gtkprivate.h"
33 #include "gtkcssprovider.h"
34 #include "gtksymboliccolor.h"
35 #include "gtkversion.h"
36
37 #ifdef GDK_WINDOWING_X11
38 #include "x11/gdkx.h"
39 #include <pango/pangofc-fontmap.h>
40 #endif
41
42
43 /**
44  * SECTION:gtksettings
45  * @Short_description: Sharing settings between applications
46  * @Title: Settings
47  *
48  * GtkSettings provide a mechanism to share global settings between applications.
49  * On the X window system, this sharing is realized by an
50  * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
51  * manager that is usually part of the desktop environment, along with utilities
52  * that let the user change these settings. In the absence of an Xsettings manager,
53  * settings can also be specified in RC files.
54  *
55  * Applications can override system-wide settings with gtk_settings_set_string_property(),
56  * gtk_settings_set_long_property(), etc. This should be restricted to special
57  * cases though; GtkSettings are not meant as an application configuration
58  * facility. When doing so, you need to be aware that settings that are specific
59  * to individual widgets may not be available before the widget type has been
60  * realized at least once. The following example demonstrates a way to do this:
61  * <informalexample><programlisting>
62  *   gtk_init (&argc, &argv);
63  *
64  *   /&ast; make sure the type is realized &ast;/
65  *   g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
66  *
67  *   g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
68  * </programlisting></informalexample>
69  *
70  * There is one GtkSettings instance per screen. It can be obtained with
71  * gtk_settings_get_for_screen(), but in many cases, it is more convenient
72  * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
73  * GtkSettings instance for the default screen.
74  */
75
76
77 #ifdef GDK_WINDOWING_QUARTZ
78 #define DEFAULT_KEY_THEME "Mac"
79 #else
80 #define DEFAULT_KEY_THEME NULL
81 #endif
82
83 #define DEFAULT_TIMEOUT_INITIAL 200
84 #define DEFAULT_TIMEOUT_REPEAT   20
85 #define DEFAULT_TIMEOUT_EXPAND  500
86
87 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
88
89 typedef enum
90 {
91   GTK_SETTINGS_SOURCE_DEFAULT,
92   GTK_SETTINGS_SOURCE_RC_FILE,
93   GTK_SETTINGS_SOURCE_XSETTING,
94   GTK_SETTINGS_SOURCE_APPLICATION
95 } GtkSettingsSource;
96
97 struct _GtkSettingsValuePrivate
98 {
99   GtkSettingsValue public;
100   GtkSettingsSource source;
101 };
102
103 struct _GtkSettingsPropertyValue
104 {
105   GValue value;
106   GtkSettingsSource source;
107 };
108
109 enum {
110   PROP_0,
111   PROP_DOUBLE_CLICK_TIME,
112   PROP_DOUBLE_CLICK_DISTANCE,
113   PROP_CURSOR_BLINK,
114   PROP_CURSOR_BLINK_TIME,
115   PROP_CURSOR_BLINK_TIMEOUT,
116   PROP_SPLIT_CURSOR,
117   PROP_THEME_NAME,
118   PROP_ICON_THEME_NAME,
119   PROP_FALLBACK_ICON_THEME,
120   PROP_KEY_THEME_NAME,
121   PROP_MENU_BAR_ACCEL,
122   PROP_DND_DRAG_THRESHOLD,
123   PROP_FONT_NAME,
124   PROP_ICON_SIZES,
125   PROP_MODULES,
126 #ifdef GDK_WINDOWING_X11
127   PROP_XFT_ANTIALIAS,
128   PROP_XFT_HINTING,
129   PROP_XFT_HINTSTYLE,
130   PROP_XFT_RGBA,
131   PROP_XFT_DPI,
132   PROP_CURSOR_THEME_NAME,
133   PROP_CURSOR_THEME_SIZE,
134 #endif
135   PROP_ALTERNATIVE_BUTTON_ORDER,
136   PROP_ALTERNATIVE_SORT_ARROWS,
137   PROP_SHOW_INPUT_METHOD_MENU,
138   PROP_SHOW_UNICODE_MENU,
139   PROP_TIMEOUT_INITIAL,
140   PROP_TIMEOUT_REPEAT,
141   PROP_TIMEOUT_EXPAND,
142   PROP_COLOR_SCHEME,
143   PROP_ENABLE_ANIMATIONS,
144   PROP_TOUCHSCREEN_MODE,
145   PROP_TOOLTIP_TIMEOUT,
146   PROP_TOOLTIP_BROWSE_TIMEOUT,
147   PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
148   PROP_KEYNAV_CURSOR_ONLY,
149   PROP_KEYNAV_WRAP_AROUND,
150   PROP_ERROR_BELL,
151   PROP_COLOR_HASH,
152   PROP_FILE_CHOOSER_BACKEND,
153   PROP_PRINT_BACKENDS,
154   PROP_PRINT_PREVIEW_COMMAND,
155   PROP_ENABLE_MNEMONICS,
156   PROP_ENABLE_ACCELS,
157   PROP_RECENT_FILES_LIMIT,
158   PROP_IM_MODULE,
159   PROP_RECENT_FILES_MAX_AGE,
160   PROP_FONTCONFIG_TIMESTAMP,
161   PROP_SOUND_THEME_NAME,
162   PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
163   PROP_ENABLE_EVENT_SOUNDS,
164   PROP_ENABLE_TOOLTIPS,
165   PROP_TOOLBAR_STYLE,
166   PROP_TOOLBAR_ICON_SIZE,
167   PROP_AUTO_MNEMONICS,
168   PROP_APPLICATION_PREFER_DARK_THEME,
169   PROP_BUTTON_IMAGES,
170   PROP_ENTRY_SELECT_ON_FOCUS,
171   PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
172   PROP_MENU_IMAGES,
173   PROP_MENU_BAR_POPUP_DELAY,
174   PROP_SCROLLED_WINDOW_PLACEMENT,
175   PROP_CAN_CHANGE_ACCELS,
176   PROP_MENU_POPUP_DELAY,
177   PROP_MENU_POPDOWN_DELAY,
178   PROP_LABEL_SELECT_ON_FOCUS,
179   PROP_COLOR_PALETTE,
180   PROP_IM_PREEDIT_STYLE,
181   PROP_IM_STATUS_STYLE
182 };
183
184 /* --- prototypes --- */
185 static void     gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
186
187 static void     gtk_settings_finalize            (GObject               *object);
188 static void     gtk_settings_get_property        (GObject               *object,
189                                                   guint                  property_id,
190                                                   GValue                *value,
191                                                   GParamSpec            *pspec);
192 static void     gtk_settings_set_property        (GObject               *object,
193                                                   guint                  property_id,
194                                                   const GValue          *value,
195                                                   GParamSpec            *pspec);
196 static void     gtk_settings_notify              (GObject               *object,
197                                                   GParamSpec            *pspec);
198 static guint    settings_install_property_parser (GtkSettingsClass      *class,
199                                                   GParamSpec            *pspec,
200                                                   GtkRcPropertyParser    parser);
201 static void    settings_update_double_click      (GtkSettings           *settings);
202 static void    settings_update_modules           (GtkSettings           *settings);
203
204 #ifdef GDK_WINDOWING_X11
205 static void    settings_update_cursor_theme      (GtkSettings           *settings);
206 static void    settings_update_resolution        (GtkSettings           *settings);
207 static void    settings_update_font_options      (GtkSettings           *settings);
208 static gboolean settings_update_fontconfig       (GtkSettings           *settings);
209 #endif
210 static void    settings_update_color_scheme      (GtkSettings *settings);
211 static void    settings_update_theme             (GtkSettings *settings);
212
213 static void    merge_color_scheme                (GtkSettings           *settings, 
214                                                   const GValue          *value, 
215                                                   GtkSettingsSource      source);
216 static gchar  *get_color_scheme                  (GtkSettings           *settings);
217 static GHashTable *get_color_hash                (GtkSettings           *settings);
218
219 /* the default palette for GtkColorSelelection */
220 static const gchar default_color_palette[] =
221   "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
222   "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
223
224 /* --- variables --- */
225 static GQuark            quark_property_parser = 0;
226 static GSList           *object_list = NULL;
227 static guint             class_n_properties = 0;
228
229
230 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
231                         G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
232                                                gtk_settings_provider_iface_init));
233
234 /* --- functions --- */
235 static void
236 gtk_settings_init (GtkSettings *settings)
237 {
238   GParamSpec **pspecs, **p;
239   guint i = 0;
240   
241   g_datalist_init (&settings->queued_settings);
242   object_list = g_slist_prepend (object_list, settings);
243
244   /* build up property array for all yet existing properties and queue
245    * notification for them (at least notification for internal properties
246    * will instantly be caught)
247    */
248   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
249   for (p = pspecs; *p; p++)
250     if ((*p)->owner_type == G_OBJECT_TYPE (settings))
251       i++;
252   settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
253   i = 0;
254   g_object_freeze_notify (G_OBJECT (settings));
255   for (p = pspecs; *p; p++)
256     {
257       GParamSpec *pspec = *p;
258
259       if (pspec->owner_type != G_OBJECT_TYPE (settings))
260         continue;
261       g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
262       g_param_value_set_default (pspec, &settings->property_values[i].value);
263       g_object_notify (G_OBJECT (settings), pspec->name);
264       settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
265       i++;
266     }
267   g_object_thaw_notify (G_OBJECT (settings));
268   g_free (pspecs);
269 }
270
271 static void
272 gtk_settings_class_init (GtkSettingsClass *class)
273 {
274   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
275   guint result;
276   
277   gobject_class->finalize = gtk_settings_finalize;
278   gobject_class->get_property = gtk_settings_get_property;
279   gobject_class->set_property = gtk_settings_set_property;
280   gobject_class->notify = gtk_settings_notify;
281
282   quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
283   result = settings_install_property_parser (class,
284                                              g_param_spec_int ("gtk-double-click-time",
285                                                                P_("Double Click Time"),
286                                                                P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
287                                                                0, G_MAXINT, 250,
288                                                                GTK_PARAM_READWRITE),
289                                              NULL);
290   g_assert (result == PROP_DOUBLE_CLICK_TIME);
291   result = settings_install_property_parser (class,
292                                              g_param_spec_int ("gtk-double-click-distance",
293                                                                P_("Double Click Distance"),
294                                                                P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
295                                                                0, G_MAXINT, 5,
296                                                                GTK_PARAM_READWRITE),
297                                              NULL);
298   g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
299
300   /**
301    * GtkSettings:gtk-cursor-blink:
302    *
303    * Whether the cursor should blink. 
304    *
305    * Also see the #GtkSettings:gtk-cursor-blink-timeout setting, 
306    * which allows more flexible control over cursor blinking.
307    */
308   result = settings_install_property_parser (class,
309                                              g_param_spec_boolean ("gtk-cursor-blink",
310                                                                    P_("Cursor Blink"),
311                                                                    P_("Whether the cursor should blink"),
312                                                                    TRUE,
313                                                                    GTK_PARAM_READWRITE),
314                                              NULL);
315   g_assert (result == PROP_CURSOR_BLINK);
316   result = settings_install_property_parser (class,
317                                              g_param_spec_int ("gtk-cursor-blink-time",
318                                                                P_("Cursor Blink Time"),
319                                                                P_("Length of the cursor blink cycle, in milliseconds"),
320                                                                100, G_MAXINT, 1200,
321                                                                GTK_PARAM_READWRITE),
322                                              NULL);
323   g_assert (result == PROP_CURSOR_BLINK_TIME);
324  
325   /**
326    * GtkSettings:gtk-cursor-blink-timeout:
327    *
328    * Time after which the cursor stops blinking, in seconds.
329    * The timer is reset after each user interaction.
330    *
331    * Setting this to zero has the same effect as setting
332    * #GtkSettings:gtk-cursor-blink to %FALSE. 
333    *
334    * Since: 2.12
335    */
336   result = settings_install_property_parser (class,
337                                              g_param_spec_int ("gtk-cursor-blink-timeout",
338                                                                P_("Cursor Blink Timeout"),
339                                                                P_("Time after which the cursor stops blinking, in seconds"),
340                                                                1, G_MAXINT, G_MAXINT,
341                                                                GTK_PARAM_READWRITE),
342                                              NULL);
343   g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
344   result = settings_install_property_parser (class,
345                                              g_param_spec_boolean ("gtk-split-cursor",
346                                                                    P_("Split Cursor"),
347                                                                    P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
348                                                                    TRUE,
349                                                                    GTK_PARAM_READWRITE),
350                                              NULL);
351   g_assert (result == PROP_SPLIT_CURSOR);
352   result = settings_install_property_parser (class,
353                                              g_param_spec_string ("gtk-theme-name",
354                                                                    P_("Theme Name"),
355                                                                    P_("Name of theme RC file to load"),
356                                                                   "Raleigh",
357                                                                   GTK_PARAM_READWRITE),
358                                              NULL);
359   g_assert (result == PROP_THEME_NAME);
360
361   result = settings_install_property_parser (class,
362                                              g_param_spec_string ("gtk-icon-theme-name",
363                                                                   P_("Icon Theme Name"),
364                                                                   P_("Name of icon theme to use"),
365                                                                   "hicolor",
366                                                                   GTK_PARAM_READWRITE),
367                                              NULL);
368   g_assert (result == PROP_ICON_THEME_NAME);
369
370   result = settings_install_property_parser (class,
371                                              g_param_spec_string ("gtk-fallback-icon-theme",
372                                                                   P_("Fallback Icon Theme Name"),
373                                                                   P_("Name of a icon theme to fall back to"),
374                                                                   NULL,
375                                                                   GTK_PARAM_READWRITE),
376                                              NULL);
377   g_assert (result == PROP_FALLBACK_ICON_THEME);
378   
379   result = settings_install_property_parser (class,
380                                              g_param_spec_string ("gtk-key-theme-name",
381                                                                   P_("Key Theme Name"),
382                                                                   P_("Name of key theme RC file to load"),
383                                                                   DEFAULT_KEY_THEME,
384                                                                   GTK_PARAM_READWRITE),
385                                              NULL);
386   g_assert (result == PROP_KEY_THEME_NAME);    
387
388   result = settings_install_property_parser (class,
389                                              g_param_spec_string ("gtk-menu-bar-accel",
390                                                                   P_("Menu bar accelerator"),
391                                                                   P_("Keybinding to activate the menu bar"),
392                                                                   "F10",
393                                                                   GTK_PARAM_READWRITE),
394                                              NULL);
395   g_assert (result == PROP_MENU_BAR_ACCEL);
396
397   result = settings_install_property_parser (class,
398                                              g_param_spec_int ("gtk-dnd-drag-threshold",
399                                                                P_("Drag threshold"),
400                                                                P_("Number of pixels the cursor can move before dragging"),
401                                                                1, G_MAXINT, 8,
402                                                                GTK_PARAM_READWRITE),
403                                              NULL);
404   g_assert (result == PROP_DND_DRAG_THRESHOLD);
405
406   result = settings_install_property_parser (class,
407                                              g_param_spec_string ("gtk-font-name",
408                                                                    P_("Font Name"),
409                                                                    P_("Name of default font to use"),
410                                                                   "Sans 10",
411                                                                   GTK_PARAM_READWRITE),
412                                              NULL);
413   g_assert (result == PROP_FONT_NAME);
414
415   /**
416    * GtkSettings:gtk-icon-sizes:
417    *
418    * A list of icon sizes. The list is separated by colons, and
419    * item has the form:
420    *
421    * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
422    *
423    * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48". 
424    * GTK+ itself use the following named icon sizes: gtk-menu, 
425    * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd, 
426    * gtk-dialog. Applications can register their own named icon 
427    * sizes with gtk_icon_size_register().
428    */
429   result = settings_install_property_parser (class,
430                                              g_param_spec_string ("gtk-icon-sizes",
431                                                                    P_("Icon Sizes"),
432                                                                    P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
433                                                                   NULL,
434                                                                   GTK_PARAM_READWRITE),
435                                              NULL);
436   g_assert (result == PROP_ICON_SIZES);
437
438   result = settings_install_property_parser (class,
439                                              g_param_spec_string ("gtk-modules",
440                                                                   P_("GTK Modules"),
441                                                                   P_("List of currently active GTK modules"),
442                                                                   NULL,
443                                                                   GTK_PARAM_READWRITE),
444                                              NULL);
445   g_assert (result == PROP_MODULES);
446
447 #ifdef GDK_WINDOWING_X11
448   result = settings_install_property_parser (class,
449                                              g_param_spec_int ("gtk-xft-antialias",
450                                                                P_("Xft Antialias"),
451                                                                P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
452                                                                -1, 1, -1,
453                                                                GTK_PARAM_READWRITE),
454                                              NULL);
455  
456   g_assert (result == PROP_XFT_ANTIALIAS);
457   
458   result = settings_install_property_parser (class,
459                                              g_param_spec_int ("gtk-xft-hinting",
460                                                                P_("Xft Hinting"),
461                                                                P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
462                                                                -1, 1, -1,
463                                                                GTK_PARAM_READWRITE),
464                                              NULL);
465   
466   g_assert (result == PROP_XFT_HINTING);
467   
468   result = settings_install_property_parser (class,
469                                              g_param_spec_string ("gtk-xft-hintstyle",
470                                                                   P_("Xft Hint Style"),
471                                                                   P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
472                                                                   NULL,
473                                                                   GTK_PARAM_READWRITE),
474                                               NULL);
475   
476   g_assert (result == PROP_XFT_HINTSTYLE);
477   
478   result = settings_install_property_parser (class,
479                                              g_param_spec_string ("gtk-xft-rgba",
480                                                                   P_("Xft RGBA"),
481                                                                   P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
482                                                                   NULL,
483                                                                   GTK_PARAM_READWRITE),
484                                              NULL);
485   
486   g_assert (result == PROP_XFT_RGBA);
487   
488   result = settings_install_property_parser (class,
489                                              g_param_spec_int ("gtk-xft-dpi",
490                                                                P_("Xft DPI"),
491                                                                P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
492                                                                -1, 1024*1024, -1,
493                                                                GTK_PARAM_READWRITE),
494                                              NULL);
495   
496   g_assert (result == PROP_XFT_DPI);
497
498   result = settings_install_property_parser (class,
499                                              g_param_spec_string ("gtk-cursor-theme-name",
500                                                                   P_("Cursor theme name"),
501                                                                   P_("Name of the cursor theme to use, or NULL to use the default theme"),
502                                                                   NULL,
503                                                                   GTK_PARAM_READWRITE),
504                                              NULL);
505   g_assert (result == PROP_CURSOR_THEME_NAME);
506
507   result = settings_install_property_parser (class,
508                                              g_param_spec_int ("gtk-cursor-theme-size",
509                                                                P_("Cursor theme size"),
510                                                                P_("Size to use for cursors, or 0 to use the default size"),
511                                                                0, 128, 0,
512                                                                GTK_PARAM_READWRITE),
513                                              NULL);
514   
515   g_assert (result == PROP_CURSOR_THEME_SIZE);
516
517 #endif  /* GDK_WINDOWING_X11 */
518   result = settings_install_property_parser (class,
519                                              g_param_spec_boolean ("gtk-alternative-button-order",
520                                                                    P_("Alternative button order"),
521                                                                    P_("Whether buttons in dialogs should use the alternative button order"),
522                                                                    FALSE,
523                                                                    GTK_PARAM_READWRITE),
524                                              NULL);
525   g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
526
527   /**
528    * GtkSettings:gtk-alternative-sort-arrows:
529    *
530    * Controls the direction of the sort indicators in sorted list and tree
531    * views. By default an arrow pointing down means the column is sorted
532    * in ascending order. When set to %TRUE, this order will be inverted.
533    *
534    * Since: 2.12
535    */
536   result = settings_install_property_parser (class,
537                                              g_param_spec_boolean ("gtk-alternative-sort-arrows",
538                                                                    P_("Alternative sort indicator direction"),
539                                                                    P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
540                                                                    FALSE,
541                                                                    GTK_PARAM_READWRITE),
542                                              NULL);
543   g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
544
545   result = settings_install_property_parser (class,
546                                              g_param_spec_boolean ("gtk-show-input-method-menu",
547                                                                    P_("Show the 'Input Methods' menu"),
548                                                                    P_("Whether the context menus of entries and text views should offer to change the input method"),
549                                                                    TRUE,
550                                                                    GTK_PARAM_READWRITE),
551                                              NULL);
552   g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
553
554   result = settings_install_property_parser (class,
555                                              g_param_spec_boolean ("gtk-show-unicode-menu",
556                                                                    P_("Show the 'Insert Unicode Control Character' menu"),
557                                                                    P_("Whether the context menus of entries and text views should offer to insert control characters"),
558                                                                    TRUE,
559                                                                    GTK_PARAM_READWRITE),
560                                              NULL);
561   g_assert (result == PROP_SHOW_UNICODE_MENU);
562
563   result = settings_install_property_parser (class,
564                                              g_param_spec_int ("gtk-timeout-initial",
565                                                                P_("Start timeout"),
566                                                                P_("Starting value for timeouts, when button is pressed"),
567                                                                0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
568                                                                GTK_PARAM_READWRITE),
569                                              NULL);
570
571   g_assert (result == PROP_TIMEOUT_INITIAL);
572
573   result = settings_install_property_parser (class,
574                                              g_param_spec_int ("gtk-timeout-repeat",
575                                                                P_("Repeat timeout"),
576                                                                P_("Repeat value for timeouts, when button is pressed"),
577                                                                0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
578                                                                GTK_PARAM_READWRITE),
579                                              NULL);
580
581   g_assert (result == PROP_TIMEOUT_REPEAT);
582
583   result = settings_install_property_parser (class,
584                                              g_param_spec_int ("gtk-timeout-expand",
585                                                                P_("Expand timeout"),
586                                                                P_("Expand value for timeouts, when a widget is expanding a new region"),
587                                                                0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
588                                                                GTK_PARAM_READWRITE),
589                                              NULL);
590
591   g_assert (result == PROP_TIMEOUT_EXPAND);
592
593   /**
594    * GtkSettings:gtk-color-scheme:
595    *
596    * A palette of named colors for use in themes. The format of the string is
597    * <programlisting>
598    * name1: color1
599    * name2: color2
600    * ...
601    * </programlisting>
602    * Color names must be acceptable as identifiers in the 
603    * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
604    * color specifications must be in the format accepted by
605    * gdk_color_parse().
606    * 
607    * Note that due to the way the color tables from different sources are
608    * merged, color specifications will be converted to hexadecimal form
609    * when getting this property.
610    *
611    * Starting with GTK+ 2.12, the entries can alternatively be separated
612    * by ';' instead of newlines:
613    * <programlisting>
614    * name1: color1; name2: color2; ...
615    * </programlisting>
616    *
617    * Since: 2.10
618    */
619   result = settings_install_property_parser (class,
620                                              g_param_spec_string ("gtk-color-scheme",
621                                                                   P_("Color scheme"),
622                                                                   P_("A palette of named colors for use in themes"),
623                                                                   "",
624                                                                   GTK_PARAM_READWRITE),
625                                              NULL);
626
627   g_assert (result == PROP_COLOR_SCHEME);
628
629   result = settings_install_property_parser (class,
630                                              g_param_spec_boolean ("gtk-enable-animations",
631                                                                    P_("Enable Animations"),
632                                                                    P_("Whether to enable toolkit-wide animations."),
633                                                                    TRUE,
634                                                                    GTK_PARAM_READWRITE),
635                                              NULL);
636
637   g_assert (result == PROP_ENABLE_ANIMATIONS);
638
639   /**
640    * GtkSettings:gtk-touchscreen-mode:
641    *
642    * When %TRUE, there are no motion notify events delivered on this screen,
643    * and widgets can't use the pointer hovering them for any essential
644    * functionality.
645    *
646    * Since: 2.10
647    */
648   result = settings_install_property_parser (class,
649                                              g_param_spec_boolean ("gtk-touchscreen-mode",
650                                                                    P_("Enable Touchscreen Mode"),
651                                                                    P_("When TRUE, there are no motion notify events delivered on this screen"),
652                                                                    FALSE,
653                                                                    GTK_PARAM_READWRITE),
654                                              NULL);
655
656   g_assert (result == PROP_TOUCHSCREEN_MODE);
657
658   /**
659    * GtkSettings:gtk-tooltip-timeout:
660    *
661    * Time, in milliseconds, after which a tooltip could appear if the
662    * cursor is hovering on top of a widget.
663    *
664    * Since: 2.12
665    */
666   result = settings_install_property_parser (class,
667                                              g_param_spec_int ("gtk-tooltip-timeout",
668                                                                P_("Tooltip timeout"),
669                                                                P_("Timeout before tooltip is shown"),
670                                                                0, G_MAXINT,
671                                                                500,
672                                                                GTK_PARAM_READWRITE),
673                                              NULL);
674
675   g_assert (result == PROP_TOOLTIP_TIMEOUT);
676
677   /**
678    * GtkSettings:gtk-tooltip-browse-timeout:
679    *
680    * Controls the time after which tooltips will appear when
681    * browse mode is enabled, in milliseconds.
682    *
683    * Browse mode is enabled when the mouse pointer moves off an object
684    * where a tooltip was currently being displayed. If the mouse pointer
685    * hits another object before the browse mode timeout expires (see
686    * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the 
687    * amount of milliseconds specified by this setting to popup the tooltip
688    * for the new object.
689    *
690    * Since: 2.12
691    */
692   result = settings_install_property_parser (class,
693                                              g_param_spec_int ("gtk-tooltip-browse-timeout",
694                                                                P_("Tooltip browse timeout"),
695                                                                P_("Timeout before tooltip is shown when browse mode is enabled"),
696                                                                0, G_MAXINT,
697                                                                60,
698                                                                GTK_PARAM_READWRITE),
699                                              NULL);
700
701   g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
702
703   /**
704    * GtkSettings:gtk-tooltip-browse-mode-timeout:
705    *
706    * Amount of time, in milliseconds, after which the browse mode
707    * will be disabled.
708    *
709    * See #GtkSettings:gtk-tooltip-browse-timeout for more information
710    * about browse mode.
711    *
712    * Since: 2.12
713    */
714   result = settings_install_property_parser (class,
715                                              g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
716                                                                P_("Tooltip browse mode timeout"),
717                                                                P_("Timeout after which browse mode is disabled"),
718                                                                0, G_MAXINT,
719                                                                500,
720                                                                GTK_PARAM_READWRITE),
721                                              NULL);
722
723   g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
724
725   /**
726    * GtkSettings:gtk-keynav-cursor-only:
727    *
728    * When %TRUE, keyboard navigation should be able to reach all widgets
729    * by using the cursor keys only. Tab, Shift etc. keys can't be expected
730    * to be present on the used input device.
731    *
732    * Since: 2.12
733    */
734   result = settings_install_property_parser (class,
735                                              g_param_spec_boolean ("gtk-keynav-cursor-only",
736                                                                    P_("Keynav Cursor Only"),
737                                                                    P_("When TRUE, there are only cursor keys available to navigate widgets"),
738                                                                    FALSE,
739                                                                    GTK_PARAM_READWRITE),
740                                              NULL);
741
742   g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
743
744   /**
745    * GtkSettings:gtk-keynav-wrap-around:
746    *
747    * When %TRUE, some widgets will wrap around when doing keyboard
748    * navigation, such as menus, menubars and notebooks.
749    *
750    * Since: 2.12
751    */
752   result = settings_install_property_parser (class,
753                                              g_param_spec_boolean ("gtk-keynav-wrap-around",
754                                                                    P_("Keynav Wrap Around"),
755                                                                    P_("Whether to wrap around when keyboard-navigating widgets"),
756                                                                    TRUE,
757                                                                    GTK_PARAM_READWRITE),
758                                              NULL);
759
760   g_assert (result == PROP_KEYNAV_WRAP_AROUND);
761
762   /**
763    * GtkSettings:gtk-error-bell:
764    *
765    * When %TRUE, keyboard navigation and other input-related errors
766    * will cause a beep. Since the error bell is implemented using
767    * gdk_window_beep(), the windowing system may offer ways to
768    * configure the error bell in many ways, such as flashing the
769    * window or similar visual effects.
770    *
771    * Since: 2.12
772    */
773   result = settings_install_property_parser (class,
774                                              g_param_spec_boolean ("gtk-error-bell",
775                                                                    P_("Error Bell"),
776                                                                    P_("When TRUE, keyboard navigation and other errors will cause a beep"),
777                                                                    TRUE,
778                                                                    GTK_PARAM_READWRITE),
779                                              NULL);
780
781   g_assert (result == PROP_ERROR_BELL);
782
783   /**
784    * GtkSettings:color-hash:
785    *
786    * Holds a hash table representation of the #GtkSettings:gtk-color-scheme 
787    * setting, mapping color names to #GdkColor<!-- -->s. 
788    *
789    * Since: 2.10
790    */
791   result = settings_install_property_parser (class, 
792                                              g_param_spec_boxed ("color-hash",
793                                                                  P_("Color Hash"),
794                                                                  P_("A hash table representation of the color scheme."),
795                                                                  G_TYPE_HASH_TABLE,
796                                                                  GTK_PARAM_READABLE),
797                                              NULL);
798   g_assert (result == PROP_COLOR_HASH);
799
800   result = settings_install_property_parser (class, 
801                                              g_param_spec_string ("gtk-file-chooser-backend",
802                                                                   P_("Default file chooser backend"),
803                                                                   P_("Name of the GtkFileChooser backend to use by default"),
804                                                                   NULL,
805                                                                   GTK_PARAM_READWRITE),
806                                              NULL);
807   g_assert (result == PROP_FILE_CHOOSER_BACKEND);
808
809   /**
810    * GtkSettings:gtk-print-backends:
811    *
812    * A comma-separated list of print backends to use in the print
813    * dialog. Available print backends depend on the GTK+ installation,
814    * and may include "file", "cups", "lpr" or "papi".
815    *
816    * Since: 2.10
817    */
818   result = settings_install_property_parser (class,
819                                              g_param_spec_string ("gtk-print-backends",
820                                                                   P_("Default print backend"),
821                                                                   P_("List of the GtkPrintBackend backends to use by default"),
822                                                                   GTK_PRINT_BACKENDS,
823                                                                   GTK_PARAM_READWRITE),
824                                              NULL);
825   g_assert (result == PROP_PRINT_BACKENDS);
826
827   /**
828    * GtkSettings:gtk-print-preview-command:
829    *
830    * A command to run for displaying the print preview. The command
831    * should contain a %f placeholder, which will get replaced by
832    * the path to the pdf file. The command may also contain a %s
833    * placeholder, which will get replaced by the path to a file
834    * containing the print settings in the format produced by 
835    * gtk_print_settings_to_file().
836    *
837    * The preview application is responsible for removing the pdf file
838    * and the print settings file when it is done.
839    *
840    * Since: 2.10
841    */
842   result = settings_install_property_parser (class,
843                                              g_param_spec_string ("gtk-print-preview-command",
844                                                                   P_("Default command to run when displaying a print preview"),
845                                                                   P_("Command to run when displaying a print preview"),
846                                                                   GTK_PRINT_PREVIEW_COMMAND,
847                                                                   GTK_PARAM_READWRITE),
848                                              NULL); 
849   g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
850
851   /**
852    * GtkSettings:gtk-enable-mnemonics:
853    *
854    * Whether labels and menu items should have visible mnemonics which
855    * can be activated.
856    *
857    * Since: 2.12
858    */
859   result = settings_install_property_parser (class,
860                                              g_param_spec_boolean ("gtk-enable-mnemonics",
861                                                                    P_("Enable Mnemonics"),
862                                                                    P_("Whether labels should have mnemonics"),
863                                                                    TRUE,
864                                                                    GTK_PARAM_READWRITE),
865                                              NULL);
866   g_assert (result == PROP_ENABLE_MNEMONICS);
867
868   /**
869    * GtkSettings:gtk-enable-accels:
870    *
871    * Whether menu items should have visible accelerators which can be
872    * activated.
873    *
874    * Since: 2.12
875    */
876   result = settings_install_property_parser (class,
877                                              g_param_spec_boolean ("gtk-enable-accels",
878                                                                    P_("Enable Accelerators"),
879                                                                    P_("Whether menu items should have accelerators"),
880                                                                    TRUE,
881                                                                    GTK_PARAM_READWRITE),
882                                              NULL);
883   g_assert (result == PROP_ENABLE_ACCELS);
884
885   /**
886    * GtkSettings:gtk-recent-files-limit:
887    *
888    * The number of recently used files that should be displayed by default by
889    * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
890    * -1 means every recently used file stored.
891    *
892    * Since: 2.12
893    */
894   result = settings_install_property_parser (class,
895                                              g_param_spec_int ("gtk-recent-files-limit",
896                                                                P_("Recent Files Limit"),
897                                                                P_("Number of recently used files"),
898                                                                -1, G_MAXINT,
899                                                                50,
900                                                                GTK_PARAM_READWRITE),
901                                              NULL);
902   g_assert (result == PROP_RECENT_FILES_LIMIT);
903
904   /**
905    * GtkSettings:gtk-im-module:
906    *
907    * Which IM (input method) module should be used by default. This is the 
908    * input method that will be used if the user has not explicitly chosen 
909    * another input method from the IM context menu.  
910    *
911    * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
912    */
913   result = settings_install_property_parser (class,
914                                              g_param_spec_string ("gtk-im-module",
915                                                                   P_("Default IM module"),
916                                                                   P_("Which IM module should be used by default"),
917                                                                   NULL,
918                                                                   GTK_PARAM_READWRITE),
919                                              NULL);
920   g_assert (result == PROP_IM_MODULE);
921
922   /**
923    * GtkSettings:gtk-recent-files-max-age:
924    *
925    * The maximum age, in days, of the items inside the recently used
926    * resources list. Items older than this setting will be excised
927    * from the list. If set to 0, the list will always be empty; if
928    * set to -1, no item will be removed.
929    *
930    * Since: 2.14
931    */
932   result = settings_install_property_parser (class,
933                                              g_param_spec_int ("gtk-recent-files-max-age",
934                                                                P_("Recent Files Max Age"),
935                                                                P_("Maximum age of recently used files, in days"),
936                                                                -1, G_MAXINT,
937                                                                30,
938                                                                GTK_PARAM_READWRITE),
939                                              NULL);
940   g_assert (result == PROP_RECENT_FILES_MAX_AGE);
941
942   result = settings_install_property_parser (class,
943                                              g_param_spec_uint ("gtk-fontconfig-timestamp",
944                                                                 P_("Fontconfig configuration timestamp"),
945                                                                 P_("Timestamp of current fontconfig configuration"),
946                                                                 0, G_MAXUINT, 0,
947                                                                 GTK_PARAM_READWRITE),
948                                              NULL);
949   
950   g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
951
952   /**
953    * GtkSettings:gtk-sound-theme-name:
954    *
955    * The XDG sound theme to use for event sounds.
956    *
957    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink> 
958    * for more information on event sounds and sound themes.
959    *
960    * GTK+ itself does not support event sounds, you have to use a loadable 
961    * module like the one that comes with libcanberra.
962    *
963    * Since: 2.14
964    */
965   result = settings_install_property_parser (class,
966                                              g_param_spec_string ("gtk-sound-theme-name",
967                                                                   P_("Sound Theme Name"),
968                                                                   P_("XDG sound theme name"),
969                                                                   "freedesktop",
970                                                                   GTK_PARAM_READWRITE),
971                                              NULL);
972   g_assert (result == PROP_SOUND_THEME_NAME);
973
974   /**
975    * GtkSettings:gtk-enable-input-feedback-sounds:
976    *
977    * Whether to play event sounds as feedback to user input.
978    *
979    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink> 
980    * for more information on event sounds and sound themes.
981    *
982    * GTK+ itself does not support event sounds, you have to use a loadable 
983    * module like the one that comes with libcanberra.
984    *
985    * Since: 2.14
986    */
987   result = settings_install_property_parser (class,
988                                              g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
989                                                                    /* Translators: this means sounds that are played as feedback to user input */
990                                                                    P_("Audible Input Feedback"),
991                                                                    P_("Whether to play event sounds as feedback to user input"),
992                                                                    TRUE,
993                                                                    GTK_PARAM_READWRITE),
994                                              NULL);
995   g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
996
997   /**
998    * GtkSettings:gtk-enable-event-sounds:
999    *
1000    * Whether to play any event sounds at all.
1001    *
1002    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink> 
1003    * for more information on event sounds and sound themes.
1004    *
1005    * GTK+ itself does not support event sounds, you have to use a loadable 
1006    * module like the one that comes with libcanberra.
1007    *
1008    * Since: 2.14
1009    */
1010   result = settings_install_property_parser (class,
1011                                              g_param_spec_boolean ("gtk-enable-event-sounds",
1012                                                                    P_("Enable Event Sounds"),
1013                                                                    P_("Whether to play any event sounds at all"),
1014                                                                    TRUE,
1015                                                                    GTK_PARAM_READWRITE),
1016                                              NULL);
1017   g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1018
1019   /**
1020    * GtkSettings:gtk-enable-tooltips:
1021    *
1022    * Whether tooltips should be shown on widgets.
1023    *
1024    * Since: 2.14
1025    */
1026   result = settings_install_property_parser (class,
1027                                              g_param_spec_boolean ("gtk-enable-tooltips",
1028                                                                    P_("Enable Tooltips"),
1029                                                                    P_("Whether tooltips should be shown on widgets"),
1030                                                                    TRUE,
1031                                                                    GTK_PARAM_READWRITE),
1032                                              NULL);
1033   g_assert (result == PROP_ENABLE_TOOLTIPS);
1034
1035   /**
1036    * GtkSettings:toolbar-style:
1037    *
1038    * The size of icons in default toolbars.
1039    */
1040   result = settings_install_property_parser (class,
1041                                              g_param_spec_enum ("gtk-toolbar-style",
1042                                                                    P_("Toolbar style"),
1043                                                                    P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1044                                                                    GTK_TYPE_TOOLBAR_STYLE,
1045                                                                    GTK_TOOLBAR_BOTH,
1046                                                                    GTK_PARAM_READWRITE),
1047                                              gtk_rc_property_parse_enum);
1048   g_assert (result == PROP_TOOLBAR_STYLE);
1049
1050   /**
1051    * GtkSettings:toolbar-icon-size:
1052    *
1053    * The size of icons in default toolbars.
1054    */
1055   result = settings_install_property_parser (class,
1056                                              g_param_spec_enum ("gtk-toolbar-icon-size",
1057                                                                    P_("Toolbar Icon Size"),
1058                                                                    P_("The size of icons in default toolbars."),
1059                                                                    GTK_TYPE_ICON_SIZE,
1060                                                                    GTK_ICON_SIZE_LARGE_TOOLBAR,
1061                                                                    GTK_PARAM_READWRITE),
1062                                              gtk_rc_property_parse_enum);
1063   g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1064
1065   /**
1066    * GtkSettings:gtk-auto-mnemonics:
1067    *
1068    * Whether mnemonics should be automatically shown and hidden when the user
1069    * presses the mnemonic activator.
1070    *
1071    * Since: 2.20
1072    */
1073   result = settings_install_property_parser (class,
1074                                              g_param_spec_boolean ("gtk-auto-mnemonics",
1075                                                                    P_("Auto Mnemonics"),
1076                                                                    P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1077                                                                    FALSE,
1078                                                                    GTK_PARAM_READWRITE),
1079                                              NULL);
1080   g_assert (result == PROP_AUTO_MNEMONICS);
1081
1082   /**
1083    * GtkSettings:gtk-application-prefer-dark-theme:
1084    *
1085    * Whether the application prefers to use a dark theme. If a GTK+ theme
1086    * includes a dark variant, it will be used instead of the configured
1087    * theme.
1088    *
1089    * Some applications benefit from minimizing the amount of light pollution that
1090    * interferes with the content. Good candidates for dark themes are photo and
1091    * video editors that make the actual content get all the attention and minimize
1092    * the distraction of the chrome.
1093    *
1094    * Dark themes should not be used for documents, where large spaces are white/light
1095    * and the dark chrome creates too much contrast (web browser, text editor...).
1096    *
1097    * Since: 2.22
1098    */
1099   result = settings_install_property_parser (class,
1100                                              g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1101                                                                  P_("Application prefers a dark theme"),
1102                                                                  P_("Whether the application prefers to have a dark theme."),
1103                                                                  FALSE,
1104                                                                  GTK_PARAM_READWRITE),
1105                                              NULL);
1106   g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1107
1108   /**
1109    * GtkSettings::gtk-button-images:
1110    *
1111    * Whether images should be shown on buttons
1112    *
1113    * Since: 2.4
1114    */
1115   result = settings_install_property_parser (class,
1116                                              g_param_spec_boolean ("gtk-button-images",
1117                                                                    P_("Show button images"),
1118                                                                    P_("Whether images should be shown on buttons"),
1119                                                                    TRUE,
1120                                                                    GTK_PARAM_READWRITE),
1121                                              NULL);
1122   g_assert (result == PROP_BUTTON_IMAGES);
1123
1124   result = settings_install_property_parser (class,
1125                                              g_param_spec_boolean ("gtk-entry-select-on-focus",
1126                                                                    P_("Select on focus"),
1127                                                                    P_("Whether to select the contents of an entry when it is focused"),
1128                                                                    TRUE,
1129                                                                    GTK_PARAM_READWRITE),
1130                                              NULL);
1131   g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1132
1133   /**
1134    * GtkSettings:gtk-entry-password-hint-timeout:
1135    *
1136    * How long to show the last input character in hidden
1137    * entries. This value is in milliseconds. 0 disables showing the
1138    * last char. 600 is a good value for enabling it.
1139    *
1140    * Since: 2.10
1141    */
1142   result = settings_install_property_parser (class,
1143                                              g_param_spec_uint ("gtk-entry-password-hint-timeout",
1144                                                                 P_("Password Hint Timeout"),
1145                                                                 P_("How long to show the last input character in hidden entries"),
1146                                                                 0, G_MAXUINT,
1147                                                                 0,
1148                                                                 GTK_PARAM_READWRITE),
1149                                              NULL);
1150   g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1151
1152   result = settings_install_property_parser (class,
1153                                              g_param_spec_boolean ("gtk-menu-images",
1154                                                                    P_("Show menu images"),
1155                                                                    P_("Whether images should be shown in menus"),
1156                                                                    TRUE,
1157                                                                    GTK_PARAM_READWRITE),
1158                                              NULL);
1159   g_assert (result == PROP_MENU_IMAGES);
1160
1161   result = settings_install_property_parser (class,
1162                                              g_param_spec_int ("gtk-menu-bar-popup-delay",
1163                                                                P_("Delay before drop down menus appear"),
1164                                                                P_("Delay before the submenus of a menu bar appear"),
1165                                                                0, G_MAXINT,
1166                                                                0,
1167                                                                GTK_PARAM_READWRITE),
1168                                              NULL);
1169   g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1170
1171   /**
1172    * GtkSettings:gtk-scrolled-window-placement:
1173    *
1174    * Where the contents of scrolled windows are located with respect to the 
1175    * scrollbars, if not overridden by the scrolled window's own placement.
1176    *
1177    * Since: 2.10
1178    */
1179   result = settings_install_property_parser (class,
1180                                              g_param_spec_enum ("gtk-scrolled-window-placement",
1181                                                                 P_("Scrolled Window Placement"),
1182                                                                 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1183                                                                 GTK_TYPE_CORNER_TYPE,
1184                                                                 GTK_CORNER_TOP_LEFT,
1185                                                                 GTK_PARAM_READWRITE),
1186                                              gtk_rc_property_parse_enum);
1187   g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1188
1189   result = settings_install_property_parser (class,
1190                                              g_param_spec_boolean ("gtk-can-change-accels",
1191                                                                    P_("Can change accelerators"),
1192                                                                    P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1193                                                                    FALSE,
1194                                                                    GTK_PARAM_READWRITE),
1195                                              NULL);
1196   g_assert (result == PROP_CAN_CHANGE_ACCELS);
1197
1198   result = settings_install_property_parser (class,
1199                                              g_param_spec_int ("gtk-menu-popup-delay",
1200                                                                P_("Delay before submenus appear"),
1201                                                                P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1202                                                                0, G_MAXINT,
1203                                                                225,
1204                                                                GTK_PARAM_READWRITE),
1205                                              NULL);
1206   g_assert (result == PROP_MENU_POPUP_DELAY);
1207
1208   result = settings_install_property_parser (class,
1209                                              g_param_spec_int ("gtk-menu-popdown-delay",
1210                                                                P_("Delay before hiding a submenu"),
1211                                                                P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1212                                                                0, G_MAXINT,
1213                                                                1000,
1214                                                                GTK_PARAM_READWRITE),
1215                                              NULL);
1216   g_assert (result == PROP_MENU_POPDOWN_DELAY);
1217
1218   result = settings_install_property_parser (class,
1219                                              g_param_spec_boolean ("gtk-label-select-on-focus",
1220                                                                    P_("Select on focus"),
1221                                                                    P_("Whether to select the contents of a selectable label when it is focused"),
1222                                                                    TRUE,
1223                                                                    GTK_PARAM_READWRITE),
1224                                              NULL);
1225   g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1226
1227   result = settings_install_property_parser (class,
1228                                              g_param_spec_string ("gtk-color-palette",
1229                                                                   P_("Custom palette"),
1230                                                                   P_("Palette to use in the color selector"),
1231                                                                   default_color_palette,
1232                                                                   GTK_PARAM_READWRITE),
1233                                              NULL);
1234   g_assert (result == PROP_COLOR_PALETTE);
1235
1236   result = settings_install_property_parser (class,
1237                                              g_param_spec_enum ("gtk-im-preedit-style",
1238                                                                 P_("IM Preedit style"),
1239                                                                 P_("How to draw the input method preedit string"),
1240                                                                 GTK_TYPE_IM_PREEDIT_STYLE,
1241                                                                 GTK_IM_PREEDIT_CALLBACK,
1242                                                                 GTK_PARAM_READWRITE),
1243                                              gtk_rc_property_parse_enum);
1244   g_assert (result == PROP_IM_PREEDIT_STYLE);
1245
1246   result = settings_install_property_parser (class,
1247                                              g_param_spec_enum ("gtk-im-status-style",
1248                                                                 P_("IM Status style"),
1249                                                                 P_("How to draw the input method statusbar"),
1250                                                                 GTK_TYPE_IM_STATUS_STYLE,
1251                                                                 GTK_IM_STATUS_CALLBACK,
1252                                                                 GTK_PARAM_READWRITE),
1253                                              gtk_rc_property_parse_enum);
1254   g_assert (result == PROP_IM_STATUS_STYLE);
1255 }
1256
1257 static GtkStyleProperties *
1258 gtk_settings_get_style (GtkStyleProvider *provider,
1259                         GtkWidgetPath    *path)
1260 {
1261   PangoFontDescription *font_desc;
1262   gchar *font_name, *color_scheme;
1263   GtkSettings *settings;
1264   GtkStyleProperties *props;
1265   gchar **colors;
1266   guint i;
1267
1268   settings = GTK_SETTINGS (provider);
1269   props = gtk_style_properties_new ();
1270
1271   g_object_get (settings,
1272                 "gtk-font-name", &font_name,
1273                 "gtk-color-scheme", &color_scheme,
1274                 NULL);
1275
1276   colors = g_strsplit_set (color_scheme, "\n;", -1);
1277
1278   for (i = 0; colors[i]; i++)
1279     {
1280       GtkSymbolicColor *color;
1281       gchar *name, *pos;
1282       GdkRGBA col;
1283
1284       if (!*colors[i])
1285         continue;
1286
1287       name = colors[i];
1288       pos = strchr (colors[i], ':');
1289
1290       if (!pos)
1291         continue;
1292
1293       /* Set NUL after color name */
1294       *pos = '\0';
1295       pos++;
1296
1297       /* Find start of color string */
1298       while (*pos == ' ')
1299         pos++;
1300
1301       if (!*pos || !gdk_rgba_parse (&col, pos))
1302         continue;
1303
1304       color = gtk_symbolic_color_new_literal (&col);
1305       gtk_style_properties_map_color (props, name, color);
1306       gtk_symbolic_color_unref (color);
1307     }
1308
1309   font_desc = pango_font_description_from_string (font_name);
1310
1311   gtk_style_properties_set (props, 0,
1312                             "font", font_desc,
1313                             NULL);
1314
1315   pango_font_description_free (font_desc);
1316   g_strfreev (colors);
1317   g_free (color_scheme);
1318   g_free (font_name);
1319
1320   return props;
1321 }
1322
1323 static void
1324 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1325 {
1326   iface->get_style = gtk_settings_get_style;
1327 }
1328
1329 static void
1330 gtk_settings_finalize (GObject *object)
1331 {
1332   GtkSettings *settings = GTK_SETTINGS (object);
1333   guint i;
1334
1335   object_list = g_slist_remove (object_list, settings);
1336
1337   for (i = 0; i < class_n_properties; i++)
1338     g_value_unset (&settings->property_values[i].value);
1339   g_free (settings->property_values);
1340   
1341   g_datalist_clear (&settings->queued_settings);
1342
1343   G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1344 }
1345
1346 static void
1347 settings_init_style (GtkSettings *settings)
1348 {
1349   static GtkCssProvider *css_provider = NULL;
1350   GtkCssProvider *default_provider;
1351
1352   /* Add provider for user file */
1353   if (G_UNLIKELY (!css_provider))
1354     {
1355       gchar *css_path;
1356
1357       css_provider = gtk_css_provider_new ();
1358       css_path = g_build_filename (g_get_user_config_dir (),
1359                                    "gtk-3.0",
1360                                    "gtk.css",
1361                                    NULL);
1362
1363       if (g_file_test (css_path,
1364                        G_FILE_TEST_IS_REGULAR))
1365         gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1366
1367       g_free (css_path);
1368     }
1369
1370   gtk_style_context_add_provider_for_screen (settings->screen,
1371                                              GTK_STYLE_PROVIDER (css_provider),
1372                                              GTK_STYLE_PROVIDER_PRIORITY_USER);
1373
1374   default_provider = gtk_css_provider_get_default ();
1375   gtk_style_context_add_provider_for_screen (settings->screen,
1376                                              GTK_STYLE_PROVIDER (default_provider),
1377                                              GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1378
1379   gtk_style_context_add_provider_for_screen (settings->screen,
1380                                              GTK_STYLE_PROVIDER (settings),
1381                                              GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1382
1383   settings_update_theme (settings);
1384 }
1385
1386 /**
1387  * gtk_settings_get_for_screen:
1388  * @screen: a #GdkScreen.
1389  *
1390  * Gets the #GtkSettings object for @screen, creating it if necessary.
1391  *
1392  * Return value: (transfer none): a #GtkSettings object.
1393  *
1394  * Since: 2.2
1395  */
1396 GtkSettings*
1397 gtk_settings_get_for_screen (GdkScreen *screen)
1398 {
1399   GtkSettings *settings;
1400
1401   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1402
1403   settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1404   if (!settings)
1405     {
1406       settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1407       settings->screen = screen;
1408       g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"), 
1409                               settings, g_object_unref);
1410
1411       settings_init_style (settings);
1412       settings_update_double_click (settings);
1413 #ifdef GDK_WINDOWING_X11
1414       settings_update_cursor_theme (settings);
1415       settings_update_resolution (settings);
1416       settings_update_font_options (settings);
1417 #endif
1418       settings_update_color_scheme (settings);
1419     }
1420   
1421   return settings;
1422 }
1423
1424 /**
1425  * gtk_settings_get_default:
1426  * 
1427  * Gets the #GtkSettings object for the default GDK screen, creating
1428  * it if necessary. See gtk_settings_get_for_screen().
1429  *
1430  * Return value: (transfer none): a #GtkSettings object. If there is no default
1431  *  screen, then returns %NULL.
1432  **/
1433 GtkSettings*
1434 gtk_settings_get_default (void)
1435 {
1436   GdkScreen *screen = gdk_screen_get_default ();
1437
1438   if (screen)
1439     return gtk_settings_get_for_screen (screen);
1440   else
1441     return NULL;
1442 }
1443
1444 static void
1445 gtk_settings_set_property (GObject      *object,
1446                            guint         property_id,
1447                            const GValue *value,
1448                            GParamSpec   *pspec)
1449 {
1450   GtkSettings *settings = GTK_SETTINGS (object);
1451
1452   g_value_copy (value, &settings->property_values[property_id - 1].value);
1453   settings->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1454   
1455   if (pspec->param_id == PROP_COLOR_SCHEME)
1456     merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1457 }
1458
1459 static void
1460 gtk_settings_get_property (GObject     *object,
1461                            guint        property_id,
1462                            GValue      *value,
1463                            GParamSpec  *pspec)
1464 {
1465   GtkSettings *settings = GTK_SETTINGS (object);
1466   GType value_type = G_VALUE_TYPE (value);
1467   GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1468
1469   /* handle internal properties */
1470   switch (property_id)
1471     {
1472     case PROP_COLOR_HASH:
1473       g_value_set_boxed (value, get_color_hash (settings));
1474       return;
1475     case PROP_COLOR_SCHEME:
1476       g_value_take_string (value, get_color_scheme (settings));
1477       return;
1478     default: ;
1479     }
1480
1481   /* For enums and strings, we need to get the value as a string,
1482    * not as an int, since we support using names/nicks as the setting
1483    * value.
1484    */
1485   if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1486        !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1487       g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1488       g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1489     {
1490       if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1491           !gdk_screen_get_setting (settings->screen, pspec->name, value))
1492         g_value_copy (&settings->property_values[property_id - 1].value, value);
1493       else 
1494         g_param_value_validate (pspec, value);
1495     }
1496   else
1497     {
1498       GValue val = { 0, };
1499
1500       /* Try to get xsetting as a string and parse it. */
1501       
1502       g_value_init (&val, G_TYPE_STRING);
1503
1504       if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1505           !gdk_screen_get_setting (settings->screen, pspec->name, &val))
1506         {
1507           g_value_copy (&settings->property_values[property_id - 1].value, value);
1508         }
1509       else
1510         {
1511           GValue tmp_value = { 0, };
1512           GValue gstring_value = { 0, };
1513           GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1514           
1515           g_value_init (&gstring_value, G_TYPE_GSTRING);
1516           g_value_take_boxed (&gstring_value,
1517                               g_string_new (g_value_get_string (&val)));
1518
1519           g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1520
1521           if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1522                                                      pspec, &tmp_value))
1523             {
1524               g_value_copy (&tmp_value, value);
1525               g_param_value_validate (pspec, value);
1526             }
1527           else
1528             {
1529               g_value_copy (&settings->property_values[property_id - 1].value, value);
1530             }
1531
1532           g_value_unset (&gstring_value);
1533           g_value_unset (&tmp_value);
1534         }
1535
1536       g_value_unset (&val);
1537     }
1538 }
1539
1540 static void
1541 gtk_settings_notify (GObject    *object,
1542                      GParamSpec *pspec)
1543 {
1544   GtkSettings *settings = GTK_SETTINGS (object);
1545   guint property_id = pspec->param_id;
1546
1547   if (settings->screen == NULL) /* initialization */
1548     return;
1549
1550   switch (property_id)
1551     {
1552     case PROP_MODULES:
1553       settings_update_modules (settings);
1554       break;
1555     case PROP_DOUBLE_CLICK_TIME:
1556     case PROP_DOUBLE_CLICK_DISTANCE:
1557       settings_update_double_click (settings);
1558       break;
1559     case PROP_COLOR_SCHEME:
1560       settings_update_color_scheme (settings);
1561       gtk_style_context_reset_widgets (settings->screen);
1562       break;
1563     case PROP_THEME_NAME:
1564       settings_update_theme (settings);
1565       break;
1566 #ifdef GDK_WINDOWING_X11
1567     case PROP_XFT_DPI:
1568       settings_update_resolution (settings);
1569       /* This is a hack because with gtk_rc_reset_styles() doesn't get
1570        * widgets with gtk_widget_style_set(), and also causes more
1571        * recomputation than necessary.
1572        */
1573       gtk_style_context_reset_widgets (settings->screen);
1574       break;
1575     case PROP_XFT_ANTIALIAS:
1576     case PROP_XFT_HINTING:
1577     case PROP_XFT_HINTSTYLE:
1578     case PROP_XFT_RGBA:
1579       settings_update_font_options (settings);
1580       gtk_style_context_reset_widgets (settings->screen);
1581       break;
1582     case PROP_FONTCONFIG_TIMESTAMP:
1583       if (settings_update_fontconfig (settings))
1584         gtk_style_context_reset_widgets (settings->screen);
1585       break;
1586     case PROP_CURSOR_THEME_NAME:
1587     case PROP_CURSOR_THEME_SIZE:
1588       settings_update_cursor_theme (settings);
1589       break;
1590 #endif /* GDK_WINDOWING_X11 */
1591     }
1592 }
1593
1594 gboolean
1595 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1596                              const GValue       *src_value,
1597                              GParamSpec         *pspec,
1598                              GValue             *dest_value)
1599 {
1600   gboolean success = FALSE;
1601
1602   g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1603
1604   if (parser)
1605     {
1606       GString *gstring;
1607       gboolean free_gstring = TRUE;
1608       
1609       if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1610         {
1611           gstring = g_value_get_boxed (src_value);
1612           free_gstring = FALSE;
1613         }
1614       else if (G_VALUE_HOLDS_LONG (src_value))
1615         {
1616           gstring = g_string_new (NULL);
1617           g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1618         }
1619       else if (G_VALUE_HOLDS_DOUBLE (src_value))
1620         {
1621           gstring = g_string_new (NULL);
1622           g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1623         }
1624       else if (G_VALUE_HOLDS_STRING (src_value))
1625         {
1626           gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1627           
1628           gstring = g_string_new ("\"");
1629           g_string_append (gstring, tstr);
1630           g_string_append_c (gstring, '\"');
1631           g_free (tstr);
1632         }
1633       else
1634         {
1635           g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1636           gstring = NULL; /* silence compiler */
1637         }
1638
1639       success = (parser (pspec, gstring, dest_value) &&
1640                  !g_param_value_validate (pspec, dest_value));
1641
1642       if (free_gstring)
1643         g_string_free (gstring, TRUE);
1644     }
1645   else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1646     {
1647       if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1648         {
1649           GString *gstring = g_value_get_boxed (src_value);
1650
1651           g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1652           success = !g_param_value_validate (pspec, dest_value);
1653         }
1654     }
1655   else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1656     success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1657
1658   return success;
1659 }
1660
1661 static void
1662 apply_queued_setting (GtkSettings             *data,
1663                       GParamSpec              *pspec,
1664                       GtkSettingsValuePrivate *qvalue)
1665 {
1666   GValue tmp_value = { 0, };
1667   GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1668
1669   g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1670   if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1671                                    pspec, &tmp_value))
1672     {
1673       if (pspec->param_id == PROP_COLOR_SCHEME) 
1674         merge_color_scheme (data, &tmp_value, qvalue->source);
1675
1676       if (data->property_values[pspec->param_id - 1].source <= qvalue->source)
1677         {
1678           g_value_copy (&tmp_value, &data->property_values[pspec->param_id - 1].value);
1679           data->property_values[pspec->param_id - 1].source = qvalue->source;
1680           g_object_notify (G_OBJECT (data), g_param_spec_get_name (pspec));
1681         }
1682
1683     }
1684   else
1685     {
1686       gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1687       
1688       g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1689                  qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1690                  pspec->name,
1691                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1692                  debug,
1693                  G_VALUE_TYPE_NAME (&tmp_value));
1694       g_free (debug);
1695     }
1696   g_value_unset (&tmp_value);
1697 }
1698
1699 static guint
1700 settings_install_property_parser (GtkSettingsClass   *class,
1701                                   GParamSpec         *pspec,
1702                                   GtkRcPropertyParser parser)
1703 {
1704   GSList *node, *next;
1705
1706   switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1707     {
1708     case G_TYPE_BOOLEAN:
1709     case G_TYPE_UCHAR:
1710     case G_TYPE_CHAR:
1711     case G_TYPE_UINT:
1712     case G_TYPE_INT:
1713     case G_TYPE_ULONG:
1714     case G_TYPE_LONG:
1715     case G_TYPE_FLOAT:
1716     case G_TYPE_DOUBLE:
1717     case G_TYPE_STRING:
1718     case G_TYPE_ENUM:
1719       break;
1720     case G_TYPE_BOXED:
1721       if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1722         {
1723           break;
1724         }
1725       /* fall through */
1726     default:
1727       if (!parser)
1728         {
1729           g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1730                      pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1731           return 0;
1732         }
1733     }
1734   if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1735     {
1736       g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1737                  pspec->name);
1738       return 0;
1739     }
1740   
1741   for (node = object_list; node; node = node->next)
1742     g_object_freeze_notify (node->data);
1743
1744   g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1745   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1746
1747   for (node = object_list; node; node = node->next)
1748     {
1749       GtkSettings *settings = node->data;
1750       GtkSettingsValuePrivate *qvalue;
1751       
1752       settings->property_values = g_renew (GtkSettingsPropertyValue, settings->property_values, class_n_properties);
1753       settings->property_values[class_n_properties - 1].value.g_type = 0;
1754       g_value_init (&settings->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1755       g_param_value_set_default (pspec, &settings->property_values[class_n_properties - 1].value);
1756       settings->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1757       g_object_notify (G_OBJECT (settings), pspec->name);
1758       
1759       qvalue = g_datalist_get_data (&settings->queued_settings, pspec->name);
1760       if (qvalue)
1761         apply_queued_setting (settings, pspec, qvalue);
1762     }
1763
1764   for (node = object_list; node; node = next)
1765     {
1766       next = node->next;
1767       g_object_thaw_notify (node->data);
1768     }
1769
1770   return class_n_properties;
1771 }
1772
1773 GtkRcPropertyParser
1774 _gtk_rc_property_parser_from_type (GType type)
1775 {
1776   if (type == GDK_TYPE_COLOR)
1777     return gtk_rc_property_parse_color;
1778   else if (type == GTK_TYPE_REQUISITION)
1779     return gtk_rc_property_parse_requisition;
1780   else if (type == GTK_TYPE_BORDER)
1781     return gtk_rc_property_parse_border;
1782   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1783     return gtk_rc_property_parse_enum;
1784   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1785     return gtk_rc_property_parse_flags;
1786   else
1787     return NULL;
1788 }
1789
1790 void
1791 gtk_settings_install_property (GParamSpec *pspec)
1792 {
1793   static GtkSettingsClass *klass = NULL;
1794
1795   GtkRcPropertyParser parser;
1796
1797   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1798
1799   if (! klass)
1800     klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1801
1802   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1803
1804   settings_install_property_parser (klass, pspec, parser);
1805 }
1806
1807 void
1808 gtk_settings_install_property_parser (GParamSpec          *pspec,
1809                                       GtkRcPropertyParser  parser)
1810 {
1811   static GtkSettingsClass *klass = NULL;
1812
1813   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1814   g_return_if_fail (parser != NULL);
1815
1816   if (! klass)
1817     klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1818
1819   settings_install_property_parser (klass, pspec, parser);
1820 }
1821
1822 static void
1823 free_value (gpointer data)
1824 {
1825   GtkSettingsValuePrivate *qvalue = data;
1826   
1827   g_value_unset (&qvalue->public.value);
1828   g_free (qvalue->public.origin);
1829   g_slice_free (GtkSettingsValuePrivate, qvalue);
1830 }
1831
1832 static void
1833 gtk_settings_set_property_value_internal (GtkSettings            *settings,
1834                                           const gchar            *prop_name,
1835                                           const GtkSettingsValue *new_value,
1836                                           GtkSettingsSource       source)
1837 {
1838   GtkSettingsValuePrivate *qvalue;
1839   GParamSpec *pspec;
1840   gchar *name;
1841   GQuark name_quark;
1842
1843   if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1844       !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1845       !G_VALUE_HOLDS_STRING (&new_value->value) &&
1846       !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1847     {
1848       g_warning (G_STRLOC ": value type invalid");
1849       return;
1850     }
1851   
1852   name = g_strdup (prop_name);
1853   g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1854   name_quark = g_quark_from_string (name);
1855   g_free (name);
1856
1857   qvalue = g_datalist_id_get_data (&settings->queued_settings, name_quark);
1858   if (!qvalue)
1859     {
1860       qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1861       g_datalist_id_set_data_full (&settings->queued_settings, name_quark, qvalue, free_value);
1862     }
1863   else
1864     {
1865       g_free (qvalue->public.origin);
1866       g_value_unset (&qvalue->public.value);
1867     }
1868   qvalue->public.origin = g_strdup (new_value->origin);
1869   g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1870   g_value_copy (&new_value->value, &qvalue->public.value);
1871   qvalue->source = source;
1872   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1873   if (pspec)
1874     apply_queued_setting (settings, pspec, qvalue);
1875 }
1876
1877 void
1878 gtk_settings_set_property_value (GtkSettings            *settings,
1879                                  const gchar            *prop_name,
1880                                  const GtkSettingsValue *new_value)
1881 {
1882   g_return_if_fail (GTK_SETTINGS (settings));
1883   g_return_if_fail (prop_name != NULL);
1884   g_return_if_fail (new_value != NULL);
1885
1886   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1887                                             GTK_SETTINGS_SOURCE_APPLICATION);
1888 }
1889
1890 void
1891 _gtk_settings_set_property_value_from_rc (GtkSettings            *settings,
1892                                           const gchar            *prop_name,
1893                                           const GtkSettingsValue *new_value)
1894 {
1895   g_return_if_fail (GTK_SETTINGS (settings));
1896   g_return_if_fail (prop_name != NULL);
1897   g_return_if_fail (new_value != NULL);
1898
1899   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1900                                             GTK_SETTINGS_SOURCE_RC_FILE);
1901 }
1902
1903 void
1904 gtk_settings_set_string_property (GtkSettings *settings,
1905                                   const gchar *name,
1906                                   const gchar *v_string,
1907                                   const gchar *origin)
1908 {
1909   GtkSettingsValue svalue = { NULL, { 0, }, };
1910
1911   g_return_if_fail (GTK_SETTINGS (settings));
1912   g_return_if_fail (name != NULL);
1913   g_return_if_fail (v_string != NULL);
1914
1915   svalue.origin = (gchar*) origin;
1916   g_value_init (&svalue.value, G_TYPE_STRING);
1917   g_value_set_static_string (&svalue.value, v_string);
1918   gtk_settings_set_property_value (settings, name, &svalue);
1919   g_value_unset (&svalue.value);
1920 }
1921
1922 void
1923 gtk_settings_set_long_property (GtkSettings *settings,
1924                                 const gchar *name,
1925                                 glong        v_long,
1926                                 const gchar *origin)
1927 {
1928   GtkSettingsValue svalue = { NULL, { 0, }, };
1929   
1930   g_return_if_fail (GTK_SETTINGS (settings));
1931   g_return_if_fail (name != NULL);
1932
1933   svalue.origin = (gchar*) origin;
1934   g_value_init (&svalue.value, G_TYPE_LONG);
1935   g_value_set_long (&svalue.value, v_long);
1936   gtk_settings_set_property_value (settings, name, &svalue);
1937   g_value_unset (&svalue.value);
1938 }
1939
1940 void
1941 gtk_settings_set_double_property (GtkSettings *settings,
1942                                   const gchar *name,
1943                                   gdouble      v_double,
1944                                   const gchar *origin)
1945 {
1946   GtkSettingsValue svalue = { NULL, { 0, }, };
1947
1948   g_return_if_fail (GTK_SETTINGS (settings));
1949   g_return_if_fail (name != NULL);
1950
1951   svalue.origin = (gchar*) origin;
1952   g_value_init (&svalue.value, G_TYPE_DOUBLE);
1953   g_value_set_double (&svalue.value, v_double);
1954   gtk_settings_set_property_value (settings, name, &svalue);
1955   g_value_unset (&svalue.value);
1956 }
1957
1958 /**
1959  * gtk_rc_property_parse_color:
1960  * @pspec: a #GParamSpec
1961  * @gstring: the #GString to be parsed
1962  * @property_value: a #GValue which must hold #GdkColor values.
1963  * 
1964  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1965  * or gtk_widget_class_install_style_property_parser() which parses a
1966  * color given either by its name or in the form 
1967  * <literal>{ red, green, blue }</literal> where %red, %green and
1968  * %blue are integers between 0 and 65535 or floating-point numbers
1969  * between 0 and 1.
1970  * 
1971  * Return value: %TRUE if @gstring could be parsed and @property_value
1972  * has been set to the resulting #GdkColor.
1973  **/
1974 gboolean
1975 gtk_rc_property_parse_color (const GParamSpec *pspec,
1976                              const GString    *gstring,
1977                              GValue           *property_value)
1978 {
1979   GdkColor color = { 0, 0, 0, 0, };
1980   GScanner *scanner;
1981   gboolean success;
1982
1983   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1984   g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
1985
1986   scanner = gtk_rc_scanner_new ();
1987   g_scanner_input_text (scanner, gstring->str, gstring->len);
1988   if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
1989       g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
1990     {
1991       g_value_set_boxed (property_value, &color);
1992       success = TRUE;
1993     }
1994   else
1995     success = FALSE;
1996   g_scanner_destroy (scanner);
1997
1998   return success;
1999 }
2000
2001 /**
2002  * gtk_rc_property_parse_enum:
2003  * @pspec: a #GParamSpec
2004  * @gstring: the #GString to be parsed
2005  * @property_value: a #GValue which must hold enum values.
2006  * 
2007  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2008  * or gtk_widget_class_install_style_property_parser() which parses a single
2009  * enumeration value.
2010  *
2011  * The enumeration value can be specified by its name, its nickname or
2012  * its numeric value. For consistency with flags parsing, the value
2013  * may be surrounded by parentheses.
2014  * 
2015  * Return value: %TRUE if @gstring could be parsed and @property_value
2016  * has been set to the resulting #GEnumValue.
2017  **/
2018 gboolean
2019 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2020                             const GString    *gstring,
2021                             GValue           *property_value)
2022 {
2023   gboolean need_closing_brace = FALSE, success = FALSE;
2024   GScanner *scanner;
2025   GEnumValue *enum_value = NULL;
2026
2027   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2028   g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2029
2030   scanner = gtk_rc_scanner_new ();
2031   g_scanner_input_text (scanner, gstring->str, gstring->len);
2032
2033   /* we just want to parse _one_ value, but for consistency with flags parsing
2034    * we support optional parenthesis
2035    */
2036   g_scanner_get_next_token (scanner);
2037   if (scanner->token == '(')
2038     {
2039       need_closing_brace = TRUE;
2040       g_scanner_get_next_token (scanner);
2041     }
2042   if (scanner->token == G_TOKEN_IDENTIFIER)
2043     {
2044       GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2045       
2046       enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2047       if (!enum_value)
2048         enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2049       if (enum_value)
2050         {
2051           g_value_set_enum (property_value, enum_value->value);
2052           success = TRUE;
2053         }
2054     }
2055   else if (scanner->token == G_TOKEN_INT)
2056     {
2057       g_value_set_enum (property_value, scanner->value.v_int);
2058       success = TRUE;
2059     }
2060   if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2061     success = FALSE;
2062   if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2063     success = FALSE;
2064
2065   g_scanner_destroy (scanner);
2066
2067   return success;
2068 }
2069
2070 static guint
2071 parse_flags_value (GScanner    *scanner,
2072                    GFlagsClass *class,
2073                    guint       *number)
2074 {
2075   g_scanner_get_next_token (scanner);
2076   if (scanner->token == G_TOKEN_IDENTIFIER)
2077     {
2078       GFlagsValue *flags_value;
2079
2080       flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2081       if (!flags_value)
2082         flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2083       if (flags_value)
2084         {
2085           *number |= flags_value->value;
2086           return G_TOKEN_NONE;
2087         }
2088     }
2089   else if (scanner->token == G_TOKEN_INT)
2090     {
2091       *number |= scanner->value.v_int;
2092       return G_TOKEN_NONE;
2093     }
2094   return G_TOKEN_IDENTIFIER;
2095 }
2096
2097 /**
2098  * gtk_rc_property_parse_flags:
2099  * @pspec: a #GParamSpec
2100  * @gstring: the #GString to be parsed
2101  * @property_value: a #GValue which must hold flags values.
2102  * 
2103  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2104  * or gtk_widget_class_install_style_property_parser() which parses flags. 
2105  * 
2106  * Flags can be specified by their name, their nickname or
2107  * numerically. Multiple flags can be specified in the form 
2108  * <literal>"( flag1 | flag2 | ... )"</literal>.
2109  * 
2110  * Return value: %TRUE if @gstring could be parsed and @property_value
2111  * has been set to the resulting flags value.
2112  **/
2113 gboolean
2114 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2115                              const GString    *gstring,
2116                              GValue           *property_value)
2117 {
2118   GFlagsClass *class;
2119    gboolean success = FALSE;
2120   GScanner *scanner;
2121
2122   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2123   g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2124
2125   class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2126   scanner = gtk_rc_scanner_new ();
2127   g_scanner_input_text (scanner, gstring->str, gstring->len);
2128
2129   /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2130   if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2131       scanner->next_token == G_TOKEN_INT)
2132     {
2133       guint token, flags_value = 0;
2134       
2135       token = parse_flags_value (scanner, class, &flags_value);
2136
2137       if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2138         {
2139           success = TRUE;
2140           g_value_set_flags (property_value, flags_value);
2141         }
2142       
2143     }
2144   else if (g_scanner_get_next_token (scanner) == '(')
2145     {
2146       guint token, flags_value = 0;
2147
2148       /* parse first value */
2149       token = parse_flags_value (scanner, class, &flags_value);
2150
2151       /* parse nth values, preceeded by '|' */
2152       while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2153         token = parse_flags_value (scanner, class, &flags_value);
2154
2155       /* done, last token must have closed expression */
2156       if (token == G_TOKEN_NONE && scanner->token == ')' &&
2157           g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2158         {
2159           g_value_set_flags (property_value, flags_value);
2160           success = TRUE;
2161         }
2162     }
2163   g_scanner_destroy (scanner);
2164
2165   return success;
2166 }
2167
2168 static gboolean
2169 get_braced_int (GScanner *scanner,
2170                 gboolean  first,
2171                 gboolean  last,
2172                 gint     *value)
2173 {
2174   if (first)
2175     {
2176       g_scanner_get_next_token (scanner);
2177       if (scanner->token != '{')
2178         return FALSE;
2179     }
2180
2181   g_scanner_get_next_token (scanner);
2182   if (scanner->token != G_TOKEN_INT)
2183     return FALSE;
2184
2185   *value = scanner->value.v_int;
2186
2187   if (last)
2188     {
2189       g_scanner_get_next_token (scanner);
2190       if (scanner->token != '}')
2191         return FALSE;
2192     }
2193   else
2194     {
2195       g_scanner_get_next_token (scanner);
2196       if (scanner->token != ',')
2197         return FALSE;
2198     }
2199
2200   return TRUE;
2201 }
2202
2203 /**
2204  * gtk_rc_property_parse_requisition:
2205  * @pspec: a #GParamSpec
2206  * @gstring: the #GString to be parsed
2207  * @property_value: a #GValue which must hold boxed values.
2208  * 
2209  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2210  * or gtk_widget_class_install_style_property_parser() which parses a
2211  * requisition in the form 
2212  * <literal>"{ width, height }"</literal> for integers %width and %height.
2213  * 
2214  * Return value: %TRUE if @gstring could be parsed and @property_value
2215  * has been set to the resulting #GtkRequisition.
2216  **/
2217 gboolean
2218 gtk_rc_property_parse_requisition  (const GParamSpec *pspec,
2219                                     const GString    *gstring,
2220                                     GValue           *property_value)
2221 {
2222   GtkRequisition requisition;
2223   GScanner *scanner;
2224   gboolean success = FALSE;
2225
2226   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2227   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2228
2229   scanner = gtk_rc_scanner_new ();
2230   g_scanner_input_text (scanner, gstring->str, gstring->len);
2231
2232   if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2233       get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2234     {
2235       g_value_set_boxed (property_value, &requisition);
2236       success = TRUE;
2237     }
2238
2239   g_scanner_destroy (scanner);
2240
2241   return success;
2242 }
2243
2244 /**
2245  * gtk_rc_property_parse_border:
2246  * @pspec: a #GParamSpec
2247  * @gstring: the #GString to be parsed
2248  * @property_value: a #GValue which must hold boxed values.
2249  * 
2250  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2251  * or gtk_widget_class_install_style_property_parser() which parses
2252  * borders in the form 
2253  * <literal>"{ left, right, top, bottom }"</literal> for integers 
2254  * %left, %right, %top and %bottom.
2255  * 
2256  * Return value: %TRUE if @gstring could be parsed and @property_value
2257  * has been set to the resulting #GtkBorder.
2258  **/
2259 gboolean
2260 gtk_rc_property_parse_border (const GParamSpec *pspec,
2261                               const GString    *gstring,
2262                               GValue           *property_value)
2263 {
2264   GtkBorder border;
2265   GScanner *scanner;
2266   gboolean success = FALSE;
2267   int left, right, top, bottom;
2268
2269   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2270   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2271
2272   scanner = gtk_rc_scanner_new ();
2273   g_scanner_input_text (scanner, gstring->str, gstring->len);
2274
2275   if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2276       get_braced_int (scanner, FALSE, FALSE, &right) &&
2277       get_braced_int (scanner, FALSE, FALSE, &top) &&
2278       get_braced_int (scanner, FALSE, TRUE, &bottom))
2279     {
2280       border.left = left;
2281       border.right = right;
2282       border.top = top;
2283       border.bottom = bottom;
2284       g_value_set_boxed (property_value, &border);
2285       success = TRUE;
2286     }
2287
2288   g_scanner_destroy (scanner);
2289
2290   return success;
2291 }
2292
2293 void
2294 _gtk_settings_handle_event (GdkEventSetting *event)
2295 {
2296   GtkSettings *settings;
2297   GParamSpec *pspec;
2298   guint property_id;
2299
2300   settings = gtk_settings_get_for_screen (gdk_window_get_screen (event->window));
2301   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2302  
2303   if (pspec) 
2304     {
2305       property_id = pspec->param_id;
2306
2307       if (property_id == PROP_COLOR_SCHEME)
2308         {
2309           GValue value = { 0, };
2310  
2311           g_value_init (&value, G_TYPE_STRING);
2312           if (!gdk_screen_get_setting (settings->screen, pspec->name, &value))
2313             g_value_set_static_string (&value, "");
2314           merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2315           g_value_unset (&value);
2316         }
2317       g_object_notify (G_OBJECT (settings), pspec->name);
2318    }
2319 }
2320
2321 static void
2322 reset_rc_values_foreach (GQuark    key_id,
2323                          gpointer  data,
2324                          gpointer  user_data)
2325 {
2326   GtkSettingsValuePrivate *qvalue = data;
2327   GSList **to_reset = user_data;
2328
2329   if (qvalue->source == GTK_SETTINGS_SOURCE_RC_FILE)
2330     *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2331 }
2332
2333 void
2334 _gtk_settings_reset_rc_values (GtkSettings *settings)
2335 {
2336   GSList *to_reset = NULL;
2337   GSList *tmp_list;
2338   GParamSpec **pspecs, **p;
2339   gint i;
2340
2341   /* Remove any queued settings
2342    */
2343   g_datalist_foreach (&settings->queued_settings,
2344                       reset_rc_values_foreach,
2345                       &to_reset);
2346
2347   for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2348     {
2349       GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2350       g_datalist_id_remove_data (&settings->queued_settings, key_id);
2351     }
2352
2353    g_slist_free (to_reset);
2354
2355   /* Now reset the active settings
2356    */
2357   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2358   i = 0;
2359
2360   g_object_freeze_notify (G_OBJECT (settings));
2361   for (p = pspecs; *p; p++)
2362     {
2363       if (settings->property_values[i].source == GTK_SETTINGS_SOURCE_RC_FILE)
2364         {
2365           GParamSpec *pspec = *p;
2366
2367           g_param_value_set_default (pspec, &settings->property_values[i].value);
2368           g_object_notify (G_OBJECT (settings), pspec->name);
2369         }
2370       i++;
2371     }
2372   g_object_thaw_notify (G_OBJECT (settings));
2373   g_free (pspecs);
2374 }
2375
2376 static void
2377 settings_update_double_click (GtkSettings *settings)
2378 {
2379   if (gdk_screen_get_number (settings->screen) == 0)
2380     {
2381       GdkDisplay *display = gdk_screen_get_display (settings->screen);
2382       gint double_click_time;
2383       gint double_click_distance;
2384   
2385       g_object_get (settings, 
2386                     "gtk-double-click-time", &double_click_time, 
2387                     "gtk-double-click-distance", &double_click_distance,
2388                     NULL);
2389       
2390       gdk_display_set_double_click_time (display, double_click_time);
2391       gdk_display_set_double_click_distance (display, double_click_distance);
2392     }
2393 }
2394
2395 static void
2396 settings_update_modules (GtkSettings *settings)
2397 {
2398   gchar *modules;
2399   
2400   g_object_get (settings, 
2401                 "gtk-modules", &modules,
2402                 NULL);
2403   
2404   _gtk_modules_settings_changed (settings, modules);
2405   
2406   g_free (modules);
2407 }
2408
2409 #ifdef GDK_WINDOWING_X11
2410 static void
2411 settings_update_cursor_theme (GtkSettings *settings)
2412 {
2413   GdkDisplay *display = gdk_screen_get_display (settings->screen);
2414   gchar *theme = NULL;
2415   gint size = 0;
2416   
2417   g_object_get (settings, 
2418                 "gtk-cursor-theme-name", &theme,
2419                 "gtk-cursor-theme-size", &size,
2420                 NULL);
2421   
2422   gdk_x11_display_set_cursor_theme (display, theme, size);
2423
2424   g_free (theme);
2425 }
2426
2427 static void
2428 settings_update_font_options (GtkSettings *settings)
2429 {
2430   gint hinting;
2431   gchar *hint_style_str;
2432   cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2433   gint antialias;
2434   cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2435   gchar *rgba_str;
2436   cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2437   cairo_font_options_t *options;
2438   
2439   g_object_get (settings,
2440                 "gtk-xft-antialias", &antialias,
2441                 "gtk-xft-hinting", &hinting,
2442                 "gtk-xft-hintstyle", &hint_style_str,
2443                 "gtk-xft-rgba", &rgba_str,
2444                 NULL);
2445
2446   options = cairo_font_options_create ();
2447
2448   cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2449   
2450   if (hinting >= 0 && !hinting)
2451     {
2452       hint_style = CAIRO_HINT_STYLE_NONE;
2453     }
2454   else if (hint_style_str)
2455     {
2456       if (strcmp (hint_style_str, "hintnone") == 0)
2457         hint_style = CAIRO_HINT_STYLE_NONE;
2458       else if (strcmp (hint_style_str, "hintslight") == 0)
2459         hint_style = CAIRO_HINT_STYLE_SLIGHT;
2460       else if (strcmp (hint_style_str, "hintmedium") == 0)
2461         hint_style = CAIRO_HINT_STYLE_MEDIUM;
2462       else if (strcmp (hint_style_str, "hintfull") == 0)
2463         hint_style = CAIRO_HINT_STYLE_FULL;
2464     }
2465
2466   g_free (hint_style_str);
2467
2468   cairo_font_options_set_hint_style (options, hint_style);
2469
2470   if (rgba_str)
2471     {
2472       if (strcmp (rgba_str, "rgb") == 0)
2473         subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2474       else if (strcmp (rgba_str, "bgr") == 0)
2475         subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2476       else if (strcmp (rgba_str, "vrgb") == 0)
2477         subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2478       else if (strcmp (rgba_str, "vbgr") == 0)
2479         subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2480
2481       g_free (rgba_str);
2482     }
2483
2484   cairo_font_options_set_subpixel_order (options, subpixel_order);
2485   
2486   if (antialias >= 0 && !antialias)
2487     antialias_mode = CAIRO_ANTIALIAS_NONE;
2488   else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2489     antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2490   else if (antialias >= 0)
2491     antialias_mode = CAIRO_ANTIALIAS_GRAY;
2492   
2493   cairo_font_options_set_antialias (options, antialias_mode);
2494
2495   gdk_screen_set_font_options (settings->screen, options);
2496   
2497   cairo_font_options_destroy (options);
2498 }
2499
2500 #ifdef GDK_WINDOWING_X11
2501 static gboolean
2502 settings_update_fontconfig (GtkSettings *settings)
2503 {
2504   static guint    last_update_timestamp;
2505   static gboolean last_update_needed;
2506
2507   guint timestamp;
2508
2509   g_object_get (settings,
2510                 "gtk-fontconfig-timestamp", &timestamp,
2511                 NULL);
2512
2513   /* if timestamp is the same as last_update_timestamp, we already have
2514    * updated fontconig on this timestamp (another screen requested it perhaps?),
2515    * just return the cached result.*/
2516
2517   if (timestamp != last_update_timestamp)
2518     {
2519       PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2520       gboolean update_needed = FALSE;
2521
2522       /* bug 547680 */
2523       if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2524         {
2525           pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2526           if (FcInitReinitialize ())
2527             update_needed = TRUE;
2528         }
2529
2530       last_update_timestamp = timestamp;
2531       last_update_needed = update_needed;
2532     }
2533
2534   return last_update_needed;
2535 }
2536 #endif /* GDK_WINDOWING_X11 */
2537
2538 static void
2539 settings_update_resolution (GtkSettings *settings)
2540 {
2541   gint dpi_int;
2542   double dpi;
2543   
2544   g_object_get (settings,
2545                 "gtk-xft-dpi", &dpi_int,
2546                 NULL);
2547
2548   if (dpi_int > 0)
2549     dpi = dpi_int / 1024.;
2550   else
2551     dpi = -1.;
2552
2553   gdk_screen_set_resolution (settings->screen, dpi);
2554 }
2555 #endif
2556
2557 typedef struct {
2558   GHashTable *color_hash;
2559   GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2560   gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2561 } ColorSchemeData;
2562
2563 static void
2564 color_scheme_data_free (ColorSchemeData *data)
2565 {
2566   gint i;
2567
2568   g_hash_table_unref (data->color_hash);
2569
2570   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2571     {
2572       if (data->tables[i])
2573         g_hash_table_unref (data->tables[i]);
2574       g_free (data->lastentry[i]);
2575     }
2576
2577   g_slice_free (ColorSchemeData, data);
2578 }
2579
2580 static void
2581 settings_update_color_scheme (GtkSettings *settings)
2582 {
2583   if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2584     {
2585       ColorSchemeData *data;
2586       GValue value = { 0, };
2587
2588       data = g_slice_new0 (ColorSchemeData);
2589       data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2590                                                 (GDestroyNotify) gdk_color_free);
2591       g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2592                               data, (GDestroyNotify) color_scheme_data_free); 
2593
2594       g_value_init (&value, G_TYPE_STRING);
2595       if (gdk_screen_get_setting (settings->screen, "gtk-color-scheme", &value))
2596         {
2597           merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2598           g_value_unset (&value);
2599         }
2600    }
2601 }
2602
2603 static void
2604 settings_update_theme (GtkSettings *settings)
2605 {
2606   static GQuark quark_theme_name = 0;
2607   GtkCssProvider *provider, *new_provider = NULL;
2608   gboolean prefer_dark_theme;
2609   gchar *theme_name;
2610
2611   if (G_UNLIKELY (!quark_theme_name))
2612     quark_theme_name = g_quark_from_static_string ("gtk-settings-theme-name");
2613
2614   provider = g_object_get_qdata (G_OBJECT (settings), quark_theme_name);
2615
2616   g_object_get (settings,
2617                 "gtk-theme-name", &theme_name,
2618                 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2619                 NULL);
2620
2621   if (theme_name && *theme_name)
2622     {
2623       gchar *variant = NULL;
2624
2625       if (prefer_dark_theme)
2626         variant = "dark";
2627
2628       new_provider = gtk_css_provider_get_named (theme_name, variant);
2629       g_free (theme_name);
2630     }
2631
2632   if (new_provider != provider)
2633     {
2634       if (provider)
2635         gtk_style_context_remove_provider_for_screen (settings->screen,
2636                                                       GTK_STYLE_PROVIDER (provider));
2637
2638       if (new_provider)
2639         {
2640           gtk_style_context_add_provider_for_screen (settings->screen,
2641                                                      GTK_STYLE_PROVIDER (new_provider),
2642                                                      GTK_STYLE_PROVIDER_PRIORITY_THEME);
2643           g_object_ref (new_provider);
2644         }
2645
2646       g_object_set_qdata_full (G_OBJECT (settings), quark_theme_name,
2647                                new_provider, (GDestroyNotify) g_object_unref);
2648     }
2649 }
2650
2651 static gboolean
2652 add_color_to_hash (gchar      *name,
2653                    GdkColor   *color,
2654                    GHashTable *target)
2655 {
2656   GdkColor *old;
2657
2658   old = g_hash_table_lookup (target, name);
2659   if (!old || !gdk_color_equal (old, color))
2660     {
2661       g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2662
2663       return TRUE;
2664     }
2665
2666   return FALSE;
2667 }
2668
2669 static gboolean
2670 add_colors_to_hash_from_string (GHashTable  *hash,
2671                                 const gchar *colors)
2672 {
2673   gchar *s, *p, *name;
2674   GdkColor color;
2675   gboolean changed = FALSE;
2676   gchar *copy;
2677
2678   copy = g_strdup (colors);
2679   s = copy;
2680   while (s && *s)
2681     {
2682       name = s;
2683       p = strchr (s, ':');
2684       if (p)
2685         {
2686           *p = '\0';
2687           p++;
2688         }
2689       else
2690         break;
2691
2692       while (*p == ' ')
2693         p++;
2694
2695       s = p;
2696       while (*s) 
2697         {
2698           if (*s == '\n' || *s == ';')
2699             {
2700               *s = '\0';
2701               s++;
2702               break;
2703             }
2704           s++;
2705         }
2706
2707       if (gdk_color_parse (p, &color))
2708         changed |= add_color_to_hash (name, &color, hash);
2709     }
2710
2711   g_free (copy);
2712
2713   return changed;
2714 }
2715
2716 static gboolean
2717 update_color_hash (ColorSchemeData   *data,
2718                    const gchar       *str,
2719                    GtkSettingsSource  source)
2720 {
2721   gboolean changed = FALSE;
2722   gint i;
2723   GHashTable *old_hash;
2724   GHashTableIter iter;
2725   gpointer name;
2726   gpointer color;
2727
2728   if ((str == NULL || *str == '\0') &&
2729       (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2730     return FALSE;
2731
2732   if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2733     return FALSE;
2734
2735   /* For the RC_FILE source we merge the values rather than over-writing
2736    * them, since multiple rc files might define independent sets of colors
2737    */
2738   if ((source != GTK_SETTINGS_SOURCE_RC_FILE) &&
2739       data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2740     {
2741       g_hash_table_unref (data->tables[source]);
2742       data->tables[source] = NULL;
2743       changed = TRUE; /* We can't rely on the code below since str might be "" */
2744     }
2745
2746   if (data->tables[source] == NULL)
2747     data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2748                                                   g_free,
2749                                                   (GDestroyNotify) gdk_color_free);
2750
2751   g_free (data->lastentry[source]);
2752   data->lastentry[source] = g_strdup (str);
2753
2754   changed |= add_colors_to_hash_from_string (data->tables[source], str);
2755
2756   if (!changed)
2757     return FALSE;
2758
2759   /* Rebuild the merged hash table. */
2760   if (data->color_hash)
2761     {
2762       old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2763                                         (GDestroyNotify) gdk_color_free);
2764
2765       g_hash_table_iter_init (&iter, data->color_hash);
2766       while (g_hash_table_iter_next (&iter, &name, &color))
2767         {
2768           g_hash_table_insert (old_hash, name, color);
2769           g_hash_table_iter_steal (&iter);
2770         }
2771     }
2772   else
2773     {
2774       old_hash = NULL;
2775     }
2776
2777   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2778     {
2779       if (data->tables[i])
2780         g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2781                               data->color_hash);
2782     }
2783
2784   if (old_hash)
2785     {
2786       /* now check if the merged hash has changed */
2787       changed = FALSE;
2788       if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2789         changed = TRUE;
2790       else
2791         {
2792           GHashTableIter iter;
2793           gpointer key, value, new_value;
2794
2795           g_hash_table_iter_init (&iter, old_hash);
2796           while (g_hash_table_iter_next (&iter, &key, &value))
2797             {
2798               new_value = g_hash_table_lookup (data->color_hash, key);
2799               if (!new_value || !gdk_color_equal (value, new_value))
2800                 {
2801                   changed = TRUE;
2802                   break;
2803                 }
2804             }
2805         }
2806
2807       g_hash_table_unref (old_hash);
2808     }
2809   else
2810     changed = TRUE;
2811
2812   return changed;
2813 }
2814
2815 static void
2816 merge_color_scheme (GtkSettings       *settings, 
2817                     const GValue      *value, 
2818                     GtkSettingsSource  source)
2819 {
2820   ColorSchemeData *data;
2821   const gchar *colors;
2822
2823   g_object_freeze_notify (G_OBJECT (settings));
2824
2825   colors = g_value_get_string (value);
2826
2827   settings_update_color_scheme (settings);
2828
2829   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2830                                                 "gtk-color-scheme");
2831   
2832   if (update_color_hash (data, colors, source))
2833     g_object_notify (G_OBJECT (settings), "color-hash");
2834
2835   g_object_thaw_notify (G_OBJECT (settings));
2836 }
2837
2838 static GHashTable *
2839 get_color_hash (GtkSettings *settings)
2840 {
2841   ColorSchemeData *data;
2842
2843   settings_update_color_scheme (settings);
2844   
2845   data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings), 
2846                                                "gtk-color-scheme");
2847
2848   return data->color_hash;
2849 }
2850
2851 static void 
2852 append_color_scheme (gpointer key,
2853                      gpointer value,
2854                      gpointer data)
2855 {
2856   gchar *name = (gchar *)key;
2857   GdkColor *color = (GdkColor *)value;
2858   GString *string = (GString *)data;
2859
2860   g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2861                           name, color->red, color->green, color->blue);
2862 }
2863
2864 static gchar *
2865 get_color_scheme (GtkSettings *settings)
2866 {
2867   ColorSchemeData *data;
2868   GString *string;
2869   
2870   settings_update_color_scheme (settings);
2871
2872   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2873                                                 "gtk-color-scheme");
2874
2875   string = g_string_new ("");
2876
2877   g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2878
2879   return g_string_free (string, FALSE);
2880 }
2881
2882 GdkScreen *
2883 _gtk_settings_get_screen (GtkSettings *settings)
2884 {
2885   return settings->screen;
2886 }