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