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