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 #ifdef GDK_WINDOWING_QUARTZ
86 #define DEFAULT_KEY_THEME "Mac"
88 #define DEFAULT_KEY_THEME NULL
91 #define DEFAULT_TIMEOUT_INITIAL 200
92 #define DEFAULT_TIMEOUT_REPEAT 20
93 #define DEFAULT_TIMEOUT_EXPAND 500
95 typedef struct _GtkSettingsPropertyValue GtkSettingsPropertyValue;
96 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
98 struct _GtkSettingsPrivate
100 GData *queued_settings; /* of type GtkSettingsValue* */
101 GtkSettingsPropertyValue *property_values;
103 GtkCssProvider *theme_provider;
104 GtkCssProvider *key_theme_provider;
109 GTK_SETTINGS_SOURCE_DEFAULT,
110 GTK_SETTINGS_SOURCE_THEME,
111 GTK_SETTINGS_SOURCE_XSETTING,
112 GTK_SETTINGS_SOURCE_APPLICATION
115 struct _GtkSettingsValuePrivate
117 GtkSettingsValue public;
118 GtkSettingsSource source;
121 struct _GtkSettingsPropertyValue
124 GtkSettingsSource source;
129 PROP_DOUBLE_CLICK_TIME,
130 PROP_DOUBLE_CLICK_DISTANCE,
132 PROP_CURSOR_BLINK_TIME,
133 PROP_CURSOR_BLINK_TIMEOUT,
136 PROP_ICON_THEME_NAME,
137 PROP_FALLBACK_ICON_THEME,
140 PROP_DND_DRAG_THRESHOLD,
144 #ifdef GDK_WINDOWING_X11
150 PROP_CURSOR_THEME_NAME,
151 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,
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,
170 PROP_FILE_CHOOSER_BACKEND,
172 PROP_PRINT_PREVIEW_COMMAND,
173 PROP_ENABLE_MNEMONICS,
175 PROP_RECENT_FILES_LIMIT,
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,
184 PROP_TOOLBAR_ICON_SIZE,
186 PROP_APPLICATION_PREFER_DARK_THEME,
188 PROP_ENTRY_SELECT_ON_FOCUS,
189 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
191 PROP_MENU_BAR_POPUP_DELAY,
192 PROP_SCROLLED_WINDOW_PLACEMENT,
193 PROP_CAN_CHANGE_ACCELS,
194 PROP_MENU_POPUP_DELAY,
195 PROP_MENU_POPDOWN_DELAY,
196 PROP_LABEL_SELECT_ON_FOCUS,
198 PROP_IM_PREEDIT_STYLE,
202 /* --- prototypes --- */
203 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
205 static void gtk_settings_finalize (GObject *object);
206 static void gtk_settings_get_property (GObject *object,
210 static void gtk_settings_set_property (GObject *object,
214 static void gtk_settings_notify (GObject *object,
216 static guint settings_install_property_parser (GtkSettingsClass *class,
218 GtkRcPropertyParser parser);
219 static void settings_update_double_click (GtkSettings *settings);
220 static void settings_update_modules (GtkSettings *settings);
222 #ifdef GDK_WINDOWING_X11
223 static void settings_update_cursor_theme (GtkSettings *settings);
224 static void settings_update_resolution (GtkSettings *settings);
225 static void settings_update_font_options (GtkSettings *settings);
226 static gboolean settings_update_fontconfig (GtkSettings *settings);
228 static void settings_update_color_scheme (GtkSettings *settings);
229 static void settings_update_theme (GtkSettings *settings);
230 static void settings_update_key_theme (GtkSettings *settings);
232 static void merge_color_scheme (GtkSettings *settings,
234 GtkSettingsSource source);
235 static gchar *get_color_scheme (GtkSettings *settings);
236 static GHashTable *get_color_hash (GtkSettings *settings);
237 static void gtk_settings_load_from_key_file (GtkSettings *settings,
239 GtkSettingsSource source);
241 /* the default palette for GtkColorSelelection */
242 static const gchar default_color_palette[] =
243 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
244 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
246 /* --- variables --- */
247 static GQuark quark_property_parser = 0;
248 static GSList *object_list = NULL;
249 static guint class_n_properties = 0;
252 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
253 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
254 gtk_settings_provider_iface_init));
256 /* --- functions --- */
258 gtk_settings_init (GtkSettings *settings)
260 GtkSettingsPrivate *priv;
261 GParamSpec **pspecs, **p;
265 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
269 settings->priv = priv;
270 g_datalist_init (&priv->queued_settings);
271 object_list = g_slist_prepend (object_list, settings);
273 /* build up property array for all yet existing properties and queue
274 * notification for them (at least notification for internal properties
275 * will instantly be caught)
277 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
278 for (p = pspecs; *p; p++)
279 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
281 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
283 g_object_freeze_notify (G_OBJECT (settings));
285 for (p = pspecs; *p; p++)
287 GParamSpec *pspec = *p;
288 GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
290 if (pspec->owner_type != G_OBJECT_TYPE (settings))
292 g_value_init (&priv->property_values[i].value, value_type);
293 g_param_value_set_default (pspec, &priv->property_values[i].value);
295 g_object_notify (G_OBJECT (settings), pspec->name);
296 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
301 path = g_build_filename (GTK_SYSCONFDIR, "gtk-3.0", "settings.ini", NULL);
302 if (g_file_test (path, G_FILE_TEST_EXISTS))
303 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
306 path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "settings.ini", NULL);
307 if (g_file_test (path, G_FILE_TEST_EXISTS))
308 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
311 g_object_thaw_notify (G_OBJECT (settings));
315 gtk_settings_class_init (GtkSettingsClass *class)
317 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
320 gobject_class->finalize = gtk_settings_finalize;
321 gobject_class->get_property = gtk_settings_get_property;
322 gobject_class->set_property = gtk_settings_set_property;
323 gobject_class->notify = gtk_settings_notify;
325 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
326 result = settings_install_property_parser (class,
327 g_param_spec_int ("gtk-double-click-time",
328 P_("Double Click Time"),
329 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
331 GTK_PARAM_READWRITE),
333 g_assert (result == PROP_DOUBLE_CLICK_TIME);
334 result = settings_install_property_parser (class,
335 g_param_spec_int ("gtk-double-click-distance",
336 P_("Double Click Distance"),
337 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
339 GTK_PARAM_READWRITE),
341 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
344 * GtkSettings:gtk-cursor-blink:
346 * Whether the cursor should blink.
348 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
349 * which allows more flexible control over cursor blinking.
351 result = settings_install_property_parser (class,
352 g_param_spec_boolean ("gtk-cursor-blink",
354 P_("Whether the cursor should blink"),
356 GTK_PARAM_READWRITE),
358 g_assert (result == PROP_CURSOR_BLINK);
359 result = settings_install_property_parser (class,
360 g_param_spec_int ("gtk-cursor-blink-time",
361 P_("Cursor Blink Time"),
362 P_("Length of the cursor blink cycle, in milliseconds"),
364 GTK_PARAM_READWRITE),
366 g_assert (result == PROP_CURSOR_BLINK_TIME);
369 * GtkSettings:gtk-cursor-blink-timeout:
371 * Time after which the cursor stops blinking, in seconds.
372 * The timer is reset after each user interaction.
374 * Setting this to zero has the same effect as setting
375 * #GtkSettings:gtk-cursor-blink to %FALSE.
379 result = settings_install_property_parser (class,
380 g_param_spec_int ("gtk-cursor-blink-timeout",
381 P_("Cursor Blink Timeout"),
382 P_("Time after which the cursor stops blinking, in seconds"),
383 1, G_MAXINT, G_MAXINT,
384 GTK_PARAM_READWRITE),
386 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
387 result = settings_install_property_parser (class,
388 g_param_spec_boolean ("gtk-split-cursor",
390 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
392 GTK_PARAM_READWRITE),
394 g_assert (result == PROP_SPLIT_CURSOR);
395 result = settings_install_property_parser (class,
396 g_param_spec_string ("gtk-theme-name",
398 P_("Name of theme to load"),
400 GTK_PARAM_READWRITE),
402 g_assert (result == PROP_THEME_NAME);
404 result = settings_install_property_parser (class,
405 g_param_spec_string ("gtk-icon-theme-name",
406 P_("Icon Theme Name"),
407 P_("Name of icon theme to use"),
409 GTK_PARAM_READWRITE),
411 g_assert (result == PROP_ICON_THEME_NAME);
413 result = settings_install_property_parser (class,
414 g_param_spec_string ("gtk-fallback-icon-theme",
415 P_("Fallback Icon Theme Name"),
416 P_("Name of a icon theme to fall back to"),
418 GTK_PARAM_READWRITE),
420 g_assert (result == PROP_FALLBACK_ICON_THEME);
422 result = settings_install_property_parser (class,
423 g_param_spec_string ("gtk-key-theme-name",
424 P_("Key Theme Name"),
425 P_("Name of key theme to load"),
427 GTK_PARAM_READWRITE),
429 g_assert (result == PROP_KEY_THEME_NAME);
431 result = settings_install_property_parser (class,
432 g_param_spec_string ("gtk-menu-bar-accel",
433 P_("Menu bar accelerator"),
434 P_("Keybinding to activate the menu bar"),
436 GTK_PARAM_READWRITE),
438 g_assert (result == PROP_MENU_BAR_ACCEL);
440 result = settings_install_property_parser (class,
441 g_param_spec_int ("gtk-dnd-drag-threshold",
442 P_("Drag threshold"),
443 P_("Number of pixels the cursor can move before dragging"),
445 GTK_PARAM_READWRITE),
447 g_assert (result == PROP_DND_DRAG_THRESHOLD);
449 result = settings_install_property_parser (class,
450 g_param_spec_string ("gtk-font-name",
452 P_("Name of default font to use"),
454 GTK_PARAM_READWRITE),
456 g_assert (result == PROP_FONT_NAME);
459 * GtkSettings:gtk-icon-sizes:
461 * A list of icon sizes. The list is separated by colons, and
464 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
466 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
467 * GTK+ itself use the following named icon sizes: gtk-menu,
468 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
469 * gtk-dialog. Applications can register their own named icon
470 * sizes with gtk_icon_size_register().
472 result = settings_install_property_parser (class,
473 g_param_spec_string ("gtk-icon-sizes",
475 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
477 GTK_PARAM_READWRITE),
479 g_assert (result == PROP_ICON_SIZES);
481 result = settings_install_property_parser (class,
482 g_param_spec_string ("gtk-modules",
484 P_("List of currently active GTK modules"),
486 GTK_PARAM_READWRITE),
488 g_assert (result == PROP_MODULES);
490 #ifdef GDK_WINDOWING_X11
491 result = settings_install_property_parser (class,
492 g_param_spec_int ("gtk-xft-antialias",
494 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
496 GTK_PARAM_READWRITE),
499 g_assert (result == PROP_XFT_ANTIALIAS);
501 result = settings_install_property_parser (class,
502 g_param_spec_int ("gtk-xft-hinting",
504 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
506 GTK_PARAM_READWRITE),
509 g_assert (result == PROP_XFT_HINTING);
511 result = settings_install_property_parser (class,
512 g_param_spec_string ("gtk-xft-hintstyle",
513 P_("Xft Hint Style"),
514 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
516 GTK_PARAM_READWRITE),
519 g_assert (result == PROP_XFT_HINTSTYLE);
521 result = settings_install_property_parser (class,
522 g_param_spec_string ("gtk-xft-rgba",
524 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
526 GTK_PARAM_READWRITE),
529 g_assert (result == PROP_XFT_RGBA);
531 result = settings_install_property_parser (class,
532 g_param_spec_int ("gtk-xft-dpi",
534 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
536 GTK_PARAM_READWRITE),
539 g_assert (result == PROP_XFT_DPI);
541 result = settings_install_property_parser (class,
542 g_param_spec_string ("gtk-cursor-theme-name",
543 P_("Cursor theme name"),
544 P_("Name of the cursor theme to use, or NULL to use the default theme"),
546 GTK_PARAM_READWRITE),
548 g_assert (result == PROP_CURSOR_THEME_NAME);
550 result = settings_install_property_parser (class,
551 g_param_spec_int ("gtk-cursor-theme-size",
552 P_("Cursor theme size"),
553 P_("Size to use for cursors, or 0 to use the default size"),
555 GTK_PARAM_READWRITE),
558 g_assert (result == PROP_CURSOR_THEME_SIZE);
560 #endif /* GDK_WINDOWING_X11 */
561 result = settings_install_property_parser (class,
562 g_param_spec_boolean ("gtk-alternative-button-order",
563 P_("Alternative button order"),
564 P_("Whether buttons in dialogs should use the alternative button order"),
566 GTK_PARAM_READWRITE),
568 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
571 * GtkSettings:gtk-alternative-sort-arrows:
573 * Controls the direction of the sort indicators in sorted list and tree
574 * views. By default an arrow pointing down means the column is sorted
575 * in ascending order. When set to %TRUE, this order will be inverted.
579 result = settings_install_property_parser (class,
580 g_param_spec_boolean ("gtk-alternative-sort-arrows",
581 P_("Alternative sort indicator direction"),
582 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
584 GTK_PARAM_READWRITE),
586 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
588 result = settings_install_property_parser (class,
589 g_param_spec_boolean ("gtk-show-input-method-menu",
590 P_("Show the 'Input Methods' menu"),
591 P_("Whether the context menus of entries and text views should offer to change the input method"),
593 GTK_PARAM_READWRITE),
595 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
597 result = settings_install_property_parser (class,
598 g_param_spec_boolean ("gtk-show-unicode-menu",
599 P_("Show the 'Insert Unicode Control Character' menu"),
600 P_("Whether the context menus of entries and text views should offer to insert control characters"),
602 GTK_PARAM_READWRITE),
604 g_assert (result == PROP_SHOW_UNICODE_MENU);
606 result = settings_install_property_parser (class,
607 g_param_spec_int ("gtk-timeout-initial",
609 P_("Starting value for timeouts, when button is pressed"),
610 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
611 GTK_PARAM_READWRITE),
614 g_assert (result == PROP_TIMEOUT_INITIAL);
616 result = settings_install_property_parser (class,
617 g_param_spec_int ("gtk-timeout-repeat",
618 P_("Repeat timeout"),
619 P_("Repeat value for timeouts, when button is pressed"),
620 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
621 GTK_PARAM_READWRITE),
624 g_assert (result == PROP_TIMEOUT_REPEAT);
626 result = settings_install_property_parser (class,
627 g_param_spec_int ("gtk-timeout-expand",
628 P_("Expand timeout"),
629 P_("Expand value for timeouts, when a widget is expanding a new region"),
630 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
631 GTK_PARAM_READWRITE),
634 g_assert (result == PROP_TIMEOUT_EXPAND);
637 * GtkSettings:gtk-color-scheme:
639 * A palette of named colors for use in themes. The format of the string is
645 * Color names must be acceptable as identifiers in the
646 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
647 * color specifications must be in the format accepted by
650 * Note that due to the way the color tables from different sources are
651 * merged, color specifications will be converted to hexadecimal form
652 * when getting this property.
654 * Starting with GTK+ 2.12, the entries can alternatively be separated
655 * by ';' instead of newlines:
657 * name1: color1; name2: color2; ...
662 result = settings_install_property_parser (class,
663 g_param_spec_string ("gtk-color-scheme",
665 P_("A palette of named colors for use in themes"),
667 GTK_PARAM_READWRITE),
670 g_assert (result == PROP_COLOR_SCHEME);
672 result = settings_install_property_parser (class,
673 g_param_spec_boolean ("gtk-enable-animations",
674 P_("Enable Animations"),
675 P_("Whether to enable toolkit-wide animations."),
677 GTK_PARAM_READWRITE),
680 g_assert (result == PROP_ENABLE_ANIMATIONS);
683 * GtkSettings:gtk-touchscreen-mode:
685 * When %TRUE, there are no motion notify events delivered on this screen,
686 * and widgets can't use the pointer hovering them for any essential
691 result = settings_install_property_parser (class,
692 g_param_spec_boolean ("gtk-touchscreen-mode",
693 P_("Enable Touchscreen Mode"),
694 P_("When TRUE, there are no motion notify events delivered on this screen"),
696 GTK_PARAM_READWRITE),
699 g_assert (result == PROP_TOUCHSCREEN_MODE);
702 * GtkSettings:gtk-tooltip-timeout:
704 * Time, in milliseconds, after which a tooltip could appear if the
705 * cursor is hovering on top of a widget.
709 result = settings_install_property_parser (class,
710 g_param_spec_int ("gtk-tooltip-timeout",
711 P_("Tooltip timeout"),
712 P_("Timeout before tooltip is shown"),
715 GTK_PARAM_READWRITE),
718 g_assert (result == PROP_TOOLTIP_TIMEOUT);
721 * GtkSettings:gtk-tooltip-browse-timeout:
723 * Controls the time after which tooltips will appear when
724 * browse mode is enabled, in milliseconds.
726 * Browse mode is enabled when the mouse pointer moves off an object
727 * where a tooltip was currently being displayed. If the mouse pointer
728 * hits another object before the browse mode timeout expires (see
729 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
730 * amount of milliseconds specified by this setting to popup the tooltip
731 * for the new object.
735 result = settings_install_property_parser (class,
736 g_param_spec_int ("gtk-tooltip-browse-timeout",
737 P_("Tooltip browse timeout"),
738 P_("Timeout before tooltip is shown when browse mode is enabled"),
741 GTK_PARAM_READWRITE),
744 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
747 * GtkSettings:gtk-tooltip-browse-mode-timeout:
749 * Amount of time, in milliseconds, after which the browse mode
752 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
757 result = settings_install_property_parser (class,
758 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
759 P_("Tooltip browse mode timeout"),
760 P_("Timeout after which browse mode is disabled"),
763 GTK_PARAM_READWRITE),
766 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
769 * GtkSettings:gtk-keynav-cursor-only:
771 * When %TRUE, keyboard navigation should be able to reach all widgets
772 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
773 * to be present on the used input device.
777 result = settings_install_property_parser (class,
778 g_param_spec_boolean ("gtk-keynav-cursor-only",
779 P_("Keynav Cursor Only"),
780 P_("When TRUE, there are only cursor keys available to navigate widgets"),
782 GTK_PARAM_READWRITE),
785 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
788 * GtkSettings:gtk-keynav-wrap-around:
790 * When %TRUE, some widgets will wrap around when doing keyboard
791 * navigation, such as menus, menubars and notebooks.
795 result = settings_install_property_parser (class,
796 g_param_spec_boolean ("gtk-keynav-wrap-around",
797 P_("Keynav Wrap Around"),
798 P_("Whether to wrap around when keyboard-navigating widgets"),
800 GTK_PARAM_READWRITE),
803 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
806 * GtkSettings:gtk-error-bell:
808 * When %TRUE, keyboard navigation and other input-related errors
809 * will cause a beep. Since the error bell is implemented using
810 * gdk_window_beep(), the windowing system may offer ways to
811 * configure the error bell in many ways, such as flashing the
812 * window or similar visual effects.
816 result = settings_install_property_parser (class,
817 g_param_spec_boolean ("gtk-error-bell",
819 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
821 GTK_PARAM_READWRITE),
824 g_assert (result == PROP_ERROR_BELL);
827 * GtkSettings:color-hash:
829 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
830 * setting, mapping color names to #GdkColor<!-- -->s.
834 result = settings_install_property_parser (class,
835 g_param_spec_boxed ("color-hash",
837 P_("A hash table representation of the color scheme."),
841 g_assert (result == PROP_COLOR_HASH);
843 result = settings_install_property_parser (class,
844 g_param_spec_string ("gtk-file-chooser-backend",
845 P_("Default file chooser backend"),
846 P_("Name of the GtkFileChooser backend to use by default"),
848 GTK_PARAM_READWRITE),
850 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
853 * GtkSettings:gtk-print-backends:
855 * A comma-separated list of print backends to use in the print
856 * dialog. Available print backends depend on the GTK+ installation,
857 * and may include "file", "cups", "lpr" or "papi".
861 result = settings_install_property_parser (class,
862 g_param_spec_string ("gtk-print-backends",
863 P_("Default print backend"),
864 P_("List of the GtkPrintBackend backends to use by default"),
866 GTK_PARAM_READWRITE),
868 g_assert (result == PROP_PRINT_BACKENDS);
871 * GtkSettings:gtk-print-preview-command:
873 * A command to run for displaying the print preview. The command
874 * should contain a %f placeholder, which will get replaced by
875 * the path to the pdf file. The command may also contain a %s
876 * placeholder, which will get replaced by the path to a file
877 * containing the print settings in the format produced by
878 * gtk_print_settings_to_file().
880 * The preview application is responsible for removing the pdf file
881 * and the print settings file when it is done.
885 result = settings_install_property_parser (class,
886 g_param_spec_string ("gtk-print-preview-command",
887 P_("Default command to run when displaying a print preview"),
888 P_("Command to run when displaying a print preview"),
889 GTK_PRINT_PREVIEW_COMMAND,
890 GTK_PARAM_READWRITE),
892 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
895 * GtkSettings:gtk-enable-mnemonics:
897 * Whether labels and menu items should have visible mnemonics which
902 result = settings_install_property_parser (class,
903 g_param_spec_boolean ("gtk-enable-mnemonics",
904 P_("Enable Mnemonics"),
905 P_("Whether labels should have mnemonics"),
907 GTK_PARAM_READWRITE),
909 g_assert (result == PROP_ENABLE_MNEMONICS);
912 * GtkSettings:gtk-enable-accels:
914 * Whether menu items should have visible accelerators which can be
919 result = settings_install_property_parser (class,
920 g_param_spec_boolean ("gtk-enable-accels",
921 P_("Enable Accelerators"),
922 P_("Whether menu items should have accelerators"),
924 GTK_PARAM_READWRITE),
926 g_assert (result == PROP_ENABLE_ACCELS);
929 * GtkSettings:gtk-recent-files-limit:
931 * The number of recently used files that should be displayed by default by
932 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
933 * -1 means every recently used file stored.
937 result = settings_install_property_parser (class,
938 g_param_spec_int ("gtk-recent-files-limit",
939 P_("Recent Files Limit"),
940 P_("Number of recently used files"),
943 GTK_PARAM_READWRITE),
945 g_assert (result == PROP_RECENT_FILES_LIMIT);
948 * GtkSettings:gtk-im-module:
950 * Which IM (input method) module should be used by default. This is the
951 * input method that will be used if the user has not explicitly chosen
952 * another input method from the IM context menu.
954 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
956 result = settings_install_property_parser (class,
957 g_param_spec_string ("gtk-im-module",
958 P_("Default IM module"),
959 P_("Which IM module should be used by default"),
961 GTK_PARAM_READWRITE),
963 g_assert (result == PROP_IM_MODULE);
966 * GtkSettings:gtk-recent-files-max-age:
968 * The maximum age, in days, of the items inside the recently used
969 * resources list. Items older than this setting will be excised
970 * from the list. If set to 0, the list will always be empty; if
971 * set to -1, no item will be removed.
975 result = settings_install_property_parser (class,
976 g_param_spec_int ("gtk-recent-files-max-age",
977 P_("Recent Files Max Age"),
978 P_("Maximum age of recently used files, in days"),
981 GTK_PARAM_READWRITE),
983 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
985 result = settings_install_property_parser (class,
986 g_param_spec_uint ("gtk-fontconfig-timestamp",
987 P_("Fontconfig configuration timestamp"),
988 P_("Timestamp of current fontconfig configuration"),
990 GTK_PARAM_READWRITE),
993 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
996 * GtkSettings:gtk-sound-theme-name:
998 * The XDG sound theme to use for event sounds.
1000 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1001 * for more information on event sounds and sound themes.
1003 * GTK+ itself does not support event sounds, you have to use a loadable
1004 * module like the one that comes with libcanberra.
1008 result = settings_install_property_parser (class,
1009 g_param_spec_string ("gtk-sound-theme-name",
1010 P_("Sound Theme Name"),
1011 P_("XDG sound theme name"),
1013 GTK_PARAM_READWRITE),
1015 g_assert (result == PROP_SOUND_THEME_NAME);
1018 * GtkSettings:gtk-enable-input-feedback-sounds:
1020 * Whether to play event sounds as feedback to user input.
1022 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1023 * for more information on event sounds and sound themes.
1025 * GTK+ itself does not support event sounds, you have to use a loadable
1026 * module like the one that comes with libcanberra.
1030 result = settings_install_property_parser (class,
1031 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1032 /* Translators: this means sounds that are played as feedback to user input */
1033 P_("Audible Input Feedback"),
1034 P_("Whether to play event sounds as feedback to user input"),
1036 GTK_PARAM_READWRITE),
1038 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1041 * GtkSettings:gtk-enable-event-sounds:
1043 * Whether to play any event sounds at all.
1045 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1046 * for more information on event sounds and sound themes.
1048 * GTK+ itself does not support event sounds, you have to use a loadable
1049 * module like the one that comes with libcanberra.
1053 result = settings_install_property_parser (class,
1054 g_param_spec_boolean ("gtk-enable-event-sounds",
1055 P_("Enable Event Sounds"),
1056 P_("Whether to play any event sounds at all"),
1058 GTK_PARAM_READWRITE),
1060 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1063 * GtkSettings:gtk-enable-tooltips:
1065 * Whether tooltips should be shown on widgets.
1069 result = settings_install_property_parser (class,
1070 g_param_spec_boolean ("gtk-enable-tooltips",
1071 P_("Enable Tooltips"),
1072 P_("Whether tooltips should be shown on widgets"),
1074 GTK_PARAM_READWRITE),
1076 g_assert (result == PROP_ENABLE_TOOLTIPS);
1079 * GtkSettings:gtk-toolbar-style:
1081 * The size of icons in default toolbars.
1083 result = settings_install_property_parser (class,
1084 g_param_spec_enum ("gtk-toolbar-style",
1085 P_("Toolbar style"),
1086 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1087 GTK_TYPE_TOOLBAR_STYLE,
1089 GTK_PARAM_READWRITE),
1090 gtk_rc_property_parse_enum);
1091 g_assert (result == PROP_TOOLBAR_STYLE);
1094 * GtkSettings:gtk-toolbar-icon-size:
1096 * The size of icons in default toolbars.
1098 result = settings_install_property_parser (class,
1099 g_param_spec_enum ("gtk-toolbar-icon-size",
1100 P_("Toolbar Icon Size"),
1101 P_("The size of icons in default toolbars."),
1103 GTK_ICON_SIZE_LARGE_TOOLBAR,
1104 GTK_PARAM_READWRITE),
1105 gtk_rc_property_parse_enum);
1106 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1109 * GtkSettings:gtk-auto-mnemonics:
1111 * Whether mnemonics should be automatically shown and hidden when the user
1112 * presses the mnemonic activator.
1116 result = settings_install_property_parser (class,
1117 g_param_spec_boolean ("gtk-auto-mnemonics",
1118 P_("Auto Mnemonics"),
1119 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1121 GTK_PARAM_READWRITE),
1123 g_assert (result == PROP_AUTO_MNEMONICS);
1126 * GtkSettings:gtk-application-prefer-dark-theme:
1128 * Whether the application prefers to use a dark theme. If a GTK+ theme
1129 * includes a dark variant, it will be used instead of the configured
1132 * Some applications benefit from minimizing the amount of light pollution that
1133 * interferes with the content. Good candidates for dark themes are photo and
1134 * video editors that make the actual content get all the attention and minimize
1135 * the distraction of the chrome.
1137 * Dark themes should not be used for documents, where large spaces are white/light
1138 * and the dark chrome creates too much contrast (web browser, text editor...).
1142 result = settings_install_property_parser (class,
1143 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1144 P_("Application prefers a dark theme"),
1145 P_("Whether the application prefers to have a dark theme."),
1147 GTK_PARAM_READWRITE),
1149 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1152 * GtkSettings::gtk-button-images:
1154 * Whether images should be shown on buttons
1158 result = settings_install_property_parser (class,
1159 g_param_spec_boolean ("gtk-button-images",
1160 P_("Show button images"),
1161 P_("Whether images should be shown on buttons"),
1163 GTK_PARAM_READWRITE),
1165 g_assert (result == PROP_BUTTON_IMAGES);
1167 result = settings_install_property_parser (class,
1168 g_param_spec_boolean ("gtk-entry-select-on-focus",
1169 P_("Select on focus"),
1170 P_("Whether to select the contents of an entry when it is focused"),
1172 GTK_PARAM_READWRITE),
1174 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1177 * GtkSettings:gtk-entry-password-hint-timeout:
1179 * How long to show the last input character in hidden
1180 * entries. This value is in milliseconds. 0 disables showing the
1181 * last char. 600 is a good value for enabling it.
1185 result = settings_install_property_parser (class,
1186 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1187 P_("Password Hint Timeout"),
1188 P_("How long to show the last input character in hidden entries"),
1191 GTK_PARAM_READWRITE),
1193 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1195 result = settings_install_property_parser (class,
1196 g_param_spec_boolean ("gtk-menu-images",
1197 P_("Show menu images"),
1198 P_("Whether images should be shown in menus"),
1200 GTK_PARAM_READWRITE),
1202 g_assert (result == PROP_MENU_IMAGES);
1204 result = settings_install_property_parser (class,
1205 g_param_spec_int ("gtk-menu-bar-popup-delay",
1206 P_("Delay before drop down menus appear"),
1207 P_("Delay before the submenus of a menu bar appear"),
1210 GTK_PARAM_READWRITE),
1212 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1215 * GtkSettings:gtk-scrolled-window-placement:
1217 * Where the contents of scrolled windows are located with respect to the
1218 * scrollbars, if not overridden by the scrolled window's own placement.
1222 result = settings_install_property_parser (class,
1223 g_param_spec_enum ("gtk-scrolled-window-placement",
1224 P_("Scrolled Window Placement"),
1225 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1226 GTK_TYPE_CORNER_TYPE,
1227 GTK_CORNER_TOP_LEFT,
1228 GTK_PARAM_READWRITE),
1229 gtk_rc_property_parse_enum);
1230 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1232 result = settings_install_property_parser (class,
1233 g_param_spec_boolean ("gtk-can-change-accels",
1234 P_("Can change accelerators"),
1235 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1237 GTK_PARAM_READWRITE),
1239 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1241 result = settings_install_property_parser (class,
1242 g_param_spec_int ("gtk-menu-popup-delay",
1243 P_("Delay before submenus appear"),
1244 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1247 GTK_PARAM_READWRITE),
1249 g_assert (result == PROP_MENU_POPUP_DELAY);
1251 result = settings_install_property_parser (class,
1252 g_param_spec_int ("gtk-menu-popdown-delay",
1253 P_("Delay before hiding a submenu"),
1254 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1257 GTK_PARAM_READWRITE),
1259 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1261 result = settings_install_property_parser (class,
1262 g_param_spec_boolean ("gtk-label-select-on-focus",
1263 P_("Select on focus"),
1264 P_("Whether to select the contents of a selectable label when it is focused"),
1266 GTK_PARAM_READWRITE),
1268 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1270 result = settings_install_property_parser (class,
1271 g_param_spec_string ("gtk-color-palette",
1272 P_("Custom palette"),
1273 P_("Palette to use in the color selector"),
1274 default_color_palette,
1275 GTK_PARAM_READWRITE),
1277 g_assert (result == PROP_COLOR_PALETTE);
1279 result = settings_install_property_parser (class,
1280 g_param_spec_enum ("gtk-im-preedit-style",
1281 P_("IM Preedit style"),
1282 P_("How to draw the input method preedit string"),
1283 GTK_TYPE_IM_PREEDIT_STYLE,
1284 GTK_IM_PREEDIT_CALLBACK,
1285 GTK_PARAM_READWRITE),
1286 gtk_rc_property_parse_enum);
1287 g_assert (result == PROP_IM_PREEDIT_STYLE);
1289 result = settings_install_property_parser (class,
1290 g_param_spec_enum ("gtk-im-status-style",
1291 P_("IM Status style"),
1292 P_("How to draw the input method statusbar"),
1293 GTK_TYPE_IM_STATUS_STYLE,
1294 GTK_IM_STATUS_CALLBACK,
1295 GTK_PARAM_READWRITE),
1296 gtk_rc_property_parse_enum);
1297 g_assert (result == PROP_IM_STATUS_STYLE);
1299 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1302 static GtkStyleProperties *
1303 gtk_settings_get_style (GtkStyleProvider *provider,
1304 GtkWidgetPath *path)
1306 PangoFontDescription *font_desc;
1307 gchar *font_name, *color_scheme;
1308 GtkSettings *settings;
1309 GtkStyleProperties *props;
1313 settings = GTK_SETTINGS (provider);
1314 props = gtk_style_properties_new ();
1316 g_object_get (settings,
1317 "gtk-font-name", &font_name,
1318 "gtk-color-scheme", &color_scheme,
1321 colors = g_strsplit_set (color_scheme, "\n;", -1);
1323 for (i = 0; colors[i]; i++)
1325 GtkSymbolicColor *color;
1333 pos = strchr (colors[i], ':');
1338 /* Set NUL after color name */
1342 /* Find start of color string */
1346 if (!*pos || !gdk_rgba_parse (&col, pos))
1349 color = gtk_symbolic_color_new_literal (&col);
1350 gtk_style_properties_map_color (props, name, color);
1351 gtk_symbolic_color_unref (color);
1354 font_desc = pango_font_description_from_string (font_name);
1356 gtk_style_properties_set (props, 0,
1360 pango_font_description_free (font_desc);
1361 g_strfreev (colors);
1362 g_free (color_scheme);
1369 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1371 iface->get_style = gtk_settings_get_style;
1375 gtk_settings_finalize (GObject *object)
1377 GtkSettings *settings = GTK_SETTINGS (object);
1378 GtkSettingsPrivate *priv = settings->priv;
1381 object_list = g_slist_remove (object_list, settings);
1383 for (i = 0; i < class_n_properties; i++)
1384 g_value_unset (&priv->property_values[i].value);
1385 g_free (priv->property_values);
1387 g_datalist_clear (&priv->queued_settings);
1389 if (priv->theme_provider)
1390 g_object_unref (priv->theme_provider);
1392 if (priv->key_theme_provider)
1393 g_object_unref (priv->key_theme_provider);
1395 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1399 settings_init_style (GtkSettings *settings)
1401 static GtkCssProvider *css_provider = NULL;
1403 GdkScreen *screen = settings->priv->screen;
1404 GtkCssProvider *default_provider;
1406 /* Add provider for user file */
1407 if (G_UNLIKELY (!css_provider))
1411 css_provider = gtk_css_provider_new ();
1412 css_path = g_build_filename (g_get_user_config_dir (),
1417 if (g_file_test (css_path,
1418 G_FILE_TEST_IS_REGULAR))
1419 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1424 gtk_style_context_add_provider_for_screen (screen,
1425 GTK_STYLE_PROVIDER (css_provider),
1426 GTK_STYLE_PROVIDER_PRIORITY_USER);
1428 default_provider = gtk_css_provider_get_default ();
1429 gtk_style_context_add_provider_for_screen (screen,
1430 GTK_STYLE_PROVIDER (default_provider),
1431 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1433 gtk_style_context_add_provider_for_screen (screen,
1434 GTK_STYLE_PROVIDER (settings),
1435 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1437 settings_update_theme (settings);
1438 settings_update_key_theme (settings);
1442 * gtk_settings_get_for_screen:
1443 * @screen: a #GdkScreen.
1445 * Gets the #GtkSettings object for @screen, creating it if necessary.
1447 * Return value: (transfer none): a #GtkSettings object.
1452 gtk_settings_get_for_screen (GdkScreen *screen)
1454 GtkSettings *settings;
1456 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1458 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1461 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1462 settings->priv->screen = screen;
1463 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1464 settings, g_object_unref);
1466 settings_init_style (settings);
1467 settings_update_double_click (settings);
1468 #ifdef GDK_WINDOWING_X11
1469 if (GDK_IS_X11_SCREEN (screen))
1471 settings_update_cursor_theme (settings);
1472 settings_update_resolution (settings);
1473 settings_update_font_options (settings);
1476 settings_update_color_scheme (settings);
1483 * gtk_settings_get_default:
1485 * Gets the #GtkSettings object for the default GDK screen, creating
1486 * it if necessary. See gtk_settings_get_for_screen().
1488 * Return value: (transfer none): a #GtkSettings object. If there is no default
1489 * screen, then returns %NULL.
1492 gtk_settings_get_default (void)
1494 GdkScreen *screen = gdk_screen_get_default ();
1497 return gtk_settings_get_for_screen (screen);
1503 gtk_settings_set_property (GObject *object,
1505 const GValue *value,
1508 GtkSettings *settings = GTK_SETTINGS (object);
1509 GtkSettingsPrivate *priv = settings->priv;
1511 g_value_copy (value, &priv->property_values[property_id - 1].value);
1512 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1514 if (pspec->param_id == PROP_COLOR_SCHEME)
1515 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1519 gtk_settings_get_property (GObject *object,
1524 GtkSettings *settings = GTK_SETTINGS (object);
1525 GtkSettingsPrivate *priv = settings->priv;
1526 GType value_type = G_VALUE_TYPE (value);
1527 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1529 /* handle internal properties */
1530 switch (property_id)
1532 case PROP_COLOR_HASH:
1533 g_value_set_boxed (value, get_color_hash (settings));
1535 case PROP_COLOR_SCHEME:
1536 g_value_take_string (value, get_color_scheme (settings));
1541 /* For enums and strings, we need to get the value as a string,
1542 * not as an int, since we support using names/nicks as the setting
1545 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1546 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1547 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1548 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1550 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1551 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1552 g_value_copy (&priv->property_values[property_id - 1].value, value);
1554 g_param_value_validate (pspec, value);
1558 GValue val = { 0, };
1560 /* Try to get xsetting as a string and parse it. */
1562 g_value_init (&val, G_TYPE_STRING);
1564 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1565 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1567 g_value_copy (&priv->property_values[property_id - 1].value, value);
1571 GValue tmp_value = { 0, };
1572 GValue gstring_value = { 0, };
1573 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1575 g_value_init (&gstring_value, G_TYPE_GSTRING);
1576 g_value_take_boxed (&gstring_value,
1577 g_string_new (g_value_get_string (&val)));
1579 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1581 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1584 g_value_copy (&tmp_value, value);
1585 g_param_value_validate (pspec, value);
1589 g_value_copy (&priv->property_values[property_id - 1].value, value);
1592 g_value_unset (&gstring_value);
1593 g_value_unset (&tmp_value);
1596 g_value_unset (&val);
1601 gtk_settings_notify (GObject *object,
1604 GtkSettings *settings = GTK_SETTINGS (object);
1605 GtkSettingsPrivate *priv = settings->priv;
1606 guint property_id = pspec->param_id;
1608 if (priv->screen == NULL) /* initialization */
1611 switch (property_id)
1614 settings_update_modules (settings);
1616 case PROP_DOUBLE_CLICK_TIME:
1617 case PROP_DOUBLE_CLICK_DISTANCE:
1618 settings_update_double_click (settings);
1620 case PROP_COLOR_SCHEME:
1621 settings_update_color_scheme (settings);
1622 gtk_style_context_reset_widgets (priv->screen);
1624 case PROP_KEY_THEME_NAME:
1625 settings_update_key_theme (settings);
1627 case PROP_THEME_NAME:
1628 case PROP_APPLICATION_PREFER_DARK_THEME:
1629 settings_update_theme (settings);
1631 #ifdef GDK_WINDOWING_X11
1633 settings_update_resolution (settings);
1634 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1635 * widgets with gtk_widget_style_set(), and also causes more
1636 * recomputation than necessary.
1638 gtk_style_context_reset_widgets (priv->screen);
1640 case PROP_XFT_ANTIALIAS:
1641 case PROP_XFT_HINTING:
1642 case PROP_XFT_HINTSTYLE:
1644 settings_update_font_options (settings);
1645 gtk_style_context_reset_widgets (priv->screen);
1647 case PROP_FONTCONFIG_TIMESTAMP:
1648 if (settings_update_fontconfig (settings))
1649 gtk_style_context_reset_widgets (priv->screen);
1651 case PROP_CURSOR_THEME_NAME:
1652 case PROP_CURSOR_THEME_SIZE:
1653 settings_update_cursor_theme (settings);
1655 #endif /* GDK_WINDOWING_X11 */
1660 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1661 const GValue *src_value,
1665 gboolean success = FALSE;
1667 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1672 gboolean free_gstring = TRUE;
1674 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1676 gstring = g_value_get_boxed (src_value);
1677 free_gstring = FALSE;
1679 else if (G_VALUE_HOLDS_LONG (src_value))
1681 gstring = g_string_new (NULL);
1682 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1684 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1686 gstring = g_string_new (NULL);
1687 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1689 else if (G_VALUE_HOLDS_STRING (src_value))
1691 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1693 gstring = g_string_new (NULL);
1694 g_string_append_c (gstring, '\"');
1695 g_string_append (gstring, tstr);
1696 g_string_append_c (gstring, '\"');
1701 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1702 gstring = NULL; /* silence compiler */
1705 success = (parser (pspec, gstring, dest_value) &&
1706 !g_param_value_validate (pspec, dest_value));
1709 g_string_free (gstring, TRUE);
1711 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1713 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1715 GString *gstring = g_value_get_boxed (src_value);
1717 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1718 success = !g_param_value_validate (pspec, dest_value);
1721 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1722 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1728 apply_queued_setting (GtkSettings *settings,
1730 GtkSettingsValuePrivate *qvalue)
1732 GtkSettingsPrivate *priv = settings->priv;
1733 GValue tmp_value = { 0, };
1734 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1736 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1737 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1740 if (pspec->param_id == PROP_COLOR_SCHEME)
1741 merge_color_scheme (settings, &tmp_value, qvalue->source);
1743 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1745 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1746 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1747 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1753 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1755 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1756 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1758 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1760 G_VALUE_TYPE_NAME (&tmp_value));
1763 g_value_unset (&tmp_value);
1767 settings_install_property_parser (GtkSettingsClass *class,
1769 GtkRcPropertyParser parser)
1771 GSList *node, *next;
1773 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1775 case G_TYPE_BOOLEAN:
1788 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1796 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1797 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1801 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1803 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1808 for (node = object_list; node; node = node->next)
1809 g_object_freeze_notify (node->data);
1811 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1812 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1814 for (node = object_list; node; node = node->next)
1816 GtkSettings *settings = node->data;
1817 GtkSettingsPrivate *priv = settings->priv;
1818 GtkSettingsValuePrivate *qvalue;
1820 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1821 priv->property_values[class_n_properties - 1].value.g_type = 0;
1822 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1823 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1824 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1825 g_object_notify (G_OBJECT (settings), pspec->name);
1827 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1829 apply_queued_setting (settings, pspec, qvalue);
1832 for (node = object_list; node; node = next)
1835 g_object_thaw_notify (node->data);
1838 return class_n_properties;
1842 _gtk_rc_property_parser_from_type (GType type)
1844 if (type == GDK_TYPE_COLOR)
1845 return gtk_rc_property_parse_color;
1846 else if (type == GTK_TYPE_REQUISITION)
1847 return gtk_rc_property_parse_requisition;
1848 else if (type == GTK_TYPE_BORDER)
1849 return gtk_rc_property_parse_border;
1850 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1851 return gtk_rc_property_parse_enum;
1852 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1853 return gtk_rc_property_parse_flags;
1859 gtk_settings_install_property (GParamSpec *pspec)
1861 static GtkSettingsClass *klass = NULL;
1863 GtkRcPropertyParser parser;
1865 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1868 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1870 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1872 settings_install_property_parser (klass, pspec, parser);
1876 * gtk_settings_install_property_parser:
1878 * @parser: (scope call):
1881 gtk_settings_install_property_parser (GParamSpec *pspec,
1882 GtkRcPropertyParser parser)
1884 static GtkSettingsClass *klass = NULL;
1886 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1887 g_return_if_fail (parser != NULL);
1890 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1892 settings_install_property_parser (klass, pspec, parser);
1896 free_value (gpointer data)
1898 GtkSettingsValuePrivate *qvalue = data;
1900 g_value_unset (&qvalue->public.value);
1901 g_free (qvalue->public.origin);
1902 g_slice_free (GtkSettingsValuePrivate, qvalue);
1906 gtk_settings_set_property_value_internal (GtkSettings *settings,
1907 const gchar *prop_name,
1908 const GtkSettingsValue *new_value,
1909 GtkSettingsSource source)
1911 GtkSettingsPrivate *priv = settings->priv;
1912 GtkSettingsValuePrivate *qvalue;
1917 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1918 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1919 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1920 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1922 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
1926 name = g_strdup (prop_name);
1927 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1928 name_quark = g_quark_from_string (name);
1931 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
1934 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1935 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
1939 g_free (qvalue->public.origin);
1940 g_value_unset (&qvalue->public.value);
1942 qvalue->public.origin = g_strdup (new_value->origin);
1943 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1944 g_value_copy (&new_value->value, &qvalue->public.value);
1945 qvalue->source = source;
1946 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1948 apply_queued_setting (settings, pspec, qvalue);
1952 gtk_settings_set_property_value (GtkSettings *settings,
1953 const gchar *prop_name,
1954 const GtkSettingsValue *new_value)
1956 g_return_if_fail (GTK_SETTINGS (settings));
1957 g_return_if_fail (prop_name != NULL);
1958 g_return_if_fail (new_value != NULL);
1960 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1961 GTK_SETTINGS_SOURCE_APPLICATION);
1965 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1966 const gchar *prop_name,
1967 const GtkSettingsValue *new_value)
1969 g_return_if_fail (GTK_SETTINGS (settings));
1970 g_return_if_fail (prop_name != NULL);
1971 g_return_if_fail (new_value != NULL);
1973 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1974 GTK_SETTINGS_SOURCE_THEME);
1978 gtk_settings_set_string_property (GtkSettings *settings,
1980 const gchar *v_string,
1981 const gchar *origin)
1983 GtkSettingsValue svalue = { NULL, { 0, }, };
1985 g_return_if_fail (GTK_SETTINGS (settings));
1986 g_return_if_fail (name != NULL);
1987 g_return_if_fail (v_string != NULL);
1989 svalue.origin = (gchar*) origin;
1990 g_value_init (&svalue.value, G_TYPE_STRING);
1991 g_value_set_static_string (&svalue.value, v_string);
1992 gtk_settings_set_property_value (settings, name, &svalue);
1993 g_value_unset (&svalue.value);
1997 gtk_settings_set_long_property (GtkSettings *settings,
2000 const gchar *origin)
2002 GtkSettingsValue svalue = { NULL, { 0, }, };
2004 g_return_if_fail (GTK_SETTINGS (settings));
2005 g_return_if_fail (name != NULL);
2007 svalue.origin = (gchar*) origin;
2008 g_value_init (&svalue.value, G_TYPE_LONG);
2009 g_value_set_long (&svalue.value, v_long);
2010 gtk_settings_set_property_value (settings, name, &svalue);
2011 g_value_unset (&svalue.value);
2015 gtk_settings_set_double_property (GtkSettings *settings,
2018 const gchar *origin)
2020 GtkSettingsValue svalue = { NULL, { 0, }, };
2022 g_return_if_fail (GTK_SETTINGS (settings));
2023 g_return_if_fail (name != NULL);
2025 svalue.origin = (gchar*) origin;
2026 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2027 g_value_set_double (&svalue.value, v_double);
2028 gtk_settings_set_property_value (settings, name, &svalue);
2029 g_value_unset (&svalue.value);
2033 * gtk_rc_property_parse_color:
2034 * @pspec: a #GParamSpec
2035 * @gstring: the #GString to be parsed
2036 * @property_value: a #GValue which must hold #GdkColor values.
2038 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2039 * or gtk_widget_class_install_style_property_parser() which parses a
2040 * color given either by its name or in the form
2041 * <literal>{ red, green, blue }</literal> where %red, %green and
2042 * %blue are integers between 0 and 65535 or floating-point numbers
2045 * Return value: %TRUE if @gstring could be parsed and @property_value
2046 * has been set to the resulting #GdkColor.
2049 gtk_rc_property_parse_color (const GParamSpec *pspec,
2050 const GString *gstring,
2051 GValue *property_value)
2053 GdkColor color = { 0, 0, 0, 0, };
2057 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2058 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2060 scanner = gtk_rc_scanner_new ();
2061 g_scanner_input_text (scanner, gstring->str, gstring->len);
2062 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2063 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2065 g_value_set_boxed (property_value, &color);
2070 g_scanner_destroy (scanner);
2076 * gtk_rc_property_parse_enum:
2077 * @pspec: a #GParamSpec
2078 * @gstring: the #GString to be parsed
2079 * @property_value: a #GValue which must hold enum values.
2081 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2082 * or gtk_widget_class_install_style_property_parser() which parses a single
2083 * enumeration value.
2085 * The enumeration value can be specified by its name, its nickname or
2086 * its numeric value. For consistency with flags parsing, the value
2087 * may be surrounded by parentheses.
2089 * Return value: %TRUE if @gstring could be parsed and @property_value
2090 * has been set to the resulting #GEnumValue.
2093 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2094 const GString *gstring,
2095 GValue *property_value)
2097 gboolean need_closing_brace = FALSE, success = FALSE;
2099 GEnumValue *enum_value = NULL;
2101 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2102 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2104 scanner = gtk_rc_scanner_new ();
2105 g_scanner_input_text (scanner, gstring->str, gstring->len);
2107 /* we just want to parse _one_ value, but for consistency with flags parsing
2108 * we support optional parenthesis
2110 g_scanner_get_next_token (scanner);
2111 if (scanner->token == '(')
2113 need_closing_brace = TRUE;
2114 g_scanner_get_next_token (scanner);
2116 if (scanner->token == G_TOKEN_IDENTIFIER)
2118 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2120 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2122 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2125 g_value_set_enum (property_value, enum_value->value);
2129 else if (scanner->token == G_TOKEN_INT)
2131 g_value_set_enum (property_value, scanner->value.v_int);
2134 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2136 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2139 g_scanner_destroy (scanner);
2145 parse_flags_value (GScanner *scanner,
2149 g_scanner_get_next_token (scanner);
2150 if (scanner->token == G_TOKEN_IDENTIFIER)
2152 GFlagsValue *flags_value;
2154 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2156 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2159 *number |= flags_value->value;
2160 return G_TOKEN_NONE;
2163 else if (scanner->token == G_TOKEN_INT)
2165 *number |= scanner->value.v_int;
2166 return G_TOKEN_NONE;
2168 return G_TOKEN_IDENTIFIER;
2172 * gtk_rc_property_parse_flags:
2173 * @pspec: a #GParamSpec
2174 * @gstring: the #GString to be parsed
2175 * @property_value: a #GValue which must hold flags values.
2177 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2178 * or gtk_widget_class_install_style_property_parser() which parses flags.
2180 * Flags can be specified by their name, their nickname or
2181 * numerically. Multiple flags can be specified in the form
2182 * <literal>"( flag1 | flag2 | ... )"</literal>.
2184 * Return value: %TRUE if @gstring could be parsed and @property_value
2185 * has been set to the resulting flags value.
2188 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2189 const GString *gstring,
2190 GValue *property_value)
2193 gboolean success = FALSE;
2196 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2197 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2199 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2200 scanner = gtk_rc_scanner_new ();
2201 g_scanner_input_text (scanner, gstring->str, gstring->len);
2203 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2204 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2205 scanner->next_token == G_TOKEN_INT)
2207 guint token, flags_value = 0;
2209 token = parse_flags_value (scanner, class, &flags_value);
2211 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2214 g_value_set_flags (property_value, flags_value);
2218 else if (g_scanner_get_next_token (scanner) == '(')
2220 guint token, flags_value = 0;
2222 /* parse first value */
2223 token = parse_flags_value (scanner, class, &flags_value);
2225 /* parse nth values, preceeded by '|' */
2226 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2227 token = parse_flags_value (scanner, class, &flags_value);
2229 /* done, last token must have closed expression */
2230 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2231 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2233 g_value_set_flags (property_value, flags_value);
2237 g_scanner_destroy (scanner);
2243 get_braced_int (GScanner *scanner,
2250 g_scanner_get_next_token (scanner);
2251 if (scanner->token != '{')
2255 g_scanner_get_next_token (scanner);
2256 if (scanner->token != G_TOKEN_INT)
2259 *value = scanner->value.v_int;
2263 g_scanner_get_next_token (scanner);
2264 if (scanner->token != '}')
2269 g_scanner_get_next_token (scanner);
2270 if (scanner->token != ',')
2278 * gtk_rc_property_parse_requisition:
2279 * @pspec: a #GParamSpec
2280 * @gstring: the #GString to be parsed
2281 * @property_value: a #GValue which must hold boxed values.
2283 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2284 * or gtk_widget_class_install_style_property_parser() which parses a
2285 * requisition in the form
2286 * <literal>"{ width, height }"</literal> for integers %width and %height.
2288 * Return value: %TRUE if @gstring could be parsed and @property_value
2289 * has been set to the resulting #GtkRequisition.
2292 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2293 const GString *gstring,
2294 GValue *property_value)
2296 GtkRequisition requisition;
2298 gboolean success = FALSE;
2300 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2301 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2303 scanner = gtk_rc_scanner_new ();
2304 g_scanner_input_text (scanner, gstring->str, gstring->len);
2306 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2307 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2309 g_value_set_boxed (property_value, &requisition);
2313 g_scanner_destroy (scanner);
2319 * gtk_rc_property_parse_border:
2320 * @pspec: a #GParamSpec
2321 * @gstring: the #GString to be parsed
2322 * @property_value: a #GValue which must hold boxed values.
2324 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2325 * or gtk_widget_class_install_style_property_parser() which parses
2326 * borders in the form
2327 * <literal>"{ left, right, top, bottom }"</literal> for integers
2328 * %left, %right, %top and %bottom.
2330 * Return value: %TRUE if @gstring could be parsed and @property_value
2331 * has been set to the resulting #GtkBorder.
2334 gtk_rc_property_parse_border (const GParamSpec *pspec,
2335 const GString *gstring,
2336 GValue *property_value)
2340 gboolean success = FALSE;
2341 int left, right, top, bottom;
2343 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2344 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2346 scanner = gtk_rc_scanner_new ();
2347 g_scanner_input_text (scanner, gstring->str, gstring->len);
2349 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2350 get_braced_int (scanner, FALSE, FALSE, &right) &&
2351 get_braced_int (scanner, FALSE, FALSE, &top) &&
2352 get_braced_int (scanner, FALSE, TRUE, &bottom))
2355 border.right = right;
2357 border.bottom = bottom;
2358 g_value_set_boxed (property_value, &border);
2362 g_scanner_destroy (scanner);
2368 _gtk_settings_handle_event (GdkEventSetting *event)
2371 GtkSettings *settings;
2375 screen = gdk_window_get_screen (event->window);
2376 settings = gtk_settings_get_for_screen (screen);
2377 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2381 property_id = pspec->param_id;
2383 if (property_id == PROP_COLOR_SCHEME)
2385 GValue value = { 0, };
2387 g_value_init (&value, G_TYPE_STRING);
2388 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2389 g_value_set_static_string (&value, "");
2390 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2391 g_value_unset (&value);
2393 g_object_notify (G_OBJECT (settings), pspec->name);
2398 reset_rc_values_foreach (GQuark key_id,
2402 GtkSettingsValuePrivate *qvalue = data;
2403 GSList **to_reset = user_data;
2405 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2406 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2410 _gtk_settings_reset_rc_values (GtkSettings *settings)
2412 GtkSettingsPrivate *priv = settings->priv;
2413 GSList *to_reset = NULL;
2415 GParamSpec **pspecs, **p;
2418 /* Remove any queued settings */
2419 g_datalist_foreach (&priv->queued_settings,
2420 reset_rc_values_foreach,
2423 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2425 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2426 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2429 g_slist_free (to_reset);
2431 /* Now reset the active settings
2433 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2436 g_object_freeze_notify (G_OBJECT (settings));
2437 for (p = pspecs; *p; p++)
2439 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2441 GParamSpec *pspec = *p;
2443 g_param_value_set_default (pspec, &priv->property_values[i].value);
2444 g_object_notify (G_OBJECT (settings), pspec->name);
2448 g_object_thaw_notify (G_OBJECT (settings));
2453 settings_update_double_click (GtkSettings *settings)
2455 GtkSettingsPrivate *priv = settings->priv;
2457 if (gdk_screen_get_number (priv->screen) == 0)
2459 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2460 gint double_click_time;
2461 gint double_click_distance;
2463 g_object_get (settings,
2464 "gtk-double-click-time", &double_click_time,
2465 "gtk-double-click-distance", &double_click_distance,
2468 gdk_display_set_double_click_time (display, double_click_time);
2469 gdk_display_set_double_click_distance (display, double_click_distance);
2474 settings_update_modules (GtkSettings *settings)
2478 g_object_get (settings,
2479 "gtk-modules", &modules,
2482 _gtk_modules_settings_changed (settings, modules);
2487 #ifdef GDK_WINDOWING_X11
2489 settings_update_cursor_theme (GtkSettings *settings)
2491 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2492 gchar *theme = NULL;
2495 g_object_get (settings,
2496 "gtk-cursor-theme-name", &theme,
2497 "gtk-cursor-theme-size", &size,
2500 gdk_x11_display_set_cursor_theme (display, theme, size);
2506 settings_update_font_options (GtkSettings *settings)
2508 GtkSettingsPrivate *priv = settings->priv;
2510 gchar *hint_style_str;
2511 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2513 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2515 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2516 cairo_font_options_t *options;
2518 g_object_get (settings,
2519 "gtk-xft-antialias", &antialias,
2520 "gtk-xft-hinting", &hinting,
2521 "gtk-xft-hintstyle", &hint_style_str,
2522 "gtk-xft-rgba", &rgba_str,
2525 options = cairo_font_options_create ();
2527 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2529 if (hinting >= 0 && !hinting)
2531 hint_style = CAIRO_HINT_STYLE_NONE;
2533 else if (hint_style_str)
2535 if (strcmp (hint_style_str, "hintnone") == 0)
2536 hint_style = CAIRO_HINT_STYLE_NONE;
2537 else if (strcmp (hint_style_str, "hintslight") == 0)
2538 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2539 else if (strcmp (hint_style_str, "hintmedium") == 0)
2540 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2541 else if (strcmp (hint_style_str, "hintfull") == 0)
2542 hint_style = CAIRO_HINT_STYLE_FULL;
2545 g_free (hint_style_str);
2547 cairo_font_options_set_hint_style (options, hint_style);
2551 if (strcmp (rgba_str, "rgb") == 0)
2552 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2553 else if (strcmp (rgba_str, "bgr") == 0)
2554 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2555 else if (strcmp (rgba_str, "vrgb") == 0)
2556 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2557 else if (strcmp (rgba_str, "vbgr") == 0)
2558 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2563 cairo_font_options_set_subpixel_order (options, subpixel_order);
2565 if (antialias >= 0 && !antialias)
2566 antialias_mode = CAIRO_ANTIALIAS_NONE;
2567 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2568 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2569 else if (antialias >= 0)
2570 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2572 cairo_font_options_set_antialias (options, antialias_mode);
2574 gdk_screen_set_font_options (priv->screen, options);
2576 cairo_font_options_destroy (options);
2579 #ifdef GDK_WINDOWING_X11
2581 settings_update_fontconfig (GtkSettings *settings)
2583 static guint last_update_timestamp;
2584 static gboolean last_update_needed;
2588 g_object_get (settings,
2589 "gtk-fontconfig-timestamp", ×tamp,
2592 /* if timestamp is the same as last_update_timestamp, we already have
2593 * updated fontconig on this timestamp (another screen requested it perhaps?),
2594 * just return the cached result.*/
2596 if (timestamp != last_update_timestamp)
2598 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2599 gboolean update_needed = FALSE;
2602 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2604 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2605 if (FcInitReinitialize ())
2606 update_needed = TRUE;
2609 last_update_timestamp = timestamp;
2610 last_update_needed = update_needed;
2613 return last_update_needed;
2615 #endif /* GDK_WINDOWING_X11 */
2618 settings_update_resolution (GtkSettings *settings)
2620 GtkSettingsPrivate *priv = settings->priv;
2624 g_object_get (settings,
2625 "gtk-xft-dpi", &dpi_int,
2629 dpi = dpi_int / 1024.;
2633 gdk_screen_set_resolution (priv->screen, dpi);
2639 GHashTable *color_hash;
2640 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2641 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2645 color_scheme_data_free (ColorSchemeData *data)
2649 g_hash_table_unref (data->color_hash);
2651 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2653 if (data->tables[i])
2654 g_hash_table_unref (data->tables[i]);
2655 g_free (data->lastentry[i]);
2658 g_slice_free (ColorSchemeData, data);
2662 settings_update_color_scheme (GtkSettings *settings)
2664 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2666 GtkSettingsPrivate *priv = settings->priv;
2667 ColorSchemeData *data;
2668 GValue value = { 0, };
2670 data = g_slice_new0 (ColorSchemeData);
2671 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2672 (GDestroyNotify) gdk_color_free);
2673 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2674 data, (GDestroyNotify) color_scheme_data_free);
2676 g_value_init (&value, G_TYPE_STRING);
2677 if (gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2679 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2680 g_value_unset (&value);
2686 settings_update_provider (GdkScreen *screen,
2687 GtkCssProvider **old,
2688 GtkCssProvider *new)
2694 gtk_style_context_remove_provider_for_screen (screen,
2695 GTK_STYLE_PROVIDER (*old));
2696 g_object_unref (*old);
2702 gtk_style_context_add_provider_for_screen (screen,
2703 GTK_STYLE_PROVIDER (new),
2704 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2705 *old = g_object_ref (new);
2711 settings_update_theme (GtkSettings *settings)
2713 GtkSettingsPrivate *priv = settings->priv;
2714 GtkCssProvider *provider = NULL;
2715 gboolean prefer_dark_theme;
2718 g_object_get (settings,
2719 "gtk-theme-name", &theme_name,
2720 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2723 if (theme_name && *theme_name)
2725 if (prefer_dark_theme)
2726 provider = gtk_css_provider_get_named (theme_name, "dark");
2729 provider = gtk_css_provider_get_named (theme_name, NULL);
2732 settings_update_provider (priv->screen, &priv->theme_provider, provider);
2734 if (theme_name && *theme_name)
2739 /* reload per-theme settings */
2740 theme_dir = _gtk_css_provider_get_theme_dir ();
2741 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2743 if (g_file_test (path, G_FILE_TEST_EXISTS))
2744 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2750 g_free (theme_name);
2754 settings_update_key_theme (GtkSettings *settings)
2756 GtkSettingsPrivate *priv = settings->priv;
2757 GtkCssProvider *provider = NULL;
2758 gchar *key_theme_name;
2760 g_object_get (settings,
2761 "gtk-key-theme-name", &key_theme_name,
2764 if (key_theme_name && *key_theme_name)
2765 provider = gtk_css_provider_get_named (key_theme_name, "keys");
2767 settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2768 g_free (key_theme_name);
2772 add_color_to_hash (gchar *name,
2778 old = g_hash_table_lookup (target, name);
2779 if (!old || !gdk_color_equal (old, color))
2781 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2790 add_colors_to_hash_from_string (GHashTable *hash,
2791 const gchar *colors)
2793 gchar *s, *p, *name;
2795 gboolean changed = FALSE;
2798 copy = g_strdup (colors);
2803 p = strchr (s, ':');
2818 if (*s == '\n' || *s == ';')
2827 if (gdk_color_parse (p, &color))
2828 changed |= add_color_to_hash (name, &color, hash);
2837 update_color_hash (ColorSchemeData *data,
2839 GtkSettingsSource source)
2841 gboolean changed = FALSE;
2843 GHashTable *old_hash;
2844 GHashTableIter iter;
2848 if ((str == NULL || *str == '\0') &&
2849 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2852 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2855 /* For the THEME source we merge the values rather than over-writing
2856 * them, since multiple rc files might define independent sets of colors
2858 if ((source != GTK_SETTINGS_SOURCE_THEME) &&
2859 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2861 g_hash_table_unref (data->tables[source]);
2862 data->tables[source] = NULL;
2863 changed = TRUE; /* We can't rely on the code below since str might be "" */
2866 if (data->tables[source] == NULL)
2867 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2869 (GDestroyNotify) gdk_color_free);
2871 g_free (data->lastentry[source]);
2872 data->lastentry[source] = g_strdup (str);
2874 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2879 /* Rebuild the merged hash table. */
2880 if (data->color_hash)
2882 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2883 (GDestroyNotify) gdk_color_free);
2885 g_hash_table_iter_init (&iter, data->color_hash);
2886 while (g_hash_table_iter_next (&iter, &name, &color))
2888 g_hash_table_insert (old_hash, name, color);
2889 g_hash_table_iter_steal (&iter);
2897 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2899 if (data->tables[i])
2900 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2906 /* now check if the merged hash has changed */
2908 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2912 GHashTableIter iter;
2913 gpointer key, value, new_value;
2915 g_hash_table_iter_init (&iter, old_hash);
2916 while (g_hash_table_iter_next (&iter, &key, &value))
2918 new_value = g_hash_table_lookup (data->color_hash, key);
2919 if (!new_value || !gdk_color_equal (value, new_value))
2927 g_hash_table_unref (old_hash);
2936 merge_color_scheme (GtkSettings *settings,
2937 const GValue *value,
2938 GtkSettingsSource source)
2940 ColorSchemeData *data;
2941 const gchar *colors;
2943 g_object_freeze_notify (G_OBJECT (settings));
2945 colors = g_value_get_string (value);
2947 settings_update_color_scheme (settings);
2949 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2950 "gtk-color-scheme");
2952 if (update_color_hash (data, colors, source))
2953 g_object_notify (G_OBJECT (settings), "color-hash");
2955 g_object_thaw_notify (G_OBJECT (settings));
2959 get_color_hash (GtkSettings *settings)
2961 ColorSchemeData *data;
2963 settings_update_color_scheme (settings);
2965 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2966 "gtk-color-scheme");
2968 return data->color_hash;
2972 append_color_scheme (gpointer key,
2976 gchar *name = (gchar *)key;
2977 GdkColor *color = (GdkColor *)value;
2978 GString *string = (GString *)data;
2980 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2981 name, color->red, color->green, color->blue);
2985 get_color_scheme (GtkSettings *settings)
2987 ColorSchemeData *data;
2990 settings_update_color_scheme (settings);
2992 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2993 "gtk-color-scheme");
2995 string = g_string_new ("");
2997 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2999 return g_string_free (string, FALSE);
3003 _gtk_settings_get_screen (GtkSettings *settings)
3005 return settings->priv->screen;
3010 gtk_settings_load_from_key_file (GtkSettings *settings,
3012 GtkSettingsSource source)
3023 keyfile = g_key_file_new ();
3025 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
3027 g_warning ("Failed to parse %s: %s", path, error->message);
3029 g_error_free (error);
3034 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3037 g_warning ("Failed to parse %s: %s", path, error->message);
3038 g_error_free (error);
3042 for (i = 0; i < n_keys; i++)
3047 GtkSettingsValue svalue = { NULL, { 0, }, };
3050 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3053 g_warning ("Unknown key %s in %s", key, path);
3057 if (pspec->owner_type != G_OBJECT_TYPE (settings))
3060 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3063 case G_TYPE_BOOLEAN:
3067 g_value_init (&svalue.value, G_TYPE_LONG);
3068 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3070 g_value_set_long (&svalue.value, b_val);
3078 g_value_init (&svalue.value, G_TYPE_LONG);
3079 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3081 g_value_set_long (&svalue.value, i_val);
3089 g_value_init (&svalue.value, G_TYPE_DOUBLE);
3090 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3092 g_value_set_double (&svalue.value, d_val);
3100 g_value_init (&svalue.value, G_TYPE_GSTRING);
3101 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3103 g_value_set_boxed (&svalue.value, g_string_new (s_val));
3110 g_warning ("Error setting %s in %s: %s", key, path, error->message);
3111 g_error_free (error);
3116 if (g_getenv ("GTK_DEBUG"))
3117 svalue.origin = (gchar *)path;
3118 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3119 g_value_unset (&svalue.value);
3125 g_key_file_free (keyfile);