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