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