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 "gtksettings.h"
28 #include "gtkmodules.h"
29 #include "gtkmodulesprivate.h"
30 #include "gtksettingsprivate.h"
32 #include "gtkwidget.h"
33 #include "gtkprivate.h"
34 #include "gtkcssproviderprivate.h"
35 #include "gtksymboliccolor.h"
36 #include "gtktypebuiltins.h"
37 #include "gtkversion.h"
39 #ifdef GDK_WINDOWING_X11
41 #include <pango/pangofc-fontmap.h>
44 #ifdef GDK_WINDOWING_QUARTZ
45 #include "quartz/gdkquartz.h"
48 #include "deprecated/gtkrc.h"
53 * @Short_description: Sharing settings between applications
56 * GtkSettings provide a mechanism to share global settings between
59 * On the X window system, this sharing is realized by an
60 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
61 * manager that is usually part of the desktop environment, along with
62 * utilities that let the user change these settings. In the absence of
63 * an Xsettings manager, GTK+ reads default values for settings from
64 * <filename>settings.ini</filename> files in
65 * <filename>/etc/gtk-3.0</filename> and <filename>$XDG_CONFIG_HOME/gtk-3.0</filename>. These files must be valid key files (see #GKeyFile), and have
66 * a section called Settings. Themes can also provide default values
67 * for settings by installing a <filename>settings.ini</filename> file
68 * next to their <filename>gtk.css</filename> file.
70 * Applications can override system-wide settings with
71 * gtk_settings_set_string_property(), gtk_settings_set_long_property(),
72 * etc. This should be restricted to special cases though; GtkSettings are
73 * not meant as an application configuration facility. When doing so, you
74 * need to be aware that settings that are specific to individual widgets
75 * may not be available before the widget type has been realized at least
76 * once. The following example demonstrates a way to do this:
77 * <informalexample><programlisting>
78 * gtk_init (&argc, &argv);
80 * /* make sure the type is realized */
81 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
83 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
84 * </programlisting></informalexample>
86 * There is one GtkSettings instance per screen. It can be obtained with
87 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
88 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
89 * GtkSettings instance for the default screen.
93 #define DEFAULT_TIMEOUT_INITIAL 200
94 #define DEFAULT_TIMEOUT_REPEAT 20
95 #define DEFAULT_TIMEOUT_EXPAND 500
97 typedef struct _GtkSettingsPropertyValue GtkSettingsPropertyValue;
98 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
100 struct _GtkSettingsPrivate
102 GData *queued_settings; /* of type GtkSettingsValue* */
103 GtkSettingsPropertyValue *property_values;
105 GtkCssProvider *theme_provider;
106 GtkCssProvider *key_theme_provider;
111 GTK_SETTINGS_SOURCE_DEFAULT,
112 GTK_SETTINGS_SOURCE_THEME,
113 GTK_SETTINGS_SOURCE_XSETTING,
114 GTK_SETTINGS_SOURCE_APPLICATION
117 struct _GtkSettingsValuePrivate
119 GtkSettingsValue public;
120 GtkSettingsSource source;
123 struct _GtkSettingsPropertyValue
126 GtkSettingsSource source;
131 PROP_DOUBLE_CLICK_TIME,
132 PROP_DOUBLE_CLICK_DISTANCE,
134 PROP_CURSOR_BLINK_TIME,
135 PROP_CURSOR_BLINK_TIMEOUT,
138 PROP_ICON_THEME_NAME,
139 PROP_FALLBACK_ICON_THEME,
142 PROP_DND_DRAG_THRESHOLD,
151 PROP_CURSOR_THEME_NAME,
152 PROP_CURSOR_THEME_SIZE,
153 PROP_ALTERNATIVE_BUTTON_ORDER,
154 PROP_ALTERNATIVE_SORT_ARROWS,
155 PROP_SHOW_INPUT_METHOD_MENU,
156 PROP_SHOW_UNICODE_MENU,
157 PROP_TIMEOUT_INITIAL,
161 PROP_ENABLE_ANIMATIONS,
162 PROP_TOUCHSCREEN_MODE,
163 PROP_TOOLTIP_TIMEOUT,
164 PROP_TOOLTIP_BROWSE_TIMEOUT,
165 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
166 PROP_KEYNAV_CURSOR_ONLY,
167 PROP_KEYNAV_WRAP_AROUND,
170 PROP_FILE_CHOOSER_BACKEND,
172 PROP_PRINT_PREVIEW_COMMAND,
173 PROP_ENABLE_MNEMONICS,
175 PROP_RECENT_FILES_LIMIT,
177 PROP_RECENT_FILES_MAX_AGE,
178 PROP_FONTCONFIG_TIMESTAMP,
179 PROP_SOUND_THEME_NAME,
180 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
181 PROP_ENABLE_EVENT_SOUNDS,
182 PROP_ENABLE_TOOLTIPS,
184 PROP_TOOLBAR_ICON_SIZE,
187 PROP_APPLICATION_PREFER_DARK_THEME,
189 PROP_ENTRY_SELECT_ON_FOCUS,
190 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
192 PROP_MENU_BAR_POPUP_DELAY,
193 PROP_SCROLLED_WINDOW_PLACEMENT,
194 PROP_CAN_CHANGE_ACCELS,
195 PROP_MENU_POPUP_DELAY,
196 PROP_MENU_POPDOWN_DELAY,
197 PROP_LABEL_SELECT_ON_FOCUS,
199 PROP_IM_PREEDIT_STYLE,
203 /* --- prototypes --- */
204 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
206 static void gtk_settings_finalize (GObject *object);
207 static void gtk_settings_get_property (GObject *object,
211 static void gtk_settings_set_property (GObject *object,
215 static void gtk_settings_notify (GObject *object,
217 static guint settings_install_property_parser (GtkSettingsClass *class,
219 GtkRcPropertyParser parser);
220 static void settings_update_double_click (GtkSettings *settings);
221 static void settings_update_modules (GtkSettings *settings);
223 static void settings_update_cursor_theme (GtkSettings *settings);
224 static void settings_update_resolution (GtkSettings *settings);
225 static void settings_update_font_options (GtkSettings *settings);
226 static gboolean settings_update_fontconfig (GtkSettings *settings);
227 static void settings_update_color_scheme (GtkSettings *settings);
228 static void settings_update_theme (GtkSettings *settings);
229 static void settings_update_key_theme (GtkSettings *settings);
231 static void merge_color_scheme (GtkSettings *settings,
233 GtkSettingsSource source);
234 static gchar *get_color_scheme (GtkSettings *settings);
235 static GHashTable *get_color_hash (GtkSettings *settings);
236 static void gtk_settings_load_from_key_file (GtkSettings *settings,
238 GtkSettingsSource source);
240 /* the default palette for GtkColorSelelection */
241 static const gchar default_color_palette[] =
242 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
243 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
245 /* --- variables --- */
246 static GQuark quark_property_parser = 0;
247 static GSList *object_list = NULL;
248 static guint class_n_properties = 0;
251 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
252 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
253 gtk_settings_provider_iface_init));
255 /* --- functions --- */
257 gtk_settings_init (GtkSettings *settings)
259 GtkSettingsPrivate *priv;
260 GParamSpec **pspecs, **p;
264 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
268 settings->priv = priv;
269 g_datalist_init (&priv->queued_settings);
270 object_list = g_slist_prepend (object_list, settings);
272 /* build up property array for all yet existing properties and queue
273 * notification for them (at least notification for internal properties
274 * will instantly be caught)
276 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
277 for (p = pspecs; *p; p++)
278 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
280 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
282 g_object_freeze_notify (G_OBJECT (settings));
284 for (p = pspecs; *p; p++)
286 GParamSpec *pspec = *p;
287 GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
289 if (pspec->owner_type != G_OBJECT_TYPE (settings))
291 g_value_init (&priv->property_values[i].value, value_type);
292 g_param_value_set_default (pspec, &priv->property_values[i].value);
294 g_object_notify (G_OBJECT (settings), pspec->name);
295 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
300 path = g_build_filename (_gtk_get_sysconfdir (), "gtk-3.0", "settings.ini", NULL);
301 if (g_file_test (path, G_FILE_TEST_EXISTS))
302 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
305 path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "settings.ini", NULL);
306 if (g_file_test (path, G_FILE_TEST_EXISTS))
307 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
310 g_object_thaw_notify (G_OBJECT (settings));
314 gtk_settings_class_init (GtkSettingsClass *class)
316 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
319 gobject_class->finalize = gtk_settings_finalize;
320 gobject_class->get_property = gtk_settings_get_property;
321 gobject_class->set_property = gtk_settings_set_property;
322 gobject_class->notify = gtk_settings_notify;
324 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
325 result = settings_install_property_parser (class,
326 g_param_spec_int ("gtk-double-click-time",
327 P_("Double Click Time"),
328 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
330 GTK_PARAM_READWRITE),
332 g_assert (result == PROP_DOUBLE_CLICK_TIME);
333 result = settings_install_property_parser (class,
334 g_param_spec_int ("gtk-double-click-distance",
335 P_("Double Click Distance"),
336 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
338 GTK_PARAM_READWRITE),
340 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
343 * GtkSettings:gtk-cursor-blink:
345 * Whether the cursor should blink.
347 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
348 * which allows more flexible control over cursor blinking.
350 result = settings_install_property_parser (class,
351 g_param_spec_boolean ("gtk-cursor-blink",
353 P_("Whether the cursor should blink"),
355 GTK_PARAM_READWRITE),
357 g_assert (result == PROP_CURSOR_BLINK);
358 result = settings_install_property_parser (class,
359 g_param_spec_int ("gtk-cursor-blink-time",
360 P_("Cursor Blink Time"),
361 P_("Length of the cursor blink cycle, in milliseconds"),
363 GTK_PARAM_READWRITE),
365 g_assert (result == PROP_CURSOR_BLINK_TIME);
368 * GtkSettings:gtk-cursor-blink-timeout:
370 * Time after which the cursor stops blinking, in seconds.
371 * The timer is reset after each user interaction.
373 * Setting this to zero has the same effect as setting
374 * #GtkSettings:gtk-cursor-blink to %FALSE.
378 result = settings_install_property_parser (class,
379 g_param_spec_int ("gtk-cursor-blink-timeout",
380 P_("Cursor Blink Timeout"),
381 P_("Time after which the cursor stops blinking, in seconds"),
382 1, G_MAXINT, G_MAXINT,
383 GTK_PARAM_READWRITE),
385 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
386 result = settings_install_property_parser (class,
387 g_param_spec_boolean ("gtk-split-cursor",
389 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
391 GTK_PARAM_READWRITE),
393 g_assert (result == PROP_SPLIT_CURSOR);
394 result = settings_install_property_parser (class,
395 g_param_spec_string ("gtk-theme-name",
397 P_("Name of theme to load"),
399 GTK_PARAM_READWRITE),
401 g_assert (result == PROP_THEME_NAME);
403 result = settings_install_property_parser (class,
404 g_param_spec_string ("gtk-icon-theme-name",
405 P_("Icon Theme Name"),
406 P_("Name of icon theme to use"),
408 GTK_PARAM_READWRITE),
410 g_assert (result == PROP_ICON_THEME_NAME);
412 result = settings_install_property_parser (class,
413 g_param_spec_string ("gtk-fallback-icon-theme",
414 P_("Fallback Icon Theme Name"),
415 P_("Name of a icon theme to fall back to"),
417 GTK_PARAM_READWRITE),
419 g_assert (result == PROP_FALLBACK_ICON_THEME);
421 result = settings_install_property_parser (class,
422 g_param_spec_string ("gtk-key-theme-name",
423 P_("Key Theme Name"),
424 P_("Name of key theme to load"),
426 GTK_PARAM_READWRITE),
428 g_assert (result == PROP_KEY_THEME_NAME);
430 result = settings_install_property_parser (class,
431 g_param_spec_string ("gtk-menu-bar-accel",
432 P_("Menu bar accelerator"),
433 P_("Keybinding to activate the menu bar"),
435 GTK_PARAM_READWRITE),
437 g_assert (result == PROP_MENU_BAR_ACCEL);
439 result = settings_install_property_parser (class,
440 g_param_spec_int ("gtk-dnd-drag-threshold",
441 P_("Drag threshold"),
442 P_("Number of pixels the cursor can move before dragging"),
444 GTK_PARAM_READWRITE),
446 g_assert (result == PROP_DND_DRAG_THRESHOLD);
448 result = settings_install_property_parser (class,
449 g_param_spec_string ("gtk-font-name",
451 P_("Name of default font to use"),
453 GTK_PARAM_READWRITE),
455 g_assert (result == PROP_FONT_NAME);
458 * GtkSettings:gtk-icon-sizes:
460 * A list of icon sizes. The list is separated by colons, and
463 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
465 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
466 * GTK+ itself use the following named icon sizes: gtk-menu,
467 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
468 * gtk-dialog. Applications can register their own named icon
469 * sizes with gtk_icon_size_register().
471 result = settings_install_property_parser (class,
472 g_param_spec_string ("gtk-icon-sizes",
474 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
476 GTK_PARAM_READWRITE),
478 g_assert (result == PROP_ICON_SIZES);
480 result = settings_install_property_parser (class,
481 g_param_spec_string ("gtk-modules",
483 P_("List of currently active GTK modules"),
485 GTK_PARAM_READWRITE),
487 g_assert (result == PROP_MODULES);
489 result = settings_install_property_parser (class,
490 g_param_spec_int ("gtk-xft-antialias",
492 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
494 GTK_PARAM_READWRITE),
497 g_assert (result == PROP_XFT_ANTIALIAS);
499 result = settings_install_property_parser (class,
500 g_param_spec_int ("gtk-xft-hinting",
502 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
504 GTK_PARAM_READWRITE),
507 g_assert (result == PROP_XFT_HINTING);
509 result = settings_install_property_parser (class,
510 g_param_spec_string ("gtk-xft-hintstyle",
511 P_("Xft Hint Style"),
512 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
514 GTK_PARAM_READWRITE),
517 g_assert (result == PROP_XFT_HINTSTYLE);
519 result = settings_install_property_parser (class,
520 g_param_spec_string ("gtk-xft-rgba",
522 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
524 GTK_PARAM_READWRITE),
527 g_assert (result == PROP_XFT_RGBA);
529 result = settings_install_property_parser (class,
530 g_param_spec_int ("gtk-xft-dpi",
532 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
534 GTK_PARAM_READWRITE),
537 g_assert (result == PROP_XFT_DPI);
539 result = settings_install_property_parser (class,
540 g_param_spec_string ("gtk-cursor-theme-name",
541 P_("Cursor theme name"),
542 P_("Name of the cursor theme to use, or NULL to use the default theme"),
544 GTK_PARAM_READWRITE),
546 g_assert (result == PROP_CURSOR_THEME_NAME);
548 result = settings_install_property_parser (class,
549 g_param_spec_int ("gtk-cursor-theme-size",
550 P_("Cursor theme size"),
551 P_("Size to use for cursors, or 0 to use the default size"),
553 GTK_PARAM_READWRITE),
556 g_assert (result == PROP_CURSOR_THEME_SIZE);
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.
950 * This also can be a colon-separated list of input methods, which GTK+
951 * will try in turn until it finds one available on the system.
953 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
955 result = settings_install_property_parser (class,
956 g_param_spec_string ("gtk-im-module",
957 P_("Default IM module"),
958 P_("Which IM module should be used by default"),
960 GTK_PARAM_READWRITE),
962 g_assert (result == PROP_IM_MODULE);
965 * GtkSettings:gtk-recent-files-max-age:
967 * The maximum age, in days, of the items inside the recently used
968 * resources list. Items older than this setting will be excised
969 * from the list. If set to 0, the list will always be empty; if
970 * set to -1, no item will be removed.
974 result = settings_install_property_parser (class,
975 g_param_spec_int ("gtk-recent-files-max-age",
976 P_("Recent Files Max Age"),
977 P_("Maximum age of recently used files, in days"),
980 GTK_PARAM_READWRITE),
982 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
984 result = settings_install_property_parser (class,
985 g_param_spec_uint ("gtk-fontconfig-timestamp",
986 P_("Fontconfig configuration timestamp"),
987 P_("Timestamp of current fontconfig configuration"),
989 GTK_PARAM_READWRITE),
992 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
995 * GtkSettings:gtk-sound-theme-name:
997 * The XDG sound theme to use for event sounds.
999 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1000 * for more information on event sounds and sound themes.
1002 * GTK+ itself does not support event sounds, you have to use a loadable
1003 * module like the one that comes with libcanberra.
1007 result = settings_install_property_parser (class,
1008 g_param_spec_string ("gtk-sound-theme-name",
1009 P_("Sound Theme Name"),
1010 P_("XDG sound theme name"),
1012 GTK_PARAM_READWRITE),
1014 g_assert (result == PROP_SOUND_THEME_NAME);
1017 * GtkSettings:gtk-enable-input-feedback-sounds:
1019 * Whether to play event sounds as feedback to user input.
1021 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1022 * for more information on event sounds and sound themes.
1024 * GTK+ itself does not support event sounds, you have to use a loadable
1025 * module like the one that comes with libcanberra.
1029 result = settings_install_property_parser (class,
1030 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1031 /* Translators: this means sounds that are played as feedback to user input */
1032 P_("Audible Input Feedback"),
1033 P_("Whether to play event sounds as feedback to user input"),
1035 GTK_PARAM_READWRITE),
1037 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1040 * GtkSettings:gtk-enable-event-sounds:
1042 * Whether to play any event sounds at all.
1044 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1045 * for more information on event sounds and sound themes.
1047 * GTK+ itself does not support event sounds, you have to use a loadable
1048 * module like the one that comes with libcanberra.
1052 result = settings_install_property_parser (class,
1053 g_param_spec_boolean ("gtk-enable-event-sounds",
1054 P_("Enable Event Sounds"),
1055 P_("Whether to play any event sounds at all"),
1057 GTK_PARAM_READWRITE),
1059 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1062 * GtkSettings:gtk-enable-tooltips:
1064 * Whether tooltips should be shown on widgets.
1068 result = settings_install_property_parser (class,
1069 g_param_spec_boolean ("gtk-enable-tooltips",
1070 P_("Enable Tooltips"),
1071 P_("Whether tooltips should be shown on widgets"),
1073 GTK_PARAM_READWRITE),
1075 g_assert (result == PROP_ENABLE_TOOLTIPS);
1078 * GtkSettings:gtk-toolbar-style:
1080 * The size of icons in default toolbars.
1082 result = settings_install_property_parser (class,
1083 g_param_spec_enum ("gtk-toolbar-style",
1084 P_("Toolbar style"),
1085 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1086 GTK_TYPE_TOOLBAR_STYLE,
1088 GTK_PARAM_READWRITE),
1089 gtk_rc_property_parse_enum);
1090 g_assert (result == PROP_TOOLBAR_STYLE);
1093 * GtkSettings:gtk-toolbar-icon-size:
1095 * The size of icons in default toolbars.
1097 result = settings_install_property_parser (class,
1098 g_param_spec_enum ("gtk-toolbar-icon-size",
1099 P_("Toolbar Icon Size"),
1100 P_("The size of icons in default toolbars."),
1102 GTK_ICON_SIZE_LARGE_TOOLBAR,
1103 GTK_PARAM_READWRITE),
1104 gtk_rc_property_parse_enum);
1105 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1108 * GtkSettings:gtk-auto-mnemonics:
1110 * Whether mnemonics should be automatically shown and hidden when the user
1111 * presses the mnemonic activator.
1115 result = settings_install_property_parser (class,
1116 g_param_spec_boolean ("gtk-auto-mnemonics",
1117 P_("Auto Mnemonics"),
1118 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1120 GTK_PARAM_READWRITE),
1122 g_assert (result == PROP_AUTO_MNEMONICS);
1125 * GtkSettings:gtk-visible-focus:
1127 * Whether 'focus rectangles' should be always visible, never visible,
1128 * or hidden until the user starts to use the keyboard.
1132 result = settings_install_property_parser (class,
1133 g_param_spec_enum ("gtk-visible-focus",
1134 P_("Visible Focus"),
1135 P_("Whether 'focus rectangles' should be hidden until the user starts to use the keyboard."),
1136 GTK_TYPE_POLICY_TYPE,
1138 GTK_PARAM_READWRITE),
1139 gtk_rc_property_parse_enum);
1140 g_assert (result == PROP_VISIBLE_FOCUS);
1143 * GtkSettings:gtk-application-prefer-dark-theme:
1145 * Whether the application prefers to use a dark theme. If a GTK+ theme
1146 * includes a dark variant, it will be used instead of the configured
1149 * Some applications benefit from minimizing the amount of light pollution that
1150 * interferes with the content. Good candidates for dark themes are photo and
1151 * video editors that make the actual content get all the attention and minimize
1152 * the distraction of the chrome.
1154 * Dark themes should not be used for documents, where large spaces are white/light
1155 * and the dark chrome creates too much contrast (web browser, text editor...).
1159 result = settings_install_property_parser (class,
1160 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1161 P_("Application prefers a dark theme"),
1162 P_("Whether the application prefers to have a dark theme."),
1164 GTK_PARAM_READWRITE),
1166 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1169 * GtkSettings::gtk-button-images:
1171 * Whether images should be shown on buttons
1175 result = settings_install_property_parser (class,
1176 g_param_spec_boolean ("gtk-button-images",
1177 P_("Show button images"),
1178 P_("Whether images should be shown on buttons"),
1180 GTK_PARAM_READWRITE),
1182 g_assert (result == PROP_BUTTON_IMAGES);
1184 result = settings_install_property_parser (class,
1185 g_param_spec_boolean ("gtk-entry-select-on-focus",
1186 P_("Select on focus"),
1187 P_("Whether to select the contents of an entry when it is focused"),
1189 GTK_PARAM_READWRITE),
1191 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1194 * GtkSettings:gtk-entry-password-hint-timeout:
1196 * How long to show the last input character in hidden
1197 * entries. This value is in milliseconds. 0 disables showing the
1198 * last char. 600 is a good value for enabling it.
1202 result = settings_install_property_parser (class,
1203 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1204 P_("Password Hint Timeout"),
1205 P_("How long to show the last input character in hidden entries"),
1208 GTK_PARAM_READWRITE),
1210 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1212 result = settings_install_property_parser (class,
1213 g_param_spec_boolean ("gtk-menu-images",
1214 P_("Show menu images"),
1215 P_("Whether images should be shown in menus"),
1217 GTK_PARAM_READWRITE),
1219 g_assert (result == PROP_MENU_IMAGES);
1221 result = settings_install_property_parser (class,
1222 g_param_spec_int ("gtk-menu-bar-popup-delay",
1223 P_("Delay before drop down menus appear"),
1224 P_("Delay before the submenus of a menu bar appear"),
1227 GTK_PARAM_READWRITE),
1229 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1232 * GtkSettings:gtk-scrolled-window-placement:
1234 * Where the contents of scrolled windows are located with respect to the
1235 * scrollbars, if not overridden by the scrolled window's own placement.
1239 result = settings_install_property_parser (class,
1240 g_param_spec_enum ("gtk-scrolled-window-placement",
1241 P_("Scrolled Window Placement"),
1242 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1243 GTK_TYPE_CORNER_TYPE,
1244 GTK_CORNER_TOP_LEFT,
1245 GTK_PARAM_READWRITE),
1246 gtk_rc_property_parse_enum);
1247 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1249 result = settings_install_property_parser (class,
1250 g_param_spec_boolean ("gtk-can-change-accels",
1251 P_("Can change accelerators"),
1252 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1254 GTK_PARAM_READWRITE),
1256 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1258 result = settings_install_property_parser (class,
1259 g_param_spec_int ("gtk-menu-popup-delay",
1260 P_("Delay before submenus appear"),
1261 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1264 GTK_PARAM_READWRITE),
1266 g_assert (result == PROP_MENU_POPUP_DELAY);
1268 result = settings_install_property_parser (class,
1269 g_param_spec_int ("gtk-menu-popdown-delay",
1270 P_("Delay before hiding a submenu"),
1271 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1274 GTK_PARAM_READWRITE),
1276 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1278 result = settings_install_property_parser (class,
1279 g_param_spec_boolean ("gtk-label-select-on-focus",
1280 P_("Select on focus"),
1281 P_("Whether to select the contents of a selectable label when it is focused"),
1283 GTK_PARAM_READWRITE),
1285 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1287 result = settings_install_property_parser (class,
1288 g_param_spec_string ("gtk-color-palette",
1289 P_("Custom palette"),
1290 P_("Palette to use in the color selector"),
1291 default_color_palette,
1292 GTK_PARAM_READWRITE),
1294 g_assert (result == PROP_COLOR_PALETTE);
1296 result = settings_install_property_parser (class,
1297 g_param_spec_enum ("gtk-im-preedit-style",
1298 P_("IM Preedit style"),
1299 P_("How to draw the input method preedit string"),
1300 GTK_TYPE_IM_PREEDIT_STYLE,
1301 GTK_IM_PREEDIT_CALLBACK,
1302 GTK_PARAM_READWRITE),
1303 gtk_rc_property_parse_enum);
1304 g_assert (result == PROP_IM_PREEDIT_STYLE);
1306 result = settings_install_property_parser (class,
1307 g_param_spec_enum ("gtk-im-status-style",
1308 P_("IM Status style"),
1309 P_("How to draw the input method statusbar"),
1310 GTK_TYPE_IM_STATUS_STYLE,
1311 GTK_IM_STATUS_CALLBACK,
1312 GTK_PARAM_READWRITE),
1313 gtk_rc_property_parse_enum);
1314 g_assert (result == PROP_IM_STATUS_STYLE);
1316 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1319 static GtkStyleProperties *
1320 gtk_settings_get_style (GtkStyleProvider *provider,
1321 GtkWidgetPath *path)
1323 PangoFontDescription *font_desc;
1324 gchar *font_name, *color_scheme;
1325 GtkSettings *settings;
1326 GtkStyleProperties *props;
1330 settings = GTK_SETTINGS (provider);
1331 props = gtk_style_properties_new ();
1333 g_object_get (settings,
1334 "gtk-font-name", &font_name,
1335 "gtk-color-scheme", &color_scheme,
1338 colors = g_strsplit_set (color_scheme, "\n;", -1);
1340 for (i = 0; colors[i]; i++)
1342 GtkSymbolicColor *color;
1350 pos = strchr (colors[i], ':');
1355 /* Set NUL after color name */
1359 /* Find start of color string */
1363 if (!*pos || !gdk_rgba_parse (&col, pos))
1366 color = gtk_symbolic_color_new_literal (&col);
1367 gtk_style_properties_map_color (props, name, color);
1368 gtk_symbolic_color_unref (color);
1371 font_desc = pango_font_description_from_string (font_name);
1373 /* Unset normal attributes from this description,
1374 * so they do not override theme values */
1375 if (pango_font_description_get_weight (font_desc) == PANGO_WEIGHT_NORMAL)
1376 pango_font_description_unset_fields (font_desc,
1377 PANGO_FONT_MASK_WEIGHT);
1379 if (pango_font_description_get_stretch (font_desc) == PANGO_STRETCH_NORMAL)
1380 pango_font_description_unset_fields (font_desc,
1381 PANGO_FONT_MASK_STRETCH);
1383 if (pango_font_description_get_variant (font_desc) == PANGO_VARIANT_NORMAL)
1384 pango_font_description_unset_fields (font_desc,
1385 PANGO_FONT_MASK_VARIANT);
1387 if (pango_font_description_get_style (font_desc) == PANGO_STYLE_NORMAL)
1388 pango_font_description_unset_fields (font_desc,
1389 PANGO_FONT_MASK_STYLE);
1391 gtk_style_properties_set (props, 0,
1395 pango_font_description_free (font_desc);
1396 g_strfreev (colors);
1397 g_free (color_scheme);
1404 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1406 iface->get_style = gtk_settings_get_style;
1410 gtk_settings_finalize (GObject *object)
1412 GtkSettings *settings = GTK_SETTINGS (object);
1413 GtkSettingsPrivate *priv = settings->priv;
1416 object_list = g_slist_remove (object_list, settings);
1418 for (i = 0; i < class_n_properties; i++)
1419 g_value_unset (&priv->property_values[i].value);
1420 g_free (priv->property_values);
1422 g_datalist_clear (&priv->queued_settings);
1424 if (priv->theme_provider)
1425 g_object_unref (priv->theme_provider);
1427 if (priv->key_theme_provider)
1428 g_object_unref (priv->key_theme_provider);
1430 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1434 settings_init_style (GtkSettings *settings)
1436 static GtkCssProvider *css_provider = NULL;
1438 GdkScreen *screen = settings->priv->screen;
1439 GtkCssProvider *default_provider;
1441 /* Add provider for user file */
1442 if (G_UNLIKELY (!css_provider))
1446 css_provider = gtk_css_provider_new ();
1447 css_path = g_build_filename (g_get_user_config_dir (),
1452 if (g_file_test (css_path,
1453 G_FILE_TEST_IS_REGULAR))
1454 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1459 gtk_style_context_add_provider_for_screen (screen,
1460 GTK_STYLE_PROVIDER (css_provider),
1461 GTK_STYLE_PROVIDER_PRIORITY_USER);
1463 default_provider = gtk_css_provider_get_default ();
1464 gtk_style_context_add_provider_for_screen (screen,
1465 GTK_STYLE_PROVIDER (default_provider),
1466 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1468 gtk_style_context_add_provider_for_screen (screen,
1469 GTK_STYLE_PROVIDER (settings),
1470 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1472 settings_update_theme (settings);
1473 settings_update_key_theme (settings);
1477 * gtk_settings_get_for_screen:
1478 * @screen: a #GdkScreen.
1480 * Gets the #GtkSettings object for @screen, creating it if necessary.
1482 * Return value: (transfer none): a #GtkSettings object.
1487 gtk_settings_get_for_screen (GdkScreen *screen)
1489 GtkSettings *settings;
1491 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1493 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1496 #ifdef GDK_WINDOWING_QUARTZ
1497 if (GDK_IS_QUARTZ_SCREEN (screen))
1498 settings = g_object_new (GTK_TYPE_SETTINGS, "gtk-key-theme-name", "Mac", NULL);
1501 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1502 settings->priv->screen = screen;
1503 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1504 settings, g_object_unref);
1506 settings_init_style (settings);
1507 settings_update_double_click (settings);
1508 settings_update_cursor_theme (settings);
1509 settings_update_resolution (settings);
1510 settings_update_font_options (settings);
1511 settings_update_color_scheme (settings);
1518 * gtk_settings_get_default:
1520 * Gets the #GtkSettings object for the default GDK screen, creating
1521 * it if necessary. See gtk_settings_get_for_screen().
1523 * Return value: (transfer none): a #GtkSettings object. If there is no default
1524 * screen, then returns %NULL.
1527 gtk_settings_get_default (void)
1529 GdkScreen *screen = gdk_screen_get_default ();
1532 return gtk_settings_get_for_screen (screen);
1538 gtk_settings_set_property (GObject *object,
1540 const GValue *value,
1543 GtkSettings *settings = GTK_SETTINGS (object);
1544 GtkSettingsPrivate *priv = settings->priv;
1546 g_value_copy (value, &priv->property_values[property_id - 1].value);
1547 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1549 if (pspec->param_id == PROP_COLOR_SCHEME)
1550 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1554 gtk_settings_get_property (GObject *object,
1559 GtkSettings *settings = GTK_SETTINGS (object);
1560 GtkSettingsPrivate *priv = settings->priv;
1561 GType value_type = G_VALUE_TYPE (value);
1562 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1564 /* handle internal properties */
1565 switch (property_id)
1567 case PROP_COLOR_HASH:
1568 g_value_set_boxed (value, get_color_hash (settings));
1570 case PROP_COLOR_SCHEME:
1571 g_value_take_string (value, get_color_scheme (settings));
1576 /* For enums and strings, we need to get the value as a string,
1577 * not as an int, since we support using names/nicks as the setting
1580 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1581 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1582 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1583 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1585 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1586 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1587 g_value_copy (&priv->property_values[property_id - 1].value, value);
1589 g_param_value_validate (pspec, value);
1593 GValue val = G_VALUE_INIT;
1595 /* Try to get xsetting as a string and parse it. */
1597 g_value_init (&val, G_TYPE_STRING);
1599 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1600 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1602 g_value_copy (&priv->property_values[property_id - 1].value, value);
1606 GValue tmp_value = G_VALUE_INIT;
1607 GValue gstring_value = G_VALUE_INIT;
1608 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1610 g_value_init (&gstring_value, G_TYPE_GSTRING);
1611 g_value_take_boxed (&gstring_value,
1612 g_string_new (g_value_get_string (&val)));
1614 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1616 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1619 g_value_copy (&tmp_value, value);
1620 g_param_value_validate (pspec, value);
1624 g_value_copy (&priv->property_values[property_id - 1].value, value);
1627 g_value_unset (&gstring_value);
1628 g_value_unset (&tmp_value);
1631 g_value_unset (&val);
1636 gtk_settings_notify (GObject *object,
1639 GtkSettings *settings = GTK_SETTINGS (object);
1640 GtkSettingsPrivate *priv = settings->priv;
1641 guint property_id = pspec->param_id;
1643 if (priv->screen == NULL) /* initialization */
1646 switch (property_id)
1649 settings_update_modules (settings);
1651 case PROP_DOUBLE_CLICK_TIME:
1652 case PROP_DOUBLE_CLICK_DISTANCE:
1653 settings_update_double_click (settings);
1655 case PROP_COLOR_SCHEME:
1656 settings_update_color_scheme (settings);
1657 gtk_style_context_reset_widgets (priv->screen);
1659 case PROP_FONT_NAME:
1660 gtk_style_context_reset_widgets (priv->screen);
1662 case PROP_KEY_THEME_NAME:
1663 settings_update_key_theme (settings);
1665 case PROP_THEME_NAME:
1666 case PROP_APPLICATION_PREFER_DARK_THEME:
1667 settings_update_theme (settings);
1670 settings_update_resolution (settings);
1671 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1672 * widgets with gtk_widget_style_set(), and also causes more
1673 * recomputation than necessary.
1675 gtk_style_context_reset_widgets (priv->screen);
1677 case PROP_XFT_ANTIALIAS:
1678 case PROP_XFT_HINTING:
1679 case PROP_XFT_HINTSTYLE:
1681 settings_update_font_options (settings);
1682 gtk_style_context_reset_widgets (priv->screen);
1684 case PROP_FONTCONFIG_TIMESTAMP:
1685 if (settings_update_fontconfig (settings))
1686 gtk_style_context_reset_widgets (priv->screen);
1688 case PROP_CURSOR_THEME_NAME:
1689 case PROP_CURSOR_THEME_SIZE:
1690 settings_update_cursor_theme (settings);
1696 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1697 const GValue *src_value,
1701 gboolean success = FALSE;
1703 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1708 gboolean free_gstring = TRUE;
1710 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1712 gstring = g_value_get_boxed (src_value);
1713 free_gstring = FALSE;
1715 else if (G_VALUE_HOLDS_LONG (src_value))
1717 gstring = g_string_new (NULL);
1718 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1720 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1722 gstring = g_string_new (NULL);
1723 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1725 else if (G_VALUE_HOLDS_STRING (src_value))
1727 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1729 gstring = g_string_new (NULL);
1730 g_string_append_c (gstring, '\"');
1731 g_string_append (gstring, tstr);
1732 g_string_append_c (gstring, '\"');
1737 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1738 gstring = NULL; /* silence compiler */
1741 success = (parser (pspec, gstring, dest_value) &&
1742 !g_param_value_validate (pspec, dest_value));
1745 g_string_free (gstring, TRUE);
1747 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1749 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1751 GString *gstring = g_value_get_boxed (src_value);
1753 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1754 success = !g_param_value_validate (pspec, dest_value);
1757 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1758 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1764 apply_queued_setting (GtkSettings *settings,
1766 GtkSettingsValuePrivate *qvalue)
1768 GtkSettingsPrivate *priv = settings->priv;
1769 GValue tmp_value = G_VALUE_INIT;
1770 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1772 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1773 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1776 if (pspec->param_id == PROP_COLOR_SCHEME)
1777 merge_color_scheme (settings, &tmp_value, qvalue->source);
1779 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1781 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1782 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1783 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1789 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1791 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1792 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1794 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1796 G_VALUE_TYPE_NAME (&tmp_value));
1799 g_value_unset (&tmp_value);
1803 settings_install_property_parser (GtkSettingsClass *class,
1805 GtkRcPropertyParser parser)
1807 GSList *node, *next;
1809 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1811 case G_TYPE_BOOLEAN:
1824 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1832 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1833 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1837 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1839 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1844 for (node = object_list; node; node = node->next)
1845 g_object_freeze_notify (node->data);
1847 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1848 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1850 for (node = object_list; node; node = node->next)
1852 GtkSettings *settings = node->data;
1853 GtkSettingsPrivate *priv = settings->priv;
1854 GtkSettingsValuePrivate *qvalue;
1856 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1857 priv->property_values[class_n_properties - 1].value.g_type = 0;
1858 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1859 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1860 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1861 g_object_notify (G_OBJECT (settings), pspec->name);
1863 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1865 apply_queued_setting (settings, pspec, qvalue);
1868 for (node = object_list; node; node = next)
1871 g_object_thaw_notify (node->data);
1874 return class_n_properties;
1878 _gtk_rc_property_parser_from_type (GType type)
1880 if (type == GDK_TYPE_COLOR)
1881 return gtk_rc_property_parse_color;
1882 else if (type == GTK_TYPE_REQUISITION)
1883 return gtk_rc_property_parse_requisition;
1884 else if (type == GTK_TYPE_BORDER)
1885 return gtk_rc_property_parse_border;
1886 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1887 return gtk_rc_property_parse_enum;
1888 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1889 return gtk_rc_property_parse_flags;
1895 gtk_settings_install_property (GParamSpec *pspec)
1897 static GtkSettingsClass *klass = NULL;
1899 GtkRcPropertyParser parser;
1901 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1904 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1906 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1908 settings_install_property_parser (klass, pspec, parser);
1912 * gtk_settings_install_property_parser:
1914 * @parser: (scope call):
1917 gtk_settings_install_property_parser (GParamSpec *pspec,
1918 GtkRcPropertyParser parser)
1920 static GtkSettingsClass *klass = NULL;
1922 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1923 g_return_if_fail (parser != NULL);
1926 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1928 settings_install_property_parser (klass, pspec, parser);
1932 free_value (gpointer data)
1934 GtkSettingsValuePrivate *qvalue = data;
1936 g_value_unset (&qvalue->public.value);
1937 g_free (qvalue->public.origin);
1938 g_slice_free (GtkSettingsValuePrivate, qvalue);
1942 gtk_settings_set_property_value_internal (GtkSettings *settings,
1943 const gchar *prop_name,
1944 const GtkSettingsValue *new_value,
1945 GtkSettingsSource source)
1947 GtkSettingsPrivate *priv = settings->priv;
1948 GtkSettingsValuePrivate *qvalue;
1953 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1954 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1955 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1956 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1958 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
1962 name = g_strdup (prop_name);
1963 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1964 name_quark = g_quark_from_string (name);
1967 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
1970 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1971 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
1975 g_free (qvalue->public.origin);
1976 g_value_unset (&qvalue->public.value);
1978 qvalue->public.origin = g_strdup (new_value->origin);
1979 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1980 g_value_copy (&new_value->value, &qvalue->public.value);
1981 qvalue->source = source;
1982 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1984 apply_queued_setting (settings, pspec, qvalue);
1988 gtk_settings_set_property_value (GtkSettings *settings,
1989 const gchar *prop_name,
1990 const GtkSettingsValue *new_value)
1992 g_return_if_fail (GTK_SETTINGS (settings));
1993 g_return_if_fail (prop_name != NULL);
1994 g_return_if_fail (new_value != NULL);
1996 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1997 GTK_SETTINGS_SOURCE_APPLICATION);
2001 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
2002 const gchar *prop_name,
2003 const GtkSettingsValue *new_value)
2005 g_return_if_fail (GTK_SETTINGS (settings));
2006 g_return_if_fail (prop_name != NULL);
2007 g_return_if_fail (new_value != NULL);
2009 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2010 GTK_SETTINGS_SOURCE_THEME);
2014 gtk_settings_set_string_property (GtkSettings *settings,
2016 const gchar *v_string,
2017 const gchar *origin)
2019 GtkSettingsValue svalue = { NULL, { 0, }, };
2021 g_return_if_fail (GTK_SETTINGS (settings));
2022 g_return_if_fail (name != NULL);
2023 g_return_if_fail (v_string != NULL);
2025 svalue.origin = (gchar*) origin;
2026 g_value_init (&svalue.value, G_TYPE_STRING);
2027 g_value_set_static_string (&svalue.value, v_string);
2028 gtk_settings_set_property_value (settings, name, &svalue);
2029 g_value_unset (&svalue.value);
2033 gtk_settings_set_long_property (GtkSettings *settings,
2036 const gchar *origin)
2038 GtkSettingsValue svalue = { NULL, { 0, }, };
2040 g_return_if_fail (GTK_SETTINGS (settings));
2041 g_return_if_fail (name != NULL);
2043 svalue.origin = (gchar*) origin;
2044 g_value_init (&svalue.value, G_TYPE_LONG);
2045 g_value_set_long (&svalue.value, v_long);
2046 gtk_settings_set_property_value (settings, name, &svalue);
2047 g_value_unset (&svalue.value);
2051 gtk_settings_set_double_property (GtkSettings *settings,
2054 const gchar *origin)
2056 GtkSettingsValue svalue = { NULL, { 0, }, };
2058 g_return_if_fail (GTK_SETTINGS (settings));
2059 g_return_if_fail (name != NULL);
2061 svalue.origin = (gchar*) origin;
2062 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2063 g_value_set_double (&svalue.value, v_double);
2064 gtk_settings_set_property_value (settings, name, &svalue);
2065 g_value_unset (&svalue.value);
2069 * gtk_rc_property_parse_color:
2070 * @pspec: a #GParamSpec
2071 * @gstring: the #GString to be parsed
2072 * @property_value: a #GValue which must hold #GdkColor values.
2074 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2075 * or gtk_widget_class_install_style_property_parser() which parses a
2076 * color given either by its name or in the form
2077 * <literal>{ red, green, blue }</literal> where %red, %green and
2078 * %blue are integers between 0 and 65535 or floating-point numbers
2081 * Return value: %TRUE if @gstring could be parsed and @property_value
2082 * has been set to the resulting #GdkColor.
2085 gtk_rc_property_parse_color (const GParamSpec *pspec,
2086 const GString *gstring,
2087 GValue *property_value)
2089 GdkColor color = { 0, 0, 0, 0, };
2093 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2094 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2096 scanner = gtk_rc_scanner_new ();
2097 g_scanner_input_text (scanner, gstring->str, gstring->len);
2098 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2099 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2101 g_value_set_boxed (property_value, &color);
2106 g_scanner_destroy (scanner);
2112 * gtk_rc_property_parse_enum:
2113 * @pspec: a #GParamSpec
2114 * @gstring: the #GString to be parsed
2115 * @property_value: a #GValue which must hold enum values.
2117 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2118 * or gtk_widget_class_install_style_property_parser() which parses a single
2119 * enumeration value.
2121 * The enumeration value can be specified by its name, its nickname or
2122 * its numeric value. For consistency with flags parsing, the value
2123 * may be surrounded by parentheses.
2125 * Return value: %TRUE if @gstring could be parsed and @property_value
2126 * has been set to the resulting #GEnumValue.
2129 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2130 const GString *gstring,
2131 GValue *property_value)
2133 gboolean need_closing_brace = FALSE, success = FALSE;
2135 GEnumValue *enum_value = NULL;
2137 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2138 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2140 scanner = gtk_rc_scanner_new ();
2141 g_scanner_input_text (scanner, gstring->str, gstring->len);
2143 /* we just want to parse _one_ value, but for consistency with flags parsing
2144 * we support optional parenthesis
2146 g_scanner_get_next_token (scanner);
2147 if (scanner->token == '(')
2149 need_closing_brace = TRUE;
2150 g_scanner_get_next_token (scanner);
2152 if (scanner->token == G_TOKEN_IDENTIFIER)
2154 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2156 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2158 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2161 g_value_set_enum (property_value, enum_value->value);
2165 else if (scanner->token == G_TOKEN_INT)
2167 g_value_set_enum (property_value, scanner->value.v_int);
2170 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2172 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2175 g_scanner_destroy (scanner);
2181 parse_flags_value (GScanner *scanner,
2185 g_scanner_get_next_token (scanner);
2186 if (scanner->token == G_TOKEN_IDENTIFIER)
2188 GFlagsValue *flags_value;
2190 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2192 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2195 *number |= flags_value->value;
2196 return G_TOKEN_NONE;
2199 else if (scanner->token == G_TOKEN_INT)
2201 *number |= scanner->value.v_int;
2202 return G_TOKEN_NONE;
2204 return G_TOKEN_IDENTIFIER;
2208 * gtk_rc_property_parse_flags:
2209 * @pspec: a #GParamSpec
2210 * @gstring: the #GString to be parsed
2211 * @property_value: a #GValue which must hold flags values.
2213 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2214 * or gtk_widget_class_install_style_property_parser() which parses flags.
2216 * Flags can be specified by their name, their nickname or
2217 * numerically. Multiple flags can be specified in the form
2218 * <literal>"( flag1 | flag2 | ... )"</literal>.
2220 * Return value: %TRUE if @gstring could be parsed and @property_value
2221 * has been set to the resulting flags value.
2224 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2225 const GString *gstring,
2226 GValue *property_value)
2229 gboolean success = FALSE;
2232 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2233 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2235 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2236 scanner = gtk_rc_scanner_new ();
2237 g_scanner_input_text (scanner, gstring->str, gstring->len);
2239 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2240 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2241 scanner->next_token == G_TOKEN_INT)
2243 guint token, flags_value = 0;
2245 token = parse_flags_value (scanner, class, &flags_value);
2247 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2250 g_value_set_flags (property_value, flags_value);
2254 else if (g_scanner_get_next_token (scanner) == '(')
2256 guint token, flags_value = 0;
2258 /* parse first value */
2259 token = parse_flags_value (scanner, class, &flags_value);
2261 /* parse nth values, preceeded by '|' */
2262 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2263 token = parse_flags_value (scanner, class, &flags_value);
2265 /* done, last token must have closed expression */
2266 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2267 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2269 g_value_set_flags (property_value, flags_value);
2273 g_scanner_destroy (scanner);
2279 get_braced_int (GScanner *scanner,
2286 g_scanner_get_next_token (scanner);
2287 if (scanner->token != '{')
2291 g_scanner_get_next_token (scanner);
2292 if (scanner->token != G_TOKEN_INT)
2295 *value = scanner->value.v_int;
2299 g_scanner_get_next_token (scanner);
2300 if (scanner->token != '}')
2305 g_scanner_get_next_token (scanner);
2306 if (scanner->token != ',')
2314 * gtk_rc_property_parse_requisition:
2315 * @pspec: a #GParamSpec
2316 * @gstring: the #GString to be parsed
2317 * @property_value: a #GValue which must hold boxed values.
2319 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2320 * or gtk_widget_class_install_style_property_parser() which parses a
2321 * requisition in the form
2322 * <literal>"{ width, height }"</literal> for integers %width and %height.
2324 * Return value: %TRUE if @gstring could be parsed and @property_value
2325 * has been set to the resulting #GtkRequisition.
2328 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2329 const GString *gstring,
2330 GValue *property_value)
2332 GtkRequisition requisition;
2334 gboolean success = FALSE;
2336 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2337 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2339 scanner = gtk_rc_scanner_new ();
2340 g_scanner_input_text (scanner, gstring->str, gstring->len);
2342 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2343 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2345 g_value_set_boxed (property_value, &requisition);
2349 g_scanner_destroy (scanner);
2355 * gtk_rc_property_parse_border:
2356 * @pspec: a #GParamSpec
2357 * @gstring: the #GString to be parsed
2358 * @property_value: a #GValue which must hold boxed values.
2360 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2361 * or gtk_widget_class_install_style_property_parser() which parses
2362 * borders in the form
2363 * <literal>"{ left, right, top, bottom }"</literal> for integers
2364 * %left, %right, %top and %bottom.
2366 * Return value: %TRUE if @gstring could be parsed and @property_value
2367 * has been set to the resulting #GtkBorder.
2370 gtk_rc_property_parse_border (const GParamSpec *pspec,
2371 const GString *gstring,
2372 GValue *property_value)
2376 gboolean success = FALSE;
2377 int left, right, top, bottom;
2379 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2380 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2382 scanner = gtk_rc_scanner_new ();
2383 g_scanner_input_text (scanner, gstring->str, gstring->len);
2385 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2386 get_braced_int (scanner, FALSE, FALSE, &right) &&
2387 get_braced_int (scanner, FALSE, FALSE, &top) &&
2388 get_braced_int (scanner, FALSE, TRUE, &bottom))
2391 border.right = right;
2393 border.bottom = bottom;
2394 g_value_set_boxed (property_value, &border);
2398 g_scanner_destroy (scanner);
2404 _gtk_settings_handle_event (GdkEventSetting *event)
2407 GtkSettings *settings;
2411 screen = gdk_window_get_screen (event->window);
2412 settings = gtk_settings_get_for_screen (screen);
2413 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2417 property_id = pspec->param_id;
2419 if (property_id == PROP_COLOR_SCHEME)
2421 GValue value = G_VALUE_INIT;
2423 g_value_init (&value, G_TYPE_STRING);
2424 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2425 g_value_set_static_string (&value, "");
2426 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2427 g_value_unset (&value);
2429 g_object_notify (G_OBJECT (settings), pspec->name);
2434 reset_rc_values_foreach (GQuark key_id,
2438 GtkSettingsValuePrivate *qvalue = data;
2439 GSList **to_reset = user_data;
2441 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2442 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2446 _gtk_settings_reset_rc_values (GtkSettings *settings)
2448 GtkSettingsPrivate *priv = settings->priv;
2449 GSList *to_reset = NULL;
2451 GParamSpec **pspecs, **p;
2454 /* Remove any queued settings */
2455 g_datalist_foreach (&priv->queued_settings,
2456 reset_rc_values_foreach,
2459 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2461 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2462 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2465 g_slist_free (to_reset);
2467 /* Now reset the active settings
2469 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2472 g_object_freeze_notify (G_OBJECT (settings));
2473 for (p = pspecs; *p; p++)
2475 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2477 GParamSpec *pspec = *p;
2479 g_param_value_set_default (pspec, &priv->property_values[i].value);
2480 g_object_notify (G_OBJECT (settings), pspec->name);
2484 g_object_thaw_notify (G_OBJECT (settings));
2489 settings_update_double_click (GtkSettings *settings)
2491 GtkSettingsPrivate *priv = settings->priv;
2493 if (gdk_screen_get_number (priv->screen) == 0)
2495 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2496 gint double_click_time;
2497 gint double_click_distance;
2499 g_object_get (settings,
2500 "gtk-double-click-time", &double_click_time,
2501 "gtk-double-click-distance", &double_click_distance,
2504 gdk_display_set_double_click_time (display, double_click_time);
2505 gdk_display_set_double_click_distance (display, double_click_distance);
2510 settings_update_modules (GtkSettings *settings)
2514 g_object_get (settings,
2515 "gtk-modules", &modules,
2518 _gtk_modules_settings_changed (settings, modules);
2524 settings_update_cursor_theme (GtkSettings *settings)
2526 #ifdef GDK_WINDOWING_X11
2527 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2528 gchar *theme = NULL;
2531 if (GDK_IS_X11_DISPLAY (display))
2533 g_object_get (settings,
2534 "gtk-cursor-theme-name", &theme,
2535 "gtk-cursor-theme-size", &size,
2538 gdk_x11_display_set_cursor_theme (display, theme, size);
2546 settings_update_font_options (GtkSettings *settings)
2548 GtkSettingsPrivate *priv = settings->priv;
2550 gchar *hint_style_str;
2551 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2553 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2555 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2556 cairo_font_options_t *options;
2558 g_object_get (settings,
2559 "gtk-xft-antialias", &antialias,
2560 "gtk-xft-hinting", &hinting,
2561 "gtk-xft-hintstyle", &hint_style_str,
2562 "gtk-xft-rgba", &rgba_str,
2565 options = cairo_font_options_create ();
2567 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2569 if (hinting >= 0 && !hinting)
2571 hint_style = CAIRO_HINT_STYLE_NONE;
2573 else if (hint_style_str)
2575 if (strcmp (hint_style_str, "hintnone") == 0)
2576 hint_style = CAIRO_HINT_STYLE_NONE;
2577 else if (strcmp (hint_style_str, "hintslight") == 0)
2578 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2579 else if (strcmp (hint_style_str, "hintmedium") == 0)
2580 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2581 else if (strcmp (hint_style_str, "hintfull") == 0)
2582 hint_style = CAIRO_HINT_STYLE_FULL;
2585 g_free (hint_style_str);
2587 cairo_font_options_set_hint_style (options, hint_style);
2591 if (strcmp (rgba_str, "rgb") == 0)
2592 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2593 else if (strcmp (rgba_str, "bgr") == 0)
2594 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2595 else if (strcmp (rgba_str, "vrgb") == 0)
2596 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2597 else if (strcmp (rgba_str, "vbgr") == 0)
2598 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2603 cairo_font_options_set_subpixel_order (options, subpixel_order);
2605 if (antialias >= 0 && !antialias)
2606 antialias_mode = CAIRO_ANTIALIAS_NONE;
2607 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2608 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2609 else if (antialias >= 0)
2610 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2612 cairo_font_options_set_antialias (options, antialias_mode);
2614 gdk_screen_set_font_options (priv->screen, options);
2616 cairo_font_options_destroy (options);
2620 settings_update_fontconfig (GtkSettings *settings)
2622 #ifdef GDK_WINDOWING_X11
2623 static guint last_update_timestamp;
2624 static gboolean last_update_needed;
2628 g_object_get (settings,
2629 "gtk-fontconfig-timestamp", ×tamp,
2632 /* if timestamp is the same as last_update_timestamp, we already have
2633 * updated fontconig on this timestamp (another screen requested it perhaps?),
2634 * just return the cached result.*/
2636 if (timestamp != last_update_timestamp)
2638 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2639 gboolean update_needed = FALSE;
2642 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2644 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2645 if (FcInitReinitialize ())
2646 update_needed = TRUE;
2649 last_update_timestamp = timestamp;
2650 last_update_needed = update_needed;
2653 return last_update_needed;
2656 #endif /* GDK_WINDOWING_X11 */
2660 settings_update_resolution (GtkSettings *settings)
2662 GtkSettingsPrivate *priv = settings->priv;
2666 g_object_get (settings,
2667 "gtk-xft-dpi", &dpi_int,
2671 dpi = dpi_int / 1024.;
2675 gdk_screen_set_resolution (priv->screen, dpi);
2680 GHashTable *color_hash;
2681 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2682 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2686 color_scheme_data_free (ColorSchemeData *data)
2690 g_hash_table_unref (data->color_hash);
2692 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2694 if (data->tables[i])
2695 g_hash_table_unref (data->tables[i]);
2696 g_free (data->lastentry[i]);
2699 g_slice_free (ColorSchemeData, data);
2703 settings_update_color_scheme (GtkSettings *settings)
2705 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2707 GtkSettingsPrivate *priv = settings->priv;
2708 ColorSchemeData *data;
2709 GValue value = G_VALUE_INIT;
2711 data = g_slice_new0 (ColorSchemeData);
2712 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2713 (GDestroyNotify) gdk_color_free);
2714 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2715 data, (GDestroyNotify) color_scheme_data_free);
2717 g_value_init (&value, G_TYPE_STRING);
2718 if (priv->screen && gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2720 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2721 g_value_unset (&value);
2727 settings_update_provider (GdkScreen *screen,
2728 GtkCssProvider **old,
2729 GtkCssProvider *new)
2735 gtk_style_context_remove_provider_for_screen (screen,
2736 GTK_STYLE_PROVIDER (*old));
2737 g_object_unref (*old);
2743 gtk_style_context_add_provider_for_screen (screen,
2744 GTK_STYLE_PROVIDER (new),
2745 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2746 *old = g_object_ref (new);
2752 settings_update_theme (GtkSettings *settings)
2754 GtkSettingsPrivate *priv = settings->priv;
2755 GtkCssProvider *provider = NULL;
2756 gboolean prefer_dark_theme;
2759 g_object_get (settings,
2760 "gtk-theme-name", &theme_name,
2761 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2764 if (theme_name && *theme_name)
2766 if (prefer_dark_theme)
2767 provider = gtk_css_provider_get_named (theme_name, "dark");
2770 provider = gtk_css_provider_get_named (theme_name, NULL);
2773 settings_update_provider (priv->screen, &priv->theme_provider, provider);
2775 if (theme_name && *theme_name)
2780 /* reload per-theme settings */
2781 theme_dir = _gtk_css_provider_get_theme_dir ();
2782 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2784 if (g_file_test (path, G_FILE_TEST_EXISTS))
2785 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2791 g_free (theme_name);
2795 settings_update_key_theme (GtkSettings *settings)
2797 GtkSettingsPrivate *priv = settings->priv;
2798 GtkCssProvider *provider = NULL;
2799 gchar *key_theme_name;
2801 g_object_get (settings,
2802 "gtk-key-theme-name", &key_theme_name,
2805 if (key_theme_name && *key_theme_name)
2806 provider = gtk_css_provider_get_named (key_theme_name, "keys");
2808 settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2809 g_free (key_theme_name);
2813 add_color_to_hash (gchar *name,
2819 old = g_hash_table_lookup (target, name);
2820 if (!old || !gdk_color_equal (old, color))
2822 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2831 add_colors_to_hash_from_string (GHashTable *hash,
2832 const gchar *colors)
2834 gchar *s, *p, *name;
2836 gboolean changed = FALSE;
2839 copy = g_strdup (colors);
2844 p = strchr (s, ':');
2859 if (*s == '\n' || *s == ';')
2868 if (gdk_color_parse (p, &color))
2869 changed |= add_color_to_hash (name, &color, hash);
2878 update_color_hash (ColorSchemeData *data,
2880 GtkSettingsSource source)
2882 gboolean changed = FALSE;
2884 GHashTable *old_hash;
2885 GHashTableIter iter;
2889 if ((str == NULL || *str == '\0') &&
2890 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2893 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2896 /* For the THEME source we merge the values rather than over-writing
2897 * them, since multiple rc files might define independent sets of colors
2899 if ((source != GTK_SETTINGS_SOURCE_THEME) &&
2900 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2902 g_hash_table_unref (data->tables[source]);
2903 data->tables[source] = NULL;
2904 changed = TRUE; /* We can't rely on the code below since str might be "" */
2907 if (data->tables[source] == NULL)
2908 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2910 (GDestroyNotify) gdk_color_free);
2912 g_free (data->lastentry[source]);
2913 data->lastentry[source] = g_strdup (str);
2915 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2920 /* Rebuild the merged hash table. */
2921 if (data->color_hash)
2923 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2924 (GDestroyNotify) gdk_color_free);
2926 g_hash_table_iter_init (&iter, data->color_hash);
2927 while (g_hash_table_iter_next (&iter, &name, &color))
2929 g_hash_table_insert (old_hash, name, color);
2930 g_hash_table_iter_steal (&iter);
2938 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2940 if (data->tables[i])
2941 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2947 /* now check if the merged hash has changed */
2949 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2953 GHashTableIter iter;
2954 gpointer key, value, new_value;
2956 g_hash_table_iter_init (&iter, old_hash);
2957 while (g_hash_table_iter_next (&iter, &key, &value))
2959 new_value = g_hash_table_lookup (data->color_hash, key);
2960 if (!new_value || !gdk_color_equal (value, new_value))
2968 g_hash_table_unref (old_hash);
2977 merge_color_scheme (GtkSettings *settings,
2978 const GValue *value,
2979 GtkSettingsSource source)
2981 ColorSchemeData *data;
2982 const gchar *colors;
2984 g_object_freeze_notify (G_OBJECT (settings));
2986 colors = g_value_get_string (value);
2988 settings_update_color_scheme (settings);
2990 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2991 "gtk-color-scheme");
2993 if (update_color_hash (data, colors, source))
2994 g_object_notify (G_OBJECT (settings), "color-hash");
2996 g_object_thaw_notify (G_OBJECT (settings));
3000 get_color_hash (GtkSettings *settings)
3002 ColorSchemeData *data;
3004 settings_update_color_scheme (settings);
3006 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
3007 "gtk-color-scheme");
3009 return data->color_hash;
3013 append_color_scheme (gpointer key,
3017 gchar *name = (gchar *)key;
3018 GdkColor *color = (GdkColor *)value;
3019 GString *string = (GString *)data;
3021 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
3022 name, color->red, color->green, color->blue);
3026 get_color_scheme (GtkSettings *settings)
3028 ColorSchemeData *data;
3031 settings_update_color_scheme (settings);
3033 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
3034 "gtk-color-scheme");
3036 string = g_string_new ("");
3038 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
3040 return g_string_free (string, FALSE);
3044 _gtk_settings_get_screen (GtkSettings *settings)
3046 return settings->priv->screen;
3051 gtk_settings_load_from_key_file (GtkSettings *settings,
3053 GtkSettingsSource source)
3064 keyfile = g_key_file_new ();
3066 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
3068 g_warning ("Failed to parse %s: %s", path, error->message);
3070 g_error_free (error);
3075 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3078 g_warning ("Failed to parse %s: %s", path, error->message);
3079 g_error_free (error);
3083 for (i = 0; i < n_keys; i++)
3088 GtkSettingsValue svalue = { NULL, { 0, }, };
3091 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3094 g_warning ("Unknown key %s in %s", key, path);
3098 if (pspec->owner_type != G_OBJECT_TYPE (settings))
3101 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3104 case G_TYPE_BOOLEAN:
3108 g_value_init (&svalue.value, G_TYPE_LONG);
3109 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3111 g_value_set_long (&svalue.value, b_val);
3119 g_value_init (&svalue.value, G_TYPE_LONG);
3120 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3122 g_value_set_long (&svalue.value, i_val);
3130 g_value_init (&svalue.value, G_TYPE_DOUBLE);
3131 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3133 g_value_set_double (&svalue.value, d_val);
3141 g_value_init (&svalue.value, G_TYPE_GSTRING);
3142 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3144 g_value_take_boxed (&svalue.value, g_string_new (s_val));
3151 g_warning ("Error setting %s in %s: %s", key, path, error->message);
3152 g_error_free (error);
3157 if (g_getenv ("GTK_DEBUG"))
3158 svalue.origin = (gchar *)path;
3159 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3160 g_value_unset (&svalue.value);
3166 g_key_file_free (keyfile);