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