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 #include "gtkwin32themeprivate.h"
53 #undef GDK_DEPRECATED_FOR
54 #define GDK_DEPRECATED
55 #define GDK_DEPRECATED_FOR(f)
57 #include "deprecated/gtkrc.h"
62 * @Short_description: Sharing settings between applications
65 * GtkSettings provide a mechanism to share global settings between
68 * On the X window system, this sharing is realized by an
69 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
70 * manager that is usually part of the desktop environment, along with
71 * utilities that let the user change these settings. In the absence of
72 * an Xsettings manager, GTK+ reads default values for settings from
73 * <filename>settings.ini</filename> files in
74 * <filename>/etc/gtk-3.0</filename>, <filename>$XDG_CONFIG_DIRS/gtk-3.0</filename>
75 * and <filename>$XDG_CONFIG_HOME/gtk-3.0</filename>.
76 * These files must be valid key files (see #GKeyFile), and have
77 * a section called Settings. Themes can also provide default values
78 * for settings by installing a <filename>settings.ini</filename> file
79 * next to their <filename>gtk.css</filename> file.
81 * Applications can override system-wide settings with
82 * gtk_settings_set_string_property(), gtk_settings_set_long_property(),
83 * etc. This should be restricted to special cases though; GtkSettings are
84 * not meant as an application configuration facility. When doing so, you
85 * need to be aware that settings that are specific to individual widgets
86 * may not be available before the widget type has been realized at least
87 * once. The following example demonstrates a way to do this:
88 * <informalexample><programlisting>
89 * gtk_init (&argc, &argv);
91 * /* make sure the type is realized */
92 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
94 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
95 * </programlisting></informalexample>
97 * There is one GtkSettings instance per screen. It can be obtained with
98 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
99 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
100 * GtkSettings instance for the default screen.
104 #define DEFAULT_TIMEOUT_INITIAL 200
105 #define DEFAULT_TIMEOUT_REPEAT 20
106 #define DEFAULT_TIMEOUT_EXPAND 500
108 typedef struct _GtkSettingsPropertyValue GtkSettingsPropertyValue;
109 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
111 struct _GtkSettingsPrivate
113 GData *queued_settings; /* of type GtkSettingsValue* */
114 GtkSettingsPropertyValue *property_values;
116 GtkCssProvider *theme_provider;
117 GtkCssProvider *key_theme_provider;
118 GtkStyleProperties *style;
123 GTK_SETTINGS_SOURCE_DEFAULT,
124 GTK_SETTINGS_SOURCE_THEME,
125 GTK_SETTINGS_SOURCE_XSETTING,
126 GTK_SETTINGS_SOURCE_APPLICATION
129 struct _GtkSettingsValuePrivate
131 GtkSettingsValue public;
132 GtkSettingsSource source;
135 struct _GtkSettingsPropertyValue
138 GtkSettingsSource source;
143 PROP_DOUBLE_CLICK_TIME,
144 PROP_DOUBLE_CLICK_DISTANCE,
146 PROP_CURSOR_BLINK_TIME,
147 PROP_CURSOR_BLINK_TIMEOUT,
150 PROP_ICON_THEME_NAME,
151 PROP_FALLBACK_ICON_THEME,
154 PROP_DND_DRAG_THRESHOLD,
163 PROP_CURSOR_THEME_NAME,
164 PROP_CURSOR_THEME_SIZE,
165 PROP_ALTERNATIVE_BUTTON_ORDER,
166 PROP_ALTERNATIVE_SORT_ARROWS,
167 PROP_SHOW_INPUT_METHOD_MENU,
168 PROP_SHOW_UNICODE_MENU,
169 PROP_TIMEOUT_INITIAL,
173 PROP_ENABLE_ANIMATIONS,
174 PROP_TOUCHSCREEN_MODE,
175 PROP_TOOLTIP_TIMEOUT,
176 PROP_TOOLTIP_BROWSE_TIMEOUT,
177 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
178 PROP_KEYNAV_CURSOR_ONLY,
179 PROP_KEYNAV_WRAP_AROUND,
182 PROP_FILE_CHOOSER_BACKEND,
184 PROP_PRINT_PREVIEW_COMMAND,
185 PROP_ENABLE_MNEMONICS,
187 PROP_RECENT_FILES_LIMIT,
189 PROP_RECENT_FILES_MAX_AGE,
190 PROP_FONTCONFIG_TIMESTAMP,
191 PROP_SOUND_THEME_NAME,
192 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
193 PROP_ENABLE_EVENT_SOUNDS,
194 PROP_ENABLE_TOOLTIPS,
196 PROP_TOOLBAR_ICON_SIZE,
198 PROP_PRIMARY_BUTTON_WARPS_SLIDER,
200 PROP_APPLICATION_PREFER_DARK_THEME,
202 PROP_ENTRY_SELECT_ON_FOCUS,
203 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
205 PROP_MENU_BAR_POPUP_DELAY,
206 PROP_SCROLLED_WINDOW_PLACEMENT,
207 PROP_CAN_CHANGE_ACCELS,
208 PROP_MENU_POPUP_DELAY,
209 PROP_MENU_POPDOWN_DELAY,
210 PROP_LABEL_SELECT_ON_FOCUS,
212 PROP_IM_PREEDIT_STYLE,
213 PROP_IM_STATUS_STYLE,
214 PROP_SHELL_SHOWS_APP_MENU,
215 PROP_SHELL_SHOWS_MENUBAR,
216 PROP_ENABLE_PRIMARY_PASTE
219 /* --- prototypes --- */
220 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
221 static void gtk_settings_provider_private_init (GtkStyleProviderPrivateInterface *iface);
223 static void gtk_settings_finalize (GObject *object);
224 static void gtk_settings_get_property (GObject *object,
228 static void gtk_settings_set_property (GObject *object,
232 static void gtk_settings_notify (GObject *object,
234 static guint settings_install_property_parser (GtkSettingsClass *class,
236 GtkRcPropertyParser parser);
237 static void settings_update_double_click (GtkSettings *settings);
238 static void settings_update_modules (GtkSettings *settings);
240 static void settings_update_cursor_theme (GtkSettings *settings);
241 static void settings_update_resolution (GtkSettings *settings);
242 static void settings_update_font_options (GtkSettings *settings);
243 static gboolean settings_update_fontconfig (GtkSettings *settings);
244 static void settings_update_color_scheme (GtkSettings *settings);
245 static void settings_update_theme (GtkSettings *settings);
246 static void settings_update_key_theme (GtkSettings *settings);
248 static void merge_color_scheme (GtkSettings *settings,
250 GtkSettingsSource source);
251 static gchar *get_color_scheme (GtkSettings *settings);
252 static GHashTable *get_color_hash (GtkSettings *settings);
253 static void gtk_settings_load_from_key_file (GtkSettings *settings,
255 GtkSettingsSource source);
257 /* the default palette for GtkColorSelelection */
258 static const gchar default_color_palette[] =
259 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
260 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
262 /* --- variables --- */
263 static GQuark quark_property_parser = 0;
264 static GSList *object_list = NULL;
265 static guint class_n_properties = 0;
268 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
269 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
270 gtk_settings_provider_iface_init)
271 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER_PRIVATE,
272 gtk_settings_provider_private_init));
274 /* --- functions --- */
276 gtk_settings_init (GtkSettings *settings)
278 GtkSettingsPrivate *priv;
279 GParamSpec **pspecs, **p;
282 const gchar * const *config_dirs;
283 const gchar *config_dir;
285 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
289 settings->priv = priv;
290 g_datalist_init (&priv->queued_settings);
291 object_list = g_slist_prepend (object_list, settings);
293 /* build up property array for all yet existing properties and queue
294 * notification for them (at least notification for internal properties
295 * will instantly be caught)
297 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
298 for (p = pspecs; *p; p++)
299 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
301 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
303 g_object_freeze_notify (G_OBJECT (settings));
305 for (p = pspecs; *p; p++)
307 GParamSpec *pspec = *p;
308 GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
310 if (pspec->owner_type != G_OBJECT_TYPE (settings))
312 g_value_init (&priv->property_values[i].value, value_type);
313 g_param_value_set_default (pspec, &priv->property_values[i].value);
315 g_object_notify (G_OBJECT (settings), pspec->name);
316 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
321 path = g_build_filename (_gtk_get_sysconfdir (), "gtk-3.0", "settings.ini", NULL);
322 if (g_file_test (path, G_FILE_TEST_EXISTS))
323 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
326 config_dirs = g_get_system_config_dirs ();
327 for (config_dir = *config_dirs; *config_dirs != NULL; config_dirs++)
329 path = g_build_filename (config_dir, "gtk-3.0", "settings.ini", NULL);
330 if (g_file_test (path, G_FILE_TEST_EXISTS))
331 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
335 path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "settings.ini", NULL);
336 if (g_file_test (path, G_FILE_TEST_EXISTS))
337 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
340 g_object_thaw_notify (G_OBJECT (settings));
344 gtk_settings_class_init (GtkSettingsClass *class)
346 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
349 gobject_class->finalize = gtk_settings_finalize;
350 gobject_class->get_property = gtk_settings_get_property;
351 gobject_class->set_property = gtk_settings_set_property;
352 gobject_class->notify = gtk_settings_notify;
354 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
355 result = settings_install_property_parser (class,
356 g_param_spec_int ("gtk-double-click-time",
357 P_("Double Click Time"),
358 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
360 GTK_PARAM_READWRITE),
362 g_assert (result == PROP_DOUBLE_CLICK_TIME);
363 result = settings_install_property_parser (class,
364 g_param_spec_int ("gtk-double-click-distance",
365 P_("Double Click Distance"),
366 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
368 GTK_PARAM_READWRITE),
370 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
373 * GtkSettings:gtk-cursor-blink:
375 * Whether the cursor should blink.
377 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
378 * which allows more flexible control over cursor blinking.
380 result = settings_install_property_parser (class,
381 g_param_spec_boolean ("gtk-cursor-blink",
383 P_("Whether the cursor should blink"),
385 GTK_PARAM_READWRITE),
387 g_assert (result == PROP_CURSOR_BLINK);
388 result = settings_install_property_parser (class,
389 g_param_spec_int ("gtk-cursor-blink-time",
390 P_("Cursor Blink Time"),
391 P_("Length of the cursor blink cycle, in milliseconds"),
393 GTK_PARAM_READWRITE),
395 g_assert (result == PROP_CURSOR_BLINK_TIME);
398 * GtkSettings:gtk-cursor-blink-timeout:
400 * Time after which the cursor stops blinking, in seconds.
401 * The timer is reset after each user interaction.
403 * Setting this to zero has the same effect as setting
404 * #GtkSettings:gtk-cursor-blink to %FALSE.
408 result = settings_install_property_parser (class,
409 g_param_spec_int ("gtk-cursor-blink-timeout",
410 P_("Cursor Blink Timeout"),
411 P_("Time after which the cursor stops blinking, in seconds"),
412 1, G_MAXINT, G_MAXINT,
413 GTK_PARAM_READWRITE),
415 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
416 result = settings_install_property_parser (class,
417 g_param_spec_boolean ("gtk-split-cursor",
419 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
421 GTK_PARAM_READWRITE),
423 g_assert (result == PROP_SPLIT_CURSOR);
424 result = settings_install_property_parser (class,
425 g_param_spec_string ("gtk-theme-name",
427 P_("Name of theme to load"),
429 _gtk_win32_theme_get_default (),
433 GTK_PARAM_READWRITE),
435 g_assert (result == PROP_THEME_NAME);
437 result = settings_install_property_parser (class,
438 g_param_spec_string ("gtk-icon-theme-name",
439 P_("Icon Theme Name"),
440 P_("Name of icon theme to use"),
442 GTK_PARAM_READWRITE),
444 g_assert (result == PROP_ICON_THEME_NAME);
446 result = settings_install_property_parser (class,
447 g_param_spec_string ("gtk-fallback-icon-theme",
448 P_("Fallback Icon Theme Name"),
449 P_("Name of a icon theme to fall back to"),
451 GTK_PARAM_READWRITE),
453 g_assert (result == PROP_FALLBACK_ICON_THEME);
455 result = settings_install_property_parser (class,
456 g_param_spec_string ("gtk-key-theme-name",
457 P_("Key Theme Name"),
458 P_("Name of key theme to load"),
460 GTK_PARAM_READWRITE),
462 g_assert (result == PROP_KEY_THEME_NAME);
464 result = settings_install_property_parser (class,
465 g_param_spec_string ("gtk-menu-bar-accel",
466 P_("Menu bar accelerator"),
467 P_("Keybinding to activate the menu bar"),
469 GTK_PARAM_READWRITE),
471 g_assert (result == PROP_MENU_BAR_ACCEL);
473 result = settings_install_property_parser (class,
474 g_param_spec_int ("gtk-dnd-drag-threshold",
475 P_("Drag threshold"),
476 P_("Number of pixels the cursor can move before dragging"),
478 GTK_PARAM_READWRITE),
480 g_assert (result == PROP_DND_DRAG_THRESHOLD);
482 result = settings_install_property_parser (class,
483 g_param_spec_string ("gtk-font-name",
485 P_("Name of default font to use"),
487 GTK_PARAM_READWRITE),
489 g_assert (result == PROP_FONT_NAME);
492 * GtkSettings:gtk-icon-sizes:
494 * A list of icon sizes. The list is separated by colons, and
497 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
499 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
500 * GTK+ itself use the following named icon sizes: gtk-menu,
501 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
502 * gtk-dialog. Applications can register their own named icon
503 * sizes with gtk_icon_size_register().
505 result = settings_install_property_parser (class,
506 g_param_spec_string ("gtk-icon-sizes",
508 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
510 GTK_PARAM_READWRITE),
512 g_assert (result == PROP_ICON_SIZES);
514 result = settings_install_property_parser (class,
515 g_param_spec_string ("gtk-modules",
517 P_("List of currently active GTK modules"),
519 GTK_PARAM_READWRITE),
521 g_assert (result == PROP_MODULES);
523 result = settings_install_property_parser (class,
524 g_param_spec_int ("gtk-xft-antialias",
526 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
528 GTK_PARAM_READWRITE),
531 g_assert (result == PROP_XFT_ANTIALIAS);
533 result = settings_install_property_parser (class,
534 g_param_spec_int ("gtk-xft-hinting",
536 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
538 GTK_PARAM_READWRITE),
541 g_assert (result == PROP_XFT_HINTING);
543 result = settings_install_property_parser (class,
544 g_param_spec_string ("gtk-xft-hintstyle",
545 P_("Xft Hint Style"),
546 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
548 GTK_PARAM_READWRITE),
551 g_assert (result == PROP_XFT_HINTSTYLE);
553 result = settings_install_property_parser (class,
554 g_param_spec_string ("gtk-xft-rgba",
556 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
558 GTK_PARAM_READWRITE),
561 g_assert (result == PROP_XFT_RGBA);
563 result = settings_install_property_parser (class,
564 g_param_spec_int ("gtk-xft-dpi",
566 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
568 GTK_PARAM_READWRITE),
571 g_assert (result == PROP_XFT_DPI);
573 result = settings_install_property_parser (class,
574 g_param_spec_string ("gtk-cursor-theme-name",
575 P_("Cursor theme name"),
576 P_("Name of the cursor theme to use, or NULL to use the default theme"),
578 GTK_PARAM_READWRITE),
580 g_assert (result == PROP_CURSOR_THEME_NAME);
582 result = settings_install_property_parser (class,
583 g_param_spec_int ("gtk-cursor-theme-size",
584 P_("Cursor theme size"),
585 P_("Size to use for cursors, or 0 to use the default size"),
587 GTK_PARAM_READWRITE),
590 g_assert (result == PROP_CURSOR_THEME_SIZE);
592 result = settings_install_property_parser (class,
593 g_param_spec_boolean ("gtk-alternative-button-order",
594 P_("Alternative button order"),
595 P_("Whether buttons in dialogs should use the alternative button order"),
597 GTK_PARAM_READWRITE),
599 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
602 * GtkSettings:gtk-alternative-sort-arrows:
604 * Controls the direction of the sort indicators in sorted list and tree
605 * views. By default an arrow pointing down means the column is sorted
606 * in ascending order. When set to %TRUE, this order will be inverted.
610 result = settings_install_property_parser (class,
611 g_param_spec_boolean ("gtk-alternative-sort-arrows",
612 P_("Alternative sort indicator direction"),
613 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
615 GTK_PARAM_READWRITE),
617 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
619 result = settings_install_property_parser (class,
620 g_param_spec_boolean ("gtk-show-input-method-menu",
621 P_("Show the 'Input Methods' menu"),
622 P_("Whether the context menus of entries and text views should offer to change the input method"),
624 GTK_PARAM_READWRITE),
626 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
628 result = settings_install_property_parser (class,
629 g_param_spec_boolean ("gtk-show-unicode-menu",
630 P_("Show the 'Insert Unicode Control Character' menu"),
631 P_("Whether the context menus of entries and text views should offer to insert control characters"),
633 GTK_PARAM_READWRITE),
635 g_assert (result == PROP_SHOW_UNICODE_MENU);
637 result = settings_install_property_parser (class,
638 g_param_spec_int ("gtk-timeout-initial",
640 P_("Starting value for timeouts, when button is pressed"),
641 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
642 GTK_PARAM_READWRITE),
645 g_assert (result == PROP_TIMEOUT_INITIAL);
647 result = settings_install_property_parser (class,
648 g_param_spec_int ("gtk-timeout-repeat",
649 P_("Repeat timeout"),
650 P_("Repeat value for timeouts, when button is pressed"),
651 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
652 GTK_PARAM_READWRITE),
655 g_assert (result == PROP_TIMEOUT_REPEAT);
657 result = settings_install_property_parser (class,
658 g_param_spec_int ("gtk-timeout-expand",
659 P_("Expand timeout"),
660 P_("Expand value for timeouts, when a widget is expanding a new region"),
661 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
662 GTK_PARAM_READWRITE),
665 g_assert (result == PROP_TIMEOUT_EXPAND);
668 * GtkSettings:gtk-color-scheme:
670 * A palette of named colors for use in themes. The format of the string is
676 * Color names must be acceptable as identifiers in the
677 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
678 * color specifications must be in the format accepted by
681 * Note that due to the way the color tables from different sources are
682 * merged, color specifications will be converted to hexadecimal form
683 * when getting this property.
685 * Starting with GTK+ 2.12, the entries can alternatively be separated
686 * by ';' instead of newlines:
688 * name1: color1; name2: color2; ...
693 result = settings_install_property_parser (class,
694 g_param_spec_string ("gtk-color-scheme",
696 P_("A palette of named colors for use in themes"),
698 GTK_PARAM_READWRITE),
701 g_assert (result == PROP_COLOR_SCHEME);
703 result = settings_install_property_parser (class,
704 g_param_spec_boolean ("gtk-enable-animations",
705 P_("Enable Animations"),
706 P_("Whether to enable toolkit-wide animations."),
708 GTK_PARAM_READWRITE),
711 g_assert (result == PROP_ENABLE_ANIMATIONS);
714 * GtkSettings:gtk-touchscreen-mode:
716 * When %TRUE, there are no motion notify events delivered on this screen,
717 * and widgets can't use the pointer hovering them for any essential
722 * Deprecated: 3.4. Generally the behavior touchscreen input should be
723 * performed dynamically based on gdk_event_get_source_device().
725 result = settings_install_property_parser (class,
726 g_param_spec_boolean ("gtk-touchscreen-mode",
727 P_("Enable Touchscreen Mode"),
728 P_("When TRUE, there are no motion notify events delivered on this screen"),
730 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED),
733 g_assert (result == PROP_TOUCHSCREEN_MODE);
736 * GtkSettings:gtk-tooltip-timeout:
738 * Time, in milliseconds, after which a tooltip could appear if the
739 * cursor is hovering on top of a widget.
743 result = settings_install_property_parser (class,
744 g_param_spec_int ("gtk-tooltip-timeout",
745 P_("Tooltip timeout"),
746 P_("Timeout before tooltip is shown"),
749 GTK_PARAM_READWRITE),
752 g_assert (result == PROP_TOOLTIP_TIMEOUT);
755 * GtkSettings:gtk-tooltip-browse-timeout:
757 * Controls the time after which tooltips will appear when
758 * browse mode is enabled, in milliseconds.
760 * Browse mode is enabled when the mouse pointer moves off an object
761 * where a tooltip was currently being displayed. If the mouse pointer
762 * hits another object before the browse mode timeout expires (see
763 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
764 * amount of milliseconds specified by this setting to popup the tooltip
765 * for the new object.
769 result = settings_install_property_parser (class,
770 g_param_spec_int ("gtk-tooltip-browse-timeout",
771 P_("Tooltip browse timeout"),
772 P_("Timeout before tooltip is shown when browse mode is enabled"),
775 GTK_PARAM_READWRITE),
778 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
781 * GtkSettings:gtk-tooltip-browse-mode-timeout:
783 * Amount of time, in milliseconds, after which the browse mode
786 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
791 result = settings_install_property_parser (class,
792 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
793 P_("Tooltip browse mode timeout"),
794 P_("Timeout after which browse mode is disabled"),
797 GTK_PARAM_READWRITE),
800 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
803 * GtkSettings:gtk-keynav-cursor-only:
805 * When %TRUE, keyboard navigation should be able to reach all widgets
806 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
807 * to be present on the used input device.
811 result = settings_install_property_parser (class,
812 g_param_spec_boolean ("gtk-keynav-cursor-only",
813 P_("Keynav Cursor Only"),
814 P_("When TRUE, there are only cursor keys available to navigate widgets"),
816 GTK_PARAM_READWRITE),
819 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
822 * GtkSettings:gtk-keynav-wrap-around:
824 * When %TRUE, some widgets will wrap around when doing keyboard
825 * navigation, such as menus, menubars and notebooks.
829 result = settings_install_property_parser (class,
830 g_param_spec_boolean ("gtk-keynav-wrap-around",
831 P_("Keynav Wrap Around"),
832 P_("Whether to wrap around when keyboard-navigating widgets"),
834 GTK_PARAM_READWRITE),
837 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
840 * GtkSettings:gtk-error-bell:
842 * When %TRUE, keyboard navigation and other input-related errors
843 * will cause a beep. Since the error bell is implemented using
844 * gdk_window_beep(), the windowing system may offer ways to
845 * configure the error bell in many ways, such as flashing the
846 * window or similar visual effects.
850 result = settings_install_property_parser (class,
851 g_param_spec_boolean ("gtk-error-bell",
853 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
855 GTK_PARAM_READWRITE),
858 g_assert (result == PROP_ERROR_BELL);
861 * GtkSettings:color-hash:
863 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
864 * setting, mapping color names to #GdkColor<!-- -->s.
868 result = settings_install_property_parser (class,
869 g_param_spec_boxed ("color-hash",
871 P_("A hash table representation of the color scheme."),
875 g_assert (result == PROP_COLOR_HASH);
877 result = settings_install_property_parser (class,
878 g_param_spec_string ("gtk-file-chooser-backend",
879 P_("Default file chooser backend"),
880 P_("Name of the GtkFileChooser backend to use by default"),
882 GTK_PARAM_READWRITE),
884 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
887 * GtkSettings:gtk-print-backends:
889 * A comma-separated list of print backends to use in the print
890 * dialog. Available print backends depend on the GTK+ installation,
891 * and may include "file", "cups", "lpr" or "papi".
895 result = settings_install_property_parser (class,
896 g_param_spec_string ("gtk-print-backends",
897 P_("Default print backend"),
898 P_("List of the GtkPrintBackend backends to use by default"),
900 GTK_PARAM_READWRITE),
902 g_assert (result == PROP_PRINT_BACKENDS);
905 * GtkSettings:gtk-print-preview-command:
907 * A command to run for displaying the print preview. The command
908 * should contain a %f placeholder, which will get replaced by
909 * the path to the pdf file. The command may also contain a %s
910 * placeholder, which will get replaced by the path to a file
911 * containing the print settings in the format produced by
912 * gtk_print_settings_to_file().
914 * The preview application is responsible for removing the pdf file
915 * and the print settings file when it is done.
919 result = settings_install_property_parser (class,
920 g_param_spec_string ("gtk-print-preview-command",
921 P_("Default command to run when displaying a print preview"),
922 P_("Command to run when displaying a print preview"),
923 GTK_PRINT_PREVIEW_COMMAND,
924 GTK_PARAM_READWRITE),
926 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
929 * GtkSettings:gtk-enable-mnemonics:
931 * Whether labels and menu items should have visible mnemonics which
936 result = settings_install_property_parser (class,
937 g_param_spec_boolean ("gtk-enable-mnemonics",
938 P_("Enable Mnemonics"),
939 P_("Whether labels should have mnemonics"),
941 GTK_PARAM_READWRITE),
943 g_assert (result == PROP_ENABLE_MNEMONICS);
946 * GtkSettings:gtk-enable-accels:
948 * Whether menu items should have visible accelerators which can be
953 result = settings_install_property_parser (class,
954 g_param_spec_boolean ("gtk-enable-accels",
955 P_("Enable Accelerators"),
956 P_("Whether menu items should have accelerators"),
958 GTK_PARAM_READWRITE),
960 g_assert (result == PROP_ENABLE_ACCELS);
963 * GtkSettings:gtk-recent-files-limit:
965 * The number of recently used files that should be displayed by default by
966 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
967 * -1 means every recently used file stored.
971 result = settings_install_property_parser (class,
972 g_param_spec_int ("gtk-recent-files-limit",
973 P_("Recent Files Limit"),
974 P_("Number of recently used files"),
977 GTK_PARAM_READWRITE),
979 g_assert (result == PROP_RECENT_FILES_LIMIT);
982 * GtkSettings:gtk-im-module:
984 * Which IM (input method) module should be used by default. This is the
985 * input method that will be used if the user has not explicitly chosen
986 * another input method from the IM context menu.
987 * This also can be a colon-separated list of input methods, which GTK+
988 * will try in turn until it finds one available on the system.
990 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
992 result = settings_install_property_parser (class,
993 g_param_spec_string ("gtk-im-module",
994 P_("Default IM module"),
995 P_("Which IM module should be used by default"),
997 GTK_PARAM_READWRITE),
999 g_assert (result == PROP_IM_MODULE);
1002 * GtkSettings:gtk-recent-files-max-age:
1004 * The maximum age, in days, of the items inside the recently used
1005 * resources list. Items older than this setting will be excised
1006 * from the list. If set to 0, the list will always be empty; if
1007 * set to -1, no item will be removed.
1011 result = settings_install_property_parser (class,
1012 g_param_spec_int ("gtk-recent-files-max-age",
1013 P_("Recent Files Max Age"),
1014 P_("Maximum age of recently used files, in days"),
1017 GTK_PARAM_READWRITE),
1019 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
1021 result = settings_install_property_parser (class,
1022 g_param_spec_uint ("gtk-fontconfig-timestamp",
1023 P_("Fontconfig configuration timestamp"),
1024 P_("Timestamp of current fontconfig configuration"),
1026 GTK_PARAM_READWRITE),
1029 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
1032 * GtkSettings:gtk-sound-theme-name:
1034 * The XDG sound theme to use for event sounds.
1036 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1037 * for more information on event sounds and sound themes.
1039 * GTK+ itself does not support event sounds, you have to use a loadable
1040 * module like the one that comes with libcanberra.
1044 result = settings_install_property_parser (class,
1045 g_param_spec_string ("gtk-sound-theme-name",
1046 P_("Sound Theme Name"),
1047 P_("XDG sound theme name"),
1049 GTK_PARAM_READWRITE),
1051 g_assert (result == PROP_SOUND_THEME_NAME);
1054 * GtkSettings:gtk-enable-input-feedback-sounds:
1056 * Whether to play event sounds as feedback to user input.
1058 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1059 * for more information on event sounds and sound themes.
1061 * GTK+ itself does not support event sounds, you have to use a loadable
1062 * module like the one that comes with libcanberra.
1066 result = settings_install_property_parser (class,
1067 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1068 /* Translators: this means sounds that are played as feedback to user input */
1069 P_("Audible Input Feedback"),
1070 P_("Whether to play event sounds as feedback to user input"),
1072 GTK_PARAM_READWRITE),
1074 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1077 * GtkSettings:gtk-enable-event-sounds:
1079 * Whether to play any event sounds at all.
1081 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1082 * for more information on event sounds and sound themes.
1084 * GTK+ itself does not support event sounds, you have to use a loadable
1085 * module like the one that comes with libcanberra.
1089 result = settings_install_property_parser (class,
1090 g_param_spec_boolean ("gtk-enable-event-sounds",
1091 P_("Enable Event Sounds"),
1092 P_("Whether to play any event sounds at all"),
1094 GTK_PARAM_READWRITE),
1096 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1099 * GtkSettings:gtk-enable-tooltips:
1101 * Whether tooltips should be shown on widgets.
1105 result = settings_install_property_parser (class,
1106 g_param_spec_boolean ("gtk-enable-tooltips",
1107 P_("Enable Tooltips"),
1108 P_("Whether tooltips should be shown on widgets"),
1110 GTK_PARAM_READWRITE),
1112 g_assert (result == PROP_ENABLE_TOOLTIPS);
1115 * GtkSettings:gtk-toolbar-style:
1117 * The size of icons in default toolbars.
1119 result = settings_install_property_parser (class,
1120 g_param_spec_enum ("gtk-toolbar-style",
1121 P_("Toolbar style"),
1122 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1123 GTK_TYPE_TOOLBAR_STYLE,
1125 GTK_PARAM_READWRITE),
1126 gtk_rc_property_parse_enum);
1127 g_assert (result == PROP_TOOLBAR_STYLE);
1130 * GtkSettings:gtk-toolbar-icon-size:
1132 * The size of icons in default toolbars.
1134 result = settings_install_property_parser (class,
1135 g_param_spec_enum ("gtk-toolbar-icon-size",
1136 P_("Toolbar Icon Size"),
1137 P_("The size of icons in default toolbars."),
1139 GTK_ICON_SIZE_LARGE_TOOLBAR,
1140 GTK_PARAM_READWRITE),
1141 gtk_rc_property_parse_enum);
1142 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1145 * GtkSettings:gtk-auto-mnemonics:
1147 * Whether mnemonics should be automatically shown and hidden when the user
1148 * presses the mnemonic activator.
1152 result = settings_install_property_parser (class,
1153 g_param_spec_boolean ("gtk-auto-mnemonics",
1154 P_("Auto Mnemonics"),
1155 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1157 GTK_PARAM_READWRITE),
1159 g_assert (result == PROP_AUTO_MNEMONICS);
1162 * GtkSettings:gtk-primary-button-warps-slider:
1164 * Whether a click in a #GtkRange trough should scroll to the click position or
1165 * scroll by a single page in the respective direction.
1169 result = settings_install_property_parser (class,
1170 g_param_spec_boolean ("gtk-primary-button-warps-slider",
1171 P_("Primary button warps slider"),
1172 P_("Whether a primary click on the trough should warp the slider into position"),
1174 GTK_PARAM_READWRITE),
1176 g_assert (result == PROP_PRIMARY_BUTTON_WARPS_SLIDER);
1179 * GtkSettings:gtk-visible-focus:
1181 * Whether 'focus rectangles' should be always visible, never visible,
1182 * or hidden until the user starts to use the keyboard.
1186 result = settings_install_property_parser (class,
1187 g_param_spec_enum ("gtk-visible-focus",
1188 P_("Visible Focus"),
1189 P_("Whether 'focus rectangles' should be hidden until the user starts to use the keyboard."),
1190 GTK_TYPE_POLICY_TYPE,
1192 GTK_PARAM_READWRITE),
1193 gtk_rc_property_parse_enum);
1194 g_assert (result == PROP_VISIBLE_FOCUS);
1197 * GtkSettings:gtk-application-prefer-dark-theme:
1199 * Whether the application prefers to use a dark theme. If a GTK+ theme
1200 * includes a dark variant, it will be used instead of the configured
1203 * Some applications benefit from minimizing the amount of light pollution that
1204 * interferes with the content. Good candidates for dark themes are photo and
1205 * video editors that make the actual content get all the attention and minimize
1206 * the distraction of the chrome.
1208 * Dark themes should not be used for documents, where large spaces are white/light
1209 * and the dark chrome creates too much contrast (web browser, text editor...).
1213 result = settings_install_property_parser (class,
1214 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1215 P_("Application prefers a dark theme"),
1216 P_("Whether the application prefers to have a dark theme."),
1218 GTK_PARAM_READWRITE),
1220 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1223 * GtkSettings::gtk-button-images:
1225 * Whether images should be shown on buttons
1229 result = settings_install_property_parser (class,
1230 g_param_spec_boolean ("gtk-button-images",
1231 P_("Show button images"),
1232 P_("Whether images should be shown on buttons"),
1234 GTK_PARAM_READWRITE),
1236 g_assert (result == PROP_BUTTON_IMAGES);
1238 result = settings_install_property_parser (class,
1239 g_param_spec_boolean ("gtk-entry-select-on-focus",
1240 P_("Select on focus"),
1241 P_("Whether to select the contents of an entry when it is focused"),
1243 GTK_PARAM_READWRITE),
1245 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1248 * GtkSettings:gtk-entry-password-hint-timeout:
1250 * How long to show the last input character in hidden
1251 * entries. This value is in milliseconds. 0 disables showing the
1252 * last char. 600 is a good value for enabling it.
1256 result = settings_install_property_parser (class,
1257 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1258 P_("Password Hint Timeout"),
1259 P_("How long to show the last input character in hidden entries"),
1262 GTK_PARAM_READWRITE),
1264 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1266 result = settings_install_property_parser (class,
1267 g_param_spec_boolean ("gtk-menu-images",
1268 P_("Show menu images"),
1269 P_("Whether images should be shown in menus"),
1271 GTK_PARAM_READWRITE),
1273 g_assert (result == PROP_MENU_IMAGES);
1275 result = settings_install_property_parser (class,
1276 g_param_spec_int ("gtk-menu-bar-popup-delay",
1277 P_("Delay before drop down menus appear"),
1278 P_("Delay before the submenus of a menu bar appear"),
1281 GTK_PARAM_READWRITE),
1283 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1286 * GtkSettings:gtk-scrolled-window-placement:
1288 * Where the contents of scrolled windows are located with respect to the
1289 * scrollbars, if not overridden by the scrolled window's own placement.
1293 result = settings_install_property_parser (class,
1294 g_param_spec_enum ("gtk-scrolled-window-placement",
1295 P_("Scrolled Window Placement"),
1296 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1297 GTK_TYPE_CORNER_TYPE,
1298 GTK_CORNER_TOP_LEFT,
1299 GTK_PARAM_READWRITE),
1300 gtk_rc_property_parse_enum);
1301 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1303 result = settings_install_property_parser (class,
1304 g_param_spec_boolean ("gtk-can-change-accels",
1305 P_("Can change accelerators"),
1306 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1308 GTK_PARAM_READWRITE),
1310 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1312 result = settings_install_property_parser (class,
1313 g_param_spec_int ("gtk-menu-popup-delay",
1314 P_("Delay before submenus appear"),
1315 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1318 GTK_PARAM_READWRITE),
1320 g_assert (result == PROP_MENU_POPUP_DELAY);
1322 result = settings_install_property_parser (class,
1323 g_param_spec_int ("gtk-menu-popdown-delay",
1324 P_("Delay before hiding a submenu"),
1325 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1328 GTK_PARAM_READWRITE),
1330 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1332 result = settings_install_property_parser (class,
1333 g_param_spec_boolean ("gtk-label-select-on-focus",
1334 P_("Select on focus"),
1335 P_("Whether to select the contents of a selectable label when it is focused"),
1337 GTK_PARAM_READWRITE),
1339 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1341 result = settings_install_property_parser (class,
1342 g_param_spec_string ("gtk-color-palette",
1343 P_("Custom palette"),
1344 P_("Palette to use in the color selector"),
1345 default_color_palette,
1346 GTK_PARAM_READWRITE),
1348 g_assert (result == PROP_COLOR_PALETTE);
1350 result = settings_install_property_parser (class,
1351 g_param_spec_enum ("gtk-im-preedit-style",
1352 P_("IM Preedit style"),
1353 P_("How to draw the input method preedit string"),
1354 GTK_TYPE_IM_PREEDIT_STYLE,
1355 GTK_IM_PREEDIT_CALLBACK,
1356 GTK_PARAM_READWRITE),
1357 gtk_rc_property_parse_enum);
1358 g_assert (result == PROP_IM_PREEDIT_STYLE);
1360 result = settings_install_property_parser (class,
1361 g_param_spec_enum ("gtk-im-status-style",
1362 P_("IM Status style"),
1363 P_("How to draw the input method statusbar"),
1364 GTK_TYPE_IM_STATUS_STYLE,
1365 GTK_IM_STATUS_CALLBACK,
1366 GTK_PARAM_READWRITE),
1367 gtk_rc_property_parse_enum);
1368 g_assert (result == PROP_IM_STATUS_STYLE);
1370 result = settings_install_property_parser (class,
1371 g_param_spec_boolean ("gtk-shell-shows-app-menu",
1372 P_("Desktop shell shows app menu"),
1373 P_("Set to TRUE if the desktop environment "
1374 "is displaying the app menu, FALSE if "
1375 "the app should display it itself."),
1376 FALSE, GTK_PARAM_READWRITE),
1378 g_assert (result == PROP_SHELL_SHOWS_APP_MENU);
1380 result = settings_install_property_parser (class,
1381 g_param_spec_boolean ("gtk-shell-shows-menubar",
1382 P_("Desktop shell shows the menubar"),
1383 P_("Set to TRUE if the desktop environment "
1384 "is displaying the menubar, FALSE if "
1385 "the app should display it itself."),
1386 FALSE, GTK_PARAM_READWRITE),
1388 g_assert (result == PROP_SHELL_SHOWS_MENUBAR);
1391 * GtkSettings:gtk-enable-primary-paste:
1393 * Whether a middle click on a mouse should paste the
1394 * 'PRIMARY' clipboard content at the cursor location.
1398 result = settings_install_property_parser (class,
1399 g_param_spec_boolean ("gtk-enable-primary-paste",
1400 P_("Enable primary paste"),
1401 P_("Whether a middle click on a mouse should paste the 'PRIMARY' clipboard content at the cursor location."),
1403 GTK_PARAM_READWRITE),
1405 g_assert (result == PROP_ENABLE_PRIMARY_PASTE);
1407 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1411 settings_ensure_style (GtkSettings *settings)
1413 GtkSettingsPrivate *priv = settings->priv;
1414 PangoFontDescription *font_desc;
1415 gchar *font_name, *color_scheme;
1422 priv->style = gtk_style_properties_new ();
1424 g_object_get (settings,
1425 "gtk-font-name", &font_name,
1426 "gtk-color-scheme", &color_scheme,
1429 colors = g_strsplit_set (color_scheme, "\n;", -1);
1431 for (i = 0; colors[i]; i++)
1433 GtkSymbolicColor *color;
1441 pos = strchr (colors[i], ':');
1446 /* Set NUL after color name */
1450 /* Find start of color string */
1454 if (!*pos || !gdk_rgba_parse (&col, pos))
1457 color = gtk_symbolic_color_new_literal (&col);
1458 gtk_style_properties_map_color (priv->style, name, color);
1459 gtk_symbolic_color_unref (color);
1462 font_desc = pango_font_description_from_string (font_name);
1464 /* Unset normal attributes from this description,
1465 * so they do not override theme values */
1466 if (pango_font_description_get_weight (font_desc) == PANGO_WEIGHT_NORMAL)
1467 pango_font_description_unset_fields (font_desc,
1468 PANGO_FONT_MASK_WEIGHT);
1470 if (pango_font_description_get_stretch (font_desc) == PANGO_STRETCH_NORMAL)
1471 pango_font_description_unset_fields (font_desc,
1472 PANGO_FONT_MASK_STRETCH);
1474 if (pango_font_description_get_variant (font_desc) == PANGO_VARIANT_NORMAL)
1475 pango_font_description_unset_fields (font_desc,
1476 PANGO_FONT_MASK_VARIANT);
1478 if (pango_font_description_get_style (font_desc) == PANGO_STYLE_NORMAL)
1479 pango_font_description_unset_fields (font_desc,
1480 PANGO_FONT_MASK_STYLE);
1482 gtk_style_properties_set (priv->style, 0,
1486 pango_font_description_free (font_desc);
1487 g_strfreev (colors);
1488 g_free (color_scheme);
1492 static GtkStyleProperties *
1493 gtk_settings_get_style (GtkStyleProvider *provider,
1494 GtkWidgetPath *path)
1496 GtkSettings *settings;
1498 settings = GTK_SETTINGS (provider);
1500 settings_ensure_style (settings);
1502 return g_object_ref (settings->priv->style);
1506 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1508 iface->get_style = gtk_settings_get_style;
1511 static GtkSymbolicColor *
1512 gtk_settings_style_provider_get_color (GtkStyleProviderPrivate *provider,
1515 GtkSettings *settings = GTK_SETTINGS (provider);
1517 settings_ensure_style (settings);
1519 return _gtk_style_provider_private_get_color (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style), name);
1523 gtk_settings_style_provider_lookup (GtkStyleProviderPrivate *provider,
1524 const GtkCssMatcher *matcher,
1525 GtkCssLookup *lookup)
1527 GtkSettings *settings = GTK_SETTINGS (provider);
1529 settings_ensure_style (settings);
1531 _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style),
1537 gtk_settings_style_provider_get_change (GtkStyleProviderPrivate *provider,
1538 const GtkCssMatcher *matcher)
1540 GtkSettings *settings = GTK_SETTINGS (provider);
1542 settings_ensure_style (settings);
1544 return _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (settings->priv->style),
1549 gtk_settings_provider_private_init (GtkStyleProviderPrivateInterface *iface)
1551 iface->get_color = gtk_settings_style_provider_get_color;
1552 iface->lookup = gtk_settings_style_provider_lookup;
1553 iface->get_change = gtk_settings_style_provider_get_change;
1557 gtk_settings_finalize (GObject *object)
1559 GtkSettings *settings = GTK_SETTINGS (object);
1560 GtkSettingsPrivate *priv = settings->priv;
1563 object_list = g_slist_remove (object_list, settings);
1565 for (i = 0; i < class_n_properties; i++)
1566 g_value_unset (&priv->property_values[i].value);
1567 g_free (priv->property_values);
1569 g_datalist_clear (&priv->queued_settings);
1571 if (priv->theme_provider)
1572 g_object_unref (priv->theme_provider);
1574 if (priv->key_theme_provider)
1575 g_object_unref (priv->key_theme_provider);
1578 g_object_unref (priv->style);
1580 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1584 settings_init_style (GtkSettings *settings)
1586 static GtkCssProvider *css_provider = NULL;
1588 GdkScreen *screen = settings->priv->screen;
1590 /* Add provider for user file */
1591 if (G_UNLIKELY (!css_provider))
1595 css_provider = gtk_css_provider_new ();
1596 css_path = g_build_filename (g_get_user_config_dir (),
1601 if (g_file_test (css_path,
1602 G_FILE_TEST_IS_REGULAR))
1603 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1608 gtk_style_context_add_provider_for_screen (screen,
1609 GTK_STYLE_PROVIDER (css_provider),
1610 GTK_STYLE_PROVIDER_PRIORITY_USER);
1612 gtk_style_context_add_provider_for_screen (screen,
1613 GTK_STYLE_PROVIDER (settings),
1614 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1616 settings_update_theme (settings);
1617 settings_update_key_theme (settings);
1621 * gtk_settings_get_for_screen:
1622 * @screen: a #GdkScreen.
1624 * Gets the #GtkSettings object for @screen, creating it if necessary.
1626 * Return value: (transfer none): a #GtkSettings object.
1631 gtk_settings_get_for_screen (GdkScreen *screen)
1633 GtkSettings *settings;
1635 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1637 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1640 #ifdef GDK_WINDOWING_QUARTZ
1641 if (GDK_IS_QUARTZ_SCREEN (screen))
1642 settings = g_object_new (GTK_TYPE_SETTINGS,
1643 "gtk-key-theme-name", "Mac",
1644 "gtk-shell-shows-app-menu", TRUE,
1645 "gtk-shell-shows-menubar", TRUE,
1649 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1650 settings->priv->screen = screen;
1651 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1652 settings, g_object_unref);
1654 settings_init_style (settings);
1655 settings_update_double_click (settings);
1656 settings_update_cursor_theme (settings);
1657 settings_update_resolution (settings);
1658 settings_update_font_options (settings);
1659 settings_update_color_scheme (settings);
1666 * gtk_settings_get_default:
1668 * Gets the #GtkSettings object for the default GDK screen, creating
1669 * it if necessary. See gtk_settings_get_for_screen().
1671 * Return value: (transfer none): a #GtkSettings object. If there is no default
1672 * screen, then returns %NULL.
1675 gtk_settings_get_default (void)
1677 GdkScreen *screen = gdk_screen_get_default ();
1680 return gtk_settings_get_for_screen (screen);
1686 gtk_settings_set_property (GObject *object,
1688 const GValue *value,
1691 GtkSettings *settings = GTK_SETTINGS (object);
1692 GtkSettingsPrivate *priv = settings->priv;
1694 g_value_copy (value, &priv->property_values[property_id - 1].value);
1695 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1697 if (pspec->param_id == PROP_COLOR_SCHEME)
1698 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1702 gtk_settings_get_property (GObject *object,
1707 GtkSettings *settings = GTK_SETTINGS (object);
1708 GtkSettingsPrivate *priv = settings->priv;
1709 GType value_type = G_VALUE_TYPE (value);
1710 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1712 /* handle internal properties */
1713 switch (property_id)
1715 case PROP_COLOR_HASH:
1716 g_value_set_boxed (value, get_color_hash (settings));
1718 case PROP_COLOR_SCHEME:
1719 g_value_take_string (value, get_color_scheme (settings));
1724 /* For enums and strings, we need to get the value as a string,
1725 * not as an int, since we support using names/nicks as the setting
1728 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1729 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1730 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1731 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1733 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1734 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1735 g_value_copy (&priv->property_values[property_id - 1].value, value);
1737 g_param_value_validate (pspec, value);
1741 GValue val = G_VALUE_INIT;
1743 /* Try to get xsetting as a string and parse it. */
1745 g_value_init (&val, G_TYPE_STRING);
1747 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1748 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1750 g_value_copy (&priv->property_values[property_id - 1].value, value);
1754 GValue tmp_value = G_VALUE_INIT;
1755 GValue gstring_value = G_VALUE_INIT;
1756 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1758 g_value_init (&gstring_value, G_TYPE_GSTRING);
1759 g_value_take_boxed (&gstring_value,
1760 g_string_new (g_value_get_string (&val)));
1762 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1764 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1767 g_value_copy (&tmp_value, value);
1768 g_param_value_validate (pspec, value);
1772 g_value_copy (&priv->property_values[property_id - 1].value, value);
1775 g_value_unset (&gstring_value);
1776 g_value_unset (&tmp_value);
1779 g_value_unset (&val);
1784 settings_invalidate_style (GtkSettings *settings)
1786 GtkSettingsPrivate *priv = settings->priv;
1790 g_object_unref (priv->style);
1794 _gtk_style_provider_private_changed (GTK_STYLE_PROVIDER_PRIVATE (settings));
1798 gtk_settings_notify (GObject *object,
1801 GtkSettings *settings = GTK_SETTINGS (object);
1802 GtkSettingsPrivate *priv = settings->priv;
1803 guint property_id = pspec->param_id;
1805 if (priv->screen == NULL) /* initialization */
1808 switch (property_id)
1811 settings_update_modules (settings);
1813 case PROP_DOUBLE_CLICK_TIME:
1814 case PROP_DOUBLE_CLICK_DISTANCE:
1815 settings_update_double_click (settings);
1817 case PROP_COLOR_SCHEME:
1818 settings_update_color_scheme (settings);
1819 settings_invalidate_style (settings);
1820 gtk_style_context_reset_widgets (priv->screen);
1822 case PROP_FONT_NAME:
1823 settings_invalidate_style (settings);
1824 gtk_style_context_reset_widgets (priv->screen);
1826 case PROP_KEY_THEME_NAME:
1827 settings_update_key_theme (settings);
1829 case PROP_THEME_NAME:
1830 case PROP_APPLICATION_PREFER_DARK_THEME:
1831 settings_update_theme (settings);
1834 settings_update_resolution (settings);
1835 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1836 * widgets with gtk_widget_style_set(), and also causes more
1837 * recomputation than necessary.
1839 gtk_style_context_reset_widgets (priv->screen);
1841 case PROP_XFT_ANTIALIAS:
1842 case PROP_XFT_HINTING:
1843 case PROP_XFT_HINTSTYLE:
1845 settings_update_font_options (settings);
1846 gtk_style_context_reset_widgets (priv->screen);
1848 case PROP_FONTCONFIG_TIMESTAMP:
1849 if (settings_update_fontconfig (settings))
1850 gtk_style_context_reset_widgets (priv->screen);
1852 case PROP_CURSOR_THEME_NAME:
1853 case PROP_CURSOR_THEME_SIZE:
1854 settings_update_cursor_theme (settings);
1860 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1861 const GValue *src_value,
1865 gboolean success = FALSE;
1867 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1872 gboolean free_gstring = TRUE;
1874 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1876 gstring = g_value_get_boxed (src_value);
1877 free_gstring = FALSE;
1879 else if (G_VALUE_HOLDS_LONG (src_value))
1881 gstring = g_string_new (NULL);
1882 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1884 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1886 gstring = g_string_new (NULL);
1887 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1889 else if (G_VALUE_HOLDS_STRING (src_value))
1891 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1893 gstring = g_string_new (NULL);
1894 g_string_append_c (gstring, '\"');
1895 g_string_append (gstring, tstr);
1896 g_string_append_c (gstring, '\"');
1901 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1902 gstring = NULL; /* silence compiler */
1905 success = (parser (pspec, gstring, dest_value) &&
1906 !g_param_value_validate (pspec, dest_value));
1909 g_string_free (gstring, TRUE);
1911 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1913 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1915 GString *gstring = g_value_get_boxed (src_value);
1917 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1918 success = !g_param_value_validate (pspec, dest_value);
1921 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1922 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1928 apply_queued_setting (GtkSettings *settings,
1930 GtkSettingsValuePrivate *qvalue)
1932 GtkSettingsPrivate *priv = settings->priv;
1933 GValue tmp_value = G_VALUE_INIT;
1934 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1936 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1937 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1940 if (pspec->param_id == PROP_COLOR_SCHEME)
1941 merge_color_scheme (settings, &tmp_value, qvalue->source);
1943 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1945 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1946 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1947 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1953 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1955 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1956 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1958 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1960 G_VALUE_TYPE_NAME (&tmp_value));
1963 g_value_unset (&tmp_value);
1967 settings_install_property_parser (GtkSettingsClass *class,
1969 GtkRcPropertyParser parser)
1971 GSList *node, *next;
1973 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1975 case G_TYPE_BOOLEAN:
1988 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1996 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1997 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
2001 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
2003 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
2008 for (node = object_list; node; node = node->next)
2009 g_object_freeze_notify (node->data);
2011 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
2012 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
2014 for (node = object_list; node; node = node->next)
2016 GtkSettings *settings = node->data;
2017 GtkSettingsPrivate *priv = settings->priv;
2018 GtkSettingsValuePrivate *qvalue;
2020 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
2021 priv->property_values[class_n_properties - 1].value.g_type = 0;
2022 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
2023 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
2024 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
2025 g_object_notify (G_OBJECT (settings), pspec->name);
2027 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
2029 apply_queued_setting (settings, pspec, qvalue);
2032 for (node = object_list; node; node = next)
2035 g_object_thaw_notify (node->data);
2038 return class_n_properties;
2042 _gtk_rc_property_parser_from_type (GType type)
2044 if (type == GDK_TYPE_COLOR)
2045 return gtk_rc_property_parse_color;
2046 else if (type == GTK_TYPE_REQUISITION)
2047 return gtk_rc_property_parse_requisition;
2048 else if (type == GTK_TYPE_BORDER)
2049 return gtk_rc_property_parse_border;
2050 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
2051 return gtk_rc_property_parse_enum;
2052 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
2053 return gtk_rc_property_parse_flags;
2059 gtk_settings_install_property (GParamSpec *pspec)
2061 static GtkSettingsClass *klass = NULL;
2063 GtkRcPropertyParser parser;
2065 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2068 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2070 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
2072 settings_install_property_parser (klass, pspec, parser);
2076 * gtk_settings_install_property_parser:
2078 * @parser: (scope call):
2081 gtk_settings_install_property_parser (GParamSpec *pspec,
2082 GtkRcPropertyParser parser)
2084 static GtkSettingsClass *klass = NULL;
2086 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
2087 g_return_if_fail (parser != NULL);
2090 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
2092 settings_install_property_parser (klass, pspec, parser);
2096 free_value (gpointer data)
2098 GtkSettingsValuePrivate *qvalue = data;
2100 g_value_unset (&qvalue->public.value);
2101 g_free (qvalue->public.origin);
2102 g_slice_free (GtkSettingsValuePrivate, qvalue);
2106 gtk_settings_set_property_value_internal (GtkSettings *settings,
2107 const gchar *prop_name,
2108 const GtkSettingsValue *new_value,
2109 GtkSettingsSource source)
2111 GtkSettingsPrivate *priv = settings->priv;
2112 GtkSettingsValuePrivate *qvalue;
2117 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
2118 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
2119 !G_VALUE_HOLDS_STRING (&new_value->value) &&
2120 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
2122 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
2126 name = g_strdup (prop_name);
2127 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
2128 name_quark = g_quark_from_string (name);
2131 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
2134 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
2135 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
2139 g_free (qvalue->public.origin);
2140 g_value_unset (&qvalue->public.value);
2142 qvalue->public.origin = g_strdup (new_value->origin);
2143 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
2144 g_value_copy (&new_value->value, &qvalue->public.value);
2145 qvalue->source = source;
2146 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
2148 apply_queued_setting (settings, pspec, qvalue);
2152 gtk_settings_set_property_value (GtkSettings *settings,
2153 const gchar *prop_name,
2154 const GtkSettingsValue *new_value)
2156 g_return_if_fail (GTK_SETTINGS (settings));
2157 g_return_if_fail (prop_name != NULL);
2158 g_return_if_fail (new_value != NULL);
2160 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2161 GTK_SETTINGS_SOURCE_APPLICATION);
2165 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
2166 const gchar *prop_name,
2167 const GtkSettingsValue *new_value)
2169 g_return_if_fail (GTK_SETTINGS (settings));
2170 g_return_if_fail (prop_name != NULL);
2171 g_return_if_fail (new_value != NULL);
2173 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2174 GTK_SETTINGS_SOURCE_THEME);
2178 gtk_settings_set_string_property (GtkSettings *settings,
2180 const gchar *v_string,
2181 const gchar *origin)
2183 GtkSettingsValue svalue = { NULL, { 0, }, };
2185 g_return_if_fail (GTK_SETTINGS (settings));
2186 g_return_if_fail (name != NULL);
2187 g_return_if_fail (v_string != NULL);
2189 svalue.origin = (gchar*) origin;
2190 g_value_init (&svalue.value, G_TYPE_STRING);
2191 g_value_set_static_string (&svalue.value, v_string);
2192 gtk_settings_set_property_value (settings, name, &svalue);
2193 g_value_unset (&svalue.value);
2197 gtk_settings_set_long_property (GtkSettings *settings,
2200 const gchar *origin)
2202 GtkSettingsValue svalue = { NULL, { 0, }, };
2204 g_return_if_fail (GTK_SETTINGS (settings));
2205 g_return_if_fail (name != NULL);
2207 svalue.origin = (gchar*) origin;
2208 g_value_init (&svalue.value, G_TYPE_LONG);
2209 g_value_set_long (&svalue.value, v_long);
2210 gtk_settings_set_property_value (settings, name, &svalue);
2211 g_value_unset (&svalue.value);
2215 gtk_settings_set_double_property (GtkSettings *settings,
2218 const gchar *origin)
2220 GtkSettingsValue svalue = { NULL, { 0, }, };
2222 g_return_if_fail (GTK_SETTINGS (settings));
2223 g_return_if_fail (name != NULL);
2225 svalue.origin = (gchar*) origin;
2226 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2227 g_value_set_double (&svalue.value, v_double);
2228 gtk_settings_set_property_value (settings, name, &svalue);
2229 g_value_unset (&svalue.value);
2233 * gtk_rc_property_parse_color:
2234 * @pspec: a #GParamSpec
2235 * @gstring: the #GString to be parsed
2236 * @property_value: a #GValue which must hold #GdkColor values.
2238 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2239 * or gtk_widget_class_install_style_property_parser() which parses a
2240 * color given either by its name or in the form
2241 * <literal>{ red, green, blue }</literal> where %red, %green and
2242 * %blue are integers between 0 and 65535 or floating-point numbers
2245 * Return value: %TRUE if @gstring could be parsed and @property_value
2246 * has been set to the resulting #GdkColor.
2249 gtk_rc_property_parse_color (const GParamSpec *pspec,
2250 const GString *gstring,
2251 GValue *property_value)
2253 GdkColor color = { 0, 0, 0, 0, };
2257 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2258 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2260 scanner = gtk_rc_scanner_new ();
2261 g_scanner_input_text (scanner, gstring->str, gstring->len);
2262 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2263 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2265 g_value_set_boxed (property_value, &color);
2270 g_scanner_destroy (scanner);
2276 * gtk_rc_property_parse_enum:
2277 * @pspec: a #GParamSpec
2278 * @gstring: the #GString to be parsed
2279 * @property_value: a #GValue which must hold enum values.
2281 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2282 * or gtk_widget_class_install_style_property_parser() which parses a single
2283 * enumeration value.
2285 * The enumeration value can be specified by its name, its nickname or
2286 * its numeric value. For consistency with flags parsing, the value
2287 * may be surrounded by parentheses.
2289 * Return value: %TRUE if @gstring could be parsed and @property_value
2290 * has been set to the resulting #GEnumValue.
2293 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2294 const GString *gstring,
2295 GValue *property_value)
2297 gboolean need_closing_brace = FALSE, success = FALSE;
2299 GEnumValue *enum_value = NULL;
2301 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2302 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2304 scanner = gtk_rc_scanner_new ();
2305 g_scanner_input_text (scanner, gstring->str, gstring->len);
2307 /* we just want to parse _one_ value, but for consistency with flags parsing
2308 * we support optional parenthesis
2310 g_scanner_get_next_token (scanner);
2311 if (scanner->token == '(')
2313 need_closing_brace = TRUE;
2314 g_scanner_get_next_token (scanner);
2316 if (scanner->token == G_TOKEN_IDENTIFIER)
2318 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2320 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2322 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2325 g_value_set_enum (property_value, enum_value->value);
2329 else if (scanner->token == G_TOKEN_INT)
2331 g_value_set_enum (property_value, scanner->value.v_int);
2334 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2336 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2339 g_scanner_destroy (scanner);
2345 parse_flags_value (GScanner *scanner,
2349 g_scanner_get_next_token (scanner);
2350 if (scanner->token == G_TOKEN_IDENTIFIER)
2352 GFlagsValue *flags_value;
2354 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2356 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2359 *number |= flags_value->value;
2360 return G_TOKEN_NONE;
2363 else if (scanner->token == G_TOKEN_INT)
2365 *number |= scanner->value.v_int;
2366 return G_TOKEN_NONE;
2368 return G_TOKEN_IDENTIFIER;
2372 * gtk_rc_property_parse_flags:
2373 * @pspec: a #GParamSpec
2374 * @gstring: the #GString to be parsed
2375 * @property_value: a #GValue which must hold flags values.
2377 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2378 * or gtk_widget_class_install_style_property_parser() which parses flags.
2380 * Flags can be specified by their name, their nickname or
2381 * numerically. Multiple flags can be specified in the form
2382 * <literal>"( flag1 | flag2 | ... )"</literal>.
2384 * Return value: %TRUE if @gstring could be parsed and @property_value
2385 * has been set to the resulting flags value.
2388 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2389 const GString *gstring,
2390 GValue *property_value)
2393 gboolean success = FALSE;
2396 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2397 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2399 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2400 scanner = gtk_rc_scanner_new ();
2401 g_scanner_input_text (scanner, gstring->str, gstring->len);
2403 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2404 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2405 scanner->next_token == G_TOKEN_INT)
2407 guint token, flags_value = 0;
2409 token = parse_flags_value (scanner, class, &flags_value);
2411 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2414 g_value_set_flags (property_value, flags_value);
2418 else if (g_scanner_get_next_token (scanner) == '(')
2420 guint token, flags_value = 0;
2422 /* parse first value */
2423 token = parse_flags_value (scanner, class, &flags_value);
2425 /* parse nth values, preceeded by '|' */
2426 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2427 token = parse_flags_value (scanner, class, &flags_value);
2429 /* done, last token must have closed expression */
2430 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2431 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2433 g_value_set_flags (property_value, flags_value);
2437 g_scanner_destroy (scanner);
2443 get_braced_int (GScanner *scanner,
2450 g_scanner_get_next_token (scanner);
2451 if (scanner->token != '{')
2455 g_scanner_get_next_token (scanner);
2456 if (scanner->token != G_TOKEN_INT)
2459 *value = scanner->value.v_int;
2463 g_scanner_get_next_token (scanner);
2464 if (scanner->token != '}')
2469 g_scanner_get_next_token (scanner);
2470 if (scanner->token != ',')
2478 * gtk_rc_property_parse_requisition:
2479 * @pspec: a #GParamSpec
2480 * @gstring: the #GString to be parsed
2481 * @property_value: a #GValue which must hold boxed values.
2483 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2484 * or gtk_widget_class_install_style_property_parser() which parses a
2485 * requisition in the form
2486 * <literal>"{ width, height }"</literal> for integers %width and %height.
2488 * Return value: %TRUE if @gstring could be parsed and @property_value
2489 * has been set to the resulting #GtkRequisition.
2492 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2493 const GString *gstring,
2494 GValue *property_value)
2496 GtkRequisition requisition;
2498 gboolean success = FALSE;
2500 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2501 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2503 scanner = gtk_rc_scanner_new ();
2504 g_scanner_input_text (scanner, gstring->str, gstring->len);
2506 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2507 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2509 g_value_set_boxed (property_value, &requisition);
2513 g_scanner_destroy (scanner);
2519 * gtk_rc_property_parse_border:
2520 * @pspec: a #GParamSpec
2521 * @gstring: the #GString to be parsed
2522 * @property_value: a #GValue which must hold boxed values.
2524 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2525 * or gtk_widget_class_install_style_property_parser() which parses
2526 * borders in the form
2527 * <literal>"{ left, right, top, bottom }"</literal> for integers
2528 * %left, %right, %top and %bottom.
2530 * Return value: %TRUE if @gstring could be parsed and @property_value
2531 * has been set to the resulting #GtkBorder.
2534 gtk_rc_property_parse_border (const GParamSpec *pspec,
2535 const GString *gstring,
2536 GValue *property_value)
2540 gboolean success = FALSE;
2541 int left, right, top, bottom;
2543 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2544 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2546 scanner = gtk_rc_scanner_new ();
2547 g_scanner_input_text (scanner, gstring->str, gstring->len);
2549 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2550 get_braced_int (scanner, FALSE, FALSE, &right) &&
2551 get_braced_int (scanner, FALSE, FALSE, &top) &&
2552 get_braced_int (scanner, FALSE, TRUE, &bottom))
2555 border.right = right;
2557 border.bottom = bottom;
2558 g_value_set_boxed (property_value, &border);
2562 g_scanner_destroy (scanner);
2568 _gtk_settings_handle_event (GdkEventSetting *event)
2571 GtkSettings *settings;
2575 screen = gdk_window_get_screen (event->window);
2576 settings = gtk_settings_get_for_screen (screen);
2577 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2581 property_id = pspec->param_id;
2583 if (property_id == PROP_COLOR_SCHEME)
2585 GValue value = G_VALUE_INIT;
2587 g_value_init (&value, G_TYPE_STRING);
2588 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2589 g_value_set_static_string (&value, "");
2590 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2591 g_value_unset (&value);
2593 g_object_notify (G_OBJECT (settings), pspec->name);
2598 reset_rc_values_foreach (GQuark key_id,
2602 GtkSettingsValuePrivate *qvalue = data;
2603 GSList **to_reset = user_data;
2605 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2606 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2610 _gtk_settings_reset_rc_values (GtkSettings *settings)
2612 GtkSettingsPrivate *priv = settings->priv;
2613 GSList *to_reset = NULL;
2615 GParamSpec **pspecs, **p;
2618 /* Remove any queued settings */
2619 g_datalist_foreach (&priv->queued_settings,
2620 reset_rc_values_foreach,
2623 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2625 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2626 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2629 g_slist_free (to_reset);
2631 /* Now reset the active settings
2633 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2636 g_object_freeze_notify (G_OBJECT (settings));
2637 for (p = pspecs; *p; p++)
2639 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2641 GParamSpec *pspec = *p;
2643 g_param_value_set_default (pspec, &priv->property_values[i].value);
2644 g_object_notify (G_OBJECT (settings), pspec->name);
2648 g_object_thaw_notify (G_OBJECT (settings));
2653 settings_update_double_click (GtkSettings *settings)
2655 GtkSettingsPrivate *priv = settings->priv;
2657 if (gdk_screen_get_number (priv->screen) == 0)
2659 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2660 gint double_click_time;
2661 gint double_click_distance;
2663 g_object_get (settings,
2664 "gtk-double-click-time", &double_click_time,
2665 "gtk-double-click-distance", &double_click_distance,
2668 gdk_display_set_double_click_time (display, double_click_time);
2669 gdk_display_set_double_click_distance (display, double_click_distance);
2674 settings_update_modules (GtkSettings *settings)
2678 g_object_get (settings,
2679 "gtk-modules", &modules,
2682 _gtk_modules_settings_changed (settings, modules);
2688 settings_update_cursor_theme (GtkSettings *settings)
2690 #ifdef GDK_WINDOWING_X11
2691 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2692 gchar *theme = NULL;
2695 if (GDK_IS_X11_DISPLAY (display))
2697 g_object_get (settings,
2698 "gtk-cursor-theme-name", &theme,
2699 "gtk-cursor-theme-size", &size,
2702 gdk_x11_display_set_cursor_theme (display, theme, size);
2710 settings_update_font_options (GtkSettings *settings)
2712 GtkSettingsPrivate *priv = settings->priv;
2714 gchar *hint_style_str;
2715 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2717 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2719 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2720 cairo_font_options_t *options;
2722 g_object_get (settings,
2723 "gtk-xft-antialias", &antialias,
2724 "gtk-xft-hinting", &hinting,
2725 "gtk-xft-hintstyle", &hint_style_str,
2726 "gtk-xft-rgba", &rgba_str,
2729 options = cairo_font_options_create ();
2731 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2733 if (hinting >= 0 && !hinting)
2735 hint_style = CAIRO_HINT_STYLE_NONE;
2737 else if (hint_style_str)
2739 if (strcmp (hint_style_str, "hintnone") == 0)
2740 hint_style = CAIRO_HINT_STYLE_NONE;
2741 else if (strcmp (hint_style_str, "hintslight") == 0)
2742 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2743 else if (strcmp (hint_style_str, "hintmedium") == 0)
2744 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2745 else if (strcmp (hint_style_str, "hintfull") == 0)
2746 hint_style = CAIRO_HINT_STYLE_FULL;
2749 g_free (hint_style_str);
2751 cairo_font_options_set_hint_style (options, hint_style);
2755 if (strcmp (rgba_str, "rgb") == 0)
2756 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2757 else if (strcmp (rgba_str, "bgr") == 0)
2758 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2759 else if (strcmp (rgba_str, "vrgb") == 0)
2760 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2761 else if (strcmp (rgba_str, "vbgr") == 0)
2762 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2767 cairo_font_options_set_subpixel_order (options, subpixel_order);
2769 if (antialias >= 0 && !antialias)
2770 antialias_mode = CAIRO_ANTIALIAS_NONE;
2771 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2772 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2773 else if (antialias >= 0)
2774 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2776 cairo_font_options_set_antialias (options, antialias_mode);
2778 gdk_screen_set_font_options (priv->screen, options);
2780 cairo_font_options_destroy (options);
2784 settings_update_fontconfig (GtkSettings *settings)
2786 #ifdef GDK_WINDOWING_X11
2787 static guint last_update_timestamp;
2788 static gboolean last_update_needed;
2792 g_object_get (settings,
2793 "gtk-fontconfig-timestamp", ×tamp,
2796 /* if timestamp is the same as last_update_timestamp, we already have
2797 * updated fontconig on this timestamp (another screen requested it perhaps?),
2798 * just return the cached result.*/
2800 if (timestamp != last_update_timestamp)
2802 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2803 gboolean update_needed = FALSE;
2806 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2808 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2809 if (FcInitReinitialize ())
2810 update_needed = TRUE;
2813 last_update_timestamp = timestamp;
2814 last_update_needed = update_needed;
2817 return last_update_needed;
2820 #endif /* GDK_WINDOWING_X11 */
2824 settings_update_resolution (GtkSettings *settings)
2826 GtkSettingsPrivate *priv = settings->priv;
2830 g_object_get (settings,
2831 "gtk-xft-dpi", &dpi_int,
2835 dpi = dpi_int / 1024.;
2839 gdk_screen_set_resolution (priv->screen, dpi);
2844 GHashTable *color_hash;
2845 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2846 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2850 color_scheme_data_free (ColorSchemeData *data)
2854 g_hash_table_unref (data->color_hash);
2856 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2858 if (data->tables[i])
2859 g_hash_table_unref (data->tables[i]);
2860 g_free (data->lastentry[i]);
2863 g_slice_free (ColorSchemeData, data);
2867 settings_update_color_scheme (GtkSettings *settings)
2869 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2871 GtkSettingsPrivate *priv = settings->priv;
2872 ColorSchemeData *data;
2873 GValue value = G_VALUE_INIT;
2875 data = g_slice_new0 (ColorSchemeData);
2876 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2877 (GDestroyNotify) gdk_color_free);
2878 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2879 data, (GDestroyNotify) color_scheme_data_free);
2881 g_value_init (&value, G_TYPE_STRING);
2882 if (priv->screen && gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2884 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2885 g_value_unset (&value);
2891 settings_update_provider (GdkScreen *screen,
2892 GtkCssProvider **old,
2893 GtkCssProvider *new)
2899 gtk_style_context_remove_provider_for_screen (screen,
2900 GTK_STYLE_PROVIDER (*old));
2901 g_object_unref (*old);
2907 gtk_style_context_add_provider_for_screen (screen,
2908 GTK_STYLE_PROVIDER (new),
2909 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2910 *old = g_object_ref (new);
2916 settings_update_theme (GtkSettings *settings)
2918 GtkSettingsPrivate *priv = settings->priv;
2919 GtkCssProvider *provider = NULL;
2920 gboolean prefer_dark_theme;
2923 g_object_get (settings,
2924 "gtk-theme-name", &theme_name,
2925 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2928 if (theme_name && *theme_name)
2930 if (prefer_dark_theme)
2931 provider = _gtk_css_provider_get_named_for_screen (priv->screen, theme_name, "dark");
2934 provider = _gtk_css_provider_get_named_for_screen (priv->screen, theme_name, NULL);
2937 /* If we didn't find the named theme, fall back */
2939 provider = _gtk_css_provider_get_named_for_screen (priv->screen, "Raleigh", NULL);
2941 settings_update_provider (priv->screen, &priv->theme_provider, provider);
2943 if (theme_name && *theme_name)
2948 /* reload per-theme settings */
2949 theme_dir = _gtk_css_provider_get_theme_dir ();
2950 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2952 if (g_file_test (path, G_FILE_TEST_EXISTS))
2953 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2959 g_free (theme_name);
2963 settings_update_key_theme (GtkSettings *settings)
2965 GtkSettingsPrivate *priv = settings->priv;
2966 GtkCssProvider *provider = NULL;
2967 gchar *key_theme_name;
2969 g_object_get (settings,
2970 "gtk-key-theme-name", &key_theme_name,
2973 if (key_theme_name && *key_theme_name)
2974 provider = _gtk_css_provider_get_named_for_screen (priv->screen, key_theme_name, "keys");
2976 settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2977 g_free (key_theme_name);
2981 add_color_to_hash (gchar *name,
2987 old = g_hash_table_lookup (target, name);
2988 if (!old || !gdk_color_equal (old, color))
2990 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2999 add_colors_to_hash_from_string (GHashTable *hash,
3000 const gchar *colors)
3002 gchar *s, *p, *name;
3004 gboolean changed = FALSE;
3007 copy = g_strdup (colors);
3012 p = strchr (s, ':');
3027 if (*s == '\n' || *s == ';')
3036 if (gdk_color_parse (p, &color))
3037 changed |= add_color_to_hash (name, &color, hash);
3046 update_color_hash (ColorSchemeData *data,
3048 GtkSettingsSource source)
3050 gboolean changed = FALSE;
3052 GHashTable *old_hash;
3053 GHashTableIter iter;
3057 if ((str == NULL || *str == '\0') &&
3058 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
3061 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
3064 /* For the THEME source we merge the values rather than over-writing
3065 * them, since multiple rc files might define independent sets of colors
3067 if ((source != GTK_SETTINGS_SOURCE_THEME) &&
3068 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
3070 g_hash_table_unref (data->tables[source]);
3071 data->tables[source] = NULL;
3072 changed = TRUE; /* We can't rely on the code below since str might be "" */
3075 if (data->tables[source] == NULL)
3076 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
3078 (GDestroyNotify) gdk_color_free);
3080 g_free (data->lastentry[source]);
3081 data->lastentry[source] = g_strdup (str);
3083 changed |= add_colors_to_hash_from_string (data->tables[source], str);
3088 /* Rebuild the merged hash table. */
3089 if (data->color_hash)
3091 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
3092 (GDestroyNotify) gdk_color_free);
3094 g_hash_table_iter_init (&iter, data->color_hash);
3095 while (g_hash_table_iter_next (&iter, &name, &color))
3097 g_hash_table_insert (old_hash, name, color);
3098 g_hash_table_iter_steal (&iter);
3106 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
3108 if (data->tables[i])
3109 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
3115 /* now check if the merged hash has changed */
3117 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
3121 GHashTableIter iter;
3122 gpointer key, value, new_value;
3124 g_hash_table_iter_init (&iter, old_hash);
3125 while (g_hash_table_iter_next (&iter, &key, &value))
3127 new_value = g_hash_table_lookup (data->color_hash, key);
3128 if (!new_value || !gdk_color_equal (value, new_value))
3136 g_hash_table_unref (old_hash);
3145 merge_color_scheme (GtkSettings *settings,
3146 const GValue *value,
3147 GtkSettingsSource source)
3149 ColorSchemeData *data;
3150 const gchar *colors;
3152 g_object_freeze_notify (G_OBJECT (settings));
3154 colors = g_value_get_string (value);
3156 settings_update_color_scheme (settings);
3158 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
3159 "gtk-color-scheme");
3161 if (update_color_hash (data, colors, source))
3162 g_object_notify (G_OBJECT (settings), "color-hash");
3164 g_object_thaw_notify (G_OBJECT (settings));
3168 get_color_hash (GtkSettings *settings)
3170 ColorSchemeData *data;
3172 settings_update_color_scheme (settings);
3174 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
3175 "gtk-color-scheme");
3177 return data->color_hash;
3181 append_color_scheme (gpointer key,
3185 gchar *name = (gchar *)key;
3186 GdkColor *color = (GdkColor *)value;
3187 GString *string = (GString *)data;
3189 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
3190 name, color->red, color->green, color->blue);
3194 get_color_scheme (GtkSettings *settings)
3196 ColorSchemeData *data;
3199 settings_update_color_scheme (settings);
3201 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
3202 "gtk-color-scheme");
3204 string = g_string_new ("");
3206 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
3208 return g_string_free (string, FALSE);
3212 _gtk_settings_get_screen (GtkSettings *settings)
3214 return settings->priv->screen;
3219 gtk_settings_load_from_key_file (GtkSettings *settings,
3221 GtkSettingsSource source)
3232 keyfile = g_key_file_new ();
3234 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
3236 g_warning ("Failed to parse %s: %s", path, error->message);
3238 g_error_free (error);
3243 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3246 g_warning ("Failed to parse %s: %s", path, error->message);
3247 g_error_free (error);
3251 for (i = 0; i < n_keys; i++)
3256 GtkSettingsValue svalue = { NULL, { 0, }, };
3259 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3262 g_warning ("Unknown key %s in %s", key, path);
3266 if (pspec->owner_type != G_OBJECT_TYPE (settings))
3269 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3272 case G_TYPE_BOOLEAN:
3276 g_value_init (&svalue.value, G_TYPE_LONG);
3277 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3279 g_value_set_long (&svalue.value, b_val);
3287 g_value_init (&svalue.value, G_TYPE_LONG);
3288 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3290 g_value_set_long (&svalue.value, i_val);
3298 g_value_init (&svalue.value, G_TYPE_DOUBLE);
3299 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3301 g_value_set_double (&svalue.value, d_val);
3309 g_value_init (&svalue.value, G_TYPE_GSTRING);
3310 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3312 g_value_take_boxed (&svalue.value, g_string_new (s_val));
3319 g_warning ("Error setting %s in %s: %s", key, path, error->message);
3320 g_error_free (error);
3325 if (g_getenv ("GTK_DEBUG"))
3326 svalue.origin = (gchar *)path;
3327 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3328 g_value_unset (&svalue.value);
3334 g_key_file_free (keyfile);