1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
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.
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.
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.
20 #define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
26 #include "gtkmodules.h"
27 #include "gtksettingsprivate.h"
30 #include "gtkwidget.h"
31 #include "gtkprivate.h"
32 #include "gtkcssproviderprivate.h"
33 #include "gtksymboliccolor.h"
34 #include "gtktypebuiltins.h"
35 #include "gtkversion.h"
37 #ifdef GDK_WINDOWING_X11
39 #include <pango/pangofc-fontmap.h>
45 * @Short_description: Sharing settings between applications
48 * GtkSettings provide a mechanism to share global settings between
51 * On the X window system, this sharing is realized by an
52 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
53 * manager that is usually part of the desktop environment, along with
54 * utilities that let the user change these settings. In the absence of
55 * an Xsettings manager, GTK+ reads default values for settings from
56 * <filename>settings.ini</filename> files in
57 * <filename>/etc/gtk-3.0</filename> and <filename>$XDG_CONFIG_HOME/gtk-3.0</filename>. These files must be valid key files (see #GKeyFile), and have
58 * a section called Settings. Themes can also provide default values
59 * for settings by installing a <filename>settings.ini</filename> file
60 * next to their <filename>gtk.css</filename> file.
62 * Applications can override system-wide settings with
63 * gtk_settings_set_string_property(), gtk_settings_set_long_property(),
64 * etc. This should be restricted to special cases though; GtkSettings are
65 * not meant as an application configuration facility. When doing so, you
66 * need to be aware that settings that are specific to individual widgets
67 * may not be available before the widget type has been realized at least
68 * once. The following example demonstrates a way to do this:
69 * <informalexample><programlisting>
70 * gtk_init (&argc, &argv);
72 * /* make sure the type is realized */
73 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
75 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
76 * </programlisting></informalexample>
78 * There is one GtkSettings instance per screen. It can be obtained with
79 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
80 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
81 * GtkSettings instance for the default screen.
85 #define DEFAULT_TIMEOUT_INITIAL 200
86 #define DEFAULT_TIMEOUT_REPEAT 20
87 #define DEFAULT_TIMEOUT_EXPAND 500
89 typedef struct _GtkSettingsPropertyValue GtkSettingsPropertyValue;
90 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
92 struct _GtkSettingsPrivate
94 GData *queued_settings; /* of type GtkSettingsValue* */
95 GtkSettingsPropertyValue *property_values;
97 GtkCssProvider *theme_provider;
98 GtkCssProvider *key_theme_provider;
103 GTK_SETTINGS_SOURCE_DEFAULT,
104 GTK_SETTINGS_SOURCE_THEME,
105 GTK_SETTINGS_SOURCE_XSETTING,
106 GTK_SETTINGS_SOURCE_APPLICATION
109 struct _GtkSettingsValuePrivate
111 GtkSettingsValue public;
112 GtkSettingsSource source;
115 struct _GtkSettingsPropertyValue
118 GtkSettingsSource source;
123 PROP_DOUBLE_CLICK_TIME,
124 PROP_DOUBLE_CLICK_DISTANCE,
126 PROP_CURSOR_BLINK_TIME,
127 PROP_CURSOR_BLINK_TIMEOUT,
130 PROP_ICON_THEME_NAME,
131 PROP_FALLBACK_ICON_THEME,
134 PROP_DND_DRAG_THRESHOLD,
143 PROP_CURSOR_THEME_NAME,
144 PROP_CURSOR_THEME_SIZE,
145 PROP_ALTERNATIVE_BUTTON_ORDER,
146 PROP_ALTERNATIVE_SORT_ARROWS,
147 PROP_SHOW_INPUT_METHOD_MENU,
148 PROP_SHOW_UNICODE_MENU,
149 PROP_TIMEOUT_INITIAL,
153 PROP_ENABLE_ANIMATIONS,
154 PROP_TOUCHSCREEN_MODE,
155 PROP_TOOLTIP_TIMEOUT,
156 PROP_TOOLTIP_BROWSE_TIMEOUT,
157 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
158 PROP_KEYNAV_CURSOR_ONLY,
159 PROP_KEYNAV_WRAP_AROUND,
162 PROP_FILE_CHOOSER_BACKEND,
164 PROP_PRINT_PREVIEW_COMMAND,
165 PROP_ENABLE_MNEMONICS,
167 PROP_RECENT_FILES_LIMIT,
169 PROP_RECENT_FILES_MAX_AGE,
170 PROP_FONTCONFIG_TIMESTAMP,
171 PROP_SOUND_THEME_NAME,
172 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
173 PROP_ENABLE_EVENT_SOUNDS,
174 PROP_ENABLE_TOOLTIPS,
176 PROP_TOOLBAR_ICON_SIZE,
178 PROP_APPLICATION_PREFER_DARK_THEME,
180 PROP_ENTRY_SELECT_ON_FOCUS,
181 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
183 PROP_MENU_BAR_POPUP_DELAY,
184 PROP_SCROLLED_WINDOW_PLACEMENT,
185 PROP_CAN_CHANGE_ACCELS,
186 PROP_MENU_POPUP_DELAY,
187 PROP_MENU_POPDOWN_DELAY,
188 PROP_LABEL_SELECT_ON_FOCUS,
190 PROP_IM_PREEDIT_STYLE,
194 /* --- prototypes --- */
195 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
197 static void gtk_settings_finalize (GObject *object);
198 static void gtk_settings_get_property (GObject *object,
202 static void gtk_settings_set_property (GObject *object,
206 static void gtk_settings_notify (GObject *object,
208 static guint settings_install_property_parser (GtkSettingsClass *class,
210 GtkRcPropertyParser parser);
211 static void settings_update_double_click (GtkSettings *settings);
212 static void settings_update_modules (GtkSettings *settings);
214 static void settings_update_cursor_theme (GtkSettings *settings);
215 static void settings_update_resolution (GtkSettings *settings);
216 static void settings_update_font_options (GtkSettings *settings);
217 static gboolean settings_update_fontconfig (GtkSettings *settings);
218 static void settings_update_color_scheme (GtkSettings *settings);
219 static void settings_update_theme (GtkSettings *settings);
220 static void settings_update_key_theme (GtkSettings *settings);
222 static void merge_color_scheme (GtkSettings *settings,
224 GtkSettingsSource source);
225 static gchar *get_color_scheme (GtkSettings *settings);
226 static GHashTable *get_color_hash (GtkSettings *settings);
227 static void gtk_settings_load_from_key_file (GtkSettings *settings,
229 GtkSettingsSource source);
231 /* the default palette for GtkColorSelelection */
232 static const gchar default_color_palette[] =
233 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
234 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
236 /* --- variables --- */
237 static GQuark quark_property_parser = 0;
238 static GSList *object_list = NULL;
239 static guint class_n_properties = 0;
242 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
243 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
244 gtk_settings_provider_iface_init));
246 /* --- functions --- */
248 gtk_settings_init (GtkSettings *settings)
250 GtkSettingsPrivate *priv;
251 GParamSpec **pspecs, **p;
255 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
259 settings->priv = priv;
260 g_datalist_init (&priv->queued_settings);
261 object_list = g_slist_prepend (object_list, settings);
263 /* build up property array for all yet existing properties and queue
264 * notification for them (at least notification for internal properties
265 * will instantly be caught)
267 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
268 for (p = pspecs; *p; p++)
269 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
271 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
273 g_object_freeze_notify (G_OBJECT (settings));
275 for (p = pspecs; *p; p++)
277 GParamSpec *pspec = *p;
278 GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
280 if (pspec->owner_type != G_OBJECT_TYPE (settings))
282 g_value_init (&priv->property_values[i].value, value_type);
283 g_param_value_set_default (pspec, &priv->property_values[i].value);
285 g_object_notify (G_OBJECT (settings), pspec->name);
286 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
291 path = g_build_filename (GTK_SYSCONFDIR, "gtk-3.0", "settings.ini", NULL);
292 if (g_file_test (path, G_FILE_TEST_EXISTS))
293 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
296 path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "settings.ini", NULL);
297 if (g_file_test (path, G_FILE_TEST_EXISTS))
298 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
301 g_object_thaw_notify (G_OBJECT (settings));
305 gtk_settings_class_init (GtkSettingsClass *class)
307 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
310 gobject_class->finalize = gtk_settings_finalize;
311 gobject_class->get_property = gtk_settings_get_property;
312 gobject_class->set_property = gtk_settings_set_property;
313 gobject_class->notify = gtk_settings_notify;
315 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
316 result = settings_install_property_parser (class,
317 g_param_spec_int ("gtk-double-click-time",
318 P_("Double Click Time"),
319 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
321 GTK_PARAM_READWRITE),
323 g_assert (result == PROP_DOUBLE_CLICK_TIME);
324 result = settings_install_property_parser (class,
325 g_param_spec_int ("gtk-double-click-distance",
326 P_("Double Click Distance"),
327 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
329 GTK_PARAM_READWRITE),
331 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
334 * GtkSettings:gtk-cursor-blink:
336 * Whether the cursor should blink.
338 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
339 * which allows more flexible control over cursor blinking.
341 result = settings_install_property_parser (class,
342 g_param_spec_boolean ("gtk-cursor-blink",
344 P_("Whether the cursor should blink"),
346 GTK_PARAM_READWRITE),
348 g_assert (result == PROP_CURSOR_BLINK);
349 result = settings_install_property_parser (class,
350 g_param_spec_int ("gtk-cursor-blink-time",
351 P_("Cursor Blink Time"),
352 P_("Length of the cursor blink cycle, in milliseconds"),
354 GTK_PARAM_READWRITE),
356 g_assert (result == PROP_CURSOR_BLINK_TIME);
359 * GtkSettings:gtk-cursor-blink-timeout:
361 * Time after which the cursor stops blinking, in seconds.
362 * The timer is reset after each user interaction.
364 * Setting this to zero has the same effect as setting
365 * #GtkSettings:gtk-cursor-blink to %FALSE.
369 result = settings_install_property_parser (class,
370 g_param_spec_int ("gtk-cursor-blink-timeout",
371 P_("Cursor Blink Timeout"),
372 P_("Time after which the cursor stops blinking, in seconds"),
373 1, G_MAXINT, G_MAXINT,
374 GTK_PARAM_READWRITE),
376 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
377 result = settings_install_property_parser (class,
378 g_param_spec_boolean ("gtk-split-cursor",
380 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
382 GTK_PARAM_READWRITE),
384 g_assert (result == PROP_SPLIT_CURSOR);
385 result = settings_install_property_parser (class,
386 g_param_spec_string ("gtk-theme-name",
388 P_("Name of theme to load"),
390 GTK_PARAM_READWRITE),
392 g_assert (result == PROP_THEME_NAME);
394 result = settings_install_property_parser (class,
395 g_param_spec_string ("gtk-icon-theme-name",
396 P_("Icon Theme Name"),
397 P_("Name of icon theme to use"),
399 GTK_PARAM_READWRITE),
401 g_assert (result == PROP_ICON_THEME_NAME);
403 result = settings_install_property_parser (class,
404 g_param_spec_string ("gtk-fallback-icon-theme",
405 P_("Fallback Icon Theme Name"),
406 P_("Name of a icon theme to fall back to"),
408 GTK_PARAM_READWRITE),
410 g_assert (result == PROP_FALLBACK_ICON_THEME);
412 result = settings_install_property_parser (class,
413 g_param_spec_string ("gtk-key-theme-name",
414 P_("Key Theme Name"),
415 P_("Name of key theme to load"),
417 GTK_PARAM_READWRITE),
419 g_assert (result == PROP_KEY_THEME_NAME);
421 result = settings_install_property_parser (class,
422 g_param_spec_string ("gtk-menu-bar-accel",
423 P_("Menu bar accelerator"),
424 P_("Keybinding to activate the menu bar"),
426 GTK_PARAM_READWRITE),
428 g_assert (result == PROP_MENU_BAR_ACCEL);
430 result = settings_install_property_parser (class,
431 g_param_spec_int ("gtk-dnd-drag-threshold",
432 P_("Drag threshold"),
433 P_("Number of pixels the cursor can move before dragging"),
435 GTK_PARAM_READWRITE),
437 g_assert (result == PROP_DND_DRAG_THRESHOLD);
439 result = settings_install_property_parser (class,
440 g_param_spec_string ("gtk-font-name",
442 P_("Name of default font to use"),
444 GTK_PARAM_READWRITE),
446 g_assert (result == PROP_FONT_NAME);
449 * GtkSettings:gtk-icon-sizes:
451 * A list of icon sizes. The list is separated by colons, and
454 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
456 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
457 * GTK+ itself use the following named icon sizes: gtk-menu,
458 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
459 * gtk-dialog. Applications can register their own named icon
460 * sizes with gtk_icon_size_register().
462 result = settings_install_property_parser (class,
463 g_param_spec_string ("gtk-icon-sizes",
465 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
467 GTK_PARAM_READWRITE),
469 g_assert (result == PROP_ICON_SIZES);
471 result = settings_install_property_parser (class,
472 g_param_spec_string ("gtk-modules",
474 P_("List of currently active GTK modules"),
476 GTK_PARAM_READWRITE),
478 g_assert (result == PROP_MODULES);
480 #ifdef GDK_WINDOWING_X11
481 result = settings_install_property_parser (class,
482 g_param_spec_int ("gtk-xft-antialias",
484 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
486 GTK_PARAM_READWRITE),
489 g_assert (result == PROP_XFT_ANTIALIAS);
491 result = settings_install_property_parser (class,
492 g_param_spec_int ("gtk-xft-hinting",
494 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
496 GTK_PARAM_READWRITE),
499 g_assert (result == PROP_XFT_HINTING);
501 result = settings_install_property_parser (class,
502 g_param_spec_string ("gtk-xft-hintstyle",
503 P_("Xft Hint Style"),
504 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
506 GTK_PARAM_READWRITE),
509 g_assert (result == PROP_XFT_HINTSTYLE);
511 result = settings_install_property_parser (class,
512 g_param_spec_string ("gtk-xft-rgba",
514 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
516 GTK_PARAM_READWRITE),
519 g_assert (result == PROP_XFT_RGBA);
521 result = settings_install_property_parser (class,
522 g_param_spec_int ("gtk-xft-dpi",
524 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
526 GTK_PARAM_READWRITE),
529 g_assert (result == PROP_XFT_DPI);
531 result = settings_install_property_parser (class,
532 g_param_spec_string ("gtk-cursor-theme-name",
533 P_("Cursor theme name"),
534 P_("Name of the cursor theme to use, or NULL to use the default theme"),
536 GTK_PARAM_READWRITE),
538 g_assert (result == PROP_CURSOR_THEME_NAME);
540 result = settings_install_property_parser (class,
541 g_param_spec_int ("gtk-cursor-theme-size",
542 P_("Cursor theme size"),
543 P_("Size to use for cursors, or 0 to use the default size"),
545 GTK_PARAM_READWRITE),
548 g_assert (result == PROP_CURSOR_THEME_SIZE);
550 #endif /* GDK_WINDOWING_X11 */
551 result = settings_install_property_parser (class,
552 g_param_spec_boolean ("gtk-alternative-button-order",
553 P_("Alternative button order"),
554 P_("Whether buttons in dialogs should use the alternative button order"),
556 GTK_PARAM_READWRITE),
558 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
561 * GtkSettings:gtk-alternative-sort-arrows:
563 * Controls the direction of the sort indicators in sorted list and tree
564 * views. By default an arrow pointing down means the column is sorted
565 * in ascending order. When set to %TRUE, this order will be inverted.
569 result = settings_install_property_parser (class,
570 g_param_spec_boolean ("gtk-alternative-sort-arrows",
571 P_("Alternative sort indicator direction"),
572 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
574 GTK_PARAM_READWRITE),
576 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
578 result = settings_install_property_parser (class,
579 g_param_spec_boolean ("gtk-show-input-method-menu",
580 P_("Show the 'Input Methods' menu"),
581 P_("Whether the context menus of entries and text views should offer to change the input method"),
583 GTK_PARAM_READWRITE),
585 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
587 result = settings_install_property_parser (class,
588 g_param_spec_boolean ("gtk-show-unicode-menu",
589 P_("Show the 'Insert Unicode Control Character' menu"),
590 P_("Whether the context menus of entries and text views should offer to insert control characters"),
592 GTK_PARAM_READWRITE),
594 g_assert (result == PROP_SHOW_UNICODE_MENU);
596 result = settings_install_property_parser (class,
597 g_param_spec_int ("gtk-timeout-initial",
599 P_("Starting value for timeouts, when button is pressed"),
600 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
601 GTK_PARAM_READWRITE),
604 g_assert (result == PROP_TIMEOUT_INITIAL);
606 result = settings_install_property_parser (class,
607 g_param_spec_int ("gtk-timeout-repeat",
608 P_("Repeat timeout"),
609 P_("Repeat value for timeouts, when button is pressed"),
610 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
611 GTK_PARAM_READWRITE),
614 g_assert (result == PROP_TIMEOUT_REPEAT);
616 result = settings_install_property_parser (class,
617 g_param_spec_int ("gtk-timeout-expand",
618 P_("Expand timeout"),
619 P_("Expand value for timeouts, when a widget is expanding a new region"),
620 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
621 GTK_PARAM_READWRITE),
624 g_assert (result == PROP_TIMEOUT_EXPAND);
627 * GtkSettings:gtk-color-scheme:
629 * A palette of named colors for use in themes. The format of the string is
635 * Color names must be acceptable as identifiers in the
636 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
637 * color specifications must be in the format accepted by
640 * Note that due to the way the color tables from different sources are
641 * merged, color specifications will be converted to hexadecimal form
642 * when getting this property.
644 * Starting with GTK+ 2.12, the entries can alternatively be separated
645 * by ';' instead of newlines:
647 * name1: color1; name2: color2; ...
652 result = settings_install_property_parser (class,
653 g_param_spec_string ("gtk-color-scheme",
655 P_("A palette of named colors for use in themes"),
657 GTK_PARAM_READWRITE),
660 g_assert (result == PROP_COLOR_SCHEME);
662 result = settings_install_property_parser (class,
663 g_param_spec_boolean ("gtk-enable-animations",
664 P_("Enable Animations"),
665 P_("Whether to enable toolkit-wide animations."),
667 GTK_PARAM_READWRITE),
670 g_assert (result == PROP_ENABLE_ANIMATIONS);
673 * GtkSettings:gtk-touchscreen-mode:
675 * When %TRUE, there are no motion notify events delivered on this screen,
676 * and widgets can't use the pointer hovering them for any essential
681 result = settings_install_property_parser (class,
682 g_param_spec_boolean ("gtk-touchscreen-mode",
683 P_("Enable Touchscreen Mode"),
684 P_("When TRUE, there are no motion notify events delivered on this screen"),
686 GTK_PARAM_READWRITE),
689 g_assert (result == PROP_TOUCHSCREEN_MODE);
692 * GtkSettings:gtk-tooltip-timeout:
694 * Time, in milliseconds, after which a tooltip could appear if the
695 * cursor is hovering on top of a widget.
699 result = settings_install_property_parser (class,
700 g_param_spec_int ("gtk-tooltip-timeout",
701 P_("Tooltip timeout"),
702 P_("Timeout before tooltip is shown"),
705 GTK_PARAM_READWRITE),
708 g_assert (result == PROP_TOOLTIP_TIMEOUT);
711 * GtkSettings:gtk-tooltip-browse-timeout:
713 * Controls the time after which tooltips will appear when
714 * browse mode is enabled, in milliseconds.
716 * Browse mode is enabled when the mouse pointer moves off an object
717 * where a tooltip was currently being displayed. If the mouse pointer
718 * hits another object before the browse mode timeout expires (see
719 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
720 * amount of milliseconds specified by this setting to popup the tooltip
721 * for the new object.
725 result = settings_install_property_parser (class,
726 g_param_spec_int ("gtk-tooltip-browse-timeout",
727 P_("Tooltip browse timeout"),
728 P_("Timeout before tooltip is shown when browse mode is enabled"),
731 GTK_PARAM_READWRITE),
734 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
737 * GtkSettings:gtk-tooltip-browse-mode-timeout:
739 * Amount of time, in milliseconds, after which the browse mode
742 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
747 result = settings_install_property_parser (class,
748 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
749 P_("Tooltip browse mode timeout"),
750 P_("Timeout after which browse mode is disabled"),
753 GTK_PARAM_READWRITE),
756 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
759 * GtkSettings:gtk-keynav-cursor-only:
761 * When %TRUE, keyboard navigation should be able to reach all widgets
762 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
763 * to be present on the used input device.
767 result = settings_install_property_parser (class,
768 g_param_spec_boolean ("gtk-keynav-cursor-only",
769 P_("Keynav Cursor Only"),
770 P_("When TRUE, there are only cursor keys available to navigate widgets"),
772 GTK_PARAM_READWRITE),
775 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
778 * GtkSettings:gtk-keynav-wrap-around:
780 * When %TRUE, some widgets will wrap around when doing keyboard
781 * navigation, such as menus, menubars and notebooks.
785 result = settings_install_property_parser (class,
786 g_param_spec_boolean ("gtk-keynav-wrap-around",
787 P_("Keynav Wrap Around"),
788 P_("Whether to wrap around when keyboard-navigating widgets"),
790 GTK_PARAM_READWRITE),
793 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
796 * GtkSettings:gtk-error-bell:
798 * When %TRUE, keyboard navigation and other input-related errors
799 * will cause a beep. Since the error bell is implemented using
800 * gdk_window_beep(), the windowing system may offer ways to
801 * configure the error bell in many ways, such as flashing the
802 * window or similar visual effects.
806 result = settings_install_property_parser (class,
807 g_param_spec_boolean ("gtk-error-bell",
809 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
811 GTK_PARAM_READWRITE),
814 g_assert (result == PROP_ERROR_BELL);
817 * GtkSettings:color-hash:
819 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
820 * setting, mapping color names to #GdkColor<!-- -->s.
824 result = settings_install_property_parser (class,
825 g_param_spec_boxed ("color-hash",
827 P_("A hash table representation of the color scheme."),
831 g_assert (result == PROP_COLOR_HASH);
833 result = settings_install_property_parser (class,
834 g_param_spec_string ("gtk-file-chooser-backend",
835 P_("Default file chooser backend"),
836 P_("Name of the GtkFileChooser backend to use by default"),
838 GTK_PARAM_READWRITE),
840 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
843 * GtkSettings:gtk-print-backends:
845 * A comma-separated list of print backends to use in the print
846 * dialog. Available print backends depend on the GTK+ installation,
847 * and may include "file", "cups", "lpr" or "papi".
851 result = settings_install_property_parser (class,
852 g_param_spec_string ("gtk-print-backends",
853 P_("Default print backend"),
854 P_("List of the GtkPrintBackend backends to use by default"),
856 GTK_PARAM_READWRITE),
858 g_assert (result == PROP_PRINT_BACKENDS);
861 * GtkSettings:gtk-print-preview-command:
863 * A command to run for displaying the print preview. The command
864 * should contain a %f placeholder, which will get replaced by
865 * the path to the pdf file. The command may also contain a %s
866 * placeholder, which will get replaced by the path to a file
867 * containing the print settings in the format produced by
868 * gtk_print_settings_to_file().
870 * The preview application is responsible for removing the pdf file
871 * and the print settings file when it is done.
875 result = settings_install_property_parser (class,
876 g_param_spec_string ("gtk-print-preview-command",
877 P_("Default command to run when displaying a print preview"),
878 P_("Command to run when displaying a print preview"),
879 GTK_PRINT_PREVIEW_COMMAND,
880 GTK_PARAM_READWRITE),
882 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
885 * GtkSettings:gtk-enable-mnemonics:
887 * Whether labels and menu items should have visible mnemonics which
892 result = settings_install_property_parser (class,
893 g_param_spec_boolean ("gtk-enable-mnemonics",
894 P_("Enable Mnemonics"),
895 P_("Whether labels should have mnemonics"),
897 GTK_PARAM_READWRITE),
899 g_assert (result == PROP_ENABLE_MNEMONICS);
902 * GtkSettings:gtk-enable-accels:
904 * Whether menu items should have visible accelerators which can be
909 result = settings_install_property_parser (class,
910 g_param_spec_boolean ("gtk-enable-accels",
911 P_("Enable Accelerators"),
912 P_("Whether menu items should have accelerators"),
914 GTK_PARAM_READWRITE),
916 g_assert (result == PROP_ENABLE_ACCELS);
919 * GtkSettings:gtk-recent-files-limit:
921 * The number of recently used files that should be displayed by default by
922 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
923 * -1 means every recently used file stored.
927 result = settings_install_property_parser (class,
928 g_param_spec_int ("gtk-recent-files-limit",
929 P_("Recent Files Limit"),
930 P_("Number of recently used files"),
933 GTK_PARAM_READWRITE),
935 g_assert (result == PROP_RECENT_FILES_LIMIT);
938 * GtkSettings:gtk-im-module:
940 * Which IM (input method) module should be used by default. This is the
941 * input method that will be used if the user has not explicitly chosen
942 * another input method from the IM context menu.
944 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
946 result = settings_install_property_parser (class,
947 g_param_spec_string ("gtk-im-module",
948 P_("Default IM module"),
949 P_("Which IM module should be used by default"),
951 GTK_PARAM_READWRITE),
953 g_assert (result == PROP_IM_MODULE);
956 * GtkSettings:gtk-recent-files-max-age:
958 * The maximum age, in days, of the items inside the recently used
959 * resources list. Items older than this setting will be excised
960 * from the list. If set to 0, the list will always be empty; if
961 * set to -1, no item will be removed.
965 result = settings_install_property_parser (class,
966 g_param_spec_int ("gtk-recent-files-max-age",
967 P_("Recent Files Max Age"),
968 P_("Maximum age of recently used files, in days"),
971 GTK_PARAM_READWRITE),
973 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
975 result = settings_install_property_parser (class,
976 g_param_spec_uint ("gtk-fontconfig-timestamp",
977 P_("Fontconfig configuration timestamp"),
978 P_("Timestamp of current fontconfig configuration"),
980 GTK_PARAM_READWRITE),
983 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
986 * GtkSettings:gtk-sound-theme-name:
988 * The XDG sound theme to use for event sounds.
990 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
991 * for more information on event sounds and sound themes.
993 * GTK+ itself does not support event sounds, you have to use a loadable
994 * module like the one that comes with libcanberra.
998 result = settings_install_property_parser (class,
999 g_param_spec_string ("gtk-sound-theme-name",
1000 P_("Sound Theme Name"),
1001 P_("XDG sound theme name"),
1003 GTK_PARAM_READWRITE),
1005 g_assert (result == PROP_SOUND_THEME_NAME);
1008 * GtkSettings:gtk-enable-input-feedback-sounds:
1010 * Whether to play event sounds as feedback to user input.
1012 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1013 * for more information on event sounds and sound themes.
1015 * GTK+ itself does not support event sounds, you have to use a loadable
1016 * module like the one that comes with libcanberra.
1020 result = settings_install_property_parser (class,
1021 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1022 /* Translators: this means sounds that are played as feedback to user input */
1023 P_("Audible Input Feedback"),
1024 P_("Whether to play event sounds as feedback to user input"),
1026 GTK_PARAM_READWRITE),
1028 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1031 * GtkSettings:gtk-enable-event-sounds:
1033 * Whether to play any event sounds at all.
1035 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1036 * for more information on event sounds and sound themes.
1038 * GTK+ itself does not support event sounds, you have to use a loadable
1039 * module like the one that comes with libcanberra.
1043 result = settings_install_property_parser (class,
1044 g_param_spec_boolean ("gtk-enable-event-sounds",
1045 P_("Enable Event Sounds"),
1046 P_("Whether to play any event sounds at all"),
1048 GTK_PARAM_READWRITE),
1050 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1053 * GtkSettings:gtk-enable-tooltips:
1055 * Whether tooltips should be shown on widgets.
1059 result = settings_install_property_parser (class,
1060 g_param_spec_boolean ("gtk-enable-tooltips",
1061 P_("Enable Tooltips"),
1062 P_("Whether tooltips should be shown on widgets"),
1064 GTK_PARAM_READWRITE),
1066 g_assert (result == PROP_ENABLE_TOOLTIPS);
1069 * GtkSettings:gtk-toolbar-style:
1071 * The size of icons in default toolbars.
1073 result = settings_install_property_parser (class,
1074 g_param_spec_enum ("gtk-toolbar-style",
1075 P_("Toolbar style"),
1076 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1077 GTK_TYPE_TOOLBAR_STYLE,
1079 GTK_PARAM_READWRITE),
1080 gtk_rc_property_parse_enum);
1081 g_assert (result == PROP_TOOLBAR_STYLE);
1084 * GtkSettings:gtk-toolbar-icon-size:
1086 * The size of icons in default toolbars.
1088 result = settings_install_property_parser (class,
1089 g_param_spec_enum ("gtk-toolbar-icon-size",
1090 P_("Toolbar Icon Size"),
1091 P_("The size of icons in default toolbars."),
1093 GTK_ICON_SIZE_LARGE_TOOLBAR,
1094 GTK_PARAM_READWRITE),
1095 gtk_rc_property_parse_enum);
1096 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1099 * GtkSettings:gtk-auto-mnemonics:
1101 * Whether mnemonics should be automatically shown and hidden when the user
1102 * presses the mnemonic activator.
1106 result = settings_install_property_parser (class,
1107 g_param_spec_boolean ("gtk-auto-mnemonics",
1108 P_("Auto Mnemonics"),
1109 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1111 GTK_PARAM_READWRITE),
1113 g_assert (result == PROP_AUTO_MNEMONICS);
1116 * GtkSettings:gtk-application-prefer-dark-theme:
1118 * Whether the application prefers to use a dark theme. If a GTK+ theme
1119 * includes a dark variant, it will be used instead of the configured
1122 * Some applications benefit from minimizing the amount of light pollution that
1123 * interferes with the content. Good candidates for dark themes are photo and
1124 * video editors that make the actual content get all the attention and minimize
1125 * the distraction of the chrome.
1127 * Dark themes should not be used for documents, where large spaces are white/light
1128 * and the dark chrome creates too much contrast (web browser, text editor...).
1132 result = settings_install_property_parser (class,
1133 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1134 P_("Application prefers a dark theme"),
1135 P_("Whether the application prefers to have a dark theme."),
1137 GTK_PARAM_READWRITE),
1139 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1142 * GtkSettings::gtk-button-images:
1144 * Whether images should be shown on buttons
1148 result = settings_install_property_parser (class,
1149 g_param_spec_boolean ("gtk-button-images",
1150 P_("Show button images"),
1151 P_("Whether images should be shown on buttons"),
1153 GTK_PARAM_READWRITE),
1155 g_assert (result == PROP_BUTTON_IMAGES);
1157 result = settings_install_property_parser (class,
1158 g_param_spec_boolean ("gtk-entry-select-on-focus",
1159 P_("Select on focus"),
1160 P_("Whether to select the contents of an entry when it is focused"),
1162 GTK_PARAM_READWRITE),
1164 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1167 * GtkSettings:gtk-entry-password-hint-timeout:
1169 * How long to show the last input character in hidden
1170 * entries. This value is in milliseconds. 0 disables showing the
1171 * last char. 600 is a good value for enabling it.
1175 result = settings_install_property_parser (class,
1176 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1177 P_("Password Hint Timeout"),
1178 P_("How long to show the last input character in hidden entries"),
1181 GTK_PARAM_READWRITE),
1183 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1185 result = settings_install_property_parser (class,
1186 g_param_spec_boolean ("gtk-menu-images",
1187 P_("Show menu images"),
1188 P_("Whether images should be shown in menus"),
1190 GTK_PARAM_READWRITE),
1192 g_assert (result == PROP_MENU_IMAGES);
1194 result = settings_install_property_parser (class,
1195 g_param_spec_int ("gtk-menu-bar-popup-delay",
1196 P_("Delay before drop down menus appear"),
1197 P_("Delay before the submenus of a menu bar appear"),
1200 GTK_PARAM_READWRITE),
1202 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1205 * GtkSettings:gtk-scrolled-window-placement:
1207 * Where the contents of scrolled windows are located with respect to the
1208 * scrollbars, if not overridden by the scrolled window's own placement.
1212 result = settings_install_property_parser (class,
1213 g_param_spec_enum ("gtk-scrolled-window-placement",
1214 P_("Scrolled Window Placement"),
1215 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1216 GTK_TYPE_CORNER_TYPE,
1217 GTK_CORNER_TOP_LEFT,
1218 GTK_PARAM_READWRITE),
1219 gtk_rc_property_parse_enum);
1220 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1222 result = settings_install_property_parser (class,
1223 g_param_spec_boolean ("gtk-can-change-accels",
1224 P_("Can change accelerators"),
1225 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1227 GTK_PARAM_READWRITE),
1229 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1231 result = settings_install_property_parser (class,
1232 g_param_spec_int ("gtk-menu-popup-delay",
1233 P_("Delay before submenus appear"),
1234 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1237 GTK_PARAM_READWRITE),
1239 g_assert (result == PROP_MENU_POPUP_DELAY);
1241 result = settings_install_property_parser (class,
1242 g_param_spec_int ("gtk-menu-popdown-delay",
1243 P_("Delay before hiding a submenu"),
1244 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1247 GTK_PARAM_READWRITE),
1249 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1251 result = settings_install_property_parser (class,
1252 g_param_spec_boolean ("gtk-label-select-on-focus",
1253 P_("Select on focus"),
1254 P_("Whether to select the contents of a selectable label when it is focused"),
1256 GTK_PARAM_READWRITE),
1258 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1260 result = settings_install_property_parser (class,
1261 g_param_spec_string ("gtk-color-palette",
1262 P_("Custom palette"),
1263 P_("Palette to use in the color selector"),
1264 default_color_palette,
1265 GTK_PARAM_READWRITE),
1267 g_assert (result == PROP_COLOR_PALETTE);
1269 result = settings_install_property_parser (class,
1270 g_param_spec_enum ("gtk-im-preedit-style",
1271 P_("IM Preedit style"),
1272 P_("How to draw the input method preedit string"),
1273 GTK_TYPE_IM_PREEDIT_STYLE,
1274 GTK_IM_PREEDIT_CALLBACK,
1275 GTK_PARAM_READWRITE),
1276 gtk_rc_property_parse_enum);
1277 g_assert (result == PROP_IM_PREEDIT_STYLE);
1279 result = settings_install_property_parser (class,
1280 g_param_spec_enum ("gtk-im-status-style",
1281 P_("IM Status style"),
1282 P_("How to draw the input method statusbar"),
1283 GTK_TYPE_IM_STATUS_STYLE,
1284 GTK_IM_STATUS_CALLBACK,
1285 GTK_PARAM_READWRITE),
1286 gtk_rc_property_parse_enum);
1287 g_assert (result == PROP_IM_STATUS_STYLE);
1289 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1292 static GtkStyleProperties *
1293 gtk_settings_get_style (GtkStyleProvider *provider,
1294 GtkWidgetPath *path)
1296 PangoFontDescription *font_desc;
1297 gchar *font_name, *color_scheme;
1298 GtkSettings *settings;
1299 GtkStyleProperties *props;
1303 settings = GTK_SETTINGS (provider);
1304 props = gtk_style_properties_new ();
1306 g_object_get (settings,
1307 "gtk-font-name", &font_name,
1308 "gtk-color-scheme", &color_scheme,
1311 colors = g_strsplit_set (color_scheme, "\n;", -1);
1313 for (i = 0; colors[i]; i++)
1315 GtkSymbolicColor *color;
1323 pos = strchr (colors[i], ':');
1328 /* Set NUL after color name */
1332 /* Find start of color string */
1336 if (!*pos || !gdk_rgba_parse (&col, pos))
1339 color = gtk_symbolic_color_new_literal (&col);
1340 gtk_style_properties_map_color (props, name, color);
1341 gtk_symbolic_color_unref (color);
1344 font_desc = pango_font_description_from_string (font_name);
1346 gtk_style_properties_set (props, 0,
1350 pango_font_description_free (font_desc);
1351 g_strfreev (colors);
1352 g_free (color_scheme);
1359 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1361 iface->get_style = gtk_settings_get_style;
1365 gtk_settings_finalize (GObject *object)
1367 GtkSettings *settings = GTK_SETTINGS (object);
1368 GtkSettingsPrivate *priv = settings->priv;
1371 object_list = g_slist_remove (object_list, settings);
1373 for (i = 0; i < class_n_properties; i++)
1374 g_value_unset (&priv->property_values[i].value);
1375 g_free (priv->property_values);
1377 g_datalist_clear (&priv->queued_settings);
1379 if (priv->theme_provider)
1380 g_object_unref (priv->theme_provider);
1382 if (priv->key_theme_provider)
1383 g_object_unref (priv->key_theme_provider);
1385 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1389 settings_init_style (GtkSettings *settings)
1391 static GtkCssProvider *css_provider = NULL;
1393 GdkScreen *screen = settings->priv->screen;
1394 GtkCssProvider *default_provider;
1396 /* Add provider for user file */
1397 if (G_UNLIKELY (!css_provider))
1401 css_provider = gtk_css_provider_new ();
1402 css_path = g_build_filename (g_get_user_config_dir (),
1407 if (g_file_test (css_path,
1408 G_FILE_TEST_IS_REGULAR))
1409 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1414 gtk_style_context_add_provider_for_screen (screen,
1415 GTK_STYLE_PROVIDER (css_provider),
1416 GTK_STYLE_PROVIDER_PRIORITY_USER);
1418 default_provider = gtk_css_provider_get_default ();
1419 gtk_style_context_add_provider_for_screen (screen,
1420 GTK_STYLE_PROVIDER (default_provider),
1421 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1423 gtk_style_context_add_provider_for_screen (screen,
1424 GTK_STYLE_PROVIDER (settings),
1425 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1427 settings_update_theme (settings);
1428 settings_update_key_theme (settings);
1432 * gtk_settings_get_for_screen:
1433 * @screen: a #GdkScreen.
1435 * Gets the #GtkSettings object for @screen, creating it if necessary.
1437 * Return value: (transfer none): a #GtkSettings object.
1442 gtk_settings_get_for_screen (GdkScreen *screen)
1444 GtkSettings *settings;
1446 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1448 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1451 #ifdef GDK_WINDOWING_QUARTZ
1452 if (GDK_IS_QUARTZ_SCREEN (screen))
1453 settings = g_object_new (GTK_TYPE_SETTINGS, "gtk-key-theme-name", "Mac", NULL);
1456 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1457 settings->priv->screen = screen;
1458 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1459 settings, g_object_unref);
1461 settings_init_style (settings);
1462 settings_update_double_click (settings);
1463 settings_update_cursor_theme (settings);
1464 settings_update_resolution (settings);
1465 settings_update_font_options (settings);
1466 settings_update_color_scheme (settings);
1473 * gtk_settings_get_default:
1475 * Gets the #GtkSettings object for the default GDK screen, creating
1476 * it if necessary. See gtk_settings_get_for_screen().
1478 * Return value: (transfer none): a #GtkSettings object. If there is no default
1479 * screen, then returns %NULL.
1482 gtk_settings_get_default (void)
1484 GdkScreen *screen = gdk_screen_get_default ();
1487 return gtk_settings_get_for_screen (screen);
1493 gtk_settings_set_property (GObject *object,
1495 const GValue *value,
1498 GtkSettings *settings = GTK_SETTINGS (object);
1499 GtkSettingsPrivate *priv = settings->priv;
1501 g_value_copy (value, &priv->property_values[property_id - 1].value);
1502 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1504 if (pspec->param_id == PROP_COLOR_SCHEME)
1505 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1509 gtk_settings_get_property (GObject *object,
1514 GtkSettings *settings = GTK_SETTINGS (object);
1515 GtkSettingsPrivate *priv = settings->priv;
1516 GType value_type = G_VALUE_TYPE (value);
1517 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1519 /* handle internal properties */
1520 switch (property_id)
1522 case PROP_COLOR_HASH:
1523 g_value_set_boxed (value, get_color_hash (settings));
1525 case PROP_COLOR_SCHEME:
1526 g_value_take_string (value, get_color_scheme (settings));
1531 /* For enums and strings, we need to get the value as a string,
1532 * not as an int, since we support using names/nicks as the setting
1535 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1536 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1537 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1538 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1540 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1541 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1542 g_value_copy (&priv->property_values[property_id - 1].value, value);
1544 g_param_value_validate (pspec, value);
1548 GValue val = { 0, };
1550 /* Try to get xsetting as a string and parse it. */
1552 g_value_init (&val, G_TYPE_STRING);
1554 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1555 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1557 g_value_copy (&priv->property_values[property_id - 1].value, value);
1561 GValue tmp_value = { 0, };
1562 GValue gstring_value = { 0, };
1563 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1565 g_value_init (&gstring_value, G_TYPE_GSTRING);
1566 g_value_take_boxed (&gstring_value,
1567 g_string_new (g_value_get_string (&val)));
1569 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1571 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1574 g_value_copy (&tmp_value, value);
1575 g_param_value_validate (pspec, value);
1579 g_value_copy (&priv->property_values[property_id - 1].value, value);
1582 g_value_unset (&gstring_value);
1583 g_value_unset (&tmp_value);
1586 g_value_unset (&val);
1591 gtk_settings_notify (GObject *object,
1594 GtkSettings *settings = GTK_SETTINGS (object);
1595 GtkSettingsPrivate *priv = settings->priv;
1596 guint property_id = pspec->param_id;
1598 if (priv->screen == NULL) /* initialization */
1601 switch (property_id)
1604 settings_update_modules (settings);
1606 case PROP_DOUBLE_CLICK_TIME:
1607 case PROP_DOUBLE_CLICK_DISTANCE:
1608 settings_update_double_click (settings);
1610 case PROP_COLOR_SCHEME:
1611 settings_update_color_scheme (settings);
1612 gtk_style_context_reset_widgets (priv->screen);
1614 case PROP_KEY_THEME_NAME:
1615 settings_update_key_theme (settings);
1617 case PROP_THEME_NAME:
1618 case PROP_APPLICATION_PREFER_DARK_THEME:
1619 settings_update_theme (settings);
1622 settings_update_resolution (settings);
1623 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1624 * widgets with gtk_widget_style_set(), and also causes more
1625 * recomputation than necessary.
1627 gtk_style_context_reset_widgets (priv->screen);
1629 case PROP_XFT_ANTIALIAS:
1630 case PROP_XFT_HINTING:
1631 case PROP_XFT_HINTSTYLE:
1633 settings_update_font_options (settings);
1634 gtk_style_context_reset_widgets (priv->screen);
1636 case PROP_FONTCONFIG_TIMESTAMP:
1637 if (settings_update_fontconfig (settings))
1638 gtk_style_context_reset_widgets (priv->screen);
1640 case PROP_CURSOR_THEME_NAME:
1641 case PROP_CURSOR_THEME_SIZE:
1642 settings_update_cursor_theme (settings);
1648 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1649 const GValue *src_value,
1653 gboolean success = FALSE;
1655 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1660 gboolean free_gstring = TRUE;
1662 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1664 gstring = g_value_get_boxed (src_value);
1665 free_gstring = FALSE;
1667 else if (G_VALUE_HOLDS_LONG (src_value))
1669 gstring = g_string_new (NULL);
1670 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1672 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1674 gstring = g_string_new (NULL);
1675 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1677 else if (G_VALUE_HOLDS_STRING (src_value))
1679 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1681 gstring = g_string_new (NULL);
1682 g_string_append_c (gstring, '\"');
1683 g_string_append (gstring, tstr);
1684 g_string_append_c (gstring, '\"');
1689 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1690 gstring = NULL; /* silence compiler */
1693 success = (parser (pspec, gstring, dest_value) &&
1694 !g_param_value_validate (pspec, dest_value));
1697 g_string_free (gstring, TRUE);
1699 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1701 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1703 GString *gstring = g_value_get_boxed (src_value);
1705 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1706 success = !g_param_value_validate (pspec, dest_value);
1709 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1710 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1716 apply_queued_setting (GtkSettings *settings,
1718 GtkSettingsValuePrivate *qvalue)
1720 GtkSettingsPrivate *priv = settings->priv;
1721 GValue tmp_value = { 0, };
1722 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1724 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1725 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1728 if (pspec->param_id == PROP_COLOR_SCHEME)
1729 merge_color_scheme (settings, &tmp_value, qvalue->source);
1731 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1733 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1734 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1735 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1741 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1743 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1744 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1746 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1748 G_VALUE_TYPE_NAME (&tmp_value));
1751 g_value_unset (&tmp_value);
1755 settings_install_property_parser (GtkSettingsClass *class,
1757 GtkRcPropertyParser parser)
1759 GSList *node, *next;
1761 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1763 case G_TYPE_BOOLEAN:
1776 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1784 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1785 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1789 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1791 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1796 for (node = object_list; node; node = node->next)
1797 g_object_freeze_notify (node->data);
1799 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1800 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1802 for (node = object_list; node; node = node->next)
1804 GtkSettings *settings = node->data;
1805 GtkSettingsPrivate *priv = settings->priv;
1806 GtkSettingsValuePrivate *qvalue;
1808 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1809 priv->property_values[class_n_properties - 1].value.g_type = 0;
1810 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1811 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1812 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1813 g_object_notify (G_OBJECT (settings), pspec->name);
1815 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1817 apply_queued_setting (settings, pspec, qvalue);
1820 for (node = object_list; node; node = next)
1823 g_object_thaw_notify (node->data);
1826 return class_n_properties;
1830 _gtk_rc_property_parser_from_type (GType type)
1832 if (type == GDK_TYPE_COLOR)
1833 return gtk_rc_property_parse_color;
1834 else if (type == GTK_TYPE_REQUISITION)
1835 return gtk_rc_property_parse_requisition;
1836 else if (type == GTK_TYPE_BORDER)
1837 return gtk_rc_property_parse_border;
1838 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1839 return gtk_rc_property_parse_enum;
1840 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1841 return gtk_rc_property_parse_flags;
1847 gtk_settings_install_property (GParamSpec *pspec)
1849 static GtkSettingsClass *klass = NULL;
1851 GtkRcPropertyParser parser;
1853 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1856 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1858 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1860 settings_install_property_parser (klass, pspec, parser);
1864 * gtk_settings_install_property_parser:
1866 * @parser: (scope call):
1869 gtk_settings_install_property_parser (GParamSpec *pspec,
1870 GtkRcPropertyParser parser)
1872 static GtkSettingsClass *klass = NULL;
1874 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1875 g_return_if_fail (parser != NULL);
1878 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1880 settings_install_property_parser (klass, pspec, parser);
1884 free_value (gpointer data)
1886 GtkSettingsValuePrivate *qvalue = data;
1888 g_value_unset (&qvalue->public.value);
1889 g_free (qvalue->public.origin);
1890 g_slice_free (GtkSettingsValuePrivate, qvalue);
1894 gtk_settings_set_property_value_internal (GtkSettings *settings,
1895 const gchar *prop_name,
1896 const GtkSettingsValue *new_value,
1897 GtkSettingsSource source)
1899 GtkSettingsPrivate *priv = settings->priv;
1900 GtkSettingsValuePrivate *qvalue;
1905 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1906 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1907 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1908 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1910 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
1914 name = g_strdup (prop_name);
1915 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1916 name_quark = g_quark_from_string (name);
1919 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
1922 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1923 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
1927 g_free (qvalue->public.origin);
1928 g_value_unset (&qvalue->public.value);
1930 qvalue->public.origin = g_strdup (new_value->origin);
1931 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1932 g_value_copy (&new_value->value, &qvalue->public.value);
1933 qvalue->source = source;
1934 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1936 apply_queued_setting (settings, pspec, qvalue);
1940 gtk_settings_set_property_value (GtkSettings *settings,
1941 const gchar *prop_name,
1942 const GtkSettingsValue *new_value)
1944 g_return_if_fail (GTK_SETTINGS (settings));
1945 g_return_if_fail (prop_name != NULL);
1946 g_return_if_fail (new_value != NULL);
1948 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1949 GTK_SETTINGS_SOURCE_APPLICATION);
1953 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1954 const gchar *prop_name,
1955 const GtkSettingsValue *new_value)
1957 g_return_if_fail (GTK_SETTINGS (settings));
1958 g_return_if_fail (prop_name != NULL);
1959 g_return_if_fail (new_value != NULL);
1961 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1962 GTK_SETTINGS_SOURCE_THEME);
1966 gtk_settings_set_string_property (GtkSettings *settings,
1968 const gchar *v_string,
1969 const gchar *origin)
1971 GtkSettingsValue svalue = { NULL, { 0, }, };
1973 g_return_if_fail (GTK_SETTINGS (settings));
1974 g_return_if_fail (name != NULL);
1975 g_return_if_fail (v_string != NULL);
1977 svalue.origin = (gchar*) origin;
1978 g_value_init (&svalue.value, G_TYPE_STRING);
1979 g_value_set_static_string (&svalue.value, v_string);
1980 gtk_settings_set_property_value (settings, name, &svalue);
1981 g_value_unset (&svalue.value);
1985 gtk_settings_set_long_property (GtkSettings *settings,
1988 const gchar *origin)
1990 GtkSettingsValue svalue = { NULL, { 0, }, };
1992 g_return_if_fail (GTK_SETTINGS (settings));
1993 g_return_if_fail (name != NULL);
1995 svalue.origin = (gchar*) origin;
1996 g_value_init (&svalue.value, G_TYPE_LONG);
1997 g_value_set_long (&svalue.value, v_long);
1998 gtk_settings_set_property_value (settings, name, &svalue);
1999 g_value_unset (&svalue.value);
2003 gtk_settings_set_double_property (GtkSettings *settings,
2006 const gchar *origin)
2008 GtkSettingsValue svalue = { NULL, { 0, }, };
2010 g_return_if_fail (GTK_SETTINGS (settings));
2011 g_return_if_fail (name != NULL);
2013 svalue.origin = (gchar*) origin;
2014 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2015 g_value_set_double (&svalue.value, v_double);
2016 gtk_settings_set_property_value (settings, name, &svalue);
2017 g_value_unset (&svalue.value);
2021 * gtk_rc_property_parse_color:
2022 * @pspec: a #GParamSpec
2023 * @gstring: the #GString to be parsed
2024 * @property_value: a #GValue which must hold #GdkColor values.
2026 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2027 * or gtk_widget_class_install_style_property_parser() which parses a
2028 * color given either by its name or in the form
2029 * <literal>{ red, green, blue }</literal> where %red, %green and
2030 * %blue are integers between 0 and 65535 or floating-point numbers
2033 * Return value: %TRUE if @gstring could be parsed and @property_value
2034 * has been set to the resulting #GdkColor.
2037 gtk_rc_property_parse_color (const GParamSpec *pspec,
2038 const GString *gstring,
2039 GValue *property_value)
2041 GdkColor color = { 0, 0, 0, 0, };
2045 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2046 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2048 scanner = gtk_rc_scanner_new ();
2049 g_scanner_input_text (scanner, gstring->str, gstring->len);
2050 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2051 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2053 g_value_set_boxed (property_value, &color);
2058 g_scanner_destroy (scanner);
2064 * gtk_rc_property_parse_enum:
2065 * @pspec: a #GParamSpec
2066 * @gstring: the #GString to be parsed
2067 * @property_value: a #GValue which must hold enum values.
2069 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2070 * or gtk_widget_class_install_style_property_parser() which parses a single
2071 * enumeration value.
2073 * The enumeration value can be specified by its name, its nickname or
2074 * its numeric value. For consistency with flags parsing, the value
2075 * may be surrounded by parentheses.
2077 * Return value: %TRUE if @gstring could be parsed and @property_value
2078 * has been set to the resulting #GEnumValue.
2081 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2082 const GString *gstring,
2083 GValue *property_value)
2085 gboolean need_closing_brace = FALSE, success = FALSE;
2087 GEnumValue *enum_value = NULL;
2089 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2090 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2092 scanner = gtk_rc_scanner_new ();
2093 g_scanner_input_text (scanner, gstring->str, gstring->len);
2095 /* we just want to parse _one_ value, but for consistency with flags parsing
2096 * we support optional parenthesis
2098 g_scanner_get_next_token (scanner);
2099 if (scanner->token == '(')
2101 need_closing_brace = TRUE;
2102 g_scanner_get_next_token (scanner);
2104 if (scanner->token == G_TOKEN_IDENTIFIER)
2106 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2108 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2110 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2113 g_value_set_enum (property_value, enum_value->value);
2117 else if (scanner->token == G_TOKEN_INT)
2119 g_value_set_enum (property_value, scanner->value.v_int);
2122 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2124 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2127 g_scanner_destroy (scanner);
2133 parse_flags_value (GScanner *scanner,
2137 g_scanner_get_next_token (scanner);
2138 if (scanner->token == G_TOKEN_IDENTIFIER)
2140 GFlagsValue *flags_value;
2142 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2144 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2147 *number |= flags_value->value;
2148 return G_TOKEN_NONE;
2151 else if (scanner->token == G_TOKEN_INT)
2153 *number |= scanner->value.v_int;
2154 return G_TOKEN_NONE;
2156 return G_TOKEN_IDENTIFIER;
2160 * gtk_rc_property_parse_flags:
2161 * @pspec: a #GParamSpec
2162 * @gstring: the #GString to be parsed
2163 * @property_value: a #GValue which must hold flags values.
2165 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2166 * or gtk_widget_class_install_style_property_parser() which parses flags.
2168 * Flags can be specified by their name, their nickname or
2169 * numerically. Multiple flags can be specified in the form
2170 * <literal>"( flag1 | flag2 | ... )"</literal>.
2172 * Return value: %TRUE if @gstring could be parsed and @property_value
2173 * has been set to the resulting flags value.
2176 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2177 const GString *gstring,
2178 GValue *property_value)
2181 gboolean success = FALSE;
2184 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2185 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2187 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2188 scanner = gtk_rc_scanner_new ();
2189 g_scanner_input_text (scanner, gstring->str, gstring->len);
2191 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2192 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2193 scanner->next_token == G_TOKEN_INT)
2195 guint token, flags_value = 0;
2197 token = parse_flags_value (scanner, class, &flags_value);
2199 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2202 g_value_set_flags (property_value, flags_value);
2206 else if (g_scanner_get_next_token (scanner) == '(')
2208 guint token, flags_value = 0;
2210 /* parse first value */
2211 token = parse_flags_value (scanner, class, &flags_value);
2213 /* parse nth values, preceeded by '|' */
2214 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2215 token = parse_flags_value (scanner, class, &flags_value);
2217 /* done, last token must have closed expression */
2218 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2219 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2221 g_value_set_flags (property_value, flags_value);
2225 g_scanner_destroy (scanner);
2231 get_braced_int (GScanner *scanner,
2238 g_scanner_get_next_token (scanner);
2239 if (scanner->token != '{')
2243 g_scanner_get_next_token (scanner);
2244 if (scanner->token != G_TOKEN_INT)
2247 *value = scanner->value.v_int;
2251 g_scanner_get_next_token (scanner);
2252 if (scanner->token != '}')
2257 g_scanner_get_next_token (scanner);
2258 if (scanner->token != ',')
2266 * gtk_rc_property_parse_requisition:
2267 * @pspec: a #GParamSpec
2268 * @gstring: the #GString to be parsed
2269 * @property_value: a #GValue which must hold boxed values.
2271 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2272 * or gtk_widget_class_install_style_property_parser() which parses a
2273 * requisition in the form
2274 * <literal>"{ width, height }"</literal> for integers %width and %height.
2276 * Return value: %TRUE if @gstring could be parsed and @property_value
2277 * has been set to the resulting #GtkRequisition.
2280 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2281 const GString *gstring,
2282 GValue *property_value)
2284 GtkRequisition requisition;
2286 gboolean success = FALSE;
2288 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2289 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2291 scanner = gtk_rc_scanner_new ();
2292 g_scanner_input_text (scanner, gstring->str, gstring->len);
2294 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2295 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2297 g_value_set_boxed (property_value, &requisition);
2301 g_scanner_destroy (scanner);
2307 * gtk_rc_property_parse_border:
2308 * @pspec: a #GParamSpec
2309 * @gstring: the #GString to be parsed
2310 * @property_value: a #GValue which must hold boxed values.
2312 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2313 * or gtk_widget_class_install_style_property_parser() which parses
2314 * borders in the form
2315 * <literal>"{ left, right, top, bottom }"</literal> for integers
2316 * %left, %right, %top and %bottom.
2318 * Return value: %TRUE if @gstring could be parsed and @property_value
2319 * has been set to the resulting #GtkBorder.
2322 gtk_rc_property_parse_border (const GParamSpec *pspec,
2323 const GString *gstring,
2324 GValue *property_value)
2328 gboolean success = FALSE;
2329 int left, right, top, bottom;
2331 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2332 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2334 scanner = gtk_rc_scanner_new ();
2335 g_scanner_input_text (scanner, gstring->str, gstring->len);
2337 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2338 get_braced_int (scanner, FALSE, FALSE, &right) &&
2339 get_braced_int (scanner, FALSE, FALSE, &top) &&
2340 get_braced_int (scanner, FALSE, TRUE, &bottom))
2343 border.right = right;
2345 border.bottom = bottom;
2346 g_value_set_boxed (property_value, &border);
2350 g_scanner_destroy (scanner);
2356 _gtk_settings_handle_event (GdkEventSetting *event)
2359 GtkSettings *settings;
2363 screen = gdk_window_get_screen (event->window);
2364 settings = gtk_settings_get_for_screen (screen);
2365 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2369 property_id = pspec->param_id;
2371 if (property_id == PROP_COLOR_SCHEME)
2373 GValue value = { 0, };
2375 g_value_init (&value, G_TYPE_STRING);
2376 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2377 g_value_set_static_string (&value, "");
2378 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2379 g_value_unset (&value);
2381 g_object_notify (G_OBJECT (settings), pspec->name);
2386 reset_rc_values_foreach (GQuark key_id,
2390 GtkSettingsValuePrivate *qvalue = data;
2391 GSList **to_reset = user_data;
2393 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2394 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2398 _gtk_settings_reset_rc_values (GtkSettings *settings)
2400 GtkSettingsPrivate *priv = settings->priv;
2401 GSList *to_reset = NULL;
2403 GParamSpec **pspecs, **p;
2406 /* Remove any queued settings */
2407 g_datalist_foreach (&priv->queued_settings,
2408 reset_rc_values_foreach,
2411 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2413 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2414 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2417 g_slist_free (to_reset);
2419 /* Now reset the active settings
2421 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2424 g_object_freeze_notify (G_OBJECT (settings));
2425 for (p = pspecs; *p; p++)
2427 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2429 GParamSpec *pspec = *p;
2431 g_param_value_set_default (pspec, &priv->property_values[i].value);
2432 g_object_notify (G_OBJECT (settings), pspec->name);
2436 g_object_thaw_notify (G_OBJECT (settings));
2441 settings_update_double_click (GtkSettings *settings)
2443 GtkSettingsPrivate *priv = settings->priv;
2445 if (gdk_screen_get_number (priv->screen) == 0)
2447 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2448 gint double_click_time;
2449 gint double_click_distance;
2451 g_object_get (settings,
2452 "gtk-double-click-time", &double_click_time,
2453 "gtk-double-click-distance", &double_click_distance,
2456 gdk_display_set_double_click_time (display, double_click_time);
2457 gdk_display_set_double_click_distance (display, double_click_distance);
2462 settings_update_modules (GtkSettings *settings)
2466 g_object_get (settings,
2467 "gtk-modules", &modules,
2470 _gtk_modules_settings_changed (settings, modules);
2476 settings_update_cursor_theme (GtkSettings *settings)
2478 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2479 gchar *theme = NULL;
2482 #ifdef GDK_WINDOWING_X11
2483 if (GDK_IS_X11_DISPLAY (display))
2485 g_object_get (settings,
2486 "gtk-cursor-theme-name", &theme,
2487 "gtk-cursor-theme-size", &size,
2490 gdk_x11_display_set_cursor_theme (display, theme, size);
2498 settings_update_font_options (GtkSettings *settings)
2500 GtkSettingsPrivate *priv = settings->priv;
2502 gchar *hint_style_str;
2503 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2505 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2507 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2508 cairo_font_options_t *options;
2510 g_object_get (settings,
2511 "gtk-xft-antialias", &antialias,
2512 "gtk-xft-hinting", &hinting,
2513 "gtk-xft-hintstyle", &hint_style_str,
2514 "gtk-xft-rgba", &rgba_str,
2517 options = cairo_font_options_create ();
2519 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2521 if (hinting >= 0 && !hinting)
2523 hint_style = CAIRO_HINT_STYLE_NONE;
2525 else if (hint_style_str)
2527 if (strcmp (hint_style_str, "hintnone") == 0)
2528 hint_style = CAIRO_HINT_STYLE_NONE;
2529 else if (strcmp (hint_style_str, "hintslight") == 0)
2530 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2531 else if (strcmp (hint_style_str, "hintmedium") == 0)
2532 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2533 else if (strcmp (hint_style_str, "hintfull") == 0)
2534 hint_style = CAIRO_HINT_STYLE_FULL;
2537 g_free (hint_style_str);
2539 cairo_font_options_set_hint_style (options, hint_style);
2543 if (strcmp (rgba_str, "rgb") == 0)
2544 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2545 else if (strcmp (rgba_str, "bgr") == 0)
2546 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2547 else if (strcmp (rgba_str, "vrgb") == 0)
2548 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2549 else if (strcmp (rgba_str, "vbgr") == 0)
2550 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2555 cairo_font_options_set_subpixel_order (options, subpixel_order);
2557 if (antialias >= 0 && !antialias)
2558 antialias_mode = CAIRO_ANTIALIAS_NONE;
2559 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2560 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2561 else if (antialias >= 0)
2562 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2564 cairo_font_options_set_antialias (options, antialias_mode);
2566 gdk_screen_set_font_options (priv->screen, options);
2568 cairo_font_options_destroy (options);
2572 settings_update_fontconfig (GtkSettings *settings)
2574 #ifdef GDK_WINDOWING_X11
2575 static guint last_update_timestamp;
2576 static gboolean last_update_needed;
2580 g_object_get (settings,
2581 "gtk-fontconfig-timestamp", ×tamp,
2584 /* if timestamp is the same as last_update_timestamp, we already have
2585 * updated fontconig on this timestamp (another screen requested it perhaps?),
2586 * just return the cached result.*/
2588 if (timestamp != last_update_timestamp)
2590 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2591 gboolean update_needed = FALSE;
2594 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2596 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2597 if (FcInitReinitialize ())
2598 update_needed = TRUE;
2601 last_update_timestamp = timestamp;
2602 last_update_needed = update_needed;
2605 return last_update_needed;
2606 #endif /* GDK_WINDOWING_X11 */
2610 settings_update_resolution (GtkSettings *settings)
2612 GtkSettingsPrivate *priv = settings->priv;
2616 g_object_get (settings,
2617 "gtk-xft-dpi", &dpi_int,
2621 dpi = dpi_int / 1024.;
2625 gdk_screen_set_resolution (priv->screen, dpi);
2630 GHashTable *color_hash;
2631 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2632 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2636 color_scheme_data_free (ColorSchemeData *data)
2640 g_hash_table_unref (data->color_hash);
2642 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2644 if (data->tables[i])
2645 g_hash_table_unref (data->tables[i]);
2646 g_free (data->lastentry[i]);
2649 g_slice_free (ColorSchemeData, data);
2653 settings_update_color_scheme (GtkSettings *settings)
2655 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2657 GtkSettingsPrivate *priv = settings->priv;
2658 ColorSchemeData *data;
2659 GValue value = { 0, };
2661 data = g_slice_new0 (ColorSchemeData);
2662 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2663 (GDestroyNotify) gdk_color_free);
2664 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2665 data, (GDestroyNotify) color_scheme_data_free);
2667 g_value_init (&value, G_TYPE_STRING);
2668 if (priv->screen && gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2670 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2671 g_value_unset (&value);
2677 settings_update_provider (GdkScreen *screen,
2678 GtkCssProvider **old,
2679 GtkCssProvider *new)
2685 gtk_style_context_remove_provider_for_screen (screen,
2686 GTK_STYLE_PROVIDER (*old));
2687 g_object_unref (*old);
2693 gtk_style_context_add_provider_for_screen (screen,
2694 GTK_STYLE_PROVIDER (new),
2695 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2696 *old = g_object_ref (new);
2702 settings_update_theme (GtkSettings *settings)
2704 GtkSettingsPrivate *priv = settings->priv;
2705 GtkCssProvider *provider = NULL;
2706 gboolean prefer_dark_theme;
2709 g_object_get (settings,
2710 "gtk-theme-name", &theme_name,
2711 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2714 if (theme_name && *theme_name)
2716 if (prefer_dark_theme)
2717 provider = gtk_css_provider_get_named (theme_name, "dark");
2720 provider = gtk_css_provider_get_named (theme_name, NULL);
2723 settings_update_provider (priv->screen, &priv->theme_provider, provider);
2725 if (theme_name && *theme_name)
2730 /* reload per-theme settings */
2731 theme_dir = _gtk_css_provider_get_theme_dir ();
2732 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2734 if (g_file_test (path, G_FILE_TEST_EXISTS))
2735 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2741 g_free (theme_name);
2745 settings_update_key_theme (GtkSettings *settings)
2747 GtkSettingsPrivate *priv = settings->priv;
2748 GtkCssProvider *provider = NULL;
2749 gchar *key_theme_name;
2751 g_object_get (settings,
2752 "gtk-key-theme-name", &key_theme_name,
2755 if (key_theme_name && *key_theme_name)
2756 provider = gtk_css_provider_get_named (key_theme_name, "keys");
2758 settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2759 g_free (key_theme_name);
2763 add_color_to_hash (gchar *name,
2769 old = g_hash_table_lookup (target, name);
2770 if (!old || !gdk_color_equal (old, color))
2772 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2781 add_colors_to_hash_from_string (GHashTable *hash,
2782 const gchar *colors)
2784 gchar *s, *p, *name;
2786 gboolean changed = FALSE;
2789 copy = g_strdup (colors);
2794 p = strchr (s, ':');
2809 if (*s == '\n' || *s == ';')
2818 if (gdk_color_parse (p, &color))
2819 changed |= add_color_to_hash (name, &color, hash);
2828 update_color_hash (ColorSchemeData *data,
2830 GtkSettingsSource source)
2832 gboolean changed = FALSE;
2834 GHashTable *old_hash;
2835 GHashTableIter iter;
2839 if ((str == NULL || *str == '\0') &&
2840 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2843 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2846 /* For the THEME source we merge the values rather than over-writing
2847 * them, since multiple rc files might define independent sets of colors
2849 if ((source != GTK_SETTINGS_SOURCE_THEME) &&
2850 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2852 g_hash_table_unref (data->tables[source]);
2853 data->tables[source] = NULL;
2854 changed = TRUE; /* We can't rely on the code below since str might be "" */
2857 if (data->tables[source] == NULL)
2858 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2860 (GDestroyNotify) gdk_color_free);
2862 g_free (data->lastentry[source]);
2863 data->lastentry[source] = g_strdup (str);
2865 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2870 /* Rebuild the merged hash table. */
2871 if (data->color_hash)
2873 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2874 (GDestroyNotify) gdk_color_free);
2876 g_hash_table_iter_init (&iter, data->color_hash);
2877 while (g_hash_table_iter_next (&iter, &name, &color))
2879 g_hash_table_insert (old_hash, name, color);
2880 g_hash_table_iter_steal (&iter);
2888 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2890 if (data->tables[i])
2891 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2897 /* now check if the merged hash has changed */
2899 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2903 GHashTableIter iter;
2904 gpointer key, value, new_value;
2906 g_hash_table_iter_init (&iter, old_hash);
2907 while (g_hash_table_iter_next (&iter, &key, &value))
2909 new_value = g_hash_table_lookup (data->color_hash, key);
2910 if (!new_value || !gdk_color_equal (value, new_value))
2918 g_hash_table_unref (old_hash);
2927 merge_color_scheme (GtkSettings *settings,
2928 const GValue *value,
2929 GtkSettingsSource source)
2931 ColorSchemeData *data;
2932 const gchar *colors;
2934 g_object_freeze_notify (G_OBJECT (settings));
2936 colors = g_value_get_string (value);
2938 settings_update_color_scheme (settings);
2940 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2941 "gtk-color-scheme");
2943 if (update_color_hash (data, colors, source))
2944 g_object_notify (G_OBJECT (settings), "color-hash");
2946 g_object_thaw_notify (G_OBJECT (settings));
2950 get_color_hash (GtkSettings *settings)
2952 ColorSchemeData *data;
2954 settings_update_color_scheme (settings);
2956 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2957 "gtk-color-scheme");
2959 return data->color_hash;
2963 append_color_scheme (gpointer key,
2967 gchar *name = (gchar *)key;
2968 GdkColor *color = (GdkColor *)value;
2969 GString *string = (GString *)data;
2971 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2972 name, color->red, color->green, color->blue);
2976 get_color_scheme (GtkSettings *settings)
2978 ColorSchemeData *data;
2981 settings_update_color_scheme (settings);
2983 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2984 "gtk-color-scheme");
2986 string = g_string_new ("");
2988 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2990 return g_string_free (string, FALSE);
2994 _gtk_settings_get_screen (GtkSettings *settings)
2996 return settings->priv->screen;
3001 gtk_settings_load_from_key_file (GtkSettings *settings,
3003 GtkSettingsSource source)
3014 keyfile = g_key_file_new ();
3016 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
3018 g_warning ("Failed to parse %s: %s", path, error->message);
3020 g_error_free (error);
3025 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3028 g_warning ("Failed to parse %s: %s", path, error->message);
3029 g_error_free (error);
3033 for (i = 0; i < n_keys; i++)
3038 GtkSettingsValue svalue = { NULL, { 0, }, };
3041 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3044 g_warning ("Unknown key %s in %s", key, path);
3048 if (pspec->owner_type != G_OBJECT_TYPE (settings))
3051 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3054 case G_TYPE_BOOLEAN:
3058 g_value_init (&svalue.value, G_TYPE_LONG);
3059 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3061 g_value_set_long (&svalue.value, b_val);
3069 g_value_init (&svalue.value, G_TYPE_LONG);
3070 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3072 g_value_set_long (&svalue.value, i_val);
3080 g_value_init (&svalue.value, G_TYPE_DOUBLE);
3081 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3083 g_value_set_double (&svalue.value, d_val);
3091 g_value_init (&svalue.value, G_TYPE_GSTRING);
3092 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3094 g_value_set_boxed (&svalue.value, g_string_new (s_val));
3101 g_warning ("Error setting %s in %s: %s", key, path, error->message);
3102 g_error_free (error);
3107 if (g_getenv ("GTK_DEBUG"))
3108 svalue.origin = (gchar *)path;
3109 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3110 g_value_unset (&svalue.value);
3116 g_key_file_free (keyfile);