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