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