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 "gtktypebuiltins.h"
36 #include "gtkversion.h"
38 #ifdef GDK_WINDOWING_X11
40 #include <pango/pangofc-fontmap.h>
43 #ifdef GDK_WINDOWING_QUARTZ
44 #include "quartz/gdkquartz.h"
48 #include "gtkwin32themeprivate.h"
52 #undef GDK_DEPRECATED_FOR
53 #define GDK_DEPRECATED
54 #define GDK_DEPRECATED_FOR(f)
56 #include "deprecated/gtkrc.h"
61 * @Short_description: Sharing settings between applications
64 * GtkSettings provide a mechanism to share global settings between
67 * On the X window system, this sharing is realized by an
68 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
69 * manager that is usually part of the desktop environment, along with
70 * utilities that let the user change these settings. In the absence of
71 * an Xsettings manager, GTK+ reads default values for settings from
72 * <filename>settings.ini</filename> files in
73 * <filename>/etc/gtk-3.0</filename>, <filename>$XDG_CONFIG_DIRS/gtk-3.0</filename>
74 * and <filename>$XDG_CONFIG_HOME/gtk-3.0</filename>.
75 * These files must be valid key files (see #GKeyFile), and have
76 * a section called Settings. Themes can also provide default values
77 * for settings by installing a <filename>settings.ini</filename> file
78 * next to their <filename>gtk.css</filename> file.
80 * Applications can override system-wide settings with
81 * gtk_settings_set_string_property(), gtk_settings_set_long_property(),
82 * etc. This should be restricted to special cases though; GtkSettings are
83 * not meant as an application configuration facility. When doing so, you
84 * need to be aware that settings that are specific to individual widgets
85 * may not be available before the widget type has been realized at least
86 * once. The following example demonstrates a way to do this:
87 * <informalexample><programlisting>
88 * gtk_init (&argc, &argv);
90 * /* make sure the type is realized */
91 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
93 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
94 * </programlisting></informalexample>
96 * There is one GtkSettings instance per screen. It can be obtained with
97 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
98 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
99 * GtkSettings instance for the default screen.
103 #define DEFAULT_TIMEOUT_INITIAL 200
104 #define DEFAULT_TIMEOUT_REPEAT 20
105 #define DEFAULT_TIMEOUT_EXPAND 500
107 typedef struct _GtkSettingsPropertyValue GtkSettingsPropertyValue;
108 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
110 struct _GtkSettingsPrivate
112 GData *queued_settings; /* of type GtkSettingsValue* */
113 GtkSettingsPropertyValue *property_values;
115 GtkCssProvider *theme_provider;
116 GtkCssProvider *key_theme_provider;
117 GtkStyleProperties *style;
122 GTK_SETTINGS_SOURCE_DEFAULT,
123 GTK_SETTINGS_SOURCE_THEME,
124 GTK_SETTINGS_SOURCE_XSETTING,
125 GTK_SETTINGS_SOURCE_APPLICATION
128 struct _GtkSettingsValuePrivate
130 GtkSettingsValue public;
131 GtkSettingsSource source;
134 struct _GtkSettingsPropertyValue
137 GtkSettingsSource source;
142 PROP_DOUBLE_CLICK_TIME,
143 PROP_DOUBLE_CLICK_DISTANCE,
145 PROP_CURSOR_BLINK_TIME,
146 PROP_CURSOR_BLINK_TIMEOUT,
149 PROP_ICON_THEME_NAME,
150 PROP_FALLBACK_ICON_THEME,
153 PROP_DND_DRAG_THRESHOLD,
162 PROP_CURSOR_THEME_NAME,
163 PROP_CURSOR_THEME_SIZE,
164 PROP_ALTERNATIVE_BUTTON_ORDER,
165 PROP_ALTERNATIVE_SORT_ARROWS,
166 PROP_SHOW_INPUT_METHOD_MENU,
167 PROP_SHOW_UNICODE_MENU,
168 PROP_TIMEOUT_INITIAL,
172 PROP_ENABLE_ANIMATIONS,
173 PROP_TOUCHSCREEN_MODE,
174 PROP_TOOLTIP_TIMEOUT,
175 PROP_TOOLTIP_BROWSE_TIMEOUT,
176 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
177 PROP_KEYNAV_CURSOR_ONLY,
178 PROP_KEYNAV_WRAP_AROUND,
181 PROP_FILE_CHOOSER_BACKEND,
183 PROP_PRINT_PREVIEW_COMMAND,
184 PROP_ENABLE_MNEMONICS,
186 PROP_RECENT_FILES_LIMIT,
188 PROP_RECENT_FILES_MAX_AGE,
189 PROP_FONTCONFIG_TIMESTAMP,
190 PROP_SOUND_THEME_NAME,
191 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
192 PROP_ENABLE_EVENT_SOUNDS,
193 PROP_ENABLE_TOOLTIPS,
195 PROP_TOOLBAR_ICON_SIZE,
197 PROP_PRIMARY_BUTTON_WARPS_SLIDER,
199 PROP_APPLICATION_PREFER_DARK_THEME,
201 PROP_ENTRY_SELECT_ON_FOCUS,
202 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
204 PROP_MENU_BAR_POPUP_DELAY,
205 PROP_SCROLLED_WINDOW_PLACEMENT,
206 PROP_CAN_CHANGE_ACCELS,
207 PROP_MENU_POPUP_DELAY,
208 PROP_MENU_POPDOWN_DELAY,
209 PROP_LABEL_SELECT_ON_FOCUS,
211 PROP_IM_PREEDIT_STYLE,
212 PROP_IM_STATUS_STYLE,
213 PROP_SHELL_SHOWS_APP_MENU,
214 PROP_SHELL_SHOWS_MENUBAR,
215 PROP_ENABLE_PRIMARY_PASTE
218 /* --- prototypes --- */
219 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
220 static void gtk_settings_provider_private_init (GtkStyleProviderPrivateInterface *iface);
222 static void gtk_settings_finalize (GObject *object);
223 static void gtk_settings_get_property (GObject *object,
227 static void gtk_settings_set_property (GObject *object,
231 static void gtk_settings_notify (GObject *object,
233 static guint settings_install_property_parser (GtkSettingsClass *class,
235 GtkRcPropertyParser parser);
236 static void settings_update_double_click (GtkSettings *settings);
237 static void settings_update_modules (GtkSettings *settings);
239 static void settings_update_cursor_theme (GtkSettings *settings);
240 static void settings_update_resolution (GtkSettings *settings);
241 static void settings_update_font_options (GtkSettings *settings);
242 static gboolean settings_update_fontconfig (GtkSettings *settings);
243 static void settings_update_theme (GtkSettings *settings);
244 static void settings_update_key_theme (GtkSettings *settings);
246 static void gtk_settings_load_from_key_file (GtkSettings *settings,
248 GtkSettingsSource source);
249 static void settings_update_provider (GdkScreen *screen,
250 GtkCssProvider **old,
251 GtkCssProvider *new);
253 /* the default palette for GtkColorSelelection */
254 static const gchar default_color_palette[] =
255 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
256 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
258 /* --- variables --- */
259 static GQuark quark_property_parser = 0;
260 static GSList *object_list = NULL;
261 static guint class_n_properties = 0;
264 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
265 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
266 gtk_settings_provider_iface_init)
267 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER_PRIVATE,
268 gtk_settings_provider_private_init));
270 /* --- functions --- */
272 gtk_settings_init (GtkSettings *settings)
274 GtkSettingsPrivate *priv;
275 GParamSpec **pspecs, **p;
278 const gchar * const *config_dirs;
279 const gchar *config_dir;
281 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
285 settings->priv = priv;
286 g_datalist_init (&priv->queued_settings);
287 object_list = g_slist_prepend (object_list, settings);
289 priv->theme_provider = gtk_css_provider_new ();
291 /* build up property array for all yet existing properties and queue
292 * notification for them (at least notification for internal properties
293 * will instantly be caught)
295 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
296 for (p = pspecs; *p; p++)
297 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
299 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
301 g_object_freeze_notify (G_OBJECT (settings));
303 for (p = pspecs; *p; p++)
305 GParamSpec *pspec = *p;
306 GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
308 if (pspec->owner_type != G_OBJECT_TYPE (settings))
310 g_value_init (&priv->property_values[i].value, value_type);
311 g_param_value_set_default (pspec, &priv->property_values[i].value);
313 g_object_notify (G_OBJECT (settings), pspec->name);
314 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
319 path = g_build_filename (_gtk_get_sysconfdir (), "gtk-3.0", "settings.ini", NULL);
320 if (g_file_test (path, G_FILE_TEST_EXISTS))
321 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
324 config_dirs = g_get_system_config_dirs ();
325 for (config_dir = *config_dirs; *config_dirs != NULL; config_dirs++)
327 path = g_build_filename (config_dir, "gtk-3.0", "settings.ini", NULL);
328 if (g_file_test (path, G_FILE_TEST_EXISTS))
329 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
333 path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "settings.ini", NULL);
334 if (g_file_test (path, G_FILE_TEST_EXISTS))
335 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
338 g_object_thaw_notify (G_OBJECT (settings));
342 gtk_settings_class_init (GtkSettingsClass *class)
344 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
347 gobject_class->finalize = gtk_settings_finalize;
348 gobject_class->get_property = gtk_settings_get_property;
349 gobject_class->set_property = gtk_settings_set_property;
350 gobject_class->notify = gtk_settings_notify;
352 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
353 result = settings_install_property_parser (class,
354 g_param_spec_int ("gtk-double-click-time",
355 P_("Double Click Time"),
356 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
358 GTK_PARAM_READWRITE),
360 g_assert (result == PROP_DOUBLE_CLICK_TIME);
361 result = settings_install_property_parser (class,
362 g_param_spec_int ("gtk-double-click-distance",
363 P_("Double Click Distance"),
364 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
366 GTK_PARAM_READWRITE),
368 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
371 * GtkSettings:gtk-cursor-blink:
373 * Whether the cursor should blink.
375 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
376 * which allows more flexible control over cursor blinking.
378 result = settings_install_property_parser (class,
379 g_param_spec_boolean ("gtk-cursor-blink",
381 P_("Whether the cursor should blink"),
383 GTK_PARAM_READWRITE),
385 g_assert (result == PROP_CURSOR_BLINK);
386 result = settings_install_property_parser (class,
387 g_param_spec_int ("gtk-cursor-blink-time",
388 P_("Cursor Blink Time"),
389 P_("Length of the cursor blink cycle, in milliseconds"),
391 GTK_PARAM_READWRITE),
393 g_assert (result == PROP_CURSOR_BLINK_TIME);
396 * GtkSettings:gtk-cursor-blink-timeout:
398 * Time after which the cursor stops blinking, in seconds.
399 * The timer is reset after each user interaction.
401 * Setting this to zero has the same effect as setting
402 * #GtkSettings:gtk-cursor-blink to %FALSE.
406 result = settings_install_property_parser (class,
407 g_param_spec_int ("gtk-cursor-blink-timeout",
408 P_("Cursor Blink Timeout"),
409 P_("Time after which the cursor stops blinking, in seconds"),
410 1, G_MAXINT, G_MAXINT,
411 GTK_PARAM_READWRITE),
413 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
414 result = settings_install_property_parser (class,
415 g_param_spec_boolean ("gtk-split-cursor",
417 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
419 GTK_PARAM_READWRITE),
421 g_assert (result == PROP_SPLIT_CURSOR);
422 result = settings_install_property_parser (class,
423 g_param_spec_string ("gtk-theme-name",
425 P_("Name of theme to load"),
427 _gtk_win32_theme_get_default (),
431 GTK_PARAM_READWRITE),
433 g_assert (result == PROP_THEME_NAME);
435 result = settings_install_property_parser (class,
436 g_param_spec_string ("gtk-icon-theme-name",
437 P_("Icon Theme Name"),
438 P_("Name of icon theme to use"),
440 GTK_PARAM_READWRITE),
442 g_assert (result == PROP_ICON_THEME_NAME);
444 result = settings_install_property_parser (class,
445 g_param_spec_string ("gtk-fallback-icon-theme",
446 P_("Fallback Icon Theme Name"),
447 P_("Name of a icon theme to fall back to"),
449 GTK_PARAM_READWRITE),
451 g_assert (result == PROP_FALLBACK_ICON_THEME);
453 result = settings_install_property_parser (class,
454 g_param_spec_string ("gtk-key-theme-name",
455 P_("Key Theme Name"),
456 P_("Name of key theme to load"),
458 GTK_PARAM_READWRITE),
460 g_assert (result == PROP_KEY_THEME_NAME);
462 result = settings_install_property_parser (class,
463 g_param_spec_string ("gtk-menu-bar-accel",
464 P_("Menu bar accelerator"),
465 P_("Keybinding to activate the menu bar"),
467 GTK_PARAM_READWRITE),
469 g_assert (result == PROP_MENU_BAR_ACCEL);
471 result = settings_install_property_parser (class,
472 g_param_spec_int ("gtk-dnd-drag-threshold",
473 P_("Drag threshold"),
474 P_("Number of pixels the cursor can move before dragging"),
476 GTK_PARAM_READWRITE),
478 g_assert (result == PROP_DND_DRAG_THRESHOLD);
480 result = settings_install_property_parser (class,
481 g_param_spec_string ("gtk-font-name",
483 P_("Name of default font to use"),
485 GTK_PARAM_READWRITE),
487 g_assert (result == PROP_FONT_NAME);
490 * GtkSettings:gtk-icon-sizes:
492 * A list of icon sizes. The list is separated by colons, and
495 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
497 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
498 * GTK+ itself use the following named icon sizes: gtk-menu,
499 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
500 * gtk-dialog. Applications can register their own named icon
501 * sizes with gtk_icon_size_register().
503 result = settings_install_property_parser (class,
504 g_param_spec_string ("gtk-icon-sizes",
506 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
508 GTK_PARAM_READWRITE),
510 g_assert (result == PROP_ICON_SIZES);
512 result = settings_install_property_parser (class,
513 g_param_spec_string ("gtk-modules",
515 P_("List of currently active GTK modules"),
517 GTK_PARAM_READWRITE),
519 g_assert (result == PROP_MODULES);
521 result = settings_install_property_parser (class,
522 g_param_spec_int ("gtk-xft-antialias",
524 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
526 GTK_PARAM_READWRITE),
529 g_assert (result == PROP_XFT_ANTIALIAS);
531 result = settings_install_property_parser (class,
532 g_param_spec_int ("gtk-xft-hinting",
534 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
536 GTK_PARAM_READWRITE),
539 g_assert (result == PROP_XFT_HINTING);
541 result = settings_install_property_parser (class,
542 g_param_spec_string ("gtk-xft-hintstyle",
543 P_("Xft Hint Style"),
544 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
546 GTK_PARAM_READWRITE),
549 g_assert (result == PROP_XFT_HINTSTYLE);
551 result = settings_install_property_parser (class,
552 g_param_spec_string ("gtk-xft-rgba",
554 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
556 GTK_PARAM_READWRITE),
559 g_assert (result == PROP_XFT_RGBA);
561 result = settings_install_property_parser (class,
562 g_param_spec_int ("gtk-xft-dpi",
564 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
566 GTK_PARAM_READWRITE),
569 g_assert (result == PROP_XFT_DPI);
571 result = settings_install_property_parser (class,
572 g_param_spec_string ("gtk-cursor-theme-name",
573 P_("Cursor theme name"),
574 P_("Name of the cursor theme to use, or NULL to use the default theme"),
576 GTK_PARAM_READWRITE),
578 g_assert (result == PROP_CURSOR_THEME_NAME);
580 result = settings_install_property_parser (class,
581 g_param_spec_int ("gtk-cursor-theme-size",
582 P_("Cursor theme size"),
583 P_("Size to use for cursors, or 0 to use the default size"),
585 GTK_PARAM_READWRITE),
588 g_assert (result == PROP_CURSOR_THEME_SIZE);
590 result = settings_install_property_parser (class,
591 g_param_spec_boolean ("gtk-alternative-button-order",
592 P_("Alternative button order"),
593 P_("Whether buttons in dialogs should use the alternative button order"),
595 GTK_PARAM_READWRITE),
597 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
600 * GtkSettings:gtk-alternative-sort-arrows:
602 * Controls the direction of the sort indicators in sorted list and tree
603 * views. By default an arrow pointing down means the column is sorted
604 * in ascending order. When set to %TRUE, this order will be inverted.
608 result = settings_install_property_parser (class,
609 g_param_spec_boolean ("gtk-alternative-sort-arrows",
610 P_("Alternative sort indicator direction"),
611 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
613 GTK_PARAM_READWRITE),
615 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
617 result = settings_install_property_parser (class,
618 g_param_spec_boolean ("gtk-show-input-method-menu",
619 P_("Show the 'Input Methods' menu"),
620 P_("Whether the context menus of entries and text views should offer to change the input method"),
622 GTK_PARAM_READWRITE),
624 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
626 result = settings_install_property_parser (class,
627 g_param_spec_boolean ("gtk-show-unicode-menu",
628 P_("Show the 'Insert Unicode Control Character' menu"),
629 P_("Whether the context menus of entries and text views should offer to insert control characters"),
631 GTK_PARAM_READWRITE),
633 g_assert (result == PROP_SHOW_UNICODE_MENU);
635 result = settings_install_property_parser (class,
636 g_param_spec_int ("gtk-timeout-initial",
638 P_("Starting value for timeouts, when button is pressed"),
639 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
640 GTK_PARAM_READWRITE),
643 g_assert (result == PROP_TIMEOUT_INITIAL);
645 result = settings_install_property_parser (class,
646 g_param_spec_int ("gtk-timeout-repeat",
647 P_("Repeat timeout"),
648 P_("Repeat value for timeouts, when button is pressed"),
649 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
650 GTK_PARAM_READWRITE),
653 g_assert (result == PROP_TIMEOUT_REPEAT);
655 result = settings_install_property_parser (class,
656 g_param_spec_int ("gtk-timeout-expand",
657 P_("Expand timeout"),
658 P_("Expand value for timeouts, when a widget is expanding a new region"),
659 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
660 GTK_PARAM_READWRITE),
663 g_assert (result == PROP_TIMEOUT_EXPAND);
666 * GtkSettings:gtk-color-scheme:
668 * A palette of named colors for use in themes. The format of the string is
674 * Color names must be acceptable as identifiers in the
675 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
676 * color specifications must be in the format accepted by
679 * Note that due to the way the color tables from different sources are
680 * merged, color specifications will be converted to hexadecimal form
681 * when getting this property.
683 * Starting with GTK+ 2.12, the entries can alternatively be separated
684 * by ';' instead of newlines:
686 * name1: color1; name2: color2; ...
691 * Deprecated: 3.8: Color scheme support was dropped and is no longer supported.
692 * You can still set this property, but it will be ignored.
694 result = settings_install_property_parser (class,
695 g_param_spec_string ("gtk-color-scheme",
697 P_("A palette of named colors for use in themes"),
699 GTK_PARAM_READWRITE),
702 g_assert (result == PROP_COLOR_SCHEME);
704 result = settings_install_property_parser (class,
705 g_param_spec_boolean ("gtk-enable-animations",
706 P_("Enable Animations"),
707 P_("Whether to enable toolkit-wide animations."),
709 GTK_PARAM_READWRITE),
712 g_assert (result == PROP_ENABLE_ANIMATIONS);
715 * GtkSettings:gtk-touchscreen-mode:
717 * When %TRUE, there are no motion notify events delivered on this screen,
718 * and widgets can't use the pointer hovering them for any essential
723 * Deprecated: 3.4. Generally, the behavior for touchscreen input should be
724 * performed dynamically based on gdk_event_get_source_device().
726 result = settings_install_property_parser (class,
727 g_param_spec_boolean ("gtk-touchscreen-mode",
728 P_("Enable Touchscreen Mode"),
729 P_("When TRUE, there are no motion notify events delivered on this screen"),
731 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED),
734 g_assert (result == PROP_TOUCHSCREEN_MODE);
737 * GtkSettings:gtk-tooltip-timeout:
739 * Time, in milliseconds, after which a tooltip could appear if the
740 * cursor is hovering on top of a widget.
744 result = settings_install_property_parser (class,
745 g_param_spec_int ("gtk-tooltip-timeout",
746 P_("Tooltip timeout"),
747 P_("Timeout before tooltip is shown"),
750 GTK_PARAM_READWRITE),
753 g_assert (result == PROP_TOOLTIP_TIMEOUT);
756 * GtkSettings:gtk-tooltip-browse-timeout:
758 * Controls the time after which tooltips will appear when
759 * browse mode is enabled, in milliseconds.
761 * Browse mode is enabled when the mouse pointer moves off an object
762 * where a tooltip was currently being displayed. If the mouse pointer
763 * hits another object before the browse mode timeout expires (see
764 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
765 * amount of milliseconds specified by this setting to popup the tooltip
766 * for the new object.
770 result = settings_install_property_parser (class,
771 g_param_spec_int ("gtk-tooltip-browse-timeout",
772 P_("Tooltip browse timeout"),
773 P_("Timeout before tooltip is shown when browse mode is enabled"),
776 GTK_PARAM_READWRITE),
779 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
782 * GtkSettings:gtk-tooltip-browse-mode-timeout:
784 * Amount of time, in milliseconds, after which the browse mode
787 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
792 result = settings_install_property_parser (class,
793 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
794 P_("Tooltip browse mode timeout"),
795 P_("Timeout after which browse mode is disabled"),
798 GTK_PARAM_READWRITE),
801 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
804 * GtkSettings:gtk-keynav-cursor-only:
806 * When %TRUE, keyboard navigation should be able to reach all widgets
807 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
808 * to be present on the used input device.
812 result = settings_install_property_parser (class,
813 g_param_spec_boolean ("gtk-keynav-cursor-only",
814 P_("Keynav Cursor Only"),
815 P_("When TRUE, there are only cursor keys available to navigate widgets"),
817 GTK_PARAM_READWRITE),
820 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
823 * GtkSettings:gtk-keynav-wrap-around:
825 * When %TRUE, some widgets will wrap around when doing keyboard
826 * navigation, such as menus, menubars and notebooks.
830 result = settings_install_property_parser (class,
831 g_param_spec_boolean ("gtk-keynav-wrap-around",
832 P_("Keynav Wrap Around"),
833 P_("Whether to wrap around when keyboard-navigating widgets"),
835 GTK_PARAM_READWRITE),
838 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
841 * GtkSettings:gtk-error-bell:
843 * When %TRUE, keyboard navigation and other input-related errors
844 * will cause a beep. Since the error bell is implemented using
845 * gdk_window_beep(), the windowing system may offer ways to
846 * configure the error bell in many ways, such as flashing the
847 * window or similar visual effects.
851 result = settings_install_property_parser (class,
852 g_param_spec_boolean ("gtk-error-bell",
854 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
856 GTK_PARAM_READWRITE),
859 g_assert (result == PROP_ERROR_BELL);
862 * GtkSettings:color-hash:
864 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
865 * setting, mapping color names to #GdkColor<!-- -->s.
869 * Deprecated: 3.8: Will always return an empty hash table.
871 result = settings_install_property_parser (class,
872 g_param_spec_boxed ("color-hash",
874 P_("A hash table representation of the color scheme."),
878 g_assert (result == PROP_COLOR_HASH);
880 result = settings_install_property_parser (class,
881 g_param_spec_string ("gtk-file-chooser-backend",
882 P_("Default file chooser backend"),
883 P_("Name of the GtkFileChooser backend to use by default"),
885 GTK_PARAM_READWRITE),
887 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
890 * GtkSettings:gtk-print-backends:
892 * A comma-separated list of print backends to use in the print
893 * dialog. Available print backends depend on the GTK+ installation,
894 * and may include "file", "cups", "lpr" or "papi".
898 result = settings_install_property_parser (class,
899 g_param_spec_string ("gtk-print-backends",
900 P_("Default print backend"),
901 P_("List of the GtkPrintBackend backends to use by default"),
903 GTK_PARAM_READWRITE),
905 g_assert (result == PROP_PRINT_BACKENDS);
908 * GtkSettings:gtk-print-preview-command:
910 * A command to run for displaying the print preview. The command
911 * should contain a %f placeholder, which will get replaced by
912 * the path to the pdf file. The command may also contain a %s
913 * placeholder, which will get replaced by the path to a file
914 * containing the print settings in the format produced by
915 * gtk_print_settings_to_file().
917 * The preview application is responsible for removing the pdf file
918 * and the print settings file when it is done.
922 result = settings_install_property_parser (class,
923 g_param_spec_string ("gtk-print-preview-command",
924 P_("Default command to run when displaying a print preview"),
925 P_("Command to run when displaying a print preview"),
926 GTK_PRINT_PREVIEW_COMMAND,
927 GTK_PARAM_READWRITE),
929 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
932 * GtkSettings:gtk-enable-mnemonics:
934 * Whether labels and menu items should have visible mnemonics which
939 result = settings_install_property_parser (class,
940 g_param_spec_boolean ("gtk-enable-mnemonics",
941 P_("Enable Mnemonics"),
942 P_("Whether labels should have mnemonics"),
944 GTK_PARAM_READWRITE),
946 g_assert (result == PROP_ENABLE_MNEMONICS);
949 * GtkSettings:gtk-enable-accels:
951 * Whether menu items should have visible accelerators which can be
956 result = settings_install_property_parser (class,
957 g_param_spec_boolean ("gtk-enable-accels",
958 P_("Enable Accelerators"),
959 P_("Whether menu items should have accelerators"),
961 GTK_PARAM_READWRITE),
963 g_assert (result == PROP_ENABLE_ACCELS);
966 * GtkSettings:gtk-recent-files-limit:
968 * The number of recently used files that should be displayed by default by
969 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
970 * -1 means every recently used file stored.
974 result = settings_install_property_parser (class,
975 g_param_spec_int ("gtk-recent-files-limit",
976 P_("Recent Files Limit"),
977 P_("Number of recently used files"),
980 GTK_PARAM_READWRITE),
982 g_assert (result == PROP_RECENT_FILES_LIMIT);
985 * GtkSettings:gtk-im-module:
987 * Which IM (input method) module should be used by default. This is the
988 * input method that will be used if the user has not explicitly chosen
989 * another input method from the IM context menu.
990 * This also can be a colon-separated list of input methods, which GTK+
991 * will try in turn until it finds one available on the system.
993 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
995 result = settings_install_property_parser (class,
996 g_param_spec_string ("gtk-im-module",
997 P_("Default IM module"),
998 P_("Which IM module should be used by default"),
1000 GTK_PARAM_READWRITE),
1002 g_assert (result == PROP_IM_MODULE);
1005 * GtkSettings:gtk-recent-files-max-age:
1007 * The maximum age, in days, of the items inside the recently used
1008 * resources list. Items older than this setting will be excised
1009 * from the list. If set to 0, the list will always be empty; if
1010 * set to -1, no item will be removed.
1014 result = settings_install_property_parser (class,
1015 g_param_spec_int ("gtk-recent-files-max-age",
1016 P_("Recent Files Max Age"),
1017 P_("Maximum age of recently used files, in days"),
1020 GTK_PARAM_READWRITE),
1022 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
1024 result = settings_install_property_parser (class,
1025 g_param_spec_uint ("gtk-fontconfig-timestamp",
1026 P_("Fontconfig configuration timestamp"),
1027 P_("Timestamp of current fontconfig configuration"),
1029 GTK_PARAM_READWRITE),
1032 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
1035 * GtkSettings:gtk-sound-theme-name:
1037 * The XDG sound theme to use for event sounds.
1039 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1040 * for more information on event sounds and sound themes.
1042 * GTK+ itself does not support event sounds, you have to use a loadable
1043 * module like the one that comes with libcanberra.
1047 result = settings_install_property_parser (class,
1048 g_param_spec_string ("gtk-sound-theme-name",
1049 P_("Sound Theme Name"),
1050 P_("XDG sound theme name"),
1052 GTK_PARAM_READWRITE),
1054 g_assert (result == PROP_SOUND_THEME_NAME);
1057 * GtkSettings:gtk-enable-input-feedback-sounds:
1059 * Whether to play event sounds as feedback to user input.
1061 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1062 * for more information on event sounds and sound themes.
1064 * GTK+ itself does not support event sounds, you have to use a loadable
1065 * module like the one that comes with libcanberra.
1069 result = settings_install_property_parser (class,
1070 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1071 /* Translators: this means sounds that are played as feedback to user input */
1072 P_("Audible Input Feedback"),
1073 P_("Whether to play event sounds as feedback to user input"),
1075 GTK_PARAM_READWRITE),
1077 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1080 * GtkSettings:gtk-enable-event-sounds:
1082 * Whether to play any event sounds at all.
1084 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1085 * for more information on event sounds and sound themes.
1087 * GTK+ itself does not support event sounds, you have to use a loadable
1088 * module like the one that comes with libcanberra.
1092 result = settings_install_property_parser (class,
1093 g_param_spec_boolean ("gtk-enable-event-sounds",
1094 P_("Enable Event Sounds"),
1095 P_("Whether to play any event sounds at all"),
1097 GTK_PARAM_READWRITE),
1099 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1102 * GtkSettings:gtk-enable-tooltips:
1104 * Whether tooltips should be shown on widgets.
1108 result = settings_install_property_parser (class,
1109 g_param_spec_boolean ("gtk-enable-tooltips",
1110 P_("Enable Tooltips"),
1111 P_("Whether tooltips should be shown on widgets"),
1113 GTK_PARAM_READWRITE),
1115 g_assert (result == PROP_ENABLE_TOOLTIPS);
1118 * GtkSettings:gtk-toolbar-style:
1120 * The size of icons in default toolbars.
1122 result = settings_install_property_parser (class,
1123 g_param_spec_enum ("gtk-toolbar-style",
1124 P_("Toolbar style"),
1125 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1126 GTK_TYPE_TOOLBAR_STYLE,
1128 GTK_PARAM_READWRITE),
1129 gtk_rc_property_parse_enum);
1130 g_assert (result == PROP_TOOLBAR_STYLE);
1133 * GtkSettings:gtk-toolbar-icon-size:
1135 * The size of icons in default toolbars.
1137 result = settings_install_property_parser (class,
1138 g_param_spec_enum ("gtk-toolbar-icon-size",
1139 P_("Toolbar Icon Size"),
1140 P_("The size of icons in default toolbars."),
1142 GTK_ICON_SIZE_LARGE_TOOLBAR,
1143 GTK_PARAM_READWRITE),
1144 gtk_rc_property_parse_enum);
1145 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1148 * GtkSettings:gtk-auto-mnemonics:
1150 * Whether mnemonics should be automatically shown and hidden when the user
1151 * presses the mnemonic activator.
1155 result = settings_install_property_parser (class,
1156 g_param_spec_boolean ("gtk-auto-mnemonics",
1157 P_("Auto Mnemonics"),
1158 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1160 GTK_PARAM_READWRITE),
1162 g_assert (result == PROP_AUTO_MNEMONICS);
1165 * GtkSettings:gtk-primary-button-warps-slider:
1167 * Whether a click in a #GtkRange trough should scroll to the click position or
1168 * scroll by a single page in the respective direction.
1172 result = settings_install_property_parser (class,
1173 g_param_spec_boolean ("gtk-primary-button-warps-slider",
1174 P_("Primary button warps slider"),
1175 P_("Whether a primary click on the trough should warp the slider into position"),
1177 GTK_PARAM_READWRITE),
1179 g_assert (result == PROP_PRIMARY_BUTTON_WARPS_SLIDER);
1182 * GtkSettings:gtk-visible-focus:
1184 * Whether 'focus rectangles' should be always visible, never visible,
1185 * or hidden until the user starts to use the keyboard.
1189 result = settings_install_property_parser (class,
1190 g_param_spec_enum ("gtk-visible-focus",
1191 P_("Visible Focus"),
1192 P_("Whether 'focus rectangles' should be hidden until the user starts to use the keyboard."),
1193 GTK_TYPE_POLICY_TYPE,
1195 GTK_PARAM_READWRITE),
1196 gtk_rc_property_parse_enum);
1197 g_assert (result == PROP_VISIBLE_FOCUS);
1200 * GtkSettings:gtk-application-prefer-dark-theme:
1202 * Whether the application prefers to use a dark theme. If a GTK+ theme
1203 * includes a dark variant, it will be used instead of the configured
1206 * Some applications benefit from minimizing the amount of light pollution that
1207 * interferes with the content. Good candidates for dark themes are photo and
1208 * video editors that make the actual content get all the attention and minimize
1209 * the distraction of the chrome.
1211 * Dark themes should not be used for documents, where large spaces are white/light
1212 * and the dark chrome creates too much contrast (web browser, text editor...).
1216 result = settings_install_property_parser (class,
1217 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1218 P_("Application prefers a dark theme"),
1219 P_("Whether the application prefers to have a dark theme."),
1221 GTK_PARAM_READWRITE),
1223 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1226 * GtkSettings::gtk-button-images:
1228 * Whether images should be shown on buttons
1232 result = settings_install_property_parser (class,
1233 g_param_spec_boolean ("gtk-button-images",
1234 P_("Show button images"),
1235 P_("Whether images should be shown on buttons"),
1237 GTK_PARAM_READWRITE),
1239 g_assert (result == PROP_BUTTON_IMAGES);
1241 result = settings_install_property_parser (class,
1242 g_param_spec_boolean ("gtk-entry-select-on-focus",
1243 P_("Select on focus"),
1244 P_("Whether to select the contents of an entry when it is focused"),
1246 GTK_PARAM_READWRITE),
1248 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1251 * GtkSettings:gtk-entry-password-hint-timeout:
1253 * How long to show the last input character in hidden
1254 * entries. This value is in milliseconds. 0 disables showing the
1255 * last char. 600 is a good value for enabling it.
1259 result = settings_install_property_parser (class,
1260 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1261 P_("Password Hint Timeout"),
1262 P_("How long to show the last input character in hidden entries"),
1265 GTK_PARAM_READWRITE),
1267 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1269 result = settings_install_property_parser (class,
1270 g_param_spec_boolean ("gtk-menu-images",
1271 P_("Show menu images"),
1272 P_("Whether images should be shown in menus"),
1274 GTK_PARAM_READWRITE),
1276 g_assert (result == PROP_MENU_IMAGES);
1278 result = settings_install_property_parser (class,
1279 g_param_spec_int ("gtk-menu-bar-popup-delay",
1280 P_("Delay before drop down menus appear"),
1281 P_("Delay before the submenus of a menu bar appear"),
1284 GTK_PARAM_READWRITE),
1286 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1289 * GtkSettings:gtk-scrolled-window-placement:
1291 * Where the contents of scrolled windows are located with respect to the
1292 * scrollbars, if not overridden by the scrolled window's own placement.
1296 result = settings_install_property_parser (class,
1297 g_param_spec_enum ("gtk-scrolled-window-placement",
1298 P_("Scrolled Window Placement"),
1299 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1300 GTK_TYPE_CORNER_TYPE,
1301 GTK_CORNER_TOP_LEFT,
1302 GTK_PARAM_READWRITE),
1303 gtk_rc_property_parse_enum);
1304 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1306 result = settings_install_property_parser (class,
1307 g_param_spec_boolean ("gtk-can-change-accels",
1308 P_("Can change accelerators"),
1309 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1311 GTK_PARAM_READWRITE),
1313 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1315 result = settings_install_property_parser (class,
1316 g_param_spec_int ("gtk-menu-popup-delay",
1317 P_("Delay before submenus appear"),
1318 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1321 GTK_PARAM_READWRITE),
1323 g_assert (result == PROP_MENU_POPUP_DELAY);
1325 result = settings_install_property_parser (class,
1326 g_param_spec_int ("gtk-menu-popdown-delay",
1327 P_("Delay before hiding a submenu"),
1328 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1331 GTK_PARAM_READWRITE),
1333 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1335 result = settings_install_property_parser (class,
1336 g_param_spec_boolean ("gtk-label-select-on-focus",
1337 P_("Select on focus"),
1338 P_("Whether to select the contents of a selectable label when it is focused"),
1340 GTK_PARAM_READWRITE),
1342 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1344 result = settings_install_property_parser (class,
1345 g_param_spec_string ("gtk-color-palette",
1346 P_("Custom palette"),
1347 P_("Palette to use in the color selector"),
1348 default_color_palette,
1349 GTK_PARAM_READWRITE),
1351 g_assert (result == PROP_COLOR_PALETTE);
1353 result = settings_install_property_parser (class,
1354 g_param_spec_enum ("gtk-im-preedit-style",
1355 P_("IM Preedit style"),
1356 P_("How to draw the input method preedit string"),
1357 GTK_TYPE_IM_PREEDIT_STYLE,
1358 GTK_IM_PREEDIT_CALLBACK,
1359 GTK_PARAM_READWRITE),
1360 gtk_rc_property_parse_enum);
1361 g_assert (result == PROP_IM_PREEDIT_STYLE);
1363 result = settings_install_property_parser (class,
1364 g_param_spec_enum ("gtk-im-status-style",
1365 P_("IM Status style"),
1366 P_("How to draw the input method statusbar"),
1367 GTK_TYPE_IM_STATUS_STYLE,
1368 GTK_IM_STATUS_CALLBACK,
1369 GTK_PARAM_READWRITE),
1370 gtk_rc_property_parse_enum);
1371 g_assert (result == PROP_IM_STATUS_STYLE);
1373 result = settings_install_property_parser (class,
1374 g_param_spec_boolean ("gtk-shell-shows-app-menu",
1375 P_("Desktop shell shows app menu"),
1376 P_("Set to TRUE if the desktop environment "
1377 "is displaying the app menu, FALSE if "
1378 "the app should display it itself."),
1379 FALSE, GTK_PARAM_READWRITE),
1381 g_assert (result == PROP_SHELL_SHOWS_APP_MENU);
1383 result = settings_install_property_parser (class,
1384 g_param_spec_boolean ("gtk-shell-shows-menubar",
1385 P_("Desktop shell shows the menubar"),
1386 P_("Set to TRUE if the desktop environment "
1387 "is displaying the menubar, FALSE if "
1388 "the app should display it itself."),
1389 FALSE, GTK_PARAM_READWRITE),
1391 g_assert (result == PROP_SHELL_SHOWS_MENUBAR);
1394 * GtkSettings:gtk-enable-primary-paste:
1396 * Whether a middle click on a mouse should paste the
1397 * 'PRIMARY' clipboard content at the cursor location.
1401 result = settings_install_property_parser (class,
1402 g_param_spec_boolean ("gtk-enable-primary-paste",
1403 P_("Enable primary paste"),
1404 P_("Whether a middle click on a mouse should paste the 'PRIMARY' clipboard content at the cursor location."),
1406 GTK_PARAM_READWRITE),
1408 g_assert (result == PROP_ENABLE_PRIMARY_PASTE);
1410 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1414 settings_ensure_style (GtkSettings *settings)
1416 GtkSettingsPrivate *priv = settings->priv;
1417 PangoFontDescription *font_desc;
1423 priv->style = gtk_style_properties_new ();
1425 g_object_get (settings,
1426 "gtk-font-name", &font_name,
1429 font_desc = pango_font_description_from_string (font_name);
1431 /* Unset attributes from this description,
1432 * so they do not override theme values */
1433 pango_font_description_unset_fields (font_desc, PANGO_FONT_MASK_WEIGHT);
1434 pango_font_description_unset_fields (font_desc, PANGO_FONT_MASK_STRETCH);
1435 pango_font_description_unset_fields (font_desc, PANGO_FONT_MASK_VARIANT);
1436 pango_font_description_unset_fields (font_desc, PANGO_FONT_MASK_STYLE);
1438 gtk_style_properties_set (priv->style, 0,
1442 pango_font_description_free (font_desc);
1447 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1451 static GtkCssValue *
1452 gtk_settings_style_provider_get_color (GtkStyleProviderPrivate *provider,
1455 GtkSettings *settings = GTK_SETTINGS (provider);
1457 settings_ensure_style (settings);
1459 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style), name);
1463 gtk_settings_style_provider_lookup (GtkStyleProviderPrivate *provider,
1464 const GtkCssMatcher *matcher,
1465 GtkCssLookup *lookup)
1467 GtkSettings *settings = GTK_SETTINGS (provider);
1469 settings_ensure_style (settings);
1471 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style),
1477 gtk_settings_style_provider_get_change (GtkStyleProviderPrivate *provider,
1478 const GtkCssMatcher *matcher)
1480 GtkSettings *settings = GTK_SETTINGS (provider);
1482 settings_ensure_style (settings);
1484 return _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style),
1489 gtk_settings_provider_private_init (GtkStyleProviderPrivateInterface *iface)
1491 iface->get_color = gtk_settings_style_provider_get_color;
1492 iface->lookup = gtk_settings_style_provider_lookup;
1493 iface->get_change = gtk_settings_style_provider_get_change;
1497 gtk_settings_finalize (GObject *object)
1499 GtkSettings *settings = GTK_SETTINGS (object);
1500 GtkSettingsPrivate *priv = settings->priv;
1503 object_list = g_slist_remove (object_list, settings);
1505 for (i = 0; i < class_n_properties; i++)
1506 g_value_unset (&priv->property_values[i].value);
1507 g_free (priv->property_values);
1509 g_datalist_clear (&priv->queued_settings);
1511 settings_update_provider (priv->screen, &priv->theme_provider, NULL);
1512 settings_update_provider (priv->screen, &priv->key_theme_provider, NULL);
1514 g_clear_object (&priv->style);
1516 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1520 settings_init_style (GtkSettings *settings)
1522 static GtkCssProvider *css_provider = NULL;
1524 GdkScreen *screen = settings->priv->screen;
1526 /* Add provider for user file */
1527 if (G_UNLIKELY (!css_provider))
1531 css_provider = gtk_css_provider_new ();
1532 css_path = g_build_filename (g_get_user_config_dir (),
1537 if (g_file_test (css_path,
1538 G_FILE_TEST_IS_REGULAR))
1539 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1544 gtk_style_context_add_provider_for_screen (screen,
1545 GTK_STYLE_PROVIDER (css_provider),
1546 GTK_STYLE_PROVIDER_PRIORITY_USER);
1548 gtk_style_context_add_provider_for_screen (screen,
1549 GTK_STYLE_PROVIDER (settings),
1550 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1552 gtk_style_context_add_provider_for_screen (screen,
1553 GTK_STYLE_PROVIDER (settings->priv->theme_provider),
1554 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1556 settings_update_theme (settings);
1557 settings_update_key_theme (settings);
1561 * gtk_settings_get_for_screen:
1562 * @screen: a #GdkScreen.
1564 * Gets the #GtkSettings object for @screen, creating it if necessary.
1566 * Return value: (transfer none): a #GtkSettings object.
1571 gtk_settings_get_for_screen (GdkScreen *screen)
1573 GtkSettings *settings;
1575 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1577 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1580 #ifdef GDK_WINDOWING_QUARTZ
1581 if (GDK_IS_QUARTZ_SCREEN (screen))
1582 settings = g_object_new (GTK_TYPE_SETTINGS,
1583 "gtk-key-theme-name", "Mac",
1584 "gtk-shell-shows-app-menu", TRUE,
1585 "gtk-shell-shows-menubar", TRUE,
1589 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1590 settings->priv->screen = screen;
1591 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1592 settings, g_object_unref);
1594 settings_init_style (settings);
1595 settings_update_double_click (settings);
1596 settings_update_cursor_theme (settings);
1597 settings_update_resolution (settings);
1598 settings_update_font_options (settings);
1605 * gtk_settings_get_default:
1607 * Gets the #GtkSettings object for the default GDK screen, creating
1608 * it if necessary. See gtk_settings_get_for_screen().
1610 * Return value: (transfer none): a #GtkSettings object. If there is no default
1611 * screen, then returns %NULL.
1614 gtk_settings_get_default (void)
1616 GdkScreen *screen = gdk_screen_get_default ();
1619 return gtk_settings_get_for_screen (screen);
1625 gtk_settings_set_property (GObject *object,
1627 const GValue *value,
1630 GtkSettings *settings = GTK_SETTINGS (object);
1631 GtkSettingsPrivate *priv = settings->priv;
1633 g_value_copy (value, &priv->property_values[property_id - 1].value);
1634 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1638 gtk_settings_get_property (GObject *object,
1643 GtkSettings *settings = GTK_SETTINGS (object);
1644 GtkSettingsPrivate *priv = settings->priv;
1645 GType value_type = G_VALUE_TYPE (value);
1646 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1648 /* handle internal properties */
1649 switch (property_id)
1651 case PROP_COLOR_HASH:
1652 g_value_take_boxed (value,
1653 g_hash_table_new_full (g_str_hash, g_str_equal,
1654 g_free, (GDestroyNotify) gdk_color_free));
1659 /* For enums and strings, we need to get the value as a string,
1660 * not as an int, since we support using names/nicks as the setting
1663 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1664 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1665 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1666 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1668 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1669 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1670 g_value_copy (&priv->property_values[property_id - 1].value, value);
1672 g_param_value_validate (pspec, value);
1676 GValue val = G_VALUE_INIT;
1678 /* Try to get xsetting as a string and parse it. */
1680 g_value_init (&val, G_TYPE_STRING);
1682 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1683 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1685 g_value_copy (&priv->property_values[property_id - 1].value, value);
1689 GValue tmp_value = G_VALUE_INIT;
1690 GValue gstring_value = G_VALUE_INIT;
1691 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1693 g_value_init (&gstring_value, G_TYPE_GSTRING);
1694 g_value_take_boxed (&gstring_value,
1695 g_string_new (g_value_get_string (&val)));
1697 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1699 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1702 g_value_copy (&tmp_value, value);
1703 g_param_value_validate (pspec, value);
1707 g_value_copy (&priv->property_values[property_id - 1].value, value);
1710 g_value_unset (&gstring_value);
1711 g_value_unset (&tmp_value);
1714 g_value_unset (&val);
1719 settings_invalidate_style (GtkSettings *settings)
1721 GtkSettingsPrivate *priv = settings->priv;
1725 g_object_unref (priv->style);
1729 _gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (settings));
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_FONT_NAME:
1753 settings_invalidate_style (settings);
1754 gtk_style_context_reset_widgets (priv->screen);
1756 case PROP_KEY_THEME_NAME:
1757 settings_update_key_theme (settings);
1759 case PROP_THEME_NAME:
1760 case PROP_APPLICATION_PREFER_DARK_THEME:
1761 settings_update_theme (settings);
1764 settings_update_resolution (settings);
1765 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1766 * widgets with gtk_widget_style_set(), and also causes more
1767 * recomputation than necessary.
1769 gtk_style_context_reset_widgets (priv->screen);
1771 case PROP_XFT_ANTIALIAS:
1772 case PROP_XFT_HINTING:
1773 case PROP_XFT_HINTSTYLE:
1775 settings_update_font_options (settings);
1776 gtk_style_context_reset_widgets (priv->screen);
1778 case PROP_FONTCONFIG_TIMESTAMP:
1779 if (settings_update_fontconfig (settings))
1780 gtk_style_context_reset_widgets (priv->screen);
1782 case PROP_ENABLE_ANIMATIONS:
1783 gtk_style_context_reset_widgets (priv->screen);
1785 case PROP_CURSOR_THEME_NAME:
1786 case PROP_CURSOR_THEME_SIZE:
1787 settings_update_cursor_theme (settings);
1793 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1794 const GValue *src_value,
1798 gboolean success = FALSE;
1800 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1805 gboolean free_gstring = TRUE;
1807 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1809 gstring = g_value_get_boxed (src_value);
1810 free_gstring = FALSE;
1812 else if (G_VALUE_HOLDS_LONG (src_value))
1814 gstring = g_string_new (NULL);
1815 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1817 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1819 gstring = g_string_new (NULL);
1820 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1822 else if (G_VALUE_HOLDS_STRING (src_value))
1824 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1826 gstring = g_string_new (NULL);
1827 g_string_append_c (gstring, '\"');
1828 g_string_append (gstring, tstr);
1829 g_string_append_c (gstring, '\"');
1834 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1835 gstring = NULL; /* silence compiler */
1838 success = (parser (pspec, gstring, dest_value) &&
1839 !g_param_value_validate (pspec, dest_value));
1842 g_string_free (gstring, TRUE);
1844 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1846 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1848 GString *gstring = g_value_get_boxed (src_value);
1850 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1851 success = !g_param_value_validate (pspec, dest_value);
1854 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1855 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1861 apply_queued_setting (GtkSettings *settings,
1863 GtkSettingsValuePrivate *qvalue)
1865 GtkSettingsPrivate *priv = settings->priv;
1866 GValue tmp_value = G_VALUE_INIT;
1867 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1869 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1870 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1873 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1875 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1876 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1877 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1883 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1885 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1886 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1888 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1890 G_VALUE_TYPE_NAME (&tmp_value));
1893 g_value_unset (&tmp_value);
1897 settings_install_property_parser (GtkSettingsClass *class,
1899 GtkRcPropertyParser parser)
1901 GSList *node, *next;
1903 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1905 case G_TYPE_BOOLEAN:
1918 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1926 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1927 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1931 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1933 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1938 for (node = object_list; node; node = node->next)
1939 g_object_freeze_notify (node->data);
1941 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1942 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1944 for (node = object_list; node; node = node->next)
1946 GtkSettings *settings = node->data;
1947 GtkSettingsPrivate *priv = settings->priv;
1948 GtkSettingsValuePrivate *qvalue;
1950 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1951 priv->property_values[class_n_properties - 1].value.g_type = 0;
1952 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1953 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1954 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1955 g_object_notify (G_OBJECT (settings), pspec->name);
1957 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1959 apply_queued_setting (settings, pspec, qvalue);
1962 for (node = object_list; node; node = next)
1965 g_object_thaw_notify (node->data);
1968 return class_n_properties;
1972 _gtk_rc_property_parser_from_type (GType type)
1974 if (type == GDK_TYPE_COLOR)
1975 return gtk_rc_property_parse_color;
1976 else if (type == GTK_TYPE_REQUISITION)
1977 return gtk_rc_property_parse_requisition;
1978 else if (type == GTK_TYPE_BORDER)
1979 return gtk_rc_property_parse_border;
1980 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1981 return gtk_rc_property_parse_enum;
1982 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1983 return gtk_rc_property_parse_flags;
1989 gtk_settings_install_property (GParamSpec *pspec)
1991 static GtkSettingsClass *klass = NULL;
1993 GtkRcPropertyParser parser;
1995 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1998 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2000 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
2002 settings_install_property_parser (klass, pspec, parser);
2006 * gtk_settings_install_property_parser:
2008 * @parser: (scope call):
2011 gtk_settings_install_property_parser (GParamSpec *pspec,
2012 GtkRcPropertyParser parser)
2014 static GtkSettingsClass *klass = NULL;
2016 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2017 g_return_if_fail (parser != NULL);
2020 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2022 settings_install_property_parser (klass, pspec, parser);
2026 free_value (gpointer data)
2028 GtkSettingsValuePrivate *qvalue = data;
2030 g_value_unset (&qvalue->public.value);
2031 g_free (qvalue->public.origin);
2032 g_slice_free (GtkSettingsValuePrivate, qvalue);
2036 gtk_settings_set_property_value_internal (GtkSettings *settings,
2037 const gchar *prop_name,
2038 const GtkSettingsValue *new_value,
2039 GtkSettingsSource source)
2041 GtkSettingsPrivate *priv = settings->priv;
2042 GtkSettingsValuePrivate *qvalue;
2047 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
2048 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
2049 !G_VALUE_HOLDS_STRING (&new_value->value) &&
2050 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
2052 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
2056 name = g_strdup (prop_name);
2057 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
2058 name_quark = g_quark_from_string (name);
2061 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
2064 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
2065 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
2069 g_free (qvalue->public.origin);
2070 g_value_unset (&qvalue->public.value);
2072 qvalue->public.origin = g_strdup (new_value->origin);
2073 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
2074 g_value_copy (&new_value->value, &qvalue->public.value);
2075 qvalue->source = source;
2076 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
2078 apply_queued_setting (settings, pspec, qvalue);
2082 gtk_settings_set_property_value (GtkSettings *settings,
2083 const gchar *prop_name,
2084 const GtkSettingsValue *new_value)
2086 g_return_if_fail (GTK_SETTINGS (settings));
2087 g_return_if_fail (prop_name != NULL);
2088 g_return_if_fail (new_value != NULL);
2090 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2091 GTK_SETTINGS_SOURCE_APPLICATION);
2095 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
2096 const gchar *prop_name,
2097 const GtkSettingsValue *new_value)
2099 g_return_if_fail (GTK_SETTINGS (settings));
2100 g_return_if_fail (prop_name != NULL);
2101 g_return_if_fail (new_value != NULL);
2103 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2104 GTK_SETTINGS_SOURCE_THEME);
2108 gtk_settings_set_string_property (GtkSettings *settings,
2110 const gchar *v_string,
2111 const gchar *origin)
2113 GtkSettingsValue svalue = { NULL, { 0, }, };
2115 g_return_if_fail (GTK_SETTINGS (settings));
2116 g_return_if_fail (name != NULL);
2117 g_return_if_fail (v_string != NULL);
2119 svalue.origin = (gchar*) origin;
2120 g_value_init (&svalue.value, G_TYPE_STRING);
2121 g_value_set_static_string (&svalue.value, v_string);
2122 gtk_settings_set_property_value (settings, name, &svalue);
2123 g_value_unset (&svalue.value);
2127 gtk_settings_set_long_property (GtkSettings *settings,
2130 const gchar *origin)
2132 GtkSettingsValue svalue = { NULL, { 0, }, };
2134 g_return_if_fail (GTK_SETTINGS (settings));
2135 g_return_if_fail (name != NULL);
2137 svalue.origin = (gchar*) origin;
2138 g_value_init (&svalue.value, G_TYPE_LONG);
2139 g_value_set_long (&svalue.value, v_long);
2140 gtk_settings_set_property_value (settings, name, &svalue);
2141 g_value_unset (&svalue.value);
2145 gtk_settings_set_double_property (GtkSettings *settings,
2148 const gchar *origin)
2150 GtkSettingsValue svalue = { NULL, { 0, }, };
2152 g_return_if_fail (GTK_SETTINGS (settings));
2153 g_return_if_fail (name != NULL);
2155 svalue.origin = (gchar*) origin;
2156 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2157 g_value_set_double (&svalue.value, v_double);
2158 gtk_settings_set_property_value (settings, name, &svalue);
2159 g_value_unset (&svalue.value);
2163 * gtk_rc_property_parse_color:
2164 * @pspec: a #GParamSpec
2165 * @gstring: the #GString to be parsed
2166 * @property_value: a #GValue which must hold #GdkColor values.
2168 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2169 * or gtk_widget_class_install_style_property_parser() which parses a
2170 * color given either by its name or in the form
2171 * <literal>{ red, green, blue }</literal> where %red, %green and
2172 * %blue are integers between 0 and 65535 or floating-point numbers
2175 * Return value: %TRUE if @gstring could be parsed and @property_value
2176 * has been set to the resulting #GdkColor.
2179 gtk_rc_property_parse_color (const GParamSpec *pspec,
2180 const GString *gstring,
2181 GValue *property_value)
2183 GdkColor color = { 0, 0, 0, 0, };
2187 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2188 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2190 scanner = gtk_rc_scanner_new ();
2191 g_scanner_input_text (scanner, gstring->str, gstring->len);
2192 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2193 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2195 g_value_set_boxed (property_value, &color);
2200 g_scanner_destroy (scanner);
2206 * gtk_rc_property_parse_enum:
2207 * @pspec: a #GParamSpec
2208 * @gstring: the #GString to be parsed
2209 * @property_value: a #GValue which must hold enum values.
2211 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2212 * or gtk_widget_class_install_style_property_parser() which parses a single
2213 * enumeration value.
2215 * The enumeration value can be specified by its name, its nickname or
2216 * its numeric value. For consistency with flags parsing, the value
2217 * may be surrounded by parentheses.
2219 * Return value: %TRUE if @gstring could be parsed and @property_value
2220 * has been set to the resulting #GEnumValue.
2223 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2224 const GString *gstring,
2225 GValue *property_value)
2227 gboolean need_closing_brace = FALSE, success = FALSE;
2229 GEnumValue *enum_value = NULL;
2231 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2232 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2234 scanner = gtk_rc_scanner_new ();
2235 g_scanner_input_text (scanner, gstring->str, gstring->len);
2237 /* we just want to parse _one_ value, but for consistency with flags parsing
2238 * we support optional parenthesis
2240 g_scanner_get_next_token (scanner);
2241 if (scanner->token == '(')
2243 need_closing_brace = TRUE;
2244 g_scanner_get_next_token (scanner);
2246 if (scanner->token == G_TOKEN_IDENTIFIER)
2248 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2250 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2252 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2255 g_value_set_enum (property_value, enum_value->value);
2259 else if (scanner->token == G_TOKEN_INT)
2261 g_value_set_enum (property_value, scanner->value.v_int);
2264 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2266 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2269 g_scanner_destroy (scanner);
2275 parse_flags_value (GScanner *scanner,
2279 g_scanner_get_next_token (scanner);
2280 if (scanner->token == G_TOKEN_IDENTIFIER)
2282 GFlagsValue *flags_value;
2284 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2286 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2289 *number |= flags_value->value;
2290 return G_TOKEN_NONE;
2293 else if (scanner->token == G_TOKEN_INT)
2295 *number |= scanner->value.v_int;
2296 return G_TOKEN_NONE;
2298 return G_TOKEN_IDENTIFIER;
2302 * gtk_rc_property_parse_flags:
2303 * @pspec: a #GParamSpec
2304 * @gstring: the #GString to be parsed
2305 * @property_value: a #GValue which must hold flags values.
2307 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2308 * or gtk_widget_class_install_style_property_parser() which parses flags.
2310 * Flags can be specified by their name, their nickname or
2311 * numerically. Multiple flags can be specified in the form
2312 * <literal>"( flag1 | flag2 | ... )"</literal>.
2314 * Return value: %TRUE if @gstring could be parsed and @property_value
2315 * has been set to the resulting flags value.
2318 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2319 const GString *gstring,
2320 GValue *property_value)
2323 gboolean success = FALSE;
2326 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2327 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2329 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2330 scanner = gtk_rc_scanner_new ();
2331 g_scanner_input_text (scanner, gstring->str, gstring->len);
2333 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2334 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2335 scanner->next_token == G_TOKEN_INT)
2337 guint token, flags_value = 0;
2339 token = parse_flags_value (scanner, class, &flags_value);
2341 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2344 g_value_set_flags (property_value, flags_value);
2348 else if (g_scanner_get_next_token (scanner) == '(')
2350 guint token, flags_value = 0;
2352 /* parse first value */
2353 token = parse_flags_value (scanner, class, &flags_value);
2355 /* parse nth values, preceeded by '|' */
2356 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2357 token = parse_flags_value (scanner, class, &flags_value);
2359 /* done, last token must have closed expression */
2360 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2361 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2363 g_value_set_flags (property_value, flags_value);
2367 g_scanner_destroy (scanner);
2373 get_braced_int (GScanner *scanner,
2380 g_scanner_get_next_token (scanner);
2381 if (scanner->token != '{')
2385 g_scanner_get_next_token (scanner);
2386 if (scanner->token != G_TOKEN_INT)
2389 *value = scanner->value.v_int;
2393 g_scanner_get_next_token (scanner);
2394 if (scanner->token != '}')
2399 g_scanner_get_next_token (scanner);
2400 if (scanner->token != ',')
2408 * gtk_rc_property_parse_requisition:
2409 * @pspec: a #GParamSpec
2410 * @gstring: the #GString to be parsed
2411 * @property_value: a #GValue which must hold boxed values.
2413 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2414 * or gtk_widget_class_install_style_property_parser() which parses a
2415 * requisition in the form
2416 * <literal>"{ width, height }"</literal> for integers %width and %height.
2418 * Return value: %TRUE if @gstring could be parsed and @property_value
2419 * has been set to the resulting #GtkRequisition.
2422 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2423 const GString *gstring,
2424 GValue *property_value)
2426 GtkRequisition requisition;
2428 gboolean success = FALSE;
2430 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2431 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2433 scanner = gtk_rc_scanner_new ();
2434 g_scanner_input_text (scanner, gstring->str, gstring->len);
2436 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2437 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2439 g_value_set_boxed (property_value, &requisition);
2443 g_scanner_destroy (scanner);
2449 * gtk_rc_property_parse_border:
2450 * @pspec: a #GParamSpec
2451 * @gstring: the #GString to be parsed
2452 * @property_value: a #GValue which must hold boxed values.
2454 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2455 * or gtk_widget_class_install_style_property_parser() which parses
2456 * borders in the form
2457 * <literal>"{ left, right, top, bottom }"</literal> for integers
2458 * %left, %right, %top and %bottom.
2460 * Return value: %TRUE if @gstring could be parsed and @property_value
2461 * has been set to the resulting #GtkBorder.
2464 gtk_rc_property_parse_border (const GParamSpec *pspec,
2465 const GString *gstring,
2466 GValue *property_value)
2470 gboolean success = FALSE;
2471 int left, right, top, bottom;
2473 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2474 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2476 scanner = gtk_rc_scanner_new ();
2477 g_scanner_input_text (scanner, gstring->str, gstring->len);
2479 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2480 get_braced_int (scanner, FALSE, FALSE, &right) &&
2481 get_braced_int (scanner, FALSE, FALSE, &top) &&
2482 get_braced_int (scanner, FALSE, TRUE, &bottom))
2485 border.right = right;
2487 border.bottom = bottom;
2488 g_value_set_boxed (property_value, &border);
2492 g_scanner_destroy (scanner);
2498 _gtk_settings_handle_event (GdkEventSetting *event)
2501 GtkSettings *settings;
2504 screen = gdk_window_get_screen (event->window);
2505 settings = gtk_settings_get_for_screen (screen);
2506 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2509 g_object_notify (G_OBJECT (settings), pspec->name);
2513 reset_rc_values_foreach (GQuark key_id,
2517 GtkSettingsValuePrivate *qvalue = data;
2518 GSList **to_reset = user_data;
2520 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2521 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2525 _gtk_settings_reset_rc_values (GtkSettings *settings)
2527 GtkSettingsPrivate *priv = settings->priv;
2528 GSList *to_reset = NULL;
2530 GParamSpec **pspecs, **p;
2533 /* Remove any queued settings */
2534 g_datalist_foreach (&priv->queued_settings,
2535 reset_rc_values_foreach,
2538 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2540 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2541 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2544 g_slist_free (to_reset);
2546 /* Now reset the active settings
2548 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2551 g_object_freeze_notify (G_OBJECT (settings));
2552 for (p = pspecs; *p; p++)
2554 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2556 GParamSpec *pspec = *p;
2558 g_param_value_set_default (pspec, &priv->property_values[i].value);
2559 g_object_notify (G_OBJECT (settings), pspec->name);
2563 g_object_thaw_notify (G_OBJECT (settings));
2568 settings_update_double_click (GtkSettings *settings)
2570 GtkSettingsPrivate *priv = settings->priv;
2572 if (gdk_screen_get_number (priv->screen) == 0)
2574 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2575 gint double_click_time;
2576 gint double_click_distance;
2578 g_object_get (settings,
2579 "gtk-double-click-time", &double_click_time,
2580 "gtk-double-click-distance", &double_click_distance,
2583 gdk_display_set_double_click_time (display, double_click_time);
2584 gdk_display_set_double_click_distance (display, double_click_distance);
2589 settings_update_modules (GtkSettings *settings)
2593 g_object_get (settings,
2594 "gtk-modules", &modules,
2597 _gtk_modules_settings_changed (settings, modules);
2603 settings_update_cursor_theme (GtkSettings *settings)
2605 #ifdef GDK_WINDOWING_X11
2606 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2607 gchar *theme = NULL;
2610 if (GDK_IS_X11_DISPLAY (display))
2612 g_object_get (settings,
2613 "gtk-cursor-theme-name", &theme,
2614 "gtk-cursor-theme-size", &size,
2617 gdk_x11_display_set_cursor_theme (display, theme, size);
2625 settings_update_font_options (GtkSettings *settings)
2627 GtkSettingsPrivate *priv = settings->priv;
2629 gchar *hint_style_str;
2630 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2632 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2634 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2635 cairo_font_options_t *options;
2637 g_object_get (settings,
2638 "gtk-xft-antialias", &antialias,
2639 "gtk-xft-hinting", &hinting,
2640 "gtk-xft-hintstyle", &hint_style_str,
2641 "gtk-xft-rgba", &rgba_str,
2644 options = cairo_font_options_create ();
2646 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2648 if (hinting >= 0 && !hinting)
2650 hint_style = CAIRO_HINT_STYLE_NONE;
2652 else if (hint_style_str)
2654 if (strcmp (hint_style_str, "hintnone") == 0)
2655 hint_style = CAIRO_HINT_STYLE_NONE;
2656 else if (strcmp (hint_style_str, "hintslight") == 0)
2657 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2658 else if (strcmp (hint_style_str, "hintmedium") == 0)
2659 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2660 else if (strcmp (hint_style_str, "hintfull") == 0)
2661 hint_style = CAIRO_HINT_STYLE_FULL;
2664 g_free (hint_style_str);
2666 cairo_font_options_set_hint_style (options, hint_style);
2670 if (strcmp (rgba_str, "rgb") == 0)
2671 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2672 else if (strcmp (rgba_str, "bgr") == 0)
2673 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2674 else if (strcmp (rgba_str, "vrgb") == 0)
2675 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2676 else if (strcmp (rgba_str, "vbgr") == 0)
2677 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2682 cairo_font_options_set_subpixel_order (options, subpixel_order);
2684 if (antialias >= 0 && !antialias)
2685 antialias_mode = CAIRO_ANTIALIAS_NONE;
2686 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2687 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2688 else if (antialias >= 0)
2689 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2691 cairo_font_options_set_antialias (options, antialias_mode);
2693 gdk_screen_set_font_options (priv->screen, options);
2695 cairo_font_options_destroy (options);
2699 settings_update_fontconfig (GtkSettings *settings)
2701 #ifdef GDK_WINDOWING_X11
2702 static guint last_update_timestamp;
2703 static gboolean last_update_needed;
2707 g_object_get (settings,
2708 "gtk-fontconfig-timestamp", ×tamp,
2711 /* if timestamp is the same as last_update_timestamp, we already have
2712 * updated fontconig on this timestamp (another screen requested it perhaps?),
2713 * just return the cached result.*/
2715 if (timestamp != last_update_timestamp)
2717 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2718 gboolean update_needed = FALSE;
2721 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2723 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2724 if (FcInitReinitialize ())
2725 update_needed = TRUE;
2728 last_update_timestamp = timestamp;
2729 last_update_needed = update_needed;
2732 return last_update_needed;
2735 #endif /* GDK_WINDOWING_X11 */
2739 settings_update_resolution (GtkSettings *settings)
2741 GtkSettingsPrivate *priv = settings->priv;
2745 g_object_get (settings,
2746 "gtk-xft-dpi", &dpi_int,
2750 dpi = dpi_int / 1024.;
2754 gdk_screen_set_resolution (priv->screen, dpi);
2758 settings_update_provider (GdkScreen *screen,
2759 GtkCssProvider **old,
2760 GtkCssProvider *new)
2766 gtk_style_context_remove_provider_for_screen (screen,
2767 GTK_STYLE_PROVIDER (*old));
2768 g_object_unref (*old);
2774 gtk_style_context_add_provider_for_screen (screen,
2775 GTK_STYLE_PROVIDER (new),
2776 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2777 *old = g_object_ref (new);
2783 settings_update_theme (GtkSettings *settings)
2785 GtkSettingsPrivate *priv = settings->priv;
2786 gboolean prefer_dark_theme;
2789 g_object_get (settings,
2790 "gtk-theme-name", &theme_name,
2791 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2794 if (!theme_name || !*theme_name)
2796 g_free (theme_name);
2797 theme_name = g_strdup ("Raleigh");
2800 _gtk_css_provider_load_named (priv->theme_provider,
2802 prefer_dark_theme ? "dark" : NULL);
2804 if (theme_name && *theme_name)
2809 /* reload per-theme settings */
2810 theme_dir = _gtk_css_provider_get_theme_dir ();
2811 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2813 if (g_file_test (path, G_FILE_TEST_EXISTS))
2814 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2820 g_free (theme_name);
2824 settings_update_key_theme (GtkSettings *settings)
2826 GtkSettingsPrivate *priv = settings->priv;
2827 GtkCssProvider *provider = NULL;
2828 gchar *key_theme_name;
2830 g_object_get (settings,
2831 "gtk-key-theme-name", &key_theme_name,
2834 if (key_theme_name && *key_theme_name)
2835 provider = gtk_css_provider_get_named (key_theme_name, "keys");
2837 settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2838 g_free (key_theme_name);
2843 _gtk_settings_get_screen (GtkSettings *settings)
2845 return settings->priv->screen;
2850 gtk_settings_load_from_key_file (GtkSettings *settings,
2852 GtkSettingsSource source)
2863 keyfile = g_key_file_new ();
2865 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
2867 g_warning ("Failed to parse %s: %s", path, error->message);
2869 g_error_free (error);
2874 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
2877 g_warning ("Failed to parse %s: %s", path, error->message);
2878 g_error_free (error);
2882 for (i = 0; i < n_keys; i++)
2887 GtkSettingsValue svalue = { NULL, { 0, }, };
2890 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
2893 g_warning ("Unknown key %s in %s", key, path);
2897 if (pspec->owner_type != G_OBJECT_TYPE (settings))
2900 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
2903 case G_TYPE_BOOLEAN:
2907 g_value_init (&svalue.value, G_TYPE_LONG);
2908 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
2910 g_value_set_long (&svalue.value, b_val);
2918 g_value_init (&svalue.value, G_TYPE_LONG);
2919 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
2921 g_value_set_long (&svalue.value, i_val);
2929 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2930 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
2932 g_value_set_double (&svalue.value, d_val);
2940 g_value_init (&svalue.value, G_TYPE_GSTRING);
2941 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
2943 g_value_take_boxed (&svalue.value, g_string_new (s_val));
2950 g_warning ("Error setting %s in %s: %s", key, path, error->message);
2951 g_error_free (error);
2956 if (g_getenv ("GTK_DEBUG"))
2957 svalue.origin = (gchar *)path;
2958 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
2959 g_value_unset (&svalue.value);
2965 g_key_file_free (keyfile);