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