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