1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
26 #include "gtkmodules.h"
27 #include "gtksettingsprivate.h"
30 #include "gtkwidget.h"
31 #include "gtkprivate.h"
32 #include "gtkcssproviderprivate.h"
33 #include "gtksymboliccolor.h"
34 #include "gtktypebuiltins.h"
35 #include "gtkversion.h"
37 #ifdef GDK_WINDOWING_X11
39 #include <pango/pangofc-fontmap.h>
45 * @Short_description: Sharing settings between applications
48 * GtkSettings provide a mechanism to share global settings between
51 * On the X window system, this sharing is realized by an
52 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
53 * manager that is usually part of the desktop environment, along with
54 * utilities that let the user change these settings. In the absence of
55 * an Xsettings manager, GTK+ reads default values for settings from
56 * <filename>settings.ini</filename> files in
57 * <filename>/etc/gtk-3.0</filename> and <filename>$XDG_CONFIG_HOME/gtk-3.0</filename>. These files must be valid key files (see #GKeyFile), and have
58 * a section called Settings. Themes can also provide default values
59 * for settings by installing a <filename>settings.ini</filename> file
60 * next to their <filename>gtk.css</filename> file.
62 * Applications can override system-wide settings with
63 * gtk_settings_set_string_property(), gtk_settings_set_long_property(),
64 * etc. This should be restricted to special cases though; GtkSettings are
65 * not meant as an application configuration facility. When doing so, you
66 * need to be aware that settings that are specific to individual widgets
67 * may not be available before the widget type has been realized at least
68 * once. The following example demonstrates a way to do this:
69 * <informalexample><programlisting>
70 * gtk_init (&argc, &argv);
72 * /* make sure the type is realized */
73 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
75 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
76 * </programlisting></informalexample>
78 * There is one GtkSettings instance per screen. It can be obtained with
79 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
80 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
81 * GtkSettings instance for the default screen.
85 #define DEFAULT_TIMEOUT_INITIAL 200
86 #define DEFAULT_TIMEOUT_REPEAT 20
87 #define DEFAULT_TIMEOUT_EXPAND 500
89 typedef struct _GtkSettingsPropertyValue GtkSettingsPropertyValue;
90 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
92 struct _GtkSettingsPrivate
94 GData *queued_settings; /* of type GtkSettingsValue* */
95 GtkSettingsPropertyValue *property_values;
97 GtkCssProvider *theme_provider;
98 GtkCssProvider *key_theme_provider;
103 GTK_SETTINGS_SOURCE_DEFAULT,
104 GTK_SETTINGS_SOURCE_THEME,
105 GTK_SETTINGS_SOURCE_XSETTING,
106 GTK_SETTINGS_SOURCE_APPLICATION
109 struct _GtkSettingsValuePrivate
111 GtkSettingsValue public;
112 GtkSettingsSource source;
115 struct _GtkSettingsPropertyValue
118 GtkSettingsSource source;
123 PROP_DOUBLE_CLICK_TIME,
124 PROP_DOUBLE_CLICK_DISTANCE,
126 PROP_CURSOR_BLINK_TIME,
127 PROP_CURSOR_BLINK_TIMEOUT,
130 PROP_ICON_THEME_NAME,
131 PROP_FALLBACK_ICON_THEME,
134 PROP_DND_DRAG_THRESHOLD,
143 PROP_CURSOR_THEME_NAME,
144 PROP_CURSOR_THEME_SIZE,
145 PROP_ALTERNATIVE_BUTTON_ORDER,
146 PROP_ALTERNATIVE_SORT_ARROWS,
147 PROP_SHOW_INPUT_METHOD_MENU,
148 PROP_SHOW_UNICODE_MENU,
149 PROP_TIMEOUT_INITIAL,
153 PROP_ENABLE_ANIMATIONS,
154 PROP_TOUCHSCREEN_MODE,
155 PROP_TOOLTIP_TIMEOUT,
156 PROP_TOOLTIP_BROWSE_TIMEOUT,
157 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
158 PROP_KEYNAV_CURSOR_ONLY,
159 PROP_KEYNAV_WRAP_AROUND,
162 PROP_FILE_CHOOSER_BACKEND,
164 PROP_PRINT_PREVIEW_COMMAND,
165 PROP_ENABLE_MNEMONICS,
167 PROP_RECENT_FILES_LIMIT,
169 PROP_RECENT_FILES_MAX_AGE,
170 PROP_FONTCONFIG_TIMESTAMP,
171 PROP_SOUND_THEME_NAME,
172 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
173 PROP_ENABLE_EVENT_SOUNDS,
174 PROP_ENABLE_TOOLTIPS,
176 PROP_TOOLBAR_ICON_SIZE,
178 PROP_APPLICATION_PREFER_DARK_THEME,
180 PROP_ENTRY_SELECT_ON_FOCUS,
181 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
183 PROP_MENU_BAR_POPUP_DELAY,
184 PROP_SCROLLED_WINDOW_PLACEMENT,
185 PROP_CAN_CHANGE_ACCELS,
186 PROP_MENU_POPUP_DELAY,
187 PROP_MENU_POPDOWN_DELAY,
188 PROP_LABEL_SELECT_ON_FOCUS,
190 PROP_IM_PREEDIT_STYLE,
194 /* --- prototypes --- */
195 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
197 static void gtk_settings_finalize (GObject *object);
198 static void gtk_settings_get_property (GObject *object,
202 static void gtk_settings_set_property (GObject *object,
206 static void gtk_settings_notify (GObject *object,
208 static guint settings_install_property_parser (GtkSettingsClass *class,
210 GtkRcPropertyParser parser);
211 static void settings_update_double_click (GtkSettings *settings);
212 static void settings_update_modules (GtkSettings *settings);
214 static void settings_update_cursor_theme (GtkSettings *settings);
215 static void settings_update_resolution (GtkSettings *settings);
216 static void settings_update_font_options (GtkSettings *settings);
217 static gboolean settings_update_fontconfig (GtkSettings *settings);
218 static void settings_update_color_scheme (GtkSettings *settings);
219 static void settings_update_theme (GtkSettings *settings);
220 static void settings_update_key_theme (GtkSettings *settings);
222 static void merge_color_scheme (GtkSettings *settings,
224 GtkSettingsSource source);
225 static gchar *get_color_scheme (GtkSettings *settings);
226 static GHashTable *get_color_hash (GtkSettings *settings);
227 static void gtk_settings_load_from_key_file (GtkSettings *settings,
229 GtkSettingsSource source);
231 /* the default palette for GtkColorSelelection */
232 static const gchar default_color_palette[] =
233 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
234 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
236 /* --- variables --- */
237 static GQuark quark_property_parser = 0;
238 static GSList *object_list = NULL;
239 static guint class_n_properties = 0;
242 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
243 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
244 gtk_settings_provider_iface_init));
246 /* --- functions --- */
248 gtk_settings_init (GtkSettings *settings)
250 GtkSettingsPrivate *priv;
251 GParamSpec **pspecs, **p;
255 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
259 settings->priv = priv;
260 g_datalist_init (&priv->queued_settings);
261 object_list = g_slist_prepend (object_list, settings);
263 /* build up property array for all yet existing properties and queue
264 * notification for them (at least notification for internal properties
265 * will instantly be caught)
267 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
268 for (p = pspecs; *p; p++)
269 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
271 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
273 g_object_freeze_notify (G_OBJECT (settings));
275 for (p = pspecs; *p; p++)
277 GParamSpec *pspec = *p;
278 GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
280 if (pspec->owner_type != G_OBJECT_TYPE (settings))
282 g_value_init (&priv->property_values[i].value, value_type);
283 g_param_value_set_default (pspec, &priv->property_values[i].value);
285 g_object_notify (G_OBJECT (settings), pspec->name);
286 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
291 path = g_build_filename (GTK_SYSCONFDIR, "gtk-3.0", "settings.ini", NULL);
292 if (g_file_test (path, G_FILE_TEST_EXISTS))
293 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
296 path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "settings.ini", NULL);
297 if (g_file_test (path, G_FILE_TEST_EXISTS))
298 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
301 g_object_thaw_notify (G_OBJECT (settings));
305 gtk_settings_class_init (GtkSettingsClass *class)
307 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
310 gobject_class->finalize = gtk_settings_finalize;
311 gobject_class->get_property = gtk_settings_get_property;
312 gobject_class->set_property = gtk_settings_set_property;
313 gobject_class->notify = gtk_settings_notify;
315 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
316 result = settings_install_property_parser (class,
317 g_param_spec_int ("gtk-double-click-time",
318 P_("Double Click Time"),
319 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
321 GTK_PARAM_READWRITE),
323 g_assert (result == PROP_DOUBLE_CLICK_TIME);
324 result = settings_install_property_parser (class,
325 g_param_spec_int ("gtk-double-click-distance",
326 P_("Double Click Distance"),
327 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
329 GTK_PARAM_READWRITE),
331 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
334 * GtkSettings:gtk-cursor-blink:
336 * Whether the cursor should blink.
338 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
339 * which allows more flexible control over cursor blinking.
341 result = settings_install_property_parser (class,
342 g_param_spec_boolean ("gtk-cursor-blink",
344 P_("Whether the cursor should blink"),
346 GTK_PARAM_READWRITE),
348 g_assert (result == PROP_CURSOR_BLINK);
349 result = settings_install_property_parser (class,
350 g_param_spec_int ("gtk-cursor-blink-time",
351 P_("Cursor Blink Time"),
352 P_("Length of the cursor blink cycle, in milliseconds"),
354 GTK_PARAM_READWRITE),
356 g_assert (result == PROP_CURSOR_BLINK_TIME);
359 * GtkSettings:gtk-cursor-blink-timeout:
361 * Time after which the cursor stops blinking, in seconds.
362 * The timer is reset after each user interaction.
364 * Setting this to zero has the same effect as setting
365 * #GtkSettings:gtk-cursor-blink to %FALSE.
369 result = settings_install_property_parser (class,
370 g_param_spec_int ("gtk-cursor-blink-timeout",
371 P_("Cursor Blink Timeout"),
372 P_("Time after which the cursor stops blinking, in seconds"),
373 1, G_MAXINT, G_MAXINT,
374 GTK_PARAM_READWRITE),
376 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
377 result = settings_install_property_parser (class,
378 g_param_spec_boolean ("gtk-split-cursor",
380 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
382 GTK_PARAM_READWRITE),
384 g_assert (result == PROP_SPLIT_CURSOR);
385 result = settings_install_property_parser (class,
386 g_param_spec_string ("gtk-theme-name",
388 P_("Name of theme to load"),
390 GTK_PARAM_READWRITE),
392 g_assert (result == PROP_THEME_NAME);
394 result = settings_install_property_parser (class,
395 g_param_spec_string ("gtk-icon-theme-name",
396 P_("Icon Theme Name"),
397 P_("Name of icon theme to use"),
399 GTK_PARAM_READWRITE),
401 g_assert (result == PROP_ICON_THEME_NAME);
403 result = settings_install_property_parser (class,
404 g_param_spec_string ("gtk-fallback-icon-theme",
405 P_("Fallback Icon Theme Name"),
406 P_("Name of a icon theme to fall back to"),
408 GTK_PARAM_READWRITE),
410 g_assert (result == PROP_FALLBACK_ICON_THEME);
412 result = settings_install_property_parser (class,
413 g_param_spec_string ("gtk-key-theme-name",
414 P_("Key Theme Name"),
415 P_("Name of key theme to load"),
417 GTK_PARAM_READWRITE),
419 g_assert (result == PROP_KEY_THEME_NAME);
421 result = settings_install_property_parser (class,
422 g_param_spec_string ("gtk-menu-bar-accel",
423 P_("Menu bar accelerator"),
424 P_("Keybinding to activate the menu bar"),
426 GTK_PARAM_READWRITE),
428 g_assert (result == PROP_MENU_BAR_ACCEL);
430 result = settings_install_property_parser (class,
431 g_param_spec_int ("gtk-dnd-drag-threshold",
432 P_("Drag threshold"),
433 P_("Number of pixels the cursor can move before dragging"),
435 GTK_PARAM_READWRITE),
437 g_assert (result == PROP_DND_DRAG_THRESHOLD);
439 result = settings_install_property_parser (class,
440 g_param_spec_string ("gtk-font-name",
442 P_("Name of default font to use"),
444 GTK_PARAM_READWRITE),
446 g_assert (result == PROP_FONT_NAME);
449 * GtkSettings:gtk-icon-sizes:
451 * A list of icon sizes. The list is separated by colons, and
454 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
456 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
457 * GTK+ itself use the following named icon sizes: gtk-menu,
458 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
459 * gtk-dialog. Applications can register their own named icon
460 * sizes with gtk_icon_size_register().
462 result = settings_install_property_parser (class,
463 g_param_spec_string ("gtk-icon-sizes",
465 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
467 GTK_PARAM_READWRITE),
469 g_assert (result == PROP_ICON_SIZES);
471 result = settings_install_property_parser (class,
472 g_param_spec_string ("gtk-modules",
474 P_("List of currently active GTK modules"),
476 GTK_PARAM_READWRITE),
478 g_assert (result == PROP_MODULES);
480 result = settings_install_property_parser (class,
481 g_param_spec_int ("gtk-xft-antialias",
483 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
485 GTK_PARAM_READWRITE),
488 g_assert (result == PROP_XFT_ANTIALIAS);
490 result = settings_install_property_parser (class,
491 g_param_spec_int ("gtk-xft-hinting",
493 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
495 GTK_PARAM_READWRITE),
498 g_assert (result == PROP_XFT_HINTING);
500 result = settings_install_property_parser (class,
501 g_param_spec_string ("gtk-xft-hintstyle",
502 P_("Xft Hint Style"),
503 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
505 GTK_PARAM_READWRITE),
508 g_assert (result == PROP_XFT_HINTSTYLE);
510 result = settings_install_property_parser (class,
511 g_param_spec_string ("gtk-xft-rgba",
513 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
515 GTK_PARAM_READWRITE),
518 g_assert (result == PROP_XFT_RGBA);
520 result = settings_install_property_parser (class,
521 g_param_spec_int ("gtk-xft-dpi",
523 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
525 GTK_PARAM_READWRITE),
528 g_assert (result == PROP_XFT_DPI);
530 result = settings_install_property_parser (class,
531 g_param_spec_string ("gtk-cursor-theme-name",
532 P_("Cursor theme name"),
533 P_("Name of the cursor theme to use, or NULL to use the default theme"),
535 GTK_PARAM_READWRITE),
537 g_assert (result == PROP_CURSOR_THEME_NAME);
539 result = settings_install_property_parser (class,
540 g_param_spec_int ("gtk-cursor-theme-size",
541 P_("Cursor theme size"),
542 P_("Size to use for cursors, or 0 to use the default size"),
544 GTK_PARAM_READWRITE),
547 g_assert (result == PROP_CURSOR_THEME_SIZE);
549 result = settings_install_property_parser (class,
550 g_param_spec_boolean ("gtk-alternative-button-order",
551 P_("Alternative button order"),
552 P_("Whether buttons in dialogs should use the alternative button order"),
554 GTK_PARAM_READWRITE),
556 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
559 * GtkSettings:gtk-alternative-sort-arrows:
561 * Controls the direction of the sort indicators in sorted list and tree
562 * views. By default an arrow pointing down means the column is sorted
563 * in ascending order. When set to %TRUE, this order will be inverted.
567 result = settings_install_property_parser (class,
568 g_param_spec_boolean ("gtk-alternative-sort-arrows",
569 P_("Alternative sort indicator direction"),
570 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
572 GTK_PARAM_READWRITE),
574 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
576 result = settings_install_property_parser (class,
577 g_param_spec_boolean ("gtk-show-input-method-menu",
578 P_("Show the 'Input Methods' menu"),
579 P_("Whether the context menus of entries and text views should offer to change the input method"),
581 GTK_PARAM_READWRITE),
583 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
585 result = settings_install_property_parser (class,
586 g_param_spec_boolean ("gtk-show-unicode-menu",
587 P_("Show the 'Insert Unicode Control Character' menu"),
588 P_("Whether the context menus of entries and text views should offer to insert control characters"),
590 GTK_PARAM_READWRITE),
592 g_assert (result == PROP_SHOW_UNICODE_MENU);
594 result = settings_install_property_parser (class,
595 g_param_spec_int ("gtk-timeout-initial",
597 P_("Starting value for timeouts, when button is pressed"),
598 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
599 GTK_PARAM_READWRITE),
602 g_assert (result == PROP_TIMEOUT_INITIAL);
604 result = settings_install_property_parser (class,
605 g_param_spec_int ("gtk-timeout-repeat",
606 P_("Repeat timeout"),
607 P_("Repeat value for timeouts, when button is pressed"),
608 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
609 GTK_PARAM_READWRITE),
612 g_assert (result == PROP_TIMEOUT_REPEAT);
614 result = settings_install_property_parser (class,
615 g_param_spec_int ("gtk-timeout-expand",
616 P_("Expand timeout"),
617 P_("Expand value for timeouts, when a widget is expanding a new region"),
618 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
619 GTK_PARAM_READWRITE),
622 g_assert (result == PROP_TIMEOUT_EXPAND);
625 * GtkSettings:gtk-color-scheme:
627 * A palette of named colors for use in themes. The format of the string is
633 * Color names must be acceptable as identifiers in the
634 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
635 * color specifications must be in the format accepted by
638 * Note that due to the way the color tables from different sources are
639 * merged, color specifications will be converted to hexadecimal form
640 * when getting this property.
642 * Starting with GTK+ 2.12, the entries can alternatively be separated
643 * by ';' instead of newlines:
645 * name1: color1; name2: color2; ...
650 result = settings_install_property_parser (class,
651 g_param_spec_string ("gtk-color-scheme",
653 P_("A palette of named colors for use in themes"),
655 GTK_PARAM_READWRITE),
658 g_assert (result == PROP_COLOR_SCHEME);
660 result = settings_install_property_parser (class,
661 g_param_spec_boolean ("gtk-enable-animations",
662 P_("Enable Animations"),
663 P_("Whether to enable toolkit-wide animations."),
665 GTK_PARAM_READWRITE),
668 g_assert (result == PROP_ENABLE_ANIMATIONS);
671 * GtkSettings:gtk-touchscreen-mode:
673 * When %TRUE, there are no motion notify events delivered on this screen,
674 * and widgets can't use the pointer hovering them for any essential
679 result = settings_install_property_parser (class,
680 g_param_spec_boolean ("gtk-touchscreen-mode",
681 P_("Enable Touchscreen Mode"),
682 P_("When TRUE, there are no motion notify events delivered on this screen"),
684 GTK_PARAM_READWRITE),
687 g_assert (result == PROP_TOUCHSCREEN_MODE);
690 * GtkSettings:gtk-tooltip-timeout:
692 * Time, in milliseconds, after which a tooltip could appear if the
693 * cursor is hovering on top of a widget.
697 result = settings_install_property_parser (class,
698 g_param_spec_int ("gtk-tooltip-timeout",
699 P_("Tooltip timeout"),
700 P_("Timeout before tooltip is shown"),
703 GTK_PARAM_READWRITE),
706 g_assert (result == PROP_TOOLTIP_TIMEOUT);
709 * GtkSettings:gtk-tooltip-browse-timeout:
711 * Controls the time after which tooltips will appear when
712 * browse mode is enabled, in milliseconds.
714 * Browse mode is enabled when the mouse pointer moves off an object
715 * where a tooltip was currently being displayed. If the mouse pointer
716 * hits another object before the browse mode timeout expires (see
717 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
718 * amount of milliseconds specified by this setting to popup the tooltip
719 * for the new object.
723 result = settings_install_property_parser (class,
724 g_param_spec_int ("gtk-tooltip-browse-timeout",
725 P_("Tooltip browse timeout"),
726 P_("Timeout before tooltip is shown when browse mode is enabled"),
729 GTK_PARAM_READWRITE),
732 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
735 * GtkSettings:gtk-tooltip-browse-mode-timeout:
737 * Amount of time, in milliseconds, after which the browse mode
740 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
745 result = settings_install_property_parser (class,
746 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
747 P_("Tooltip browse mode timeout"),
748 P_("Timeout after which browse mode is disabled"),
751 GTK_PARAM_READWRITE),
754 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
757 * GtkSettings:gtk-keynav-cursor-only:
759 * When %TRUE, keyboard navigation should be able to reach all widgets
760 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
761 * to be present on the used input device.
765 result = settings_install_property_parser (class,
766 g_param_spec_boolean ("gtk-keynav-cursor-only",
767 P_("Keynav Cursor Only"),
768 P_("When TRUE, there are only cursor keys available to navigate widgets"),
770 GTK_PARAM_READWRITE),
773 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
776 * GtkSettings:gtk-keynav-wrap-around:
778 * When %TRUE, some widgets will wrap around when doing keyboard
779 * navigation, such as menus, menubars and notebooks.
783 result = settings_install_property_parser (class,
784 g_param_spec_boolean ("gtk-keynav-wrap-around",
785 P_("Keynav Wrap Around"),
786 P_("Whether to wrap around when keyboard-navigating widgets"),
788 GTK_PARAM_READWRITE),
791 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
794 * GtkSettings:gtk-error-bell:
796 * When %TRUE, keyboard navigation and other input-related errors
797 * will cause a beep. Since the error bell is implemented using
798 * gdk_window_beep(), the windowing system may offer ways to
799 * configure the error bell in many ways, such as flashing the
800 * window or similar visual effects.
804 result = settings_install_property_parser (class,
805 g_param_spec_boolean ("gtk-error-bell",
807 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
809 GTK_PARAM_READWRITE),
812 g_assert (result == PROP_ERROR_BELL);
815 * GtkSettings:color-hash:
817 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
818 * setting, mapping color names to #GdkColor<!-- -->s.
822 result = settings_install_property_parser (class,
823 g_param_spec_boxed ("color-hash",
825 P_("A hash table representation of the color scheme."),
829 g_assert (result == PROP_COLOR_HASH);
831 result = settings_install_property_parser (class,
832 g_param_spec_string ("gtk-file-chooser-backend",
833 P_("Default file chooser backend"),
834 P_("Name of the GtkFileChooser backend to use by default"),
836 GTK_PARAM_READWRITE),
838 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
841 * GtkSettings:gtk-print-backends:
843 * A comma-separated list of print backends to use in the print
844 * dialog. Available print backends depend on the GTK+ installation,
845 * and may include "file", "cups", "lpr" or "papi".
849 result = settings_install_property_parser (class,
850 g_param_spec_string ("gtk-print-backends",
851 P_("Default print backend"),
852 P_("List of the GtkPrintBackend backends to use by default"),
854 GTK_PARAM_READWRITE),
856 g_assert (result == PROP_PRINT_BACKENDS);
859 * GtkSettings:gtk-print-preview-command:
861 * A command to run for displaying the print preview. The command
862 * should contain a %f placeholder, which will get replaced by
863 * the path to the pdf file. The command may also contain a %s
864 * placeholder, which will get replaced by the path to a file
865 * containing the print settings in the format produced by
866 * gtk_print_settings_to_file().
868 * The preview application is responsible for removing the pdf file
869 * and the print settings file when it is done.
873 result = settings_install_property_parser (class,
874 g_param_spec_string ("gtk-print-preview-command",
875 P_("Default command to run when displaying a print preview"),
876 P_("Command to run when displaying a print preview"),
877 GTK_PRINT_PREVIEW_COMMAND,
878 GTK_PARAM_READWRITE),
880 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
883 * GtkSettings:gtk-enable-mnemonics:
885 * Whether labels and menu items should have visible mnemonics which
890 result = settings_install_property_parser (class,
891 g_param_spec_boolean ("gtk-enable-mnemonics",
892 P_("Enable Mnemonics"),
893 P_("Whether labels should have mnemonics"),
895 GTK_PARAM_READWRITE),
897 g_assert (result == PROP_ENABLE_MNEMONICS);
900 * GtkSettings:gtk-enable-accels:
902 * Whether menu items should have visible accelerators which can be
907 result = settings_install_property_parser (class,
908 g_param_spec_boolean ("gtk-enable-accels",
909 P_("Enable Accelerators"),
910 P_("Whether menu items should have accelerators"),
912 GTK_PARAM_READWRITE),
914 g_assert (result == PROP_ENABLE_ACCELS);
917 * GtkSettings:gtk-recent-files-limit:
919 * The number of recently used files that should be displayed by default by
920 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
921 * -1 means every recently used file stored.
925 result = settings_install_property_parser (class,
926 g_param_spec_int ("gtk-recent-files-limit",
927 P_("Recent Files Limit"),
928 P_("Number of recently used files"),
931 GTK_PARAM_READWRITE),
933 g_assert (result == PROP_RECENT_FILES_LIMIT);
936 * GtkSettings:gtk-im-module:
938 * Which IM (input method) module should be used by default. This is the
939 * input method that will be used if the user has not explicitly chosen
940 * another input method from the IM context menu.
942 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
944 result = settings_install_property_parser (class,
945 g_param_spec_string ("gtk-im-module",
946 P_("Default IM module"),
947 P_("Which IM module should be used by default"),
949 GTK_PARAM_READWRITE),
951 g_assert (result == PROP_IM_MODULE);
954 * GtkSettings:gtk-recent-files-max-age:
956 * The maximum age, in days, of the items inside the recently used
957 * resources list. Items older than this setting will be excised
958 * from the list. If set to 0, the list will always be empty; if
959 * set to -1, no item will be removed.
963 result = settings_install_property_parser (class,
964 g_param_spec_int ("gtk-recent-files-max-age",
965 P_("Recent Files Max Age"),
966 P_("Maximum age of recently used files, in days"),
969 GTK_PARAM_READWRITE),
971 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
973 result = settings_install_property_parser (class,
974 g_param_spec_uint ("gtk-fontconfig-timestamp",
975 P_("Fontconfig configuration timestamp"),
976 P_("Timestamp of current fontconfig configuration"),
978 GTK_PARAM_READWRITE),
981 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
984 * GtkSettings:gtk-sound-theme-name:
986 * The XDG sound theme to use for event sounds.
988 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
989 * for more information on event sounds and sound themes.
991 * GTK+ itself does not support event sounds, you have to use a loadable
992 * module like the one that comes with libcanberra.
996 result = settings_install_property_parser (class,
997 g_param_spec_string ("gtk-sound-theme-name",
998 P_("Sound Theme Name"),
999 P_("XDG sound theme name"),
1001 GTK_PARAM_READWRITE),
1003 g_assert (result == PROP_SOUND_THEME_NAME);
1006 * GtkSettings:gtk-enable-input-feedback-sounds:
1008 * Whether to play event sounds as feedback to user input.
1010 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1011 * for more information on event sounds and sound themes.
1013 * GTK+ itself does not support event sounds, you have to use a loadable
1014 * module like the one that comes with libcanberra.
1018 result = settings_install_property_parser (class,
1019 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1020 /* Translators: this means sounds that are played as feedback to user input */
1021 P_("Audible Input Feedback"),
1022 P_("Whether to play event sounds as feedback to user input"),
1024 GTK_PARAM_READWRITE),
1026 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1029 * GtkSettings:gtk-enable-event-sounds:
1031 * Whether to play any event sounds at all.
1033 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1034 * for more information on event sounds and sound themes.
1036 * GTK+ itself does not support event sounds, you have to use a loadable
1037 * module like the one that comes with libcanberra.
1041 result = settings_install_property_parser (class,
1042 g_param_spec_boolean ("gtk-enable-event-sounds",
1043 P_("Enable Event Sounds"),
1044 P_("Whether to play any event sounds at all"),
1046 GTK_PARAM_READWRITE),
1048 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1051 * GtkSettings:gtk-enable-tooltips:
1053 * Whether tooltips should be shown on widgets.
1057 result = settings_install_property_parser (class,
1058 g_param_spec_boolean ("gtk-enable-tooltips",
1059 P_("Enable Tooltips"),
1060 P_("Whether tooltips should be shown on widgets"),
1062 GTK_PARAM_READWRITE),
1064 g_assert (result == PROP_ENABLE_TOOLTIPS);
1067 * GtkSettings:gtk-toolbar-style:
1069 * The size of icons in default toolbars.
1071 result = settings_install_property_parser (class,
1072 g_param_spec_enum ("gtk-toolbar-style",
1073 P_("Toolbar style"),
1074 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1075 GTK_TYPE_TOOLBAR_STYLE,
1077 GTK_PARAM_READWRITE),
1078 gtk_rc_property_parse_enum);
1079 g_assert (result == PROP_TOOLBAR_STYLE);
1082 * GtkSettings:gtk-toolbar-icon-size:
1084 * The size of icons in default toolbars.
1086 result = settings_install_property_parser (class,
1087 g_param_spec_enum ("gtk-toolbar-icon-size",
1088 P_("Toolbar Icon Size"),
1089 P_("The size of icons in default toolbars."),
1091 GTK_ICON_SIZE_LARGE_TOOLBAR,
1092 GTK_PARAM_READWRITE),
1093 gtk_rc_property_parse_enum);
1094 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1097 * GtkSettings:gtk-auto-mnemonics:
1099 * Whether mnemonics should be automatically shown and hidden when the user
1100 * presses the mnemonic activator.
1104 result = settings_install_property_parser (class,
1105 g_param_spec_boolean ("gtk-auto-mnemonics",
1106 P_("Auto Mnemonics"),
1107 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1109 GTK_PARAM_READWRITE),
1111 g_assert (result == PROP_AUTO_MNEMONICS);
1114 * GtkSettings:gtk-application-prefer-dark-theme:
1116 * Whether the application prefers to use a dark theme. If a GTK+ theme
1117 * includes a dark variant, it will be used instead of the configured
1120 * Some applications benefit from minimizing the amount of light pollution that
1121 * interferes with the content. Good candidates for dark themes are photo and
1122 * video editors that make the actual content get all the attention and minimize
1123 * the distraction of the chrome.
1125 * Dark themes should not be used for documents, where large spaces are white/light
1126 * and the dark chrome creates too much contrast (web browser, text editor...).
1130 result = settings_install_property_parser (class,
1131 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1132 P_("Application prefers a dark theme"),
1133 P_("Whether the application prefers to have a dark theme."),
1135 GTK_PARAM_READWRITE),
1137 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1140 * GtkSettings::gtk-button-images:
1142 * Whether images should be shown on buttons
1146 result = settings_install_property_parser (class,
1147 g_param_spec_boolean ("gtk-button-images",
1148 P_("Show button images"),
1149 P_("Whether images should be shown on buttons"),
1151 GTK_PARAM_READWRITE),
1153 g_assert (result == PROP_BUTTON_IMAGES);
1155 result = settings_install_property_parser (class,
1156 g_param_spec_boolean ("gtk-entry-select-on-focus",
1157 P_("Select on focus"),
1158 P_("Whether to select the contents of an entry when it is focused"),
1160 GTK_PARAM_READWRITE),
1162 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1165 * GtkSettings:gtk-entry-password-hint-timeout:
1167 * How long to show the last input character in hidden
1168 * entries. This value is in milliseconds. 0 disables showing the
1169 * last char. 600 is a good value for enabling it.
1173 result = settings_install_property_parser (class,
1174 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1175 P_("Password Hint Timeout"),
1176 P_("How long to show the last input character in hidden entries"),
1179 GTK_PARAM_READWRITE),
1181 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1183 result = settings_install_property_parser (class,
1184 g_param_spec_boolean ("gtk-menu-images",
1185 P_("Show menu images"),
1186 P_("Whether images should be shown in menus"),
1188 GTK_PARAM_READWRITE),
1190 g_assert (result == PROP_MENU_IMAGES);
1192 result = settings_install_property_parser (class,
1193 g_param_spec_int ("gtk-menu-bar-popup-delay",
1194 P_("Delay before drop down menus appear"),
1195 P_("Delay before the submenus of a menu bar appear"),
1198 GTK_PARAM_READWRITE),
1200 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1203 * GtkSettings:gtk-scrolled-window-placement:
1205 * Where the contents of scrolled windows are located with respect to the
1206 * scrollbars, if not overridden by the scrolled window's own placement.
1210 result = settings_install_property_parser (class,
1211 g_param_spec_enum ("gtk-scrolled-window-placement",
1212 P_("Scrolled Window Placement"),
1213 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1214 GTK_TYPE_CORNER_TYPE,
1215 GTK_CORNER_TOP_LEFT,
1216 GTK_PARAM_READWRITE),
1217 gtk_rc_property_parse_enum);
1218 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1220 result = settings_install_property_parser (class,
1221 g_param_spec_boolean ("gtk-can-change-accels",
1222 P_("Can change accelerators"),
1223 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1225 GTK_PARAM_READWRITE),
1227 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1229 result = settings_install_property_parser (class,
1230 g_param_spec_int ("gtk-menu-popup-delay",
1231 P_("Delay before submenus appear"),
1232 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1235 GTK_PARAM_READWRITE),
1237 g_assert (result == PROP_MENU_POPUP_DELAY);
1239 result = settings_install_property_parser (class,
1240 g_param_spec_int ("gtk-menu-popdown-delay",
1241 P_("Delay before hiding a submenu"),
1242 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1245 GTK_PARAM_READWRITE),
1247 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1249 result = settings_install_property_parser (class,
1250 g_param_spec_boolean ("gtk-label-select-on-focus",
1251 P_("Select on focus"),
1252 P_("Whether to select the contents of a selectable label when it is focused"),
1254 GTK_PARAM_READWRITE),
1256 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1258 result = settings_install_property_parser (class,
1259 g_param_spec_string ("gtk-color-palette",
1260 P_("Custom palette"),
1261 P_("Palette to use in the color selector"),
1262 default_color_palette,
1263 GTK_PARAM_READWRITE),
1265 g_assert (result == PROP_COLOR_PALETTE);
1267 result = settings_install_property_parser (class,
1268 g_param_spec_enum ("gtk-im-preedit-style",
1269 P_("IM Preedit style"),
1270 P_("How to draw the input method preedit string"),
1271 GTK_TYPE_IM_PREEDIT_STYLE,
1272 GTK_IM_PREEDIT_CALLBACK,
1273 GTK_PARAM_READWRITE),
1274 gtk_rc_property_parse_enum);
1275 g_assert (result == PROP_IM_PREEDIT_STYLE);
1277 result = settings_install_property_parser (class,
1278 g_param_spec_enum ("gtk-im-status-style",
1279 P_("IM Status style"),
1280 P_("How to draw the input method statusbar"),
1281 GTK_TYPE_IM_STATUS_STYLE,
1282 GTK_IM_STATUS_CALLBACK,
1283 GTK_PARAM_READWRITE),
1284 gtk_rc_property_parse_enum);
1285 g_assert (result == PROP_IM_STATUS_STYLE);
1287 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1290 static GtkStyleProperties *
1291 gtk_settings_get_style (GtkStyleProvider *provider,
1292 GtkWidgetPath *path)
1294 PangoFontDescription *font_desc;
1295 gchar *font_name, *color_scheme;
1296 GtkSettings *settings;
1297 GtkStyleProperties *props;
1301 settings = GTK_SETTINGS (provider);
1302 props = gtk_style_properties_new ();
1304 g_object_get (settings,
1305 "gtk-font-name", &font_name,
1306 "gtk-color-scheme", &color_scheme,
1309 colors = g_strsplit_set (color_scheme, "\n;", -1);
1311 for (i = 0; colors[i]; i++)
1313 GtkSymbolicColor *color;
1321 pos = strchr (colors[i], ':');
1326 /* Set NUL after color name */
1330 /* Find start of color string */
1334 if (!*pos || !gdk_rgba_parse (&col, pos))
1337 color = gtk_symbolic_color_new_literal (&col);
1338 gtk_style_properties_map_color (props, name, color);
1339 gtk_symbolic_color_unref (color);
1342 font_desc = pango_font_description_from_string (font_name);
1344 gtk_style_properties_set (props, 0,
1348 pango_font_description_free (font_desc);
1349 g_strfreev (colors);
1350 g_free (color_scheme);
1357 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1359 iface->get_style = gtk_settings_get_style;
1363 gtk_settings_finalize (GObject *object)
1365 GtkSettings *settings = GTK_SETTINGS (object);
1366 GtkSettingsPrivate *priv = settings->priv;
1369 object_list = g_slist_remove (object_list, settings);
1371 for (i = 0; i < class_n_properties; i++)
1372 g_value_unset (&priv->property_values[i].value);
1373 g_free (priv->property_values);
1375 g_datalist_clear (&priv->queued_settings);
1377 if (priv->theme_provider)
1378 g_object_unref (priv->theme_provider);
1380 if (priv->key_theme_provider)
1381 g_object_unref (priv->key_theme_provider);
1383 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1387 settings_init_style (GtkSettings *settings)
1389 static GtkCssProvider *css_provider = NULL;
1391 GdkScreen *screen = settings->priv->screen;
1392 GtkCssProvider *default_provider;
1394 /* Add provider for user file */
1395 if (G_UNLIKELY (!css_provider))
1399 css_provider = gtk_css_provider_new ();
1400 css_path = g_build_filename (g_get_user_config_dir (),
1405 if (g_file_test (css_path,
1406 G_FILE_TEST_IS_REGULAR))
1407 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1412 gtk_style_context_add_provider_for_screen (screen,
1413 GTK_STYLE_PROVIDER (css_provider),
1414 GTK_STYLE_PROVIDER_PRIORITY_USER);
1416 default_provider = gtk_css_provider_get_default ();
1417 gtk_style_context_add_provider_for_screen (screen,
1418 GTK_STYLE_PROVIDER (default_provider),
1419 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1421 gtk_style_context_add_provider_for_screen (screen,
1422 GTK_STYLE_PROVIDER (settings),
1423 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1425 settings_update_theme (settings);
1426 settings_update_key_theme (settings);
1430 * gtk_settings_get_for_screen:
1431 * @screen: a #GdkScreen.
1433 * Gets the #GtkSettings object for @screen, creating it if necessary.
1435 * Return value: (transfer none): a #GtkSettings object.
1440 gtk_settings_get_for_screen (GdkScreen *screen)
1442 GtkSettings *settings;
1444 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1446 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1449 #ifdef GDK_WINDOWING_QUARTZ
1450 if (GDK_IS_QUARTZ_SCREEN (screen))
1451 settings = g_object_new (GTK_TYPE_SETTINGS, "gtk-key-theme-name", "Mac", NULL);
1454 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1455 settings->priv->screen = screen;
1456 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1457 settings, g_object_unref);
1459 settings_init_style (settings);
1460 settings_update_double_click (settings);
1461 settings_update_cursor_theme (settings);
1462 settings_update_resolution (settings);
1463 settings_update_font_options (settings);
1464 settings_update_color_scheme (settings);
1471 * gtk_settings_get_default:
1473 * Gets the #GtkSettings object for the default GDK screen, creating
1474 * it if necessary. See gtk_settings_get_for_screen().
1476 * Return value: (transfer none): a #GtkSettings object. If there is no default
1477 * screen, then returns %NULL.
1480 gtk_settings_get_default (void)
1482 GdkScreen *screen = gdk_screen_get_default ();
1485 return gtk_settings_get_for_screen (screen);
1491 gtk_settings_set_property (GObject *object,
1493 const GValue *value,
1496 GtkSettings *settings = GTK_SETTINGS (object);
1497 GtkSettingsPrivate *priv = settings->priv;
1499 g_value_copy (value, &priv->property_values[property_id - 1].value);
1500 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1502 if (pspec->param_id == PROP_COLOR_SCHEME)
1503 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1507 gtk_settings_get_property (GObject *object,
1512 GtkSettings *settings = GTK_SETTINGS (object);
1513 GtkSettingsPrivate *priv = settings->priv;
1514 GType value_type = G_VALUE_TYPE (value);
1515 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1517 /* handle internal properties */
1518 switch (property_id)
1520 case PROP_COLOR_HASH:
1521 g_value_set_boxed (value, get_color_hash (settings));
1523 case PROP_COLOR_SCHEME:
1524 g_value_take_string (value, get_color_scheme (settings));
1529 /* For enums and strings, we need to get the value as a string,
1530 * not as an int, since we support using names/nicks as the setting
1533 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1534 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1535 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1536 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1538 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1539 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1540 g_value_copy (&priv->property_values[property_id - 1].value, value);
1542 g_param_value_validate (pspec, value);
1546 GValue val = { 0, };
1548 /* Try to get xsetting as a string and parse it. */
1550 g_value_init (&val, G_TYPE_STRING);
1552 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1553 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1555 g_value_copy (&priv->property_values[property_id - 1].value, value);
1559 GValue tmp_value = { 0, };
1560 GValue gstring_value = { 0, };
1561 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1563 g_value_init (&gstring_value, G_TYPE_GSTRING);
1564 g_value_take_boxed (&gstring_value,
1565 g_string_new (g_value_get_string (&val)));
1567 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1569 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1572 g_value_copy (&tmp_value, value);
1573 g_param_value_validate (pspec, value);
1577 g_value_copy (&priv->property_values[property_id - 1].value, value);
1580 g_value_unset (&gstring_value);
1581 g_value_unset (&tmp_value);
1584 g_value_unset (&val);
1589 gtk_settings_notify (GObject *object,
1592 GtkSettings *settings = GTK_SETTINGS (object);
1593 GtkSettingsPrivate *priv = settings->priv;
1594 guint property_id = pspec->param_id;
1596 if (priv->screen == NULL) /* initialization */
1599 switch (property_id)
1602 settings_update_modules (settings);
1604 case PROP_DOUBLE_CLICK_TIME:
1605 case PROP_DOUBLE_CLICK_DISTANCE:
1606 settings_update_double_click (settings);
1608 case PROP_COLOR_SCHEME:
1609 settings_update_color_scheme (settings);
1610 gtk_style_context_reset_widgets (priv->screen);
1612 case PROP_KEY_THEME_NAME:
1613 settings_update_key_theme (settings);
1615 case PROP_THEME_NAME:
1616 case PROP_APPLICATION_PREFER_DARK_THEME:
1617 settings_update_theme (settings);
1620 settings_update_resolution (settings);
1621 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1622 * widgets with gtk_widget_style_set(), and also causes more
1623 * recomputation than necessary.
1625 gtk_style_context_reset_widgets (priv->screen);
1627 case PROP_XFT_ANTIALIAS:
1628 case PROP_XFT_HINTING:
1629 case PROP_XFT_HINTSTYLE:
1631 settings_update_font_options (settings);
1632 gtk_style_context_reset_widgets (priv->screen);
1634 case PROP_FONTCONFIG_TIMESTAMP:
1635 if (settings_update_fontconfig (settings))
1636 gtk_style_context_reset_widgets (priv->screen);
1638 case PROP_CURSOR_THEME_NAME:
1639 case PROP_CURSOR_THEME_SIZE:
1640 settings_update_cursor_theme (settings);
1646 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1647 const GValue *src_value,
1651 gboolean success = FALSE;
1653 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1658 gboolean free_gstring = TRUE;
1660 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1662 gstring = g_value_get_boxed (src_value);
1663 free_gstring = FALSE;
1665 else if (G_VALUE_HOLDS_LONG (src_value))
1667 gstring = g_string_new (NULL);
1668 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1670 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1672 gstring = g_string_new (NULL);
1673 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1675 else if (G_VALUE_HOLDS_STRING (src_value))
1677 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1679 gstring = g_string_new (NULL);
1680 g_string_append_c (gstring, '\"');
1681 g_string_append (gstring, tstr);
1682 g_string_append_c (gstring, '\"');
1687 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1688 gstring = NULL; /* silence compiler */
1691 success = (parser (pspec, gstring, dest_value) &&
1692 !g_param_value_validate (pspec, dest_value));
1695 g_string_free (gstring, TRUE);
1697 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1699 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1701 GString *gstring = g_value_get_boxed (src_value);
1703 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1704 success = !g_param_value_validate (pspec, dest_value);
1707 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1708 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1714 apply_queued_setting (GtkSettings *settings,
1716 GtkSettingsValuePrivate *qvalue)
1718 GtkSettingsPrivate *priv = settings->priv;
1719 GValue tmp_value = { 0, };
1720 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1722 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1723 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1726 if (pspec->param_id == PROP_COLOR_SCHEME)
1727 merge_color_scheme (settings, &tmp_value, qvalue->source);
1729 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1731 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1732 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1733 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1739 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1741 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1742 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1744 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1746 G_VALUE_TYPE_NAME (&tmp_value));
1749 g_value_unset (&tmp_value);
1753 settings_install_property_parser (GtkSettingsClass *class,
1755 GtkRcPropertyParser parser)
1757 GSList *node, *next;
1759 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1761 case G_TYPE_BOOLEAN:
1774 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1782 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1783 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1787 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1789 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1794 for (node = object_list; node; node = node->next)
1795 g_object_freeze_notify (node->data);
1797 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1798 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1800 for (node = object_list; node; node = node->next)
1802 GtkSettings *settings = node->data;
1803 GtkSettingsPrivate *priv = settings->priv;
1804 GtkSettingsValuePrivate *qvalue;
1806 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1807 priv->property_values[class_n_properties - 1].value.g_type = 0;
1808 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1809 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1810 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1811 g_object_notify (G_OBJECT (settings), pspec->name);
1813 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1815 apply_queued_setting (settings, pspec, qvalue);
1818 for (node = object_list; node; node = next)
1821 g_object_thaw_notify (node->data);
1824 return class_n_properties;
1828 _gtk_rc_property_parser_from_type (GType type)
1830 if (type == GDK_TYPE_COLOR)
1831 return gtk_rc_property_parse_color;
1832 else if (type == GTK_TYPE_REQUISITION)
1833 return gtk_rc_property_parse_requisition;
1834 else if (type == GTK_TYPE_BORDER)
1835 return gtk_rc_property_parse_border;
1836 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1837 return gtk_rc_property_parse_enum;
1838 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1839 return gtk_rc_property_parse_flags;
1845 gtk_settings_install_property (GParamSpec *pspec)
1847 static GtkSettingsClass *klass = NULL;
1849 GtkRcPropertyParser parser;
1851 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1854 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1856 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1858 settings_install_property_parser (klass, pspec, parser);
1862 * gtk_settings_install_property_parser:
1864 * @parser: (scope call):
1867 gtk_settings_install_property_parser (GParamSpec *pspec,
1868 GtkRcPropertyParser parser)
1870 static GtkSettingsClass *klass = NULL;
1872 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1873 g_return_if_fail (parser != NULL);
1876 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1878 settings_install_property_parser (klass, pspec, parser);
1882 free_value (gpointer data)
1884 GtkSettingsValuePrivate *qvalue = data;
1886 g_value_unset (&qvalue->public.value);
1887 g_free (qvalue->public.origin);
1888 g_slice_free (GtkSettingsValuePrivate, qvalue);
1892 gtk_settings_set_property_value_internal (GtkSettings *settings,
1893 const gchar *prop_name,
1894 const GtkSettingsValue *new_value,
1895 GtkSettingsSource source)
1897 GtkSettingsPrivate *priv = settings->priv;
1898 GtkSettingsValuePrivate *qvalue;
1903 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1904 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1905 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1906 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1908 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
1912 name = g_strdup (prop_name);
1913 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1914 name_quark = g_quark_from_string (name);
1917 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
1920 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1921 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
1925 g_free (qvalue->public.origin);
1926 g_value_unset (&qvalue->public.value);
1928 qvalue->public.origin = g_strdup (new_value->origin);
1929 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1930 g_value_copy (&new_value->value, &qvalue->public.value);
1931 qvalue->source = source;
1932 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1934 apply_queued_setting (settings, pspec, qvalue);
1938 gtk_settings_set_property_value (GtkSettings *settings,
1939 const gchar *prop_name,
1940 const GtkSettingsValue *new_value)
1942 g_return_if_fail (GTK_SETTINGS (settings));
1943 g_return_if_fail (prop_name != NULL);
1944 g_return_if_fail (new_value != NULL);
1946 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1947 GTK_SETTINGS_SOURCE_APPLICATION);
1951 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1952 const gchar *prop_name,
1953 const GtkSettingsValue *new_value)
1955 g_return_if_fail (GTK_SETTINGS (settings));
1956 g_return_if_fail (prop_name != NULL);
1957 g_return_if_fail (new_value != NULL);
1959 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1960 GTK_SETTINGS_SOURCE_THEME);
1964 gtk_settings_set_string_property (GtkSettings *settings,
1966 const gchar *v_string,
1967 const gchar *origin)
1969 GtkSettingsValue svalue = { NULL, { 0, }, };
1971 g_return_if_fail (GTK_SETTINGS (settings));
1972 g_return_if_fail (name != NULL);
1973 g_return_if_fail (v_string != NULL);
1975 svalue.origin = (gchar*) origin;
1976 g_value_init (&svalue.value, G_TYPE_STRING);
1977 g_value_set_static_string (&svalue.value, v_string);
1978 gtk_settings_set_property_value (settings, name, &svalue);
1979 g_value_unset (&svalue.value);
1983 gtk_settings_set_long_property (GtkSettings *settings,
1986 const gchar *origin)
1988 GtkSettingsValue svalue = { NULL, { 0, }, };
1990 g_return_if_fail (GTK_SETTINGS (settings));
1991 g_return_if_fail (name != NULL);
1993 svalue.origin = (gchar*) origin;
1994 g_value_init (&svalue.value, G_TYPE_LONG);
1995 g_value_set_long (&svalue.value, v_long);
1996 gtk_settings_set_property_value (settings, name, &svalue);
1997 g_value_unset (&svalue.value);
2001 gtk_settings_set_double_property (GtkSettings *settings,
2004 const gchar *origin)
2006 GtkSettingsValue svalue = { NULL, { 0, }, };
2008 g_return_if_fail (GTK_SETTINGS (settings));
2009 g_return_if_fail (name != NULL);
2011 svalue.origin = (gchar*) origin;
2012 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2013 g_value_set_double (&svalue.value, v_double);
2014 gtk_settings_set_property_value (settings, name, &svalue);
2015 g_value_unset (&svalue.value);
2019 * gtk_rc_property_parse_color:
2020 * @pspec: a #GParamSpec
2021 * @gstring: the #GString to be parsed
2022 * @property_value: a #GValue which must hold #GdkColor values.
2024 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2025 * or gtk_widget_class_install_style_property_parser() which parses a
2026 * color given either by its name or in the form
2027 * <literal>{ red, green, blue }</literal> where %red, %green and
2028 * %blue are integers between 0 and 65535 or floating-point numbers
2031 * Return value: %TRUE if @gstring could be parsed and @property_value
2032 * has been set to the resulting #GdkColor.
2035 gtk_rc_property_parse_color (const GParamSpec *pspec,
2036 const GString *gstring,
2037 GValue *property_value)
2039 GdkColor color = { 0, 0, 0, 0, };
2043 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2044 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2046 scanner = gtk_rc_scanner_new ();
2047 g_scanner_input_text (scanner, gstring->str, gstring->len);
2048 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2049 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2051 g_value_set_boxed (property_value, &color);
2056 g_scanner_destroy (scanner);
2062 * gtk_rc_property_parse_enum:
2063 * @pspec: a #GParamSpec
2064 * @gstring: the #GString to be parsed
2065 * @property_value: a #GValue which must hold enum values.
2067 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2068 * or gtk_widget_class_install_style_property_parser() which parses a single
2069 * enumeration value.
2071 * The enumeration value can be specified by its name, its nickname or
2072 * its numeric value. For consistency with flags parsing, the value
2073 * may be surrounded by parentheses.
2075 * Return value: %TRUE if @gstring could be parsed and @property_value
2076 * has been set to the resulting #GEnumValue.
2079 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2080 const GString *gstring,
2081 GValue *property_value)
2083 gboolean need_closing_brace = FALSE, success = FALSE;
2085 GEnumValue *enum_value = NULL;
2087 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2088 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2090 scanner = gtk_rc_scanner_new ();
2091 g_scanner_input_text (scanner, gstring->str, gstring->len);
2093 /* we just want to parse _one_ value, but for consistency with flags parsing
2094 * we support optional parenthesis
2096 g_scanner_get_next_token (scanner);
2097 if (scanner->token == '(')
2099 need_closing_brace = TRUE;
2100 g_scanner_get_next_token (scanner);
2102 if (scanner->token == G_TOKEN_IDENTIFIER)
2104 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2106 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2108 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2111 g_value_set_enum (property_value, enum_value->value);
2115 else if (scanner->token == G_TOKEN_INT)
2117 g_value_set_enum (property_value, scanner->value.v_int);
2120 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2122 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2125 g_scanner_destroy (scanner);
2131 parse_flags_value (GScanner *scanner,
2135 g_scanner_get_next_token (scanner);
2136 if (scanner->token == G_TOKEN_IDENTIFIER)
2138 GFlagsValue *flags_value;
2140 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2142 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2145 *number |= flags_value->value;
2146 return G_TOKEN_NONE;
2149 else if (scanner->token == G_TOKEN_INT)
2151 *number |= scanner->value.v_int;
2152 return G_TOKEN_NONE;
2154 return G_TOKEN_IDENTIFIER;
2158 * gtk_rc_property_parse_flags:
2159 * @pspec: a #GParamSpec
2160 * @gstring: the #GString to be parsed
2161 * @property_value: a #GValue which must hold flags values.
2163 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2164 * or gtk_widget_class_install_style_property_parser() which parses flags.
2166 * Flags can be specified by their name, their nickname or
2167 * numerically. Multiple flags can be specified in the form
2168 * <literal>"( flag1 | flag2 | ... )"</literal>.
2170 * Return value: %TRUE if @gstring could be parsed and @property_value
2171 * has been set to the resulting flags value.
2174 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2175 const GString *gstring,
2176 GValue *property_value)
2179 gboolean success = FALSE;
2182 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2183 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2185 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2186 scanner = gtk_rc_scanner_new ();
2187 g_scanner_input_text (scanner, gstring->str, gstring->len);
2189 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2190 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2191 scanner->next_token == G_TOKEN_INT)
2193 guint token, flags_value = 0;
2195 token = parse_flags_value (scanner, class, &flags_value);
2197 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2200 g_value_set_flags (property_value, flags_value);
2204 else if (g_scanner_get_next_token (scanner) == '(')
2206 guint token, flags_value = 0;
2208 /* parse first value */
2209 token = parse_flags_value (scanner, class, &flags_value);
2211 /* parse nth values, preceeded by '|' */
2212 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2213 token = parse_flags_value (scanner, class, &flags_value);
2215 /* done, last token must have closed expression */
2216 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2217 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2219 g_value_set_flags (property_value, flags_value);
2223 g_scanner_destroy (scanner);
2229 get_braced_int (GScanner *scanner,
2236 g_scanner_get_next_token (scanner);
2237 if (scanner->token != '{')
2241 g_scanner_get_next_token (scanner);
2242 if (scanner->token != G_TOKEN_INT)
2245 *value = scanner->value.v_int;
2249 g_scanner_get_next_token (scanner);
2250 if (scanner->token != '}')
2255 g_scanner_get_next_token (scanner);
2256 if (scanner->token != ',')
2264 * gtk_rc_property_parse_requisition:
2265 * @pspec: a #GParamSpec
2266 * @gstring: the #GString to be parsed
2267 * @property_value: a #GValue which must hold boxed values.
2269 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2270 * or gtk_widget_class_install_style_property_parser() which parses a
2271 * requisition in the form
2272 * <literal>"{ width, height }"</literal> for integers %width and %height.
2274 * Return value: %TRUE if @gstring could be parsed and @property_value
2275 * has been set to the resulting #GtkRequisition.
2278 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2279 const GString *gstring,
2280 GValue *property_value)
2282 GtkRequisition requisition;
2284 gboolean success = FALSE;
2286 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2287 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2289 scanner = gtk_rc_scanner_new ();
2290 g_scanner_input_text (scanner, gstring->str, gstring->len);
2292 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2293 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2295 g_value_set_boxed (property_value, &requisition);
2299 g_scanner_destroy (scanner);
2305 * gtk_rc_property_parse_border:
2306 * @pspec: a #GParamSpec
2307 * @gstring: the #GString to be parsed
2308 * @property_value: a #GValue which must hold boxed values.
2310 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2311 * or gtk_widget_class_install_style_property_parser() which parses
2312 * borders in the form
2313 * <literal>"{ left, right, top, bottom }"</literal> for integers
2314 * %left, %right, %top and %bottom.
2316 * Return value: %TRUE if @gstring could be parsed and @property_value
2317 * has been set to the resulting #GtkBorder.
2320 gtk_rc_property_parse_border (const GParamSpec *pspec,
2321 const GString *gstring,
2322 GValue *property_value)
2326 gboolean success = FALSE;
2327 int left, right, top, bottom;
2329 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2330 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2332 scanner = gtk_rc_scanner_new ();
2333 g_scanner_input_text (scanner, gstring->str, gstring->len);
2335 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2336 get_braced_int (scanner, FALSE, FALSE, &right) &&
2337 get_braced_int (scanner, FALSE, FALSE, &top) &&
2338 get_braced_int (scanner, FALSE, TRUE, &bottom))
2341 border.right = right;
2343 border.bottom = bottom;
2344 g_value_set_boxed (property_value, &border);
2348 g_scanner_destroy (scanner);
2354 _gtk_settings_handle_event (GdkEventSetting *event)
2357 GtkSettings *settings;
2361 screen = gdk_window_get_screen (event->window);
2362 settings = gtk_settings_get_for_screen (screen);
2363 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2367 property_id = pspec->param_id;
2369 if (property_id == PROP_COLOR_SCHEME)
2371 GValue value = { 0, };
2373 g_value_init (&value, G_TYPE_STRING);
2374 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2375 g_value_set_static_string (&value, "");
2376 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2377 g_value_unset (&value);
2379 g_object_notify (G_OBJECT (settings), pspec->name);
2384 reset_rc_values_foreach (GQuark key_id,
2388 GtkSettingsValuePrivate *qvalue = data;
2389 GSList **to_reset = user_data;
2391 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2392 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2396 _gtk_settings_reset_rc_values (GtkSettings *settings)
2398 GtkSettingsPrivate *priv = settings->priv;
2399 GSList *to_reset = NULL;
2401 GParamSpec **pspecs, **p;
2404 /* Remove any queued settings */
2405 g_datalist_foreach (&priv->queued_settings,
2406 reset_rc_values_foreach,
2409 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2411 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2412 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2415 g_slist_free (to_reset);
2417 /* Now reset the active settings
2419 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2422 g_object_freeze_notify (G_OBJECT (settings));
2423 for (p = pspecs; *p; p++)
2425 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2427 GParamSpec *pspec = *p;
2429 g_param_value_set_default (pspec, &priv->property_values[i].value);
2430 g_object_notify (G_OBJECT (settings), pspec->name);
2434 g_object_thaw_notify (G_OBJECT (settings));
2439 settings_update_double_click (GtkSettings *settings)
2441 GtkSettingsPrivate *priv = settings->priv;
2443 if (gdk_screen_get_number (priv->screen) == 0)
2445 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2446 gint double_click_time;
2447 gint double_click_distance;
2449 g_object_get (settings,
2450 "gtk-double-click-time", &double_click_time,
2451 "gtk-double-click-distance", &double_click_distance,
2454 gdk_display_set_double_click_time (display, double_click_time);
2455 gdk_display_set_double_click_distance (display, double_click_distance);
2460 settings_update_modules (GtkSettings *settings)
2464 g_object_get (settings,
2465 "gtk-modules", &modules,
2468 _gtk_modules_settings_changed (settings, modules);
2474 settings_update_cursor_theme (GtkSettings *settings)
2476 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2477 gchar *theme = NULL;
2480 #ifdef GDK_WINDOWING_X11
2481 if (GDK_IS_X11_DISPLAY (display))
2483 g_object_get (settings,
2484 "gtk-cursor-theme-name", &theme,
2485 "gtk-cursor-theme-size", &size,
2488 gdk_x11_display_set_cursor_theme (display, theme, size);
2496 settings_update_font_options (GtkSettings *settings)
2498 GtkSettingsPrivate *priv = settings->priv;
2500 gchar *hint_style_str;
2501 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2503 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2505 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2506 cairo_font_options_t *options;
2508 g_object_get (settings,
2509 "gtk-xft-antialias", &antialias,
2510 "gtk-xft-hinting", &hinting,
2511 "gtk-xft-hintstyle", &hint_style_str,
2512 "gtk-xft-rgba", &rgba_str,
2515 options = cairo_font_options_create ();
2517 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2519 if (hinting >= 0 && !hinting)
2521 hint_style = CAIRO_HINT_STYLE_NONE;
2523 else if (hint_style_str)
2525 if (strcmp (hint_style_str, "hintnone") == 0)
2526 hint_style = CAIRO_HINT_STYLE_NONE;
2527 else if (strcmp (hint_style_str, "hintslight") == 0)
2528 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2529 else if (strcmp (hint_style_str, "hintmedium") == 0)
2530 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2531 else if (strcmp (hint_style_str, "hintfull") == 0)
2532 hint_style = CAIRO_HINT_STYLE_FULL;
2535 g_free (hint_style_str);
2537 cairo_font_options_set_hint_style (options, hint_style);
2541 if (strcmp (rgba_str, "rgb") == 0)
2542 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2543 else if (strcmp (rgba_str, "bgr") == 0)
2544 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2545 else if (strcmp (rgba_str, "vrgb") == 0)
2546 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2547 else if (strcmp (rgba_str, "vbgr") == 0)
2548 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2553 cairo_font_options_set_subpixel_order (options, subpixel_order);
2555 if (antialias >= 0 && !antialias)
2556 antialias_mode = CAIRO_ANTIALIAS_NONE;
2557 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2558 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2559 else if (antialias >= 0)
2560 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2562 cairo_font_options_set_antialias (options, antialias_mode);
2564 gdk_screen_set_font_options (priv->screen, options);
2566 cairo_font_options_destroy (options);
2570 settings_update_fontconfig (GtkSettings *settings)
2572 #ifdef GDK_WINDOWING_X11
2573 static guint last_update_timestamp;
2574 static gboolean last_update_needed;
2578 g_object_get (settings,
2579 "gtk-fontconfig-timestamp", ×tamp,
2582 /* if timestamp is the same as last_update_timestamp, we already have
2583 * updated fontconig on this timestamp (another screen requested it perhaps?),
2584 * just return the cached result.*/
2586 if (timestamp != last_update_timestamp)
2588 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2589 gboolean update_needed = FALSE;
2592 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2594 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2595 if (FcInitReinitialize ())
2596 update_needed = TRUE;
2599 last_update_timestamp = timestamp;
2600 last_update_needed = update_needed;
2603 return last_update_needed;
2604 #endif /* GDK_WINDOWING_X11 */
2608 settings_update_resolution (GtkSettings *settings)
2610 GtkSettingsPrivate *priv = settings->priv;
2614 g_object_get (settings,
2615 "gtk-xft-dpi", &dpi_int,
2619 dpi = dpi_int / 1024.;
2623 gdk_screen_set_resolution (priv->screen, dpi);
2628 GHashTable *color_hash;
2629 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2630 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2634 color_scheme_data_free (ColorSchemeData *data)
2638 g_hash_table_unref (data->color_hash);
2640 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2642 if (data->tables[i])
2643 g_hash_table_unref (data->tables[i]);
2644 g_free (data->lastentry[i]);
2647 g_slice_free (ColorSchemeData, data);
2651 settings_update_color_scheme (GtkSettings *settings)
2653 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2655 GtkSettingsPrivate *priv = settings->priv;
2656 ColorSchemeData *data;
2657 GValue value = { 0, };
2659 data = g_slice_new0 (ColorSchemeData);
2660 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2661 (GDestroyNotify) gdk_color_free);
2662 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2663 data, (GDestroyNotify) color_scheme_data_free);
2665 g_value_init (&value, G_TYPE_STRING);
2666 if (priv->screen && gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2668 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2669 g_value_unset (&value);
2675 settings_update_provider (GdkScreen *screen,
2676 GtkCssProvider **old,
2677 GtkCssProvider *new)
2683 gtk_style_context_remove_provider_for_screen (screen,
2684 GTK_STYLE_PROVIDER (*old));
2685 g_object_unref (*old);
2691 gtk_style_context_add_provider_for_screen (screen,
2692 GTK_STYLE_PROVIDER (new),
2693 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2694 *old = g_object_ref (new);
2700 settings_update_theme (GtkSettings *settings)
2702 GtkSettingsPrivate *priv = settings->priv;
2703 GtkCssProvider *provider = NULL;
2704 gboolean prefer_dark_theme;
2707 g_object_get (settings,
2708 "gtk-theme-name", &theme_name,
2709 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2712 if (theme_name && *theme_name)
2714 if (prefer_dark_theme)
2715 provider = gtk_css_provider_get_named (theme_name, "dark");
2718 provider = gtk_css_provider_get_named (theme_name, NULL);
2721 settings_update_provider (priv->screen, &priv->theme_provider, provider);
2723 if (theme_name && *theme_name)
2728 /* reload per-theme settings */
2729 theme_dir = _gtk_css_provider_get_theme_dir ();
2730 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2732 if (g_file_test (path, G_FILE_TEST_EXISTS))
2733 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2739 g_free (theme_name);
2743 settings_update_key_theme (GtkSettings *settings)
2745 GtkSettingsPrivate *priv = settings->priv;
2746 GtkCssProvider *provider = NULL;
2747 gchar *key_theme_name;
2749 g_object_get (settings,
2750 "gtk-key-theme-name", &key_theme_name,
2753 if (key_theme_name && *key_theme_name)
2754 provider = gtk_css_provider_get_named (key_theme_name, "keys");
2756 settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2757 g_free (key_theme_name);
2761 add_color_to_hash (gchar *name,
2767 old = g_hash_table_lookup (target, name);
2768 if (!old || !gdk_color_equal (old, color))
2770 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2779 add_colors_to_hash_from_string (GHashTable *hash,
2780 const gchar *colors)
2782 gchar *s, *p, *name;
2784 gboolean changed = FALSE;
2787 copy = g_strdup (colors);
2792 p = strchr (s, ':');
2807 if (*s == '\n' || *s == ';')
2816 if (gdk_color_parse (p, &color))
2817 changed |= add_color_to_hash (name, &color, hash);
2826 update_color_hash (ColorSchemeData *data,
2828 GtkSettingsSource source)
2830 gboolean changed = FALSE;
2832 GHashTable *old_hash;
2833 GHashTableIter iter;
2837 if ((str == NULL || *str == '\0') &&
2838 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2841 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2844 /* For the THEME source we merge the values rather than over-writing
2845 * them, since multiple rc files might define independent sets of colors
2847 if ((source != GTK_SETTINGS_SOURCE_THEME) &&
2848 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2850 g_hash_table_unref (data->tables[source]);
2851 data->tables[source] = NULL;
2852 changed = TRUE; /* We can't rely on the code below since str might be "" */
2855 if (data->tables[source] == NULL)
2856 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2858 (GDestroyNotify) gdk_color_free);
2860 g_free (data->lastentry[source]);
2861 data->lastentry[source] = g_strdup (str);
2863 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2868 /* Rebuild the merged hash table. */
2869 if (data->color_hash)
2871 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2872 (GDestroyNotify) gdk_color_free);
2874 g_hash_table_iter_init (&iter, data->color_hash);
2875 while (g_hash_table_iter_next (&iter, &name, &color))
2877 g_hash_table_insert (old_hash, name, color);
2878 g_hash_table_iter_steal (&iter);
2886 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2888 if (data->tables[i])
2889 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2895 /* now check if the merged hash has changed */
2897 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2901 GHashTableIter iter;
2902 gpointer key, value, new_value;
2904 g_hash_table_iter_init (&iter, old_hash);
2905 while (g_hash_table_iter_next (&iter, &key, &value))
2907 new_value = g_hash_table_lookup (data->color_hash, key);
2908 if (!new_value || !gdk_color_equal (value, new_value))
2916 g_hash_table_unref (old_hash);
2925 merge_color_scheme (GtkSettings *settings,
2926 const GValue *value,
2927 GtkSettingsSource source)
2929 ColorSchemeData *data;
2930 const gchar *colors;
2932 g_object_freeze_notify (G_OBJECT (settings));
2934 colors = g_value_get_string (value);
2936 settings_update_color_scheme (settings);
2938 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2939 "gtk-color-scheme");
2941 if (update_color_hash (data, colors, source))
2942 g_object_notify (G_OBJECT (settings), "color-hash");
2944 g_object_thaw_notify (G_OBJECT (settings));
2948 get_color_hash (GtkSettings *settings)
2950 ColorSchemeData *data;
2952 settings_update_color_scheme (settings);
2954 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2955 "gtk-color-scheme");
2957 return data->color_hash;
2961 append_color_scheme (gpointer key,
2965 gchar *name = (gchar *)key;
2966 GdkColor *color = (GdkColor *)value;
2967 GString *string = (GString *)data;
2969 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2970 name, color->red, color->green, color->blue);
2974 get_color_scheme (GtkSettings *settings)
2976 ColorSchemeData *data;
2979 settings_update_color_scheme (settings);
2981 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2982 "gtk-color-scheme");
2984 string = g_string_new ("");
2986 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2988 return g_string_free (string, FALSE);
2992 _gtk_settings_get_screen (GtkSettings *settings)
2994 return settings->priv->screen;
2999 gtk_settings_load_from_key_file (GtkSettings *settings,
3001 GtkSettingsSource source)
3012 keyfile = g_key_file_new ();
3014 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
3016 g_warning ("Failed to parse %s: %s", path, error->message);
3018 g_error_free (error);
3023 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3026 g_warning ("Failed to parse %s: %s", path, error->message);
3027 g_error_free (error);
3031 for (i = 0; i < n_keys; i++)
3036 GtkSettingsValue svalue = { NULL, { 0, }, };
3039 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3042 g_warning ("Unknown key %s in %s", key, path);
3046 if (pspec->owner_type != G_OBJECT_TYPE (settings))
3049 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3052 case G_TYPE_BOOLEAN:
3056 g_value_init (&svalue.value, G_TYPE_LONG);
3057 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3059 g_value_set_long (&svalue.value, b_val);
3067 g_value_init (&svalue.value, G_TYPE_LONG);
3068 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3070 g_value_set_long (&svalue.value, i_val);
3078 g_value_init (&svalue.value, G_TYPE_DOUBLE);
3079 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3081 g_value_set_double (&svalue.value, d_val);
3089 g_value_init (&svalue.value, G_TYPE_GSTRING);
3090 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3092 g_value_set_boxed (&svalue.value, g_string_new (s_val));
3099 g_warning ("Error setting %s in %s: %s", key, path, error->message);
3100 g_error_free (error);
3105 if (g_getenv ("GTK_DEBUG"))
3106 svalue.origin = (gchar *)path;
3107 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3108 g_value_unset (&svalue.value);
3114 g_key_file_free (keyfile);