]> Pileus Git - ~andy/gtk/blob - gtk/gtksettings.c
2ba95ad67041cd7ec439de43f50c5ab90ace70e6
[~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 normal attributes from this description,
1432    * so they do not override theme values */
1433   if (pango_font_description_get_weight (font_desc) == PANGO_WEIGHT_NORMAL)
1434     pango_font_description_unset_fields (font_desc,
1435                                          PANGO_FONT_MASK_WEIGHT);
1436
1437   if (pango_font_description_get_stretch (font_desc) == PANGO_STRETCH_NORMAL)
1438     pango_font_description_unset_fields (font_desc,
1439                                          PANGO_FONT_MASK_STRETCH);
1440
1441   if (pango_font_description_get_variant (font_desc) == PANGO_VARIANT_NORMAL)
1442     pango_font_description_unset_fields (font_desc,
1443                                          PANGO_FONT_MASK_VARIANT);
1444
1445   if (pango_font_description_get_style (font_desc) == PANGO_STYLE_NORMAL)
1446     pango_font_description_unset_fields (font_desc,
1447                                          PANGO_FONT_MASK_STYLE);
1448
1449   gtk_style_properties_set (priv->style, 0,
1450                             "font", font_desc,
1451                             NULL);
1452
1453   pango_font_description_free (font_desc);
1454   g_free (font_name);
1455 }
1456
1457 static void
1458 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1459 {
1460 }
1461
1462 static GtkCssValue *
1463 gtk_settings_style_provider_get_color (GtkStyleProviderPrivate *provider,
1464                                        const char              *name)
1465 {
1466   GtkSettings *settings = GTK_SETTINGS (provider);
1467
1468   settings_ensure_style (settings);
1469
1470   return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style), name);
1471 }
1472
1473 static void
1474 gtk_settings_style_provider_lookup (GtkStyleProviderPrivate *provider,
1475                                     const GtkCssMatcher     *matcher,
1476                                     GtkCssLookup            *lookup)
1477 {
1478   GtkSettings *settings = GTK_SETTINGS (provider);
1479
1480   settings_ensure_style (settings);
1481
1482   _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style),
1483                                       matcher,
1484                                       lookup);
1485 }
1486
1487 static GtkCssChange
1488 gtk_settings_style_provider_get_change (GtkStyleProviderPrivate *provider,
1489                                         const GtkCssMatcher     *matcher)
1490 {
1491   GtkSettings *settings = GTK_SETTINGS (provider);
1492
1493   settings_ensure_style (settings);
1494
1495   return _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style),
1496                                                  matcher);
1497 }
1498
1499 static void
1500 gtk_settings_provider_private_init (GtkStyleProviderPrivateInterface *iface)
1501 {
1502   iface->get_color = gtk_settings_style_provider_get_color;
1503   iface->lookup = gtk_settings_style_provider_lookup;
1504   iface->get_change = gtk_settings_style_provider_get_change;
1505 }
1506
1507 static void
1508 gtk_settings_finalize (GObject *object)
1509 {
1510   GtkSettings *settings = GTK_SETTINGS (object);
1511   GtkSettingsPrivate *priv = settings->priv;
1512   guint i;
1513
1514   object_list = g_slist_remove (object_list, settings);
1515
1516   for (i = 0; i < class_n_properties; i++)
1517     g_value_unset (&priv->property_values[i].value);
1518   g_free (priv->property_values);
1519
1520   g_datalist_clear (&priv->queued_settings);
1521
1522   settings_update_provider (priv->screen, &priv->theme_provider, NULL);
1523   settings_update_provider (priv->screen, &priv->key_theme_provider, NULL);
1524
1525   g_clear_object (&priv->style);
1526
1527   G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1528 }
1529
1530 static void
1531 settings_init_style (GtkSettings *settings)
1532 {
1533   static GtkCssProvider *css_provider = NULL;
1534
1535   GdkScreen *screen = settings->priv->screen;
1536
1537   /* Add provider for user file */
1538   if (G_UNLIKELY (!css_provider))
1539     {
1540       gchar *css_path;
1541
1542       css_provider = gtk_css_provider_new ();
1543       css_path = g_build_filename (g_get_user_config_dir (),
1544                                    "gtk-3.0",
1545                                    "gtk.css",
1546                                    NULL);
1547
1548       if (g_file_test (css_path,
1549                        G_FILE_TEST_IS_REGULAR))
1550         gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1551
1552       g_free (css_path);
1553     }
1554
1555   gtk_style_context_add_provider_for_screen (screen,
1556                                              GTK_STYLE_PROVIDER (css_provider),
1557                                              GTK_STYLE_PROVIDER_PRIORITY_USER);
1558
1559   gtk_style_context_add_provider_for_screen (screen,
1560                                              GTK_STYLE_PROVIDER (settings),
1561                                              GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1562
1563   gtk_style_context_add_provider_for_screen (screen,
1564                                              GTK_STYLE_PROVIDER (settings->priv->theme_provider),
1565                                              GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1566
1567   settings_update_theme (settings);
1568   settings_update_key_theme (settings);
1569 }
1570
1571 /**
1572  * gtk_settings_get_for_screen:
1573  * @screen: a #GdkScreen.
1574  *
1575  * Gets the #GtkSettings object for @screen, creating it if necessary.
1576  *
1577  * Return value: (transfer none): a #GtkSettings object.
1578  *
1579  * Since: 2.2
1580  */
1581 GtkSettings*
1582 gtk_settings_get_for_screen (GdkScreen *screen)
1583 {
1584   GtkSettings *settings;
1585
1586   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1587
1588   settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1589   if (!settings)
1590     {
1591 #ifdef GDK_WINDOWING_QUARTZ
1592       if (GDK_IS_QUARTZ_SCREEN (screen))
1593         settings = g_object_new (GTK_TYPE_SETTINGS,
1594                                  "gtk-key-theme-name", "Mac",
1595                                  "gtk-shell-shows-app-menu", TRUE,
1596                                  "gtk-shell-shows-menubar", TRUE,
1597                                  NULL);
1598       else
1599 #endif
1600         settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1601       settings->priv->screen = screen;
1602       g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1603                               settings, g_object_unref);
1604
1605       settings_init_style (settings);
1606       settings_update_double_click (settings);
1607       settings_update_cursor_theme (settings);
1608       settings_update_resolution (settings);
1609       settings_update_font_options (settings);
1610     }
1611
1612   return settings;
1613 }
1614
1615 /**
1616  * gtk_settings_get_default:
1617  *
1618  * Gets the #GtkSettings object for the default GDK screen, creating
1619  * it if necessary. See gtk_settings_get_for_screen().
1620  *
1621  * Return value: (transfer none): a #GtkSettings object. If there is no default
1622  *  screen, then returns %NULL.
1623  **/
1624 GtkSettings*
1625 gtk_settings_get_default (void)
1626 {
1627   GdkScreen *screen = gdk_screen_get_default ();
1628
1629   if (screen)
1630     return gtk_settings_get_for_screen (screen);
1631   else
1632     return NULL;
1633 }
1634
1635 static void
1636 gtk_settings_set_property (GObject      *object,
1637                            guint         property_id,
1638                            const GValue *value,
1639                            GParamSpec   *pspec)
1640 {
1641   GtkSettings *settings = GTK_SETTINGS (object);
1642   GtkSettingsPrivate *priv = settings->priv;
1643
1644   g_value_copy (value, &priv->property_values[property_id - 1].value);
1645   priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1646 }
1647
1648 static void
1649 gtk_settings_get_property (GObject     *object,
1650                            guint        property_id,
1651                            GValue      *value,
1652                            GParamSpec  *pspec)
1653 {
1654   GtkSettings *settings = GTK_SETTINGS (object);
1655   GtkSettingsPrivate *priv = settings->priv;
1656   GType value_type = G_VALUE_TYPE (value);
1657   GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1658
1659   /* handle internal properties */
1660   switch (property_id)
1661     {
1662     case PROP_COLOR_HASH:
1663       g_value_take_boxed (value,
1664                           g_hash_table_new_full (g_str_hash, g_str_equal,
1665                                                  g_free, (GDestroyNotify) gdk_color_free));
1666       return;
1667     default: ;
1668     }
1669
1670   /* For enums and strings, we need to get the value as a string,
1671    * not as an int, since we support using names/nicks as the setting
1672    * value.
1673    */
1674   if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1675        !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1676       g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1677       g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1678     {
1679       if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1680           !gdk_screen_get_setting (priv->screen, pspec->name, value))
1681         g_value_copy (&priv->property_values[property_id - 1].value, value);
1682       else
1683         g_param_value_validate (pspec, value);
1684     }
1685   else
1686     {
1687       GValue val = G_VALUE_INIT;
1688
1689       /* Try to get xsetting as a string and parse it. */
1690
1691       g_value_init (&val, G_TYPE_STRING);
1692
1693       if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1694           !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1695         {
1696           g_value_copy (&priv->property_values[property_id - 1].value, value);
1697         }
1698       else
1699         {
1700           GValue tmp_value = G_VALUE_INIT;
1701           GValue gstring_value = G_VALUE_INIT;
1702           GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1703
1704           g_value_init (&gstring_value, G_TYPE_GSTRING);
1705           g_value_take_boxed (&gstring_value,
1706                               g_string_new (g_value_get_string (&val)));
1707
1708           g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1709
1710           if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1711                                                      pspec, &tmp_value))
1712             {
1713               g_value_copy (&tmp_value, value);
1714               g_param_value_validate (pspec, value);
1715             }
1716           else
1717             {
1718               g_value_copy (&priv->property_values[property_id - 1].value, value);
1719             }
1720
1721           g_value_unset (&gstring_value);
1722           g_value_unset (&tmp_value);
1723         }
1724
1725       g_value_unset (&val);
1726     }
1727 }
1728
1729 static void
1730 settings_invalidate_style (GtkSettings *settings)
1731 {
1732   GtkSettingsPrivate *priv = settings->priv;
1733
1734   if (priv->style)
1735     {
1736       g_object_unref (priv->style);
1737       priv->style = NULL;
1738     }
1739
1740   _gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (settings));
1741 }
1742
1743 static void
1744 gtk_settings_notify (GObject    *object,
1745                      GParamSpec *pspec)
1746 {
1747   GtkSettings *settings = GTK_SETTINGS (object);
1748   GtkSettingsPrivate *priv = settings->priv;
1749   guint property_id = pspec->param_id;
1750
1751   if (priv->screen == NULL) /* initialization */
1752     return;
1753
1754   switch (property_id)
1755     {
1756     case PROP_MODULES:
1757       settings_update_modules (settings);
1758       break;
1759     case PROP_DOUBLE_CLICK_TIME:
1760     case PROP_DOUBLE_CLICK_DISTANCE:
1761       settings_update_double_click (settings);
1762       break;
1763     case PROP_FONT_NAME:
1764       settings_invalidate_style (settings);
1765       gtk_style_context_reset_widgets (priv->screen);
1766       break;
1767     case PROP_KEY_THEME_NAME:
1768       settings_update_key_theme (settings);
1769       break;
1770     case PROP_THEME_NAME:
1771     case PROP_APPLICATION_PREFER_DARK_THEME:
1772       settings_update_theme (settings);
1773       break;
1774     case PROP_XFT_DPI:
1775       settings_update_resolution (settings);
1776       /* This is a hack because with gtk_rc_reset_styles() doesn't get
1777        * widgets with gtk_widget_style_set(), and also causes more
1778        * recomputation than necessary.
1779        */
1780       gtk_style_context_reset_widgets (priv->screen);
1781       break;
1782     case PROP_XFT_ANTIALIAS:
1783     case PROP_XFT_HINTING:
1784     case PROP_XFT_HINTSTYLE:
1785     case PROP_XFT_RGBA:
1786       settings_update_font_options (settings);
1787       gtk_style_context_reset_widgets (priv->screen);
1788       break;
1789     case PROP_FONTCONFIG_TIMESTAMP:
1790       if (settings_update_fontconfig (settings))
1791         gtk_style_context_reset_widgets (priv->screen);
1792       break;
1793     case PROP_ENABLE_ANIMATIONS:
1794       gtk_style_context_reset_widgets (priv->screen);
1795       break;
1796     case PROP_CURSOR_THEME_NAME:
1797     case PROP_CURSOR_THEME_SIZE:
1798       settings_update_cursor_theme (settings);
1799       break;
1800     }
1801 }
1802
1803 gboolean
1804 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1805                              const GValue       *src_value,
1806                              GParamSpec         *pspec,
1807                              GValue             *dest_value)
1808 {
1809   gboolean success = FALSE;
1810
1811   g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1812
1813   if (parser)
1814     {
1815       GString *gstring;
1816       gboolean free_gstring = TRUE;
1817
1818       if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1819         {
1820           gstring = g_value_get_boxed (src_value);
1821           free_gstring = FALSE;
1822         }
1823       else if (G_VALUE_HOLDS_LONG (src_value))
1824         {
1825           gstring = g_string_new (NULL);
1826           g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1827         }
1828       else if (G_VALUE_HOLDS_DOUBLE (src_value))
1829         {
1830           gstring = g_string_new (NULL);
1831           g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1832         }
1833       else if (G_VALUE_HOLDS_STRING (src_value))
1834         {
1835           gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1836
1837           gstring = g_string_new (NULL);
1838           g_string_append_c (gstring, '\"');
1839           g_string_append (gstring, tstr);
1840           g_string_append_c (gstring, '\"');
1841           g_free (tstr);
1842         }
1843       else
1844         {
1845           g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1846           gstring = NULL; /* silence compiler */
1847         }
1848
1849       success = (parser (pspec, gstring, dest_value) &&
1850                  !g_param_value_validate (pspec, dest_value));
1851
1852       if (free_gstring)
1853         g_string_free (gstring, TRUE);
1854     }
1855   else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1856     {
1857       if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1858         {
1859           GString *gstring = g_value_get_boxed (src_value);
1860
1861           g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1862           success = !g_param_value_validate (pspec, dest_value);
1863         }
1864     }
1865   else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1866     success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1867
1868   return success;
1869 }
1870
1871 static void
1872 apply_queued_setting (GtkSettings             *settings,
1873                       GParamSpec              *pspec,
1874                       GtkSettingsValuePrivate *qvalue)
1875 {
1876   GtkSettingsPrivate *priv = settings->priv;
1877   GValue tmp_value = G_VALUE_INIT;
1878   GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1879
1880   g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1881   if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1882                                    pspec, &tmp_value))
1883     {
1884       if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1885         {
1886           g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1887           priv->property_values[pspec->param_id - 1].source = qvalue->source;
1888           g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1889         }
1890
1891     }
1892   else
1893     {
1894       gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1895
1896       g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1897                  qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1898                  pspec->name,
1899                  g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1900                  debug,
1901                  G_VALUE_TYPE_NAME (&tmp_value));
1902       g_free (debug);
1903     }
1904   g_value_unset (&tmp_value);
1905 }
1906
1907 static guint
1908 settings_install_property_parser (GtkSettingsClass   *class,
1909                                   GParamSpec         *pspec,
1910                                   GtkRcPropertyParser parser)
1911 {
1912   GSList *node, *next;
1913
1914   switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1915     {
1916     case G_TYPE_BOOLEAN:
1917     case G_TYPE_UCHAR:
1918     case G_TYPE_CHAR:
1919     case G_TYPE_UINT:
1920     case G_TYPE_INT:
1921     case G_TYPE_ULONG:
1922     case G_TYPE_LONG:
1923     case G_TYPE_FLOAT:
1924     case G_TYPE_DOUBLE:
1925     case G_TYPE_STRING:
1926     case G_TYPE_ENUM:
1927       break;
1928     case G_TYPE_BOXED:
1929       if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1930         {
1931           break;
1932         }
1933       /* fall through */
1934     default:
1935       if (!parser)
1936         {
1937           g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1938                      pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1939           return 0;
1940         }
1941     }
1942   if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1943     {
1944       g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1945                  pspec->name);
1946       return 0;
1947     }
1948
1949   for (node = object_list; node; node = node->next)
1950     g_object_freeze_notify (node->data);
1951
1952   g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1953   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1954
1955   for (node = object_list; node; node = node->next)
1956     {
1957       GtkSettings *settings = node->data;
1958       GtkSettingsPrivate *priv = settings->priv;
1959       GtkSettingsValuePrivate *qvalue;
1960
1961       priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1962       priv->property_values[class_n_properties - 1].value.g_type = 0;
1963       g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1964       g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1965       priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1966       g_object_notify (G_OBJECT (settings), pspec->name);
1967
1968       qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1969       if (qvalue)
1970         apply_queued_setting (settings, pspec, qvalue);
1971     }
1972
1973   for (node = object_list; node; node = next)
1974     {
1975       next = node->next;
1976       g_object_thaw_notify (node->data);
1977     }
1978
1979   return class_n_properties;
1980 }
1981
1982 GtkRcPropertyParser
1983 _gtk_rc_property_parser_from_type (GType type)
1984 {
1985   if (type == GDK_TYPE_COLOR)
1986     return gtk_rc_property_parse_color;
1987   else if (type == GTK_TYPE_REQUISITION)
1988     return gtk_rc_property_parse_requisition;
1989   else if (type == GTK_TYPE_BORDER)
1990     return gtk_rc_property_parse_border;
1991   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1992     return gtk_rc_property_parse_enum;
1993   else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1994     return gtk_rc_property_parse_flags;
1995   else
1996     return NULL;
1997 }
1998
1999 void
2000 gtk_settings_install_property (GParamSpec *pspec)
2001 {
2002   static GtkSettingsClass *klass = NULL;
2003
2004   GtkRcPropertyParser parser;
2005
2006   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2007
2008   if (! klass)
2009     klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2010
2011   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
2012
2013   settings_install_property_parser (klass, pspec, parser);
2014 }
2015
2016 /**
2017  * gtk_settings_install_property_parser:
2018  * @pspec:
2019  * @parser: (scope call):
2020  */
2021 void
2022 gtk_settings_install_property_parser (GParamSpec          *pspec,
2023                                       GtkRcPropertyParser  parser)
2024 {
2025   static GtkSettingsClass *klass = NULL;
2026
2027   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2028   g_return_if_fail (parser != NULL);
2029
2030   if (! klass)
2031     klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2032
2033   settings_install_property_parser (klass, pspec, parser);
2034 }
2035
2036 static void
2037 free_value (gpointer data)
2038 {
2039   GtkSettingsValuePrivate *qvalue = data;
2040
2041   g_value_unset (&qvalue->public.value);
2042   g_free (qvalue->public.origin);
2043   g_slice_free (GtkSettingsValuePrivate, qvalue);
2044 }
2045
2046 static void
2047 gtk_settings_set_property_value_internal (GtkSettings            *settings,
2048                                           const gchar            *prop_name,
2049                                           const GtkSettingsValue *new_value,
2050                                           GtkSettingsSource       source)
2051 {
2052   GtkSettingsPrivate *priv = settings->priv;
2053   GtkSettingsValuePrivate *qvalue;
2054   GParamSpec *pspec;
2055   gchar *name;
2056   GQuark name_quark;
2057
2058   if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
2059       !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
2060       !G_VALUE_HOLDS_STRING (&new_value->value) &&
2061       !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
2062     {
2063       g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
2064       return;
2065     }
2066
2067   name = g_strdup (prop_name);
2068   g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
2069   name_quark = g_quark_from_string (name);
2070   g_free (name);
2071
2072   qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
2073   if (!qvalue)
2074     {
2075       qvalue = g_slice_new0 (GtkSettingsValuePrivate);
2076       g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
2077     }
2078   else
2079     {
2080       g_free (qvalue->public.origin);
2081       g_value_unset (&qvalue->public.value);
2082     }
2083   qvalue->public.origin = g_strdup (new_value->origin);
2084   g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
2085   g_value_copy (&new_value->value, &qvalue->public.value);
2086   qvalue->source = source;
2087   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
2088   if (pspec)
2089     apply_queued_setting (settings, pspec, qvalue);
2090 }
2091
2092 void
2093 gtk_settings_set_property_value (GtkSettings            *settings,
2094                                  const gchar            *prop_name,
2095                                  const GtkSettingsValue *new_value)
2096 {
2097   g_return_if_fail (GTK_SETTINGS (settings));
2098   g_return_if_fail (prop_name != NULL);
2099   g_return_if_fail (new_value != NULL);
2100
2101   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2102                                             GTK_SETTINGS_SOURCE_APPLICATION);
2103 }
2104
2105 void
2106 _gtk_settings_set_property_value_from_rc (GtkSettings            *settings,
2107                                           const gchar            *prop_name,
2108                                           const GtkSettingsValue *new_value)
2109 {
2110   g_return_if_fail (GTK_SETTINGS (settings));
2111   g_return_if_fail (prop_name != NULL);
2112   g_return_if_fail (new_value != NULL);
2113
2114   gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2115                                             GTK_SETTINGS_SOURCE_THEME);
2116 }
2117
2118 void
2119 gtk_settings_set_string_property (GtkSettings *settings,
2120                                   const gchar *name,
2121                                   const gchar *v_string,
2122                                   const gchar *origin)
2123 {
2124   GtkSettingsValue svalue = { NULL, { 0, }, };
2125
2126   g_return_if_fail (GTK_SETTINGS (settings));
2127   g_return_if_fail (name != NULL);
2128   g_return_if_fail (v_string != NULL);
2129
2130   svalue.origin = (gchar*) origin;
2131   g_value_init (&svalue.value, G_TYPE_STRING);
2132   g_value_set_static_string (&svalue.value, v_string);
2133   gtk_settings_set_property_value (settings, name, &svalue);
2134   g_value_unset (&svalue.value);
2135 }
2136
2137 void
2138 gtk_settings_set_long_property (GtkSettings *settings,
2139                                 const gchar *name,
2140                                 glong        v_long,
2141                                 const gchar *origin)
2142 {
2143   GtkSettingsValue svalue = { NULL, { 0, }, };
2144
2145   g_return_if_fail (GTK_SETTINGS (settings));
2146   g_return_if_fail (name != NULL);
2147
2148   svalue.origin = (gchar*) origin;
2149   g_value_init (&svalue.value, G_TYPE_LONG);
2150   g_value_set_long (&svalue.value, v_long);
2151   gtk_settings_set_property_value (settings, name, &svalue);
2152   g_value_unset (&svalue.value);
2153 }
2154
2155 void
2156 gtk_settings_set_double_property (GtkSettings *settings,
2157                                   const gchar *name,
2158                                   gdouble      v_double,
2159                                   const gchar *origin)
2160 {
2161   GtkSettingsValue svalue = { NULL, { 0, }, };
2162
2163   g_return_if_fail (GTK_SETTINGS (settings));
2164   g_return_if_fail (name != NULL);
2165
2166   svalue.origin = (gchar*) origin;
2167   g_value_init (&svalue.value, G_TYPE_DOUBLE);
2168   g_value_set_double (&svalue.value, v_double);
2169   gtk_settings_set_property_value (settings, name, &svalue);
2170   g_value_unset (&svalue.value);
2171 }
2172
2173 /**
2174  * gtk_rc_property_parse_color:
2175  * @pspec: a #GParamSpec
2176  * @gstring: the #GString to be parsed
2177  * @property_value: a #GValue which must hold #GdkColor values.
2178  *
2179  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2180  * or gtk_widget_class_install_style_property_parser() which parses a
2181  * color given either by its name or in the form
2182  * <literal>{ red, green, blue }</literal> where %red, %green and
2183  * %blue are integers between 0 and 65535 or floating-point numbers
2184  * between 0 and 1.
2185  *
2186  * Return value: %TRUE if @gstring could be parsed and @property_value
2187  * has been set to the resulting #GdkColor.
2188  **/
2189 gboolean
2190 gtk_rc_property_parse_color (const GParamSpec *pspec,
2191                              const GString    *gstring,
2192                              GValue           *property_value)
2193 {
2194   GdkColor color = { 0, 0, 0, 0, };
2195   GScanner *scanner;
2196   gboolean success;
2197
2198   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2199   g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2200
2201   scanner = gtk_rc_scanner_new ();
2202   g_scanner_input_text (scanner, gstring->str, gstring->len);
2203   if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2204       g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2205     {
2206       g_value_set_boxed (property_value, &color);
2207       success = TRUE;
2208     }
2209   else
2210     success = FALSE;
2211   g_scanner_destroy (scanner);
2212
2213   return success;
2214 }
2215
2216 /**
2217  * gtk_rc_property_parse_enum:
2218  * @pspec: a #GParamSpec
2219  * @gstring: the #GString to be parsed
2220  * @property_value: a #GValue which must hold enum values.
2221  *
2222  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2223  * or gtk_widget_class_install_style_property_parser() which parses a single
2224  * enumeration value.
2225  *
2226  * The enumeration value can be specified by its name, its nickname or
2227  * its numeric value. For consistency with flags parsing, the value
2228  * may be surrounded by parentheses.
2229  *
2230  * Return value: %TRUE if @gstring could be parsed and @property_value
2231  * has been set to the resulting #GEnumValue.
2232  **/
2233 gboolean
2234 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2235                             const GString    *gstring,
2236                             GValue           *property_value)
2237 {
2238   gboolean need_closing_brace = FALSE, success = FALSE;
2239   GScanner *scanner;
2240   GEnumValue *enum_value = NULL;
2241
2242   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2243   g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2244
2245   scanner = gtk_rc_scanner_new ();
2246   g_scanner_input_text (scanner, gstring->str, gstring->len);
2247
2248   /* we just want to parse _one_ value, but for consistency with flags parsing
2249    * we support optional parenthesis
2250    */
2251   g_scanner_get_next_token (scanner);
2252   if (scanner->token == '(')
2253     {
2254       need_closing_brace = TRUE;
2255       g_scanner_get_next_token (scanner);
2256     }
2257   if (scanner->token == G_TOKEN_IDENTIFIER)
2258     {
2259       GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2260
2261       enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2262       if (!enum_value)
2263         enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2264       if (enum_value)
2265         {
2266           g_value_set_enum (property_value, enum_value->value);
2267           success = TRUE;
2268         }
2269     }
2270   else if (scanner->token == G_TOKEN_INT)
2271     {
2272       g_value_set_enum (property_value, scanner->value.v_int);
2273       success = TRUE;
2274     }
2275   if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2276     success = FALSE;
2277   if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2278     success = FALSE;
2279
2280   g_scanner_destroy (scanner);
2281
2282   return success;
2283 }
2284
2285 static guint
2286 parse_flags_value (GScanner    *scanner,
2287                    GFlagsClass *class,
2288                    guint       *number)
2289 {
2290   g_scanner_get_next_token (scanner);
2291   if (scanner->token == G_TOKEN_IDENTIFIER)
2292     {
2293       GFlagsValue *flags_value;
2294
2295       flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2296       if (!flags_value)
2297         flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2298       if (flags_value)
2299         {
2300           *number |= flags_value->value;
2301           return G_TOKEN_NONE;
2302         }
2303     }
2304   else if (scanner->token == G_TOKEN_INT)
2305     {
2306       *number |= scanner->value.v_int;
2307       return G_TOKEN_NONE;
2308     }
2309   return G_TOKEN_IDENTIFIER;
2310 }
2311
2312 /**
2313  * gtk_rc_property_parse_flags:
2314  * @pspec: a #GParamSpec
2315  * @gstring: the #GString to be parsed
2316  * @property_value: a #GValue which must hold flags values.
2317  *
2318  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2319  * or gtk_widget_class_install_style_property_parser() which parses flags.
2320  *
2321  * Flags can be specified by their name, their nickname or
2322  * numerically. Multiple flags can be specified in the form
2323  * <literal>"( flag1 | flag2 | ... )"</literal>.
2324  *
2325  * Return value: %TRUE if @gstring could be parsed and @property_value
2326  * has been set to the resulting flags value.
2327  **/
2328 gboolean
2329 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2330                              const GString    *gstring,
2331                              GValue           *property_value)
2332 {
2333   GFlagsClass *class;
2334    gboolean success = FALSE;
2335   GScanner *scanner;
2336
2337   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2338   g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2339
2340   class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2341   scanner = gtk_rc_scanner_new ();
2342   g_scanner_input_text (scanner, gstring->str, gstring->len);
2343
2344   /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2345   if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2346       scanner->next_token == G_TOKEN_INT)
2347     {
2348       guint token, flags_value = 0;
2349
2350       token = parse_flags_value (scanner, class, &flags_value);
2351
2352       if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2353         {
2354           success = TRUE;
2355           g_value_set_flags (property_value, flags_value);
2356         }
2357
2358     }
2359   else if (g_scanner_get_next_token (scanner) == '(')
2360     {
2361       guint token, flags_value = 0;
2362
2363       /* parse first value */
2364       token = parse_flags_value (scanner, class, &flags_value);
2365
2366       /* parse nth values, preceeded by '|' */
2367       while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2368         token = parse_flags_value (scanner, class, &flags_value);
2369
2370       /* done, last token must have closed expression */
2371       if (token == G_TOKEN_NONE && scanner->token == ')' &&
2372           g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2373         {
2374           g_value_set_flags (property_value, flags_value);
2375           success = TRUE;
2376         }
2377     }
2378   g_scanner_destroy (scanner);
2379
2380   return success;
2381 }
2382
2383 static gboolean
2384 get_braced_int (GScanner *scanner,
2385                 gboolean  first,
2386                 gboolean  last,
2387                 gint     *value)
2388 {
2389   if (first)
2390     {
2391       g_scanner_get_next_token (scanner);
2392       if (scanner->token != '{')
2393         return FALSE;
2394     }
2395
2396   g_scanner_get_next_token (scanner);
2397   if (scanner->token != G_TOKEN_INT)
2398     return FALSE;
2399
2400   *value = scanner->value.v_int;
2401
2402   if (last)
2403     {
2404       g_scanner_get_next_token (scanner);
2405       if (scanner->token != '}')
2406         return FALSE;
2407     }
2408   else
2409     {
2410       g_scanner_get_next_token (scanner);
2411       if (scanner->token != ',')
2412         return FALSE;
2413     }
2414
2415   return TRUE;
2416 }
2417
2418 /**
2419  * gtk_rc_property_parse_requisition:
2420  * @pspec: a #GParamSpec
2421  * @gstring: the #GString to be parsed
2422  * @property_value: a #GValue which must hold boxed values.
2423  *
2424  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2425  * or gtk_widget_class_install_style_property_parser() which parses a
2426  * requisition in the form
2427  * <literal>"{ width, height }"</literal> for integers %width and %height.
2428  *
2429  * Return value: %TRUE if @gstring could be parsed and @property_value
2430  * has been set to the resulting #GtkRequisition.
2431  **/
2432 gboolean
2433 gtk_rc_property_parse_requisition  (const GParamSpec *pspec,
2434                                     const GString    *gstring,
2435                                     GValue           *property_value)
2436 {
2437   GtkRequisition requisition;
2438   GScanner *scanner;
2439   gboolean success = FALSE;
2440
2441   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2442   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2443
2444   scanner = gtk_rc_scanner_new ();
2445   g_scanner_input_text (scanner, gstring->str, gstring->len);
2446
2447   if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2448       get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2449     {
2450       g_value_set_boxed (property_value, &requisition);
2451       success = TRUE;
2452     }
2453
2454   g_scanner_destroy (scanner);
2455
2456   return success;
2457 }
2458
2459 /**
2460  * gtk_rc_property_parse_border:
2461  * @pspec: a #GParamSpec
2462  * @gstring: the #GString to be parsed
2463  * @property_value: a #GValue which must hold boxed values.
2464  *
2465  * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2466  * or gtk_widget_class_install_style_property_parser() which parses
2467  * borders in the form
2468  * <literal>"{ left, right, top, bottom }"</literal> for integers
2469  * %left, %right, %top and %bottom.
2470  *
2471  * Return value: %TRUE if @gstring could be parsed and @property_value
2472  * has been set to the resulting #GtkBorder.
2473  **/
2474 gboolean
2475 gtk_rc_property_parse_border (const GParamSpec *pspec,
2476                               const GString    *gstring,
2477                               GValue           *property_value)
2478 {
2479   GtkBorder border;
2480   GScanner *scanner;
2481   gboolean success = FALSE;
2482   int left, right, top, bottom;
2483
2484   g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2485   g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2486
2487   scanner = gtk_rc_scanner_new ();
2488   g_scanner_input_text (scanner, gstring->str, gstring->len);
2489
2490   if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2491       get_braced_int (scanner, FALSE, FALSE, &right) &&
2492       get_braced_int (scanner, FALSE, FALSE, &top) &&
2493       get_braced_int (scanner, FALSE, TRUE, &bottom))
2494     {
2495       border.left = left;
2496       border.right = right;
2497       border.top = top;
2498       border.bottom = bottom;
2499       g_value_set_boxed (property_value, &border);
2500       success = TRUE;
2501     }
2502
2503   g_scanner_destroy (scanner);
2504
2505   return success;
2506 }
2507
2508 void
2509 _gtk_settings_handle_event (GdkEventSetting *event)
2510 {
2511   GdkScreen *screen;
2512   GtkSettings *settings;
2513   GParamSpec *pspec;
2514
2515   screen = gdk_window_get_screen (event->window);
2516   settings = gtk_settings_get_for_screen (screen);
2517   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2518
2519   if (pspec)
2520     g_object_notify (G_OBJECT (settings), pspec->name);
2521 }
2522
2523 static void
2524 reset_rc_values_foreach (GQuark   key_id,
2525                          gpointer data,
2526                          gpointer user_data)
2527 {
2528   GtkSettingsValuePrivate *qvalue = data;
2529   GSList **to_reset = user_data;
2530
2531   if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2532     *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2533 }
2534
2535 void
2536 _gtk_settings_reset_rc_values (GtkSettings *settings)
2537 {
2538   GtkSettingsPrivate *priv = settings->priv;
2539   GSList *to_reset = NULL;
2540   GSList *tmp_list;
2541   GParamSpec **pspecs, **p;
2542   gint i;
2543
2544   /* Remove any queued settings */
2545   g_datalist_foreach (&priv->queued_settings,
2546                       reset_rc_values_foreach,
2547                       &to_reset);
2548
2549   for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2550     {
2551       GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2552       g_datalist_id_remove_data (&priv->queued_settings, key_id);
2553     }
2554
2555    g_slist_free (to_reset);
2556
2557   /* Now reset the active settings
2558    */
2559   pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2560   i = 0;
2561
2562   g_object_freeze_notify (G_OBJECT (settings));
2563   for (p = pspecs; *p; p++)
2564     {
2565       if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2566         {
2567           GParamSpec *pspec = *p;
2568
2569           g_param_value_set_default (pspec, &priv->property_values[i].value);
2570           g_object_notify (G_OBJECT (settings), pspec->name);
2571         }
2572       i++;
2573     }
2574   g_object_thaw_notify (G_OBJECT (settings));
2575   g_free (pspecs);
2576 }
2577
2578 static void
2579 settings_update_double_click (GtkSettings *settings)
2580 {
2581   GtkSettingsPrivate *priv = settings->priv;
2582
2583   if (gdk_screen_get_number (priv->screen) == 0)
2584     {
2585       GdkDisplay *display = gdk_screen_get_display (priv->screen);
2586       gint double_click_time;
2587       gint double_click_distance;
2588
2589       g_object_get (settings,
2590                     "gtk-double-click-time", &double_click_time,
2591                     "gtk-double-click-distance", &double_click_distance,
2592                     NULL);
2593
2594       gdk_display_set_double_click_time (display, double_click_time);
2595       gdk_display_set_double_click_distance (display, double_click_distance);
2596     }
2597 }
2598
2599 static void
2600 settings_update_modules (GtkSettings *settings)
2601 {
2602   gchar *modules;
2603
2604   g_object_get (settings,
2605                 "gtk-modules", &modules,
2606                 NULL);
2607
2608   _gtk_modules_settings_changed (settings, modules);
2609
2610   g_free (modules);
2611 }
2612
2613 static void
2614 settings_update_cursor_theme (GtkSettings *settings)
2615 {
2616 #ifdef GDK_WINDOWING_X11
2617   GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2618   gchar *theme = NULL;
2619   gint size = 0;
2620
2621   if (GDK_IS_X11_DISPLAY (display))
2622     {
2623       g_object_get (settings,
2624                     "gtk-cursor-theme-name", &theme,
2625                     "gtk-cursor-theme-size", &size,
2626                     NULL);
2627
2628       gdk_x11_display_set_cursor_theme (display, theme, size);
2629
2630       g_free (theme);
2631     }
2632 #endif
2633 }
2634
2635 static void
2636 settings_update_font_options (GtkSettings *settings)
2637 {
2638   GtkSettingsPrivate *priv = settings->priv;
2639   gint hinting;
2640   gchar *hint_style_str;
2641   cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2642   gint antialias;
2643   cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2644   gchar *rgba_str;
2645   cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2646   cairo_font_options_t *options;
2647
2648   g_object_get (settings,
2649                 "gtk-xft-antialias", &antialias,
2650                 "gtk-xft-hinting", &hinting,
2651                 "gtk-xft-hintstyle", &hint_style_str,
2652                 "gtk-xft-rgba", &rgba_str,
2653                 NULL);
2654
2655   options = cairo_font_options_create ();
2656
2657   cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2658
2659   if (hinting >= 0 && !hinting)
2660     {
2661       hint_style = CAIRO_HINT_STYLE_NONE;
2662     }
2663   else if (hint_style_str)
2664     {
2665       if (strcmp (hint_style_str, "hintnone") == 0)
2666         hint_style = CAIRO_HINT_STYLE_NONE;
2667       else if (strcmp (hint_style_str, "hintslight") == 0)
2668         hint_style = CAIRO_HINT_STYLE_SLIGHT;
2669       else if (strcmp (hint_style_str, "hintmedium") == 0)
2670         hint_style = CAIRO_HINT_STYLE_MEDIUM;
2671       else if (strcmp (hint_style_str, "hintfull") == 0)
2672         hint_style = CAIRO_HINT_STYLE_FULL;
2673     }
2674
2675   g_free (hint_style_str);
2676
2677   cairo_font_options_set_hint_style (options, hint_style);
2678
2679   if (rgba_str)
2680     {
2681       if (strcmp (rgba_str, "rgb") == 0)
2682         subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2683       else if (strcmp (rgba_str, "bgr") == 0)
2684         subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2685       else if (strcmp (rgba_str, "vrgb") == 0)
2686         subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2687       else if (strcmp (rgba_str, "vbgr") == 0)
2688         subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2689
2690       g_free (rgba_str);
2691     }
2692
2693   cairo_font_options_set_subpixel_order (options, subpixel_order);
2694
2695   if (antialias >= 0 && !antialias)
2696     antialias_mode = CAIRO_ANTIALIAS_NONE;
2697   else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2698     antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2699   else if (antialias >= 0)
2700     antialias_mode = CAIRO_ANTIALIAS_GRAY;
2701
2702   cairo_font_options_set_antialias (options, antialias_mode);
2703
2704   gdk_screen_set_font_options (priv->screen, options);
2705
2706   cairo_font_options_destroy (options);
2707 }
2708
2709 static gboolean
2710 settings_update_fontconfig (GtkSettings *settings)
2711 {
2712 #ifdef GDK_WINDOWING_X11
2713   static guint    last_update_timestamp;
2714   static gboolean last_update_needed;
2715
2716   guint timestamp;
2717
2718   g_object_get (settings,
2719                 "gtk-fontconfig-timestamp", &timestamp,
2720                 NULL);
2721
2722   /* if timestamp is the same as last_update_timestamp, we already have
2723    * updated fontconig on this timestamp (another screen requested it perhaps?),
2724    * just return the cached result.*/
2725
2726   if (timestamp != last_update_timestamp)
2727     {
2728       PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2729       gboolean update_needed = FALSE;
2730
2731       /* bug 547680 */
2732       if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2733         {
2734           pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2735           if (FcInitReinitialize ())
2736             update_needed = TRUE;
2737         }
2738
2739       last_update_timestamp = timestamp;
2740       last_update_needed = update_needed;
2741     }
2742
2743   return last_update_needed;
2744 #else
2745   return FALSE;
2746 #endif /* GDK_WINDOWING_X11 */
2747 }
2748
2749 static void
2750 settings_update_resolution (GtkSettings *settings)
2751 {
2752   GtkSettingsPrivate *priv = settings->priv;
2753   gint dpi_int;
2754   gdouble dpi;
2755
2756   g_object_get (settings,
2757                 "gtk-xft-dpi", &dpi_int,
2758                 NULL);
2759
2760   if (dpi_int > 0)
2761     dpi = dpi_int / 1024.;
2762   else
2763     dpi = -1.;
2764
2765   gdk_screen_set_resolution (priv->screen, dpi);
2766 }
2767
2768 static void
2769 settings_update_provider (GdkScreen       *screen,
2770                           GtkCssProvider **old,
2771                           GtkCssProvider  *new)
2772 {
2773   if (*old != new)
2774     {
2775       if (*old)
2776         {
2777           gtk_style_context_remove_provider_for_screen (screen,
2778                                                         GTK_STYLE_PROVIDER (*old));
2779           g_object_unref (*old);
2780           *old = NULL;
2781         }
2782
2783       if (new)
2784         {
2785           gtk_style_context_add_provider_for_screen (screen,
2786                                                      GTK_STYLE_PROVIDER (new),
2787                                                      GTK_STYLE_PROVIDER_PRIORITY_THEME);
2788           *old = g_object_ref (new);
2789         }
2790     }
2791 }
2792
2793 static void
2794 settings_update_theme (GtkSettings *settings)
2795 {
2796   GtkSettingsPrivate *priv = settings->priv;
2797   gboolean prefer_dark_theme;
2798   gchar *theme_name;
2799
2800   g_object_get (settings,
2801                 "gtk-theme-name", &theme_name,
2802                 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2803                 NULL);
2804
2805   if (!theme_name || !*theme_name)
2806     {
2807       g_free (theme_name);
2808       theme_name = g_strdup ("Raleigh");
2809     }
2810   
2811   _gtk_css_provider_load_named (priv->theme_provider,
2812                                 theme_name,
2813                                 prefer_dark_theme ? "dark" : NULL);
2814
2815   if (theme_name && *theme_name)
2816     {
2817       gchar *theme_dir;
2818       gchar *path;
2819
2820       /* reload per-theme settings */
2821       theme_dir = _gtk_css_provider_get_theme_dir ();
2822       path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2823
2824      if (g_file_test (path, G_FILE_TEST_EXISTS))
2825        gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2826
2827       g_free (theme_dir);
2828       g_free (path);
2829     }
2830
2831   g_free (theme_name);
2832 }
2833
2834 static void
2835 settings_update_key_theme (GtkSettings *settings)
2836 {
2837   GtkSettingsPrivate *priv = settings->priv;
2838   GtkCssProvider *provider = NULL;
2839   gchar *key_theme_name;
2840
2841   g_object_get (settings,
2842                 "gtk-key-theme-name", &key_theme_name,
2843                 NULL);
2844
2845   if (key_theme_name && *key_theme_name)
2846     provider = gtk_css_provider_get_named (key_theme_name, "keys");
2847
2848   settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2849   g_free (key_theme_name);
2850 }
2851
2852
2853 GdkScreen *
2854 _gtk_settings_get_screen (GtkSettings *settings)
2855 {
2856   return settings->priv->screen;
2857 }
2858
2859
2860 static void
2861 gtk_settings_load_from_key_file (GtkSettings       *settings,
2862                                  const gchar       *path,
2863                                  GtkSettingsSource  source)
2864 {
2865   GError *error;
2866   GKeyFile *keyfile;
2867   gchar **keys;
2868   gsize n_keys;
2869   gint i;
2870
2871   error = NULL;
2872   keys = NULL;
2873
2874   keyfile = g_key_file_new ();
2875
2876   if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
2877     {
2878       g_warning ("Failed to parse %s: %s", path, error->message);
2879
2880       g_error_free (error);
2881
2882       goto out;
2883     }
2884
2885   keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
2886   if (error)
2887     {
2888       g_warning ("Failed to parse %s: %s", path, error->message);
2889       g_error_free (error);
2890       goto out;
2891     }
2892
2893   for (i = 0; i < n_keys; i++)
2894     {
2895       gchar *key;
2896       GParamSpec *pspec;
2897       GType value_type;
2898       GtkSettingsValue svalue = { NULL, { 0, }, };
2899
2900       key = keys[i];
2901       pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
2902       if (!pspec)
2903         {
2904           g_warning ("Unknown key %s in %s", key, path);
2905           continue;
2906         }
2907
2908       if (pspec->owner_type != G_OBJECT_TYPE (settings))
2909         continue;
2910
2911       value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
2912       switch (value_type)
2913         {
2914         case G_TYPE_BOOLEAN:
2915           {
2916             gboolean b_val;
2917
2918             g_value_init (&svalue.value, G_TYPE_LONG);
2919             b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
2920             if (!error)
2921               g_value_set_long (&svalue.value, b_val);
2922             break;
2923           }
2924
2925         case G_TYPE_INT:
2926           {
2927             gint i_val;
2928
2929             g_value_init (&svalue.value, G_TYPE_LONG);
2930             i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
2931             if (!error)
2932               g_value_set_long (&svalue.value, i_val);
2933             break;
2934           }
2935
2936         case G_TYPE_DOUBLE:
2937           {
2938             gdouble d_val;
2939
2940             g_value_init (&svalue.value, G_TYPE_DOUBLE);
2941             d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
2942             if (!error)
2943               g_value_set_double (&svalue.value, d_val);
2944             break;
2945           }
2946
2947         default:
2948           {
2949             gchar *s_val;
2950
2951             g_value_init (&svalue.value, G_TYPE_GSTRING);
2952             s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
2953             if (!error)
2954               g_value_take_boxed (&svalue.value, g_string_new (s_val));
2955             g_free (s_val);
2956             break;
2957           }
2958         }
2959       if (error)
2960         {
2961           g_warning ("Error setting %s in %s: %s", key, path, error->message);
2962           g_error_free (error);
2963           error = NULL;
2964         }
2965       else
2966         {
2967           if (g_getenv ("GTK_DEBUG"))
2968             svalue.origin = (gchar *)path;
2969           gtk_settings_set_property_value_internal (settings, key, &svalue, source);
2970           g_value_unset (&svalue.value);
2971         }
2972     }
2973
2974  out:
2975   g_strfreev (keys);
2976   g_key_file_free (keyfile);
2977 }