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