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