]> Pileus Git - ~andy/gtk/blob - gtk/gtksettings.c
f265642bbf4eeca515cac8aea8f0291b53f5ad92
[~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_theme_get_default (),
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    * Deprecated: 3.4. Generally the behavior touchscreen input should be
705    *             performed dynamically based on gdk_event_get_source_device().
706    */
707   result = settings_install_property_parser (class,
708                                              g_param_spec_boolean ("gtk-touchscreen-mode",
709                                                                    P_("Enable Touchscreen Mode"),
710                                                                    P_("When TRUE, there are no motion notify events delivered on this screen"),
711                                                                    FALSE,
712                                                                    GTK_PARAM_READWRITE | G_PARAM_DEPRECATED),
713                                              NULL);
714
715   g_assert (result == PROP_TOUCHSCREEN_MODE);
716
717   /**
718    * GtkSettings:gtk-tooltip-timeout:
719    *
720    * Time, in milliseconds, after which a tooltip could appear if the
721    * cursor is hovering on top of a widget.
722    *
723    * Since: 2.12
724    */
725   result = settings_install_property_parser (class,
726                                              g_param_spec_int ("gtk-tooltip-timeout",
727                                                                P_("Tooltip timeout"),
728                                                                P_("Timeout before tooltip is shown"),
729                                                                0, G_MAXINT,
730                                                                500,
731                                                                GTK_PARAM_READWRITE),
732                                              NULL);
733
734   g_assert (result == PROP_TOOLTIP_TIMEOUT);
735
736   /**
737    * GtkSettings:gtk-tooltip-browse-timeout:
738    *
739    * Controls the time after which tooltips will appear when
740    * browse mode is enabled, in milliseconds.
741    *
742    * Browse mode is enabled when the mouse pointer moves off an object
743    * where a tooltip was currently being displayed. If the mouse pointer
744    * hits another object before the browse mode timeout expires (see
745    * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
746    * amount of milliseconds specified by this setting to popup the tooltip
747    * for the new object.
748    *
749    * Since: 2.12
750    */
751   result = settings_install_property_parser (class,
752                                              g_param_spec_int ("gtk-tooltip-browse-timeout",
753                                                                P_("Tooltip browse timeout"),
754                                                                P_("Timeout before tooltip is shown when browse mode is enabled"),
755                                                                0, G_MAXINT,
756                                                                60,
757                                                                GTK_PARAM_READWRITE),
758                                              NULL);
759
760   g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
761
762   /**
763    * GtkSettings:gtk-tooltip-browse-mode-timeout:
764    *
765    * Amount of time, in milliseconds, after which the browse mode
766    * will be disabled.
767    *
768    * See #GtkSettings:gtk-tooltip-browse-timeout for more information
769    * about browse mode.
770    *
771    * Since: 2.12
772    */
773   result = settings_install_property_parser (class,
774                                              g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
775                                                                P_("Tooltip browse mode timeout"),
776                                                                P_("Timeout after which browse mode is disabled"),
777                                                                0, G_MAXINT,
778                                                                500,
779                                                                GTK_PARAM_READWRITE),
780                                              NULL);
781
782   g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
783
784   /**
785    * GtkSettings:gtk-keynav-cursor-only:
786    *
787    * When %TRUE, keyboard navigation should be able to reach all widgets
788    * by using the cursor keys only. Tab, Shift etc. keys can't be expected
789    * to be present on the used input device.
790    *
791    * Since: 2.12
792    */
793   result = settings_install_property_parser (class,
794                                              g_param_spec_boolean ("gtk-keynav-cursor-only",
795                                                                    P_("Keynav Cursor Only"),
796                                                                    P_("When TRUE, there are only cursor keys available to navigate widgets"),
797                                                                    FALSE,
798                                                                    GTK_PARAM_READWRITE),
799                                              NULL);
800
801   g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
802
803   /**
804    * GtkSettings:gtk-keynav-wrap-around:
805    *
806    * When %TRUE, some widgets will wrap around when doing keyboard
807    * navigation, such as menus, menubars and notebooks.
808    *
809    * Since: 2.12
810    */
811   result = settings_install_property_parser (class,
812                                              g_param_spec_boolean ("gtk-keynav-wrap-around",
813                                                                    P_("Keynav Wrap Around"),
814                                                                    P_("Whether to wrap around when keyboard-navigating widgets"),
815                                                                    TRUE,
816                                                                    GTK_PARAM_READWRITE),
817                                              NULL);
818
819   g_assert (result == PROP_KEYNAV_WRAP_AROUND);
820
821   /**
822    * GtkSettings:gtk-error-bell:
823    *
824    * When %TRUE, keyboard navigation and other input-related errors
825    * will cause a beep. Since the error bell is implemented using
826    * gdk_window_beep(), the windowing system may offer ways to
827    * configure the error bell in many ways, such as flashing the
828    * window or similar visual effects.
829    *
830    * Since: 2.12
831    */
832   result = settings_install_property_parser (class,
833                                              g_param_spec_boolean ("gtk-error-bell",
834                                                                    P_("Error Bell"),
835                                                                    P_("When TRUE, keyboard navigation and other errors will cause a beep"),
836                                                                    TRUE,
837                                                                    GTK_PARAM_READWRITE),
838                                              NULL);
839
840   g_assert (result == PROP_ERROR_BELL);
841
842   /**
843    * GtkSettings:color-hash:
844    *
845    * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
846    * setting, mapping color names to #GdkColor<!-- -->s.
847    *
848    * Since: 2.10
849    */
850   result = settings_install_property_parser (class,
851                                              g_param_spec_boxed ("color-hash",
852                                                                  P_("Color Hash"),
853                                                                  P_("A hash table representation of the color scheme."),
854                                                                  G_TYPE_HASH_TABLE,
855                                                                  GTK_PARAM_READABLE),
856                                              NULL);
857   g_assert (result == PROP_COLOR_HASH);
858
859   result = settings_install_property_parser (class,
860                                              g_param_spec_string ("gtk-file-chooser-backend",
861                                                                   P_("Default file chooser backend"),
862                                                                   P_("Name of the GtkFileChooser backend to use by default"),
863                                                                   NULL,
864                                                                   GTK_PARAM_READWRITE),
865                                              NULL);
866   g_assert (result == PROP_FILE_CHOOSER_BACKEND);
867
868   /**
869    * GtkSettings:gtk-print-backends:
870    *
871    * A comma-separated list of print backends to use in the print
872    * dialog. Available print backends depend on the GTK+ installation,
873    * and may include "file", "cups", "lpr" or "papi".
874    *
875    * Since: 2.10
876    */
877   result = settings_install_property_parser (class,
878                                              g_param_spec_string ("gtk-print-backends",
879                                                                   P_("Default print backend"),
880                                                                   P_("List of the GtkPrintBackend backends to use by default"),
881                                                                   GTK_PRINT_BACKENDS,
882                                                                   GTK_PARAM_READWRITE),
883                                              NULL);
884   g_assert (result == PROP_PRINT_BACKENDS);
885
886   /**
887    * GtkSettings:gtk-print-preview-command:
888    *
889    * A command to run for displaying the print preview. The command
890    * should contain a %f placeholder, which will get replaced by
891    * the path to the pdf file. The command may also contain a %s
892    * placeholder, which will get replaced by the path to a file
893    * containing the print settings in the format produced by
894    * gtk_print_settings_to_file().
895    *
896    * The preview application is responsible for removing the pdf file
897    * and the print settings file when it is done.
898    *
899    * Since: 2.10
900    */
901   result = settings_install_property_parser (class,
902                                              g_param_spec_string ("gtk-print-preview-command",
903                                                                   P_("Default command to run when displaying a print preview"),
904                                                                   P_("Command to run when displaying a print preview"),
905                                                                   GTK_PRINT_PREVIEW_COMMAND,
906                                                                   GTK_PARAM_READWRITE),
907                                              NULL);
908   g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
909
910   /**
911    * GtkSettings:gtk-enable-mnemonics:
912    *
913    * Whether labels and menu items should have visible mnemonics which
914    * can be activated.
915    *
916    * Since: 2.12
917    */
918   result = settings_install_property_parser (class,
919                                              g_param_spec_boolean ("gtk-enable-mnemonics",
920                                                                    P_("Enable Mnemonics"),
921                                                                    P_("Whether labels should have mnemonics"),
922                                                                    TRUE,
923                                                                    GTK_PARAM_READWRITE),
924                                              NULL);
925   g_assert (result == PROP_ENABLE_MNEMONICS);
926
927   /**
928    * GtkSettings:gtk-enable-accels:
929    *
930    * Whether menu items should have visible accelerators which can be
931    * activated.
932    *
933    * Since: 2.12
934    */
935   result = settings_install_property_parser (class,
936                                              g_param_spec_boolean ("gtk-enable-accels",
937                                                                    P_("Enable Accelerators"),
938                                                                    P_("Whether menu items should have accelerators"),
939                                                                    TRUE,
940                                                                    GTK_PARAM_READWRITE),
941                                              NULL);
942   g_assert (result == PROP_ENABLE_ACCELS);
943
944   /**
945    * GtkSettings:gtk-recent-files-limit:
946    *
947    * The number of recently used files that should be displayed by default by
948    * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
949    * -1 means every recently used file stored.
950    *
951    * Since: 2.12
952    */
953   result = settings_install_property_parser (class,
954                                              g_param_spec_int ("gtk-recent-files-limit",
955                                                                P_("Recent Files Limit"),
956                                                                P_("Number of recently used files"),
957                                                                -1, G_MAXINT,
958                                                                50,
959                                                                GTK_PARAM_READWRITE),
960                                              NULL);
961   g_assert (result == PROP_RECENT_FILES_LIMIT);
962
963   /**
964    * GtkSettings:gtk-im-module:
965    *
966    * Which IM (input method) module should be used by default. This is the
967    * input method that will be used if the user has not explicitly chosen
968    * another input method from the IM context menu.
969    * This also can be a colon-separated list of input methods, which GTK+
970    * will try in turn until it finds one available on the system.
971    *
972    * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
973    */
974   result = settings_install_property_parser (class,
975                                              g_param_spec_string ("gtk-im-module",
976                                                                   P_("Default IM module"),
977                                                                   P_("Which IM module should be used by default"),
978                                                                   NULL,
979                                                                   GTK_PARAM_READWRITE),
980                                              NULL);
981   g_assert (result == PROP_IM_MODULE);
982
983   /**
984    * GtkSettings:gtk-recent-files-max-age:
985    *
986    * The maximum age, in days, of the items inside the recently used
987    * resources list. Items older than this setting will be excised
988    * from the list. If set to 0, the list will always be empty; if
989    * set to -1, no item will be removed.
990    *
991    * Since: 2.14
992    */
993   result = settings_install_property_parser (class,
994                                              g_param_spec_int ("gtk-recent-files-max-age",
995                                                                P_("Recent Files Max Age"),
996                                                                P_("Maximum age of recently used files, in days"),
997                                                                -1, G_MAXINT,
998                                                                30,
999                                                                GTK_PARAM_READWRITE),
1000                                              NULL);
1001   g_assert (result == PROP_RECENT_FILES_MAX_AGE);
1002
1003   result = settings_install_property_parser (class,
1004                                              g_param_spec_uint ("gtk-fontconfig-timestamp",
1005                                                                 P_("Fontconfig configuration timestamp"),
1006                                                                 P_("Timestamp of current fontconfig configuration"),
1007                                                                 0, G_MAXUINT, 0,
1008                                                                 GTK_PARAM_READWRITE),
1009                                              NULL);
1010
1011   g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
1012
1013   /**
1014    * GtkSettings:gtk-sound-theme-name:
1015    *
1016    * The XDG sound theme to use for event sounds.
1017    *
1018    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1019    * for more information on event sounds and sound themes.
1020    *
1021    * GTK+ itself does not support event sounds, you have to use a loadable
1022    * module like the one that comes with libcanberra.
1023    *
1024    * Since: 2.14
1025    */
1026   result = settings_install_property_parser (class,
1027                                              g_param_spec_string ("gtk-sound-theme-name",
1028                                                                   P_("Sound Theme Name"),
1029                                                                   P_("XDG sound theme name"),
1030                                                                   "freedesktop",
1031                                                                   GTK_PARAM_READWRITE),
1032                                              NULL);
1033   g_assert (result == PROP_SOUND_THEME_NAME);
1034
1035   /**
1036    * GtkSettings:gtk-enable-input-feedback-sounds:
1037    *
1038    * Whether to play event sounds as feedback to user input.
1039    *
1040    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1041    * for more information on event sounds and sound themes.
1042    *
1043    * GTK+ itself does not support event sounds, you have to use a loadable
1044    * module like the one that comes with libcanberra.
1045    *
1046    * Since: 2.14
1047    */
1048   result = settings_install_property_parser (class,
1049                                              g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1050                                                                    /* Translators: this means sounds that are played as feedback to user input */
1051                                                                    P_("Audible Input Feedback"),
1052                                                                    P_("Whether to play event sounds as feedback to user input"),
1053                                                                    TRUE,
1054                                                                    GTK_PARAM_READWRITE),
1055                                              NULL);
1056   g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1057
1058   /**
1059    * GtkSettings:gtk-enable-event-sounds:
1060    *
1061    * Whether to play any event sounds at all.
1062    *
1063    * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1064    * for more information on event sounds and sound themes.
1065    *
1066    * GTK+ itself does not support event sounds, you have to use a loadable
1067    * module like the one that comes with libcanberra.
1068    *
1069    * Since: 2.14
1070    */
1071   result = settings_install_property_parser (class,
1072                                              g_param_spec_boolean ("gtk-enable-event-sounds",
1073                                                                    P_("Enable Event Sounds"),
1074                                                                    P_("Whether to play any event sounds at all"),
1075                                                                    TRUE,
1076                                                                    GTK_PARAM_READWRITE),
1077                                              NULL);
1078   g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1079
1080   /**
1081    * GtkSettings:gtk-enable-tooltips:
1082    *
1083    * Whether tooltips should be shown on widgets.
1084    *
1085    * Since: 2.14
1086    */
1087   result = settings_install_property_parser (class,
1088                                              g_param_spec_boolean ("gtk-enable-tooltips",
1089                                                                    P_("Enable Tooltips"),
1090                                                                    P_("Whether tooltips should be shown on widgets"),
1091                                                                    TRUE,
1092                                                                    GTK_PARAM_READWRITE),
1093                                              NULL);
1094   g_assert (result == PROP_ENABLE_TOOLTIPS);
1095
1096   /**
1097    * GtkSettings:gtk-toolbar-style:
1098    *
1099    * The size of icons in default toolbars.
1100    */
1101   result = settings_install_property_parser (class,
1102                                              g_param_spec_enum ("gtk-toolbar-style",
1103                                                                    P_("Toolbar style"),
1104                                                                    P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1105                                                                    GTK_TYPE_TOOLBAR_STYLE,
1106                                                                    GTK_TOOLBAR_BOTH,
1107                                                                    GTK_PARAM_READWRITE),
1108                                              gtk_rc_property_parse_enum);
1109   g_assert (result == PROP_TOOLBAR_STYLE);
1110
1111   /**
1112    * GtkSettings:gtk-toolbar-icon-size:
1113    *
1114    * The size of icons in default toolbars.
1115    */
1116   result = settings_install_property_parser (class,
1117                                              g_param_spec_enum ("gtk-toolbar-icon-size",
1118                                                                    P_("Toolbar Icon Size"),
1119                                                                    P_("The size of icons in default toolbars."),
1120                                                                    GTK_TYPE_ICON_SIZE,
1121                                                                    GTK_ICON_SIZE_LARGE_TOOLBAR,
1122                                                                    GTK_PARAM_READWRITE),
1123                                              gtk_rc_property_parse_enum);
1124   g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1125
1126   /**
1127    * GtkSettings:gtk-auto-mnemonics:
1128    *
1129    * Whether mnemonics should be automatically shown and hidden when the user
1130    * presses the mnemonic activator.
1131    *
1132    * Since: 2.20
1133    */
1134   result = settings_install_property_parser (class,
1135                                              g_param_spec_boolean ("gtk-auto-mnemonics",
1136                                                                    P_("Auto Mnemonics"),
1137                                                                    P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1138                                                                    FALSE,
1139                                                                    GTK_PARAM_READWRITE),
1140                                              NULL);
1141   g_assert (result == PROP_AUTO_MNEMONICS);
1142
1143   /**
1144    * GtkSettings:gtk-visible-focus:
1145    *
1146    * Whether 'focus rectangles' should be always visible, never visible,
1147    * or hidden until the user starts to use the keyboard.
1148    *
1149    * Since: 3.2
1150    */
1151   result = settings_install_property_parser (class,
1152                                              g_param_spec_enum ("gtk-visible-focus",
1153                                                                 P_("Visible Focus"),
1154                                                                 P_("Whether 'focus rectangles' should be hidden until the user starts to use the keyboard."),
1155                                                                 GTK_TYPE_POLICY_TYPE,
1156                                                                 GTK_POLICY_ALWAYS,
1157                                                                 GTK_PARAM_READWRITE),
1158                                              gtk_rc_property_parse_enum);
1159   g_assert (result == PROP_VISIBLE_FOCUS);
1160
1161   /**
1162    * GtkSettings:gtk-application-prefer-dark-theme:
1163    *
1164    * Whether the application prefers to use a dark theme. If a GTK+ theme
1165    * includes a dark variant, it will be used instead of the configured
1166    * theme.
1167    *
1168    * Some applications benefit from minimizing the amount of light pollution that
1169    * interferes with the content. Good candidates for dark themes are photo and
1170    * video editors that make the actual content get all the attention and minimize
1171    * the distraction of the chrome.
1172    *
1173    * Dark themes should not be used for documents, where large spaces are white/light
1174    * and the dark chrome creates too much contrast (web browser, text editor...).
1175    *
1176    * Since: 3.0
1177    */
1178   result = settings_install_property_parser (class,
1179                                              g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1180                                                                  P_("Application prefers a dark theme"),
1181                                                                  P_("Whether the application prefers to have a dark theme."),
1182                                                                  FALSE,
1183                                                                  GTK_PARAM_READWRITE),
1184                                              NULL);
1185   g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1186
1187   /**
1188    * GtkSettings::gtk-button-images:
1189    *
1190    * Whether images should be shown on buttons
1191    *
1192    * Since: 2.4
1193    */
1194   result = settings_install_property_parser (class,
1195                                              g_param_spec_boolean ("gtk-button-images",
1196                                                                    P_("Show button images"),
1197                                                                    P_("Whether images should be shown on buttons"),
1198                                                                    TRUE,
1199                                                                    GTK_PARAM_READWRITE),
1200                                              NULL);
1201   g_assert (result == PROP_BUTTON_IMAGES);
1202
1203   result = settings_install_property_parser (class,
1204                                              g_param_spec_boolean ("gtk-entry-select-on-focus",
1205                                                                    P_("Select on focus"),
1206                                                                    P_("Whether to select the contents of an entry when it is focused"),
1207                                                                    TRUE,
1208                                                                    GTK_PARAM_READWRITE),
1209                                              NULL);
1210   g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1211
1212   /**
1213    * GtkSettings:gtk-entry-password-hint-timeout:
1214    *
1215    * How long to show the last input character in hidden
1216    * entries. This value is in milliseconds. 0 disables showing the
1217    * last char. 600 is a good value for enabling it.
1218    *
1219    * Since: 2.10
1220    */
1221   result = settings_install_property_parser (class,
1222                                              g_param_spec_uint ("gtk-entry-password-hint-timeout",
1223                                                                 P_("Password Hint Timeout"),
1224                                                                 P_("How long to show the last input character in hidden entries"),
1225                                                                 0, G_MAXUINT,
1226                                                                 0,
1227                                                                 GTK_PARAM_READWRITE),
1228                                              NULL);
1229   g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1230
1231   result = settings_install_property_parser (class,
1232                                              g_param_spec_boolean ("gtk-menu-images",
1233                                                                    P_("Show menu images"),
1234                                                                    P_("Whether images should be shown in menus"),
1235                                                                    TRUE,
1236                                                                    GTK_PARAM_READWRITE),
1237                                              NULL);
1238   g_assert (result == PROP_MENU_IMAGES);
1239
1240   result = settings_install_property_parser (class,
1241                                              g_param_spec_int ("gtk-menu-bar-popup-delay",
1242                                                                P_("Delay before drop down menus appear"),
1243                                                                P_("Delay before the submenus of a menu bar appear"),
1244                                                                0, G_MAXINT,
1245                                                                0,
1246                                                                GTK_PARAM_READWRITE),
1247                                              NULL);
1248   g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1249
1250   /**
1251    * GtkSettings:gtk-scrolled-window-placement:
1252    *
1253    * Where the contents of scrolled windows are located with respect to the
1254    * scrollbars, if not overridden by the scrolled window's own placement.
1255    *
1256    * Since: 2.10
1257    */
1258   result = settings_install_property_parser (class,
1259                                              g_param_spec_enum ("gtk-scrolled-window-placement",
1260                                                                 P_("Scrolled Window Placement"),
1261                                                                 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1262                                                                 GTK_TYPE_CORNER_TYPE,
1263                                                                 GTK_CORNER_TOP_LEFT,
1264                                                                 GTK_PARAM_READWRITE),
1265                                              gtk_rc_property_parse_enum);
1266   g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1267
1268   result = settings_install_property_parser (class,
1269                                              g_param_spec_boolean ("gtk-can-change-accels",
1270                                                                    P_("Can change accelerators"),
1271                                                                    P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1272                                                                    FALSE,
1273                                                                    GTK_PARAM_READWRITE),
1274                                              NULL);
1275   g_assert (result == PROP_CAN_CHANGE_ACCELS);
1276
1277   result = settings_install_property_parser (class,
1278                                              g_param_spec_int ("gtk-menu-popup-delay",
1279                                                                P_("Delay before submenus appear"),
1280                                                                P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1281                                                                0, G_MAXINT,
1282                                                                225,
1283                                                                GTK_PARAM_READWRITE),
1284                                              NULL);
1285   g_assert (result == PROP_MENU_POPUP_DELAY);
1286
1287   result = settings_install_property_parser (class,
1288                                              g_param_spec_int ("gtk-menu-popdown-delay",
1289                                                                P_("Delay before hiding a submenu"),
1290                                                                P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1291                                                                0, G_MAXINT,
1292                                                                1000,
1293                                                                GTK_PARAM_READWRITE),
1294                                              NULL);
1295   g_assert (result == PROP_MENU_POPDOWN_DELAY);
1296
1297   result = settings_install_property_parser (class,
1298                                              g_param_spec_boolean ("gtk-label-select-on-focus",
1299                                                                    P_("Select on focus"),
1300                                                                    P_("Whether to select the contents of a selectable label when it is focused"),
1301                                                                    TRUE,
1302                                                                    GTK_PARAM_READWRITE),
1303                                              NULL);
1304   g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1305
1306   result = settings_install_property_parser (class,
1307                                              g_param_spec_string ("gtk-color-palette",
1308                                                                   P_("Custom palette"),
1309                                                                   P_("Palette to use in the color selector"),
1310                                                                   default_color_palette,
1311                                                                   GTK_PARAM_READWRITE),
1312                                              NULL);
1313   g_assert (result == PROP_COLOR_PALETTE);
1314
1315   result = settings_install_property_parser (class,
1316                                              g_param_spec_enum ("gtk-im-preedit-style",
1317                                                                 P_("IM Preedit style"),
1318                                                                 P_("How to draw the input method preedit string"),
1319                                                                 GTK_TYPE_IM_PREEDIT_STYLE,
1320                                                                 GTK_IM_PREEDIT_CALLBACK,
1321                                                                 GTK_PARAM_READWRITE),
1322                                              gtk_rc_property_parse_enum);
1323   g_assert (result == PROP_IM_PREEDIT_STYLE);
1324
1325   result = settings_install_property_parser (class,
1326                                              g_param_spec_enum ("gtk-im-status-style",
1327                                                                 P_("IM Status style"),
1328                                                                 P_("How to draw the input method statusbar"),
1329                                                                 GTK_TYPE_IM_STATUS_STYLE,
1330                                                                 GTK_IM_STATUS_CALLBACK,
1331                                                                 GTK_PARAM_READWRITE),
1332                                              gtk_rc_property_parse_enum);
1333   g_assert (result == PROP_IM_STATUS_STYLE);
1334
1335   result = settings_install_property_parser (class,
1336                                              g_param_spec_boolean ("gtk-shell-shows-app-menu",
1337                                                                    P_("Desktop shell shows app menu"),
1338                                                                    P_("Set to TRUE if the desktop environment "
1339                                                                       "is displaying the app menu, FALSE if "
1340                                                                       "the app should display it itself."),
1341                                                                    FALSE, GTK_PARAM_READWRITE),
1342                                              NULL);
1343   g_assert (result == PROP_SHELL_SHOWS_APP_MENU);
1344
1345   result = settings_install_property_parser (class,
1346                                              g_param_spec_boolean ("gtk-shell-shows-menubar",
1347                                                                    P_("Desktop shell shows the menubar"),
1348                                                                    P_("Set to TRUE if the desktop environment "
1349                                                                       "is displaying the menubar, FALSE if "
1350                                                                       "the app should display it itself."),
1351                                                                    FALSE, GTK_PARAM_READWRITE),
1352                                              NULL);
1353   g_assert (result == PROP_SHELL_SHOWS_MENUBAR);
1354
1355   g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1356 }
1357
1358 static void
1359 settings_ensure_style (GtkSettings *settings)
1360 {
1361   GtkSettingsPrivate *priv = settings->priv;
1362   PangoFontDescription *font_desc;
1363   gchar *font_name, *color_scheme;
1364   gchar **colors;
1365   guint i;
1366
1367   if (priv->style)
1368     return;
1369
1370   priv->style = gtk_style_properties_new ();
1371
1372   g_object_get (settings,
1373                 "gtk-font-name", &font_name,
1374                 "gtk-color-scheme", &color_scheme,
1375                 NULL);
1376
1377   colors = g_strsplit_set (color_scheme, "\n;", -1);
1378
1379   for (i = 0; colors[i]; i++)
1380     {
1381       GtkSymbolicColor *color;
1382       gchar *name, *pos;
1383       GdkRGBA col;
1384
1385       if (!*colors[i])
1386         continue;
1387
1388       name = colors[i];
1389       pos = strchr (colors[i], ':');
1390
1391       if (!pos)
1392         continue;
1393
1394       /* Set NUL after color name */
1395       *pos = '\0';
1396       pos++;
1397
1398       /* Find start of color string */
1399       while (*pos == ' ')
1400         pos++;
1401
1402       if (!*pos || !gdk_rgba_parse (&col, pos))
1403         continue;
1404
1405       color = gtk_symbolic_color_new_literal (&col);
1406       gtk_style_properties_map_color (priv->style, name, color);
1407       gtk_symbolic_color_unref (color);
1408     }
1409
1410   font_desc = pango_font_description_from_string (font_name);
1411
1412   /* Unset normal attributes from this description,
1413    * so they do not override theme values */
1414   if (pango_font_description_get_weight (font_desc) == PANGO_WEIGHT_NORMAL)
1415     pango_font_description_unset_fields (font_desc,
1416                                          PANGO_FONT_MASK_WEIGHT);
1417
1418   if (pango_font_description_get_stretch (font_desc) == PANGO_STRETCH_NORMAL)
1419     pango_font_description_unset_fields (font_desc,
1420                                          PANGO_FONT_MASK_STRETCH);
1421
1422   if (pango_font_description_get_variant (font_desc) == PANGO_VARIANT_NORMAL)
1423     pango_font_description_unset_fields (font_desc,
1424                                          PANGO_FONT_MASK_VARIANT);
1425
1426   if (pango_font_description_get_style (font_desc) == PANGO_STYLE_NORMAL)
1427     pango_font_description_unset_fields (font_desc,
1428                                          PANGO_FONT_MASK_STYLE);
1429
1430   gtk_style_properties_set (priv->style, 0,
1431                             "font", font_desc,
1432                             NULL);
1433
1434   pango_font_description_free (font_desc);
1435   g_strfreev (colors);
1436   g_free (color_scheme);
1437   g_free (font_name);
1438 }
1439
1440 static GtkStyleProperties *
1441 gtk_settings_get_style (GtkStyleProvider *provider,
1442                         GtkWidgetPath    *path)
1443 {
1444   GtkSettings *settings;
1445
1446   settings = GTK_SETTINGS (provider);
1447
1448   settings_ensure_style (settings);
1449
1450   return g_object_ref (settings->priv->style);
1451 }
1452
1453 static void
1454 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1455 {
1456   iface->get_style = gtk_settings_get_style;
1457 }
1458
1459 static GtkSymbolicColor *
1460 gtk_settings_style_provider_get_color (GtkStyleProviderPrivate *provider,
1461                                        const char              *name)
1462 {
1463   GtkSettings *settings = GTK_SETTINGS (provider);
1464
1465   settings_ensure_style (settings);
1466
1467   return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style), name);
1468 }
1469
1470 static void
1471 gtk_settings_style_provider_lookup (GtkStyleProviderPrivate *provider,
1472                                     GtkWidgetPath           *path,
1473                                     GtkStateFlags            state,
1474                                     GtkCssLookup            *lookup)
1475 {
1476   GtkSettings *settings = GTK_SETTINGS (provider);
1477
1478   settings_ensure_style (settings);
1479
1480   _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style),
1481                                       path,
1482                                       state,
1483                                       lookup);
1484 }
1485
1486 static void
1487 gtk_settings_provider_private_init (GtkStyleProviderPrivateInterface *iface)
1488 {
1489   iface->get_color = gtk_settings_style_provider_get_color;
1490   iface->lookup = gtk_settings_style_provider_lookup;
1491 }
1492
1493 static void
1494 gtk_settings_finalize (GObject *object)
1495 {
1496   GtkSettings *settings = GTK_SETTINGS (object);
1497   GtkSettingsPrivate *priv = settings->priv;
1498   guint i;
1499
1500   object_list = g_slist_remove (object_list, settings);
1501
1502   for (i = 0; i < class_n_properties; i++)
1503     g_value_unset (&priv->property_values[i].value);
1504   g_free (priv->property_values);
1505
1506   g_datalist_clear (&priv->queued_settings);
1507
1508   if (priv->theme_provider)
1509     g_object_unref (priv->theme_provider);
1510
1511   if (priv->key_theme_provider)
1512     g_object_unref (priv->key_theme_provider);
1513
1514   if (priv->style)
1515     g_object_unref (priv->style);
1516
1517   G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1518 }
1519
1520 static void
1521 settings_init_style (GtkSettings *settings)
1522 {
1523   static GtkCssProvider *css_provider = NULL;
1524
1525   GdkScreen *screen = settings->priv->screen;
1526
1527   /* Add provider for user file */
1528   if (G_UNLIKELY (!css_provider))
1529     {
1530       gchar *css_path;
1531
1532       css_provider = gtk_css_provider_new ();
1533       css_path = g_build_filename (g_get_user_config_dir (),
1534                                    "gtk-3.0",
1535                                    "gtk.css",
1536                                    NULL);
1537
1538       if (g_file_test (css_path,
1539                        G_FILE_TEST_IS_REGULAR))
1540         gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1541
1542       g_free (css_path);
1543     }
1544
1545   gtk_style_context_add_provider_for_screen (screen,
1546                                              GTK_STYLE_PROVIDER (css_provider),
1547                                              GTK_STYLE_PROVIDER_PRIORITY_USER);
1548
1549   gtk_style_context_add_provider_for_screen (screen,
1550                                              GTK_STYLE_PROVIDER (settings),
1551                                              GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1552
1553   settings_update_theme (settings);
1554   settings_update_key_theme (settings);
1555 }
1556
1557 /**
1558  * gtk_settings_get_for_screen:
1559  * @screen: a #GdkScreen.
1560  *
1561  * Gets the #GtkSettings object for @screen, creating it if necessary.
1562  *
1563  * Return value: (transfer none): a #GtkSettings object.
1564  *
1565  * Since: 2.2
1566  */
1567 GtkSettings*
1568 gtk_settings_get_for_screen (GdkScreen *screen)
1569 {
1570   GtkSettings *settings;
1571
1572   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1573
1574   settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1575   if (!settings)
1576     {
1577 #ifdef GDK_WINDOWING_QUARTZ
1578       if (GDK_IS_QUARTZ_SCREEN (screen))
1579         settings = g_object_new (GTK_TYPE_SETTINGS,
1580                                  "gtk-key-theme-name", "Mac",
1581                                  "gtk-shell-shows-app-menu", TRUE,
1582                                  "gtk-shell-shows-menubar", TRUE,
1583                                  NULL);
1584       else
1585 #endif
1586         settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1587       settings->priv->screen = screen;
1588       g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1589                               settings, g_object_unref);
1590
1591       settings_init_style (settings);
1592       settings_update_double_click (settings);
1593       settings_update_cursor_theme (settings);
1594       settings_update_resolution (settings);
1595       settings_update_font_options (settings);
1596       settings_update_color_scheme (settings);
1597     }
1598
1599   return settings;
1600 }
1601
1602 /**
1603  * gtk_settings_get_default:
1604  *
1605  * Gets the #GtkSettings object for the default GDK screen, creating
1606  * it if necessary. See gtk_settings_get_for_screen().
1607  *
1608  * Return value: (transfer none): a #GtkSettings object. If there is no default
1609  *  screen, then returns %NULL.
1610  **/
1611 GtkSettings*
1612 gtk_settings_get_default (void)
1613 {
1614   GdkScreen *screen = gdk_screen_get_default ();
1615
1616   if (screen)
1617     return gtk_settings_get_for_screen (screen);
1618   else
1619     return NULL;
1620 }
1621
1622 static void
1623 gtk_settings_set_property (GObject      *object,
1624                            guint         property_id,
1625                            const GValue *value,
1626                            GParamSpec   *pspec)
1627 {
1628   GtkSettings *settings = GTK_SETTINGS (object);
1629   GtkSettingsPrivate *priv = settings->priv;
1630
1631   g_value_copy (value, &priv->property_values[property_id - 1].value);
1632   priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1633
1634   if (pspec->param_id == PROP_COLOR_SCHEME)
1635     merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1636 }
1637
1638 static void
1639 gtk_settings_get_property (GObject     *object,
1640                            guint        property_id,
1641                            GValue      *value,
1642                            GParamSpec  *pspec)
1643 {
1644   GtkSettings *settings = GTK_SETTINGS (object);
1645   GtkSettingsPrivate *priv = settings->priv;
1646   GType value_type = G_VALUE_TYPE (value);
1647   GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1648
1649   /* handle internal properties */
1650   switch (property_id)
1651     {
1652     case PROP_COLOR_HASH:
1653       g_value_set_boxed (value, get_color_hash (settings));
1654       return;
1655     case PROP_COLOR_SCHEME:
1656       g_value_take_string (value, get_color_scheme (settings));
1657       return;
1658     default: ;
1659     }
1660
1661   /* For enums and strings, we need to get the value as a string,
1662    * not as an int, since we support using names/nicks as the setting
1663    * value.
1664    */
1665   if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1666        !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1667       g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1668       g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1669     {
1670       if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1671           !gdk_screen_get_setting (priv->screen, pspec->name, value))
1672         g_value_copy (&priv->property_values[property_id - 1].value, value);
1673       else
1674         g_param_value_validate (pspec, value);
1675     }
1676   else
1677     {
1678       GValue val = G_VALUE_INIT;
1679
1680       /* Try to get xsetting as a string and parse it. */
1681
1682       g_value_init (&val, G_TYPE_STRING);
1683
1684       if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1685           !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1686         {
1687           g_value_copy (&priv->property_values[property_id - 1].value, value);
1688         }
1689       else
1690         {
1691           GValue tmp_value = G_VALUE_INIT;
1692           GValue gstring_value = G_VALUE_INIT;
1693           GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1694
1695           g_value_init (&gstring_value, G_TYPE_GSTRING);
1696           g_value_take_boxed (&gstring_value,
1697                               g_string_new (g_value_get_string (&val)));
1698
1699           g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1700
1701           if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1702                                                      pspec, &tmp_value))
1703             {
1704               g_value_copy (&tmp_value, value);
1705               g_param_value_validate (pspec, value);
1706             }
1707           else
1708             {
1709               g_value_copy (&priv->property_values[property_id - 1].value, value);
1710             }
1711
1712           g_value_unset (&gstring_value);
1713           g_value_unset (&tmp_value);
1714         }
1715
1716       g_value_unset (&val);
1717     }
1718 }
1719
1720 static void
1721 settings_invalidate_style (GtkSettings *settings)
1722 {
1723   GtkSettingsPrivate *priv = settings->priv;
1724
1725   if (priv->style)
1726     {
1727       g_object_unref (priv->style);
1728       priv->style = NULL;
1729     }
1730 }
1731
1732 static void
1733 gtk_settings_notify (GObject    *object,
1734                      GParamSpec *pspec)
1735 {
1736   GtkSettings *settings = GTK_SETTINGS (object);
1737   GtkSettingsPrivate *priv = settings->priv;
1738   guint property_id = pspec->param_id;
1739
1740   if (priv->screen == NULL) /* initialization */
1741     return;
1742
1743   switch (property_id)
1744     {
1745     case PROP_MODULES:
1746       settings_update_modules (settings);
1747       break;
1748     case PROP_DOUBLE_CLICK_TIME:
1749     case PROP_DOUBLE_CLICK_DISTANCE:
1750       settings_update_double_click (settings);
1751       break;
1752     case PROP_COLOR_SCHEME:
1753       settings_update_color_scheme (settings);
1754       settings_invalidate_style (settings);
1755       gtk_style_context_reset_widgets (priv->screen);
1756       break;
1757     case PROP_FONT_NAME:
1758       settings_invalidate_style (settings);
1759       gtk_style_context_reset_widgets (priv->screen);
1760       break;
1761     case PROP_KEY_THEME_NAME:
1762       settings_update_key_theme (settings);
1763       break;
1764     case PROP_THEME_NAME:
1765     case PROP_APPLICATION_PREFER_DARK_THEME:
1766       settings_update_theme (settings);
1767       break;
1768     case PROP_XFT_DPI:
1769       settings_update_resolution (settings);
1770       /* This is a hack because with gtk_rc_reset_styles() doesn't get
1771        * widgets with gtk_widget_style_set(), and also causes more
1772        * recomputation than necessary.
1773        */
1774       gtk_style_context_reset_widgets (priv->screen);
1775       break;
1776     case PROP_XFT_ANTIALIAS:
1777     case PROP_XFT_HINTING:
1778     case PROP_XFT_HINTSTYLE:
1779     case PROP_XFT_RGBA:
1780       settings_update_font_options (settings);
1781       gtk_style_context_reset_widgets (priv->screen);
1782       break;
1783     case PROP_FONTCONFIG_TIMESTAMP:
1784       if (settings_update_fontconfig (settings))
1785         gtk_style_context_reset_widgets (priv->screen);
1786       break;
1787     case PROP_CURSOR_THEME_NAME:
1788     case PROP_CURSOR_THEME_SIZE:
1789       settings_update_cursor_theme (settings);
1790       break;
1791     }
1792 }
1793
1794 gboolean
1795 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1796                              const GValue       *src_value,
1797                              GParamSpec         *pspec,
1798                              GValue             *dest_value)
1799 {
1800   gboolean success = FALSE;
1801
1802   g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1803
1804   if (parser)
1805     {
1806       GString *gstring;
1807       gboolean free_gstring = TRUE;
1808
1809       if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1810         {
1811           gstring = g_value_get_boxed (src_value);
1812           free_gstring = FALSE;
1813         }
1814       else if (G_VALUE_HOLDS_LONG (src_value))
1815         {
1816           gstring = g_string_new (NULL);
1817           g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1818         }
1819       else if (G_VALUE_HOLDS_DOUBLE (src_value))
1820         {
1821           gstring = g_string_new (NULL);
1822           g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1823         }
1824       else if (G_VALUE_HOLDS_STRING (src_value))
1825         {
1826           gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1827
1828           gstring = g_string_new (NULL);
1829           g_string_append_c (gstring, '\"');
1830           g_string_append (gstring, tstr);
1831           g_string_append_c (gstring, '\"');
1832           g_free (tstr);
1833         }
1834       else
1835         {
1836           g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1837           gstring = NULL; /* silence compiler */
1838         }
1839
1840       success = (parser (pspec, gstring, dest_value) &&
1841                  !g_param_value_validate (pspec, dest_value));
1842
1843       if (free_gstring)
1844         g_string_free (gstring, TRUE);
1845     }
1846   else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1847     {
1848       if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1849         {
1850           GString *gstring = g_value_get_boxed (src_value);
1851
1852           g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1853           success = !g_param_value_validate (pspec, dest_value);
1854         }
1855     }
1856   else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1857     success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1858
1859   return success;
1860 }
1861
1862 static void
1863 apply_queued_setting (GtkSettings             *settings,
1864                       GParamSpec              *pspec,
1865                       GtkSettingsValuePrivate *qvalue)
1866 {
1867   GtkSettingsPrivate *priv = settings->priv;
1868   GValue tmp_value = G_VALUE_INIT;
1869   GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1870
1871   g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1872   if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1873                                    pspec, &tmp_value))
1874     {
1875       if (pspec->param_id == PROP_COLOR_SCHEME)
1876         merge_color_scheme (settings, &tmp_value, qvalue->source);
1877
1878       if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1879         {
1880           g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1881           priv->property_values[pspec->param_id - 1].source = qvalue->source;
1882           g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1883         }
1884
1885     }
1886   else
1887     {
1888       gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1889
1890       g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1891                  qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1892                  pspec->name,
1893                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1894                  debug,
1895                  G_VALUE_TYPE_NAME (&tmp_value));
1896       g_free (debug);
1897     }
1898   g_value_unset (&tmp_value);
1899 }
1900
1901 static guint
1902 settings_install_property_parser (GtkSettingsClass   *class,
1903                                   GParamSpec         *pspec,
1904                                   GtkRcPropertyParser parser)
1905 {
1906   GSList *node, *next;
1907
1908   switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1909     {
1910     case G_TYPE_BOOLEAN:
1911     case G_TYPE_UCHAR:
1912     case G_TYPE_CHAR:
1913     case G_TYPE_UINT:
1914     case G_TYPE_INT:
1915     case G_TYPE_ULONG:
1916     case G_TYPE_LONG:
1917     case G_TYPE_FLOAT:
1918     case G_TYPE_DOUBLE:
1919     case G_TYPE_STRING:
1920     case G_TYPE_ENUM:
1921       break;
1922     case G_TYPE_BOXED:
1923       if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1924         {
1925           break;
1926         }
1927       /* fall through */
1928     default:
1929       if (!parser)
1930         {
1931           g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1932                      pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1933           return 0;
1934         }
1935     }
1936   if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1937     {
1938       g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1939                  pspec->name);
1940       return 0;
1941     }
1942
1943   for (node = object_list; node; node = node->next)
1944     g_object_freeze_notify (node->data);
1945
1946   g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1947   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1948
1949   for (node = object_list; node; node = node->next)
1950     {
1951       GtkSettings *settings = node->data;
1952       GtkSettingsPrivate *priv = settings->priv;
1953       GtkSettingsValuePrivate *qvalue;
1954
1955       priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1956       priv->property_values[class_n_properties - 1].value.g_type = 0;
1957       g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1958       g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1959       priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1960       g_object_notify (G_OBJECT (settings), pspec->name);
1961
1962       qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1963       if (qvalue)
1964         apply_queued_setting (settings, pspec, qvalue);
1965     }
1966
1967   for (node = object_list; node; node = next)
1968     {
1969       next = node->next;
1970       g_object_thaw_notify (node->data);
1971     }
1972
1973   return class_n_properties;
1974 }
1975
1976 GtkRcPropertyParser
1977 _gtk_rc_property_parser_from_type (GType type)
1978 {
1979   if (type == GDK_TYPE_COLOR)
1980     return gtk_rc_property_parse_color;
1981   else if (type == GTK_TYPE_REQUISITION)
1982     return gtk_rc_property_parse_requisition;
1983   else if (type == GTK_TYPE_BORDER)
1984     return gtk_rc_property_parse_border;
1985   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1986     return gtk_rc_property_parse_enum;
1987   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1988     return gtk_rc_property_parse_flags;
1989   else
1990     return NULL;
1991 }
1992
1993 void
1994 gtk_settings_install_property (GParamSpec *pspec)
1995 {
1996   static GtkSettingsClass *klass = NULL;
1997
1998   GtkRcPropertyParser parser;
1999
2000   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2001
2002   if (! klass)
2003     klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2004
2005   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
2006
2007   settings_install_property_parser (klass, pspec, parser);
2008 }
2009
2010 /**
2011  * gtk_settings_install_property_parser:
2012  * @pspec:
2013  * @parser: (scope call):
2014  */
2015 void
2016 gtk_settings_install_property_parser (GParamSpec          *pspec,
2017                                       GtkRcPropertyParser  parser)
2018 {
2019   static GtkSettingsClass *klass = NULL;
2020
2021   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2022   g_return_if_fail (parser != NULL);
2023
2024   if (! klass)
2025     klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2026
2027   settings_install_property_parser (klass, pspec, parser);
2028 }
2029
2030 static void
2031 free_value (gpointer data)
2032 {
2033   GtkSettingsValuePrivate *qvalue = data;
2034
2035   g_value_unset (&qvalue->public.value);
2036   g_free (qvalue->public.origin);
2037   g_slice_free (GtkSettingsValuePrivate, qvalue);
2038 }
2039
2040 static void
2041 gtk_settings_set_property_value_internal (GtkSettings            *settings,
2042                                           const gchar            *prop_name,
2043                                           const GtkSettingsValue *new_value,
2044                                           GtkSettingsSource       source)
2045 {
2046   GtkSettingsPrivate *priv = settings->priv;
2047   GtkSettingsValuePrivate *qvalue;
2048   GParamSpec *pspec;
2049   gchar *name;
2050   GQuark name_quark;
2051
2052   if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
2053       !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
2054       !G_VALUE_HOLDS_STRING (&new_value->value) &&
2055       !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
2056     {
2057       g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
2058       return;
2059     }
2060
2061   name = g_strdup (prop_name);
2062   g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
2063   name_quark = g_quark_from_string (name);
2064   g_free (name);
2065
2066   qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
2067   if (!qvalue)
2068     {
2069       qvalue = g_slice_new0 (GtkSettingsValuePrivate);
2070       g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
2071     }
2072   else
2073     {
2074       g_free (qvalue->public.origin);
2075       g_value_unset (&qvalue->public.value);
2076     }
2077   qvalue->public.origin = g_strdup (new_value->origin);
2078   g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
2079   g_value_copy (&new_value->value, &qvalue->public.value);
2080   qvalue->source = source;
2081   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
2082   if (pspec)
2083     apply_queued_setting (settings, pspec, qvalue);
2084 }
2085
2086 void
2087 gtk_settings_set_property_value (GtkSettings            *settings,
2088                                  const gchar            *prop_name,
2089                                  const GtkSettingsValue *new_value)
2090 {
2091   g_return_if_fail (GTK_SETTINGS (settings));
2092   g_return_if_fail (prop_name != NULL);
2093   g_return_if_fail (new_value != NULL);
2094
2095   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2096                                             GTK_SETTINGS_SOURCE_APPLICATION);
2097 }
2098
2099 void
2100 _gtk_settings_set_property_value_from_rc (GtkSettings            *settings,
2101                                           const gchar            *prop_name,
2102                                           const GtkSettingsValue *new_value)
2103 {
2104   g_return_if_fail (GTK_SETTINGS (settings));
2105   g_return_if_fail (prop_name != NULL);
2106   g_return_if_fail (new_value != NULL);
2107
2108   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2109                                             GTK_SETTINGS_SOURCE_THEME);
2110 }
2111
2112 void
2113 gtk_settings_set_string_property (GtkSettings *settings,
2114                                   const gchar *name,
2115                                   const gchar *v_string,
2116                                   const gchar *origin)
2117 {
2118   GtkSettingsValue svalue = { NULL, { 0, }, };
2119
2120   g_return_if_fail (GTK_SETTINGS (settings));
2121   g_return_if_fail (name != NULL);
2122   g_return_if_fail (v_string != NULL);
2123
2124   svalue.origin = (gchar*) origin;
2125   g_value_init (&svalue.value, G_TYPE_STRING);
2126   g_value_set_static_string (&svalue.value, v_string);
2127   gtk_settings_set_property_value (settings, name, &svalue);
2128   g_value_unset (&svalue.value);
2129 }
2130
2131 void
2132 gtk_settings_set_long_property (GtkSettings *settings,
2133                                 const gchar *name,
2134                                 glong        v_long,
2135                                 const gchar *origin)
2136 {
2137   GtkSettingsValue svalue = { NULL, { 0, }, };
2138
2139   g_return_if_fail (GTK_SETTINGS (settings));
2140   g_return_if_fail (name != NULL);
2141
2142   svalue.origin = (gchar*) origin;
2143   g_value_init (&svalue.value, G_TYPE_LONG);
2144   g_value_set_long (&svalue.value, v_long);
2145   gtk_settings_set_property_value (settings, name, &svalue);
2146   g_value_unset (&svalue.value);
2147 }
2148
2149 void
2150 gtk_settings_set_double_property (GtkSettings *settings,
2151                                   const gchar *name,
2152                                   gdouble      v_double,
2153                                   const gchar *origin)
2154 {
2155   GtkSettingsValue svalue = { NULL, { 0, }, };
2156
2157   g_return_if_fail (GTK_SETTINGS (settings));
2158   g_return_if_fail (name != NULL);
2159
2160   svalue.origin = (gchar*) origin;
2161   g_value_init (&svalue.value, G_TYPE_DOUBLE);
2162   g_value_set_double (&svalue.value, v_double);
2163   gtk_settings_set_property_value (settings, name, &svalue);
2164   g_value_unset (&svalue.value);
2165 }
2166
2167 /**
2168  * gtk_rc_property_parse_color:
2169  * @pspec: a #GParamSpec
2170  * @gstring: the #GString to be parsed
2171  * @property_value: a #GValue which must hold #GdkColor values.
2172  *
2173  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2174  * or gtk_widget_class_install_style_property_parser() which parses a
2175  * color given either by its name or in the form
2176  * <literal>{ red, green, blue }</literal> where %red, %green and
2177  * %blue are integers between 0 and 65535 or floating-point numbers
2178  * between 0 and 1.
2179  *
2180  * Return value: %TRUE if @gstring could be parsed and @property_value
2181  * has been set to the resulting #GdkColor.
2182  **/
2183 gboolean
2184 gtk_rc_property_parse_color (const GParamSpec *pspec,
2185                              const GString    *gstring,
2186                              GValue           *property_value)
2187 {
2188   GdkColor color = { 0, 0, 0, 0, };
2189   GScanner *scanner;
2190   gboolean success;
2191
2192   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2193   g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2194
2195   scanner = gtk_rc_scanner_new ();
2196   g_scanner_input_text (scanner, gstring->str, gstring->len);
2197   if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2198       g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2199     {
2200       g_value_set_boxed (property_value, &color);
2201       success = TRUE;
2202     }
2203   else
2204     success = FALSE;
2205   g_scanner_destroy (scanner);
2206
2207   return success;
2208 }
2209
2210 /**
2211  * gtk_rc_property_parse_enum:
2212  * @pspec: a #GParamSpec
2213  * @gstring: the #GString to be parsed
2214  * @property_value: a #GValue which must hold enum values.
2215  *
2216  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2217  * or gtk_widget_class_install_style_property_parser() which parses a single
2218  * enumeration value.
2219  *
2220  * The enumeration value can be specified by its name, its nickname or
2221  * its numeric value. For consistency with flags parsing, the value
2222  * may be surrounded by parentheses.
2223  *
2224  * Return value: %TRUE if @gstring could be parsed and @property_value
2225  * has been set to the resulting #GEnumValue.
2226  **/
2227 gboolean
2228 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2229                             const GString    *gstring,
2230                             GValue           *property_value)
2231 {
2232   gboolean need_closing_brace = FALSE, success = FALSE;
2233   GScanner *scanner;
2234   GEnumValue *enum_value = NULL;
2235
2236   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2237   g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2238
2239   scanner = gtk_rc_scanner_new ();
2240   g_scanner_input_text (scanner, gstring->str, gstring->len);
2241
2242   /* we just want to parse _one_ value, but for consistency with flags parsing
2243    * we support optional parenthesis
2244    */
2245   g_scanner_get_next_token (scanner);
2246   if (scanner->token == '(')
2247     {
2248       need_closing_brace = TRUE;
2249       g_scanner_get_next_token (scanner);
2250     }
2251   if (scanner->token == G_TOKEN_IDENTIFIER)
2252     {
2253       GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2254
2255       enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2256       if (!enum_value)
2257         enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2258       if (enum_value)
2259         {
2260           g_value_set_enum (property_value, enum_value->value);
2261           success = TRUE;
2262         }
2263     }
2264   else if (scanner->token == G_TOKEN_INT)
2265     {
2266       g_value_set_enum (property_value, scanner->value.v_int);
2267       success = TRUE;
2268     }
2269   if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2270     success = FALSE;
2271   if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2272     success = FALSE;
2273
2274   g_scanner_destroy (scanner);
2275
2276   return success;
2277 }
2278
2279 static guint
2280 parse_flags_value (GScanner    *scanner,
2281                    GFlagsClass *class,
2282                    guint       *number)
2283 {
2284   g_scanner_get_next_token (scanner);
2285   if (scanner->token == G_TOKEN_IDENTIFIER)
2286     {
2287       GFlagsValue *flags_value;
2288
2289       flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2290       if (!flags_value)
2291         flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2292       if (flags_value)
2293         {
2294           *number |= flags_value->value;
2295           return G_TOKEN_NONE;
2296         }
2297     }
2298   else if (scanner->token == G_TOKEN_INT)
2299     {
2300       *number |= scanner->value.v_int;
2301       return G_TOKEN_NONE;
2302     }
2303   return G_TOKEN_IDENTIFIER;
2304 }
2305
2306 /**
2307  * gtk_rc_property_parse_flags:
2308  * @pspec: a #GParamSpec
2309  * @gstring: the #GString to be parsed
2310  * @property_value: a #GValue which must hold flags values.
2311  *
2312  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2313  * or gtk_widget_class_install_style_property_parser() which parses flags.
2314  *
2315  * Flags can be specified by their name, their nickname or
2316  * numerically. Multiple flags can be specified in the form
2317  * <literal>"( flag1 | flag2 | ... )"</literal>.
2318  *
2319  * Return value: %TRUE if @gstring could be parsed and @property_value
2320  * has been set to the resulting flags value.
2321  **/
2322 gboolean
2323 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2324                              const GString    *gstring,
2325                              GValue           *property_value)
2326 {
2327   GFlagsClass *class;
2328    gboolean success = FALSE;
2329   GScanner *scanner;
2330
2331   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2332   g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2333
2334   class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2335   scanner = gtk_rc_scanner_new ();
2336   g_scanner_input_text (scanner, gstring->str, gstring->len);
2337
2338   /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2339   if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2340       scanner->next_token == G_TOKEN_INT)
2341     {
2342       guint token, flags_value = 0;
2343
2344       token = parse_flags_value (scanner, class, &flags_value);
2345
2346       if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2347         {
2348           success = TRUE;
2349           g_value_set_flags (property_value, flags_value);
2350         }
2351
2352     }
2353   else if (g_scanner_get_next_token (scanner) == '(')
2354     {
2355       guint token, flags_value = 0;
2356
2357       /* parse first value */
2358       token = parse_flags_value (scanner, class, &flags_value);
2359
2360       /* parse nth values, preceeded by '|' */
2361       while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2362         token = parse_flags_value (scanner, class, &flags_value);
2363
2364       /* done, last token must have closed expression */
2365       if (token == G_TOKEN_NONE && scanner->token == ')' &&
2366           g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2367         {
2368           g_value_set_flags (property_value, flags_value);
2369           success = TRUE;
2370         }
2371     }
2372   g_scanner_destroy (scanner);
2373
2374   return success;
2375 }
2376
2377 static gboolean
2378 get_braced_int (GScanner *scanner,
2379                 gboolean  first,
2380                 gboolean  last,
2381                 gint     *value)
2382 {
2383   if (first)
2384     {
2385       g_scanner_get_next_token (scanner);
2386       if (scanner->token != '{')
2387         return FALSE;
2388     }
2389
2390   g_scanner_get_next_token (scanner);
2391   if (scanner->token != G_TOKEN_INT)
2392     return FALSE;
2393
2394   *value = scanner->value.v_int;
2395
2396   if (last)
2397     {
2398       g_scanner_get_next_token (scanner);
2399       if (scanner->token != '}')
2400         return FALSE;
2401     }
2402   else
2403     {
2404       g_scanner_get_next_token (scanner);
2405       if (scanner->token != ',')
2406         return FALSE;
2407     }
2408
2409   return TRUE;
2410 }
2411
2412 /**
2413  * gtk_rc_property_parse_requisition:
2414  * @pspec: a #GParamSpec
2415  * @gstring: the #GString to be parsed
2416  * @property_value: a #GValue which must hold boxed values.
2417  *
2418  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2419  * or gtk_widget_class_install_style_property_parser() which parses a
2420  * requisition in the form
2421  * <literal>"{ width, height }"</literal> for integers %width and %height.
2422  *
2423  * Return value: %TRUE if @gstring could be parsed and @property_value
2424  * has been set to the resulting #GtkRequisition.
2425  **/
2426 gboolean
2427 gtk_rc_property_parse_requisition  (const GParamSpec *pspec,
2428                                     const GString    *gstring,
2429                                     GValue           *property_value)
2430 {
2431   GtkRequisition requisition;
2432   GScanner *scanner;
2433   gboolean success = FALSE;
2434
2435   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2436   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2437
2438   scanner = gtk_rc_scanner_new ();
2439   g_scanner_input_text (scanner, gstring->str, gstring->len);
2440
2441   if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2442       get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2443     {
2444       g_value_set_boxed (property_value, &requisition);
2445       success = TRUE;
2446     }
2447
2448   g_scanner_destroy (scanner);
2449
2450   return success;
2451 }
2452
2453 /**
2454  * gtk_rc_property_parse_border:
2455  * @pspec: a #GParamSpec
2456  * @gstring: the #GString to be parsed
2457  * @property_value: a #GValue which must hold boxed values.
2458  *
2459  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2460  * or gtk_widget_class_install_style_property_parser() which parses
2461  * borders in the form
2462  * <literal>"{ left, right, top, bottom }"</literal> for integers
2463  * %left, %right, %top and %bottom.
2464  *
2465  * Return value: %TRUE if @gstring could be parsed and @property_value
2466  * has been set to the resulting #GtkBorder.
2467  **/
2468 gboolean
2469 gtk_rc_property_parse_border (const GParamSpec *pspec,
2470                               const GString    *gstring,
2471                               GValue           *property_value)
2472 {
2473   GtkBorder border;
2474   GScanner *scanner;
2475   gboolean success = FALSE;
2476   int left, right, top, bottom;
2477
2478   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2479   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2480
2481   scanner = gtk_rc_scanner_new ();
2482   g_scanner_input_text (scanner, gstring->str, gstring->len);
2483
2484   if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2485       get_braced_int (scanner, FALSE, FALSE, &right) &&
2486       get_braced_int (scanner, FALSE, FALSE, &top) &&
2487       get_braced_int (scanner, FALSE, TRUE, &bottom))
2488     {
2489       border.left = left;
2490       border.right = right;
2491       border.top = top;
2492       border.bottom = bottom;
2493       g_value_set_boxed (property_value, &border);
2494       success = TRUE;
2495     }
2496
2497   g_scanner_destroy (scanner);
2498
2499   return success;
2500 }
2501
2502 void
2503 _gtk_settings_handle_event (GdkEventSetting *event)
2504 {
2505   GdkScreen *screen;
2506   GtkSettings *settings;
2507   GParamSpec *pspec;
2508   guint property_id;
2509
2510   screen = gdk_window_get_screen (event->window);
2511   settings = gtk_settings_get_for_screen (screen);
2512   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2513
2514   if (pspec)
2515     {
2516       property_id = pspec->param_id;
2517
2518       if (property_id == PROP_COLOR_SCHEME)
2519         {
2520           GValue value = G_VALUE_INIT;
2521
2522           g_value_init (&value, G_TYPE_STRING);
2523           if (!gdk_screen_get_setting (screen, pspec->name, &value))
2524             g_value_set_static_string (&value, "");
2525           merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2526           g_value_unset (&value);
2527         }
2528       g_object_notify (G_OBJECT (settings), pspec->name);
2529    }
2530 }
2531
2532 static void
2533 reset_rc_values_foreach (GQuark   key_id,
2534                          gpointer data,
2535                          gpointer user_data)
2536 {
2537   GtkSettingsValuePrivate *qvalue = data;
2538   GSList **to_reset = user_data;
2539
2540   if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2541     *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2542 }
2543
2544 void
2545 _gtk_settings_reset_rc_values (GtkSettings *settings)
2546 {
2547   GtkSettingsPrivate *priv = settings->priv;
2548   GSList *to_reset = NULL;
2549   GSList *tmp_list;
2550   GParamSpec **pspecs, **p;
2551   gint i;
2552
2553   /* Remove any queued settings */
2554   g_datalist_foreach (&priv->queued_settings,
2555                       reset_rc_values_foreach,
2556                       &to_reset);
2557
2558   for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2559     {
2560       GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2561       g_datalist_id_remove_data (&priv->queued_settings, key_id);
2562     }
2563
2564    g_slist_free (to_reset);
2565
2566   /* Now reset the active settings
2567    */
2568   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2569   i = 0;
2570
2571   g_object_freeze_notify (G_OBJECT (settings));
2572   for (p = pspecs; *p; p++)
2573     {
2574       if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2575         {
2576           GParamSpec *pspec = *p;
2577
2578           g_param_value_set_default (pspec, &priv->property_values[i].value);
2579           g_object_notify (G_OBJECT (settings), pspec->name);
2580         }
2581       i++;
2582     }
2583   g_object_thaw_notify (G_OBJECT (settings));
2584   g_free (pspecs);
2585 }
2586
2587 static void
2588 settings_update_double_click (GtkSettings *settings)
2589 {
2590   GtkSettingsPrivate *priv = settings->priv;
2591
2592   if (gdk_screen_get_number (priv->screen) == 0)
2593     {
2594       GdkDisplay *display = gdk_screen_get_display (priv->screen);
2595       gint double_click_time;
2596       gint double_click_distance;
2597
2598       g_object_get (settings,
2599                     "gtk-double-click-time", &double_click_time,
2600                     "gtk-double-click-distance", &double_click_distance,
2601                     NULL);
2602
2603       gdk_display_set_double_click_time (display, double_click_time);
2604       gdk_display_set_double_click_distance (display, double_click_distance);
2605     }
2606 }
2607
2608 static void
2609 settings_update_modules (GtkSettings *settings)
2610 {
2611   gchar *modules;
2612
2613   g_object_get (settings,
2614                 "gtk-modules", &modules,
2615                 NULL);
2616
2617   _gtk_modules_settings_changed (settings, modules);
2618
2619   g_free (modules);
2620 }
2621
2622 static void
2623 settings_update_cursor_theme (GtkSettings *settings)
2624 {
2625 #ifdef GDK_WINDOWING_X11
2626   GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2627   gchar *theme = NULL;
2628   gint size = 0;
2629
2630   if (GDK_IS_X11_DISPLAY (display))
2631     {
2632       g_object_get (settings,
2633                     "gtk-cursor-theme-name", &theme,
2634                     "gtk-cursor-theme-size", &size,
2635                     NULL);
2636
2637       gdk_x11_display_set_cursor_theme (display, theme, size);
2638
2639       g_free (theme);
2640     }
2641 #endif
2642 }
2643
2644 static void
2645 settings_update_font_options (GtkSettings *settings)
2646 {
2647   GtkSettingsPrivate *priv = settings->priv;
2648   gint hinting;
2649   gchar *hint_style_str;
2650   cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2651   gint antialias;
2652   cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2653   gchar *rgba_str;
2654   cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2655   cairo_font_options_t *options;
2656
2657   g_object_get (settings,
2658                 "gtk-xft-antialias", &antialias,
2659                 "gtk-xft-hinting", &hinting,
2660                 "gtk-xft-hintstyle", &hint_style_str,
2661                 "gtk-xft-rgba", &rgba_str,
2662                 NULL);
2663
2664   options = cairo_font_options_create ();
2665
2666   cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2667
2668   if (hinting >= 0 && !hinting)
2669     {
2670       hint_style = CAIRO_HINT_STYLE_NONE;
2671     }
2672   else if (hint_style_str)
2673     {
2674       if (strcmp (hint_style_str, "hintnone") == 0)
2675         hint_style = CAIRO_HINT_STYLE_NONE;
2676       else if (strcmp (hint_style_str, "hintslight") == 0)
2677         hint_style = CAIRO_HINT_STYLE_SLIGHT;
2678       else if (strcmp (hint_style_str, "hintmedium") == 0)
2679         hint_style = CAIRO_HINT_STYLE_MEDIUM;
2680       else if (strcmp (hint_style_str, "hintfull") == 0)
2681         hint_style = CAIRO_HINT_STYLE_FULL;
2682     }
2683
2684   g_free (hint_style_str);
2685
2686   cairo_font_options_set_hint_style (options, hint_style);
2687
2688   if (rgba_str)
2689     {
2690       if (strcmp (rgba_str, "rgb") == 0)
2691         subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2692       else if (strcmp (rgba_str, "bgr") == 0)
2693         subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2694       else if (strcmp (rgba_str, "vrgb") == 0)
2695         subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2696       else if (strcmp (rgba_str, "vbgr") == 0)
2697         subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2698
2699       g_free (rgba_str);
2700     }
2701
2702   cairo_font_options_set_subpixel_order (options, subpixel_order);
2703
2704   if (antialias >= 0 && !antialias)
2705     antialias_mode = CAIRO_ANTIALIAS_NONE;
2706   else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2707     antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2708   else if (antialias >= 0)
2709     antialias_mode = CAIRO_ANTIALIAS_GRAY;
2710
2711   cairo_font_options_set_antialias (options, antialias_mode);
2712
2713   gdk_screen_set_font_options (priv->screen, options);
2714
2715   cairo_font_options_destroy (options);
2716 }
2717
2718 static gboolean
2719 settings_update_fontconfig (GtkSettings *settings)
2720 {
2721 #ifdef GDK_WINDOWING_X11
2722   static guint    last_update_timestamp;
2723   static gboolean last_update_needed;
2724
2725   guint timestamp;
2726
2727   g_object_get (settings,
2728                 "gtk-fontconfig-timestamp", &timestamp,
2729                 NULL);
2730
2731   /* if timestamp is the same as last_update_timestamp, we already have
2732    * updated fontconig on this timestamp (another screen requested it perhaps?),
2733    * just return the cached result.*/
2734
2735   if (timestamp != last_update_timestamp)
2736     {
2737       PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2738       gboolean update_needed = FALSE;
2739
2740       /* bug 547680 */
2741       if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2742         {
2743           pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2744           if (FcInitReinitialize ())
2745             update_needed = TRUE;
2746         }
2747
2748       last_update_timestamp = timestamp;
2749       last_update_needed = update_needed;
2750     }
2751
2752   return last_update_needed;
2753 #else
2754   return FALSE;
2755 #endif /* GDK_WINDOWING_X11 */
2756 }
2757
2758 static void
2759 settings_update_resolution (GtkSettings *settings)
2760 {
2761   GtkSettingsPrivate *priv = settings->priv;
2762   gint dpi_int;
2763   gdouble dpi;
2764
2765   g_object_get (settings,
2766                 "gtk-xft-dpi", &dpi_int,
2767                 NULL);
2768
2769   if (dpi_int > 0)
2770     dpi = dpi_int / 1024.;
2771   else
2772     dpi = -1.;
2773
2774   gdk_screen_set_resolution (priv->screen, dpi);
2775 }
2776
2777 typedef struct
2778 {
2779   GHashTable *color_hash;
2780   GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2781   gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2782 } ColorSchemeData;
2783
2784 static void
2785 color_scheme_data_free (ColorSchemeData *data)
2786 {
2787   gint i;
2788
2789   g_hash_table_unref (data->color_hash);
2790
2791   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2792     {
2793       if (data->tables[i])
2794         g_hash_table_unref (data->tables[i]);
2795       g_free (data->lastentry[i]);
2796     }
2797
2798   g_slice_free (ColorSchemeData, data);
2799 }
2800
2801 static void
2802 settings_update_color_scheme (GtkSettings *settings)
2803 {
2804   if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2805     {
2806       GtkSettingsPrivate *priv = settings->priv;
2807       ColorSchemeData *data;
2808       GValue value = G_VALUE_INIT;
2809
2810       data = g_slice_new0 (ColorSchemeData);
2811       data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2812                                                 (GDestroyNotify) gdk_color_free);
2813       g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2814                               data, (GDestroyNotify) color_scheme_data_free);
2815
2816       g_value_init (&value, G_TYPE_STRING);
2817       if (priv->screen && gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2818         {
2819           merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2820           g_value_unset (&value);
2821         }
2822    }
2823 }
2824
2825 static void
2826 settings_update_provider (GdkScreen       *screen,
2827                           GtkCssProvider **old,
2828                           GtkCssProvider  *new)
2829 {
2830   if (*old != new)
2831     {
2832       if (*old)
2833         {
2834           gtk_style_context_remove_provider_for_screen (screen,
2835                                                         GTK_STYLE_PROVIDER (*old));
2836           g_object_unref (*old);
2837           *old = NULL;
2838         }
2839
2840       if (new)
2841         {
2842           gtk_style_context_add_provider_for_screen (screen,
2843                                                      GTK_STYLE_PROVIDER (new),
2844                                                      GTK_STYLE_PROVIDER_PRIORITY_THEME);
2845           *old = g_object_ref (new);
2846         }
2847     }
2848 }
2849
2850 static void
2851 settings_update_theme (GtkSettings *settings)
2852 {
2853   GtkSettingsPrivate *priv = settings->priv;
2854   GtkCssProvider *provider = NULL;
2855   gboolean prefer_dark_theme;
2856   gchar *theme_name;
2857
2858   g_object_get (settings,
2859                 "gtk-theme-name", &theme_name,
2860                 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2861                 NULL);
2862
2863   if (theme_name && *theme_name)
2864     {
2865       if (prefer_dark_theme)
2866         provider = gtk_css_provider_get_named (theme_name, "dark");
2867
2868       if (!provider)
2869         provider = gtk_css_provider_get_named (theme_name, NULL);
2870     }
2871
2872   /* If we didn't find the named theme, fall back */
2873   if (!provider)
2874     provider = gtk_css_provider_get_named ("Raleigh", NULL);
2875
2876   settings_update_provider (priv->screen, &priv->theme_provider, provider);
2877
2878   if (theme_name && *theme_name)
2879     {
2880       gchar *theme_dir;
2881       gchar *path;
2882
2883       /* reload per-theme settings */
2884       theme_dir = _gtk_css_provider_get_theme_dir ();
2885       path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2886
2887      if (g_file_test (path, G_FILE_TEST_EXISTS))
2888        gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2889
2890       g_free (theme_dir);
2891       g_free (path);
2892     }
2893
2894   g_free (theme_name);
2895 }
2896
2897 static void
2898 settings_update_key_theme (GtkSettings *settings)
2899 {
2900   GtkSettingsPrivate *priv = settings->priv;
2901   GtkCssProvider *provider = NULL;
2902   gchar *key_theme_name;
2903
2904   g_object_get (settings,
2905                 "gtk-key-theme-name", &key_theme_name,
2906                 NULL);
2907
2908   if (key_theme_name && *key_theme_name)
2909     provider = gtk_css_provider_get_named (key_theme_name, "keys");
2910
2911   settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2912   g_free (key_theme_name);
2913 }
2914
2915 static gboolean
2916 add_color_to_hash (gchar      *name,
2917                    GdkColor   *color,
2918                    GHashTable *target)
2919 {
2920   GdkColor *old;
2921
2922   old = g_hash_table_lookup (target, name);
2923   if (!old || !gdk_color_equal (old, color))
2924     {
2925       g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2926
2927       return TRUE;
2928     }
2929
2930   return FALSE;
2931 }
2932
2933 static gboolean
2934 add_colors_to_hash_from_string (GHashTable  *hash,
2935                                 const gchar *colors)
2936 {
2937   gchar *s, *p, *name;
2938   GdkColor color;
2939   gboolean changed = FALSE;
2940   gchar *copy;
2941
2942   copy = g_strdup (colors);
2943   s = copy;
2944   while (s && *s)
2945     {
2946       name = s;
2947       p = strchr (s, ':');
2948       if (p)
2949         {
2950           *p = '\0';
2951           p++;
2952         }
2953       else
2954         break;
2955
2956       while (*p == ' ')
2957         p++;
2958
2959       s = p;
2960       while (*s)
2961         {
2962           if (*s == '\n' || *s == ';')
2963             {
2964               *s = '\0';
2965               s++;
2966               break;
2967             }
2968           s++;
2969         }
2970
2971       if (gdk_color_parse (p, &color))
2972         changed |= add_color_to_hash (name, &color, hash);
2973     }
2974
2975   g_free (copy);
2976
2977   return changed;
2978 }
2979
2980 static gboolean
2981 update_color_hash (ColorSchemeData   *data,
2982                    const gchar       *str,
2983                    GtkSettingsSource  source)
2984 {
2985   gboolean changed = FALSE;
2986   gint i;
2987   GHashTable *old_hash;
2988   GHashTableIter iter;
2989   gpointer name;
2990   gpointer color;
2991
2992   if ((str == NULL || *str == '\0') &&
2993       (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2994     return FALSE;
2995
2996   if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2997     return FALSE;
2998
2999   /* For the THEME source we merge the values rather than over-writing
3000    * them, since multiple rc files might define independent sets of colors
3001    */
3002   if ((source != GTK_SETTINGS_SOURCE_THEME) &&
3003       data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
3004     {
3005       g_hash_table_unref (data->tables[source]);
3006       data->tables[source] = NULL;
3007       changed = TRUE; /* We can't rely on the code below since str might be "" */
3008     }
3009
3010   if (data->tables[source] == NULL)
3011     data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
3012                                                   g_free,
3013                                                   (GDestroyNotify) gdk_color_free);
3014
3015   g_free (data->lastentry[source]);
3016   data->lastentry[source] = g_strdup (str);
3017
3018   changed |= add_colors_to_hash_from_string (data->tables[source], str);
3019
3020   if (!changed)
3021     return FALSE;
3022
3023   /* Rebuild the merged hash table. */
3024   if (data->color_hash)
3025     {
3026       old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
3027                                         (GDestroyNotify) gdk_color_free);
3028
3029       g_hash_table_iter_init (&iter, data->color_hash);
3030       while (g_hash_table_iter_next (&iter, &name, &color))
3031         {
3032           g_hash_table_insert (old_hash, name, color);
3033           g_hash_table_iter_steal (&iter);
3034         }
3035     }
3036   else
3037     {
3038       old_hash = NULL;
3039     }
3040
3041   for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
3042     {
3043       if (data->tables[i])
3044         g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
3045                               data->color_hash);
3046     }
3047
3048   if (old_hash)
3049     {
3050       /* now check if the merged hash has changed */
3051       changed = FALSE;
3052       if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
3053         changed = TRUE;
3054       else
3055         {
3056           GHashTableIter iter;
3057           gpointer key, value, new_value;
3058
3059           g_hash_table_iter_init (&iter, old_hash);
3060           while (g_hash_table_iter_next (&iter, &key, &value))
3061             {
3062               new_value = g_hash_table_lookup (data->color_hash, key);
3063               if (!new_value || !gdk_color_equal (value, new_value))
3064                 {
3065                   changed = TRUE;
3066                   break;
3067                 }
3068             }
3069         }
3070
3071       g_hash_table_unref (old_hash);
3072     }
3073   else
3074     changed = TRUE;
3075
3076   return changed;
3077 }
3078
3079 static void
3080 merge_color_scheme (GtkSettings       *settings,
3081                     const GValue      *value,
3082                     GtkSettingsSource  source)
3083 {
3084   ColorSchemeData *data;
3085   const gchar *colors;
3086
3087   g_object_freeze_notify (G_OBJECT (settings));
3088
3089   colors = g_value_get_string (value);
3090
3091   settings_update_color_scheme (settings);
3092
3093   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
3094                                                 "gtk-color-scheme");
3095
3096   if (update_color_hash (data, colors, source))
3097     g_object_notify (G_OBJECT (settings), "color-hash");
3098
3099   g_object_thaw_notify (G_OBJECT (settings));
3100 }
3101
3102 static GHashTable *
3103 get_color_hash (GtkSettings *settings)
3104 {
3105   ColorSchemeData *data;
3106
3107   settings_update_color_scheme (settings);
3108
3109   data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
3110                                                "gtk-color-scheme");
3111
3112   return data->color_hash;
3113 }
3114
3115 static void
3116 append_color_scheme (gpointer key,
3117                      gpointer value,
3118                      gpointer data)
3119 {
3120   gchar *name = (gchar *)key;
3121   GdkColor *color = (GdkColor *)value;
3122   GString *string = (GString *)data;
3123
3124   g_string_append_printf (string, "%s: #%04x%04x%04x\n",
3125                           name, color->red, color->green, color->blue);
3126 }
3127
3128 static gchar *
3129 get_color_scheme (GtkSettings *settings)
3130 {
3131   ColorSchemeData *data;
3132   GString *string;
3133
3134   settings_update_color_scheme (settings);
3135
3136   data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
3137                                                 "gtk-color-scheme");
3138
3139   string = g_string_new ("");
3140
3141   g_hash_table_foreach (data->color_hash, append_color_scheme, string);
3142
3143   return g_string_free (string, FALSE);
3144 }
3145
3146 GdkScreen *
3147 _gtk_settings_get_screen (GtkSettings *settings)
3148 {
3149   return settings->priv->screen;
3150 }
3151
3152
3153 static void
3154 gtk_settings_load_from_key_file (GtkSettings       *settings,
3155                                  const gchar       *path,
3156                                  GtkSettingsSource  source)
3157 {
3158   GError *error;
3159   GKeyFile *keyfile;
3160   gchar **keys;
3161   gsize n_keys;
3162   gint i;
3163
3164   error = NULL;
3165   keys = NULL;
3166
3167   keyfile = g_key_file_new ();
3168
3169   if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
3170     {
3171       g_warning ("Failed to parse %s: %s", path, error->message);
3172
3173       g_error_free (error);
3174
3175       goto out;
3176     }
3177
3178   keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3179   if (error)
3180     {
3181       g_warning ("Failed to parse %s: %s", path, error->message);
3182       g_error_free (error);
3183       goto out;
3184     }
3185
3186   for (i = 0; i < n_keys; i++)
3187     {
3188       gchar *key;
3189       GParamSpec *pspec;
3190       GType value_type;
3191       GtkSettingsValue svalue = { NULL, { 0, }, };
3192
3193       key = keys[i];
3194       pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3195       if (!pspec)
3196         {
3197           g_warning ("Unknown key %s in %s", key, path);
3198           continue;
3199         }
3200
3201       if (pspec->owner_type != G_OBJECT_TYPE (settings))
3202         continue;
3203
3204       value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3205       switch (value_type)
3206         {
3207         case G_TYPE_BOOLEAN:
3208           {
3209             gboolean b_val;
3210
3211             g_value_init (&svalue.value, G_TYPE_LONG);
3212             b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3213             if (!error)
3214               g_value_set_long (&svalue.value, b_val);
3215             break;
3216           }
3217
3218         case G_TYPE_INT:
3219           {
3220             gint i_val;
3221
3222             g_value_init (&svalue.value, G_TYPE_LONG);
3223             i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3224             if (!error)
3225               g_value_set_long (&svalue.value, i_val);
3226             break;
3227           }
3228
3229         case G_TYPE_DOUBLE:
3230           {
3231             gdouble d_val;
3232
3233             g_value_init (&svalue.value, G_TYPE_DOUBLE);
3234             d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3235             if (!error)
3236               g_value_set_double (&svalue.value, d_val);
3237             break;
3238           }
3239
3240         default:
3241           {
3242             gchar *s_val;
3243
3244             g_value_init (&svalue.value, G_TYPE_GSTRING);
3245             s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3246             if (!error)
3247               g_value_take_boxed (&svalue.value, g_string_new (s_val));
3248             g_free (s_val);
3249             break;
3250           }
3251         }
3252       if (error)
3253         {
3254           g_warning ("Error setting %s in %s: %s", key, path, error->message);
3255           g_error_free (error);
3256           error = NULL;
3257         }
3258       else
3259         {
3260           if (g_getenv ("GTK_DEBUG"))
3261             svalue.origin = (gchar *)path;
3262           gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3263           g_value_unset (&svalue.value);
3264         }
3265     }
3266
3267  out:
3268   g_strfreev (keys);
3269   g_key_file_free (keyfile);
3270 }