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