1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
26 #include "gtkmodules.h"
27 #include "gtksettingsprivate.h"
30 #include "gtkwidget.h"
31 #include "gtkprivate.h"
32 #include "gtkcssprovider.h"
33 #include "gtksymboliccolor.h"
34 #include "gtktypebuiltins.h"
35 #include "gtkversion.h"
37 #ifdef GDK_WINDOWING_X11
39 #include <pango/pangofc-fontmap.h>
45 * @Short_description: Sharing settings between applications
48 * GtkSettings provide a mechanism to share global settings between applications.
49 * On the X window system, this sharing is realized by an
50 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
51 * manager that is usually part of the desktop environment, along with utilities
52 * that let the user change these settings. In the absence of an Xsettings manager,
53 * settings can also be specified in RC files.
55 * Applications can override system-wide settings with gtk_settings_set_string_property(),
56 * gtk_settings_set_long_property(), etc. This should be restricted to special
57 * cases though; GtkSettings are not meant as an application configuration
58 * facility. When doing so, you need to be aware that settings that are specific
59 * to individual widgets may not be available before the widget type has been
60 * realized at least once. The following example demonstrates a way to do this:
61 * <informalexample><programlisting>
62 * gtk_init (&argc, &argv);
64 * /* make sure the type is realized */
65 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
67 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
68 * </programlisting></informalexample>
70 * There is one GtkSettings instance per screen. It can be obtained with
71 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
72 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
73 * GtkSettings instance for the default screen.
77 #ifdef GDK_WINDOWING_QUARTZ
78 #define DEFAULT_KEY_THEME "Mac"
80 #define DEFAULT_KEY_THEME NULL
83 #define DEFAULT_TIMEOUT_INITIAL 200
84 #define DEFAULT_TIMEOUT_REPEAT 20
85 #define DEFAULT_TIMEOUT_EXPAND 500
87 typedef struct _GtkSettingsPropertyValue GtkSettingsPropertyValue;
88 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
90 struct _GtkSettingsPrivate
92 GData *queued_settings; /* of type GtkSettingsValue* */
93 GtkSettingsPropertyValue *property_values;
99 GTK_SETTINGS_SOURCE_DEFAULT,
100 GTK_SETTINGS_SOURCE_RC_FILE,
101 GTK_SETTINGS_SOURCE_XSETTING,
102 GTK_SETTINGS_SOURCE_APPLICATION
105 struct _GtkSettingsValuePrivate
107 GtkSettingsValue public;
108 GtkSettingsSource source;
111 struct _GtkSettingsPropertyValue
114 GtkSettingsSource source;
119 PROP_DOUBLE_CLICK_TIME,
120 PROP_DOUBLE_CLICK_DISTANCE,
122 PROP_CURSOR_BLINK_TIME,
123 PROP_CURSOR_BLINK_TIMEOUT,
126 PROP_ICON_THEME_NAME,
127 PROP_FALLBACK_ICON_THEME,
130 PROP_DND_DRAG_THRESHOLD,
134 #ifdef GDK_WINDOWING_X11
140 PROP_CURSOR_THEME_NAME,
141 PROP_CURSOR_THEME_SIZE,
143 PROP_ALTERNATIVE_BUTTON_ORDER,
144 PROP_ALTERNATIVE_SORT_ARROWS,
145 PROP_SHOW_INPUT_METHOD_MENU,
146 PROP_SHOW_UNICODE_MENU,
147 PROP_TIMEOUT_INITIAL,
151 PROP_ENABLE_ANIMATIONS,
152 PROP_TOUCHSCREEN_MODE,
153 PROP_TOOLTIP_TIMEOUT,
154 PROP_TOOLTIP_BROWSE_TIMEOUT,
155 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
156 PROP_KEYNAV_CURSOR_ONLY,
157 PROP_KEYNAV_WRAP_AROUND,
160 PROP_FILE_CHOOSER_BACKEND,
162 PROP_PRINT_PREVIEW_COMMAND,
163 PROP_ENABLE_MNEMONICS,
165 PROP_RECENT_FILES_LIMIT,
167 PROP_RECENT_FILES_MAX_AGE,
168 PROP_FONTCONFIG_TIMESTAMP,
169 PROP_SOUND_THEME_NAME,
170 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
171 PROP_ENABLE_EVENT_SOUNDS,
172 PROP_ENABLE_TOOLTIPS,
174 PROP_TOOLBAR_ICON_SIZE,
176 PROP_APPLICATION_PREFER_DARK_THEME,
178 PROP_ENTRY_SELECT_ON_FOCUS,
179 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
181 PROP_MENU_BAR_POPUP_DELAY,
182 PROP_SCROLLED_WINDOW_PLACEMENT,
183 PROP_CAN_CHANGE_ACCELS,
184 PROP_MENU_POPUP_DELAY,
185 PROP_MENU_POPDOWN_DELAY,
186 PROP_LABEL_SELECT_ON_FOCUS,
188 PROP_IM_PREEDIT_STYLE,
192 /* --- prototypes --- */
193 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
195 static void gtk_settings_finalize (GObject *object);
196 static void gtk_settings_get_property (GObject *object,
200 static void gtk_settings_set_property (GObject *object,
204 static void gtk_settings_notify (GObject *object,
206 static guint settings_install_property_parser (GtkSettingsClass *class,
208 GtkRcPropertyParser parser);
209 static void settings_update_double_click (GtkSettings *settings);
210 static void settings_update_modules (GtkSettings *settings);
212 #ifdef GDK_WINDOWING_X11
213 static void settings_update_cursor_theme (GtkSettings *settings);
214 static void settings_update_resolution (GtkSettings *settings);
215 static void settings_update_font_options (GtkSettings *settings);
216 static gboolean settings_update_fontconfig (GtkSettings *settings);
218 static void settings_update_color_scheme (GtkSettings *settings);
219 static void settings_update_theme (GtkSettings *settings);
221 static void merge_color_scheme (GtkSettings *settings,
223 GtkSettingsSource source);
224 static gchar *get_color_scheme (GtkSettings *settings);
225 static GHashTable *get_color_hash (GtkSettings *settings);
227 /* the default palette for GtkColorSelelection */
228 static const gchar default_color_palette[] =
229 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
230 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
232 /* --- variables --- */
233 static GQuark quark_property_parser = 0;
234 static GSList *object_list = NULL;
235 static guint class_n_properties = 0;
238 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
239 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
240 gtk_settings_provider_iface_init));
242 /* --- functions --- */
244 gtk_settings_init (GtkSettings *settings)
246 GtkSettingsPrivate *priv;
247 GParamSpec **pspecs, **p;
250 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
254 settings->priv = priv;
255 g_datalist_init (&priv->queued_settings);
256 object_list = g_slist_prepend (object_list, settings);
258 /* build up property array for all yet existing properties and queue
259 * notification for them (at least notification for internal properties
260 * will instantly be caught)
262 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
263 for (p = pspecs; *p; p++)
264 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
266 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
268 g_object_freeze_notify (G_OBJECT (settings));
269 for (p = pspecs; *p; p++)
271 GParamSpec *pspec = *p;
273 if (pspec->owner_type != G_OBJECT_TYPE (settings))
275 g_value_init (&priv->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
276 g_param_value_set_default (pspec, &priv->property_values[i].value);
277 g_object_notify (G_OBJECT (settings), pspec->name);
278 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
281 g_object_thaw_notify (G_OBJECT (settings));
286 gtk_settings_class_init (GtkSettingsClass *class)
288 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
291 gobject_class->finalize = gtk_settings_finalize;
292 gobject_class->get_property = gtk_settings_get_property;
293 gobject_class->set_property = gtk_settings_set_property;
294 gobject_class->notify = gtk_settings_notify;
296 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
297 result = settings_install_property_parser (class,
298 g_param_spec_int ("gtk-double-click-time",
299 P_("Double Click Time"),
300 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
302 GTK_PARAM_READWRITE),
304 g_assert (result == PROP_DOUBLE_CLICK_TIME);
305 result = settings_install_property_parser (class,
306 g_param_spec_int ("gtk-double-click-distance",
307 P_("Double Click Distance"),
308 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
310 GTK_PARAM_READWRITE),
312 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
315 * GtkSettings:gtk-cursor-blink:
317 * Whether the cursor should blink.
319 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
320 * which allows more flexible control over cursor blinking.
322 result = settings_install_property_parser (class,
323 g_param_spec_boolean ("gtk-cursor-blink",
325 P_("Whether the cursor should blink"),
327 GTK_PARAM_READWRITE),
329 g_assert (result == PROP_CURSOR_BLINK);
330 result = settings_install_property_parser (class,
331 g_param_spec_int ("gtk-cursor-blink-time",
332 P_("Cursor Blink Time"),
333 P_("Length of the cursor blink cycle, in milliseconds"),
335 GTK_PARAM_READWRITE),
337 g_assert (result == PROP_CURSOR_BLINK_TIME);
340 * GtkSettings:gtk-cursor-blink-timeout:
342 * Time after which the cursor stops blinking, in seconds.
343 * The timer is reset after each user interaction.
345 * Setting this to zero has the same effect as setting
346 * #GtkSettings:gtk-cursor-blink to %FALSE.
350 result = settings_install_property_parser (class,
351 g_param_spec_int ("gtk-cursor-blink-timeout",
352 P_("Cursor Blink Timeout"),
353 P_("Time after which the cursor stops blinking, in seconds"),
354 1, G_MAXINT, G_MAXINT,
355 GTK_PARAM_READWRITE),
357 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
358 result = settings_install_property_parser (class,
359 g_param_spec_boolean ("gtk-split-cursor",
361 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
363 GTK_PARAM_READWRITE),
365 g_assert (result == PROP_SPLIT_CURSOR);
366 result = settings_install_property_parser (class,
367 g_param_spec_string ("gtk-theme-name",
369 P_("Name of theme RC file to load"),
371 GTK_PARAM_READWRITE),
373 g_assert (result == PROP_THEME_NAME);
375 result = settings_install_property_parser (class,
376 g_param_spec_string ("gtk-icon-theme-name",
377 P_("Icon Theme Name"),
378 P_("Name of icon theme to use"),
380 GTK_PARAM_READWRITE),
382 g_assert (result == PROP_ICON_THEME_NAME);
384 result = settings_install_property_parser (class,
385 g_param_spec_string ("gtk-fallback-icon-theme",
386 P_("Fallback Icon Theme Name"),
387 P_("Name of a icon theme to fall back to"),
389 GTK_PARAM_READWRITE),
391 g_assert (result == PROP_FALLBACK_ICON_THEME);
393 result = settings_install_property_parser (class,
394 g_param_spec_string ("gtk-key-theme-name",
395 P_("Key Theme Name"),
396 P_("Name of key theme RC file to load"),
398 GTK_PARAM_READWRITE),
400 g_assert (result == PROP_KEY_THEME_NAME);
402 result = settings_install_property_parser (class,
403 g_param_spec_string ("gtk-menu-bar-accel",
404 P_("Menu bar accelerator"),
405 P_("Keybinding to activate the menu bar"),
407 GTK_PARAM_READWRITE),
409 g_assert (result == PROP_MENU_BAR_ACCEL);
411 result = settings_install_property_parser (class,
412 g_param_spec_int ("gtk-dnd-drag-threshold",
413 P_("Drag threshold"),
414 P_("Number of pixels the cursor can move before dragging"),
416 GTK_PARAM_READWRITE),
418 g_assert (result == PROP_DND_DRAG_THRESHOLD);
420 result = settings_install_property_parser (class,
421 g_param_spec_string ("gtk-font-name",
423 P_("Name of default font to use"),
425 GTK_PARAM_READWRITE),
427 g_assert (result == PROP_FONT_NAME);
430 * GtkSettings:gtk-icon-sizes:
432 * A list of icon sizes. The list is separated by colons, and
435 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
437 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
438 * GTK+ itself use the following named icon sizes: gtk-menu,
439 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
440 * gtk-dialog. Applications can register their own named icon
441 * sizes with gtk_icon_size_register().
443 result = settings_install_property_parser (class,
444 g_param_spec_string ("gtk-icon-sizes",
446 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
448 GTK_PARAM_READWRITE),
450 g_assert (result == PROP_ICON_SIZES);
452 result = settings_install_property_parser (class,
453 g_param_spec_string ("gtk-modules",
455 P_("List of currently active GTK modules"),
457 GTK_PARAM_READWRITE),
459 g_assert (result == PROP_MODULES);
461 #ifdef GDK_WINDOWING_X11
462 result = settings_install_property_parser (class,
463 g_param_spec_int ("gtk-xft-antialias",
465 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
467 GTK_PARAM_READWRITE),
470 g_assert (result == PROP_XFT_ANTIALIAS);
472 result = settings_install_property_parser (class,
473 g_param_spec_int ("gtk-xft-hinting",
475 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
477 GTK_PARAM_READWRITE),
480 g_assert (result == PROP_XFT_HINTING);
482 result = settings_install_property_parser (class,
483 g_param_spec_string ("gtk-xft-hintstyle",
484 P_("Xft Hint Style"),
485 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
487 GTK_PARAM_READWRITE),
490 g_assert (result == PROP_XFT_HINTSTYLE);
492 result = settings_install_property_parser (class,
493 g_param_spec_string ("gtk-xft-rgba",
495 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
497 GTK_PARAM_READWRITE),
500 g_assert (result == PROP_XFT_RGBA);
502 result = settings_install_property_parser (class,
503 g_param_spec_int ("gtk-xft-dpi",
505 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
507 GTK_PARAM_READWRITE),
510 g_assert (result == PROP_XFT_DPI);
512 result = settings_install_property_parser (class,
513 g_param_spec_string ("gtk-cursor-theme-name",
514 P_("Cursor theme name"),
515 P_("Name of the cursor theme to use, or NULL to use the default theme"),
517 GTK_PARAM_READWRITE),
519 g_assert (result == PROP_CURSOR_THEME_NAME);
521 result = settings_install_property_parser (class,
522 g_param_spec_int ("gtk-cursor-theme-size",
523 P_("Cursor theme size"),
524 P_("Size to use for cursors, or 0 to use the default size"),
526 GTK_PARAM_READWRITE),
529 g_assert (result == PROP_CURSOR_THEME_SIZE);
531 #endif /* GDK_WINDOWING_X11 */
532 result = settings_install_property_parser (class,
533 g_param_spec_boolean ("gtk-alternative-button-order",
534 P_("Alternative button order"),
535 P_("Whether buttons in dialogs should use the alternative button order"),
537 GTK_PARAM_READWRITE),
539 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
542 * GtkSettings:gtk-alternative-sort-arrows:
544 * Controls the direction of the sort indicators in sorted list and tree
545 * views. By default an arrow pointing down means the column is sorted
546 * in ascending order. When set to %TRUE, this order will be inverted.
550 result = settings_install_property_parser (class,
551 g_param_spec_boolean ("gtk-alternative-sort-arrows",
552 P_("Alternative sort indicator direction"),
553 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
555 GTK_PARAM_READWRITE),
557 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
559 result = settings_install_property_parser (class,
560 g_param_spec_boolean ("gtk-show-input-method-menu",
561 P_("Show the 'Input Methods' menu"),
562 P_("Whether the context menus of entries and text views should offer to change the input method"),
564 GTK_PARAM_READWRITE),
566 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
568 result = settings_install_property_parser (class,
569 g_param_spec_boolean ("gtk-show-unicode-menu",
570 P_("Show the 'Insert Unicode Control Character' menu"),
571 P_("Whether the context menus of entries and text views should offer to insert control characters"),
573 GTK_PARAM_READWRITE),
575 g_assert (result == PROP_SHOW_UNICODE_MENU);
577 result = settings_install_property_parser (class,
578 g_param_spec_int ("gtk-timeout-initial",
580 P_("Starting value for timeouts, when button is pressed"),
581 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
582 GTK_PARAM_READWRITE),
585 g_assert (result == PROP_TIMEOUT_INITIAL);
587 result = settings_install_property_parser (class,
588 g_param_spec_int ("gtk-timeout-repeat",
589 P_("Repeat timeout"),
590 P_("Repeat value for timeouts, when button is pressed"),
591 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
592 GTK_PARAM_READWRITE),
595 g_assert (result == PROP_TIMEOUT_REPEAT);
597 result = settings_install_property_parser (class,
598 g_param_spec_int ("gtk-timeout-expand",
599 P_("Expand timeout"),
600 P_("Expand value for timeouts, when a widget is expanding a new region"),
601 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
602 GTK_PARAM_READWRITE),
605 g_assert (result == PROP_TIMEOUT_EXPAND);
608 * GtkSettings:gtk-color-scheme:
610 * A palette of named colors for use in themes. The format of the string is
616 * Color names must be acceptable as identifiers in the
617 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
618 * color specifications must be in the format accepted by
621 * Note that due to the way the color tables from different sources are
622 * merged, color specifications will be converted to hexadecimal form
623 * when getting this property.
625 * Starting with GTK+ 2.12, the entries can alternatively be separated
626 * by ';' instead of newlines:
628 * name1: color1; name2: color2; ...
633 result = settings_install_property_parser (class,
634 g_param_spec_string ("gtk-color-scheme",
636 P_("A palette of named colors for use in themes"),
638 GTK_PARAM_READWRITE),
641 g_assert (result == PROP_COLOR_SCHEME);
643 result = settings_install_property_parser (class,
644 g_param_spec_boolean ("gtk-enable-animations",
645 P_("Enable Animations"),
646 P_("Whether to enable toolkit-wide animations."),
648 GTK_PARAM_READWRITE),
651 g_assert (result == PROP_ENABLE_ANIMATIONS);
654 * GtkSettings:gtk-touchscreen-mode:
656 * When %TRUE, there are no motion notify events delivered on this screen,
657 * and widgets can't use the pointer hovering them for any essential
662 result = settings_install_property_parser (class,
663 g_param_spec_boolean ("gtk-touchscreen-mode",
664 P_("Enable Touchscreen Mode"),
665 P_("When TRUE, there are no motion notify events delivered on this screen"),
667 GTK_PARAM_READWRITE),
670 g_assert (result == PROP_TOUCHSCREEN_MODE);
673 * GtkSettings:gtk-tooltip-timeout:
675 * Time, in milliseconds, after which a tooltip could appear if the
676 * cursor is hovering on top of a widget.
680 result = settings_install_property_parser (class,
681 g_param_spec_int ("gtk-tooltip-timeout",
682 P_("Tooltip timeout"),
683 P_("Timeout before tooltip is shown"),
686 GTK_PARAM_READWRITE),
689 g_assert (result == PROP_TOOLTIP_TIMEOUT);
692 * GtkSettings:gtk-tooltip-browse-timeout:
694 * Controls the time after which tooltips will appear when
695 * browse mode is enabled, in milliseconds.
697 * Browse mode is enabled when the mouse pointer moves off an object
698 * where a tooltip was currently being displayed. If the mouse pointer
699 * hits another object before the browse mode timeout expires (see
700 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
701 * amount of milliseconds specified by this setting to popup the tooltip
702 * for the new object.
706 result = settings_install_property_parser (class,
707 g_param_spec_int ("gtk-tooltip-browse-timeout",
708 P_("Tooltip browse timeout"),
709 P_("Timeout before tooltip is shown when browse mode is enabled"),
712 GTK_PARAM_READWRITE),
715 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
718 * GtkSettings:gtk-tooltip-browse-mode-timeout:
720 * Amount of time, in milliseconds, after which the browse mode
723 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
728 result = settings_install_property_parser (class,
729 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
730 P_("Tooltip browse mode timeout"),
731 P_("Timeout after which browse mode is disabled"),
734 GTK_PARAM_READWRITE),
737 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
740 * GtkSettings:gtk-keynav-cursor-only:
742 * When %TRUE, keyboard navigation should be able to reach all widgets
743 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
744 * to be present on the used input device.
748 result = settings_install_property_parser (class,
749 g_param_spec_boolean ("gtk-keynav-cursor-only",
750 P_("Keynav Cursor Only"),
751 P_("When TRUE, there are only cursor keys available to navigate widgets"),
753 GTK_PARAM_READWRITE),
756 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
759 * GtkSettings:gtk-keynav-wrap-around:
761 * When %TRUE, some widgets will wrap around when doing keyboard
762 * navigation, such as menus, menubars and notebooks.
766 result = settings_install_property_parser (class,
767 g_param_spec_boolean ("gtk-keynav-wrap-around",
768 P_("Keynav Wrap Around"),
769 P_("Whether to wrap around when keyboard-navigating widgets"),
771 GTK_PARAM_READWRITE),
774 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
777 * GtkSettings:gtk-error-bell:
779 * When %TRUE, keyboard navigation and other input-related errors
780 * will cause a beep. Since the error bell is implemented using
781 * gdk_window_beep(), the windowing system may offer ways to
782 * configure the error bell in many ways, such as flashing the
783 * window or similar visual effects.
787 result = settings_install_property_parser (class,
788 g_param_spec_boolean ("gtk-error-bell",
790 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
792 GTK_PARAM_READWRITE),
795 g_assert (result == PROP_ERROR_BELL);
798 * GtkSettings:color-hash:
800 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
801 * setting, mapping color names to #GdkColor<!-- -->s.
805 result = settings_install_property_parser (class,
806 g_param_spec_boxed ("color-hash",
808 P_("A hash table representation of the color scheme."),
812 g_assert (result == PROP_COLOR_HASH);
814 result = settings_install_property_parser (class,
815 g_param_spec_string ("gtk-file-chooser-backend",
816 P_("Default file chooser backend"),
817 P_("Name of the GtkFileChooser backend to use by default"),
819 GTK_PARAM_READWRITE),
821 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
824 * GtkSettings:gtk-print-backends:
826 * A comma-separated list of print backends to use in the print
827 * dialog. Available print backends depend on the GTK+ installation,
828 * and may include "file", "cups", "lpr" or "papi".
832 result = settings_install_property_parser (class,
833 g_param_spec_string ("gtk-print-backends",
834 P_("Default print backend"),
835 P_("List of the GtkPrintBackend backends to use by default"),
837 GTK_PARAM_READWRITE),
839 g_assert (result == PROP_PRINT_BACKENDS);
842 * GtkSettings:gtk-print-preview-command:
844 * A command to run for displaying the print preview. The command
845 * should contain a %f placeholder, which will get replaced by
846 * the path to the pdf file. The command may also contain a %s
847 * placeholder, which will get replaced by the path to a file
848 * containing the print settings in the format produced by
849 * gtk_print_settings_to_file().
851 * The preview application is responsible for removing the pdf file
852 * and the print settings file when it is done.
856 result = settings_install_property_parser (class,
857 g_param_spec_string ("gtk-print-preview-command",
858 P_("Default command to run when displaying a print preview"),
859 P_("Command to run when displaying a print preview"),
860 GTK_PRINT_PREVIEW_COMMAND,
861 GTK_PARAM_READWRITE),
863 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
866 * GtkSettings:gtk-enable-mnemonics:
868 * Whether labels and menu items should have visible mnemonics which
873 result = settings_install_property_parser (class,
874 g_param_spec_boolean ("gtk-enable-mnemonics",
875 P_("Enable Mnemonics"),
876 P_("Whether labels should have mnemonics"),
878 GTK_PARAM_READWRITE),
880 g_assert (result == PROP_ENABLE_MNEMONICS);
883 * GtkSettings:gtk-enable-accels:
885 * Whether menu items should have visible accelerators which can be
890 result = settings_install_property_parser (class,
891 g_param_spec_boolean ("gtk-enable-accels",
892 P_("Enable Accelerators"),
893 P_("Whether menu items should have accelerators"),
895 GTK_PARAM_READWRITE),
897 g_assert (result == PROP_ENABLE_ACCELS);
900 * GtkSettings:gtk-recent-files-limit:
902 * The number of recently used files that should be displayed by default by
903 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
904 * -1 means every recently used file stored.
908 result = settings_install_property_parser (class,
909 g_param_spec_int ("gtk-recent-files-limit",
910 P_("Recent Files Limit"),
911 P_("Number of recently used files"),
914 GTK_PARAM_READWRITE),
916 g_assert (result == PROP_RECENT_FILES_LIMIT);
919 * GtkSettings:gtk-im-module:
921 * Which IM (input method) module should be used by default. This is the
922 * input method that will be used if the user has not explicitly chosen
923 * another input method from the IM context menu.
925 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
927 result = settings_install_property_parser (class,
928 g_param_spec_string ("gtk-im-module",
929 P_("Default IM module"),
930 P_("Which IM module should be used by default"),
932 GTK_PARAM_READWRITE),
934 g_assert (result == PROP_IM_MODULE);
937 * GtkSettings:gtk-recent-files-max-age:
939 * The maximum age, in days, of the items inside the recently used
940 * resources list. Items older than this setting will be excised
941 * from the list. If set to 0, the list will always be empty; if
942 * set to -1, no item will be removed.
946 result = settings_install_property_parser (class,
947 g_param_spec_int ("gtk-recent-files-max-age",
948 P_("Recent Files Max Age"),
949 P_("Maximum age of recently used files, in days"),
952 GTK_PARAM_READWRITE),
954 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
956 result = settings_install_property_parser (class,
957 g_param_spec_uint ("gtk-fontconfig-timestamp",
958 P_("Fontconfig configuration timestamp"),
959 P_("Timestamp of current fontconfig configuration"),
961 GTK_PARAM_READWRITE),
964 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
967 * GtkSettings:gtk-sound-theme-name:
969 * The XDG sound theme to use for event sounds.
971 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
972 * for more information on event sounds and sound themes.
974 * GTK+ itself does not support event sounds, you have to use a loadable
975 * module like the one that comes with libcanberra.
979 result = settings_install_property_parser (class,
980 g_param_spec_string ("gtk-sound-theme-name",
981 P_("Sound Theme Name"),
982 P_("XDG sound theme name"),
984 GTK_PARAM_READWRITE),
986 g_assert (result == PROP_SOUND_THEME_NAME);
989 * GtkSettings:gtk-enable-input-feedback-sounds:
991 * Whether to play event sounds as feedback to user input.
993 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
994 * for more information on event sounds and sound themes.
996 * GTK+ itself does not support event sounds, you have to use a loadable
997 * module like the one that comes with libcanberra.
1001 result = settings_install_property_parser (class,
1002 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1003 /* Translators: this means sounds that are played as feedback to user input */
1004 P_("Audible Input Feedback"),
1005 P_("Whether to play event sounds as feedback to user input"),
1007 GTK_PARAM_READWRITE),
1009 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1012 * GtkSettings:gtk-enable-event-sounds:
1014 * Whether to play any event sounds at all.
1016 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1017 * for more information on event sounds and sound themes.
1019 * GTK+ itself does not support event sounds, you have to use a loadable
1020 * module like the one that comes with libcanberra.
1024 result = settings_install_property_parser (class,
1025 g_param_spec_boolean ("gtk-enable-event-sounds",
1026 P_("Enable Event Sounds"),
1027 P_("Whether to play any event sounds at all"),
1029 GTK_PARAM_READWRITE),
1031 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1034 * GtkSettings:gtk-enable-tooltips:
1036 * Whether tooltips should be shown on widgets.
1040 result = settings_install_property_parser (class,
1041 g_param_spec_boolean ("gtk-enable-tooltips",
1042 P_("Enable Tooltips"),
1043 P_("Whether tooltips should be shown on widgets"),
1045 GTK_PARAM_READWRITE),
1047 g_assert (result == PROP_ENABLE_TOOLTIPS);
1050 * GtkSettings:gtk-toolbar-style:
1052 * The size of icons in default toolbars.
1054 result = settings_install_property_parser (class,
1055 g_param_spec_enum ("gtk-toolbar-style",
1056 P_("Toolbar style"),
1057 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1058 GTK_TYPE_TOOLBAR_STYLE,
1060 GTK_PARAM_READWRITE),
1061 gtk_rc_property_parse_enum);
1062 g_assert (result == PROP_TOOLBAR_STYLE);
1065 * GtkSettings:gtk-toolbar-icon-size:
1067 * The size of icons in default toolbars.
1069 result = settings_install_property_parser (class,
1070 g_param_spec_enum ("gtk-toolbar-icon-size",
1071 P_("Toolbar Icon Size"),
1072 P_("The size of icons in default toolbars."),
1074 GTK_ICON_SIZE_LARGE_TOOLBAR,
1075 GTK_PARAM_READWRITE),
1076 gtk_rc_property_parse_enum);
1077 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1080 * GtkSettings:gtk-auto-mnemonics:
1082 * Whether mnemonics should be automatically shown and hidden when the user
1083 * presses the mnemonic activator.
1087 result = settings_install_property_parser (class,
1088 g_param_spec_boolean ("gtk-auto-mnemonics",
1089 P_("Auto Mnemonics"),
1090 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1092 GTK_PARAM_READWRITE),
1094 g_assert (result == PROP_AUTO_MNEMONICS);
1097 * GtkSettings:gtk-application-prefer-dark-theme:
1099 * Whether the application prefers to use a dark theme. If a GTK+ theme
1100 * includes a dark variant, it will be used instead of the configured
1103 * Some applications benefit from minimizing the amount of light pollution that
1104 * interferes with the content. Good candidates for dark themes are photo and
1105 * video editors that make the actual content get all the attention and minimize
1106 * the distraction of the chrome.
1108 * Dark themes should not be used for documents, where large spaces are white/light
1109 * and the dark chrome creates too much contrast (web browser, text editor...).
1113 result = settings_install_property_parser (class,
1114 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1115 P_("Application prefers a dark theme"),
1116 P_("Whether the application prefers to have a dark theme."),
1118 GTK_PARAM_READWRITE),
1120 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1123 * GtkSettings::gtk-button-images:
1125 * Whether images should be shown on buttons
1129 result = settings_install_property_parser (class,
1130 g_param_spec_boolean ("gtk-button-images",
1131 P_("Show button images"),
1132 P_("Whether images should be shown on buttons"),
1134 GTK_PARAM_READWRITE),
1136 g_assert (result == PROP_BUTTON_IMAGES);
1138 result = settings_install_property_parser (class,
1139 g_param_spec_boolean ("gtk-entry-select-on-focus",
1140 P_("Select on focus"),
1141 P_("Whether to select the contents of an entry when it is focused"),
1143 GTK_PARAM_READWRITE),
1145 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1148 * GtkSettings:gtk-entry-password-hint-timeout:
1150 * How long to show the last input character in hidden
1151 * entries. This value is in milliseconds. 0 disables showing the
1152 * last char. 600 is a good value for enabling it.
1156 result = settings_install_property_parser (class,
1157 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1158 P_("Password Hint Timeout"),
1159 P_("How long to show the last input character in hidden entries"),
1162 GTK_PARAM_READWRITE),
1164 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1166 result = settings_install_property_parser (class,
1167 g_param_spec_boolean ("gtk-menu-images",
1168 P_("Show menu images"),
1169 P_("Whether images should be shown in menus"),
1171 GTK_PARAM_READWRITE),
1173 g_assert (result == PROP_MENU_IMAGES);
1175 result = settings_install_property_parser (class,
1176 g_param_spec_int ("gtk-menu-bar-popup-delay",
1177 P_("Delay before drop down menus appear"),
1178 P_("Delay before the submenus of a menu bar appear"),
1181 GTK_PARAM_READWRITE),
1183 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1186 * GtkSettings:gtk-scrolled-window-placement:
1188 * Where the contents of scrolled windows are located with respect to the
1189 * scrollbars, if not overridden by the scrolled window's own placement.
1193 result = settings_install_property_parser (class,
1194 g_param_spec_enum ("gtk-scrolled-window-placement",
1195 P_("Scrolled Window Placement"),
1196 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1197 GTK_TYPE_CORNER_TYPE,
1198 GTK_CORNER_TOP_LEFT,
1199 GTK_PARAM_READWRITE),
1200 gtk_rc_property_parse_enum);
1201 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1203 result = settings_install_property_parser (class,
1204 g_param_spec_boolean ("gtk-can-change-accels",
1205 P_("Can change accelerators"),
1206 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1208 GTK_PARAM_READWRITE),
1210 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1212 result = settings_install_property_parser (class,
1213 g_param_spec_int ("gtk-menu-popup-delay",
1214 P_("Delay before submenus appear"),
1215 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1218 GTK_PARAM_READWRITE),
1220 g_assert (result == PROP_MENU_POPUP_DELAY);
1222 result = settings_install_property_parser (class,
1223 g_param_spec_int ("gtk-menu-popdown-delay",
1224 P_("Delay before hiding a submenu"),
1225 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1228 GTK_PARAM_READWRITE),
1230 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1232 result = settings_install_property_parser (class,
1233 g_param_spec_boolean ("gtk-label-select-on-focus",
1234 P_("Select on focus"),
1235 P_("Whether to select the contents of a selectable label when it is focused"),
1237 GTK_PARAM_READWRITE),
1239 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1241 result = settings_install_property_parser (class,
1242 g_param_spec_string ("gtk-color-palette",
1243 P_("Custom palette"),
1244 P_("Palette to use in the color selector"),
1245 default_color_palette,
1246 GTK_PARAM_READWRITE),
1248 g_assert (result == PROP_COLOR_PALETTE);
1250 result = settings_install_property_parser (class,
1251 g_param_spec_enum ("gtk-im-preedit-style",
1252 P_("IM Preedit style"),
1253 P_("How to draw the input method preedit string"),
1254 GTK_TYPE_IM_PREEDIT_STYLE,
1255 GTK_IM_PREEDIT_CALLBACK,
1256 GTK_PARAM_READWRITE),
1257 gtk_rc_property_parse_enum);
1258 g_assert (result == PROP_IM_PREEDIT_STYLE);
1260 result = settings_install_property_parser (class,
1261 g_param_spec_enum ("gtk-im-status-style",
1262 P_("IM Status style"),
1263 P_("How to draw the input method statusbar"),
1264 GTK_TYPE_IM_STATUS_STYLE,
1265 GTK_IM_STATUS_CALLBACK,
1266 GTK_PARAM_READWRITE),
1267 gtk_rc_property_parse_enum);
1268 g_assert (result == PROP_IM_STATUS_STYLE);
1270 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1273 static GtkStyleProperties *
1274 gtk_settings_get_style (GtkStyleProvider *provider,
1275 GtkWidgetPath *path)
1277 PangoFontDescription *font_desc;
1278 gchar *font_name, *color_scheme;
1279 GtkSettings *settings;
1280 GtkStyleProperties *props;
1284 settings = GTK_SETTINGS (provider);
1285 props = gtk_style_properties_new ();
1287 g_object_get (settings,
1288 "gtk-font-name", &font_name,
1289 "gtk-color-scheme", &color_scheme,
1292 colors = g_strsplit_set (color_scheme, "\n;", -1);
1294 for (i = 0; colors[i]; i++)
1296 GtkSymbolicColor *color;
1304 pos = strchr (colors[i], ':');
1309 /* Set NUL after color name */
1313 /* Find start of color string */
1317 if (!*pos || !gdk_rgba_parse (&col, pos))
1320 color = gtk_symbolic_color_new_literal (&col);
1321 gtk_style_properties_map_color (props, name, color);
1322 gtk_symbolic_color_unref (color);
1325 font_desc = pango_font_description_from_string (font_name);
1327 gtk_style_properties_set (props, 0,
1331 pango_font_description_free (font_desc);
1332 g_strfreev (colors);
1333 g_free (color_scheme);
1340 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1342 iface->get_style = gtk_settings_get_style;
1346 gtk_settings_finalize (GObject *object)
1348 GtkSettings *settings = GTK_SETTINGS (object);
1349 GtkSettingsPrivate *priv = settings->priv;
1352 object_list = g_slist_remove (object_list, settings);
1354 for (i = 0; i < class_n_properties; i++)
1355 g_value_unset (&priv->property_values[i].value);
1356 g_free (priv->property_values);
1358 g_datalist_clear (&priv->queued_settings);
1360 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1364 settings_init_style (GtkSettings *settings)
1366 static GtkCssProvider *css_provider = NULL;
1368 GdkScreen *screen = settings->priv->screen;
1369 GtkCssProvider *default_provider;
1371 /* Add provider for user file */
1372 if (G_UNLIKELY (!css_provider))
1376 css_provider = gtk_css_provider_new ();
1377 css_path = g_build_filename (g_get_user_config_dir (),
1382 if (g_file_test (css_path,
1383 G_FILE_TEST_IS_REGULAR))
1384 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1389 gtk_style_context_add_provider_for_screen (screen,
1390 GTK_STYLE_PROVIDER (css_provider),
1391 GTK_STYLE_PROVIDER_PRIORITY_USER);
1393 default_provider = gtk_css_provider_get_default ();
1394 gtk_style_context_add_provider_for_screen (screen,
1395 GTK_STYLE_PROVIDER (default_provider),
1396 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1398 gtk_style_context_add_provider_for_screen (screen,
1399 GTK_STYLE_PROVIDER (settings),
1400 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1402 settings_update_theme (settings);
1406 * gtk_settings_get_for_screen:
1407 * @screen: a #GdkScreen.
1409 * Gets the #GtkSettings object for @screen, creating it if necessary.
1411 * Return value: (transfer none): a #GtkSettings object.
1416 gtk_settings_get_for_screen (GdkScreen *screen)
1418 GtkSettings *settings;
1420 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1422 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1425 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1426 settings->priv->screen = screen;
1427 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1428 settings, g_object_unref);
1430 settings_init_style (settings);
1431 settings_update_double_click (settings);
1432 #ifdef GDK_WINDOWING_X11
1433 settings_update_cursor_theme (settings);
1434 settings_update_resolution (settings);
1435 settings_update_font_options (settings);
1437 settings_update_color_scheme (settings);
1444 * gtk_settings_get_default:
1446 * Gets the #GtkSettings object for the default GDK screen, creating
1447 * it if necessary. See gtk_settings_get_for_screen().
1449 * Return value: (transfer none): a #GtkSettings object. If there is no default
1450 * screen, then returns %NULL.
1453 gtk_settings_get_default (void)
1455 GdkScreen *screen = gdk_screen_get_default ();
1458 return gtk_settings_get_for_screen (screen);
1464 gtk_settings_set_property (GObject *object,
1466 const GValue *value,
1469 GtkSettings *settings = GTK_SETTINGS (object);
1470 GtkSettingsPrivate *priv = settings->priv;
1472 g_value_copy (value, &priv->property_values[property_id - 1].value);
1473 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1475 if (pspec->param_id == PROP_COLOR_SCHEME)
1476 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1480 gtk_settings_get_property (GObject *object,
1485 GtkSettings *settings = GTK_SETTINGS (object);
1486 GtkSettingsPrivate *priv = settings->priv;
1487 GType value_type = G_VALUE_TYPE (value);
1488 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1490 /* handle internal properties */
1491 switch (property_id)
1493 case PROP_COLOR_HASH:
1494 g_value_set_boxed (value, get_color_hash (settings));
1496 case PROP_COLOR_SCHEME:
1497 g_value_take_string (value, get_color_scheme (settings));
1502 /* For enums and strings, we need to get the value as a string,
1503 * not as an int, since we support using names/nicks as the setting
1506 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1507 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1508 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1509 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1511 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1512 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1513 g_value_copy (&priv->property_values[property_id - 1].value, value);
1515 g_param_value_validate (pspec, value);
1519 GValue val = { 0, };
1521 /* Try to get xsetting as a string and parse it. */
1523 g_value_init (&val, G_TYPE_STRING);
1525 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1526 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1528 g_value_copy (&priv->property_values[property_id - 1].value, value);
1532 GValue tmp_value = { 0, };
1533 GValue gstring_value = { 0, };
1534 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1536 g_value_init (&gstring_value, G_TYPE_GSTRING);
1537 g_value_take_boxed (&gstring_value,
1538 g_string_new (g_value_get_string (&val)));
1540 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1542 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1545 g_value_copy (&tmp_value, value);
1546 g_param_value_validate (pspec, value);
1550 g_value_copy (&priv->property_values[property_id - 1].value, value);
1553 g_value_unset (&gstring_value);
1554 g_value_unset (&tmp_value);
1557 g_value_unset (&val);
1562 gtk_settings_notify (GObject *object,
1565 GtkSettings *settings = GTK_SETTINGS (object);
1566 GtkSettingsPrivate *priv = settings->priv;
1567 guint property_id = pspec->param_id;
1569 if (priv->screen == NULL) /* initialization */
1572 switch (property_id)
1575 settings_update_modules (settings);
1577 case PROP_DOUBLE_CLICK_TIME:
1578 case PROP_DOUBLE_CLICK_DISTANCE:
1579 settings_update_double_click (settings);
1581 case PROP_COLOR_SCHEME:
1582 settings_update_color_scheme (settings);
1583 gtk_style_context_reset_widgets (priv->screen);
1585 case PROP_THEME_NAME:
1586 settings_update_theme (settings);
1588 #ifdef GDK_WINDOWING_X11
1590 settings_update_resolution (settings);
1591 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1592 * widgets with gtk_widget_style_set(), and also causes more
1593 * recomputation than necessary.
1595 gtk_style_context_reset_widgets (priv->screen);
1597 case PROP_XFT_ANTIALIAS:
1598 case PROP_XFT_HINTING:
1599 case PROP_XFT_HINTSTYLE:
1601 settings_update_font_options (settings);
1602 gtk_style_context_reset_widgets (priv->screen);
1604 case PROP_FONTCONFIG_TIMESTAMP:
1605 if (settings_update_fontconfig (settings))
1606 gtk_style_context_reset_widgets (priv->screen);
1608 case PROP_CURSOR_THEME_NAME:
1609 case PROP_CURSOR_THEME_SIZE:
1610 settings_update_cursor_theme (settings);
1612 #endif /* GDK_WINDOWING_X11 */
1617 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1618 const GValue *src_value,
1622 gboolean success = FALSE;
1624 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1629 gboolean free_gstring = TRUE;
1631 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1633 gstring = g_value_get_boxed (src_value);
1634 free_gstring = FALSE;
1636 else if (G_VALUE_HOLDS_LONG (src_value))
1638 gstring = g_string_new (NULL);
1639 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1641 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1643 gstring = g_string_new (NULL);
1644 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1646 else if (G_VALUE_HOLDS_STRING (src_value))
1648 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1650 gstring = g_string_new ("\"");
1651 g_string_append (gstring, tstr);
1652 g_string_append_c (gstring, '\"');
1657 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1658 gstring = NULL; /* silence compiler */
1661 success = (parser (pspec, gstring, dest_value) &&
1662 !g_param_value_validate (pspec, dest_value));
1665 g_string_free (gstring, TRUE);
1667 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1669 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1671 GString *gstring = g_value_get_boxed (src_value);
1673 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1674 success = !g_param_value_validate (pspec, dest_value);
1677 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1678 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1684 apply_queued_setting (GtkSettings *settings,
1686 GtkSettingsValuePrivate *qvalue)
1688 GtkSettingsPrivate *priv = settings->priv;
1689 GValue tmp_value = { 0, };
1690 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1692 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1693 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1696 if (pspec->param_id == PROP_COLOR_SCHEME)
1697 merge_color_scheme (settings, &tmp_value, qvalue->source);
1699 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1701 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1702 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1703 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1709 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1711 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1712 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1714 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1716 G_VALUE_TYPE_NAME (&tmp_value));
1719 g_value_unset (&tmp_value);
1723 settings_install_property_parser (GtkSettingsClass *class,
1725 GtkRcPropertyParser parser)
1727 GSList *node, *next;
1729 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1731 case G_TYPE_BOOLEAN:
1744 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1752 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1753 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1757 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1759 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1764 for (node = object_list; node; node = node->next)
1765 g_object_freeze_notify (node->data);
1767 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1768 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1770 for (node = object_list; node; node = node->next)
1772 GtkSettings *settings = node->data;
1773 GtkSettingsPrivate *priv = settings->priv;
1774 GtkSettingsValuePrivate *qvalue;
1776 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1777 priv->property_values[class_n_properties - 1].value.g_type = 0;
1778 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1779 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1780 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1781 g_object_notify (G_OBJECT (settings), pspec->name);
1783 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1785 apply_queued_setting (settings, pspec, qvalue);
1788 for (node = object_list; node; node = next)
1791 g_object_thaw_notify (node->data);
1794 return class_n_properties;
1798 _gtk_rc_property_parser_from_type (GType type)
1800 if (type == GDK_TYPE_COLOR)
1801 return gtk_rc_property_parse_color;
1802 else if (type == GTK_TYPE_REQUISITION)
1803 return gtk_rc_property_parse_requisition;
1804 else if (type == GTK_TYPE_BORDER)
1805 return gtk_rc_property_parse_border;
1806 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1807 return gtk_rc_property_parse_enum;
1808 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1809 return gtk_rc_property_parse_flags;
1815 gtk_settings_install_property (GParamSpec *pspec)
1817 static GtkSettingsClass *klass = NULL;
1819 GtkRcPropertyParser parser;
1821 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1824 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1826 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1828 settings_install_property_parser (klass, pspec, parser);
1832 * gtk_settings_install_property_parser:
1834 * @parser: (scope call):
1837 gtk_settings_install_property_parser (GParamSpec *pspec,
1838 GtkRcPropertyParser parser)
1840 static GtkSettingsClass *klass = NULL;
1842 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1843 g_return_if_fail (parser != NULL);
1846 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1848 settings_install_property_parser (klass, pspec, parser);
1852 free_value (gpointer data)
1854 GtkSettingsValuePrivate *qvalue = data;
1856 g_value_unset (&qvalue->public.value);
1857 g_free (qvalue->public.origin);
1858 g_slice_free (GtkSettingsValuePrivate, qvalue);
1862 gtk_settings_set_property_value_internal (GtkSettings *settings,
1863 const gchar *prop_name,
1864 const GtkSettingsValue *new_value,
1865 GtkSettingsSource source)
1867 GtkSettingsPrivate *priv = settings->priv;
1868 GtkSettingsValuePrivate *qvalue;
1873 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1874 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1875 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1876 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1878 g_warning (G_STRLOC ": value type invalid");
1882 name = g_strdup (prop_name);
1883 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1884 name_quark = g_quark_from_string (name);
1887 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
1890 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1891 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
1895 g_free (qvalue->public.origin);
1896 g_value_unset (&qvalue->public.value);
1898 qvalue->public.origin = g_strdup (new_value->origin);
1899 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1900 g_value_copy (&new_value->value, &qvalue->public.value);
1901 qvalue->source = source;
1902 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1904 apply_queued_setting (settings, pspec, qvalue);
1908 gtk_settings_set_property_value (GtkSettings *settings,
1909 const gchar *prop_name,
1910 const GtkSettingsValue *new_value)
1912 g_return_if_fail (GTK_SETTINGS (settings));
1913 g_return_if_fail (prop_name != NULL);
1914 g_return_if_fail (new_value != NULL);
1916 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1917 GTK_SETTINGS_SOURCE_APPLICATION);
1921 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1922 const gchar *prop_name,
1923 const GtkSettingsValue *new_value)
1925 g_return_if_fail (GTK_SETTINGS (settings));
1926 g_return_if_fail (prop_name != NULL);
1927 g_return_if_fail (new_value != NULL);
1929 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1930 GTK_SETTINGS_SOURCE_RC_FILE);
1934 gtk_settings_set_string_property (GtkSettings *settings,
1936 const gchar *v_string,
1937 const gchar *origin)
1939 GtkSettingsValue svalue = { NULL, { 0, }, };
1941 g_return_if_fail (GTK_SETTINGS (settings));
1942 g_return_if_fail (name != NULL);
1943 g_return_if_fail (v_string != NULL);
1945 svalue.origin = (gchar*) origin;
1946 g_value_init (&svalue.value, G_TYPE_STRING);
1947 g_value_set_static_string (&svalue.value, v_string);
1948 gtk_settings_set_property_value (settings, name, &svalue);
1949 g_value_unset (&svalue.value);
1953 gtk_settings_set_long_property (GtkSettings *settings,
1956 const gchar *origin)
1958 GtkSettingsValue svalue = { NULL, { 0, }, };
1960 g_return_if_fail (GTK_SETTINGS (settings));
1961 g_return_if_fail (name != NULL);
1963 svalue.origin = (gchar*) origin;
1964 g_value_init (&svalue.value, G_TYPE_LONG);
1965 g_value_set_long (&svalue.value, v_long);
1966 gtk_settings_set_property_value (settings, name, &svalue);
1967 g_value_unset (&svalue.value);
1971 gtk_settings_set_double_property (GtkSettings *settings,
1974 const gchar *origin)
1976 GtkSettingsValue svalue = { NULL, { 0, }, };
1978 g_return_if_fail (GTK_SETTINGS (settings));
1979 g_return_if_fail (name != NULL);
1981 svalue.origin = (gchar*) origin;
1982 g_value_init (&svalue.value, G_TYPE_DOUBLE);
1983 g_value_set_double (&svalue.value, v_double);
1984 gtk_settings_set_property_value (settings, name, &svalue);
1985 g_value_unset (&svalue.value);
1989 * gtk_rc_property_parse_color:
1990 * @pspec: a #GParamSpec
1991 * @gstring: the #GString to be parsed
1992 * @property_value: a #GValue which must hold #GdkColor values.
1994 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1995 * or gtk_widget_class_install_style_property_parser() which parses a
1996 * color given either by its name or in the form
1997 * <literal>{ red, green, blue }</literal> where %red, %green and
1998 * %blue are integers between 0 and 65535 or floating-point numbers
2001 * Return value: %TRUE if @gstring could be parsed and @property_value
2002 * has been set to the resulting #GdkColor.
2005 gtk_rc_property_parse_color (const GParamSpec *pspec,
2006 const GString *gstring,
2007 GValue *property_value)
2009 GdkColor color = { 0, 0, 0, 0, };
2013 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2014 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2016 scanner = gtk_rc_scanner_new ();
2017 g_scanner_input_text (scanner, gstring->str, gstring->len);
2018 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2019 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2021 g_value_set_boxed (property_value, &color);
2026 g_scanner_destroy (scanner);
2032 * gtk_rc_property_parse_enum:
2033 * @pspec: a #GParamSpec
2034 * @gstring: the #GString to be parsed
2035 * @property_value: a #GValue which must hold enum values.
2037 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2038 * or gtk_widget_class_install_style_property_parser() which parses a single
2039 * enumeration value.
2041 * The enumeration value can be specified by its name, its nickname or
2042 * its numeric value. For consistency with flags parsing, the value
2043 * may be surrounded by parentheses.
2045 * Return value: %TRUE if @gstring could be parsed and @property_value
2046 * has been set to the resulting #GEnumValue.
2049 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2050 const GString *gstring,
2051 GValue *property_value)
2053 gboolean need_closing_brace = FALSE, success = FALSE;
2055 GEnumValue *enum_value = NULL;
2057 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2058 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2060 scanner = gtk_rc_scanner_new ();
2061 g_scanner_input_text (scanner, gstring->str, gstring->len);
2063 /* we just want to parse _one_ value, but for consistency with flags parsing
2064 * we support optional parenthesis
2066 g_scanner_get_next_token (scanner);
2067 if (scanner->token == '(')
2069 need_closing_brace = TRUE;
2070 g_scanner_get_next_token (scanner);
2072 if (scanner->token == G_TOKEN_IDENTIFIER)
2074 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2076 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2078 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2081 g_value_set_enum (property_value, enum_value->value);
2085 else if (scanner->token == G_TOKEN_INT)
2087 g_value_set_enum (property_value, scanner->value.v_int);
2090 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2092 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2095 g_scanner_destroy (scanner);
2101 parse_flags_value (GScanner *scanner,
2105 g_scanner_get_next_token (scanner);
2106 if (scanner->token == G_TOKEN_IDENTIFIER)
2108 GFlagsValue *flags_value;
2110 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2112 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2115 *number |= flags_value->value;
2116 return G_TOKEN_NONE;
2119 else if (scanner->token == G_TOKEN_INT)
2121 *number |= scanner->value.v_int;
2122 return G_TOKEN_NONE;
2124 return G_TOKEN_IDENTIFIER;
2128 * gtk_rc_property_parse_flags:
2129 * @pspec: a #GParamSpec
2130 * @gstring: the #GString to be parsed
2131 * @property_value: a #GValue which must hold flags values.
2133 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2134 * or gtk_widget_class_install_style_property_parser() which parses flags.
2136 * Flags can be specified by their name, their nickname or
2137 * numerically. Multiple flags can be specified in the form
2138 * <literal>"( flag1 | flag2 | ... )"</literal>.
2140 * Return value: %TRUE if @gstring could be parsed and @property_value
2141 * has been set to the resulting flags value.
2144 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2145 const GString *gstring,
2146 GValue *property_value)
2149 gboolean success = FALSE;
2152 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2153 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2155 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2156 scanner = gtk_rc_scanner_new ();
2157 g_scanner_input_text (scanner, gstring->str, gstring->len);
2159 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2160 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2161 scanner->next_token == G_TOKEN_INT)
2163 guint token, flags_value = 0;
2165 token = parse_flags_value (scanner, class, &flags_value);
2167 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2170 g_value_set_flags (property_value, flags_value);
2174 else if (g_scanner_get_next_token (scanner) == '(')
2176 guint token, flags_value = 0;
2178 /* parse first value */
2179 token = parse_flags_value (scanner, class, &flags_value);
2181 /* parse nth values, preceeded by '|' */
2182 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2183 token = parse_flags_value (scanner, class, &flags_value);
2185 /* done, last token must have closed expression */
2186 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2187 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2189 g_value_set_flags (property_value, flags_value);
2193 g_scanner_destroy (scanner);
2199 get_braced_int (GScanner *scanner,
2206 g_scanner_get_next_token (scanner);
2207 if (scanner->token != '{')
2211 g_scanner_get_next_token (scanner);
2212 if (scanner->token != G_TOKEN_INT)
2215 *value = scanner->value.v_int;
2219 g_scanner_get_next_token (scanner);
2220 if (scanner->token != '}')
2225 g_scanner_get_next_token (scanner);
2226 if (scanner->token != ',')
2234 * gtk_rc_property_parse_requisition:
2235 * @pspec: a #GParamSpec
2236 * @gstring: the #GString to be parsed
2237 * @property_value: a #GValue which must hold boxed values.
2239 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2240 * or gtk_widget_class_install_style_property_parser() which parses a
2241 * requisition in the form
2242 * <literal>"{ width, height }"</literal> for integers %width and %height.
2244 * Return value: %TRUE if @gstring could be parsed and @property_value
2245 * has been set to the resulting #GtkRequisition.
2248 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2249 const GString *gstring,
2250 GValue *property_value)
2252 GtkRequisition requisition;
2254 gboolean success = FALSE;
2256 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2257 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2259 scanner = gtk_rc_scanner_new ();
2260 g_scanner_input_text (scanner, gstring->str, gstring->len);
2262 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2263 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2265 g_value_set_boxed (property_value, &requisition);
2269 g_scanner_destroy (scanner);
2275 * gtk_rc_property_parse_border:
2276 * @pspec: a #GParamSpec
2277 * @gstring: the #GString to be parsed
2278 * @property_value: a #GValue which must hold boxed values.
2280 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2281 * or gtk_widget_class_install_style_property_parser() which parses
2282 * borders in the form
2283 * <literal>"{ left, right, top, bottom }"</literal> for integers
2284 * %left, %right, %top and %bottom.
2286 * Return value: %TRUE if @gstring could be parsed and @property_value
2287 * has been set to the resulting #GtkBorder.
2290 gtk_rc_property_parse_border (const GParamSpec *pspec,
2291 const GString *gstring,
2292 GValue *property_value)
2296 gboolean success = FALSE;
2297 int left, right, top, bottom;
2299 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2300 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2302 scanner = gtk_rc_scanner_new ();
2303 g_scanner_input_text (scanner, gstring->str, gstring->len);
2305 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2306 get_braced_int (scanner, FALSE, FALSE, &right) &&
2307 get_braced_int (scanner, FALSE, FALSE, &top) &&
2308 get_braced_int (scanner, FALSE, TRUE, &bottom))
2311 border.right = right;
2313 border.bottom = bottom;
2314 g_value_set_boxed (property_value, &border);
2318 g_scanner_destroy (scanner);
2324 _gtk_settings_handle_event (GdkEventSetting *event)
2327 GtkSettings *settings;
2331 screen = gdk_window_get_screen (event->window);
2332 settings = gtk_settings_get_for_screen (screen);
2333 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2337 property_id = pspec->param_id;
2339 if (property_id == PROP_COLOR_SCHEME)
2341 GValue value = { 0, };
2343 g_value_init (&value, G_TYPE_STRING);
2344 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2345 g_value_set_static_string (&value, "");
2346 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2347 g_value_unset (&value);
2349 g_object_notify (G_OBJECT (settings), pspec->name);
2354 reset_rc_values_foreach (GQuark key_id,
2358 GtkSettingsValuePrivate *qvalue = data;
2359 GSList **to_reset = user_data;
2361 if (qvalue->source == GTK_SETTINGS_SOURCE_RC_FILE)
2362 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2366 _gtk_settings_reset_rc_values (GtkSettings *settings)
2368 GtkSettingsPrivate *priv = settings->priv;
2369 GSList *to_reset = NULL;
2371 GParamSpec **pspecs, **p;
2374 /* Remove any queued settings */
2375 g_datalist_foreach (&priv->queued_settings,
2376 reset_rc_values_foreach,
2379 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2381 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2382 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2385 g_slist_free (to_reset);
2387 /* Now reset the active settings
2389 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2392 g_object_freeze_notify (G_OBJECT (settings));
2393 for (p = pspecs; *p; p++)
2395 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_RC_FILE)
2397 GParamSpec *pspec = *p;
2399 g_param_value_set_default (pspec, &priv->property_values[i].value);
2400 g_object_notify (G_OBJECT (settings), pspec->name);
2404 g_object_thaw_notify (G_OBJECT (settings));
2409 settings_update_double_click (GtkSettings *settings)
2411 GtkSettingsPrivate *priv = settings->priv;
2413 if (gdk_screen_get_number (priv->screen) == 0)
2415 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2416 gint double_click_time;
2417 gint double_click_distance;
2419 g_object_get (settings,
2420 "gtk-double-click-time", &double_click_time,
2421 "gtk-double-click-distance", &double_click_distance,
2424 gdk_display_set_double_click_time (display, double_click_time);
2425 gdk_display_set_double_click_distance (display, double_click_distance);
2430 settings_update_modules (GtkSettings *settings)
2434 g_object_get (settings,
2435 "gtk-modules", &modules,
2438 _gtk_modules_settings_changed (settings, modules);
2443 #ifdef GDK_WINDOWING_X11
2445 settings_update_cursor_theme (GtkSettings *settings)
2447 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2448 gchar *theme = NULL;
2451 g_object_get (settings,
2452 "gtk-cursor-theme-name", &theme,
2453 "gtk-cursor-theme-size", &size,
2456 gdk_x11_display_set_cursor_theme (display, theme, size);
2462 settings_update_font_options (GtkSettings *settings)
2464 GtkSettingsPrivate *priv = settings->priv;
2466 gchar *hint_style_str;
2467 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2469 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2471 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2472 cairo_font_options_t *options;
2474 g_object_get (settings,
2475 "gtk-xft-antialias", &antialias,
2476 "gtk-xft-hinting", &hinting,
2477 "gtk-xft-hintstyle", &hint_style_str,
2478 "gtk-xft-rgba", &rgba_str,
2481 options = cairo_font_options_create ();
2483 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2485 if (hinting >= 0 && !hinting)
2487 hint_style = CAIRO_HINT_STYLE_NONE;
2489 else if (hint_style_str)
2491 if (strcmp (hint_style_str, "hintnone") == 0)
2492 hint_style = CAIRO_HINT_STYLE_NONE;
2493 else if (strcmp (hint_style_str, "hintslight") == 0)
2494 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2495 else if (strcmp (hint_style_str, "hintmedium") == 0)
2496 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2497 else if (strcmp (hint_style_str, "hintfull") == 0)
2498 hint_style = CAIRO_HINT_STYLE_FULL;
2501 g_free (hint_style_str);
2503 cairo_font_options_set_hint_style (options, hint_style);
2507 if (strcmp (rgba_str, "rgb") == 0)
2508 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2509 else if (strcmp (rgba_str, "bgr") == 0)
2510 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2511 else if (strcmp (rgba_str, "vrgb") == 0)
2512 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2513 else if (strcmp (rgba_str, "vbgr") == 0)
2514 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2519 cairo_font_options_set_subpixel_order (options, subpixel_order);
2521 if (antialias >= 0 && !antialias)
2522 antialias_mode = CAIRO_ANTIALIAS_NONE;
2523 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2524 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2525 else if (antialias >= 0)
2526 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2528 cairo_font_options_set_antialias (options, antialias_mode);
2530 gdk_screen_set_font_options (priv->screen, options);
2532 cairo_font_options_destroy (options);
2535 #ifdef GDK_WINDOWING_X11
2537 settings_update_fontconfig (GtkSettings *settings)
2539 static guint last_update_timestamp;
2540 static gboolean last_update_needed;
2544 g_object_get (settings,
2545 "gtk-fontconfig-timestamp", ×tamp,
2548 /* if timestamp is the same as last_update_timestamp, we already have
2549 * updated fontconig on this timestamp (another screen requested it perhaps?),
2550 * just return the cached result.*/
2552 if (timestamp != last_update_timestamp)
2554 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2555 gboolean update_needed = FALSE;
2558 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2560 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2561 if (FcInitReinitialize ())
2562 update_needed = TRUE;
2565 last_update_timestamp = timestamp;
2566 last_update_needed = update_needed;
2569 return last_update_needed;
2571 #endif /* GDK_WINDOWING_X11 */
2574 settings_update_resolution (GtkSettings *settings)
2576 GtkSettingsPrivate *priv = settings->priv;
2580 g_object_get (settings,
2581 "gtk-xft-dpi", &dpi_int,
2585 dpi = dpi_int / 1024.;
2589 gdk_screen_set_resolution (priv->screen, dpi);
2595 GHashTable *color_hash;
2596 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2597 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2601 color_scheme_data_free (ColorSchemeData *data)
2605 g_hash_table_unref (data->color_hash);
2607 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2609 if (data->tables[i])
2610 g_hash_table_unref (data->tables[i]);
2611 g_free (data->lastentry[i]);
2614 g_slice_free (ColorSchemeData, data);
2618 settings_update_color_scheme (GtkSettings *settings)
2620 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2622 GtkSettingsPrivate *priv = settings->priv;
2623 ColorSchemeData *data;
2624 GValue value = { 0, };
2626 data = g_slice_new0 (ColorSchemeData);
2627 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2628 (GDestroyNotify) gdk_color_free);
2629 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2630 data, (GDestroyNotify) color_scheme_data_free);
2632 g_value_init (&value, G_TYPE_STRING);
2633 if (gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2635 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2636 g_value_unset (&value);
2642 settings_update_theme (GtkSettings *settings)
2644 static GQuark quark_theme_name = 0;
2646 GtkSettingsPrivate *priv = settings->priv;
2647 GtkCssProvider *provider, *new_provider = NULL;
2648 gboolean prefer_dark_theme;
2651 if (G_UNLIKELY (!quark_theme_name))
2652 quark_theme_name = g_quark_from_static_string ("gtk-settings-theme-name");
2654 provider = g_object_get_qdata (G_OBJECT (settings), quark_theme_name);
2656 g_object_get (settings,
2657 "gtk-theme-name", &theme_name,
2658 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2661 if (theme_name && *theme_name)
2663 gchar *variant = NULL;
2665 if (prefer_dark_theme)
2668 new_provider = gtk_css_provider_get_named (theme_name, variant);
2669 g_free (theme_name);
2672 if (new_provider != provider)
2675 gtk_style_context_remove_provider_for_screen (priv->screen,
2676 GTK_STYLE_PROVIDER (provider));
2680 gtk_style_context_add_provider_for_screen (priv->screen,
2681 GTK_STYLE_PROVIDER (new_provider),
2682 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2683 g_object_ref (new_provider);
2686 g_object_set_qdata_full (G_OBJECT (settings), quark_theme_name,
2687 new_provider, (GDestroyNotify) g_object_unref);
2692 add_color_to_hash (gchar *name,
2698 old = g_hash_table_lookup (target, name);
2699 if (!old || !gdk_color_equal (old, color))
2701 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2710 add_colors_to_hash_from_string (GHashTable *hash,
2711 const gchar *colors)
2713 gchar *s, *p, *name;
2715 gboolean changed = FALSE;
2718 copy = g_strdup (colors);
2723 p = strchr (s, ':');
2738 if (*s == '\n' || *s == ';')
2747 if (gdk_color_parse (p, &color))
2748 changed |= add_color_to_hash (name, &color, hash);
2757 update_color_hash (ColorSchemeData *data,
2759 GtkSettingsSource source)
2761 gboolean changed = FALSE;
2763 GHashTable *old_hash;
2764 GHashTableIter iter;
2768 if ((str == NULL || *str == '\0') &&
2769 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2772 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2775 /* For the RC_FILE source we merge the values rather than over-writing
2776 * them, since multiple rc files might define independent sets of colors
2778 if ((source != GTK_SETTINGS_SOURCE_RC_FILE) &&
2779 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2781 g_hash_table_unref (data->tables[source]);
2782 data->tables[source] = NULL;
2783 changed = TRUE; /* We can't rely on the code below since str might be "" */
2786 if (data->tables[source] == NULL)
2787 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2789 (GDestroyNotify) gdk_color_free);
2791 g_free (data->lastentry[source]);
2792 data->lastentry[source] = g_strdup (str);
2794 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2799 /* Rebuild the merged hash table. */
2800 if (data->color_hash)
2802 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2803 (GDestroyNotify) gdk_color_free);
2805 g_hash_table_iter_init (&iter, data->color_hash);
2806 while (g_hash_table_iter_next (&iter, &name, &color))
2808 g_hash_table_insert (old_hash, name, color);
2809 g_hash_table_iter_steal (&iter);
2817 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2819 if (data->tables[i])
2820 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2826 /* now check if the merged hash has changed */
2828 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2832 GHashTableIter iter;
2833 gpointer key, value, new_value;
2835 g_hash_table_iter_init (&iter, old_hash);
2836 while (g_hash_table_iter_next (&iter, &key, &value))
2838 new_value = g_hash_table_lookup (data->color_hash, key);
2839 if (!new_value || !gdk_color_equal (value, new_value))
2847 g_hash_table_unref (old_hash);
2856 merge_color_scheme (GtkSettings *settings,
2857 const GValue *value,
2858 GtkSettingsSource source)
2860 ColorSchemeData *data;
2861 const gchar *colors;
2863 g_object_freeze_notify (G_OBJECT (settings));
2865 colors = g_value_get_string (value);
2867 settings_update_color_scheme (settings);
2869 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2870 "gtk-color-scheme");
2872 if (update_color_hash (data, colors, source))
2873 g_object_notify (G_OBJECT (settings), "color-hash");
2875 g_object_thaw_notify (G_OBJECT (settings));
2879 get_color_hash (GtkSettings *settings)
2881 ColorSchemeData *data;
2883 settings_update_color_scheme (settings);
2885 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2886 "gtk-color-scheme");
2888 return data->color_hash;
2892 append_color_scheme (gpointer key,
2896 gchar *name = (gchar *)key;
2897 GdkColor *color = (GdkColor *)value;
2898 GString *string = (GString *)data;
2900 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2901 name, color->red, color->green, color->blue);
2905 get_color_scheme (GtkSettings *settings)
2907 ColorSchemeData *data;
2910 settings_update_color_scheme (settings);
2912 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2913 "gtk-color-scheme");
2915 string = g_string_new ("");
2917 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2919 return g_string_free (string, FALSE);
2923 _gtk_settings_get_screen (GtkSettings *settings)
2925 return settings->priv->screen;