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.
951 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
953 result = settings_install_property_parser (class,
954 g_param_spec_string ("gtk-im-module",
955 P_("Default IM module"),
956 P_("Which IM module should be used by default"),
958 GTK_PARAM_READWRITE),
960 g_assert (result == PROP_IM_MODULE);
963 * GtkSettings:gtk-recent-files-max-age:
965 * The maximum age, in days, of the items inside the recently used
966 * resources list. Items older than this setting will be excised
967 * from the list. If set to 0, the list will always be empty; if
968 * set to -1, no item will be removed.
972 result = settings_install_property_parser (class,
973 g_param_spec_int ("gtk-recent-files-max-age",
974 P_("Recent Files Max Age"),
975 P_("Maximum age of recently used files, in days"),
978 GTK_PARAM_READWRITE),
980 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
982 result = settings_install_property_parser (class,
983 g_param_spec_uint ("gtk-fontconfig-timestamp",
984 P_("Fontconfig configuration timestamp"),
985 P_("Timestamp of current fontconfig configuration"),
987 GTK_PARAM_READWRITE),
990 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
993 * GtkSettings:gtk-sound-theme-name:
995 * The XDG sound theme to use for event sounds.
997 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
998 * for more information on event sounds and sound themes.
1000 * GTK+ itself does not support event sounds, you have to use a loadable
1001 * module like the one that comes with libcanberra.
1005 result = settings_install_property_parser (class,
1006 g_param_spec_string ("gtk-sound-theme-name",
1007 P_("Sound Theme Name"),
1008 P_("XDG sound theme name"),
1010 GTK_PARAM_READWRITE),
1012 g_assert (result == PROP_SOUND_THEME_NAME);
1015 * GtkSettings:gtk-enable-input-feedback-sounds:
1017 * Whether to play event sounds as feedback to user input.
1019 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1020 * for more information on event sounds and sound themes.
1022 * GTK+ itself does not support event sounds, you have to use a loadable
1023 * module like the one that comes with libcanberra.
1027 result = settings_install_property_parser (class,
1028 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1029 /* Translators: this means sounds that are played as feedback to user input */
1030 P_("Audible Input Feedback"),
1031 P_("Whether to play event sounds as feedback to user input"),
1033 GTK_PARAM_READWRITE),
1035 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1038 * GtkSettings:gtk-enable-event-sounds:
1040 * Whether to play any event sounds at all.
1042 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1043 * for more information on event sounds and sound themes.
1045 * GTK+ itself does not support event sounds, you have to use a loadable
1046 * module like the one that comes with libcanberra.
1050 result = settings_install_property_parser (class,
1051 g_param_spec_boolean ("gtk-enable-event-sounds",
1052 P_("Enable Event Sounds"),
1053 P_("Whether to play any event sounds at all"),
1055 GTK_PARAM_READWRITE),
1057 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1060 * GtkSettings:gtk-enable-tooltips:
1062 * Whether tooltips should be shown on widgets.
1066 result = settings_install_property_parser (class,
1067 g_param_spec_boolean ("gtk-enable-tooltips",
1068 P_("Enable Tooltips"),
1069 P_("Whether tooltips should be shown on widgets"),
1071 GTK_PARAM_READWRITE),
1073 g_assert (result == PROP_ENABLE_TOOLTIPS);
1076 * GtkSettings:gtk-toolbar-style:
1078 * The size of icons in default toolbars.
1080 result = settings_install_property_parser (class,
1081 g_param_spec_enum ("gtk-toolbar-style",
1082 P_("Toolbar style"),
1083 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1084 GTK_TYPE_TOOLBAR_STYLE,
1086 GTK_PARAM_READWRITE),
1087 gtk_rc_property_parse_enum);
1088 g_assert (result == PROP_TOOLBAR_STYLE);
1091 * GtkSettings:gtk-toolbar-icon-size:
1093 * The size of icons in default toolbars.
1095 result = settings_install_property_parser (class,
1096 g_param_spec_enum ("gtk-toolbar-icon-size",
1097 P_("Toolbar Icon Size"),
1098 P_("The size of icons in default toolbars."),
1100 GTK_ICON_SIZE_LARGE_TOOLBAR,
1101 GTK_PARAM_READWRITE),
1102 gtk_rc_property_parse_enum);
1103 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1106 * GtkSettings:gtk-auto-mnemonics:
1108 * Whether mnemonics should be automatically shown and hidden when the user
1109 * presses the mnemonic activator.
1113 result = settings_install_property_parser (class,
1114 g_param_spec_boolean ("gtk-auto-mnemonics",
1115 P_("Auto Mnemonics"),
1116 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1118 GTK_PARAM_READWRITE),
1120 g_assert (result == PROP_AUTO_MNEMONICS);
1123 * GtkSettings:gtk-visible-focus:
1125 * Whether 'focus rectangles' should be always visible, never visible,
1126 * or hidden until the user starts to use the keyboard.
1130 result = settings_install_property_parser (class,
1131 g_param_spec_enum ("gtk-visible-focus",
1132 P_("Visible Focus"),
1133 P_("Whether 'focus rectangles' should be hidden until the user starts to use the keyboard."),
1134 GTK_TYPE_POLICY_TYPE,
1136 GTK_PARAM_READWRITE),
1137 gtk_rc_property_parse_enum);
1138 g_assert (result == PROP_VISIBLE_FOCUS);
1141 * GtkSettings:gtk-application-prefer-dark-theme:
1143 * Whether the application prefers to use a dark theme. If a GTK+ theme
1144 * includes a dark variant, it will be used instead of the configured
1147 * Some applications benefit from minimizing the amount of light pollution that
1148 * interferes with the content. Good candidates for dark themes are photo and
1149 * video editors that make the actual content get all the attention and minimize
1150 * the distraction of the chrome.
1152 * Dark themes should not be used for documents, where large spaces are white/light
1153 * and the dark chrome creates too much contrast (web browser, text editor...).
1157 result = settings_install_property_parser (class,
1158 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1159 P_("Application prefers a dark theme"),
1160 P_("Whether the application prefers to have a dark theme."),
1162 GTK_PARAM_READWRITE),
1164 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1167 * GtkSettings::gtk-button-images:
1169 * Whether images should be shown on buttons
1173 result = settings_install_property_parser (class,
1174 g_param_spec_boolean ("gtk-button-images",
1175 P_("Show button images"),
1176 P_("Whether images should be shown on buttons"),
1178 GTK_PARAM_READWRITE),
1180 g_assert (result == PROP_BUTTON_IMAGES);
1182 result = settings_install_property_parser (class,
1183 g_param_spec_boolean ("gtk-entry-select-on-focus",
1184 P_("Select on focus"),
1185 P_("Whether to select the contents of an entry when it is focused"),
1187 GTK_PARAM_READWRITE),
1189 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1192 * GtkSettings:gtk-entry-password-hint-timeout:
1194 * How long to show the last input character in hidden
1195 * entries. This value is in milliseconds. 0 disables showing the
1196 * last char. 600 is a good value for enabling it.
1200 result = settings_install_property_parser (class,
1201 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1202 P_("Password Hint Timeout"),
1203 P_("How long to show the last input character in hidden entries"),
1206 GTK_PARAM_READWRITE),
1208 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1210 result = settings_install_property_parser (class,
1211 g_param_spec_boolean ("gtk-menu-images",
1212 P_("Show menu images"),
1213 P_("Whether images should be shown in menus"),
1215 GTK_PARAM_READWRITE),
1217 g_assert (result == PROP_MENU_IMAGES);
1219 result = settings_install_property_parser (class,
1220 g_param_spec_int ("gtk-menu-bar-popup-delay",
1221 P_("Delay before drop down menus appear"),
1222 P_("Delay before the submenus of a menu bar appear"),
1225 GTK_PARAM_READWRITE),
1227 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1230 * GtkSettings:gtk-scrolled-window-placement:
1232 * Where the contents of scrolled windows are located with respect to the
1233 * scrollbars, if not overridden by the scrolled window's own placement.
1237 result = settings_install_property_parser (class,
1238 g_param_spec_enum ("gtk-scrolled-window-placement",
1239 P_("Scrolled Window Placement"),
1240 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1241 GTK_TYPE_CORNER_TYPE,
1242 GTK_CORNER_TOP_LEFT,
1243 GTK_PARAM_READWRITE),
1244 gtk_rc_property_parse_enum);
1245 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1247 result = settings_install_property_parser (class,
1248 g_param_spec_boolean ("gtk-can-change-accels",
1249 P_("Can change accelerators"),
1250 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1252 GTK_PARAM_READWRITE),
1254 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1256 result = settings_install_property_parser (class,
1257 g_param_spec_int ("gtk-menu-popup-delay",
1258 P_("Delay before submenus appear"),
1259 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1262 GTK_PARAM_READWRITE),
1264 g_assert (result == PROP_MENU_POPUP_DELAY);
1266 result = settings_install_property_parser (class,
1267 g_param_spec_int ("gtk-menu-popdown-delay",
1268 P_("Delay before hiding a submenu"),
1269 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1272 GTK_PARAM_READWRITE),
1274 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1276 result = settings_install_property_parser (class,
1277 g_param_spec_boolean ("gtk-label-select-on-focus",
1278 P_("Select on focus"),
1279 P_("Whether to select the contents of a selectable label when it is focused"),
1281 GTK_PARAM_READWRITE),
1283 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1285 result = settings_install_property_parser (class,
1286 g_param_spec_string ("gtk-color-palette",
1287 P_("Custom palette"),
1288 P_("Palette to use in the color selector"),
1289 default_color_palette,
1290 GTK_PARAM_READWRITE),
1292 g_assert (result == PROP_COLOR_PALETTE);
1294 result = settings_install_property_parser (class,
1295 g_param_spec_enum ("gtk-im-preedit-style",
1296 P_("IM Preedit style"),
1297 P_("How to draw the input method preedit string"),
1298 GTK_TYPE_IM_PREEDIT_STYLE,
1299 GTK_IM_PREEDIT_CALLBACK,
1300 GTK_PARAM_READWRITE),
1301 gtk_rc_property_parse_enum);
1302 g_assert (result == PROP_IM_PREEDIT_STYLE);
1304 result = settings_install_property_parser (class,
1305 g_param_spec_enum ("gtk-im-status-style",
1306 P_("IM Status style"),
1307 P_("How to draw the input method statusbar"),
1308 GTK_TYPE_IM_STATUS_STYLE,
1309 GTK_IM_STATUS_CALLBACK,
1310 GTK_PARAM_READWRITE),
1311 gtk_rc_property_parse_enum);
1312 g_assert (result == PROP_IM_STATUS_STYLE);
1314 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1317 static GtkStyleProperties *
1318 gtk_settings_get_style (GtkStyleProvider *provider,
1319 GtkWidgetPath *path)
1321 PangoFontDescription *font_desc;
1322 gchar *font_name, *color_scheme;
1323 GtkSettings *settings;
1324 GtkStyleProperties *props;
1328 settings = GTK_SETTINGS (provider);
1329 props = gtk_style_properties_new ();
1331 g_object_get (settings,
1332 "gtk-font-name", &font_name,
1333 "gtk-color-scheme", &color_scheme,
1336 colors = g_strsplit_set (color_scheme, "\n;", -1);
1338 for (i = 0; colors[i]; i++)
1340 GtkSymbolicColor *color;
1348 pos = strchr (colors[i], ':');
1353 /* Set NUL after color name */
1357 /* Find start of color string */
1361 if (!*pos || !gdk_rgba_parse (&col, pos))
1364 color = gtk_symbolic_color_new_literal (&col);
1365 gtk_style_properties_map_color (props, name, color);
1366 gtk_symbolic_color_unref (color);
1369 font_desc = pango_font_description_from_string (font_name);
1371 /* Unset normal attributes from this description,
1372 * so they do not override theme values */
1373 if (pango_font_description_get_weight (font_desc) == PANGO_WEIGHT_NORMAL)
1374 pango_font_description_unset_fields (font_desc,
1375 PANGO_FONT_MASK_WEIGHT);
1377 if (pango_font_description_get_stretch (font_desc) == PANGO_STRETCH_NORMAL)
1378 pango_font_description_unset_fields (font_desc,
1379 PANGO_FONT_MASK_STRETCH);
1381 if (pango_font_description_get_variant (font_desc) == PANGO_VARIANT_NORMAL)
1382 pango_font_description_unset_fields (font_desc,
1383 PANGO_FONT_MASK_VARIANT);
1385 if (pango_font_description_get_style (font_desc) == PANGO_STYLE_NORMAL)
1386 pango_font_description_unset_fields (font_desc,
1387 PANGO_FONT_MASK_STYLE);
1389 gtk_style_properties_set (props, 0,
1393 pango_font_description_free (font_desc);
1394 g_strfreev (colors);
1395 g_free (color_scheme);
1402 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1404 iface->get_style = gtk_settings_get_style;
1408 gtk_settings_finalize (GObject *object)
1410 GtkSettings *settings = GTK_SETTINGS (object);
1411 GtkSettingsPrivate *priv = settings->priv;
1414 object_list = g_slist_remove (object_list, settings);
1416 for (i = 0; i < class_n_properties; i++)
1417 g_value_unset (&priv->property_values[i].value);
1418 g_free (priv->property_values);
1420 g_datalist_clear (&priv->queued_settings);
1422 if (priv->theme_provider)
1423 g_object_unref (priv->theme_provider);
1425 if (priv->key_theme_provider)
1426 g_object_unref (priv->key_theme_provider);
1428 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1432 settings_init_style (GtkSettings *settings)
1434 static GtkCssProvider *css_provider = NULL;
1436 GdkScreen *screen = settings->priv->screen;
1437 GtkCssProvider *default_provider;
1439 /* Add provider for user file */
1440 if (G_UNLIKELY (!css_provider))
1444 css_provider = gtk_css_provider_new ();
1445 css_path = g_build_filename (g_get_user_config_dir (),
1450 if (g_file_test (css_path,
1451 G_FILE_TEST_IS_REGULAR))
1452 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1457 gtk_style_context_add_provider_for_screen (screen,
1458 GTK_STYLE_PROVIDER (css_provider),
1459 GTK_STYLE_PROVIDER_PRIORITY_USER);
1461 default_provider = gtk_css_provider_get_default ();
1462 gtk_style_context_add_provider_for_screen (screen,
1463 GTK_STYLE_PROVIDER (default_provider),
1464 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1466 gtk_style_context_add_provider_for_screen (screen,
1467 GTK_STYLE_PROVIDER (settings),
1468 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1470 settings_update_theme (settings);
1471 settings_update_key_theme (settings);
1475 * gtk_settings_get_for_screen:
1476 * @screen: a #GdkScreen.
1478 * Gets the #GtkSettings object for @screen, creating it if necessary.
1480 * Return value: (transfer none): a #GtkSettings object.
1485 gtk_settings_get_for_screen (GdkScreen *screen)
1487 GtkSettings *settings;
1489 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1491 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1494 #ifdef GDK_WINDOWING_QUARTZ
1495 if (GDK_IS_QUARTZ_SCREEN (screen))
1496 settings = g_object_new (GTK_TYPE_SETTINGS, "gtk-key-theme-name", "Mac", NULL);
1499 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1500 settings->priv->screen = screen;
1501 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1502 settings, g_object_unref);
1504 settings_init_style (settings);
1505 settings_update_double_click (settings);
1506 settings_update_cursor_theme (settings);
1507 settings_update_resolution (settings);
1508 settings_update_font_options (settings);
1509 settings_update_color_scheme (settings);
1516 * gtk_settings_get_default:
1518 * Gets the #GtkSettings object for the default GDK screen, creating
1519 * it if necessary. See gtk_settings_get_for_screen().
1521 * Return value: (transfer none): a #GtkSettings object. If there is no default
1522 * screen, then returns %NULL.
1525 gtk_settings_get_default (void)
1527 GdkScreen *screen = gdk_screen_get_default ();
1530 return gtk_settings_get_for_screen (screen);
1536 gtk_settings_set_property (GObject *object,
1538 const GValue *value,
1541 GtkSettings *settings = GTK_SETTINGS (object);
1542 GtkSettingsPrivate *priv = settings->priv;
1544 g_value_copy (value, &priv->property_values[property_id - 1].value);
1545 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1547 if (pspec->param_id == PROP_COLOR_SCHEME)
1548 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1552 gtk_settings_get_property (GObject *object,
1557 GtkSettings *settings = GTK_SETTINGS (object);
1558 GtkSettingsPrivate *priv = settings->priv;
1559 GType value_type = G_VALUE_TYPE (value);
1560 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1562 /* handle internal properties */
1563 switch (property_id)
1565 case PROP_COLOR_HASH:
1566 g_value_set_boxed (value, get_color_hash (settings));
1568 case PROP_COLOR_SCHEME:
1569 g_value_take_string (value, get_color_scheme (settings));
1574 /* For enums and strings, we need to get the value as a string,
1575 * not as an int, since we support using names/nicks as the setting
1578 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1579 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1580 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1581 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1583 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1584 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1585 g_value_copy (&priv->property_values[property_id - 1].value, value);
1587 g_param_value_validate (pspec, value);
1591 GValue val = G_VALUE_INIT;
1593 /* Try to get xsetting as a string and parse it. */
1595 g_value_init (&val, G_TYPE_STRING);
1597 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1598 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1600 g_value_copy (&priv->property_values[property_id - 1].value, value);
1604 GValue tmp_value = G_VALUE_INIT;
1605 GValue gstring_value = G_VALUE_INIT;
1606 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1608 g_value_init (&gstring_value, G_TYPE_GSTRING);
1609 g_value_take_boxed (&gstring_value,
1610 g_string_new (g_value_get_string (&val)));
1612 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1614 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1617 g_value_copy (&tmp_value, value);
1618 g_param_value_validate (pspec, value);
1622 g_value_copy (&priv->property_values[property_id - 1].value, value);
1625 g_value_unset (&gstring_value);
1626 g_value_unset (&tmp_value);
1629 g_value_unset (&val);
1634 gtk_settings_notify (GObject *object,
1637 GtkSettings *settings = GTK_SETTINGS (object);
1638 GtkSettingsPrivate *priv = settings->priv;
1639 guint property_id = pspec->param_id;
1641 if (priv->screen == NULL) /* initialization */
1644 switch (property_id)
1647 settings_update_modules (settings);
1649 case PROP_DOUBLE_CLICK_TIME:
1650 case PROP_DOUBLE_CLICK_DISTANCE:
1651 settings_update_double_click (settings);
1653 case PROP_COLOR_SCHEME:
1654 settings_update_color_scheme (settings);
1655 gtk_style_context_reset_widgets (priv->screen);
1657 case PROP_FONT_NAME:
1658 gtk_style_context_reset_widgets (priv->screen);
1660 case PROP_KEY_THEME_NAME:
1661 settings_update_key_theme (settings);
1663 case PROP_THEME_NAME:
1664 case PROP_APPLICATION_PREFER_DARK_THEME:
1665 settings_update_theme (settings);
1668 settings_update_resolution (settings);
1669 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1670 * widgets with gtk_widget_style_set(), and also causes more
1671 * recomputation than necessary.
1673 gtk_style_context_reset_widgets (priv->screen);
1675 case PROP_XFT_ANTIALIAS:
1676 case PROP_XFT_HINTING:
1677 case PROP_XFT_HINTSTYLE:
1679 settings_update_font_options (settings);
1680 gtk_style_context_reset_widgets (priv->screen);
1682 case PROP_FONTCONFIG_TIMESTAMP:
1683 if (settings_update_fontconfig (settings))
1684 gtk_style_context_reset_widgets (priv->screen);
1686 case PROP_CURSOR_THEME_NAME:
1687 case PROP_CURSOR_THEME_SIZE:
1688 settings_update_cursor_theme (settings);
1694 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1695 const GValue *src_value,
1699 gboolean success = FALSE;
1701 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1706 gboolean free_gstring = TRUE;
1708 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1710 gstring = g_value_get_boxed (src_value);
1711 free_gstring = FALSE;
1713 else if (G_VALUE_HOLDS_LONG (src_value))
1715 gstring = g_string_new (NULL);
1716 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1718 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1720 gstring = g_string_new (NULL);
1721 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1723 else if (G_VALUE_HOLDS_STRING (src_value))
1725 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1727 gstring = g_string_new (NULL);
1728 g_string_append_c (gstring, '\"');
1729 g_string_append (gstring, tstr);
1730 g_string_append_c (gstring, '\"');
1735 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1736 gstring = NULL; /* silence compiler */
1739 success = (parser (pspec, gstring, dest_value) &&
1740 !g_param_value_validate (pspec, dest_value));
1743 g_string_free (gstring, TRUE);
1745 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1747 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1749 GString *gstring = g_value_get_boxed (src_value);
1751 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1752 success = !g_param_value_validate (pspec, dest_value);
1755 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1756 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1762 apply_queued_setting (GtkSettings *settings,
1764 GtkSettingsValuePrivate *qvalue)
1766 GtkSettingsPrivate *priv = settings->priv;
1767 GValue tmp_value = G_VALUE_INIT;
1768 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1770 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1771 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1774 if (pspec->param_id == PROP_COLOR_SCHEME)
1775 merge_color_scheme (settings, &tmp_value, qvalue->source);
1777 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1779 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1780 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1781 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1787 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1789 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1790 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1792 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1794 G_VALUE_TYPE_NAME (&tmp_value));
1797 g_value_unset (&tmp_value);
1801 settings_install_property_parser (GtkSettingsClass *class,
1803 GtkRcPropertyParser parser)
1805 GSList *node, *next;
1807 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1809 case G_TYPE_BOOLEAN:
1822 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1830 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1831 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1835 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1837 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1842 for (node = object_list; node; node = node->next)
1843 g_object_freeze_notify (node->data);
1845 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1846 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1848 for (node = object_list; node; node = node->next)
1850 GtkSettings *settings = node->data;
1851 GtkSettingsPrivate *priv = settings->priv;
1852 GtkSettingsValuePrivate *qvalue;
1854 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1855 priv->property_values[class_n_properties - 1].value.g_type = 0;
1856 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1857 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1858 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1859 g_object_notify (G_OBJECT (settings), pspec->name);
1861 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1863 apply_queued_setting (settings, pspec, qvalue);
1866 for (node = object_list; node; node = next)
1869 g_object_thaw_notify (node->data);
1872 return class_n_properties;
1876 _gtk_rc_property_parser_from_type (GType type)
1878 if (type == GDK_TYPE_COLOR)
1879 return gtk_rc_property_parse_color;
1880 else if (type == GTK_TYPE_REQUISITION)
1881 return gtk_rc_property_parse_requisition;
1882 else if (type == GTK_TYPE_BORDER)
1883 return gtk_rc_property_parse_border;
1884 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1885 return gtk_rc_property_parse_enum;
1886 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1887 return gtk_rc_property_parse_flags;
1893 gtk_settings_install_property (GParamSpec *pspec)
1895 static GtkSettingsClass *klass = NULL;
1897 GtkRcPropertyParser parser;
1899 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1902 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1904 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1906 settings_install_property_parser (klass, pspec, parser);
1910 * gtk_settings_install_property_parser:
1912 * @parser: (scope call):
1915 gtk_settings_install_property_parser (GParamSpec *pspec,
1916 GtkRcPropertyParser parser)
1918 static GtkSettingsClass *klass = NULL;
1920 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1921 g_return_if_fail (parser != NULL);
1924 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1926 settings_install_property_parser (klass, pspec, parser);
1930 free_value (gpointer data)
1932 GtkSettingsValuePrivate *qvalue = data;
1934 g_value_unset (&qvalue->public.value);
1935 g_free (qvalue->public.origin);
1936 g_slice_free (GtkSettingsValuePrivate, qvalue);
1940 gtk_settings_set_property_value_internal (GtkSettings *settings,
1941 const gchar *prop_name,
1942 const GtkSettingsValue *new_value,
1943 GtkSettingsSource source)
1945 GtkSettingsPrivate *priv = settings->priv;
1946 GtkSettingsValuePrivate *qvalue;
1951 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1952 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1953 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1954 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1956 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
1960 name = g_strdup (prop_name);
1961 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1962 name_quark = g_quark_from_string (name);
1965 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
1968 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1969 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
1973 g_free (qvalue->public.origin);
1974 g_value_unset (&qvalue->public.value);
1976 qvalue->public.origin = g_strdup (new_value->origin);
1977 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1978 g_value_copy (&new_value->value, &qvalue->public.value);
1979 qvalue->source = source;
1980 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1982 apply_queued_setting (settings, pspec, qvalue);
1986 gtk_settings_set_property_value (GtkSettings *settings,
1987 const gchar *prop_name,
1988 const GtkSettingsValue *new_value)
1990 g_return_if_fail (GTK_SETTINGS (settings));
1991 g_return_if_fail (prop_name != NULL);
1992 g_return_if_fail (new_value != NULL);
1994 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1995 GTK_SETTINGS_SOURCE_APPLICATION);
1999 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
2000 const gchar *prop_name,
2001 const GtkSettingsValue *new_value)
2003 g_return_if_fail (GTK_SETTINGS (settings));
2004 g_return_if_fail (prop_name != NULL);
2005 g_return_if_fail (new_value != NULL);
2007 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2008 GTK_SETTINGS_SOURCE_THEME);
2012 gtk_settings_set_string_property (GtkSettings *settings,
2014 const gchar *v_string,
2015 const gchar *origin)
2017 GtkSettingsValue svalue = { NULL, { 0, }, };
2019 g_return_if_fail (GTK_SETTINGS (settings));
2020 g_return_if_fail (name != NULL);
2021 g_return_if_fail (v_string != NULL);
2023 svalue.origin = (gchar*) origin;
2024 g_value_init (&svalue.value, G_TYPE_STRING);
2025 g_value_set_static_string (&svalue.value, v_string);
2026 gtk_settings_set_property_value (settings, name, &svalue);
2027 g_value_unset (&svalue.value);
2031 gtk_settings_set_long_property (GtkSettings *settings,
2034 const gchar *origin)
2036 GtkSettingsValue svalue = { NULL, { 0, }, };
2038 g_return_if_fail (GTK_SETTINGS (settings));
2039 g_return_if_fail (name != NULL);
2041 svalue.origin = (gchar*) origin;
2042 g_value_init (&svalue.value, G_TYPE_LONG);
2043 g_value_set_long (&svalue.value, v_long);
2044 gtk_settings_set_property_value (settings, name, &svalue);
2045 g_value_unset (&svalue.value);
2049 gtk_settings_set_double_property (GtkSettings *settings,
2052 const gchar *origin)
2054 GtkSettingsValue svalue = { NULL, { 0, }, };
2056 g_return_if_fail (GTK_SETTINGS (settings));
2057 g_return_if_fail (name != NULL);
2059 svalue.origin = (gchar*) origin;
2060 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2061 g_value_set_double (&svalue.value, v_double);
2062 gtk_settings_set_property_value (settings, name, &svalue);
2063 g_value_unset (&svalue.value);
2067 * gtk_rc_property_parse_color:
2068 * @pspec: a #GParamSpec
2069 * @gstring: the #GString to be parsed
2070 * @property_value: a #GValue which must hold #GdkColor values.
2072 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2073 * or gtk_widget_class_install_style_property_parser() which parses a
2074 * color given either by its name or in the form
2075 * <literal>{ red, green, blue }</literal> where %red, %green and
2076 * %blue are integers between 0 and 65535 or floating-point numbers
2079 * Return value: %TRUE if @gstring could be parsed and @property_value
2080 * has been set to the resulting #GdkColor.
2083 gtk_rc_property_parse_color (const GParamSpec *pspec,
2084 const GString *gstring,
2085 GValue *property_value)
2087 GdkColor color = { 0, 0, 0, 0, };
2091 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2092 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2094 scanner = gtk_rc_scanner_new ();
2095 g_scanner_input_text (scanner, gstring->str, gstring->len);
2096 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2097 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2099 g_value_set_boxed (property_value, &color);
2104 g_scanner_destroy (scanner);
2110 * gtk_rc_property_parse_enum:
2111 * @pspec: a #GParamSpec
2112 * @gstring: the #GString to be parsed
2113 * @property_value: a #GValue which must hold enum values.
2115 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2116 * or gtk_widget_class_install_style_property_parser() which parses a single
2117 * enumeration value.
2119 * The enumeration value can be specified by its name, its nickname or
2120 * its numeric value. For consistency with flags parsing, the value
2121 * may be surrounded by parentheses.
2123 * Return value: %TRUE if @gstring could be parsed and @property_value
2124 * has been set to the resulting #GEnumValue.
2127 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2128 const GString *gstring,
2129 GValue *property_value)
2131 gboolean need_closing_brace = FALSE, success = FALSE;
2133 GEnumValue *enum_value = NULL;
2135 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2136 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2138 scanner = gtk_rc_scanner_new ();
2139 g_scanner_input_text (scanner, gstring->str, gstring->len);
2141 /* we just want to parse _one_ value, but for consistency with flags parsing
2142 * we support optional parenthesis
2144 g_scanner_get_next_token (scanner);
2145 if (scanner->token == '(')
2147 need_closing_brace = TRUE;
2148 g_scanner_get_next_token (scanner);
2150 if (scanner->token == G_TOKEN_IDENTIFIER)
2152 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2154 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2156 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2159 g_value_set_enum (property_value, enum_value->value);
2163 else if (scanner->token == G_TOKEN_INT)
2165 g_value_set_enum (property_value, scanner->value.v_int);
2168 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2170 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2173 g_scanner_destroy (scanner);
2179 parse_flags_value (GScanner *scanner,
2183 g_scanner_get_next_token (scanner);
2184 if (scanner->token == G_TOKEN_IDENTIFIER)
2186 GFlagsValue *flags_value;
2188 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2190 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2193 *number |= flags_value->value;
2194 return G_TOKEN_NONE;
2197 else if (scanner->token == G_TOKEN_INT)
2199 *number |= scanner->value.v_int;
2200 return G_TOKEN_NONE;
2202 return G_TOKEN_IDENTIFIER;
2206 * gtk_rc_property_parse_flags:
2207 * @pspec: a #GParamSpec
2208 * @gstring: the #GString to be parsed
2209 * @property_value: a #GValue which must hold flags values.
2211 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2212 * or gtk_widget_class_install_style_property_parser() which parses flags.
2214 * Flags can be specified by their name, their nickname or
2215 * numerically. Multiple flags can be specified in the form
2216 * <literal>"( flag1 | flag2 | ... )"</literal>.
2218 * Return value: %TRUE if @gstring could be parsed and @property_value
2219 * has been set to the resulting flags value.
2222 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2223 const GString *gstring,
2224 GValue *property_value)
2227 gboolean success = FALSE;
2230 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2231 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2233 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2234 scanner = gtk_rc_scanner_new ();
2235 g_scanner_input_text (scanner, gstring->str, gstring->len);
2237 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2238 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2239 scanner->next_token == G_TOKEN_INT)
2241 guint token, flags_value = 0;
2243 token = parse_flags_value (scanner, class, &flags_value);
2245 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2248 g_value_set_flags (property_value, flags_value);
2252 else if (g_scanner_get_next_token (scanner) == '(')
2254 guint token, flags_value = 0;
2256 /* parse first value */
2257 token = parse_flags_value (scanner, class, &flags_value);
2259 /* parse nth values, preceeded by '|' */
2260 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2261 token = parse_flags_value (scanner, class, &flags_value);
2263 /* done, last token must have closed expression */
2264 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2265 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2267 g_value_set_flags (property_value, flags_value);
2271 g_scanner_destroy (scanner);
2277 get_braced_int (GScanner *scanner,
2284 g_scanner_get_next_token (scanner);
2285 if (scanner->token != '{')
2289 g_scanner_get_next_token (scanner);
2290 if (scanner->token != G_TOKEN_INT)
2293 *value = scanner->value.v_int;
2297 g_scanner_get_next_token (scanner);
2298 if (scanner->token != '}')
2303 g_scanner_get_next_token (scanner);
2304 if (scanner->token != ',')
2312 * gtk_rc_property_parse_requisition:
2313 * @pspec: a #GParamSpec
2314 * @gstring: the #GString to be parsed
2315 * @property_value: a #GValue which must hold boxed values.
2317 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2318 * or gtk_widget_class_install_style_property_parser() which parses a
2319 * requisition in the form
2320 * <literal>"{ width, height }"</literal> for integers %width and %height.
2322 * Return value: %TRUE if @gstring could be parsed and @property_value
2323 * has been set to the resulting #GtkRequisition.
2326 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2327 const GString *gstring,
2328 GValue *property_value)
2330 GtkRequisition requisition;
2332 gboolean success = FALSE;
2334 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2335 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2337 scanner = gtk_rc_scanner_new ();
2338 g_scanner_input_text (scanner, gstring->str, gstring->len);
2340 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2341 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2343 g_value_set_boxed (property_value, &requisition);
2347 g_scanner_destroy (scanner);
2353 * gtk_rc_property_parse_border:
2354 * @pspec: a #GParamSpec
2355 * @gstring: the #GString to be parsed
2356 * @property_value: a #GValue which must hold boxed values.
2358 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2359 * or gtk_widget_class_install_style_property_parser() which parses
2360 * borders in the form
2361 * <literal>"{ left, right, top, bottom }"</literal> for integers
2362 * %left, %right, %top and %bottom.
2364 * Return value: %TRUE if @gstring could be parsed and @property_value
2365 * has been set to the resulting #GtkBorder.
2368 gtk_rc_property_parse_border (const GParamSpec *pspec,
2369 const GString *gstring,
2370 GValue *property_value)
2374 gboolean success = FALSE;
2375 int left, right, top, bottom;
2377 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2378 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2380 scanner = gtk_rc_scanner_new ();
2381 g_scanner_input_text (scanner, gstring->str, gstring->len);
2383 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2384 get_braced_int (scanner, FALSE, FALSE, &right) &&
2385 get_braced_int (scanner, FALSE, FALSE, &top) &&
2386 get_braced_int (scanner, FALSE, TRUE, &bottom))
2389 border.right = right;
2391 border.bottom = bottom;
2392 g_value_set_boxed (property_value, &border);
2396 g_scanner_destroy (scanner);
2402 _gtk_settings_handle_event (GdkEventSetting *event)
2405 GtkSettings *settings;
2409 screen = gdk_window_get_screen (event->window);
2410 settings = gtk_settings_get_for_screen (screen);
2411 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2415 property_id = pspec->param_id;
2417 if (property_id == PROP_COLOR_SCHEME)
2419 GValue value = G_VALUE_INIT;
2421 g_value_init (&value, G_TYPE_STRING);
2422 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2423 g_value_set_static_string (&value, "");
2424 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2425 g_value_unset (&value);
2427 g_object_notify (G_OBJECT (settings), pspec->name);
2432 reset_rc_values_foreach (GQuark key_id,
2436 GtkSettingsValuePrivate *qvalue = data;
2437 GSList **to_reset = user_data;
2439 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2440 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2444 _gtk_settings_reset_rc_values (GtkSettings *settings)
2446 GtkSettingsPrivate *priv = settings->priv;
2447 GSList *to_reset = NULL;
2449 GParamSpec **pspecs, **p;
2452 /* Remove any queued settings */
2453 g_datalist_foreach (&priv->queued_settings,
2454 reset_rc_values_foreach,
2457 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2459 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2460 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2463 g_slist_free (to_reset);
2465 /* Now reset the active settings
2467 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2470 g_object_freeze_notify (G_OBJECT (settings));
2471 for (p = pspecs; *p; p++)
2473 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2475 GParamSpec *pspec = *p;
2477 g_param_value_set_default (pspec, &priv->property_values[i].value);
2478 g_object_notify (G_OBJECT (settings), pspec->name);
2482 g_object_thaw_notify (G_OBJECT (settings));
2487 settings_update_double_click (GtkSettings *settings)
2489 GtkSettingsPrivate *priv = settings->priv;
2491 if (gdk_screen_get_number (priv->screen) == 0)
2493 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2494 gint double_click_time;
2495 gint double_click_distance;
2497 g_object_get (settings,
2498 "gtk-double-click-time", &double_click_time,
2499 "gtk-double-click-distance", &double_click_distance,
2502 gdk_display_set_double_click_time (display, double_click_time);
2503 gdk_display_set_double_click_distance (display, double_click_distance);
2508 settings_update_modules (GtkSettings *settings)
2512 g_object_get (settings,
2513 "gtk-modules", &modules,
2516 _gtk_modules_settings_changed (settings, modules);
2522 settings_update_cursor_theme (GtkSettings *settings)
2524 #ifdef GDK_WINDOWING_X11
2525 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2526 gchar *theme = NULL;
2529 if (GDK_IS_X11_DISPLAY (display))
2531 g_object_get (settings,
2532 "gtk-cursor-theme-name", &theme,
2533 "gtk-cursor-theme-size", &size,
2536 gdk_x11_display_set_cursor_theme (display, theme, size);
2544 settings_update_font_options (GtkSettings *settings)
2546 GtkSettingsPrivate *priv = settings->priv;
2548 gchar *hint_style_str;
2549 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2551 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2553 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2554 cairo_font_options_t *options;
2556 g_object_get (settings,
2557 "gtk-xft-antialias", &antialias,
2558 "gtk-xft-hinting", &hinting,
2559 "gtk-xft-hintstyle", &hint_style_str,
2560 "gtk-xft-rgba", &rgba_str,
2563 options = cairo_font_options_create ();
2565 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2567 if (hinting >= 0 && !hinting)
2569 hint_style = CAIRO_HINT_STYLE_NONE;
2571 else if (hint_style_str)
2573 if (strcmp (hint_style_str, "hintnone") == 0)
2574 hint_style = CAIRO_HINT_STYLE_NONE;
2575 else if (strcmp (hint_style_str, "hintslight") == 0)
2576 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2577 else if (strcmp (hint_style_str, "hintmedium") == 0)
2578 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2579 else if (strcmp (hint_style_str, "hintfull") == 0)
2580 hint_style = CAIRO_HINT_STYLE_FULL;
2583 g_free (hint_style_str);
2585 cairo_font_options_set_hint_style (options, hint_style);
2589 if (strcmp (rgba_str, "rgb") == 0)
2590 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2591 else if (strcmp (rgba_str, "bgr") == 0)
2592 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2593 else if (strcmp (rgba_str, "vrgb") == 0)
2594 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2595 else if (strcmp (rgba_str, "vbgr") == 0)
2596 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2601 cairo_font_options_set_subpixel_order (options, subpixel_order);
2603 if (antialias >= 0 && !antialias)
2604 antialias_mode = CAIRO_ANTIALIAS_NONE;
2605 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2606 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2607 else if (antialias >= 0)
2608 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2610 cairo_font_options_set_antialias (options, antialias_mode);
2612 gdk_screen_set_font_options (priv->screen, options);
2614 cairo_font_options_destroy (options);
2618 settings_update_fontconfig (GtkSettings *settings)
2620 #ifdef GDK_WINDOWING_X11
2621 static guint last_update_timestamp;
2622 static gboolean last_update_needed;
2626 g_object_get (settings,
2627 "gtk-fontconfig-timestamp", ×tamp,
2630 /* if timestamp is the same as last_update_timestamp, we already have
2631 * updated fontconig on this timestamp (another screen requested it perhaps?),
2632 * just return the cached result.*/
2634 if (timestamp != last_update_timestamp)
2636 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2637 gboolean update_needed = FALSE;
2640 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2642 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2643 if (FcInitReinitialize ())
2644 update_needed = TRUE;
2647 last_update_timestamp = timestamp;
2648 last_update_needed = update_needed;
2651 return last_update_needed;
2654 #endif /* GDK_WINDOWING_X11 */
2658 settings_update_resolution (GtkSettings *settings)
2660 GtkSettingsPrivate *priv = settings->priv;
2664 g_object_get (settings,
2665 "gtk-xft-dpi", &dpi_int,
2669 dpi = dpi_int / 1024.;
2673 gdk_screen_set_resolution (priv->screen, dpi);
2678 GHashTable *color_hash;
2679 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2680 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2684 color_scheme_data_free (ColorSchemeData *data)
2688 g_hash_table_unref (data->color_hash);
2690 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2692 if (data->tables[i])
2693 g_hash_table_unref (data->tables[i]);
2694 g_free (data->lastentry[i]);
2697 g_slice_free (ColorSchemeData, data);
2701 settings_update_color_scheme (GtkSettings *settings)
2703 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2705 GtkSettingsPrivate *priv = settings->priv;
2706 ColorSchemeData *data;
2707 GValue value = G_VALUE_INIT;
2709 data = g_slice_new0 (ColorSchemeData);
2710 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2711 (GDestroyNotify) gdk_color_free);
2712 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2713 data, (GDestroyNotify) color_scheme_data_free);
2715 g_value_init (&value, G_TYPE_STRING);
2716 if (priv->screen && gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2718 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2719 g_value_unset (&value);
2725 settings_update_provider (GdkScreen *screen,
2726 GtkCssProvider **old,
2727 GtkCssProvider *new)
2733 gtk_style_context_remove_provider_for_screen (screen,
2734 GTK_STYLE_PROVIDER (*old));
2735 g_object_unref (*old);
2741 gtk_style_context_add_provider_for_screen (screen,
2742 GTK_STYLE_PROVIDER (new),
2743 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2744 *old = g_object_ref (new);
2750 settings_update_theme (GtkSettings *settings)
2752 GtkSettingsPrivate *priv = settings->priv;
2753 GtkCssProvider *provider = NULL;
2754 gboolean prefer_dark_theme;
2757 g_object_get (settings,
2758 "gtk-theme-name", &theme_name,
2759 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2762 if (theme_name && *theme_name)
2764 if (prefer_dark_theme)
2765 provider = gtk_css_provider_get_named (theme_name, "dark");
2768 provider = gtk_css_provider_get_named (theme_name, NULL);
2771 settings_update_provider (priv->screen, &priv->theme_provider, provider);
2773 if (theme_name && *theme_name)
2778 /* reload per-theme settings */
2779 theme_dir = _gtk_css_provider_get_theme_dir ();
2780 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2782 if (g_file_test (path, G_FILE_TEST_EXISTS))
2783 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2789 g_free (theme_name);
2793 settings_update_key_theme (GtkSettings *settings)
2795 GtkSettingsPrivate *priv = settings->priv;
2796 GtkCssProvider *provider = NULL;
2797 gchar *key_theme_name;
2799 g_object_get (settings,
2800 "gtk-key-theme-name", &key_theme_name,
2803 if (key_theme_name && *key_theme_name)
2804 provider = gtk_css_provider_get_named (key_theme_name, "keys");
2806 settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2807 g_free (key_theme_name);
2811 add_color_to_hash (gchar *name,
2817 old = g_hash_table_lookup (target, name);
2818 if (!old || !gdk_color_equal (old, color))
2820 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2829 add_colors_to_hash_from_string (GHashTable *hash,
2830 const gchar *colors)
2832 gchar *s, *p, *name;
2834 gboolean changed = FALSE;
2837 copy = g_strdup (colors);
2842 p = strchr (s, ':');
2857 if (*s == '\n' || *s == ';')
2866 if (gdk_color_parse (p, &color))
2867 changed |= add_color_to_hash (name, &color, hash);
2876 update_color_hash (ColorSchemeData *data,
2878 GtkSettingsSource source)
2880 gboolean changed = FALSE;
2882 GHashTable *old_hash;
2883 GHashTableIter iter;
2887 if ((str == NULL || *str == '\0') &&
2888 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2891 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2894 /* For the THEME source we merge the values rather than over-writing
2895 * them, since multiple rc files might define independent sets of colors
2897 if ((source != GTK_SETTINGS_SOURCE_THEME) &&
2898 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2900 g_hash_table_unref (data->tables[source]);
2901 data->tables[source] = NULL;
2902 changed = TRUE; /* We can't rely on the code below since str might be "" */
2905 if (data->tables[source] == NULL)
2906 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2908 (GDestroyNotify) gdk_color_free);
2910 g_free (data->lastentry[source]);
2911 data->lastentry[source] = g_strdup (str);
2913 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2918 /* Rebuild the merged hash table. */
2919 if (data->color_hash)
2921 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2922 (GDestroyNotify) gdk_color_free);
2924 g_hash_table_iter_init (&iter, data->color_hash);
2925 while (g_hash_table_iter_next (&iter, &name, &color))
2927 g_hash_table_insert (old_hash, name, color);
2928 g_hash_table_iter_steal (&iter);
2936 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2938 if (data->tables[i])
2939 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2945 /* now check if the merged hash has changed */
2947 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2951 GHashTableIter iter;
2952 gpointer key, value, new_value;
2954 g_hash_table_iter_init (&iter, old_hash);
2955 while (g_hash_table_iter_next (&iter, &key, &value))
2957 new_value = g_hash_table_lookup (data->color_hash, key);
2958 if (!new_value || !gdk_color_equal (value, new_value))
2966 g_hash_table_unref (old_hash);
2975 merge_color_scheme (GtkSettings *settings,
2976 const GValue *value,
2977 GtkSettingsSource source)
2979 ColorSchemeData *data;
2980 const gchar *colors;
2982 g_object_freeze_notify (G_OBJECT (settings));
2984 colors = g_value_get_string (value);
2986 settings_update_color_scheme (settings);
2988 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2989 "gtk-color-scheme");
2991 if (update_color_hash (data, colors, source))
2992 g_object_notify (G_OBJECT (settings), "color-hash");
2994 g_object_thaw_notify (G_OBJECT (settings));
2998 get_color_hash (GtkSettings *settings)
3000 ColorSchemeData *data;
3002 settings_update_color_scheme (settings);
3004 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
3005 "gtk-color-scheme");
3007 return data->color_hash;
3011 append_color_scheme (gpointer key,
3015 gchar *name = (gchar *)key;
3016 GdkColor *color = (GdkColor *)value;
3017 GString *string = (GString *)data;
3019 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
3020 name, color->red, color->green, color->blue);
3024 get_color_scheme (GtkSettings *settings)
3026 ColorSchemeData *data;
3029 settings_update_color_scheme (settings);
3031 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
3032 "gtk-color-scheme");
3034 string = g_string_new ("");
3036 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
3038 return g_string_free (string, FALSE);
3042 _gtk_settings_get_screen (GtkSettings *settings)
3044 return settings->priv->screen;
3049 gtk_settings_load_from_key_file (GtkSettings *settings,
3051 GtkSettingsSource source)
3062 keyfile = g_key_file_new ();
3064 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
3066 g_warning ("Failed to parse %s: %s", path, error->message);
3068 g_error_free (error);
3073 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3076 g_warning ("Failed to parse %s: %s", path, error->message);
3077 g_error_free (error);
3081 for (i = 0; i < n_keys; i++)
3086 GtkSettingsValue svalue = { NULL, { 0, }, };
3089 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3092 g_warning ("Unknown key %s in %s", key, path);
3096 if (pspec->owner_type != G_OBJECT_TYPE (settings))
3099 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3102 case G_TYPE_BOOLEAN:
3106 g_value_init (&svalue.value, G_TYPE_LONG);
3107 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3109 g_value_set_long (&svalue.value, b_val);
3117 g_value_init (&svalue.value, G_TYPE_LONG);
3118 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3120 g_value_set_long (&svalue.value, i_val);
3128 g_value_init (&svalue.value, G_TYPE_DOUBLE);
3129 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3131 g_value_set_double (&svalue.value, d_val);
3139 g_value_init (&svalue.value, G_TYPE_GSTRING);
3140 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3142 g_value_take_boxed (&svalue.value, g_string_new (s_val));
3149 g_warning ("Error setting %s in %s: %s", key, path, error->message);
3150 g_error_free (error);
3155 if (g_getenv ("GTK_DEBUG"))
3156 svalue.origin = (gchar *)path;
3157 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3158 g_value_unset (&svalue.value);
3164 g_key_file_free (keyfile);