]> Pileus Git - ~andy/gtk/blob - gtk/gtksettings.c
GtkSettings: Ensure the theme CSS is loaded on startup.
[~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 "gtkversion.h"
35
36 #ifdef GDK_WINDOWING_X11
37 #include "x11/gdkx.h"
38 #include <pango/pangofc-fontmap.h>
39 #endif
40
41
42 /**
43  * SECTION:gtksettings
44  * @Short_description: Sharing settings between applications
45  * @Title: Settings
46  *
47  * GtkSettings provide a mechanism to share global settings between applications.
48  * On the X window system, this sharing is realized by an
49  * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
50  * manager that is usually part of the desktop environment, along with utilities
51  * that let the user change these settings. In the absence of an Xsettings manager,
52  * settings can also be specified in RC files.
53  *
54  * Applications can override system-wide settings with gtk_settings_set_string_property(),
55  * gtk_settings_set_long_property(), etc. This should be restricted to special
56  * cases though; GtkSettings are not meant as an application configuration
57  * facility. When doing so, you need to be aware that settings that are specific
58  * to individual widgets may not be available before the widget type has been
59  * realized at least once. The following example demonstrates a way to do this:
60  * <informalexample><programlisting>
61  *   gtk_init (&argc, &argv);
62  *
63  *   /&ast; make sure the type is realized &ast;/
64  *   g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
65  *
66  *   g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
67  * </programlisting></informalexample>
68  *
69  * There is one GtkSettings instance per screen. It can be obtained with
70  * gtk_settings_get_for_screen(), but in many cases, it is more convenient
71  * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
72  * GtkSettings instance for the default screen.
73  */
74
75
76 #ifdef GDK_WINDOWING_QUARTZ
77 #define DEFAULT_KEY_THEME "Mac"
78 #else
79 #define DEFAULT_KEY_THEME NULL
80 #endif
81
82 #define DEFAULT_TIMEOUT_INITIAL 200
83 #define DEFAULT_TIMEOUT_REPEAT   20
84 #define DEFAULT_TIMEOUT_EXPAND  500
85
86 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
87
88 typedef enum
89 {
90   GTK_SETTINGS_SOURCE_DEFAULT,
91   GTK_SETTINGS_SOURCE_RC_FILE,
92   GTK_SETTINGS_SOURCE_XSETTING,
93   GTK_SETTINGS_SOURCE_APPLICATION
94 } GtkSettingsSource;
95
96 struct _GtkSettingsValuePrivate
97 {
98   GtkSettingsValue public;
99   GtkSettingsSource source;
100 };
101
102 struct _GtkSettingsPropertyValue
103 {
104   GValue value;
105   GtkSettingsSource source;
106 };
107
108 enum {
109   PROP_0,
110   PROP_DOUBLE_CLICK_TIME,
111   PROP_DOUBLE_CLICK_DISTANCE,
112   PROP_CURSOR_BLINK,
113   PROP_CURSOR_BLINK_TIME,
114   PROP_CURSOR_BLINK_TIMEOUT,
115   PROP_SPLIT_CURSOR,
116   PROP_THEME_NAME,
117   PROP_ICON_THEME_NAME,
118   PROP_FALLBACK_ICON_THEME,
119   PROP_KEY_THEME_NAME,
120   PROP_MENU_BAR_ACCEL,
121   PROP_DND_DRAG_THRESHOLD,
122   PROP_FONT_NAME,
123   PROP_ICON_SIZES,
124   PROP_MODULES,
125 #ifdef GDK_WINDOWING_X11
126   PROP_XFT_ANTIALIAS,
127   PROP_XFT_HINTING,
128   PROP_XFT_HINTSTYLE,
129   PROP_XFT_RGBA,
130   PROP_XFT_DPI,
131   PROP_CURSOR_THEME_NAME,
132   PROP_CURSOR_THEME_SIZE,
133 #endif
134   PROP_ALTERNATIVE_BUTTON_ORDER,
135   PROP_ALTERNATIVE_SORT_ARROWS,
136   PROP_SHOW_INPUT_METHOD_MENU,
137   PROP_SHOW_UNICODE_MENU,
138   PROP_TIMEOUT_INITIAL,
139   PROP_TIMEOUT_REPEAT,
140   PROP_TIMEOUT_EXPAND,
141   PROP_COLOR_SCHEME,
142   PROP_ENABLE_ANIMATIONS,
143   PROP_TOUCHSCREEN_MODE,
144   PROP_TOOLTIP_TIMEOUT,
145   PROP_TOOLTIP_BROWSE_TIMEOUT,
146   PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
147   PROP_KEYNAV_CURSOR_ONLY,
148   PROP_KEYNAV_WRAP_AROUND,
149   PROP_ERROR_BELL,
150   PROP_COLOR_HASH,
151   PROP_FILE_CHOOSER_BACKEND,
152   PROP_PRINT_BACKENDS,
153   PROP_PRINT_PREVIEW_COMMAND,
154   PROP_ENABLE_MNEMONICS,
155   PROP_ENABLE_ACCELS,
156   PROP_RECENT_FILES_LIMIT,
157   PROP_IM_MODULE,
158   PROP_RECENT_FILES_MAX_AGE,
159   PROP_FONTCONFIG_TIMESTAMP,
160   PROP_SOUND_THEME_NAME,
161   PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
162   PROP_ENABLE_EVENT_SOUNDS,
163   PROP_ENABLE_TOOLTIPS,
164   PROP_TOOLBAR_STYLE,
165   PROP_TOOLBAR_ICON_SIZE,
166   PROP_AUTO_MNEMONICS,
167   PROP_APPLICATION_PREFER_DARK_THEME,
168   PROP_BUTTON_IMAGES,
169   PROP_ENTRY_SELECT_ON_FOCUS,
170   PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
171   PROP_MENU_IMAGES,
172   PROP_MENU_BAR_POPUP_DELAY,
173   PROP_SCROLLED_WINDOW_PLACEMENT,
174   PROP_CAN_CHANGE_ACCELS,
175   PROP_MENU_POPUP_DELAY,
176   PROP_MENU_POPDOWN_DELAY,
177   PROP_LABEL_SELECT_ON_FOCUS,
178   PROP_COLOR_PALETTE,
179   PROP_IM_PREEDIT_STYLE,
180   PROP_IM_STATUS_STYLE
181 };
182
183 /* --- prototypes --- */
184 static void     gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
185
186 static void     gtk_settings_finalize            (GObject               *object);
187 static void     gtk_settings_get_property        (GObject               *object,
188                                                   guint                  property_id,
189                                                   GValue                *value,
190                                                   GParamSpec            *pspec);
191 static void     gtk_settings_set_property        (GObject               *object,
192                                                   guint                  property_id,
193                                                   const GValue          *value,
194                                                   GParamSpec            *pspec);
195 static void     gtk_settings_notify              (GObject               *object,
196                                                   GParamSpec            *pspec);
197 static guint    settings_install_property_parser (GtkSettingsClass      *class,
198                                                   GParamSpec            *pspec,
199                                                   GtkRcPropertyParser    parser);
200 static void    settings_update_double_click      (GtkSettings           *settings);
201 static void    settings_update_modules           (GtkSettings           *settings);
202
203 #ifdef GDK_WINDOWING_X11
204 static void    settings_update_cursor_theme      (GtkSettings           *settings);
205 static void    settings_update_resolution        (GtkSettings           *settings);
206 static void    settings_update_font_options      (GtkSettings           *settings);
207 static gboolean settings_update_fontconfig       (GtkSettings           *settings);
208 #endif
209 static void    settings_update_color_scheme      (GtkSettings *settings);
210 static void    settings_update_theme             (GtkSettings *settings);
211
212 static void    merge_color_scheme                (GtkSettings           *settings, 
213                                                   const GValue          *value, 
214                                                   GtkSettingsSource      source);
215 static gchar  *get_color_scheme                  (GtkSettings           *settings);
216 static GHashTable *get_color_hash                (GtkSettings           *settings);
217
218 /* the default palette for GtkColorSelelection */
219 static const gchar default_color_palette[] =
220   "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
221   "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
222
223 /* --- variables --- */
224 static GQuark            quark_property_parser = 0;
225 static GSList           *object_list = NULL;
226 static guint             class_n_properties = 0;
227
228
229 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
230                         G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
231                                                gtk_settings_provider_iface_init));
232
233 /* --- functions --- */
234 static void
235 gtk_settings_init (GtkSettings *settings)
236 {
237   GParamSpec **pspecs, **p;
238   guint i = 0;
239   
240   g_datalist_init (&settings->queued_settings);
241   object_list = g_slist_prepend (object_list, settings);
242
243   /* build up property array for all yet existing properties and queue
244    * notification for them (at least notification for internal properties
245    * will instantly be caught)
246    */
247   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
248   for (p = pspecs; *p; p++)
249     if ((*p)->owner_type == G_OBJECT_TYPE (settings))
250       i++;
251   settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
252   i = 0;
253   g_object_freeze_notify (G_OBJECT (settings));
254   for (p = pspecs; *p; p++)
255     {
256       GParamSpec *pspec = *p;
257
258       if (pspec->owner_type != G_OBJECT_TYPE (settings))
259         continue;
260       g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
261       g_param_value_set_default (pspec, &settings->property_values[i].value);
262       g_object_notify (G_OBJECT (settings), pspec->name);
263       settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
264       i++;
265     }
266   g_object_thaw_notify (G_OBJECT (settings));
267   g_free (pspecs);
268 }
269
270 static void
271 gtk_settings_class_init (GtkSettingsClass *class)
272 {
273   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
274   guint result;
275   
276   gobject_class->finalize = gtk_settings_finalize;
277   gobject_class->get_property = gtk_settings_get_property;
278   gobject_class->set_property = gtk_settings_set_property;
279   gobject_class->notify = gtk_settings_notify;
280
281   quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
282   result = settings_install_property_parser (class,
283                                              g_param_spec_int ("gtk-double-click-time",
284                                                                P_("Double Click Time"),
285                                                                P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
286                                                                0, G_MAXINT, 250,
287                                                                GTK_PARAM_READWRITE),
288                                              NULL);
289   g_assert (result == PROP_DOUBLE_CLICK_TIME);
290   result = settings_install_property_parser (class,
291                                              g_param_spec_int ("gtk-double-click-distance",
292                                                                P_("Double Click Distance"),
293                                                                P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
294                                                                0, G_MAXINT, 5,
295                                                                GTK_PARAM_READWRITE),
296                                              NULL);
297   g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
298
299   /**
300    * GtkSettings:gtk-cursor-blink:
301    *
302    * Whether the cursor should blink. 
303    *
304    * Also see the #GtkSettings:gtk-cursor-blink-timeout setting, 
305    * which allows more flexible control over cursor blinking.
306    */
307   result = settings_install_property_parser (class,
308                                              g_param_spec_boolean ("gtk-cursor-blink",
309                                                                    P_("Cursor Blink"),
310                                                                    P_("Whether the cursor should blink"),
311                                                                    TRUE,
312                                                                    GTK_PARAM_READWRITE),
313                                              NULL);
314   g_assert (result == PROP_CURSOR_BLINK);
315   result = settings_install_property_parser (class,
316                                              g_param_spec_int ("gtk-cursor-blink-time",
317                                                                P_("Cursor Blink Time"),
318                                                                P_("Length of the cursor blink cycle, in milliseconds"),
319                                                                100, G_MAXINT, 1200,
320                                                                GTK_PARAM_READWRITE),
321                                              NULL);
322   g_assert (result == PROP_CURSOR_BLINK_TIME);
323  
324   /**
325    * GtkSettings:gtk-cursor-blink-timeout:
326    *
327    * Time after which the cursor stops blinking, in seconds.
328    * The timer is reset after each user interaction.
329    *
330    * Setting this to zero has the same effect as setting
331    * #GtkSettings:gtk-cursor-blink to %FALSE. 
332    *
333    * Since: 2.12
334    */
335   result = settings_install_property_parser (class,
336                                              g_param_spec_int ("gtk-cursor-blink-timeout",
337                                                                P_("Cursor Blink Timeout"),
338                                                                P_("Time after which the cursor stops blinking, in seconds"),
339                                                                1, G_MAXINT, G_MAXINT,
340                                                                GTK_PARAM_READWRITE),
341                                              NULL);
342   g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
343   result = settings_install_property_parser (class,
344                                              g_param_spec_boolean ("gtk-split-cursor",
345                                                                    P_("Split Cursor"),
346                                                                    P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
347                                                                    TRUE,
348                                                                    GTK_PARAM_READWRITE),
349                                              NULL);
350   g_assert (result == PROP_SPLIT_CURSOR);
351   result = settings_install_property_parser (class,
352                                              g_param_spec_string ("gtk-theme-name",
353                                                                    P_("Theme Name"),
354                                                                    P_("Name of theme RC file to load"),
355                                                                   "Raleigh",
356                                                                   GTK_PARAM_READWRITE),
357                                              NULL);
358   g_assert (result == PROP_THEME_NAME);
359
360   result = settings_install_property_parser (class,
361                                              g_param_spec_string ("gtk-icon-theme-name",
362                                                                   P_("Icon Theme Name"),
363                                                                   P_("Name of icon theme to use"),
364                                                                   "hicolor",
365                                                                   GTK_PARAM_READWRITE),
366                                              NULL);
367   g_assert (result == PROP_ICON_THEME_NAME);
368
369   result = settings_install_property_parser (class,
370                                              g_param_spec_string ("gtk-fallback-icon-theme",
371                                                                   P_("Fallback Icon Theme Name"),
372                                                                   P_("Name of a icon theme to fall back to"),
373                                                                   NULL,
374                                                                   GTK_PARAM_READWRITE),
375                                              NULL);
376   g_assert (result == PROP_FALLBACK_ICON_THEME);
377   
378   result = settings_install_property_parser (class,
379                                              g_param_spec_string ("gtk-key-theme-name",
380                                                                   P_("Key Theme Name"),
381                                                                   P_("Name of key theme RC file to load"),
382                                                                   DEFAULT_KEY_THEME,
383                                                                   GTK_PARAM_READWRITE),
384                                              NULL);
385   g_assert (result == PROP_KEY_THEME_NAME);    
386
387   result = settings_install_property_parser (class,
388                                              g_param_spec_string ("gtk-menu-bar-accel",
389                                                                   P_("Menu bar accelerator"),
390                                                                   P_("Keybinding to activate the menu bar"),
391                                                                   "F10",
392                                                                   GTK_PARAM_READWRITE),
393                                              NULL);
394   g_assert (result == PROP_MENU_BAR_ACCEL);
395
396   result = settings_install_property_parser (class,
397                                              g_param_spec_int ("gtk-dnd-drag-threshold",
398                                                                P_("Drag threshold"),
399                                                                P_("Number of pixels the cursor can move before dragging"),
400                                                                1, G_MAXINT, 8,
401                                                                GTK_PARAM_READWRITE),
402                                              NULL);
403   g_assert (result == PROP_DND_DRAG_THRESHOLD);
404
405   result = settings_install_property_parser (class,
406                                              g_param_spec_string ("gtk-font-name",
407                                                                    P_("Font Name"),
408                                                                    P_("Name of default font to use"),
409                                                                   "Sans 10",
410                                                                   GTK_PARAM_READWRITE),
411                                              NULL);
412   g_assert (result == PROP_FONT_NAME);
413
414   /**
415    * GtkSettings:gtk-icon-sizes:
416    *
417    * A list of icon sizes. The list is separated by colons, and
418    * item has the form:
419    *
420    * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
421    *
422    * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48". 
423    * GTK+ itself use the following named icon sizes: gtk-menu, 
424    * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd, 
425    * gtk-dialog. Applications can register their own named icon 
426    * sizes with gtk_icon_size_register().
427    */
428   result = settings_install_property_parser (class,
429                                              g_param_spec_string ("gtk-icon-sizes",
430                                                                    P_("Icon Sizes"),
431                                                                    P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
432                                                                   NULL,
433                                                                   GTK_PARAM_READWRITE),
434                                              NULL);
435   g_assert (result == PROP_ICON_SIZES);
436
437   result = settings_install_property_parser (class,
438                                              g_param_spec_string ("gtk-modules",
439                                                                   P_("GTK Modules"),
440                                                                   P_("List of currently active GTK modules"),
441                                                                   NULL,
442                                                                   GTK_PARAM_READWRITE),
443                                              NULL);
444   g_assert (result == PROP_MODULES);
445
446 #ifdef GDK_WINDOWING_X11
447   result = settings_install_property_parser (class,
448                                              g_param_spec_int ("gtk-xft-antialias",
449                                                                P_("Xft Antialias"),
450                                                                P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
451                                                                -1, 1, -1,
452                                                                GTK_PARAM_READWRITE),
453                                              NULL);
454  
455   g_assert (result == PROP_XFT_ANTIALIAS);
456   
457   result = settings_install_property_parser (class,
458                                              g_param_spec_int ("gtk-xft-hinting",
459                                                                P_("Xft Hinting"),
460                                                                P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
461                                                                -1, 1, -1,
462                                                                GTK_PARAM_READWRITE),
463                                              NULL);
464   
465   g_assert (result == PROP_XFT_HINTING);
466   
467   result = settings_install_property_parser (class,
468                                              g_param_spec_string ("gtk-xft-hintstyle",
469                                                                   P_("Xft Hint Style"),
470                                                                   P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
471                                                                   NULL,
472                                                                   GTK_PARAM_READWRITE),
473                                               NULL);
474   
475   g_assert (result == PROP_XFT_HINTSTYLE);
476   
477   result = settings_install_property_parser (class,
478                                              g_param_spec_string ("gtk-xft-rgba",
479                                                                   P_("Xft RGBA"),
480                                                                   P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
481                                                                   NULL,
482                                                                   GTK_PARAM_READWRITE),
483                                              NULL);
484   
485   g_assert (result == PROP_XFT_RGBA);
486   
487   result = settings_install_property_parser (class,
488                                              g_param_spec_int ("gtk-xft-dpi",
489                                                                P_("Xft DPI"),
490                                                                P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
491                                                                -1, 1024*1024, -1,
492                                                                GTK_PARAM_READWRITE),
493                                              NULL);
494   
495   g_assert (result == PROP_XFT_DPI);
496
497   result = settings_install_property_parser (class,
498                                              g_param_spec_string ("gtk-cursor-theme-name",
499                                                                   P_("Cursor theme name"),
500                                                                   P_("Name of the cursor theme to use, or NULL to use the default theme"),
501                                                                   NULL,
502                                                                   GTK_PARAM_READWRITE),
503                                              NULL);
504   g_assert (result == PROP_CURSOR_THEME_NAME);
505
506   result = settings_install_property_parser (class,
507                                              g_param_spec_int ("gtk-cursor-theme-size",
508                                                                P_("Cursor theme size"),
509                                                                P_("Size to use for cursors, or 0 to use the default size"),
510                                                                0, 128, 0,
511                                                                GTK_PARAM_READWRITE),
512                                              NULL);
513   
514   g_assert (result == PROP_CURSOR_THEME_SIZE);
515
516 #endif  /* GDK_WINDOWING_X11 */
517   result = settings_install_property_parser (class,
518                                              g_param_spec_boolean ("gtk-alternative-button-order",
519                                                                    P_("Alternative button order"),
520                                                                    P_("Whether buttons in dialogs should use the alternative button order"),
521                                                                    FALSE,
522                                                                    GTK_PARAM_READWRITE),
523                                              NULL);
524   g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
525
526   /**
527    * GtkSettings:gtk-alternative-sort-arrows:
528    *
529    * Controls the direction of the sort indicators in sorted list and tree
530    * views. By default an arrow pointing down means the column is sorted
531    * in ascending order. When set to %TRUE, this order will be inverted.
532    *
533    * Since: 2.12
534    */
535   result = settings_install_property_parser (class,
536                                              g_param_spec_boolean ("gtk-alternative-sort-arrows",
537                                                                    P_("Alternative sort indicator direction"),
538                                                                    P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
539                                                                    FALSE,
540                                                                    GTK_PARAM_READWRITE),
541                                              NULL);
542   g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
543
544   result = settings_install_property_parser (class,
545                                              g_param_spec_boolean ("gtk-show-input-method-menu",
546                                                                    P_("Show the 'Input Methods' menu"),
547                                                                    P_("Whether the context menus of entries and text views should offer to change the input method"),
548                                                                    TRUE,
549                                                                    GTK_PARAM_READWRITE),
550                                              NULL);
551   g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
552
553   result = settings_install_property_parser (class,
554                                              g_param_spec_boolean ("gtk-show-unicode-menu",
555                                                                    P_("Show the 'Insert Unicode Control Character' menu"),
556                                                                    P_("Whether the context menus of entries and text views should offer to insert control characters"),
557                                                                    TRUE,
558                                                                    GTK_PARAM_READWRITE),
559                                              NULL);
560   g_assert (result == PROP_SHOW_UNICODE_MENU);
561
562   result = settings_install_property_parser (class,
563                                              g_param_spec_int ("gtk-timeout-initial",
564                                                                P_("Start timeout"),
565                                                                P_("Starting value for timeouts, when button is pressed"),
566                                                                0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
567                                                                GTK_PARAM_READWRITE),
568                                              NULL);
569
570   g_assert (result == PROP_TIMEOUT_INITIAL);
571
572   result = settings_install_property_parser (class,
573                                              g_param_spec_int ("gtk-timeout-repeat",
574                                                                P_("Repeat timeout"),
575                                                                P_("Repeat value for timeouts, when button is pressed"),
576                                                                0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
577                                                                GTK_PARAM_READWRITE),
578                                              NULL);
579
580   g_assert (result == PROP_TIMEOUT_REPEAT);
581
582   result = settings_install_property_parser (class,
583                                              g_param_spec_int ("gtk-timeout-expand",
584                                                                P_("Expand timeout"),
585                                                                P_("Expand value for timeouts, when a widget is expanding a new region"),
586                                                                0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
587                                                                GTK_PARAM_READWRITE),
588                                              NULL);
589
590   g_assert (result == PROP_TIMEOUT_EXPAND);
591
592   /**
593    * GtkSettings:gtk-color-scheme:
594    *
595    * A palette of named colors for use in themes. The format of the string is
596    * <programlisting>
597    * name1: color1
598    * name2: color2
599    * ...
600    * </programlisting>
601    * Color names must be acceptable as identifiers in the 
602    * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
603    * color specifications must be in the format accepted by
604    * gdk_color_parse().
605    * 
606    * Note that due to the way the color tables from different sources are
607    * merged, color specifications will be converted to hexadecimal form
608    * when getting this property.
609    *
610    * Starting with GTK+ 2.12, the entries can alternatively be separated
611    * by ';' instead of newlines:
612    * <programlisting>
613    * name1: color1; name2: color2; ...
614    * </programlisting>
615    *
616    * Since: 2.10
617    */
618   result = settings_install_property_parser (class,
619                                              g_param_spec_string ("gtk-color-scheme",
620                                                                   P_("Color scheme"),
621                                                                   P_("A palette of named colors for use in themes"),
622                                                                   "",
623                                                                   GTK_PARAM_READWRITE),
624                                              NULL);
625
626   g_assert (result == PROP_COLOR_SCHEME);
627
628   result = settings_install_property_parser (class,
629                                              g_param_spec_boolean ("gtk-enable-animations",
630                                                                    P_("Enable Animations"),
631                                                                    P_("Whether to enable toolkit-wide animations."),
632                                                                    TRUE,
633                                                                    GTK_PARAM_READWRITE),
634                                              NULL);
635
636   g_assert (result == PROP_ENABLE_ANIMATIONS);
637
638   /**
639    * GtkSettings:gtk-touchscreen-mode:
640    *
641    * When %TRUE, there are no motion notify events delivered on this screen,
642    * and widgets can't use the pointer hovering them for any essential
643    * functionality.
644    *
645    * Since: 2.10
646    */
647   result = settings_install_property_parser (class,
648                                              g_param_spec_boolean ("gtk-touchscreen-mode",
649                                                                    P_("Enable Touchscreen Mode"),
650                                                                    P_("When TRUE, there are no motion notify events delivered on this screen"),
651                                                                    FALSE,
652                                                                    GTK_PARAM_READWRITE),
653                                              NULL);
654
655   g_assert (result == PROP_TOUCHSCREEN_MODE);
656
657   /**
658    * GtkSettings:gtk-tooltip-timeout:
659    *
660    * Time, in milliseconds, after which a tooltip could appear if the
661    * cursor is hovering on top of a widget.
662    *
663    * Since: 2.12
664    */
665   result = settings_install_property_parser (class,
666                                              g_param_spec_int ("gtk-tooltip-timeout",
667                                                                P_("Tooltip timeout"),
668                                                                P_("Timeout before tooltip is shown"),
669                                                                0, G_MAXINT,
670                                                                500,
671                                                                GTK_PARAM_READWRITE),
672                                              NULL);
673
674   g_assert (result == PROP_TOOLTIP_TIMEOUT);
675
676   /**
677    * GtkSettings:gtk-tooltip-browse-timeout:
678    *
679    * Controls the time after which tooltips will appear when
680    * browse mode is enabled, in milliseconds.
681    *
682    * Browse mode is enabled when the mouse pointer moves off an object
683    * where a tooltip was currently being displayed. If the mouse pointer
684    * hits another object before the browse mode timeout expires (see
685    * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the 
686    * amount of milliseconds specified by this setting to popup the tooltip
687    * for the new object.
688    *
689    * Since: 2.12
690    */
691   result = settings_install_property_parser (class,
692                                              g_param_spec_int ("gtk-tooltip-browse-timeout",
693                                                                P_("Tooltip browse timeout"),
694                                                                P_("Timeout before tooltip is shown when browse mode is enabled"),
695                                                                0, G_MAXINT,
696                                                                60,
697                                                                GTK_PARAM_READWRITE),
698                                              NULL);
699
700   g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
701
702   /**
703    * GtkSettings:gtk-tooltip-browse-mode-timeout:
704    *
705    * Amount of time, in milliseconds, after which the browse mode
706    * will be disabled.
707    *
708    * See #GtkSettings:gtk-tooltip-browse-timeout for more information
709    * about browse mode.
710    *
711    * Since: 2.12
712    */
713   result = settings_install_property_parser (class,
714                                              g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
715                                                                P_("Tooltip browse mode timeout"),
716                                                                P_("Timeout after which browse mode is disabled"),
717                                                                0, G_MAXINT,
718                                                                500,
719                                                                GTK_PARAM_READWRITE),
720                                              NULL);
721
722   g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
723
724   /**
725    * GtkSettings:gtk-keynav-cursor-only:
726    *
727    * When %TRUE, keyboard navigation should be able to reach all widgets
728    * by using the cursor keys only. Tab, Shift etc. keys can't be expected
729    * to be present on the used input device.
730    *
731    * Since: 2.12
732    */
733   result = settings_install_property_parser (class,
734                                              g_param_spec_boolean ("gtk-keynav-cursor-only",
735                                                                    P_("Keynav Cursor Only"),
736                                                                    P_("When TRUE, there are only cursor keys available to navigate widgets"),
737                                                                    FALSE,
738                                                                    GTK_PARAM_READWRITE),
739                                              NULL);
740
741   g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
742
743   /**
744    * GtkSettings:gtk-keynav-wrap-around:
745    *
746    * When %TRUE, some widgets will wrap around when doing keyboard
747    * navigation, such as menus, menubars and notebooks.
748    *
749    * Since: 2.12
750    */
751   result = settings_install_property_parser (class,
752                                              g_param_spec_boolean ("gtk-keynav-wrap-around",
753                                                                    P_("Keynav Wrap Around"),
754                                                                    P_("Whether to wrap around when keyboard-navigating widgets"),
755                                                                    TRUE,
756                                                                    GTK_PARAM_READWRITE),
757                                              NULL);
758
759   g_assert (result == PROP_KEYNAV_WRAP_AROUND);
760
761   /**
762    * GtkSettings:gtk-error-bell:
763    *
764    * When %TRUE, keyboard navigation and other input-related errors
765    * will cause a beep. Since the error bell is implemented using
766    * gdk_window_beep(), the windowing system may offer ways to
767    * configure the error bell in many ways, such as flashing the
768    * window or similar visual effects.
769    *
770    * Since: 2.12
771    */
772   result = settings_install_property_parser (class,
773                                              g_param_spec_boolean ("gtk-error-bell",
774                                                                    P_("Error Bell"),
775                                                                    P_("When TRUE, keyboard navigation and other errors will cause a beep"),
776                                                                    TRUE,
777                                                                    GTK_PARAM_READWRITE),
778                                              NULL);
779
780   g_assert (result == PROP_ERROR_BELL);
781
782   /**
783    * GtkSettings:color-hash:
784    *
785    * Holds a hash table representation of the #GtkSettings:gtk-color-scheme 
786    * setting, mapping color names to #GdkColor<!-- -->s. 
787    *
788    * Since: 2.10
789    */
790   result = settings_install_property_parser (class, 
791                                              g_param_spec_boxed ("color-hash",
792                                                                  P_("Color Hash"),
793                                                                  P_("A hash table representation of the color scheme."),
794                                                                  G_TYPE_HASH_TABLE,
795                                                                  GTK_PARAM_READABLE),
796                                              NULL);
797   g_assert (result == PROP_COLOR_HASH);
798
799   result = settings_install_property_parser (class, 
800                                              g_param_spec_string ("gtk-file-chooser-backend",
801                                                                   P_("Default file chooser backend"),
802                                                                   P_("Name of the GtkFileChooser backend to use by default"),
803                                                                   NULL,
804                                                                   GTK_PARAM_READWRITE),
805                                              NULL);
806   g_assert (result == PROP_FILE_CHOOSER_BACKEND);
807
808   /**
809    * GtkSettings:gtk-print-backends:
810    *
811    * A comma-separated list of print backends to use in the print
812    * dialog. Available print backends depend on the GTK+ installation,
813    * and may include "file", "cups", "lpr" or "papi".
814    *
815    * Since: 2.10
816    */
817   result = settings_install_property_parser (class,
818                                              g_param_spec_string ("gtk-print-backends",
819                                                                   P_("Default print backend"),
820                                                                   P_("List of the GtkPrintBackend backends to use by default"),
821                                                                   GTK_PRINT_BACKENDS,
822                                                                   GTK_PARAM_READWRITE),
823                                              NULL);
824   g_assert (result == PROP_PRINT_BACKENDS);
825
826   /**
827    * GtkSettings:gtk-print-preview-command:
828    *
829    * A command to run for displaying the print preview. The command
830    * should contain a %f placeholder, which will get replaced by
831    * the path to the pdf file. The command may also contain a %s
832    * placeholder, which will get replaced by the path to a file
833    * containing the print settings in the format produced by 
834    * gtk_print_settings_to_file().
835    *
836    * The preview application is responsible for removing the pdf file
837    * and the print settings file when it is done.
838    *
839    * Since: 2.10
840    */
841   result = settings_install_property_parser (class,
842                                              g_param_spec_string ("gtk-print-preview-command",
843                                                                   P_("Default command to run when displaying a print preview"),
844                                                                   P_("Command to run when displaying a print preview"),
845                                                                   GTK_PRINT_PREVIEW_COMMAND,
846                                                                   GTK_PARAM_READWRITE),
847                                              NULL); 
848   g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
849
850   /**
851    * GtkSettings:gtk-enable-mnemonics:
852    *
853    * Whether labels and menu items should have visible mnemonics which
854    * can be activated.
855    *
856    * Since: 2.12
857    */
858   result = settings_install_property_parser (class,
859                                              g_param_spec_boolean ("gtk-enable-mnemonics",
860                                                                    P_("Enable Mnemonics"),
861                                                                    P_("Whether labels should have mnemonics"),
862                                                                    TRUE,
863                                                                    GTK_PARAM_READWRITE),
864                                              NULL);
865   g_assert (result == PROP_ENABLE_MNEMONICS);
866
867   /**
868    * GtkSettings:gtk-enable-accels:
869    *
870    * Whether menu items should have visible accelerators which can be
871    * activated.
872    *
873    * Since: 2.12
874    */
875   result = settings_install_property_parser (class,
876                                              g_param_spec_boolean ("gtk-enable-accels",
877                                                                    P_("Enable Accelerators"),
878                                                                    P_("Whether menu items should have accelerators"),
879                                                                    TRUE,
880                                                                    GTK_PARAM_READWRITE),
881                                              NULL);
882   g_assert (result == PROP_ENABLE_ACCELS);
883
884   /**
885    * GtkSettings:gtk-recent-files-limit:
886    *
887    * The number of recently used files that should be displayed by default by
888    * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
889    * -1 means every recently used file stored.
890    *
891    * Since: 2.12
892    */
893   result = settings_install_property_parser (class,
894                                              g_param_spec_int ("gtk-recent-files-limit",
895                                                                P_("Recent Files Limit"),
896                                                                P_("Number of recently used files"),
897                                                                -1, G_MAXINT,
898                                                                50,
899                                                                GTK_PARAM_READWRITE),
900                                              NULL);
901   g_assert (result == PROP_RECENT_FILES_LIMIT);
902
903   /**
904    * GtkSettings:gtk-im-module:
905    *
906    * Which IM (input method) module should be used by default. This is the 
907    * input method that will be used if the user has not explicitly chosen 
908    * another input method from the IM context menu.  
909    *
910    * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
911    */
912   result = settings_install_property_parser (class,
913                                              g_param_spec_string ("gtk-im-module",
914                                                                   P_("Default IM module"),
915                                                                   P_("Which IM module should be used by default"),
916                                                                   NULL,
917                                                                   GTK_PARAM_READWRITE),
918                                              NULL);
919   g_assert (result == PROP_IM_MODULE);
920
921   /**
922    * GtkSettings:gtk-recent-files-max-age:
923    *
924    * The maximum age, in days, of the items inside the recently used
925    * resources list. Items older than this setting will be excised
926    * from the list. If set to 0, the list will always be empty; if
927    * set to -1, no item will be removed.
928    *
929    * Since: 2.14
930    */
931   result = settings_install_property_parser (class,
932                                              g_param_spec_int ("gtk-recent-files-max-age",
933                                                                P_("Recent Files Max Age"),
934                                                                P_("Maximum age of recently used files, in days"),
935                                                                -1, G_MAXINT,
936                                                                30,
937                                                                GTK_PARAM_READWRITE),
938                                              NULL);
939   g_assert (result == PROP_RECENT_FILES_MAX_AGE);
940
941   result = settings_install_property_parser (class,
942                                              g_param_spec_uint ("gtk-fontconfig-timestamp",
943                                                                 P_("Fontconfig configuration timestamp"),
944                                                                 P_("Timestamp of current fontconfig configuration"),
945                                                                 0, G_MAXUINT, 0,
946                                                                 GTK_PARAM_READWRITE),
947                                              NULL);
948   
949   g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
950
951   /**
952    * GtkSettings:gtk-sound-theme-name:
953    *
954    * The XDG sound theme to use for event sounds.
955    *
956    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink> 
957    * for more information on event sounds and sound themes.
958    *
959    * GTK+ itself does not support event sounds, you have to use a loadable 
960    * module like the one that comes with libcanberra.
961    *
962    * Since: 2.14
963    */
964   result = settings_install_property_parser (class,
965                                              g_param_spec_string ("gtk-sound-theme-name",
966                                                                   P_("Sound Theme Name"),
967                                                                   P_("XDG sound theme name"),
968                                                                   "freedesktop",
969                                                                   GTK_PARAM_READWRITE),
970                                              NULL);
971   g_assert (result == PROP_SOUND_THEME_NAME);
972
973   /**
974    * GtkSettings:gtk-enable-input-feedback-sounds:
975    *
976    * Whether to play event sounds as feedback to user input.
977    *
978    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink> 
979    * for more information on event sounds and sound themes.
980    *
981    * GTK+ itself does not support event sounds, you have to use a loadable 
982    * module like the one that comes with libcanberra.
983    *
984    * Since: 2.14
985    */
986   result = settings_install_property_parser (class,
987                                              g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
988                                                                    /* Translators: this means sounds that are played as feedback to user input */
989                                                                    P_("Audible Input Feedback"),
990                                                                    P_("Whether to play event sounds as feedback to user input"),
991                                                                    TRUE,
992                                                                    GTK_PARAM_READWRITE),
993                                              NULL);
994   g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
995
996   /**
997    * GtkSettings:gtk-enable-event-sounds:
998    *
999    * Whether to play any event sounds at all.
1000    *
1001    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink> 
1002    * for more information on event sounds and sound themes.
1003    *
1004    * GTK+ itself does not support event sounds, you have to use a loadable 
1005    * module like the one that comes with libcanberra.
1006    *
1007    * Since: 2.14
1008    */
1009   result = settings_install_property_parser (class,
1010                                              g_param_spec_boolean ("gtk-enable-event-sounds",
1011                                                                    P_("Enable Event Sounds"),
1012                                                                    P_("Whether to play any event sounds at all"),
1013                                                                    TRUE,
1014                                                                    GTK_PARAM_READWRITE),
1015                                              NULL);
1016   g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1017
1018   /**
1019    * GtkSettings:gtk-enable-tooltips:
1020    *
1021    * Whether tooltips should be shown on widgets.
1022    *
1023    * Since: 2.14
1024    */
1025   result = settings_install_property_parser (class,
1026                                              g_param_spec_boolean ("gtk-enable-tooltips",
1027                                                                    P_("Enable Tooltips"),
1028                                                                    P_("Whether tooltips should be shown on widgets"),
1029                                                                    TRUE,
1030                                                                    GTK_PARAM_READWRITE),
1031                                              NULL);
1032   g_assert (result == PROP_ENABLE_TOOLTIPS);
1033
1034   /**
1035    * GtkSettings:toolbar-style:
1036    *
1037    * The size of icons in default toolbars.
1038    */
1039   result = settings_install_property_parser (class,
1040                                              g_param_spec_enum ("gtk-toolbar-style",
1041                                                                    P_("Toolbar style"),
1042                                                                    P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1043                                                                    GTK_TYPE_TOOLBAR_STYLE,
1044                                                                    GTK_TOOLBAR_BOTH,
1045                                                                    GTK_PARAM_READWRITE),
1046                                              gtk_rc_property_parse_enum);
1047   g_assert (result == PROP_TOOLBAR_STYLE);
1048
1049   /**
1050    * GtkSettings:toolbar-icon-size:
1051    *
1052    * The size of icons in default toolbars.
1053    */
1054   result = settings_install_property_parser (class,
1055                                              g_param_spec_enum ("gtk-toolbar-icon-size",
1056                                                                    P_("Toolbar Icon Size"),
1057                                                                    P_("The size of icons in default toolbars."),
1058                                                                    GTK_TYPE_ICON_SIZE,
1059                                                                    GTK_ICON_SIZE_LARGE_TOOLBAR,
1060                                                                    GTK_PARAM_READWRITE),
1061                                              gtk_rc_property_parse_enum);
1062   g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1063
1064   /**
1065    * GtkSettings:gtk-auto-mnemonics:
1066    *
1067    * Whether mnemonics should be automatically shown and hidden when the user
1068    * presses the mnemonic activator.
1069    *
1070    * Since: 2.20
1071    */
1072   result = settings_install_property_parser (class,
1073                                              g_param_spec_boolean ("gtk-auto-mnemonics",
1074                                                                    P_("Auto Mnemonics"),
1075                                                                    P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1076                                                                    FALSE,
1077                                                                    GTK_PARAM_READWRITE),
1078                                              NULL);
1079   g_assert (result == PROP_AUTO_MNEMONICS);
1080
1081   /**
1082    * GtkSettings:gtk-application-prefer-dark-theme:
1083    *
1084    * Whether the application prefers to use a dark theme. If a GTK+ theme
1085    * includes a dark variant, it will be used instead of the configured
1086    * theme.
1087    *
1088    * Some applications benefit from minimizing the amount of light pollution that
1089    * interferes with the content. Good candidates for dark themes are photo and
1090    * video editors that make the actual content get all the attention and minimize
1091    * the distraction of the chrome.
1092    *
1093    * Dark themes should not be used for documents, where large spaces are white/light
1094    * and the dark chrome creates too much contrast (web browser, text editor...).
1095    *
1096    * Since: 2.22
1097    */
1098   result = settings_install_property_parser (class,
1099                                              g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1100                                                                  P_("Application prefers a dark theme"),
1101                                                                  P_("Whether the application prefers to have a dark theme."),
1102                                                                  FALSE,
1103                                                                  GTK_PARAM_READWRITE),
1104                                              NULL);
1105   g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1106
1107   /**
1108    * GtkSettings::gtk-button-images:
1109    *
1110    * Whether images should be shown on buttons
1111    *
1112    * Since: 2.4
1113    */
1114   result = settings_install_property_parser (class,
1115                                              g_param_spec_boolean ("gtk-button-images",
1116                                                                    P_("Show button images"),
1117                                                                    P_("Whether images should be shown on buttons"),
1118                                                                    TRUE,
1119                                                                    GTK_PARAM_READWRITE),
1120                                              NULL);
1121   g_assert (result == PROP_BUTTON_IMAGES);
1122
1123   result = settings_install_property_parser (class,
1124                                              g_param_spec_boolean ("gtk-entry-select-on-focus",
1125                                                                    P_("Select on focus"),
1126                                                                    P_("Whether to select the contents of an entry when it is focused"),
1127                                                                    TRUE,
1128                                                                    GTK_PARAM_READWRITE),
1129                                              NULL);
1130   g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1131
1132   /**
1133    * GtkSettings:gtk-entry-password-hint-timeout:
1134    *
1135    * How long to show the last input character in hidden
1136    * entries. This value is in milliseconds. 0 disables showing the
1137    * last char. 600 is a good value for enabling it.
1138    *
1139    * Since: 2.10
1140    */
1141   result = settings_install_property_parser (class,
1142                                              g_param_spec_uint ("gtk-entry-password-hint-timeout",
1143                                                                 P_("Password Hint Timeout"),
1144                                                                 P_("How long to show the last input character in hidden entries"),
1145                                                                 0, G_MAXUINT,
1146                                                                 0,
1147                                                                 GTK_PARAM_READWRITE),
1148                                              NULL);
1149   g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1150
1151   result = settings_install_property_parser (class,
1152                                              g_param_spec_boolean ("gtk-menu-images",
1153                                                                    P_("Show menu images"),
1154                                                                    P_("Whether images should be shown in menus"),
1155                                                                    TRUE,
1156                                                                    GTK_PARAM_READWRITE),
1157                                              NULL);
1158   g_assert (result == PROP_MENU_IMAGES);
1159
1160   result = settings_install_property_parser (class,
1161                                              g_param_spec_int ("gtk-menu-bar-popup-delay",
1162                                                                P_("Delay before drop down menus appear"),
1163                                                                P_("Delay before the submenus of a menu bar appear"),
1164                                                                0, G_MAXINT,
1165                                                                0,
1166                                                                GTK_PARAM_READWRITE),
1167                                              NULL);
1168   g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1169
1170   /**
1171    * GtkSettings:gtk-scrolled-window-placement:
1172    *
1173    * Where the contents of scrolled windows are located with respect to the 
1174    * scrollbars, if not overridden by the scrolled window's own placement.
1175    *
1176    * Since: 2.10
1177    */
1178   result = settings_install_property_parser (class,
1179                                              g_param_spec_enum ("gtk-scrolled-window-placement",
1180                                                                 P_("Scrolled Window Placement"),
1181                                                                 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1182                                                                 GTK_TYPE_CORNER_TYPE,
1183                                                                 GTK_CORNER_TOP_LEFT,
1184                                                                 GTK_PARAM_READWRITE),
1185                                              gtk_rc_property_parse_enum);
1186   g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1187
1188   result = settings_install_property_parser (class,
1189                                              g_param_spec_boolean ("gtk-can-change-accels",
1190                                                                    P_("Can change accelerators"),
1191                                                                    P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1192                                                                    FALSE,
1193                                                                    GTK_PARAM_READWRITE),
1194                                              NULL);
1195   g_assert (result == PROP_CAN_CHANGE_ACCELS);
1196
1197   result = settings_install_property_parser (class,
1198                                              g_param_spec_int ("gtk-menu-popup-delay",
1199                                                                P_("Delay before submenus appear"),
1200                                                                P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1201                                                                0, G_MAXINT,
1202                                                                225,
1203                                                                GTK_PARAM_READWRITE),
1204                                              NULL);
1205   g_assert (result == PROP_MENU_POPUP_DELAY);
1206
1207   result = settings_install_property_parser (class,
1208                                              g_param_spec_int ("gtk-menu-popdown-delay",
1209                                                                P_("Delay before hiding a submenu"),
1210                                                                P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1211                                                                0, G_MAXINT,
1212                                                                1000,
1213                                                                GTK_PARAM_READWRITE),
1214                                              NULL);
1215   g_assert (result == PROP_MENU_POPDOWN_DELAY);
1216
1217   result = settings_install_property_parser (class,
1218                                              g_param_spec_boolean ("gtk-label-select-on-focus",
1219                                                                    P_("Select on focus"),
1220                                                                    P_("Whether to select the contents of a selectable label when it is focused"),
1221                                                                    TRUE,
1222                                                                    GTK_PARAM_READWRITE),
1223                                              NULL);
1224   g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1225
1226   result = settings_install_property_parser (class,
1227                                              g_param_spec_string ("gtk-color-palette",
1228                                                                   P_("Custom palette"),
1229                                                                   P_("Palette to use in the color selector"),
1230                                                                   default_color_palette,
1231                                                                   GTK_PARAM_READWRITE),
1232                                              NULL);
1233   g_assert (result == PROP_COLOR_PALETTE);
1234
1235   result = settings_install_property_parser (class,
1236                                              g_param_spec_enum ("gtk-im-preedit-style",
1237                                                                 P_("IM Preedit style"),
1238                                                                 P_("How to draw the input method preedit string"),
1239                                                                 GTK_TYPE_IM_PREEDIT_STYLE,
1240                                                                 GTK_IM_PREEDIT_CALLBACK,
1241                                                                 GTK_PARAM_READWRITE),
1242                                              gtk_rc_property_parse_enum);
1243   g_assert (result == PROP_IM_PREEDIT_STYLE);
1244
1245   result = settings_install_property_parser (class,
1246                                              g_param_spec_enum ("gtk-im-status-style",
1247                                                                 P_("IM Status style"),
1248                                                                 P_("How to draw the input method statusbar"),
1249                                                                 GTK_TYPE_IM_STATUS_STYLE,
1250                                                                 GTK_IM_STATUS_CALLBACK,
1251                                                                 GTK_PARAM_READWRITE),
1252                                              gtk_rc_property_parse_enum);
1253   g_assert (result == PROP_IM_STATUS_STYLE);
1254 }
1255
1256 static GtkStyleProperties *
1257 gtk_settings_get_style (GtkStyleProvider *provider,
1258                         GtkWidgetPath    *path)
1259 {
1260   PangoFontDescription *font_desc;
1261   gchar *font_name, *color_scheme;
1262   GtkSettings *settings;
1263   GtkStyleProperties *props;
1264   gchar **colors;
1265   guint i;
1266
1267   settings = GTK_SETTINGS (provider);
1268   props = gtk_style_properties_new ();
1269
1270   g_object_get (settings,
1271                 "gtk-font-name", &font_name,
1272                 "gtk-color-scheme", &color_scheme,
1273                 NULL);
1274
1275   colors = g_strsplit_set (color_scheme, "\n;", -1);
1276
1277   for (i = 0; colors[i]; i++)
1278     {
1279       GtkSymbolicColor *color;
1280       gchar *name, *pos;
1281       GdkRGBA col;
1282
1283       if (!*colors[i])
1284         continue;
1285
1286       name = colors[i];
1287       pos = strchr (colors[i], ':');
1288
1289       if (!pos)
1290         continue;
1291
1292       /* Set NUL after color name */
1293       *pos = '\0';
1294       pos++;
1295
1296       /* Find start of color string */
1297       while (*pos == ' ')
1298         pos++;
1299
1300       if (!*pos || !gdk_rgba_parse (&col, pos))
1301         continue;
1302
1303       color = gtk_symbolic_color_new_literal (&col);
1304       gtk_style_properties_map_color (props, name, color);
1305       gtk_symbolic_color_unref (color);
1306     }
1307
1308   font_desc = pango_font_description_from_string (font_name);
1309
1310   gtk_style_properties_set (props, 0,
1311                             "font", font_desc,
1312                             NULL);
1313
1314   pango_font_description_free (font_desc);
1315   g_strfreev (colors);
1316   g_free (color_scheme);
1317   g_free (font_name);
1318
1319   return props;
1320 }
1321
1322 static void
1323 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1324 {
1325   iface->get_style = gtk_settings_get_style;
1326 }
1327
1328 static void
1329 gtk_settings_finalize (GObject *object)
1330 {
1331   GtkSettings *settings = GTK_SETTINGS (object);
1332   guint i;
1333
1334   object_list = g_slist_remove (object_list, settings);
1335
1336   _gtk_rc_context_destroy (settings);
1337
1338   for (i = 0; i < class_n_properties; i++)
1339     g_value_unset (&settings->property_values[i].value);
1340   g_free (settings->property_values);
1341   
1342   g_datalist_clear (&settings->queued_settings);
1343
1344   G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1345 }
1346
1347 static void
1348 settings_init_style (GtkSettings *settings)
1349 {
1350   static GtkCssProvider *css_provider = NULL;
1351   GtkCssProvider *default_provider;
1352
1353   /* Add provider for user file */
1354   if (G_UNLIKELY (!css_provider))
1355     {
1356       GFile *home_dir, *css_file;
1357
1358       css_provider = gtk_css_provider_new ();
1359
1360       home_dir = g_file_new_for_path (g_get_home_dir ());
1361       css_file = g_file_get_child (home_dir, ".gtk-3.0.css");
1362
1363       if (g_file_query_exists (css_file, NULL))
1364         gtk_css_provider_load_from_file (css_provider, css_file, NULL);
1365
1366       g_object_unref (home_dir);
1367       g_object_unref (css_file);
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_rc_reset_styles (GTK_SETTINGS (object));
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_rc_reset_styles (GTK_SETTINGS (object));
1581       break;
1582     case PROP_FONTCONFIG_TIMESTAMP:
1583       if (settings_update_fontconfig (settings))
1584         gtk_rc_reset_styles (GTK_SETTINGS (object));
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         gtk_style_context_add_provider_for_screen (settings->screen,
2640                                                    GTK_STYLE_PROVIDER (new_provider),
2641                                                    GTK_STYLE_PROVIDER_PRIORITY_SETTINGS + 1);
2642
2643       g_object_set_qdata_full (G_OBJECT (settings), quark_theme_name,
2644                               new_provider, (GDestroyNotify) g_object_unref);
2645     }
2646 }
2647
2648 static gboolean
2649 add_color_to_hash (gchar      *name,
2650                    GdkColor   *color,
2651                    GHashTable *target)
2652 {
2653   GdkColor *old;
2654
2655   old = g_hash_table_lookup (target, name);
2656   if (!old || !gdk_color_equal (old, color))
2657     {
2658       g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2659
2660       return TRUE;
2661     }
2662
2663   return FALSE;
2664 }
2665
2666 static gboolean
2667 add_colors_to_hash_from_string (GHashTable  *hash,
2668                                 const gchar *colors)
2669 {
2670   gchar *s, *p, *name;
2671   GdkColor color;
2672   gboolean changed = FALSE;
2673   gchar *copy;
2674
2675   copy = g_strdup (colors);
2676   s = copy;
2677   while (s && *s)
2678     {
2679       name = s;
2680       p = strchr (s, ':');
2681       if (p)
2682         {
2683           *p = '\0';
2684           p++;
2685         }
2686       else
2687         break;
2688
2689       while (*p == ' ')
2690         p++;
2691
2692       s = p;
2693       while (*s) 
2694         {
2695           if (*s == '\n' || *s == ';')
2696             {
2697               *s = '\0';
2698               s++;
2699               break;
2700             }
2701           s++;
2702         }
2703
2704       if (gdk_color_parse (p, &color))
2705         changed |= add_color_to_hash (name, &color, hash);
2706     }
2707
2708   g_free (copy);
2709
2710   return changed;
2711 }
2712
2713 static gboolean
2714 update_color_hash (ColorSchemeData   *data,
2715                    const gchar       *str,
2716                    GtkSettingsSource  source)
2717 {
2718   gboolean changed = FALSE;
2719   gint i;
2720   GHashTable *old_hash;
2721   GHashTableIter iter;
2722   gpointer name;
2723   gpointer color;
2724
2725   if ((str == NULL || *str == '\0') &&
2726       (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2727     return FALSE;
2728
2729   if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2730     return FALSE;
2731
2732   /* For the RC_FILE source we merge the values rather than over-writing
2733    * them, since multiple rc files might define independent sets of colors
2734    */
2735   if ((source != GTK_SETTINGS_SOURCE_RC_FILE) &&
2736       data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2737     {
2738       g_hash_table_unref (data->tables[source]);
2739       data->tables[source] = NULL;
2740       changed = TRUE; /* We can't rely on the code below since str might be "" */
2741     }
2742
2743   if (data->tables[source] == NULL)
2744     data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2745                                                   g_free,
2746                                                   (GDestroyNotify) gdk_color_free);
2747
2748   g_free (data->lastentry[source]);
2749   data->lastentry[source] = g_strdup (str);
2750
2751   changed |= add_colors_to_hash_from_string (data->tables[source], str);
2752
2753   if (!changed)
2754     return FALSE;
2755
2756   /* Rebuild the merged hash table. */
2757   if (data->color_hash)
2758     {
2759       old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2760                                         (GDestroyNotify) gdk_color_free);
2761
2762       g_hash_table_iter_init (&iter, data->color_hash);
2763       while (g_hash_table_iter_next (&iter, &name, &color))
2764         {
2765           g_hash_table_insert (old_hash, name, color);
2766           g_hash_table_iter_steal (&iter);
2767         }
2768     }
2769   else
2770     {
2771       old_hash = NULL;
2772     }
2773
2774   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2775     {
2776       if (data->tables[i])
2777         g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2778                               data->color_hash);
2779     }
2780
2781   if (old_hash)
2782     {
2783       /* now check if the merged hash has changed */
2784       changed = FALSE;
2785       if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2786         changed = TRUE;
2787       else
2788         {
2789           GHashTableIter iter;
2790           gpointer key, value, new_value;
2791
2792           g_hash_table_iter_init (&iter, old_hash);
2793           while (g_hash_table_iter_next (&iter, &key, &value))
2794             {
2795               new_value = g_hash_table_lookup (data->color_hash, key);
2796               if (!new_value || !gdk_color_equal (value, new_value))
2797                 {
2798                   changed = TRUE;
2799                   break;
2800                 }
2801             }
2802         }
2803
2804       g_hash_table_unref (old_hash);
2805     }
2806   else
2807     changed = TRUE;
2808
2809   return changed;
2810 }
2811
2812 static void
2813 merge_color_scheme (GtkSettings       *settings, 
2814                     const GValue      *value, 
2815                     GtkSettingsSource  source)
2816 {
2817   ColorSchemeData *data;
2818   const gchar *colors;
2819
2820   g_object_freeze_notify (G_OBJECT (settings));
2821
2822   colors = g_value_get_string (value);
2823
2824   settings_update_color_scheme (settings);
2825
2826   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2827                                                 "gtk-color-scheme");
2828   
2829   if (update_color_hash (data, colors, source))
2830     g_object_notify (G_OBJECT (settings), "color-hash");
2831
2832   g_object_thaw_notify (G_OBJECT (settings));
2833 }
2834
2835 static GHashTable *
2836 get_color_hash (GtkSettings *settings)
2837 {
2838   ColorSchemeData *data;
2839
2840   settings_update_color_scheme (settings);
2841   
2842   data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings), 
2843                                                "gtk-color-scheme");
2844
2845   return data->color_hash;
2846 }
2847
2848 static void 
2849 append_color_scheme (gpointer key,
2850                      gpointer value,
2851                      gpointer data)
2852 {
2853   gchar *name = (gchar *)key;
2854   GdkColor *color = (GdkColor *)value;
2855   GString *string = (GString *)data;
2856
2857   g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2858                           name, color->red, color->green, color->blue);
2859 }
2860
2861 static gchar *
2862 get_color_scheme (GtkSettings *settings)
2863 {
2864   ColorSchemeData *data;
2865   GString *string;
2866   
2867   settings_update_color_scheme (settings);
2868
2869   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2870                                                 "gtk-color-scheme");
2871
2872   string = g_string_new ("");
2873
2874   g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2875
2876   return g_string_free (string, FALSE);
2877 }