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