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