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;
107 GTK_SETTINGS_SOURCE_DEFAULT,
108 GTK_SETTINGS_SOURCE_THEME,
109 GTK_SETTINGS_SOURCE_XSETTING,
110 GTK_SETTINGS_SOURCE_APPLICATION
113 struct _GtkSettingsValuePrivate
115 GtkSettingsValue public;
116 GtkSettingsSource source;
119 struct _GtkSettingsPropertyValue
122 GtkSettingsSource source;
127 PROP_DOUBLE_CLICK_TIME,
128 PROP_DOUBLE_CLICK_DISTANCE,
130 PROP_CURSOR_BLINK_TIME,
131 PROP_CURSOR_BLINK_TIMEOUT,
134 PROP_ICON_THEME_NAME,
135 PROP_FALLBACK_ICON_THEME,
138 PROP_DND_DRAG_THRESHOLD,
142 #ifdef GDK_WINDOWING_X11
148 PROP_CURSOR_THEME_NAME,
149 PROP_CURSOR_THEME_SIZE,
151 PROP_ALTERNATIVE_BUTTON_ORDER,
152 PROP_ALTERNATIVE_SORT_ARROWS,
153 PROP_SHOW_INPUT_METHOD_MENU,
154 PROP_SHOW_UNICODE_MENU,
155 PROP_TIMEOUT_INITIAL,
159 PROP_ENABLE_ANIMATIONS,
160 PROP_TOUCHSCREEN_MODE,
161 PROP_TOOLTIP_TIMEOUT,
162 PROP_TOOLTIP_BROWSE_TIMEOUT,
163 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
164 PROP_KEYNAV_CURSOR_ONLY,
165 PROP_KEYNAV_WRAP_AROUND,
168 PROP_FILE_CHOOSER_BACKEND,
170 PROP_PRINT_PREVIEW_COMMAND,
171 PROP_ENABLE_MNEMONICS,
173 PROP_RECENT_FILES_LIMIT,
175 PROP_RECENT_FILES_MAX_AGE,
176 PROP_FONTCONFIG_TIMESTAMP,
177 PROP_SOUND_THEME_NAME,
178 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
179 PROP_ENABLE_EVENT_SOUNDS,
180 PROP_ENABLE_TOOLTIPS,
182 PROP_TOOLBAR_ICON_SIZE,
184 PROP_APPLICATION_PREFER_DARK_THEME,
186 PROP_ENTRY_SELECT_ON_FOCUS,
187 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
189 PROP_MENU_BAR_POPUP_DELAY,
190 PROP_SCROLLED_WINDOW_PLACEMENT,
191 PROP_CAN_CHANGE_ACCELS,
192 PROP_MENU_POPUP_DELAY,
193 PROP_MENU_POPDOWN_DELAY,
194 PROP_LABEL_SELECT_ON_FOCUS,
196 PROP_IM_PREEDIT_STYLE,
200 /* --- prototypes --- */
201 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
203 static void gtk_settings_finalize (GObject *object);
204 static void gtk_settings_get_property (GObject *object,
208 static void gtk_settings_set_property (GObject *object,
212 static void gtk_settings_notify (GObject *object,
214 static guint settings_install_property_parser (GtkSettingsClass *class,
216 GtkRcPropertyParser parser);
217 static void settings_update_double_click (GtkSettings *settings);
218 static void settings_update_modules (GtkSettings *settings);
220 #ifdef GDK_WINDOWING_X11
221 static void settings_update_cursor_theme (GtkSettings *settings);
222 static void settings_update_resolution (GtkSettings *settings);
223 static void settings_update_font_options (GtkSettings *settings);
224 static gboolean settings_update_fontconfig (GtkSettings *settings);
226 static void settings_update_color_scheme (GtkSettings *settings);
227 static void settings_update_theme (GtkSettings *settings);
229 static void merge_color_scheme (GtkSettings *settings,
231 GtkSettingsSource source);
232 static gchar *get_color_scheme (GtkSettings *settings);
233 static GHashTable *get_color_hash (GtkSettings *settings);
234 static void gtk_settings_load_from_key_file (GtkSettings *settings,
236 GtkSettingsSource source);
238 /* the default palette for GtkColorSelelection */
239 static const gchar default_color_palette[] =
240 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
241 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
243 /* --- variables --- */
244 static GQuark quark_property_parser = 0;
245 static GSList *object_list = NULL;
246 static guint class_n_properties = 0;
249 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
250 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
251 gtk_settings_provider_iface_init));
253 /* --- functions --- */
255 gtk_settings_init (GtkSettings *settings)
257 GtkSettingsPrivate *priv;
258 GParamSpec **pspecs, **p;
262 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
266 settings->priv = priv;
267 g_datalist_init (&priv->queued_settings);
268 object_list = g_slist_prepend (object_list, settings);
270 /* build up property array for all yet existing properties and queue
271 * notification for them (at least notification for internal properties
272 * will instantly be caught)
274 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
275 for (p = pspecs; *p; p++)
276 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
278 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
280 g_object_freeze_notify (G_OBJECT (settings));
282 for (p = pspecs; *p; p++)
284 GParamSpec *pspec = *p;
285 GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
287 if (pspec->owner_type != G_OBJECT_TYPE (settings))
289 g_value_init (&priv->property_values[i].value, value_type);
290 g_param_value_set_default (pspec, &priv->property_values[i].value);
292 g_object_notify (G_OBJECT (settings), pspec->name);
293 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
298 path = g_build_filename (GTK_SYSCONFDIR, "gtk-3.0", "settings.ini", NULL);
299 if (g_file_test (path, G_FILE_TEST_EXISTS))
300 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
303 path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "settings.ini", NULL);
304 if (g_file_test (path, G_FILE_TEST_EXISTS))
305 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
308 g_object_thaw_notify (G_OBJECT (settings));
312 gtk_settings_class_init (GtkSettingsClass *class)
314 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
317 gobject_class->finalize = gtk_settings_finalize;
318 gobject_class->get_property = gtk_settings_get_property;
319 gobject_class->set_property = gtk_settings_set_property;
320 gobject_class->notify = gtk_settings_notify;
322 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
323 result = settings_install_property_parser (class,
324 g_param_spec_int ("gtk-double-click-time",
325 P_("Double Click Time"),
326 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
328 GTK_PARAM_READWRITE),
330 g_assert (result == PROP_DOUBLE_CLICK_TIME);
331 result = settings_install_property_parser (class,
332 g_param_spec_int ("gtk-double-click-distance",
333 P_("Double Click Distance"),
334 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
336 GTK_PARAM_READWRITE),
338 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
341 * GtkSettings:gtk-cursor-blink:
343 * Whether the cursor should blink.
345 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
346 * which allows more flexible control over cursor blinking.
348 result = settings_install_property_parser (class,
349 g_param_spec_boolean ("gtk-cursor-blink",
351 P_("Whether the cursor should blink"),
353 GTK_PARAM_READWRITE),
355 g_assert (result == PROP_CURSOR_BLINK);
356 result = settings_install_property_parser (class,
357 g_param_spec_int ("gtk-cursor-blink-time",
358 P_("Cursor Blink Time"),
359 P_("Length of the cursor blink cycle, in milliseconds"),
361 GTK_PARAM_READWRITE),
363 g_assert (result == PROP_CURSOR_BLINK_TIME);
366 * GtkSettings:gtk-cursor-blink-timeout:
368 * Time after which the cursor stops blinking, in seconds.
369 * The timer is reset after each user interaction.
371 * Setting this to zero has the same effect as setting
372 * #GtkSettings:gtk-cursor-blink to %FALSE.
376 result = settings_install_property_parser (class,
377 g_param_spec_int ("gtk-cursor-blink-timeout",
378 P_("Cursor Blink Timeout"),
379 P_("Time after which the cursor stops blinking, in seconds"),
380 1, G_MAXINT, G_MAXINT,
381 GTK_PARAM_READWRITE),
383 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
384 result = settings_install_property_parser (class,
385 g_param_spec_boolean ("gtk-split-cursor",
387 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
389 GTK_PARAM_READWRITE),
391 g_assert (result == PROP_SPLIT_CURSOR);
392 result = settings_install_property_parser (class,
393 g_param_spec_string ("gtk-theme-name",
395 P_("Name of theme RC file to load"),
397 GTK_PARAM_READWRITE),
399 g_assert (result == PROP_THEME_NAME);
401 result = settings_install_property_parser (class,
402 g_param_spec_string ("gtk-icon-theme-name",
403 P_("Icon Theme Name"),
404 P_("Name of icon theme to use"),
406 GTK_PARAM_READWRITE),
408 g_assert (result == PROP_ICON_THEME_NAME);
410 result = settings_install_property_parser (class,
411 g_param_spec_string ("gtk-fallback-icon-theme",
412 P_("Fallback Icon Theme Name"),
413 P_("Name of a icon theme to fall back to"),
415 GTK_PARAM_READWRITE),
417 g_assert (result == PROP_FALLBACK_ICON_THEME);
419 result = settings_install_property_parser (class,
420 g_param_spec_string ("gtk-key-theme-name",
421 P_("Key Theme Name"),
422 P_("Name of key theme RC file to load"),
424 GTK_PARAM_READWRITE),
426 g_assert (result == PROP_KEY_THEME_NAME);
428 result = settings_install_property_parser (class,
429 g_param_spec_string ("gtk-menu-bar-accel",
430 P_("Menu bar accelerator"),
431 P_("Keybinding to activate the menu bar"),
433 GTK_PARAM_READWRITE),
435 g_assert (result == PROP_MENU_BAR_ACCEL);
437 result = settings_install_property_parser (class,
438 g_param_spec_int ("gtk-dnd-drag-threshold",
439 P_("Drag threshold"),
440 P_("Number of pixels the cursor can move before dragging"),
442 GTK_PARAM_READWRITE),
444 g_assert (result == PROP_DND_DRAG_THRESHOLD);
446 result = settings_install_property_parser (class,
447 g_param_spec_string ("gtk-font-name",
449 P_("Name of default font to use"),
451 GTK_PARAM_READWRITE),
453 g_assert (result == PROP_FONT_NAME);
456 * GtkSettings:gtk-icon-sizes:
458 * A list of icon sizes. The list is separated by colons, and
461 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
463 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
464 * GTK+ itself use the following named icon sizes: gtk-menu,
465 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
466 * gtk-dialog. Applications can register their own named icon
467 * sizes with gtk_icon_size_register().
469 result = settings_install_property_parser (class,
470 g_param_spec_string ("gtk-icon-sizes",
472 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
474 GTK_PARAM_READWRITE),
476 g_assert (result == PROP_ICON_SIZES);
478 result = settings_install_property_parser (class,
479 g_param_spec_string ("gtk-modules",
481 P_("List of currently active GTK modules"),
483 GTK_PARAM_READWRITE),
485 g_assert (result == PROP_MODULES);
487 #ifdef GDK_WINDOWING_X11
488 result = settings_install_property_parser (class,
489 g_param_spec_int ("gtk-xft-antialias",
491 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
493 GTK_PARAM_READWRITE),
496 g_assert (result == PROP_XFT_ANTIALIAS);
498 result = settings_install_property_parser (class,
499 g_param_spec_int ("gtk-xft-hinting",
501 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
503 GTK_PARAM_READWRITE),
506 g_assert (result == PROP_XFT_HINTING);
508 result = settings_install_property_parser (class,
509 g_param_spec_string ("gtk-xft-hintstyle",
510 P_("Xft Hint Style"),
511 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
513 GTK_PARAM_READWRITE),
516 g_assert (result == PROP_XFT_HINTSTYLE);
518 result = settings_install_property_parser (class,
519 g_param_spec_string ("gtk-xft-rgba",
521 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
523 GTK_PARAM_READWRITE),
526 g_assert (result == PROP_XFT_RGBA);
528 result = settings_install_property_parser (class,
529 g_param_spec_int ("gtk-xft-dpi",
531 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
533 GTK_PARAM_READWRITE),
536 g_assert (result == PROP_XFT_DPI);
538 result = settings_install_property_parser (class,
539 g_param_spec_string ("gtk-cursor-theme-name",
540 P_("Cursor theme name"),
541 P_("Name of the cursor theme to use, or NULL to use the default theme"),
543 GTK_PARAM_READWRITE),
545 g_assert (result == PROP_CURSOR_THEME_NAME);
547 result = settings_install_property_parser (class,
548 g_param_spec_int ("gtk-cursor-theme-size",
549 P_("Cursor theme size"),
550 P_("Size to use for cursors, or 0 to use the default size"),
552 GTK_PARAM_READWRITE),
555 g_assert (result == PROP_CURSOR_THEME_SIZE);
557 #endif /* GDK_WINDOWING_X11 */
558 result = settings_install_property_parser (class,
559 g_param_spec_boolean ("gtk-alternative-button-order",
560 P_("Alternative button order"),
561 P_("Whether buttons in dialogs should use the alternative button order"),
563 GTK_PARAM_READWRITE),
565 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
568 * GtkSettings:gtk-alternative-sort-arrows:
570 * Controls the direction of the sort indicators in sorted list and tree
571 * views. By default an arrow pointing down means the column is sorted
572 * in ascending order. When set to %TRUE, this order will be inverted.
576 result = settings_install_property_parser (class,
577 g_param_spec_boolean ("gtk-alternative-sort-arrows",
578 P_("Alternative sort indicator direction"),
579 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
581 GTK_PARAM_READWRITE),
583 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
585 result = settings_install_property_parser (class,
586 g_param_spec_boolean ("gtk-show-input-method-menu",
587 P_("Show the 'Input Methods' menu"),
588 P_("Whether the context menus of entries and text views should offer to change the input method"),
590 GTK_PARAM_READWRITE),
592 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
594 result = settings_install_property_parser (class,
595 g_param_spec_boolean ("gtk-show-unicode-menu",
596 P_("Show the 'Insert Unicode Control Character' menu"),
597 P_("Whether the context menus of entries and text views should offer to insert control characters"),
599 GTK_PARAM_READWRITE),
601 g_assert (result == PROP_SHOW_UNICODE_MENU);
603 result = settings_install_property_parser (class,
604 g_param_spec_int ("gtk-timeout-initial",
606 P_("Starting value for timeouts, when button is pressed"),
607 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
608 GTK_PARAM_READWRITE),
611 g_assert (result == PROP_TIMEOUT_INITIAL);
613 result = settings_install_property_parser (class,
614 g_param_spec_int ("gtk-timeout-repeat",
615 P_("Repeat timeout"),
616 P_("Repeat value for timeouts, when button is pressed"),
617 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
618 GTK_PARAM_READWRITE),
621 g_assert (result == PROP_TIMEOUT_REPEAT);
623 result = settings_install_property_parser (class,
624 g_param_spec_int ("gtk-timeout-expand",
625 P_("Expand timeout"),
626 P_("Expand value for timeouts, when a widget is expanding a new region"),
627 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
628 GTK_PARAM_READWRITE),
631 g_assert (result == PROP_TIMEOUT_EXPAND);
634 * GtkSettings:gtk-color-scheme:
636 * A palette of named colors for use in themes. The format of the string is
642 * Color names must be acceptable as identifiers in the
643 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
644 * color specifications must be in the format accepted by
647 * Note that due to the way the color tables from different sources are
648 * merged, color specifications will be converted to hexadecimal form
649 * when getting this property.
651 * Starting with GTK+ 2.12, the entries can alternatively be separated
652 * by ';' instead of newlines:
654 * name1: color1; name2: color2; ...
659 result = settings_install_property_parser (class,
660 g_param_spec_string ("gtk-color-scheme",
662 P_("A palette of named colors for use in themes"),
664 GTK_PARAM_READWRITE),
667 g_assert (result == PROP_COLOR_SCHEME);
669 result = settings_install_property_parser (class,
670 g_param_spec_boolean ("gtk-enable-animations",
671 P_("Enable Animations"),
672 P_("Whether to enable toolkit-wide animations."),
674 GTK_PARAM_READWRITE),
677 g_assert (result == PROP_ENABLE_ANIMATIONS);
680 * GtkSettings:gtk-touchscreen-mode:
682 * When %TRUE, there are no motion notify events delivered on this screen,
683 * and widgets can't use the pointer hovering them for any essential
688 result = settings_install_property_parser (class,
689 g_param_spec_boolean ("gtk-touchscreen-mode",
690 P_("Enable Touchscreen Mode"),
691 P_("When TRUE, there are no motion notify events delivered on this screen"),
693 GTK_PARAM_READWRITE),
696 g_assert (result == PROP_TOUCHSCREEN_MODE);
699 * GtkSettings:gtk-tooltip-timeout:
701 * Time, in milliseconds, after which a tooltip could appear if the
702 * cursor is hovering on top of a widget.
706 result = settings_install_property_parser (class,
707 g_param_spec_int ("gtk-tooltip-timeout",
708 P_("Tooltip timeout"),
709 P_("Timeout before tooltip is shown"),
712 GTK_PARAM_READWRITE),
715 g_assert (result == PROP_TOOLTIP_TIMEOUT);
718 * GtkSettings:gtk-tooltip-browse-timeout:
720 * Controls the time after which tooltips will appear when
721 * browse mode is enabled, in milliseconds.
723 * Browse mode is enabled when the mouse pointer moves off an object
724 * where a tooltip was currently being displayed. If the mouse pointer
725 * hits another object before the browse mode timeout expires (see
726 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
727 * amount of milliseconds specified by this setting to popup the tooltip
728 * for the new object.
732 result = settings_install_property_parser (class,
733 g_param_spec_int ("gtk-tooltip-browse-timeout",
734 P_("Tooltip browse timeout"),
735 P_("Timeout before tooltip is shown when browse mode is enabled"),
738 GTK_PARAM_READWRITE),
741 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
744 * GtkSettings:gtk-tooltip-browse-mode-timeout:
746 * Amount of time, in milliseconds, after which the browse mode
749 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
754 result = settings_install_property_parser (class,
755 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
756 P_("Tooltip browse mode timeout"),
757 P_("Timeout after which browse mode is disabled"),
760 GTK_PARAM_READWRITE),
763 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
766 * GtkSettings:gtk-keynav-cursor-only:
768 * When %TRUE, keyboard navigation should be able to reach all widgets
769 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
770 * to be present on the used input device.
774 result = settings_install_property_parser (class,
775 g_param_spec_boolean ("gtk-keynav-cursor-only",
776 P_("Keynav Cursor Only"),
777 P_("When TRUE, there are only cursor keys available to navigate widgets"),
779 GTK_PARAM_READWRITE),
782 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
785 * GtkSettings:gtk-keynav-wrap-around:
787 * When %TRUE, some widgets will wrap around when doing keyboard
788 * navigation, such as menus, menubars and notebooks.
792 result = settings_install_property_parser (class,
793 g_param_spec_boolean ("gtk-keynav-wrap-around",
794 P_("Keynav Wrap Around"),
795 P_("Whether to wrap around when keyboard-navigating widgets"),
797 GTK_PARAM_READWRITE),
800 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
803 * GtkSettings:gtk-error-bell:
805 * When %TRUE, keyboard navigation and other input-related errors
806 * will cause a beep. Since the error bell is implemented using
807 * gdk_window_beep(), the windowing system may offer ways to
808 * configure the error bell in many ways, such as flashing the
809 * window or similar visual effects.
813 result = settings_install_property_parser (class,
814 g_param_spec_boolean ("gtk-error-bell",
816 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
818 GTK_PARAM_READWRITE),
821 g_assert (result == PROP_ERROR_BELL);
824 * GtkSettings:color-hash:
826 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
827 * setting, mapping color names to #GdkColor<!-- -->s.
831 result = settings_install_property_parser (class,
832 g_param_spec_boxed ("color-hash",
834 P_("A hash table representation of the color scheme."),
838 g_assert (result == PROP_COLOR_HASH);
840 result = settings_install_property_parser (class,
841 g_param_spec_string ("gtk-file-chooser-backend",
842 P_("Default file chooser backend"),
843 P_("Name of the GtkFileChooser backend to use by default"),
845 GTK_PARAM_READWRITE),
847 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
850 * GtkSettings:gtk-print-backends:
852 * A comma-separated list of print backends to use in the print
853 * dialog. Available print backends depend on the GTK+ installation,
854 * and may include "file", "cups", "lpr" or "papi".
858 result = settings_install_property_parser (class,
859 g_param_spec_string ("gtk-print-backends",
860 P_("Default print backend"),
861 P_("List of the GtkPrintBackend backends to use by default"),
863 GTK_PARAM_READWRITE),
865 g_assert (result == PROP_PRINT_BACKENDS);
868 * GtkSettings:gtk-print-preview-command:
870 * A command to run for displaying the print preview. The command
871 * should contain a %f placeholder, which will get replaced by
872 * the path to the pdf file. The command may also contain a %s
873 * placeholder, which will get replaced by the path to a file
874 * containing the print settings in the format produced by
875 * gtk_print_settings_to_file().
877 * The preview application is responsible for removing the pdf file
878 * and the print settings file when it is done.
882 result = settings_install_property_parser (class,
883 g_param_spec_string ("gtk-print-preview-command",
884 P_("Default command to run when displaying a print preview"),
885 P_("Command to run when displaying a print preview"),
886 GTK_PRINT_PREVIEW_COMMAND,
887 GTK_PARAM_READWRITE),
889 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
892 * GtkSettings:gtk-enable-mnemonics:
894 * Whether labels and menu items should have visible mnemonics which
899 result = settings_install_property_parser (class,
900 g_param_spec_boolean ("gtk-enable-mnemonics",
901 P_("Enable Mnemonics"),
902 P_("Whether labels should have mnemonics"),
904 GTK_PARAM_READWRITE),
906 g_assert (result == PROP_ENABLE_MNEMONICS);
909 * GtkSettings:gtk-enable-accels:
911 * Whether menu items should have visible accelerators which can be
916 result = settings_install_property_parser (class,
917 g_param_spec_boolean ("gtk-enable-accels",
918 P_("Enable Accelerators"),
919 P_("Whether menu items should have accelerators"),
921 GTK_PARAM_READWRITE),
923 g_assert (result == PROP_ENABLE_ACCELS);
926 * GtkSettings:gtk-recent-files-limit:
928 * The number of recently used files that should be displayed by default by
929 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
930 * -1 means every recently used file stored.
934 result = settings_install_property_parser (class,
935 g_param_spec_int ("gtk-recent-files-limit",
936 P_("Recent Files Limit"),
937 P_("Number of recently used files"),
940 GTK_PARAM_READWRITE),
942 g_assert (result == PROP_RECENT_FILES_LIMIT);
945 * GtkSettings:gtk-im-module:
947 * Which IM (input method) module should be used by default. This is the
948 * input method that will be used if the user has not explicitly chosen
949 * another input method from the IM context menu.
951 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
953 result = settings_install_property_parser (class,
954 g_param_spec_string ("gtk-im-module",
955 P_("Default IM module"),
956 P_("Which IM module should be used by default"),
958 GTK_PARAM_READWRITE),
960 g_assert (result == PROP_IM_MODULE);
963 * GtkSettings:gtk-recent-files-max-age:
965 * The maximum age, in days, of the items inside the recently used
966 * resources list. Items older than this setting will be excised
967 * from the list. If set to 0, the list will always be empty; if
968 * set to -1, no item will be removed.
972 result = settings_install_property_parser (class,
973 g_param_spec_int ("gtk-recent-files-max-age",
974 P_("Recent Files Max Age"),
975 P_("Maximum age of recently used files, in days"),
978 GTK_PARAM_READWRITE),
980 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
982 result = settings_install_property_parser (class,
983 g_param_spec_uint ("gtk-fontconfig-timestamp",
984 P_("Fontconfig configuration timestamp"),
985 P_("Timestamp of current fontconfig configuration"),
987 GTK_PARAM_READWRITE),
990 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
993 * GtkSettings:gtk-sound-theme-name:
995 * The XDG sound theme to use for event sounds.
997 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
998 * for more information on event sounds and sound themes.
1000 * GTK+ itself does not support event sounds, you have to use a loadable
1001 * module like the one that comes with libcanberra.
1005 result = settings_install_property_parser (class,
1006 g_param_spec_string ("gtk-sound-theme-name",
1007 P_("Sound Theme Name"),
1008 P_("XDG sound theme name"),
1010 GTK_PARAM_READWRITE),
1012 g_assert (result == PROP_SOUND_THEME_NAME);
1015 * GtkSettings:gtk-enable-input-feedback-sounds:
1017 * Whether to play event sounds as feedback to user input.
1019 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1020 * for more information on event sounds and sound themes.
1022 * GTK+ itself does not support event sounds, you have to use a loadable
1023 * module like the one that comes with libcanberra.
1027 result = settings_install_property_parser (class,
1028 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1029 /* Translators: this means sounds that are played as feedback to user input */
1030 P_("Audible Input Feedback"),
1031 P_("Whether to play event sounds as feedback to user input"),
1033 GTK_PARAM_READWRITE),
1035 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1038 * GtkSettings:gtk-enable-event-sounds:
1040 * Whether to play any event sounds at all.
1042 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1043 * for more information on event sounds and sound themes.
1045 * GTK+ itself does not support event sounds, you have to use a loadable
1046 * module like the one that comes with libcanberra.
1050 result = settings_install_property_parser (class,
1051 g_param_spec_boolean ("gtk-enable-event-sounds",
1052 P_("Enable Event Sounds"),
1053 P_("Whether to play any event sounds at all"),
1055 GTK_PARAM_READWRITE),
1057 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1060 * GtkSettings:gtk-enable-tooltips:
1062 * Whether tooltips should be shown on widgets.
1066 result = settings_install_property_parser (class,
1067 g_param_spec_boolean ("gtk-enable-tooltips",
1068 P_("Enable Tooltips"),
1069 P_("Whether tooltips should be shown on widgets"),
1071 GTK_PARAM_READWRITE),
1073 g_assert (result == PROP_ENABLE_TOOLTIPS);
1076 * GtkSettings:gtk-toolbar-style:
1078 * The size of icons in default toolbars.
1080 result = settings_install_property_parser (class,
1081 g_param_spec_enum ("gtk-toolbar-style",
1082 P_("Toolbar style"),
1083 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1084 GTK_TYPE_TOOLBAR_STYLE,
1086 GTK_PARAM_READWRITE),
1087 gtk_rc_property_parse_enum);
1088 g_assert (result == PROP_TOOLBAR_STYLE);
1091 * GtkSettings:gtk-toolbar-icon-size:
1093 * The size of icons in default toolbars.
1095 result = settings_install_property_parser (class,
1096 g_param_spec_enum ("gtk-toolbar-icon-size",
1097 P_("Toolbar Icon Size"),
1098 P_("The size of icons in default toolbars."),
1100 GTK_ICON_SIZE_LARGE_TOOLBAR,
1101 GTK_PARAM_READWRITE),
1102 gtk_rc_property_parse_enum);
1103 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1106 * GtkSettings:gtk-auto-mnemonics:
1108 * Whether mnemonics should be automatically shown and hidden when the user
1109 * presses the mnemonic activator.
1113 result = settings_install_property_parser (class,
1114 g_param_spec_boolean ("gtk-auto-mnemonics",
1115 P_("Auto Mnemonics"),
1116 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1118 GTK_PARAM_READWRITE),
1120 g_assert (result == PROP_AUTO_MNEMONICS);
1123 * GtkSettings:gtk-application-prefer-dark-theme:
1125 * Whether the application prefers to use a dark theme. If a GTK+ theme
1126 * includes a dark variant, it will be used instead of the configured
1129 * Some applications benefit from minimizing the amount of light pollution that
1130 * interferes with the content. Good candidates for dark themes are photo and
1131 * video editors that make the actual content get all the attention and minimize
1132 * the distraction of the chrome.
1134 * Dark themes should not be used for documents, where large spaces are white/light
1135 * and the dark chrome creates too much contrast (web browser, text editor...).
1139 result = settings_install_property_parser (class,
1140 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1141 P_("Application prefers a dark theme"),
1142 P_("Whether the application prefers to have a dark theme."),
1144 GTK_PARAM_READWRITE),
1146 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1149 * GtkSettings::gtk-button-images:
1151 * Whether images should be shown on buttons
1155 result = settings_install_property_parser (class,
1156 g_param_spec_boolean ("gtk-button-images",
1157 P_("Show button images"),
1158 P_("Whether images should be shown on buttons"),
1160 GTK_PARAM_READWRITE),
1162 g_assert (result == PROP_BUTTON_IMAGES);
1164 result = settings_install_property_parser (class,
1165 g_param_spec_boolean ("gtk-entry-select-on-focus",
1166 P_("Select on focus"),
1167 P_("Whether to select the contents of an entry when it is focused"),
1169 GTK_PARAM_READWRITE),
1171 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1174 * GtkSettings:gtk-entry-password-hint-timeout:
1176 * How long to show the last input character in hidden
1177 * entries. This value is in milliseconds. 0 disables showing the
1178 * last char. 600 is a good value for enabling it.
1182 result = settings_install_property_parser (class,
1183 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1184 P_("Password Hint Timeout"),
1185 P_("How long to show the last input character in hidden entries"),
1188 GTK_PARAM_READWRITE),
1190 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1192 result = settings_install_property_parser (class,
1193 g_param_spec_boolean ("gtk-menu-images",
1194 P_("Show menu images"),
1195 P_("Whether images should be shown in menus"),
1197 GTK_PARAM_READWRITE),
1199 g_assert (result == PROP_MENU_IMAGES);
1201 result = settings_install_property_parser (class,
1202 g_param_spec_int ("gtk-menu-bar-popup-delay",
1203 P_("Delay before drop down menus appear"),
1204 P_("Delay before the submenus of a menu bar appear"),
1207 GTK_PARAM_READWRITE),
1209 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1212 * GtkSettings:gtk-scrolled-window-placement:
1214 * Where the contents of scrolled windows are located with respect to the
1215 * scrollbars, if not overridden by the scrolled window's own placement.
1219 result = settings_install_property_parser (class,
1220 g_param_spec_enum ("gtk-scrolled-window-placement",
1221 P_("Scrolled Window Placement"),
1222 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1223 GTK_TYPE_CORNER_TYPE,
1224 GTK_CORNER_TOP_LEFT,
1225 GTK_PARAM_READWRITE),
1226 gtk_rc_property_parse_enum);
1227 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1229 result = settings_install_property_parser (class,
1230 g_param_spec_boolean ("gtk-can-change-accels",
1231 P_("Can change accelerators"),
1232 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1234 GTK_PARAM_READWRITE),
1236 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1238 result = settings_install_property_parser (class,
1239 g_param_spec_int ("gtk-menu-popup-delay",
1240 P_("Delay before submenus appear"),
1241 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1244 GTK_PARAM_READWRITE),
1246 g_assert (result == PROP_MENU_POPUP_DELAY);
1248 result = settings_install_property_parser (class,
1249 g_param_spec_int ("gtk-menu-popdown-delay",
1250 P_("Delay before hiding a submenu"),
1251 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1254 GTK_PARAM_READWRITE),
1256 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1258 result = settings_install_property_parser (class,
1259 g_param_spec_boolean ("gtk-label-select-on-focus",
1260 P_("Select on focus"),
1261 P_("Whether to select the contents of a selectable label when it is focused"),
1263 GTK_PARAM_READWRITE),
1265 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1267 result = settings_install_property_parser (class,
1268 g_param_spec_string ("gtk-color-palette",
1269 P_("Custom palette"),
1270 P_("Palette to use in the color selector"),
1271 default_color_palette,
1272 GTK_PARAM_READWRITE),
1274 g_assert (result == PROP_COLOR_PALETTE);
1276 result = settings_install_property_parser (class,
1277 g_param_spec_enum ("gtk-im-preedit-style",
1278 P_("IM Preedit style"),
1279 P_("How to draw the input method preedit string"),
1280 GTK_TYPE_IM_PREEDIT_STYLE,
1281 GTK_IM_PREEDIT_CALLBACK,
1282 GTK_PARAM_READWRITE),
1283 gtk_rc_property_parse_enum);
1284 g_assert (result == PROP_IM_PREEDIT_STYLE);
1286 result = settings_install_property_parser (class,
1287 g_param_spec_enum ("gtk-im-status-style",
1288 P_("IM Status style"),
1289 P_("How to draw the input method statusbar"),
1290 GTK_TYPE_IM_STATUS_STYLE,
1291 GTK_IM_STATUS_CALLBACK,
1292 GTK_PARAM_READWRITE),
1293 gtk_rc_property_parse_enum);
1294 g_assert (result == PROP_IM_STATUS_STYLE);
1296 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1299 static GtkStyleProperties *
1300 gtk_settings_get_style (GtkStyleProvider *provider,
1301 GtkWidgetPath *path)
1303 PangoFontDescription *font_desc;
1304 gchar *font_name, *color_scheme;
1305 GtkSettings *settings;
1306 GtkStyleProperties *props;
1310 settings = GTK_SETTINGS (provider);
1311 props = gtk_style_properties_new ();
1313 g_object_get (settings,
1314 "gtk-font-name", &font_name,
1315 "gtk-color-scheme", &color_scheme,
1318 colors = g_strsplit_set (color_scheme, "\n;", -1);
1320 for (i = 0; colors[i]; i++)
1322 GtkSymbolicColor *color;
1330 pos = strchr (colors[i], ':');
1335 /* Set NUL after color name */
1339 /* Find start of color string */
1343 if (!*pos || !gdk_rgba_parse (&col, pos))
1346 color = gtk_symbolic_color_new_literal (&col);
1347 gtk_style_properties_map_color (props, name, color);
1348 gtk_symbolic_color_unref (color);
1351 font_desc = pango_font_description_from_string (font_name);
1353 gtk_style_properties_set (props, 0,
1357 pango_font_description_free (font_desc);
1358 g_strfreev (colors);
1359 g_free (color_scheme);
1366 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1368 iface->get_style = gtk_settings_get_style;
1372 gtk_settings_finalize (GObject *object)
1374 GtkSettings *settings = GTK_SETTINGS (object);
1375 GtkSettingsPrivate *priv = settings->priv;
1378 object_list = g_slist_remove (object_list, settings);
1380 for (i = 0; i < class_n_properties; i++)
1381 g_value_unset (&priv->property_values[i].value);
1382 g_free (priv->property_values);
1384 g_datalist_clear (&priv->queued_settings);
1386 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1390 settings_init_style (GtkSettings *settings)
1392 static GtkCssProvider *css_provider = NULL;
1394 GdkScreen *screen = settings->priv->screen;
1395 GtkCssProvider *default_provider;
1397 /* Add provider for user file */
1398 if (G_UNLIKELY (!css_provider))
1402 css_provider = gtk_css_provider_new ();
1403 css_path = g_build_filename (g_get_user_config_dir (),
1408 if (g_file_test (css_path,
1409 G_FILE_TEST_IS_REGULAR))
1410 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1415 gtk_style_context_add_provider_for_screen (screen,
1416 GTK_STYLE_PROVIDER (css_provider),
1417 GTK_STYLE_PROVIDER_PRIORITY_USER);
1419 default_provider = gtk_css_provider_get_default ();
1420 gtk_style_context_add_provider_for_screen (screen,
1421 GTK_STYLE_PROVIDER (default_provider),
1422 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1424 gtk_style_context_add_provider_for_screen (screen,
1425 GTK_STYLE_PROVIDER (settings),
1426 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1428 settings_update_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 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1452 settings->priv->screen = screen;
1453 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1454 settings, g_object_unref);
1456 settings_init_style (settings);
1457 settings_update_double_click (settings);
1458 #ifdef GDK_WINDOWING_X11
1459 settings_update_cursor_theme (settings);
1460 settings_update_resolution (settings);
1461 settings_update_font_options (settings);
1463 settings_update_color_scheme (settings);
1470 * gtk_settings_get_default:
1472 * Gets the #GtkSettings object for the default GDK screen, creating
1473 * it if necessary. See gtk_settings_get_for_screen().
1475 * Return value: (transfer none): a #GtkSettings object. If there is no default
1476 * screen, then returns %NULL.
1479 gtk_settings_get_default (void)
1481 GdkScreen *screen = gdk_screen_get_default ();
1484 return gtk_settings_get_for_screen (screen);
1490 gtk_settings_set_property (GObject *object,
1492 const GValue *value,
1495 GtkSettings *settings = GTK_SETTINGS (object);
1496 GtkSettingsPrivate *priv = settings->priv;
1498 g_value_copy (value, &priv->property_values[property_id - 1].value);
1499 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1501 if (pspec->param_id == PROP_COLOR_SCHEME)
1502 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1506 gtk_settings_get_property (GObject *object,
1511 GtkSettings *settings = GTK_SETTINGS (object);
1512 GtkSettingsPrivate *priv = settings->priv;
1513 GType value_type = G_VALUE_TYPE (value);
1514 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1516 /* handle internal properties */
1517 switch (property_id)
1519 case PROP_COLOR_HASH:
1520 g_value_set_boxed (value, get_color_hash (settings));
1522 case PROP_COLOR_SCHEME:
1523 g_value_take_string (value, get_color_scheme (settings));
1528 /* For enums and strings, we need to get the value as a string,
1529 * not as an int, since we support using names/nicks as the setting
1532 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1533 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1534 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1535 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1537 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1538 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1539 g_value_copy (&priv->property_values[property_id - 1].value, value);
1541 g_param_value_validate (pspec, value);
1545 GValue val = { 0, };
1547 /* Try to get xsetting as a string and parse it. */
1549 g_value_init (&val, G_TYPE_STRING);
1551 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1552 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1554 g_value_copy (&priv->property_values[property_id - 1].value, value);
1558 GValue tmp_value = { 0, };
1559 GValue gstring_value = { 0, };
1560 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1562 g_value_init (&gstring_value, G_TYPE_GSTRING);
1563 g_value_take_boxed (&gstring_value,
1564 g_string_new (g_value_get_string (&val)));
1566 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1568 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1571 g_value_copy (&tmp_value, value);
1572 g_param_value_validate (pspec, value);
1576 g_value_copy (&priv->property_values[property_id - 1].value, value);
1579 g_value_unset (&gstring_value);
1580 g_value_unset (&tmp_value);
1583 g_value_unset (&val);
1588 gtk_settings_notify (GObject *object,
1591 GtkSettings *settings = GTK_SETTINGS (object);
1592 GtkSettingsPrivate *priv = settings->priv;
1593 guint property_id = pspec->param_id;
1595 if (priv->screen == NULL) /* initialization */
1598 switch (property_id)
1601 settings_update_modules (settings);
1603 case PROP_DOUBLE_CLICK_TIME:
1604 case PROP_DOUBLE_CLICK_DISTANCE:
1605 settings_update_double_click (settings);
1607 case PROP_COLOR_SCHEME:
1608 settings_update_color_scheme (settings);
1609 gtk_style_context_reset_widgets (priv->screen);
1611 case PROP_APPLICATION_PREFER_DARK_THEME:
1612 case PROP_THEME_NAME:
1613 settings_update_theme (settings);
1615 #ifdef GDK_WINDOWING_X11
1617 settings_update_resolution (settings);
1618 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1619 * widgets with gtk_widget_style_set(), and also causes more
1620 * recomputation than necessary.
1622 gtk_style_context_reset_widgets (priv->screen);
1624 case PROP_XFT_ANTIALIAS:
1625 case PROP_XFT_HINTING:
1626 case PROP_XFT_HINTSTYLE:
1628 settings_update_font_options (settings);
1629 gtk_style_context_reset_widgets (priv->screen);
1631 case PROP_FONTCONFIG_TIMESTAMP:
1632 if (settings_update_fontconfig (settings))
1633 gtk_style_context_reset_widgets (priv->screen);
1635 case PROP_CURSOR_THEME_NAME:
1636 case PROP_CURSOR_THEME_SIZE:
1637 settings_update_cursor_theme (settings);
1639 #endif /* GDK_WINDOWING_X11 */
1644 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1645 const GValue *src_value,
1649 gboolean success = FALSE;
1651 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1656 gboolean free_gstring = TRUE;
1658 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1660 gstring = g_value_get_boxed (src_value);
1661 free_gstring = FALSE;
1663 else if (G_VALUE_HOLDS_LONG (src_value))
1665 gstring = g_string_new (NULL);
1666 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1668 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1670 gstring = g_string_new (NULL);
1671 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1673 else if (G_VALUE_HOLDS_STRING (src_value))
1675 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1677 gstring = g_string_new (NULL);
1678 g_string_append_c (gstring, '\"');
1679 g_string_append (gstring, tstr);
1680 g_string_append_c (gstring, '\"');
1685 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1686 gstring = NULL; /* silence compiler */
1689 success = (parser (pspec, gstring, dest_value) &&
1690 !g_param_value_validate (pspec, dest_value));
1693 g_string_free (gstring, TRUE);
1695 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1697 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1699 GString *gstring = g_value_get_boxed (src_value);
1701 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1702 success = !g_param_value_validate (pspec, dest_value);
1705 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1706 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1712 apply_queued_setting (GtkSettings *settings,
1714 GtkSettingsValuePrivate *qvalue)
1716 GtkSettingsPrivate *priv = settings->priv;
1717 GValue tmp_value = { 0, };
1718 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1720 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1721 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1724 if (pspec->param_id == PROP_COLOR_SCHEME)
1725 merge_color_scheme (settings, &tmp_value, qvalue->source);
1727 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1729 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1730 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1731 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1737 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1739 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1740 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1742 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1744 G_VALUE_TYPE_NAME (&tmp_value));
1747 g_value_unset (&tmp_value);
1751 settings_install_property_parser (GtkSettingsClass *class,
1753 GtkRcPropertyParser parser)
1755 GSList *node, *next;
1757 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1759 case G_TYPE_BOOLEAN:
1772 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1780 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1781 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1785 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1787 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1792 for (node = object_list; node; node = node->next)
1793 g_object_freeze_notify (node->data);
1795 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1796 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1798 for (node = object_list; node; node = node->next)
1800 GtkSettings *settings = node->data;
1801 GtkSettingsPrivate *priv = settings->priv;
1802 GtkSettingsValuePrivate *qvalue;
1804 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1805 priv->property_values[class_n_properties - 1].value.g_type = 0;
1806 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1807 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1808 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1809 g_object_notify (G_OBJECT (settings), pspec->name);
1811 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1813 apply_queued_setting (settings, pspec, qvalue);
1816 for (node = object_list; node; node = next)
1819 g_object_thaw_notify (node->data);
1822 return class_n_properties;
1826 _gtk_rc_property_parser_from_type (GType type)
1828 if (type == GDK_TYPE_COLOR)
1829 return gtk_rc_property_parse_color;
1830 else if (type == GTK_TYPE_REQUISITION)
1831 return gtk_rc_property_parse_requisition;
1832 else if (type == GTK_TYPE_BORDER)
1833 return gtk_rc_property_parse_border;
1834 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1835 return gtk_rc_property_parse_enum;
1836 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1837 return gtk_rc_property_parse_flags;
1843 gtk_settings_install_property (GParamSpec *pspec)
1845 static GtkSettingsClass *klass = NULL;
1847 GtkRcPropertyParser parser;
1849 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1852 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1854 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1856 settings_install_property_parser (klass, pspec, parser);
1860 * gtk_settings_install_property_parser:
1862 * @parser: (scope call):
1865 gtk_settings_install_property_parser (GParamSpec *pspec,
1866 GtkRcPropertyParser parser)
1868 static GtkSettingsClass *klass = NULL;
1870 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1871 g_return_if_fail (parser != NULL);
1874 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1876 settings_install_property_parser (klass, pspec, parser);
1880 free_value (gpointer data)
1882 GtkSettingsValuePrivate *qvalue = data;
1884 g_value_unset (&qvalue->public.value);
1885 g_free (qvalue->public.origin);
1886 g_slice_free (GtkSettingsValuePrivate, qvalue);
1890 gtk_settings_set_property_value_internal (GtkSettings *settings,
1891 const gchar *prop_name,
1892 const GtkSettingsValue *new_value,
1893 GtkSettingsSource source)
1895 GtkSettingsPrivate *priv = settings->priv;
1896 GtkSettingsValuePrivate *qvalue;
1901 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1902 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1903 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1904 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1906 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
1910 name = g_strdup (prop_name);
1911 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1912 name_quark = g_quark_from_string (name);
1915 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
1918 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1919 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
1923 g_free (qvalue->public.origin);
1924 g_value_unset (&qvalue->public.value);
1926 qvalue->public.origin = g_strdup (new_value->origin);
1927 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1928 g_value_copy (&new_value->value, &qvalue->public.value);
1929 qvalue->source = source;
1930 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1932 apply_queued_setting (settings, pspec, qvalue);
1936 gtk_settings_set_property_value (GtkSettings *settings,
1937 const gchar *prop_name,
1938 const GtkSettingsValue *new_value)
1940 g_return_if_fail (GTK_SETTINGS (settings));
1941 g_return_if_fail (prop_name != NULL);
1942 g_return_if_fail (new_value != NULL);
1944 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1945 GTK_SETTINGS_SOURCE_APPLICATION);
1949 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1950 const gchar *prop_name,
1951 const GtkSettingsValue *new_value)
1953 g_return_if_fail (GTK_SETTINGS (settings));
1954 g_return_if_fail (prop_name != NULL);
1955 g_return_if_fail (new_value != NULL);
1957 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1958 GTK_SETTINGS_SOURCE_THEME);
1962 gtk_settings_set_string_property (GtkSettings *settings,
1964 const gchar *v_string,
1965 const gchar *origin)
1967 GtkSettingsValue svalue = { NULL, { 0, }, };
1969 g_return_if_fail (GTK_SETTINGS (settings));
1970 g_return_if_fail (name != NULL);
1971 g_return_if_fail (v_string != NULL);
1973 svalue.origin = (gchar*) origin;
1974 g_value_init (&svalue.value, G_TYPE_STRING);
1975 g_value_set_static_string (&svalue.value, v_string);
1976 gtk_settings_set_property_value (settings, name, &svalue);
1977 g_value_unset (&svalue.value);
1981 gtk_settings_set_long_property (GtkSettings *settings,
1984 const gchar *origin)
1986 GtkSettingsValue svalue = { NULL, { 0, }, };
1988 g_return_if_fail (GTK_SETTINGS (settings));
1989 g_return_if_fail (name != NULL);
1991 svalue.origin = (gchar*) origin;
1992 g_value_init (&svalue.value, G_TYPE_LONG);
1993 g_value_set_long (&svalue.value, v_long);
1994 gtk_settings_set_property_value (settings, name, &svalue);
1995 g_value_unset (&svalue.value);
1999 gtk_settings_set_double_property (GtkSettings *settings,
2002 const gchar *origin)
2004 GtkSettingsValue svalue = { NULL, { 0, }, };
2006 g_return_if_fail (GTK_SETTINGS (settings));
2007 g_return_if_fail (name != NULL);
2009 svalue.origin = (gchar*) origin;
2010 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2011 g_value_set_double (&svalue.value, v_double);
2012 gtk_settings_set_property_value (settings, name, &svalue);
2013 g_value_unset (&svalue.value);
2017 * gtk_rc_property_parse_color:
2018 * @pspec: a #GParamSpec
2019 * @gstring: the #GString to be parsed
2020 * @property_value: a #GValue which must hold #GdkColor values.
2022 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2023 * or gtk_widget_class_install_style_property_parser() which parses a
2024 * color given either by its name or in the form
2025 * <literal>{ red, green, blue }</literal> where %red, %green and
2026 * %blue are integers between 0 and 65535 or floating-point numbers
2029 * Return value: %TRUE if @gstring could be parsed and @property_value
2030 * has been set to the resulting #GdkColor.
2033 gtk_rc_property_parse_color (const GParamSpec *pspec,
2034 const GString *gstring,
2035 GValue *property_value)
2037 GdkColor color = { 0, 0, 0, 0, };
2041 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2042 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2044 scanner = gtk_rc_scanner_new ();
2045 g_scanner_input_text (scanner, gstring->str, gstring->len);
2046 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2047 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2049 g_value_set_boxed (property_value, &color);
2054 g_scanner_destroy (scanner);
2060 * gtk_rc_property_parse_enum:
2061 * @pspec: a #GParamSpec
2062 * @gstring: the #GString to be parsed
2063 * @property_value: a #GValue which must hold enum values.
2065 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2066 * or gtk_widget_class_install_style_property_parser() which parses a single
2067 * enumeration value.
2069 * The enumeration value can be specified by its name, its nickname or
2070 * its numeric value. For consistency with flags parsing, the value
2071 * may be surrounded by parentheses.
2073 * Return value: %TRUE if @gstring could be parsed and @property_value
2074 * has been set to the resulting #GEnumValue.
2077 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2078 const GString *gstring,
2079 GValue *property_value)
2081 gboolean need_closing_brace = FALSE, success = FALSE;
2083 GEnumValue *enum_value = NULL;
2085 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2086 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2088 scanner = gtk_rc_scanner_new ();
2089 g_scanner_input_text (scanner, gstring->str, gstring->len);
2091 /* we just want to parse _one_ value, but for consistency with flags parsing
2092 * we support optional parenthesis
2094 g_scanner_get_next_token (scanner);
2095 if (scanner->token == '(')
2097 need_closing_brace = TRUE;
2098 g_scanner_get_next_token (scanner);
2100 if (scanner->token == G_TOKEN_IDENTIFIER)
2102 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2104 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2106 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2109 g_value_set_enum (property_value, enum_value->value);
2113 else if (scanner->token == G_TOKEN_INT)
2115 g_value_set_enum (property_value, scanner->value.v_int);
2118 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2120 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2123 g_scanner_destroy (scanner);
2129 parse_flags_value (GScanner *scanner,
2133 g_scanner_get_next_token (scanner);
2134 if (scanner->token == G_TOKEN_IDENTIFIER)
2136 GFlagsValue *flags_value;
2138 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2140 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2143 *number |= flags_value->value;
2144 return G_TOKEN_NONE;
2147 else if (scanner->token == G_TOKEN_INT)
2149 *number |= scanner->value.v_int;
2150 return G_TOKEN_NONE;
2152 return G_TOKEN_IDENTIFIER;
2156 * gtk_rc_property_parse_flags:
2157 * @pspec: a #GParamSpec
2158 * @gstring: the #GString to be parsed
2159 * @property_value: a #GValue which must hold flags values.
2161 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2162 * or gtk_widget_class_install_style_property_parser() which parses flags.
2164 * Flags can be specified by their name, their nickname or
2165 * numerically. Multiple flags can be specified in the form
2166 * <literal>"( flag1 | flag2 | ... )"</literal>.
2168 * Return value: %TRUE if @gstring could be parsed and @property_value
2169 * has been set to the resulting flags value.
2172 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2173 const GString *gstring,
2174 GValue *property_value)
2177 gboolean success = FALSE;
2180 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2181 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2183 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2184 scanner = gtk_rc_scanner_new ();
2185 g_scanner_input_text (scanner, gstring->str, gstring->len);
2187 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2188 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2189 scanner->next_token == G_TOKEN_INT)
2191 guint token, flags_value = 0;
2193 token = parse_flags_value (scanner, class, &flags_value);
2195 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2198 g_value_set_flags (property_value, flags_value);
2202 else if (g_scanner_get_next_token (scanner) == '(')
2204 guint token, flags_value = 0;
2206 /* parse first value */
2207 token = parse_flags_value (scanner, class, &flags_value);
2209 /* parse nth values, preceeded by '|' */
2210 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2211 token = parse_flags_value (scanner, class, &flags_value);
2213 /* done, last token must have closed expression */
2214 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2215 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2217 g_value_set_flags (property_value, flags_value);
2221 g_scanner_destroy (scanner);
2227 get_braced_int (GScanner *scanner,
2234 g_scanner_get_next_token (scanner);
2235 if (scanner->token != '{')
2239 g_scanner_get_next_token (scanner);
2240 if (scanner->token != G_TOKEN_INT)
2243 *value = scanner->value.v_int;
2247 g_scanner_get_next_token (scanner);
2248 if (scanner->token != '}')
2253 g_scanner_get_next_token (scanner);
2254 if (scanner->token != ',')
2262 * gtk_rc_property_parse_requisition:
2263 * @pspec: a #GParamSpec
2264 * @gstring: the #GString to be parsed
2265 * @property_value: a #GValue which must hold boxed values.
2267 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2268 * or gtk_widget_class_install_style_property_parser() which parses a
2269 * requisition in the form
2270 * <literal>"{ width, height }"</literal> for integers %width and %height.
2272 * Return value: %TRUE if @gstring could be parsed and @property_value
2273 * has been set to the resulting #GtkRequisition.
2276 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2277 const GString *gstring,
2278 GValue *property_value)
2280 GtkRequisition requisition;
2282 gboolean success = FALSE;
2284 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2285 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2287 scanner = gtk_rc_scanner_new ();
2288 g_scanner_input_text (scanner, gstring->str, gstring->len);
2290 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2291 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2293 g_value_set_boxed (property_value, &requisition);
2297 g_scanner_destroy (scanner);
2303 * gtk_rc_property_parse_border:
2304 * @pspec: a #GParamSpec
2305 * @gstring: the #GString to be parsed
2306 * @property_value: a #GValue which must hold boxed values.
2308 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2309 * or gtk_widget_class_install_style_property_parser() which parses
2310 * borders in the form
2311 * <literal>"{ left, right, top, bottom }"</literal> for integers
2312 * %left, %right, %top and %bottom.
2314 * Return value: %TRUE if @gstring could be parsed and @property_value
2315 * has been set to the resulting #GtkBorder.
2318 gtk_rc_property_parse_border (const GParamSpec *pspec,
2319 const GString *gstring,
2320 GValue *property_value)
2324 gboolean success = FALSE;
2325 int left, right, top, bottom;
2327 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2328 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2330 scanner = gtk_rc_scanner_new ();
2331 g_scanner_input_text (scanner, gstring->str, gstring->len);
2333 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2334 get_braced_int (scanner, FALSE, FALSE, &right) &&
2335 get_braced_int (scanner, FALSE, FALSE, &top) &&
2336 get_braced_int (scanner, FALSE, TRUE, &bottom))
2339 border.right = right;
2341 border.bottom = bottom;
2342 g_value_set_boxed (property_value, &border);
2346 g_scanner_destroy (scanner);
2352 _gtk_settings_handle_event (GdkEventSetting *event)
2355 GtkSettings *settings;
2359 screen = gdk_window_get_screen (event->window);
2360 settings = gtk_settings_get_for_screen (screen);
2361 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2365 property_id = pspec->param_id;
2367 if (property_id == PROP_COLOR_SCHEME)
2369 GValue value = { 0, };
2371 g_value_init (&value, G_TYPE_STRING);
2372 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2373 g_value_set_static_string (&value, "");
2374 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2375 g_value_unset (&value);
2377 g_object_notify (G_OBJECT (settings), pspec->name);
2382 reset_rc_values_foreach (GQuark key_id,
2386 GtkSettingsValuePrivate *qvalue = data;
2387 GSList **to_reset = user_data;
2389 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2390 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2394 _gtk_settings_reset_rc_values (GtkSettings *settings)
2396 GtkSettingsPrivate *priv = settings->priv;
2397 GSList *to_reset = NULL;
2399 GParamSpec **pspecs, **p;
2402 /* Remove any queued settings */
2403 g_datalist_foreach (&priv->queued_settings,
2404 reset_rc_values_foreach,
2407 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2409 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2410 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2413 g_slist_free (to_reset);
2415 /* Now reset the active settings
2417 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2420 g_object_freeze_notify (G_OBJECT (settings));
2421 for (p = pspecs; *p; p++)
2423 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2425 GParamSpec *pspec = *p;
2427 g_param_value_set_default (pspec, &priv->property_values[i].value);
2428 g_object_notify (G_OBJECT (settings), pspec->name);
2432 g_object_thaw_notify (G_OBJECT (settings));
2437 settings_update_double_click (GtkSettings *settings)
2439 GtkSettingsPrivate *priv = settings->priv;
2441 if (gdk_screen_get_number (priv->screen) == 0)
2443 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2444 gint double_click_time;
2445 gint double_click_distance;
2447 g_object_get (settings,
2448 "gtk-double-click-time", &double_click_time,
2449 "gtk-double-click-distance", &double_click_distance,
2452 gdk_display_set_double_click_time (display, double_click_time);
2453 gdk_display_set_double_click_distance (display, double_click_distance);
2458 settings_update_modules (GtkSettings *settings)
2462 g_object_get (settings,
2463 "gtk-modules", &modules,
2466 _gtk_modules_settings_changed (settings, modules);
2471 #ifdef GDK_WINDOWING_X11
2473 settings_update_cursor_theme (GtkSettings *settings)
2475 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2476 gchar *theme = NULL;
2479 g_object_get (settings,
2480 "gtk-cursor-theme-name", &theme,
2481 "gtk-cursor-theme-size", &size,
2484 gdk_x11_display_set_cursor_theme (display, theme, size);
2490 settings_update_font_options (GtkSettings *settings)
2492 GtkSettingsPrivate *priv = settings->priv;
2494 gchar *hint_style_str;
2495 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2497 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2499 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2500 cairo_font_options_t *options;
2502 g_object_get (settings,
2503 "gtk-xft-antialias", &antialias,
2504 "gtk-xft-hinting", &hinting,
2505 "gtk-xft-hintstyle", &hint_style_str,
2506 "gtk-xft-rgba", &rgba_str,
2509 options = cairo_font_options_create ();
2511 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2513 if (hinting >= 0 && !hinting)
2515 hint_style = CAIRO_HINT_STYLE_NONE;
2517 else if (hint_style_str)
2519 if (strcmp (hint_style_str, "hintnone") == 0)
2520 hint_style = CAIRO_HINT_STYLE_NONE;
2521 else if (strcmp (hint_style_str, "hintslight") == 0)
2522 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2523 else if (strcmp (hint_style_str, "hintmedium") == 0)
2524 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2525 else if (strcmp (hint_style_str, "hintfull") == 0)
2526 hint_style = CAIRO_HINT_STYLE_FULL;
2529 g_free (hint_style_str);
2531 cairo_font_options_set_hint_style (options, hint_style);
2535 if (strcmp (rgba_str, "rgb") == 0)
2536 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2537 else if (strcmp (rgba_str, "bgr") == 0)
2538 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2539 else if (strcmp (rgba_str, "vrgb") == 0)
2540 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2541 else if (strcmp (rgba_str, "vbgr") == 0)
2542 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2547 cairo_font_options_set_subpixel_order (options, subpixel_order);
2549 if (antialias >= 0 && !antialias)
2550 antialias_mode = CAIRO_ANTIALIAS_NONE;
2551 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2552 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2553 else if (antialias >= 0)
2554 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2556 cairo_font_options_set_antialias (options, antialias_mode);
2558 gdk_screen_set_font_options (priv->screen, options);
2560 cairo_font_options_destroy (options);
2563 #ifdef GDK_WINDOWING_X11
2565 settings_update_fontconfig (GtkSettings *settings)
2567 static guint last_update_timestamp;
2568 static gboolean last_update_needed;
2572 g_object_get (settings,
2573 "gtk-fontconfig-timestamp", ×tamp,
2576 /* if timestamp is the same as last_update_timestamp, we already have
2577 * updated fontconig on this timestamp (another screen requested it perhaps?),
2578 * just return the cached result.*/
2580 if (timestamp != last_update_timestamp)
2582 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2583 gboolean update_needed = FALSE;
2586 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2588 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2589 if (FcInitReinitialize ())
2590 update_needed = TRUE;
2593 last_update_timestamp = timestamp;
2594 last_update_needed = update_needed;
2597 return last_update_needed;
2599 #endif /* GDK_WINDOWING_X11 */
2602 settings_update_resolution (GtkSettings *settings)
2604 GtkSettingsPrivate *priv = settings->priv;
2608 g_object_get (settings,
2609 "gtk-xft-dpi", &dpi_int,
2613 dpi = dpi_int / 1024.;
2617 gdk_screen_set_resolution (priv->screen, dpi);
2623 GHashTable *color_hash;
2624 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2625 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2629 color_scheme_data_free (ColorSchemeData *data)
2633 g_hash_table_unref (data->color_hash);
2635 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2637 if (data->tables[i])
2638 g_hash_table_unref (data->tables[i]);
2639 g_free (data->lastentry[i]);
2642 g_slice_free (ColorSchemeData, data);
2646 settings_update_color_scheme (GtkSettings *settings)
2648 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2650 GtkSettingsPrivate *priv = settings->priv;
2651 ColorSchemeData *data;
2652 GValue value = { 0, };
2654 data = g_slice_new0 (ColorSchemeData);
2655 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2656 (GDestroyNotify) gdk_color_free);
2657 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2658 data, (GDestroyNotify) color_scheme_data_free);
2660 g_value_init (&value, G_TYPE_STRING);
2661 if (gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2663 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2664 g_value_unset (&value);
2670 settings_update_theme (GtkSettings *settings)
2672 static GQuark quark_theme_name = 0;
2674 GtkSettingsPrivate *priv = settings->priv;
2675 GtkCssProvider *provider;
2676 GtkCssProvider *new_provider;
2677 gboolean prefer_dark_theme;
2680 if (G_UNLIKELY (!quark_theme_name))
2681 quark_theme_name = g_quark_from_static_string ("gtk-settings-theme-name");
2683 provider = g_object_get_qdata (G_OBJECT (settings), quark_theme_name);
2685 g_object_get (settings,
2686 "gtk-theme-name", &theme_name,
2687 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2690 new_provider = NULL;
2692 if (theme_name && *theme_name)
2694 if (prefer_dark_theme)
2695 new_provider = gtk_css_provider_get_named (theme_name, "dark");
2698 new_provider = gtk_css_provider_get_named (theme_name, NULL);
2701 if (new_provider != provider)
2704 gtk_style_context_remove_provider_for_screen (priv->screen,
2705 GTK_STYLE_PROVIDER (provider));
2709 gtk_style_context_add_provider_for_screen (priv->screen,
2710 GTK_STYLE_PROVIDER (new_provider),
2711 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2712 g_object_ref (new_provider);
2715 g_object_set_qdata_full (G_OBJECT (settings), quark_theme_name,
2716 new_provider, (GDestroyNotify) g_object_unref);
2719 if (theme_name && *theme_name)
2724 /* reload per-theme settings */
2725 theme_dir = _gtk_css_provider_get_theme_dir ();
2726 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2728 if (g_file_test (path, G_FILE_TEST_EXISTS))
2729 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2735 g_free (theme_name);
2739 add_color_to_hash (gchar *name,
2745 old = g_hash_table_lookup (target, name);
2746 if (!old || !gdk_color_equal (old, color))
2748 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2757 add_colors_to_hash_from_string (GHashTable *hash,
2758 const gchar *colors)
2760 gchar *s, *p, *name;
2762 gboolean changed = FALSE;
2765 copy = g_strdup (colors);
2770 p = strchr (s, ':');
2785 if (*s == '\n' || *s == ';')
2794 if (gdk_color_parse (p, &color))
2795 changed |= add_color_to_hash (name, &color, hash);
2804 update_color_hash (ColorSchemeData *data,
2806 GtkSettingsSource source)
2808 gboolean changed = FALSE;
2810 GHashTable *old_hash;
2811 GHashTableIter iter;
2815 if ((str == NULL || *str == '\0') &&
2816 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2819 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2822 /* For the THEME source we merge the values rather than over-writing
2823 * them, since multiple rc files might define independent sets of colors
2825 if ((source != GTK_SETTINGS_SOURCE_THEME) &&
2826 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2828 g_hash_table_unref (data->tables[source]);
2829 data->tables[source] = NULL;
2830 changed = TRUE; /* We can't rely on the code below since str might be "" */
2833 if (data->tables[source] == NULL)
2834 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2836 (GDestroyNotify) gdk_color_free);
2838 g_free (data->lastentry[source]);
2839 data->lastentry[source] = g_strdup (str);
2841 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2846 /* Rebuild the merged hash table. */
2847 if (data->color_hash)
2849 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2850 (GDestroyNotify) gdk_color_free);
2852 g_hash_table_iter_init (&iter, data->color_hash);
2853 while (g_hash_table_iter_next (&iter, &name, &color))
2855 g_hash_table_insert (old_hash, name, color);
2856 g_hash_table_iter_steal (&iter);
2864 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2866 if (data->tables[i])
2867 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2873 /* now check if the merged hash has changed */
2875 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2879 GHashTableIter iter;
2880 gpointer key, value, new_value;
2882 g_hash_table_iter_init (&iter, old_hash);
2883 while (g_hash_table_iter_next (&iter, &key, &value))
2885 new_value = g_hash_table_lookup (data->color_hash, key);
2886 if (!new_value || !gdk_color_equal (value, new_value))
2894 g_hash_table_unref (old_hash);
2903 merge_color_scheme (GtkSettings *settings,
2904 const GValue *value,
2905 GtkSettingsSource source)
2907 ColorSchemeData *data;
2908 const gchar *colors;
2910 g_object_freeze_notify (G_OBJECT (settings));
2912 colors = g_value_get_string (value);
2914 settings_update_color_scheme (settings);
2916 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2917 "gtk-color-scheme");
2919 if (update_color_hash (data, colors, source))
2920 g_object_notify (G_OBJECT (settings), "color-hash");
2922 g_object_thaw_notify (G_OBJECT (settings));
2926 get_color_hash (GtkSettings *settings)
2928 ColorSchemeData *data;
2930 settings_update_color_scheme (settings);
2932 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2933 "gtk-color-scheme");
2935 return data->color_hash;
2939 append_color_scheme (gpointer key,
2943 gchar *name = (gchar *)key;
2944 GdkColor *color = (GdkColor *)value;
2945 GString *string = (GString *)data;
2947 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2948 name, color->red, color->green, color->blue);
2952 get_color_scheme (GtkSettings *settings)
2954 ColorSchemeData *data;
2957 settings_update_color_scheme (settings);
2959 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2960 "gtk-color-scheme");
2962 string = g_string_new ("");
2964 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2966 return g_string_free (string, FALSE);
2970 _gtk_settings_get_screen (GtkSettings *settings)
2972 return settings->priv->screen;
2977 gtk_settings_load_from_key_file (GtkSettings *settings,
2979 GtkSettingsSource source)
2990 keyfile = g_key_file_new ();
2992 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
2994 g_warning ("Failed to parse %s: %s", path, error->message);
2996 g_error_free (error);
3001 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3004 g_warning ("Failed to parse %s: %s", path, error->message);
3005 g_error_free (error);
3009 for (i = 0; i < n_keys; i++)
3014 GtkSettingsValue svalue = { NULL, { 0, }, };
3017 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3020 g_warning ("Unknown key %s in %s", key, path);
3024 if (pspec->owner_type != G_OBJECT_TYPE (settings))
3027 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3030 case G_TYPE_BOOLEAN:
3034 g_value_init (&svalue.value, G_TYPE_LONG);
3035 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3037 g_value_set_long (&svalue.value, b_val);
3045 g_value_init (&svalue.value, G_TYPE_LONG);
3046 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3048 g_value_set_long (&svalue.value, i_val);
3056 g_value_init (&svalue.value, G_TYPE_DOUBLE);
3057 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3059 g_value_set_double (&svalue.value, d_val);
3067 g_value_init (&svalue.value, G_TYPE_GSTRING);
3068 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3070 g_value_set_boxed (&svalue.value, g_string_new (s_val));
3077 g_warning ("Error setting %s in %s: %s", key, path, error->message);
3078 g_error_free (error);
3083 if (g_getenv ("GTK_DEBUG"))
3084 svalue.origin = (gchar *)path;
3085 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3086 g_value_unset (&svalue.value);
3092 g_key_file_free (keyfile);