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, see <http://www.gnu.org/licenses/>.Free
19 #define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
25 #include "gtksettings.h"
27 #include "gtkmodules.h"
28 #include "gtkmodulesprivate.h"
29 #include "gtksettingsprivate.h"
31 #include "gtkwidget.h"
32 #include "gtkprivate.h"
33 #include "gtkcssproviderprivate.h"
34 #include "gtkstyleproviderprivate.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"
49 #undef GDK_DEPRECATED_FOR
50 #define GDK_DEPRECATED
51 #define GDK_DEPRECATED_FOR(f)
52 #undef GTK_DISABLE_DEPRECATED
54 #include "deprecated/gtkrc.h"
59 * @Short_description: Sharing settings between applications
62 * GtkSettings provide a mechanism to share global settings between
65 * On the X window system, this sharing is realized by an
66 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
67 * manager that is usually part of the desktop environment, along with
68 * utilities that let the user change these settings. In the absence of
69 * an Xsettings manager, GTK+ reads default values for settings from
70 * <filename>settings.ini</filename> files in
71 * <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
72 * a section called Settings. Themes can also provide default values
73 * for settings by installing a <filename>settings.ini</filename> file
74 * next to their <filename>gtk.css</filename> file.
76 * Applications can override system-wide settings with
77 * gtk_settings_set_string_property(), gtk_settings_set_long_property(),
78 * etc. This should be restricted to special cases though; GtkSettings are
79 * not meant as an application configuration facility. When doing so, you
80 * need to be aware that settings that are specific to individual widgets
81 * may not be available before the widget type has been realized at least
82 * once. The following example demonstrates a way to do this:
83 * <informalexample><programlisting>
84 * gtk_init (&argc, &argv);
86 * /* make sure the type is realized */
87 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
89 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
90 * </programlisting></informalexample>
92 * There is one GtkSettings instance per screen. It can be obtained with
93 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
94 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
95 * GtkSettings instance for the default screen.
99 #define DEFAULT_TIMEOUT_INITIAL 200
100 #define DEFAULT_TIMEOUT_REPEAT 20
101 #define DEFAULT_TIMEOUT_EXPAND 500
103 typedef struct _GtkSettingsPropertyValue GtkSettingsPropertyValue;
104 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
106 struct _GtkSettingsPrivate
108 GData *queued_settings; /* of type GtkSettingsValue* */
109 GtkSettingsPropertyValue *property_values;
111 GtkCssProvider *theme_provider;
112 GtkCssProvider *key_theme_provider;
113 GtkStyleProperties *style;
118 GTK_SETTINGS_SOURCE_DEFAULT,
119 GTK_SETTINGS_SOURCE_THEME,
120 GTK_SETTINGS_SOURCE_XSETTING,
121 GTK_SETTINGS_SOURCE_APPLICATION
124 struct _GtkSettingsValuePrivate
126 GtkSettingsValue public;
127 GtkSettingsSource source;
130 struct _GtkSettingsPropertyValue
133 GtkSettingsSource source;
138 PROP_DOUBLE_CLICK_TIME,
139 PROP_DOUBLE_CLICK_DISTANCE,
141 PROP_CURSOR_BLINK_TIME,
142 PROP_CURSOR_BLINK_TIMEOUT,
145 PROP_ICON_THEME_NAME,
146 PROP_FALLBACK_ICON_THEME,
149 PROP_DND_DRAG_THRESHOLD,
158 PROP_CURSOR_THEME_NAME,
159 PROP_CURSOR_THEME_SIZE,
160 PROP_ALTERNATIVE_BUTTON_ORDER,
161 PROP_ALTERNATIVE_SORT_ARROWS,
162 PROP_SHOW_INPUT_METHOD_MENU,
163 PROP_SHOW_UNICODE_MENU,
164 PROP_TIMEOUT_INITIAL,
168 PROP_ENABLE_ANIMATIONS,
169 PROP_TOUCHSCREEN_MODE,
170 PROP_TOOLTIP_TIMEOUT,
171 PROP_TOOLTIP_BROWSE_TIMEOUT,
172 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
173 PROP_KEYNAV_CURSOR_ONLY,
174 PROP_KEYNAV_WRAP_AROUND,
177 PROP_FILE_CHOOSER_BACKEND,
179 PROP_PRINT_PREVIEW_COMMAND,
180 PROP_ENABLE_MNEMONICS,
182 PROP_RECENT_FILES_LIMIT,
184 PROP_RECENT_FILES_MAX_AGE,
185 PROP_FONTCONFIG_TIMESTAMP,
186 PROP_SOUND_THEME_NAME,
187 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
188 PROP_ENABLE_EVENT_SOUNDS,
189 PROP_ENABLE_TOOLTIPS,
191 PROP_TOOLBAR_ICON_SIZE,
194 PROP_APPLICATION_PREFER_DARK_THEME,
196 PROP_ENTRY_SELECT_ON_FOCUS,
197 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
199 PROP_MENU_BAR_POPUP_DELAY,
200 PROP_SCROLLED_WINDOW_PLACEMENT,
201 PROP_CAN_CHANGE_ACCELS,
202 PROP_MENU_POPUP_DELAY,
203 PROP_MENU_POPDOWN_DELAY,
204 PROP_LABEL_SELECT_ON_FOCUS,
206 PROP_IM_PREEDIT_STYLE,
207 PROP_IM_STATUS_STYLE,
208 PROP_SHELL_SHOWS_APP_MENU,
209 PROP_SHELL_SHOWS_MENUBAR
212 /* --- prototypes --- */
213 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
214 static void gtk_settings_provider_private_init (GtkStyleProviderPrivateInterface *iface);
216 static void gtk_settings_finalize (GObject *object);
217 static void gtk_settings_get_property (GObject *object,
221 static void gtk_settings_set_property (GObject *object,
225 static void gtk_settings_notify (GObject *object,
227 static guint settings_install_property_parser (GtkSettingsClass *class,
229 GtkRcPropertyParser parser);
230 static void settings_update_double_click (GtkSettings *settings);
231 static void settings_update_modules (GtkSettings *settings);
233 static void settings_update_cursor_theme (GtkSettings *settings);
234 static void settings_update_resolution (GtkSettings *settings);
235 static void settings_update_font_options (GtkSettings *settings);
236 static gboolean settings_update_fontconfig (GtkSettings *settings);
237 static void settings_update_color_scheme (GtkSettings *settings);
238 static void settings_update_theme (GtkSettings *settings);
239 static void settings_update_key_theme (GtkSettings *settings);
241 static void merge_color_scheme (GtkSettings *settings,
243 GtkSettingsSource source);
244 static gchar *get_color_scheme (GtkSettings *settings);
245 static GHashTable *get_color_hash (GtkSettings *settings);
246 static void gtk_settings_load_from_key_file (GtkSettings *settings,
248 GtkSettingsSource source);
250 /* the default palette for GtkColorSelelection */
251 static const gchar default_color_palette[] =
252 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
253 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
255 /* --- variables --- */
256 static GQuark quark_property_parser = 0;
257 static GSList *object_list = NULL;
258 static guint class_n_properties = 0;
261 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
262 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
263 gtk_settings_provider_iface_init)
264 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER_PRIVATE,
265 gtk_settings_provider_private_init));
267 /* --- functions --- */
269 gtk_settings_init (GtkSettings *settings)
271 GtkSettingsPrivate *priv;
272 GParamSpec **pspecs, **p;
276 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
280 settings->priv = priv;
281 g_datalist_init (&priv->queued_settings);
282 object_list = g_slist_prepend (object_list, settings);
284 /* build up property array for all yet existing properties and queue
285 * notification for them (at least notification for internal properties
286 * will instantly be caught)
288 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
289 for (p = pspecs; *p; p++)
290 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
292 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
294 g_object_freeze_notify (G_OBJECT (settings));
296 for (p = pspecs; *p; p++)
298 GParamSpec *pspec = *p;
299 GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
301 if (pspec->owner_type != G_OBJECT_TYPE (settings))
303 g_value_init (&priv->property_values[i].value, value_type);
304 g_param_value_set_default (pspec, &priv->property_values[i].value);
306 g_object_notify (G_OBJECT (settings), pspec->name);
307 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
312 path = g_build_filename (_gtk_get_sysconfdir (), "gtk-3.0", "settings.ini", NULL);
313 if (g_file_test (path, G_FILE_TEST_EXISTS))
314 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
317 path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "settings.ini", NULL);
318 if (g_file_test (path, G_FILE_TEST_EXISTS))
319 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
322 g_object_thaw_notify (G_OBJECT (settings));
326 gtk_settings_class_init (GtkSettingsClass *class)
328 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
331 gobject_class->finalize = gtk_settings_finalize;
332 gobject_class->get_property = gtk_settings_get_property;
333 gobject_class->set_property = gtk_settings_set_property;
334 gobject_class->notify = gtk_settings_notify;
336 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
337 result = settings_install_property_parser (class,
338 g_param_spec_int ("gtk-double-click-time",
339 P_("Double Click Time"),
340 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
342 GTK_PARAM_READWRITE),
344 g_assert (result == PROP_DOUBLE_CLICK_TIME);
345 result = settings_install_property_parser (class,
346 g_param_spec_int ("gtk-double-click-distance",
347 P_("Double Click Distance"),
348 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
350 GTK_PARAM_READWRITE),
352 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
355 * GtkSettings:gtk-cursor-blink:
357 * Whether the cursor should blink.
359 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
360 * which allows more flexible control over cursor blinking.
362 result = settings_install_property_parser (class,
363 g_param_spec_boolean ("gtk-cursor-blink",
365 P_("Whether the cursor should blink"),
367 GTK_PARAM_READWRITE),
369 g_assert (result == PROP_CURSOR_BLINK);
370 result = settings_install_property_parser (class,
371 g_param_spec_int ("gtk-cursor-blink-time",
372 P_("Cursor Blink Time"),
373 P_("Length of the cursor blink cycle, in milliseconds"),
375 GTK_PARAM_READWRITE),
377 g_assert (result == PROP_CURSOR_BLINK_TIME);
380 * GtkSettings:gtk-cursor-blink-timeout:
382 * Time after which the cursor stops blinking, in seconds.
383 * The timer is reset after each user interaction.
385 * Setting this to zero has the same effect as setting
386 * #GtkSettings:gtk-cursor-blink to %FALSE.
390 result = settings_install_property_parser (class,
391 g_param_spec_int ("gtk-cursor-blink-timeout",
392 P_("Cursor Blink Timeout"),
393 P_("Time after which the cursor stops blinking, in seconds"),
394 1, G_MAXINT, G_MAXINT,
395 GTK_PARAM_READWRITE),
397 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
398 result = settings_install_property_parser (class,
399 g_param_spec_boolean ("gtk-split-cursor",
401 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
403 GTK_PARAM_READWRITE),
405 g_assert (result == PROP_SPLIT_CURSOR);
406 result = settings_install_property_parser (class,
407 g_param_spec_string ("gtk-theme-name",
409 P_("Name of theme to load"),
411 _gtk_win32_theme_get_default (),
415 GTK_PARAM_READWRITE),
417 g_assert (result == PROP_THEME_NAME);
419 result = settings_install_property_parser (class,
420 g_param_spec_string ("gtk-icon-theme-name",
421 P_("Icon Theme Name"),
422 P_("Name of icon theme to use"),
424 GTK_PARAM_READWRITE),
426 g_assert (result == PROP_ICON_THEME_NAME);
428 result = settings_install_property_parser (class,
429 g_param_spec_string ("gtk-fallback-icon-theme",
430 P_("Fallback Icon Theme Name"),
431 P_("Name of a icon theme to fall back to"),
433 GTK_PARAM_READWRITE),
435 g_assert (result == PROP_FALLBACK_ICON_THEME);
437 result = settings_install_property_parser (class,
438 g_param_spec_string ("gtk-key-theme-name",
439 P_("Key Theme Name"),
440 P_("Name of key theme to load"),
442 GTK_PARAM_READWRITE),
444 g_assert (result == PROP_KEY_THEME_NAME);
446 result = settings_install_property_parser (class,
447 g_param_spec_string ("gtk-menu-bar-accel",
448 P_("Menu bar accelerator"),
449 P_("Keybinding to activate the menu bar"),
451 GTK_PARAM_READWRITE),
453 g_assert (result == PROP_MENU_BAR_ACCEL);
455 result = settings_install_property_parser (class,
456 g_param_spec_int ("gtk-dnd-drag-threshold",
457 P_("Drag threshold"),
458 P_("Number of pixels the cursor can move before dragging"),
460 GTK_PARAM_READWRITE),
462 g_assert (result == PROP_DND_DRAG_THRESHOLD);
464 result = settings_install_property_parser (class,
465 g_param_spec_string ("gtk-font-name",
467 P_("Name of default font to use"),
469 GTK_PARAM_READWRITE),
471 g_assert (result == PROP_FONT_NAME);
474 * GtkSettings:gtk-icon-sizes:
476 * A list of icon sizes. The list is separated by colons, and
479 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
481 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
482 * GTK+ itself use the following named icon sizes: gtk-menu,
483 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
484 * gtk-dialog. Applications can register their own named icon
485 * sizes with gtk_icon_size_register().
487 result = settings_install_property_parser (class,
488 g_param_spec_string ("gtk-icon-sizes",
490 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
492 GTK_PARAM_READWRITE),
494 g_assert (result == PROP_ICON_SIZES);
496 result = settings_install_property_parser (class,
497 g_param_spec_string ("gtk-modules",
499 P_("List of currently active GTK modules"),
501 GTK_PARAM_READWRITE),
503 g_assert (result == PROP_MODULES);
505 result = settings_install_property_parser (class,
506 g_param_spec_int ("gtk-xft-antialias",
508 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
510 GTK_PARAM_READWRITE),
513 g_assert (result == PROP_XFT_ANTIALIAS);
515 result = settings_install_property_parser (class,
516 g_param_spec_int ("gtk-xft-hinting",
518 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
520 GTK_PARAM_READWRITE),
523 g_assert (result == PROP_XFT_HINTING);
525 result = settings_install_property_parser (class,
526 g_param_spec_string ("gtk-xft-hintstyle",
527 P_("Xft Hint Style"),
528 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
530 GTK_PARAM_READWRITE),
533 g_assert (result == PROP_XFT_HINTSTYLE);
535 result = settings_install_property_parser (class,
536 g_param_spec_string ("gtk-xft-rgba",
538 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
540 GTK_PARAM_READWRITE),
543 g_assert (result == PROP_XFT_RGBA);
545 result = settings_install_property_parser (class,
546 g_param_spec_int ("gtk-xft-dpi",
548 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
550 GTK_PARAM_READWRITE),
553 g_assert (result == PROP_XFT_DPI);
555 result = settings_install_property_parser (class,
556 g_param_spec_string ("gtk-cursor-theme-name",
557 P_("Cursor theme name"),
558 P_("Name of the cursor theme to use, or NULL to use the default theme"),
560 GTK_PARAM_READWRITE),
562 g_assert (result == PROP_CURSOR_THEME_NAME);
564 result = settings_install_property_parser (class,
565 g_param_spec_int ("gtk-cursor-theme-size",
566 P_("Cursor theme size"),
567 P_("Size to use for cursors, or 0 to use the default size"),
569 GTK_PARAM_READWRITE),
572 g_assert (result == PROP_CURSOR_THEME_SIZE);
574 result = settings_install_property_parser (class,
575 g_param_spec_boolean ("gtk-alternative-button-order",
576 P_("Alternative button order"),
577 P_("Whether buttons in dialogs should use the alternative button order"),
579 GTK_PARAM_READWRITE),
581 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
584 * GtkSettings:gtk-alternative-sort-arrows:
586 * Controls the direction of the sort indicators in sorted list and tree
587 * views. By default an arrow pointing down means the column is sorted
588 * in ascending order. When set to %TRUE, this order will be inverted.
592 result = settings_install_property_parser (class,
593 g_param_spec_boolean ("gtk-alternative-sort-arrows",
594 P_("Alternative sort indicator direction"),
595 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
597 GTK_PARAM_READWRITE),
599 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
601 result = settings_install_property_parser (class,
602 g_param_spec_boolean ("gtk-show-input-method-menu",
603 P_("Show the 'Input Methods' menu"),
604 P_("Whether the context menus of entries and text views should offer to change the input method"),
606 GTK_PARAM_READWRITE),
608 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
610 result = settings_install_property_parser (class,
611 g_param_spec_boolean ("gtk-show-unicode-menu",
612 P_("Show the 'Insert Unicode Control Character' menu"),
613 P_("Whether the context menus of entries and text views should offer to insert control characters"),
615 GTK_PARAM_READWRITE),
617 g_assert (result == PROP_SHOW_UNICODE_MENU);
619 result = settings_install_property_parser (class,
620 g_param_spec_int ("gtk-timeout-initial",
622 P_("Starting value for timeouts, when button is pressed"),
623 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
624 GTK_PARAM_READWRITE),
627 g_assert (result == PROP_TIMEOUT_INITIAL);
629 result = settings_install_property_parser (class,
630 g_param_spec_int ("gtk-timeout-repeat",
631 P_("Repeat timeout"),
632 P_("Repeat value for timeouts, when button is pressed"),
633 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
634 GTK_PARAM_READWRITE),
637 g_assert (result == PROP_TIMEOUT_REPEAT);
639 result = settings_install_property_parser (class,
640 g_param_spec_int ("gtk-timeout-expand",
641 P_("Expand timeout"),
642 P_("Expand value for timeouts, when a widget is expanding a new region"),
643 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
644 GTK_PARAM_READWRITE),
647 g_assert (result == PROP_TIMEOUT_EXPAND);
650 * GtkSettings:gtk-color-scheme:
652 * A palette of named colors for use in themes. The format of the string is
658 * Color names must be acceptable as identifiers in the
659 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
660 * color specifications must be in the format accepted by
663 * Note that due to the way the color tables from different sources are
664 * merged, color specifications will be converted to hexadecimal form
665 * when getting this property.
667 * Starting with GTK+ 2.12, the entries can alternatively be separated
668 * by ';' instead of newlines:
670 * name1: color1; name2: color2; ...
675 result = settings_install_property_parser (class,
676 g_param_spec_string ("gtk-color-scheme",
678 P_("A palette of named colors for use in themes"),
680 GTK_PARAM_READWRITE),
683 g_assert (result == PROP_COLOR_SCHEME);
685 result = settings_install_property_parser (class,
686 g_param_spec_boolean ("gtk-enable-animations",
687 P_("Enable Animations"),
688 P_("Whether to enable toolkit-wide animations."),
690 GTK_PARAM_READWRITE),
693 g_assert (result == PROP_ENABLE_ANIMATIONS);
696 * GtkSettings:gtk-touchscreen-mode:
698 * When %TRUE, there are no motion notify events delivered on this screen,
699 * and widgets can't use the pointer hovering them for any essential
704 * Deprecated: 3.4. Generally the behavior touchscreen input should be
705 * performed dynamically based on gdk_event_get_source_device().
707 result = settings_install_property_parser (class,
708 g_param_spec_boolean ("gtk-touchscreen-mode",
709 P_("Enable Touchscreen Mode"),
710 P_("When TRUE, there are no motion notify events delivered on this screen"),
712 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED),
715 g_assert (result == PROP_TOUCHSCREEN_MODE);
718 * GtkSettings:gtk-tooltip-timeout:
720 * Time, in milliseconds, after which a tooltip could appear if the
721 * cursor is hovering on top of a widget.
725 result = settings_install_property_parser (class,
726 g_param_spec_int ("gtk-tooltip-timeout",
727 P_("Tooltip timeout"),
728 P_("Timeout before tooltip is shown"),
731 GTK_PARAM_READWRITE),
734 g_assert (result == PROP_TOOLTIP_TIMEOUT);
737 * GtkSettings:gtk-tooltip-browse-timeout:
739 * Controls the time after which tooltips will appear when
740 * browse mode is enabled, in milliseconds.
742 * Browse mode is enabled when the mouse pointer moves off an object
743 * where a tooltip was currently being displayed. If the mouse pointer
744 * hits another object before the browse mode timeout expires (see
745 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
746 * amount of milliseconds specified by this setting to popup the tooltip
747 * for the new object.
751 result = settings_install_property_parser (class,
752 g_param_spec_int ("gtk-tooltip-browse-timeout",
753 P_("Tooltip browse timeout"),
754 P_("Timeout before tooltip is shown when browse mode is enabled"),
757 GTK_PARAM_READWRITE),
760 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
763 * GtkSettings:gtk-tooltip-browse-mode-timeout:
765 * Amount of time, in milliseconds, after which the browse mode
768 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
773 result = settings_install_property_parser (class,
774 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
775 P_("Tooltip browse mode timeout"),
776 P_("Timeout after which browse mode is disabled"),
779 GTK_PARAM_READWRITE),
782 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
785 * GtkSettings:gtk-keynav-cursor-only:
787 * When %TRUE, keyboard navigation should be able to reach all widgets
788 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
789 * to be present on the used input device.
793 result = settings_install_property_parser (class,
794 g_param_spec_boolean ("gtk-keynav-cursor-only",
795 P_("Keynav Cursor Only"),
796 P_("When TRUE, there are only cursor keys available to navigate widgets"),
798 GTK_PARAM_READWRITE),
801 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
804 * GtkSettings:gtk-keynav-wrap-around:
806 * When %TRUE, some widgets will wrap around when doing keyboard
807 * navigation, such as menus, menubars and notebooks.
811 result = settings_install_property_parser (class,
812 g_param_spec_boolean ("gtk-keynav-wrap-around",
813 P_("Keynav Wrap Around"),
814 P_("Whether to wrap around when keyboard-navigating widgets"),
816 GTK_PARAM_READWRITE),
819 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
822 * GtkSettings:gtk-error-bell:
824 * When %TRUE, keyboard navigation and other input-related errors
825 * will cause a beep. Since the error bell is implemented using
826 * gdk_window_beep(), the windowing system may offer ways to
827 * configure the error bell in many ways, such as flashing the
828 * window or similar visual effects.
832 result = settings_install_property_parser (class,
833 g_param_spec_boolean ("gtk-error-bell",
835 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
837 GTK_PARAM_READWRITE),
840 g_assert (result == PROP_ERROR_BELL);
843 * GtkSettings:color-hash:
845 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
846 * setting, mapping color names to #GdkColor<!-- -->s.
850 result = settings_install_property_parser (class,
851 g_param_spec_boxed ("color-hash",
853 P_("A hash table representation of the color scheme."),
857 g_assert (result == PROP_COLOR_HASH);
859 result = settings_install_property_parser (class,
860 g_param_spec_string ("gtk-file-chooser-backend",
861 P_("Default file chooser backend"),
862 P_("Name of the GtkFileChooser backend to use by default"),
864 GTK_PARAM_READWRITE),
866 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
869 * GtkSettings:gtk-print-backends:
871 * A comma-separated list of print backends to use in the print
872 * dialog. Available print backends depend on the GTK+ installation,
873 * and may include "file", "cups", "lpr" or "papi".
877 result = settings_install_property_parser (class,
878 g_param_spec_string ("gtk-print-backends",
879 P_("Default print backend"),
880 P_("List of the GtkPrintBackend backends to use by default"),
882 GTK_PARAM_READWRITE),
884 g_assert (result == PROP_PRINT_BACKENDS);
887 * GtkSettings:gtk-print-preview-command:
889 * A command to run for displaying the print preview. The command
890 * should contain a %f placeholder, which will get replaced by
891 * the path to the pdf file. The command may also contain a %s
892 * placeholder, which will get replaced by the path to a file
893 * containing the print settings in the format produced by
894 * gtk_print_settings_to_file().
896 * The preview application is responsible for removing the pdf file
897 * and the print settings file when it is done.
901 result = settings_install_property_parser (class,
902 g_param_spec_string ("gtk-print-preview-command",
903 P_("Default command to run when displaying a print preview"),
904 P_("Command to run when displaying a print preview"),
905 GTK_PRINT_PREVIEW_COMMAND,
906 GTK_PARAM_READWRITE),
908 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
911 * GtkSettings:gtk-enable-mnemonics:
913 * Whether labels and menu items should have visible mnemonics which
918 result = settings_install_property_parser (class,
919 g_param_spec_boolean ("gtk-enable-mnemonics",
920 P_("Enable Mnemonics"),
921 P_("Whether labels should have mnemonics"),
923 GTK_PARAM_READWRITE),
925 g_assert (result == PROP_ENABLE_MNEMONICS);
928 * GtkSettings:gtk-enable-accels:
930 * Whether menu items should have visible accelerators which can be
935 result = settings_install_property_parser (class,
936 g_param_spec_boolean ("gtk-enable-accels",
937 P_("Enable Accelerators"),
938 P_("Whether menu items should have accelerators"),
940 GTK_PARAM_READWRITE),
942 g_assert (result == PROP_ENABLE_ACCELS);
945 * GtkSettings:gtk-recent-files-limit:
947 * The number of recently used files that should be displayed by default by
948 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
949 * -1 means every recently used file stored.
953 result = settings_install_property_parser (class,
954 g_param_spec_int ("gtk-recent-files-limit",
955 P_("Recent Files Limit"),
956 P_("Number of recently used files"),
959 GTK_PARAM_READWRITE),
961 g_assert (result == PROP_RECENT_FILES_LIMIT);
964 * GtkSettings:gtk-im-module:
966 * Which IM (input method) module should be used by default. This is the
967 * input method that will be used if the user has not explicitly chosen
968 * another input method from the IM context menu.
969 * This also can be a colon-separated list of input methods, which GTK+
970 * will try in turn until it finds one available on the system.
972 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
974 result = settings_install_property_parser (class,
975 g_param_spec_string ("gtk-im-module",
976 P_("Default IM module"),
977 P_("Which IM module should be used by default"),
979 GTK_PARAM_READWRITE),
981 g_assert (result == PROP_IM_MODULE);
984 * GtkSettings:gtk-recent-files-max-age:
986 * The maximum age, in days, of the items inside the recently used
987 * resources list. Items older than this setting will be excised
988 * from the list. If set to 0, the list will always be empty; if
989 * set to -1, no item will be removed.
993 result = settings_install_property_parser (class,
994 g_param_spec_int ("gtk-recent-files-max-age",
995 P_("Recent Files Max Age"),
996 P_("Maximum age of recently used files, in days"),
999 GTK_PARAM_READWRITE),
1001 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
1003 result = settings_install_property_parser (class,
1004 g_param_spec_uint ("gtk-fontconfig-timestamp",
1005 P_("Fontconfig configuration timestamp"),
1006 P_("Timestamp of current fontconfig configuration"),
1008 GTK_PARAM_READWRITE),
1011 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
1014 * GtkSettings:gtk-sound-theme-name:
1016 * The XDG sound theme to use for event sounds.
1018 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1019 * for more information on event sounds and sound themes.
1021 * GTK+ itself does not support event sounds, you have to use a loadable
1022 * module like the one that comes with libcanberra.
1026 result = settings_install_property_parser (class,
1027 g_param_spec_string ("gtk-sound-theme-name",
1028 P_("Sound Theme Name"),
1029 P_("XDG sound theme name"),
1031 GTK_PARAM_READWRITE),
1033 g_assert (result == PROP_SOUND_THEME_NAME);
1036 * GtkSettings:gtk-enable-input-feedback-sounds:
1038 * Whether to play event sounds as feedback to user input.
1040 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1041 * for more information on event sounds and sound themes.
1043 * GTK+ itself does not support event sounds, you have to use a loadable
1044 * module like the one that comes with libcanberra.
1048 result = settings_install_property_parser (class,
1049 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1050 /* Translators: this means sounds that are played as feedback to user input */
1051 P_("Audible Input Feedback"),
1052 P_("Whether to play event sounds as feedback to user input"),
1054 GTK_PARAM_READWRITE),
1056 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1059 * GtkSettings:gtk-enable-event-sounds:
1061 * Whether to play any event sounds at all.
1063 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1064 * for more information on event sounds and sound themes.
1066 * GTK+ itself does not support event sounds, you have to use a loadable
1067 * module like the one that comes with libcanberra.
1071 result = settings_install_property_parser (class,
1072 g_param_spec_boolean ("gtk-enable-event-sounds",
1073 P_("Enable Event Sounds"),
1074 P_("Whether to play any event sounds at all"),
1076 GTK_PARAM_READWRITE),
1078 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1081 * GtkSettings:gtk-enable-tooltips:
1083 * Whether tooltips should be shown on widgets.
1087 result = settings_install_property_parser (class,
1088 g_param_spec_boolean ("gtk-enable-tooltips",
1089 P_("Enable Tooltips"),
1090 P_("Whether tooltips should be shown on widgets"),
1092 GTK_PARAM_READWRITE),
1094 g_assert (result == PROP_ENABLE_TOOLTIPS);
1097 * GtkSettings:gtk-toolbar-style:
1099 * The size of icons in default toolbars.
1101 result = settings_install_property_parser (class,
1102 g_param_spec_enum ("gtk-toolbar-style",
1103 P_("Toolbar style"),
1104 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1105 GTK_TYPE_TOOLBAR_STYLE,
1107 GTK_PARAM_READWRITE),
1108 gtk_rc_property_parse_enum);
1109 g_assert (result == PROP_TOOLBAR_STYLE);
1112 * GtkSettings:gtk-toolbar-icon-size:
1114 * The size of icons in default toolbars.
1116 result = settings_install_property_parser (class,
1117 g_param_spec_enum ("gtk-toolbar-icon-size",
1118 P_("Toolbar Icon Size"),
1119 P_("The size of icons in default toolbars."),
1121 GTK_ICON_SIZE_LARGE_TOOLBAR,
1122 GTK_PARAM_READWRITE),
1123 gtk_rc_property_parse_enum);
1124 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1127 * GtkSettings:gtk-auto-mnemonics:
1129 * Whether mnemonics should be automatically shown and hidden when the user
1130 * presses the mnemonic activator.
1134 result = settings_install_property_parser (class,
1135 g_param_spec_boolean ("gtk-auto-mnemonics",
1136 P_("Auto Mnemonics"),
1137 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1139 GTK_PARAM_READWRITE),
1141 g_assert (result == PROP_AUTO_MNEMONICS);
1144 * GtkSettings:gtk-visible-focus:
1146 * Whether 'focus rectangles' should be always visible, never visible,
1147 * or hidden until the user starts to use the keyboard.
1151 result = settings_install_property_parser (class,
1152 g_param_spec_enum ("gtk-visible-focus",
1153 P_("Visible Focus"),
1154 P_("Whether 'focus rectangles' should be hidden until the user starts to use the keyboard."),
1155 GTK_TYPE_POLICY_TYPE,
1157 GTK_PARAM_READWRITE),
1158 gtk_rc_property_parse_enum);
1159 g_assert (result == PROP_VISIBLE_FOCUS);
1162 * GtkSettings:gtk-application-prefer-dark-theme:
1164 * Whether the application prefers to use a dark theme. If a GTK+ theme
1165 * includes a dark variant, it will be used instead of the configured
1168 * Some applications benefit from minimizing the amount of light pollution that
1169 * interferes with the content. Good candidates for dark themes are photo and
1170 * video editors that make the actual content get all the attention and minimize
1171 * the distraction of the chrome.
1173 * Dark themes should not be used for documents, where large spaces are white/light
1174 * and the dark chrome creates too much contrast (web browser, text editor...).
1178 result = settings_install_property_parser (class,
1179 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1180 P_("Application prefers a dark theme"),
1181 P_("Whether the application prefers to have a dark theme."),
1183 GTK_PARAM_READWRITE),
1185 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1188 * GtkSettings::gtk-button-images:
1190 * Whether images should be shown on buttons
1194 result = settings_install_property_parser (class,
1195 g_param_spec_boolean ("gtk-button-images",
1196 P_("Show button images"),
1197 P_("Whether images should be shown on buttons"),
1199 GTK_PARAM_READWRITE),
1201 g_assert (result == PROP_BUTTON_IMAGES);
1203 result = settings_install_property_parser (class,
1204 g_param_spec_boolean ("gtk-entry-select-on-focus",
1205 P_("Select on focus"),
1206 P_("Whether to select the contents of an entry when it is focused"),
1208 GTK_PARAM_READWRITE),
1210 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1213 * GtkSettings:gtk-entry-password-hint-timeout:
1215 * How long to show the last input character in hidden
1216 * entries. This value is in milliseconds. 0 disables showing the
1217 * last char. 600 is a good value for enabling it.
1221 result = settings_install_property_parser (class,
1222 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1223 P_("Password Hint Timeout"),
1224 P_("How long to show the last input character in hidden entries"),
1227 GTK_PARAM_READWRITE),
1229 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1231 result = settings_install_property_parser (class,
1232 g_param_spec_boolean ("gtk-menu-images",
1233 P_("Show menu images"),
1234 P_("Whether images should be shown in menus"),
1236 GTK_PARAM_READWRITE),
1238 g_assert (result == PROP_MENU_IMAGES);
1240 result = settings_install_property_parser (class,
1241 g_param_spec_int ("gtk-menu-bar-popup-delay",
1242 P_("Delay before drop down menus appear"),
1243 P_("Delay before the submenus of a menu bar appear"),
1246 GTK_PARAM_READWRITE),
1248 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1251 * GtkSettings:gtk-scrolled-window-placement:
1253 * Where the contents of scrolled windows are located with respect to the
1254 * scrollbars, if not overridden by the scrolled window's own placement.
1258 result = settings_install_property_parser (class,
1259 g_param_spec_enum ("gtk-scrolled-window-placement",
1260 P_("Scrolled Window Placement"),
1261 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1262 GTK_TYPE_CORNER_TYPE,
1263 GTK_CORNER_TOP_LEFT,
1264 GTK_PARAM_READWRITE),
1265 gtk_rc_property_parse_enum);
1266 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1268 result = settings_install_property_parser (class,
1269 g_param_spec_boolean ("gtk-can-change-accels",
1270 P_("Can change accelerators"),
1271 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1273 GTK_PARAM_READWRITE),
1275 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1277 result = settings_install_property_parser (class,
1278 g_param_spec_int ("gtk-menu-popup-delay",
1279 P_("Delay before submenus appear"),
1280 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1283 GTK_PARAM_READWRITE),
1285 g_assert (result == PROP_MENU_POPUP_DELAY);
1287 result = settings_install_property_parser (class,
1288 g_param_spec_int ("gtk-menu-popdown-delay",
1289 P_("Delay before hiding a submenu"),
1290 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1293 GTK_PARAM_READWRITE),
1295 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1297 result = settings_install_property_parser (class,
1298 g_param_spec_boolean ("gtk-label-select-on-focus",
1299 P_("Select on focus"),
1300 P_("Whether to select the contents of a selectable label when it is focused"),
1302 GTK_PARAM_READWRITE),
1304 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1306 result = settings_install_property_parser (class,
1307 g_param_spec_string ("gtk-color-palette",
1308 P_("Custom palette"),
1309 P_("Palette to use in the color selector"),
1310 default_color_palette,
1311 GTK_PARAM_READWRITE),
1313 g_assert (result == PROP_COLOR_PALETTE);
1315 result = settings_install_property_parser (class,
1316 g_param_spec_enum ("gtk-im-preedit-style",
1317 P_("IM Preedit style"),
1318 P_("How to draw the input method preedit string"),
1319 GTK_TYPE_IM_PREEDIT_STYLE,
1320 GTK_IM_PREEDIT_CALLBACK,
1321 GTK_PARAM_READWRITE),
1322 gtk_rc_property_parse_enum);
1323 g_assert (result == PROP_IM_PREEDIT_STYLE);
1325 result = settings_install_property_parser (class,
1326 g_param_spec_enum ("gtk-im-status-style",
1327 P_("IM Status style"),
1328 P_("How to draw the input method statusbar"),
1329 GTK_TYPE_IM_STATUS_STYLE,
1330 GTK_IM_STATUS_CALLBACK,
1331 GTK_PARAM_READWRITE),
1332 gtk_rc_property_parse_enum);
1333 g_assert (result == PROP_IM_STATUS_STYLE);
1335 result = settings_install_property_parser (class,
1336 g_param_spec_boolean ("gtk-shell-shows-app-menu",
1337 P_("Desktop shell shows app menu"),
1338 P_("Set to TRUE if the desktop environment "
1339 "is displaying the app menu, FALSE if "
1340 "the app should display it itself."),
1341 FALSE, GTK_PARAM_READWRITE),
1343 g_assert (result == PROP_SHELL_SHOWS_APP_MENU);
1345 result = settings_install_property_parser (class,
1346 g_param_spec_boolean ("gtk-shell-shows-menubar",
1347 P_("Desktop shell shows the menubar"),
1348 P_("Set to TRUE if the desktop environment "
1349 "is displaying the menubar, FALSE if "
1350 "the app should display it itself."),
1351 FALSE, GTK_PARAM_READWRITE),
1353 g_assert (result == PROP_SHELL_SHOWS_MENUBAR);
1355 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1359 settings_ensure_style (GtkSettings *settings)
1361 GtkSettingsPrivate *priv = settings->priv;
1362 PangoFontDescription *font_desc;
1363 gchar *font_name, *color_scheme;
1370 priv->style = gtk_style_properties_new ();
1372 g_object_get (settings,
1373 "gtk-font-name", &font_name,
1374 "gtk-color-scheme", &color_scheme,
1377 colors = g_strsplit_set (color_scheme, "\n;", -1);
1379 for (i = 0; colors[i]; i++)
1381 GtkSymbolicColor *color;
1389 pos = strchr (colors[i], ':');
1394 /* Set NUL after color name */
1398 /* Find start of color string */
1402 if (!*pos || !gdk_rgba_parse (&col, pos))
1405 color = gtk_symbolic_color_new_literal (&col);
1406 gtk_style_properties_map_color (priv->style, name, color);
1407 gtk_symbolic_color_unref (color);
1410 font_desc = pango_font_description_from_string (font_name);
1412 /* Unset normal attributes from this description,
1413 * so they do not override theme values */
1414 if (pango_font_description_get_weight (font_desc) == PANGO_WEIGHT_NORMAL)
1415 pango_font_description_unset_fields (font_desc,
1416 PANGO_FONT_MASK_WEIGHT);
1418 if (pango_font_description_get_stretch (font_desc) == PANGO_STRETCH_NORMAL)
1419 pango_font_description_unset_fields (font_desc,
1420 PANGO_FONT_MASK_STRETCH);
1422 if (pango_font_description_get_variant (font_desc) == PANGO_VARIANT_NORMAL)
1423 pango_font_description_unset_fields (font_desc,
1424 PANGO_FONT_MASK_VARIANT);
1426 if (pango_font_description_get_style (font_desc) == PANGO_STYLE_NORMAL)
1427 pango_font_description_unset_fields (font_desc,
1428 PANGO_FONT_MASK_STYLE);
1430 gtk_style_properties_set (priv->style, 0,
1434 pango_font_description_free (font_desc);
1435 g_strfreev (colors);
1436 g_free (color_scheme);
1440 static GtkStyleProperties *
1441 gtk_settings_get_style (GtkStyleProvider *provider,
1442 GtkWidgetPath *path)
1444 GtkSettings *settings;
1446 settings = GTK_SETTINGS (provider);
1448 settings_ensure_style (settings);
1450 return g_object_ref (settings->priv->style);
1454 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1456 iface->get_style = gtk_settings_get_style;
1459 static GtkSymbolicColor *
1460 gtk_settings_style_provider_get_color (GtkStyleProviderPrivate *provider,
1463 GtkSettings *settings = GTK_SETTINGS (provider);
1465 settings_ensure_style (settings);
1467 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style), name);
1471 gtk_settings_style_provider_lookup (GtkStyleProviderPrivate *provider,
1472 GtkWidgetPath *path,
1473 GtkStateFlags state,
1474 GtkCssLookup *lookup)
1476 GtkSettings *settings = GTK_SETTINGS (provider);
1478 settings_ensure_style (settings);
1480 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style),
1487 gtk_settings_provider_private_init (GtkStyleProviderPrivateInterface *iface)
1489 iface->get_color = gtk_settings_style_provider_get_color;
1490 iface->lookup = gtk_settings_style_provider_lookup;
1494 gtk_settings_finalize (GObject *object)
1496 GtkSettings *settings = GTK_SETTINGS (object);
1497 GtkSettingsPrivate *priv = settings->priv;
1500 object_list = g_slist_remove (object_list, settings);
1502 for (i = 0; i < class_n_properties; i++)
1503 g_value_unset (&priv->property_values[i].value);
1504 g_free (priv->property_values);
1506 g_datalist_clear (&priv->queued_settings);
1508 if (priv->theme_provider)
1509 g_object_unref (priv->theme_provider);
1511 if (priv->key_theme_provider)
1512 g_object_unref (priv->key_theme_provider);
1515 g_object_unref (priv->style);
1517 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1521 settings_init_style (GtkSettings *settings)
1523 static GtkCssProvider *css_provider = NULL;
1525 GdkScreen *screen = settings->priv->screen;
1527 /* Add provider for user file */
1528 if (G_UNLIKELY (!css_provider))
1532 css_provider = gtk_css_provider_new ();
1533 css_path = g_build_filename (g_get_user_config_dir (),
1538 if (g_file_test (css_path,
1539 G_FILE_TEST_IS_REGULAR))
1540 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1545 gtk_style_context_add_provider_for_screen (screen,
1546 GTK_STYLE_PROVIDER (css_provider),
1547 GTK_STYLE_PROVIDER_PRIORITY_USER);
1549 gtk_style_context_add_provider_for_screen (screen,
1550 GTK_STYLE_PROVIDER (settings),
1551 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1553 settings_update_theme (settings);
1554 settings_update_key_theme (settings);
1558 * gtk_settings_get_for_screen:
1559 * @screen: a #GdkScreen.
1561 * Gets the #GtkSettings object for @screen, creating it if necessary.
1563 * Return value: (transfer none): a #GtkSettings object.
1568 gtk_settings_get_for_screen (GdkScreen *screen)
1570 GtkSettings *settings;
1572 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1574 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1577 #ifdef GDK_WINDOWING_QUARTZ
1578 if (GDK_IS_QUARTZ_SCREEN (screen))
1579 settings = g_object_new (GTK_TYPE_SETTINGS,
1580 "gtk-key-theme-name", "Mac",
1581 "gtk-shell-shows-app-menu", TRUE,
1582 "gtk-shell-shows-menubar", TRUE,
1586 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1587 settings->priv->screen = screen;
1588 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1589 settings, g_object_unref);
1591 settings_init_style (settings);
1592 settings_update_double_click (settings);
1593 settings_update_cursor_theme (settings);
1594 settings_update_resolution (settings);
1595 settings_update_font_options (settings);
1596 settings_update_color_scheme (settings);
1603 * gtk_settings_get_default:
1605 * Gets the #GtkSettings object for the default GDK screen, creating
1606 * it if necessary. See gtk_settings_get_for_screen().
1608 * Return value: (transfer none): a #GtkSettings object. If there is no default
1609 * screen, then returns %NULL.
1612 gtk_settings_get_default (void)
1614 GdkScreen *screen = gdk_screen_get_default ();
1617 return gtk_settings_get_for_screen (screen);
1623 gtk_settings_set_property (GObject *object,
1625 const GValue *value,
1628 GtkSettings *settings = GTK_SETTINGS (object);
1629 GtkSettingsPrivate *priv = settings->priv;
1631 g_value_copy (value, &priv->property_values[property_id - 1].value);
1632 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1634 if (pspec->param_id == PROP_COLOR_SCHEME)
1635 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1639 gtk_settings_get_property (GObject *object,
1644 GtkSettings *settings = GTK_SETTINGS (object);
1645 GtkSettingsPrivate *priv = settings->priv;
1646 GType value_type = G_VALUE_TYPE (value);
1647 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1649 /* handle internal properties */
1650 switch (property_id)
1652 case PROP_COLOR_HASH:
1653 g_value_set_boxed (value, get_color_hash (settings));
1655 case PROP_COLOR_SCHEME:
1656 g_value_take_string (value, get_color_scheme (settings));
1661 /* For enums and strings, we need to get the value as a string,
1662 * not as an int, since we support using names/nicks as the setting
1665 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1666 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1667 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1668 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1670 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1671 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1672 g_value_copy (&priv->property_values[property_id - 1].value, value);
1674 g_param_value_validate (pspec, value);
1678 GValue val = G_VALUE_INIT;
1680 /* Try to get xsetting as a string and parse it. */
1682 g_value_init (&val, G_TYPE_STRING);
1684 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1685 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1687 g_value_copy (&priv->property_values[property_id - 1].value, value);
1691 GValue tmp_value = G_VALUE_INIT;
1692 GValue gstring_value = G_VALUE_INIT;
1693 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1695 g_value_init (&gstring_value, G_TYPE_GSTRING);
1696 g_value_take_boxed (&gstring_value,
1697 g_string_new (g_value_get_string (&val)));
1699 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1701 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1704 g_value_copy (&tmp_value, value);
1705 g_param_value_validate (pspec, value);
1709 g_value_copy (&priv->property_values[property_id - 1].value, value);
1712 g_value_unset (&gstring_value);
1713 g_value_unset (&tmp_value);
1716 g_value_unset (&val);
1721 settings_invalidate_style (GtkSettings *settings)
1723 GtkSettingsPrivate *priv = settings->priv;
1727 g_object_unref (priv->style);
1733 gtk_settings_notify (GObject *object,
1736 GtkSettings *settings = GTK_SETTINGS (object);
1737 GtkSettingsPrivate *priv = settings->priv;
1738 guint property_id = pspec->param_id;
1740 if (priv->screen == NULL) /* initialization */
1743 switch (property_id)
1746 settings_update_modules (settings);
1748 case PROP_DOUBLE_CLICK_TIME:
1749 case PROP_DOUBLE_CLICK_DISTANCE:
1750 settings_update_double_click (settings);
1752 case PROP_COLOR_SCHEME:
1753 settings_update_color_scheme (settings);
1754 settings_invalidate_style (settings);
1755 gtk_style_context_reset_widgets (priv->screen);
1757 case PROP_FONT_NAME:
1758 settings_invalidate_style (settings);
1759 gtk_style_context_reset_widgets (priv->screen);
1761 case PROP_KEY_THEME_NAME:
1762 settings_update_key_theme (settings);
1764 case PROP_THEME_NAME:
1765 case PROP_APPLICATION_PREFER_DARK_THEME:
1766 settings_update_theme (settings);
1769 settings_update_resolution (settings);
1770 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1771 * widgets with gtk_widget_style_set(), and also causes more
1772 * recomputation than necessary.
1774 gtk_style_context_reset_widgets (priv->screen);
1776 case PROP_XFT_ANTIALIAS:
1777 case PROP_XFT_HINTING:
1778 case PROP_XFT_HINTSTYLE:
1780 settings_update_font_options (settings);
1781 gtk_style_context_reset_widgets (priv->screen);
1783 case PROP_FONTCONFIG_TIMESTAMP:
1784 if (settings_update_fontconfig (settings))
1785 gtk_style_context_reset_widgets (priv->screen);
1787 case PROP_CURSOR_THEME_NAME:
1788 case PROP_CURSOR_THEME_SIZE:
1789 settings_update_cursor_theme (settings);
1795 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1796 const GValue *src_value,
1800 gboolean success = FALSE;
1802 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1807 gboolean free_gstring = TRUE;
1809 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1811 gstring = g_value_get_boxed (src_value);
1812 free_gstring = FALSE;
1814 else if (G_VALUE_HOLDS_LONG (src_value))
1816 gstring = g_string_new (NULL);
1817 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1819 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1821 gstring = g_string_new (NULL);
1822 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1824 else if (G_VALUE_HOLDS_STRING (src_value))
1826 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1828 gstring = g_string_new (NULL);
1829 g_string_append_c (gstring, '\"');
1830 g_string_append (gstring, tstr);
1831 g_string_append_c (gstring, '\"');
1836 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1837 gstring = NULL; /* silence compiler */
1840 success = (parser (pspec, gstring, dest_value) &&
1841 !g_param_value_validate (pspec, dest_value));
1844 g_string_free (gstring, TRUE);
1846 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1848 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1850 GString *gstring = g_value_get_boxed (src_value);
1852 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1853 success = !g_param_value_validate (pspec, dest_value);
1856 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1857 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1863 apply_queued_setting (GtkSettings *settings,
1865 GtkSettingsValuePrivate *qvalue)
1867 GtkSettingsPrivate *priv = settings->priv;
1868 GValue tmp_value = G_VALUE_INIT;
1869 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1871 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1872 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1875 if (pspec->param_id == PROP_COLOR_SCHEME)
1876 merge_color_scheme (settings, &tmp_value, qvalue->source);
1878 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1880 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1881 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1882 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1888 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1890 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1891 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1893 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1895 G_VALUE_TYPE_NAME (&tmp_value));
1898 g_value_unset (&tmp_value);
1902 settings_install_property_parser (GtkSettingsClass *class,
1904 GtkRcPropertyParser parser)
1906 GSList *node, *next;
1908 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1910 case G_TYPE_BOOLEAN:
1923 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1931 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1932 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1936 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1938 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1943 for (node = object_list; node; node = node->next)
1944 g_object_freeze_notify (node->data);
1946 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1947 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1949 for (node = object_list; node; node = node->next)
1951 GtkSettings *settings = node->data;
1952 GtkSettingsPrivate *priv = settings->priv;
1953 GtkSettingsValuePrivate *qvalue;
1955 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1956 priv->property_values[class_n_properties - 1].value.g_type = 0;
1957 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1958 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1959 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1960 g_object_notify (G_OBJECT (settings), pspec->name);
1962 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1964 apply_queued_setting (settings, pspec, qvalue);
1967 for (node = object_list; node; node = next)
1970 g_object_thaw_notify (node->data);
1973 return class_n_properties;
1977 _gtk_rc_property_parser_from_type (GType type)
1979 if (type == GDK_TYPE_COLOR)
1980 return gtk_rc_property_parse_color;
1981 else if (type == GTK_TYPE_REQUISITION)
1982 return gtk_rc_property_parse_requisition;
1983 else if (type == GTK_TYPE_BORDER)
1984 return gtk_rc_property_parse_border;
1985 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1986 return gtk_rc_property_parse_enum;
1987 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1988 return gtk_rc_property_parse_flags;
1994 gtk_settings_install_property (GParamSpec *pspec)
1996 static GtkSettingsClass *klass = NULL;
1998 GtkRcPropertyParser parser;
2000 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2003 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2005 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
2007 settings_install_property_parser (klass, pspec, parser);
2011 * gtk_settings_install_property_parser:
2013 * @parser: (scope call):
2016 gtk_settings_install_property_parser (GParamSpec *pspec,
2017 GtkRcPropertyParser parser)
2019 static GtkSettingsClass *klass = NULL;
2021 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2022 g_return_if_fail (parser != NULL);
2025 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2027 settings_install_property_parser (klass, pspec, parser);
2031 free_value (gpointer data)
2033 GtkSettingsValuePrivate *qvalue = data;
2035 g_value_unset (&qvalue->public.value);
2036 g_free (qvalue->public.origin);
2037 g_slice_free (GtkSettingsValuePrivate, qvalue);
2041 gtk_settings_set_property_value_internal (GtkSettings *settings,
2042 const gchar *prop_name,
2043 const GtkSettingsValue *new_value,
2044 GtkSettingsSource source)
2046 GtkSettingsPrivate *priv = settings->priv;
2047 GtkSettingsValuePrivate *qvalue;
2052 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
2053 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
2054 !G_VALUE_HOLDS_STRING (&new_value->value) &&
2055 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
2057 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
2061 name = g_strdup (prop_name);
2062 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
2063 name_quark = g_quark_from_string (name);
2066 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
2069 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
2070 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
2074 g_free (qvalue->public.origin);
2075 g_value_unset (&qvalue->public.value);
2077 qvalue->public.origin = g_strdup (new_value->origin);
2078 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
2079 g_value_copy (&new_value->value, &qvalue->public.value);
2080 qvalue->source = source;
2081 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
2083 apply_queued_setting (settings, pspec, qvalue);
2087 gtk_settings_set_property_value (GtkSettings *settings,
2088 const gchar *prop_name,
2089 const GtkSettingsValue *new_value)
2091 g_return_if_fail (GTK_SETTINGS (settings));
2092 g_return_if_fail (prop_name != NULL);
2093 g_return_if_fail (new_value != NULL);
2095 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2096 GTK_SETTINGS_SOURCE_APPLICATION);
2100 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
2101 const gchar *prop_name,
2102 const GtkSettingsValue *new_value)
2104 g_return_if_fail (GTK_SETTINGS (settings));
2105 g_return_if_fail (prop_name != NULL);
2106 g_return_if_fail (new_value != NULL);
2108 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2109 GTK_SETTINGS_SOURCE_THEME);
2113 gtk_settings_set_string_property (GtkSettings *settings,
2115 const gchar *v_string,
2116 const gchar *origin)
2118 GtkSettingsValue svalue = { NULL, { 0, }, };
2120 g_return_if_fail (GTK_SETTINGS (settings));
2121 g_return_if_fail (name != NULL);
2122 g_return_if_fail (v_string != NULL);
2124 svalue.origin = (gchar*) origin;
2125 g_value_init (&svalue.value, G_TYPE_STRING);
2126 g_value_set_static_string (&svalue.value, v_string);
2127 gtk_settings_set_property_value (settings, name, &svalue);
2128 g_value_unset (&svalue.value);
2132 gtk_settings_set_long_property (GtkSettings *settings,
2135 const gchar *origin)
2137 GtkSettingsValue svalue = { NULL, { 0, }, };
2139 g_return_if_fail (GTK_SETTINGS (settings));
2140 g_return_if_fail (name != NULL);
2142 svalue.origin = (gchar*) origin;
2143 g_value_init (&svalue.value, G_TYPE_LONG);
2144 g_value_set_long (&svalue.value, v_long);
2145 gtk_settings_set_property_value (settings, name, &svalue);
2146 g_value_unset (&svalue.value);
2150 gtk_settings_set_double_property (GtkSettings *settings,
2153 const gchar *origin)
2155 GtkSettingsValue svalue = { NULL, { 0, }, };
2157 g_return_if_fail (GTK_SETTINGS (settings));
2158 g_return_if_fail (name != NULL);
2160 svalue.origin = (gchar*) origin;
2161 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2162 g_value_set_double (&svalue.value, v_double);
2163 gtk_settings_set_property_value (settings, name, &svalue);
2164 g_value_unset (&svalue.value);
2168 * gtk_rc_property_parse_color:
2169 * @pspec: a #GParamSpec
2170 * @gstring: the #GString to be parsed
2171 * @property_value: a #GValue which must hold #GdkColor values.
2173 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2174 * or gtk_widget_class_install_style_property_parser() which parses a
2175 * color given either by its name or in the form
2176 * <literal>{ red, green, blue }</literal> where %red, %green and
2177 * %blue are integers between 0 and 65535 or floating-point numbers
2180 * Return value: %TRUE if @gstring could be parsed and @property_value
2181 * has been set to the resulting #GdkColor.
2184 gtk_rc_property_parse_color (const GParamSpec *pspec,
2185 const GString *gstring,
2186 GValue *property_value)
2188 GdkColor color = { 0, 0, 0, 0, };
2192 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2193 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2195 scanner = gtk_rc_scanner_new ();
2196 g_scanner_input_text (scanner, gstring->str, gstring->len);
2197 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2198 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2200 g_value_set_boxed (property_value, &color);
2205 g_scanner_destroy (scanner);
2211 * gtk_rc_property_parse_enum:
2212 * @pspec: a #GParamSpec
2213 * @gstring: the #GString to be parsed
2214 * @property_value: a #GValue which must hold enum values.
2216 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2217 * or gtk_widget_class_install_style_property_parser() which parses a single
2218 * enumeration value.
2220 * The enumeration value can be specified by its name, its nickname or
2221 * its numeric value. For consistency with flags parsing, the value
2222 * may be surrounded by parentheses.
2224 * Return value: %TRUE if @gstring could be parsed and @property_value
2225 * has been set to the resulting #GEnumValue.
2228 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2229 const GString *gstring,
2230 GValue *property_value)
2232 gboolean need_closing_brace = FALSE, success = FALSE;
2234 GEnumValue *enum_value = NULL;
2236 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2237 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2239 scanner = gtk_rc_scanner_new ();
2240 g_scanner_input_text (scanner, gstring->str, gstring->len);
2242 /* we just want to parse _one_ value, but for consistency with flags parsing
2243 * we support optional parenthesis
2245 g_scanner_get_next_token (scanner);
2246 if (scanner->token == '(')
2248 need_closing_brace = TRUE;
2249 g_scanner_get_next_token (scanner);
2251 if (scanner->token == G_TOKEN_IDENTIFIER)
2253 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2255 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2257 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2260 g_value_set_enum (property_value, enum_value->value);
2264 else if (scanner->token == G_TOKEN_INT)
2266 g_value_set_enum (property_value, scanner->value.v_int);
2269 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2271 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2274 g_scanner_destroy (scanner);
2280 parse_flags_value (GScanner *scanner,
2284 g_scanner_get_next_token (scanner);
2285 if (scanner->token == G_TOKEN_IDENTIFIER)
2287 GFlagsValue *flags_value;
2289 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2291 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2294 *number |= flags_value->value;
2295 return G_TOKEN_NONE;
2298 else if (scanner->token == G_TOKEN_INT)
2300 *number |= scanner->value.v_int;
2301 return G_TOKEN_NONE;
2303 return G_TOKEN_IDENTIFIER;
2307 * gtk_rc_property_parse_flags:
2308 * @pspec: a #GParamSpec
2309 * @gstring: the #GString to be parsed
2310 * @property_value: a #GValue which must hold flags values.
2312 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2313 * or gtk_widget_class_install_style_property_parser() which parses flags.
2315 * Flags can be specified by their name, their nickname or
2316 * numerically. Multiple flags can be specified in the form
2317 * <literal>"( flag1 | flag2 | ... )"</literal>.
2319 * Return value: %TRUE if @gstring could be parsed and @property_value
2320 * has been set to the resulting flags value.
2323 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2324 const GString *gstring,
2325 GValue *property_value)
2328 gboolean success = FALSE;
2331 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2332 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2334 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2335 scanner = gtk_rc_scanner_new ();
2336 g_scanner_input_text (scanner, gstring->str, gstring->len);
2338 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2339 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2340 scanner->next_token == G_TOKEN_INT)
2342 guint token, flags_value = 0;
2344 token = parse_flags_value (scanner, class, &flags_value);
2346 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2349 g_value_set_flags (property_value, flags_value);
2353 else if (g_scanner_get_next_token (scanner) == '(')
2355 guint token, flags_value = 0;
2357 /* parse first value */
2358 token = parse_flags_value (scanner, class, &flags_value);
2360 /* parse nth values, preceeded by '|' */
2361 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2362 token = parse_flags_value (scanner, class, &flags_value);
2364 /* done, last token must have closed expression */
2365 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2366 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2368 g_value_set_flags (property_value, flags_value);
2372 g_scanner_destroy (scanner);
2378 get_braced_int (GScanner *scanner,
2385 g_scanner_get_next_token (scanner);
2386 if (scanner->token != '{')
2390 g_scanner_get_next_token (scanner);
2391 if (scanner->token != G_TOKEN_INT)
2394 *value = scanner->value.v_int;
2398 g_scanner_get_next_token (scanner);
2399 if (scanner->token != '}')
2404 g_scanner_get_next_token (scanner);
2405 if (scanner->token != ',')
2413 * gtk_rc_property_parse_requisition:
2414 * @pspec: a #GParamSpec
2415 * @gstring: the #GString to be parsed
2416 * @property_value: a #GValue which must hold boxed values.
2418 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2419 * or gtk_widget_class_install_style_property_parser() which parses a
2420 * requisition in the form
2421 * <literal>"{ width, height }"</literal> for integers %width and %height.
2423 * Return value: %TRUE if @gstring could be parsed and @property_value
2424 * has been set to the resulting #GtkRequisition.
2427 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2428 const GString *gstring,
2429 GValue *property_value)
2431 GtkRequisition requisition;
2433 gboolean success = FALSE;
2435 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2436 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2438 scanner = gtk_rc_scanner_new ();
2439 g_scanner_input_text (scanner, gstring->str, gstring->len);
2441 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2442 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2444 g_value_set_boxed (property_value, &requisition);
2448 g_scanner_destroy (scanner);
2454 * gtk_rc_property_parse_border:
2455 * @pspec: a #GParamSpec
2456 * @gstring: the #GString to be parsed
2457 * @property_value: a #GValue which must hold boxed values.
2459 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2460 * or gtk_widget_class_install_style_property_parser() which parses
2461 * borders in the form
2462 * <literal>"{ left, right, top, bottom }"</literal> for integers
2463 * %left, %right, %top and %bottom.
2465 * Return value: %TRUE if @gstring could be parsed and @property_value
2466 * has been set to the resulting #GtkBorder.
2469 gtk_rc_property_parse_border (const GParamSpec *pspec,
2470 const GString *gstring,
2471 GValue *property_value)
2475 gboolean success = FALSE;
2476 int left, right, top, bottom;
2478 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2479 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2481 scanner = gtk_rc_scanner_new ();
2482 g_scanner_input_text (scanner, gstring->str, gstring->len);
2484 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2485 get_braced_int (scanner, FALSE, FALSE, &right) &&
2486 get_braced_int (scanner, FALSE, FALSE, &top) &&
2487 get_braced_int (scanner, FALSE, TRUE, &bottom))
2490 border.right = right;
2492 border.bottom = bottom;
2493 g_value_set_boxed (property_value, &border);
2497 g_scanner_destroy (scanner);
2503 _gtk_settings_handle_event (GdkEventSetting *event)
2506 GtkSettings *settings;
2510 screen = gdk_window_get_screen (event->window);
2511 settings = gtk_settings_get_for_screen (screen);
2512 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2516 property_id = pspec->param_id;
2518 if (property_id == PROP_COLOR_SCHEME)
2520 GValue value = G_VALUE_INIT;
2522 g_value_init (&value, G_TYPE_STRING);
2523 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2524 g_value_set_static_string (&value, "");
2525 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2526 g_value_unset (&value);
2528 g_object_notify (G_OBJECT (settings), pspec->name);
2533 reset_rc_values_foreach (GQuark key_id,
2537 GtkSettingsValuePrivate *qvalue = data;
2538 GSList **to_reset = user_data;
2540 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2541 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2545 _gtk_settings_reset_rc_values (GtkSettings *settings)
2547 GtkSettingsPrivate *priv = settings->priv;
2548 GSList *to_reset = NULL;
2550 GParamSpec **pspecs, **p;
2553 /* Remove any queued settings */
2554 g_datalist_foreach (&priv->queued_settings,
2555 reset_rc_values_foreach,
2558 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2560 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2561 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2564 g_slist_free (to_reset);
2566 /* Now reset the active settings
2568 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2571 g_object_freeze_notify (G_OBJECT (settings));
2572 for (p = pspecs; *p; p++)
2574 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2576 GParamSpec *pspec = *p;
2578 g_param_value_set_default (pspec, &priv->property_values[i].value);
2579 g_object_notify (G_OBJECT (settings), pspec->name);
2583 g_object_thaw_notify (G_OBJECT (settings));
2588 settings_update_double_click (GtkSettings *settings)
2590 GtkSettingsPrivate *priv = settings->priv;
2592 if (gdk_screen_get_number (priv->screen) == 0)
2594 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2595 gint double_click_time;
2596 gint double_click_distance;
2598 g_object_get (settings,
2599 "gtk-double-click-time", &double_click_time,
2600 "gtk-double-click-distance", &double_click_distance,
2603 gdk_display_set_double_click_time (display, double_click_time);
2604 gdk_display_set_double_click_distance (display, double_click_distance);
2609 settings_update_modules (GtkSettings *settings)
2613 g_object_get (settings,
2614 "gtk-modules", &modules,
2617 _gtk_modules_settings_changed (settings, modules);
2623 settings_update_cursor_theme (GtkSettings *settings)
2625 #ifdef GDK_WINDOWING_X11
2626 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2627 gchar *theme = NULL;
2630 if (GDK_IS_X11_DISPLAY (display))
2632 g_object_get (settings,
2633 "gtk-cursor-theme-name", &theme,
2634 "gtk-cursor-theme-size", &size,
2637 gdk_x11_display_set_cursor_theme (display, theme, size);
2645 settings_update_font_options (GtkSettings *settings)
2647 GtkSettingsPrivate *priv = settings->priv;
2649 gchar *hint_style_str;
2650 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2652 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2654 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2655 cairo_font_options_t *options;
2657 g_object_get (settings,
2658 "gtk-xft-antialias", &antialias,
2659 "gtk-xft-hinting", &hinting,
2660 "gtk-xft-hintstyle", &hint_style_str,
2661 "gtk-xft-rgba", &rgba_str,
2664 options = cairo_font_options_create ();
2666 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2668 if (hinting >= 0 && !hinting)
2670 hint_style = CAIRO_HINT_STYLE_NONE;
2672 else if (hint_style_str)
2674 if (strcmp (hint_style_str, "hintnone") == 0)
2675 hint_style = CAIRO_HINT_STYLE_NONE;
2676 else if (strcmp (hint_style_str, "hintslight") == 0)
2677 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2678 else if (strcmp (hint_style_str, "hintmedium") == 0)
2679 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2680 else if (strcmp (hint_style_str, "hintfull") == 0)
2681 hint_style = CAIRO_HINT_STYLE_FULL;
2684 g_free (hint_style_str);
2686 cairo_font_options_set_hint_style (options, hint_style);
2690 if (strcmp (rgba_str, "rgb") == 0)
2691 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2692 else if (strcmp (rgba_str, "bgr") == 0)
2693 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2694 else if (strcmp (rgba_str, "vrgb") == 0)
2695 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2696 else if (strcmp (rgba_str, "vbgr") == 0)
2697 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2702 cairo_font_options_set_subpixel_order (options, subpixel_order);
2704 if (antialias >= 0 && !antialias)
2705 antialias_mode = CAIRO_ANTIALIAS_NONE;
2706 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2707 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2708 else if (antialias >= 0)
2709 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2711 cairo_font_options_set_antialias (options, antialias_mode);
2713 gdk_screen_set_font_options (priv->screen, options);
2715 cairo_font_options_destroy (options);
2719 settings_update_fontconfig (GtkSettings *settings)
2721 #ifdef GDK_WINDOWING_X11
2722 static guint last_update_timestamp;
2723 static gboolean last_update_needed;
2727 g_object_get (settings,
2728 "gtk-fontconfig-timestamp", ×tamp,
2731 /* if timestamp is the same as last_update_timestamp, we already have
2732 * updated fontconig on this timestamp (another screen requested it perhaps?),
2733 * just return the cached result.*/
2735 if (timestamp != last_update_timestamp)
2737 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2738 gboolean update_needed = FALSE;
2741 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2743 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2744 if (FcInitReinitialize ())
2745 update_needed = TRUE;
2748 last_update_timestamp = timestamp;
2749 last_update_needed = update_needed;
2752 return last_update_needed;
2755 #endif /* GDK_WINDOWING_X11 */
2759 settings_update_resolution (GtkSettings *settings)
2761 GtkSettingsPrivate *priv = settings->priv;
2765 g_object_get (settings,
2766 "gtk-xft-dpi", &dpi_int,
2770 dpi = dpi_int / 1024.;
2774 gdk_screen_set_resolution (priv->screen, dpi);
2779 GHashTable *color_hash;
2780 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2781 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2785 color_scheme_data_free (ColorSchemeData *data)
2789 g_hash_table_unref (data->color_hash);
2791 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2793 if (data->tables[i])
2794 g_hash_table_unref (data->tables[i]);
2795 g_free (data->lastentry[i]);
2798 g_slice_free (ColorSchemeData, data);
2802 settings_update_color_scheme (GtkSettings *settings)
2804 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2806 GtkSettingsPrivate *priv = settings->priv;
2807 ColorSchemeData *data;
2808 GValue value = G_VALUE_INIT;
2810 data = g_slice_new0 (ColorSchemeData);
2811 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2812 (GDestroyNotify) gdk_color_free);
2813 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2814 data, (GDestroyNotify) color_scheme_data_free);
2816 g_value_init (&value, G_TYPE_STRING);
2817 if (priv->screen && gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2819 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2820 g_value_unset (&value);
2826 settings_update_provider (GdkScreen *screen,
2827 GtkCssProvider **old,
2828 GtkCssProvider *new)
2834 gtk_style_context_remove_provider_for_screen (screen,
2835 GTK_STYLE_PROVIDER (*old));
2836 g_object_unref (*old);
2842 gtk_style_context_add_provider_for_screen (screen,
2843 GTK_STYLE_PROVIDER (new),
2844 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2845 *old = g_object_ref (new);
2851 settings_update_theme (GtkSettings *settings)
2853 GtkSettingsPrivate *priv = settings->priv;
2854 GtkCssProvider *provider = NULL;
2855 gboolean prefer_dark_theme;
2858 g_object_get (settings,
2859 "gtk-theme-name", &theme_name,
2860 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2863 if (theme_name && *theme_name)
2865 if (prefer_dark_theme)
2866 provider = gtk_css_provider_get_named (theme_name, "dark");
2869 provider = gtk_css_provider_get_named (theme_name, NULL);
2872 /* If we didn't find the named theme, fall back */
2874 provider = gtk_css_provider_get_named ("Raleigh", NULL);
2876 settings_update_provider (priv->screen, &priv->theme_provider, provider);
2878 if (theme_name && *theme_name)
2883 /* reload per-theme settings */
2884 theme_dir = _gtk_css_provider_get_theme_dir ();
2885 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2887 if (g_file_test (path, G_FILE_TEST_EXISTS))
2888 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2894 g_free (theme_name);
2898 settings_update_key_theme (GtkSettings *settings)
2900 GtkSettingsPrivate *priv = settings->priv;
2901 GtkCssProvider *provider = NULL;
2902 gchar *key_theme_name;
2904 g_object_get (settings,
2905 "gtk-key-theme-name", &key_theme_name,
2908 if (key_theme_name && *key_theme_name)
2909 provider = gtk_css_provider_get_named (key_theme_name, "keys");
2911 settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2912 g_free (key_theme_name);
2916 add_color_to_hash (gchar *name,
2922 old = g_hash_table_lookup (target, name);
2923 if (!old || !gdk_color_equal (old, color))
2925 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2934 add_colors_to_hash_from_string (GHashTable *hash,
2935 const gchar *colors)
2937 gchar *s, *p, *name;
2939 gboolean changed = FALSE;
2942 copy = g_strdup (colors);
2947 p = strchr (s, ':');
2962 if (*s == '\n' || *s == ';')
2971 if (gdk_color_parse (p, &color))
2972 changed |= add_color_to_hash (name, &color, hash);
2981 update_color_hash (ColorSchemeData *data,
2983 GtkSettingsSource source)
2985 gboolean changed = FALSE;
2987 GHashTable *old_hash;
2988 GHashTableIter iter;
2992 if ((str == NULL || *str == '\0') &&
2993 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2996 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2999 /* For the THEME source we merge the values rather than over-writing
3000 * them, since multiple rc files might define independent sets of colors
3002 if ((source != GTK_SETTINGS_SOURCE_THEME) &&
3003 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
3005 g_hash_table_unref (data->tables[source]);
3006 data->tables[source] = NULL;
3007 changed = TRUE; /* We can't rely on the code below since str might be "" */
3010 if (data->tables[source] == NULL)
3011 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
3013 (GDestroyNotify) gdk_color_free);
3015 g_free (data->lastentry[source]);
3016 data->lastentry[source] = g_strdup (str);
3018 changed |= add_colors_to_hash_from_string (data->tables[source], str);
3023 /* Rebuild the merged hash table. */
3024 if (data->color_hash)
3026 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
3027 (GDestroyNotify) gdk_color_free);
3029 g_hash_table_iter_init (&iter, data->color_hash);
3030 while (g_hash_table_iter_next (&iter, &name, &color))
3032 g_hash_table_insert (old_hash, name, color);
3033 g_hash_table_iter_steal (&iter);
3041 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
3043 if (data->tables[i])
3044 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
3050 /* now check if the merged hash has changed */
3052 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
3056 GHashTableIter iter;
3057 gpointer key, value, new_value;
3059 g_hash_table_iter_init (&iter, old_hash);
3060 while (g_hash_table_iter_next (&iter, &key, &value))
3062 new_value = g_hash_table_lookup (data->color_hash, key);
3063 if (!new_value || !gdk_color_equal (value, new_value))
3071 g_hash_table_unref (old_hash);
3080 merge_color_scheme (GtkSettings *settings,
3081 const GValue *value,
3082 GtkSettingsSource source)
3084 ColorSchemeData *data;
3085 const gchar *colors;
3087 g_object_freeze_notify (G_OBJECT (settings));
3089 colors = g_value_get_string (value);
3091 settings_update_color_scheme (settings);
3093 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
3094 "gtk-color-scheme");
3096 if (update_color_hash (data, colors, source))
3097 g_object_notify (G_OBJECT (settings), "color-hash");
3099 g_object_thaw_notify (G_OBJECT (settings));
3103 get_color_hash (GtkSettings *settings)
3105 ColorSchemeData *data;
3107 settings_update_color_scheme (settings);
3109 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
3110 "gtk-color-scheme");
3112 return data->color_hash;
3116 append_color_scheme (gpointer key,
3120 gchar *name = (gchar *)key;
3121 GdkColor *color = (GdkColor *)value;
3122 GString *string = (GString *)data;
3124 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
3125 name, color->red, color->green, color->blue);
3129 get_color_scheme (GtkSettings *settings)
3131 ColorSchemeData *data;
3134 settings_update_color_scheme (settings);
3136 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
3137 "gtk-color-scheme");
3139 string = g_string_new ("");
3141 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
3143 return g_string_free (string, FALSE);
3147 _gtk_settings_get_screen (GtkSettings *settings)
3149 return settings->priv->screen;
3154 gtk_settings_load_from_key_file (GtkSettings *settings,
3156 GtkSettingsSource source)
3167 keyfile = g_key_file_new ();
3169 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
3171 g_warning ("Failed to parse %s: %s", path, error->message);
3173 g_error_free (error);
3178 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3181 g_warning ("Failed to parse %s: %s", path, error->message);
3182 g_error_free (error);
3186 for (i = 0; i < n_keys; i++)
3191 GtkSettingsValue svalue = { NULL, { 0, }, };
3194 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3197 g_warning ("Unknown key %s in %s", key, path);
3201 if (pspec->owner_type != G_OBJECT_TYPE (settings))
3204 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3207 case G_TYPE_BOOLEAN:
3211 g_value_init (&svalue.value, G_TYPE_LONG);
3212 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3214 g_value_set_long (&svalue.value, b_val);
3222 g_value_init (&svalue.value, G_TYPE_LONG);
3223 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3225 g_value_set_long (&svalue.value, i_val);
3233 g_value_init (&svalue.value, G_TYPE_DOUBLE);
3234 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3236 g_value_set_double (&svalue.value, d_val);
3244 g_value_init (&svalue.value, G_TYPE_GSTRING);
3245 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3247 g_value_take_boxed (&svalue.value, g_string_new (s_val));
3254 g_warning ("Error setting %s in %s: %s", key, path, error->message);
3255 g_error_free (error);
3260 if (g_getenv ("GTK_DEBUG"))
3261 svalue.origin = (gchar *)path;
3262 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3263 g_value_unset (&svalue.value);
3269 g_key_file_free (keyfile);