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