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