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 "gtksettings.h"
30 #include "gtkwidget.h"
31 #include "gtktypeutils.h"
32 #include "gtkprivate.h"
33 #include "gtkcssprovider.h"
34 #include "gtksymboliccolor.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 _GtkSettingsValuePrivate GtkSettingsValuePrivate;
91 GTK_SETTINGS_SOURCE_DEFAULT,
92 GTK_SETTINGS_SOURCE_RC_FILE,
93 GTK_SETTINGS_SOURCE_XSETTING,
94 GTK_SETTINGS_SOURCE_APPLICATION
97 struct _GtkSettingsValuePrivate
99 GtkSettingsValue public;
100 GtkSettingsSource source;
103 struct _GtkSettingsPropertyValue
106 GtkSettingsSource source;
111 PROP_DOUBLE_CLICK_TIME,
112 PROP_DOUBLE_CLICK_DISTANCE,
114 PROP_CURSOR_BLINK_TIME,
115 PROP_CURSOR_BLINK_TIMEOUT,
118 PROP_ICON_THEME_NAME,
119 PROP_FALLBACK_ICON_THEME,
122 PROP_DND_DRAG_THRESHOLD,
126 #ifdef GDK_WINDOWING_X11
132 PROP_CURSOR_THEME_NAME,
133 PROP_CURSOR_THEME_SIZE,
135 PROP_ALTERNATIVE_BUTTON_ORDER,
136 PROP_ALTERNATIVE_SORT_ARROWS,
137 PROP_SHOW_INPUT_METHOD_MENU,
138 PROP_SHOW_UNICODE_MENU,
139 PROP_TIMEOUT_INITIAL,
143 PROP_ENABLE_ANIMATIONS,
144 PROP_TOUCHSCREEN_MODE,
145 PROP_TOOLTIP_TIMEOUT,
146 PROP_TOOLTIP_BROWSE_TIMEOUT,
147 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
148 PROP_KEYNAV_CURSOR_ONLY,
149 PROP_KEYNAV_WRAP_AROUND,
152 PROP_FILE_CHOOSER_BACKEND,
154 PROP_PRINT_PREVIEW_COMMAND,
155 PROP_ENABLE_MNEMONICS,
157 PROP_RECENT_FILES_LIMIT,
159 PROP_RECENT_FILES_MAX_AGE,
160 PROP_FONTCONFIG_TIMESTAMP,
161 PROP_SOUND_THEME_NAME,
162 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
163 PROP_ENABLE_EVENT_SOUNDS,
164 PROP_ENABLE_TOOLTIPS,
166 PROP_TOOLBAR_ICON_SIZE,
168 PROP_APPLICATION_PREFER_DARK_THEME,
170 PROP_ENTRY_SELECT_ON_FOCUS,
171 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
173 PROP_MENU_BAR_POPUP_DELAY,
174 PROP_SCROLLED_WINDOW_PLACEMENT,
175 PROP_CAN_CHANGE_ACCELS,
176 PROP_MENU_POPUP_DELAY,
177 PROP_MENU_POPDOWN_DELAY,
178 PROP_LABEL_SELECT_ON_FOCUS,
180 PROP_IM_PREEDIT_STYLE,
184 /* --- prototypes --- */
185 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
187 static void gtk_settings_finalize (GObject *object);
188 static void gtk_settings_get_property (GObject *object,
192 static void gtk_settings_set_property (GObject *object,
196 static void gtk_settings_notify (GObject *object,
198 static guint settings_install_property_parser (GtkSettingsClass *class,
200 GtkRcPropertyParser parser);
201 static void settings_update_double_click (GtkSettings *settings);
202 static void settings_update_modules (GtkSettings *settings);
204 #ifdef GDK_WINDOWING_X11
205 static void settings_update_cursor_theme (GtkSettings *settings);
206 static void settings_update_resolution (GtkSettings *settings);
207 static void settings_update_font_options (GtkSettings *settings);
208 static gboolean settings_update_fontconfig (GtkSettings *settings);
210 static void settings_update_color_scheme (GtkSettings *settings);
211 static void settings_update_theme (GtkSettings *settings);
213 static void merge_color_scheme (GtkSettings *settings,
215 GtkSettingsSource source);
216 static gchar *get_color_scheme (GtkSettings *settings);
217 static GHashTable *get_color_hash (GtkSettings *settings);
219 /* the default palette for GtkColorSelelection */
220 static const gchar default_color_palette[] =
221 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
222 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
224 /* --- variables --- */
225 static GQuark quark_property_parser = 0;
226 static GSList *object_list = NULL;
227 static guint class_n_properties = 0;
230 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
231 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
232 gtk_settings_provider_iface_init));
234 /* --- functions --- */
236 gtk_settings_init (GtkSettings *settings)
238 GParamSpec **pspecs, **p;
241 g_datalist_init (&settings->queued_settings);
242 object_list = g_slist_prepend (object_list, settings);
244 /* build up property array for all yet existing properties and queue
245 * notification for them (at least notification for internal properties
246 * will instantly be caught)
248 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
249 for (p = pspecs; *p; p++)
250 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
252 settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
254 g_object_freeze_notify (G_OBJECT (settings));
255 for (p = pspecs; *p; p++)
257 GParamSpec *pspec = *p;
259 if (pspec->owner_type != G_OBJECT_TYPE (settings))
261 g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
262 g_param_value_set_default (pspec, &settings->property_values[i].value);
263 g_object_notify (G_OBJECT (settings), pspec->name);
264 settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
267 g_object_thaw_notify (G_OBJECT (settings));
272 gtk_settings_class_init (GtkSettingsClass *class)
274 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
277 gobject_class->finalize = gtk_settings_finalize;
278 gobject_class->get_property = gtk_settings_get_property;
279 gobject_class->set_property = gtk_settings_set_property;
280 gobject_class->notify = gtk_settings_notify;
282 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
283 result = settings_install_property_parser (class,
284 g_param_spec_int ("gtk-double-click-time",
285 P_("Double Click Time"),
286 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
288 GTK_PARAM_READWRITE),
290 g_assert (result == PROP_DOUBLE_CLICK_TIME);
291 result = settings_install_property_parser (class,
292 g_param_spec_int ("gtk-double-click-distance",
293 P_("Double Click Distance"),
294 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
296 GTK_PARAM_READWRITE),
298 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
301 * GtkSettings:gtk-cursor-blink:
303 * Whether the cursor should blink.
305 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
306 * which allows more flexible control over cursor blinking.
308 result = settings_install_property_parser (class,
309 g_param_spec_boolean ("gtk-cursor-blink",
311 P_("Whether the cursor should blink"),
313 GTK_PARAM_READWRITE),
315 g_assert (result == PROP_CURSOR_BLINK);
316 result = settings_install_property_parser (class,
317 g_param_spec_int ("gtk-cursor-blink-time",
318 P_("Cursor Blink Time"),
319 P_("Length of the cursor blink cycle, in milliseconds"),
321 GTK_PARAM_READWRITE),
323 g_assert (result == PROP_CURSOR_BLINK_TIME);
326 * GtkSettings:gtk-cursor-blink-timeout:
328 * Time after which the cursor stops blinking, in seconds.
329 * The timer is reset after each user interaction.
331 * Setting this to zero has the same effect as setting
332 * #GtkSettings:gtk-cursor-blink to %FALSE.
336 result = settings_install_property_parser (class,
337 g_param_spec_int ("gtk-cursor-blink-timeout",
338 P_("Cursor Blink Timeout"),
339 P_("Time after which the cursor stops blinking, in seconds"),
340 1, G_MAXINT, G_MAXINT,
341 GTK_PARAM_READWRITE),
343 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
344 result = settings_install_property_parser (class,
345 g_param_spec_boolean ("gtk-split-cursor",
347 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
349 GTK_PARAM_READWRITE),
351 g_assert (result == PROP_SPLIT_CURSOR);
352 result = settings_install_property_parser (class,
353 g_param_spec_string ("gtk-theme-name",
355 P_("Name of theme RC file to load"),
357 GTK_PARAM_READWRITE),
359 g_assert (result == PROP_THEME_NAME);
361 result = settings_install_property_parser (class,
362 g_param_spec_string ("gtk-icon-theme-name",
363 P_("Icon Theme Name"),
364 P_("Name of icon theme to use"),
366 GTK_PARAM_READWRITE),
368 g_assert (result == PROP_ICON_THEME_NAME);
370 result = settings_install_property_parser (class,
371 g_param_spec_string ("gtk-fallback-icon-theme",
372 P_("Fallback Icon Theme Name"),
373 P_("Name of a icon theme to fall back to"),
375 GTK_PARAM_READWRITE),
377 g_assert (result == PROP_FALLBACK_ICON_THEME);
379 result = settings_install_property_parser (class,
380 g_param_spec_string ("gtk-key-theme-name",
381 P_("Key Theme Name"),
382 P_("Name of key theme RC file to load"),
384 GTK_PARAM_READWRITE),
386 g_assert (result == PROP_KEY_THEME_NAME);
388 result = settings_install_property_parser (class,
389 g_param_spec_string ("gtk-menu-bar-accel",
390 P_("Menu bar accelerator"),
391 P_("Keybinding to activate the menu bar"),
393 GTK_PARAM_READWRITE),
395 g_assert (result == PROP_MENU_BAR_ACCEL);
397 result = settings_install_property_parser (class,
398 g_param_spec_int ("gtk-dnd-drag-threshold",
399 P_("Drag threshold"),
400 P_("Number of pixels the cursor can move before dragging"),
402 GTK_PARAM_READWRITE),
404 g_assert (result == PROP_DND_DRAG_THRESHOLD);
406 result = settings_install_property_parser (class,
407 g_param_spec_string ("gtk-font-name",
409 P_("Name of default font to use"),
411 GTK_PARAM_READWRITE),
413 g_assert (result == PROP_FONT_NAME);
416 * GtkSettings:gtk-icon-sizes:
418 * A list of icon sizes. The list is separated by colons, and
421 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
423 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
424 * GTK+ itself use the following named icon sizes: gtk-menu,
425 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
426 * gtk-dialog. Applications can register their own named icon
427 * sizes with gtk_icon_size_register().
429 result = settings_install_property_parser (class,
430 g_param_spec_string ("gtk-icon-sizes",
432 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
434 GTK_PARAM_READWRITE),
436 g_assert (result == PROP_ICON_SIZES);
438 result = settings_install_property_parser (class,
439 g_param_spec_string ("gtk-modules",
441 P_("List of currently active GTK modules"),
443 GTK_PARAM_READWRITE),
445 g_assert (result == PROP_MODULES);
447 #ifdef GDK_WINDOWING_X11
448 result = settings_install_property_parser (class,
449 g_param_spec_int ("gtk-xft-antialias",
451 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
453 GTK_PARAM_READWRITE),
456 g_assert (result == PROP_XFT_ANTIALIAS);
458 result = settings_install_property_parser (class,
459 g_param_spec_int ("gtk-xft-hinting",
461 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
463 GTK_PARAM_READWRITE),
466 g_assert (result == PROP_XFT_HINTING);
468 result = settings_install_property_parser (class,
469 g_param_spec_string ("gtk-xft-hintstyle",
470 P_("Xft Hint Style"),
471 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
473 GTK_PARAM_READWRITE),
476 g_assert (result == PROP_XFT_HINTSTYLE);
478 result = settings_install_property_parser (class,
479 g_param_spec_string ("gtk-xft-rgba",
481 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
483 GTK_PARAM_READWRITE),
486 g_assert (result == PROP_XFT_RGBA);
488 result = settings_install_property_parser (class,
489 g_param_spec_int ("gtk-xft-dpi",
491 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
493 GTK_PARAM_READWRITE),
496 g_assert (result == PROP_XFT_DPI);
498 result = settings_install_property_parser (class,
499 g_param_spec_string ("gtk-cursor-theme-name",
500 P_("Cursor theme name"),
501 P_("Name of the cursor theme to use, or NULL to use the default theme"),
503 GTK_PARAM_READWRITE),
505 g_assert (result == PROP_CURSOR_THEME_NAME);
507 result = settings_install_property_parser (class,
508 g_param_spec_int ("gtk-cursor-theme-size",
509 P_("Cursor theme size"),
510 P_("Size to use for cursors, or 0 to use the default size"),
512 GTK_PARAM_READWRITE),
515 g_assert (result == PROP_CURSOR_THEME_SIZE);
517 #endif /* GDK_WINDOWING_X11 */
518 result = settings_install_property_parser (class,
519 g_param_spec_boolean ("gtk-alternative-button-order",
520 P_("Alternative button order"),
521 P_("Whether buttons in dialogs should use the alternative button order"),
523 GTK_PARAM_READWRITE),
525 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
528 * GtkSettings:gtk-alternative-sort-arrows:
530 * Controls the direction of the sort indicators in sorted list and tree
531 * views. By default an arrow pointing down means the column is sorted
532 * in ascending order. When set to %TRUE, this order will be inverted.
536 result = settings_install_property_parser (class,
537 g_param_spec_boolean ("gtk-alternative-sort-arrows",
538 P_("Alternative sort indicator direction"),
539 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
541 GTK_PARAM_READWRITE),
543 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
545 result = settings_install_property_parser (class,
546 g_param_spec_boolean ("gtk-show-input-method-menu",
547 P_("Show the 'Input Methods' menu"),
548 P_("Whether the context menus of entries and text views should offer to change the input method"),
550 GTK_PARAM_READWRITE),
552 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
554 result = settings_install_property_parser (class,
555 g_param_spec_boolean ("gtk-show-unicode-menu",
556 P_("Show the 'Insert Unicode Control Character' menu"),
557 P_("Whether the context menus of entries and text views should offer to insert control characters"),
559 GTK_PARAM_READWRITE),
561 g_assert (result == PROP_SHOW_UNICODE_MENU);
563 result = settings_install_property_parser (class,
564 g_param_spec_int ("gtk-timeout-initial",
566 P_("Starting value for timeouts, when button is pressed"),
567 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
568 GTK_PARAM_READWRITE),
571 g_assert (result == PROP_TIMEOUT_INITIAL);
573 result = settings_install_property_parser (class,
574 g_param_spec_int ("gtk-timeout-repeat",
575 P_("Repeat timeout"),
576 P_("Repeat value for timeouts, when button is pressed"),
577 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
578 GTK_PARAM_READWRITE),
581 g_assert (result == PROP_TIMEOUT_REPEAT);
583 result = settings_install_property_parser (class,
584 g_param_spec_int ("gtk-timeout-expand",
585 P_("Expand timeout"),
586 P_("Expand value for timeouts, when a widget is expanding a new region"),
587 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
588 GTK_PARAM_READWRITE),
591 g_assert (result == PROP_TIMEOUT_EXPAND);
594 * GtkSettings:gtk-color-scheme:
596 * A palette of named colors for use in themes. The format of the string is
602 * Color names must be acceptable as identifiers in the
603 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
604 * color specifications must be in the format accepted by
607 * Note that due to the way the color tables from different sources are
608 * merged, color specifications will be converted to hexadecimal form
609 * when getting this property.
611 * Starting with GTK+ 2.12, the entries can alternatively be separated
612 * by ';' instead of newlines:
614 * name1: color1; name2: color2; ...
619 result = settings_install_property_parser (class,
620 g_param_spec_string ("gtk-color-scheme",
622 P_("A palette of named colors for use in themes"),
624 GTK_PARAM_READWRITE),
627 g_assert (result == PROP_COLOR_SCHEME);
629 result = settings_install_property_parser (class,
630 g_param_spec_boolean ("gtk-enable-animations",
631 P_("Enable Animations"),
632 P_("Whether to enable toolkit-wide animations."),
634 GTK_PARAM_READWRITE),
637 g_assert (result == PROP_ENABLE_ANIMATIONS);
640 * GtkSettings:gtk-touchscreen-mode:
642 * When %TRUE, there are no motion notify events delivered on this screen,
643 * and widgets can't use the pointer hovering them for any essential
648 result = settings_install_property_parser (class,
649 g_param_spec_boolean ("gtk-touchscreen-mode",
650 P_("Enable Touchscreen Mode"),
651 P_("When TRUE, there are no motion notify events delivered on this screen"),
653 GTK_PARAM_READWRITE),
656 g_assert (result == PROP_TOUCHSCREEN_MODE);
659 * GtkSettings:gtk-tooltip-timeout:
661 * Time, in milliseconds, after which a tooltip could appear if the
662 * cursor is hovering on top of a widget.
666 result = settings_install_property_parser (class,
667 g_param_spec_int ("gtk-tooltip-timeout",
668 P_("Tooltip timeout"),
669 P_("Timeout before tooltip is shown"),
672 GTK_PARAM_READWRITE),
675 g_assert (result == PROP_TOOLTIP_TIMEOUT);
678 * GtkSettings:gtk-tooltip-browse-timeout:
680 * Controls the time after which tooltips will appear when
681 * browse mode is enabled, in milliseconds.
683 * Browse mode is enabled when the mouse pointer moves off an object
684 * where a tooltip was currently being displayed. If the mouse pointer
685 * hits another object before the browse mode timeout expires (see
686 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
687 * amount of milliseconds specified by this setting to popup the tooltip
688 * for the new object.
692 result = settings_install_property_parser (class,
693 g_param_spec_int ("gtk-tooltip-browse-timeout",
694 P_("Tooltip browse timeout"),
695 P_("Timeout before tooltip is shown when browse mode is enabled"),
698 GTK_PARAM_READWRITE),
701 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
704 * GtkSettings:gtk-tooltip-browse-mode-timeout:
706 * Amount of time, in milliseconds, after which the browse mode
709 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
714 result = settings_install_property_parser (class,
715 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
716 P_("Tooltip browse mode timeout"),
717 P_("Timeout after which browse mode is disabled"),
720 GTK_PARAM_READWRITE),
723 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
726 * GtkSettings:gtk-keynav-cursor-only:
728 * When %TRUE, keyboard navigation should be able to reach all widgets
729 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
730 * to be present on the used input device.
734 result = settings_install_property_parser (class,
735 g_param_spec_boolean ("gtk-keynav-cursor-only",
736 P_("Keynav Cursor Only"),
737 P_("When TRUE, there are only cursor keys available to navigate widgets"),
739 GTK_PARAM_READWRITE),
742 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
745 * GtkSettings:gtk-keynav-wrap-around:
747 * When %TRUE, some widgets will wrap around when doing keyboard
748 * navigation, such as menus, menubars and notebooks.
752 result = settings_install_property_parser (class,
753 g_param_spec_boolean ("gtk-keynav-wrap-around",
754 P_("Keynav Wrap Around"),
755 P_("Whether to wrap around when keyboard-navigating widgets"),
757 GTK_PARAM_READWRITE),
760 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
763 * GtkSettings:gtk-error-bell:
765 * When %TRUE, keyboard navigation and other input-related errors
766 * will cause a beep. Since the error bell is implemented using
767 * gdk_window_beep(), the windowing system may offer ways to
768 * configure the error bell in many ways, such as flashing the
769 * window or similar visual effects.
773 result = settings_install_property_parser (class,
774 g_param_spec_boolean ("gtk-error-bell",
776 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
778 GTK_PARAM_READWRITE),
781 g_assert (result == PROP_ERROR_BELL);
784 * GtkSettings:color-hash:
786 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
787 * setting, mapping color names to #GdkColor<!-- -->s.
791 result = settings_install_property_parser (class,
792 g_param_spec_boxed ("color-hash",
794 P_("A hash table representation of the color scheme."),
798 g_assert (result == PROP_COLOR_HASH);
800 result = settings_install_property_parser (class,
801 g_param_spec_string ("gtk-file-chooser-backend",
802 P_("Default file chooser backend"),
803 P_("Name of the GtkFileChooser backend to use by default"),
805 GTK_PARAM_READWRITE),
807 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
810 * GtkSettings:gtk-print-backends:
812 * A comma-separated list of print backends to use in the print
813 * dialog. Available print backends depend on the GTK+ installation,
814 * and may include "file", "cups", "lpr" or "papi".
818 result = settings_install_property_parser (class,
819 g_param_spec_string ("gtk-print-backends",
820 P_("Default print backend"),
821 P_("List of the GtkPrintBackend backends to use by default"),
823 GTK_PARAM_READWRITE),
825 g_assert (result == PROP_PRINT_BACKENDS);
828 * GtkSettings:gtk-print-preview-command:
830 * A command to run for displaying the print preview. The command
831 * should contain a %f placeholder, which will get replaced by
832 * the path to the pdf file. The command may also contain a %s
833 * placeholder, which will get replaced by the path to a file
834 * containing the print settings in the format produced by
835 * gtk_print_settings_to_file().
837 * The preview application is responsible for removing the pdf file
838 * and the print settings file when it is done.
842 result = settings_install_property_parser (class,
843 g_param_spec_string ("gtk-print-preview-command",
844 P_("Default command to run when displaying a print preview"),
845 P_("Command to run when displaying a print preview"),
846 GTK_PRINT_PREVIEW_COMMAND,
847 GTK_PARAM_READWRITE),
849 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
852 * GtkSettings:gtk-enable-mnemonics:
854 * Whether labels and menu items should have visible mnemonics which
859 result = settings_install_property_parser (class,
860 g_param_spec_boolean ("gtk-enable-mnemonics",
861 P_("Enable Mnemonics"),
862 P_("Whether labels should have mnemonics"),
864 GTK_PARAM_READWRITE),
866 g_assert (result == PROP_ENABLE_MNEMONICS);
869 * GtkSettings:gtk-enable-accels:
871 * Whether menu items should have visible accelerators which can be
876 result = settings_install_property_parser (class,
877 g_param_spec_boolean ("gtk-enable-accels",
878 P_("Enable Accelerators"),
879 P_("Whether menu items should have accelerators"),
881 GTK_PARAM_READWRITE),
883 g_assert (result == PROP_ENABLE_ACCELS);
886 * GtkSettings:gtk-recent-files-limit:
888 * The number of recently used files that should be displayed by default by
889 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
890 * -1 means every recently used file stored.
894 result = settings_install_property_parser (class,
895 g_param_spec_int ("gtk-recent-files-limit",
896 P_("Recent Files Limit"),
897 P_("Number of recently used files"),
900 GTK_PARAM_READWRITE),
902 g_assert (result == PROP_RECENT_FILES_LIMIT);
905 * GtkSettings:gtk-im-module:
907 * Which IM (input method) module should be used by default. This is the
908 * input method that will be used if the user has not explicitly chosen
909 * another input method from the IM context menu.
911 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
913 result = settings_install_property_parser (class,
914 g_param_spec_string ("gtk-im-module",
915 P_("Default IM module"),
916 P_("Which IM module should be used by default"),
918 GTK_PARAM_READWRITE),
920 g_assert (result == PROP_IM_MODULE);
923 * GtkSettings:gtk-recent-files-max-age:
925 * The maximum age, in days, of the items inside the recently used
926 * resources list. Items older than this setting will be excised
927 * from the list. If set to 0, the list will always be empty; if
928 * set to -1, no item will be removed.
932 result = settings_install_property_parser (class,
933 g_param_spec_int ("gtk-recent-files-max-age",
934 P_("Recent Files Max Age"),
935 P_("Maximum age of recently used files, in days"),
938 GTK_PARAM_READWRITE),
940 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
942 result = settings_install_property_parser (class,
943 g_param_spec_uint ("gtk-fontconfig-timestamp",
944 P_("Fontconfig configuration timestamp"),
945 P_("Timestamp of current fontconfig configuration"),
947 GTK_PARAM_READWRITE),
950 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
953 * GtkSettings:gtk-sound-theme-name:
955 * The XDG sound theme to use for event sounds.
957 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
958 * for more information on event sounds and sound themes.
960 * GTK+ itself does not support event sounds, you have to use a loadable
961 * module like the one that comes with libcanberra.
965 result = settings_install_property_parser (class,
966 g_param_spec_string ("gtk-sound-theme-name",
967 P_("Sound Theme Name"),
968 P_("XDG sound theme name"),
970 GTK_PARAM_READWRITE),
972 g_assert (result == PROP_SOUND_THEME_NAME);
975 * GtkSettings:gtk-enable-input-feedback-sounds:
977 * Whether to play event sounds as feedback to user input.
979 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
980 * for more information on event sounds and sound themes.
982 * GTK+ itself does not support event sounds, you have to use a loadable
983 * module like the one that comes with libcanberra.
987 result = settings_install_property_parser (class,
988 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
989 /* Translators: this means sounds that are played as feedback to user input */
990 P_("Audible Input Feedback"),
991 P_("Whether to play event sounds as feedback to user input"),
993 GTK_PARAM_READWRITE),
995 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
998 * GtkSettings:gtk-enable-event-sounds:
1000 * Whether to play any event sounds at all.
1002 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1003 * for more information on event sounds and sound themes.
1005 * GTK+ itself does not support event sounds, you have to use a loadable
1006 * module like the one that comes with libcanberra.
1010 result = settings_install_property_parser (class,
1011 g_param_spec_boolean ("gtk-enable-event-sounds",
1012 P_("Enable Event Sounds"),
1013 P_("Whether to play any event sounds at all"),
1015 GTK_PARAM_READWRITE),
1017 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1020 * GtkSettings:gtk-enable-tooltips:
1022 * Whether tooltips should be shown on widgets.
1026 result = settings_install_property_parser (class,
1027 g_param_spec_boolean ("gtk-enable-tooltips",
1028 P_("Enable Tooltips"),
1029 P_("Whether tooltips should be shown on widgets"),
1031 GTK_PARAM_READWRITE),
1033 g_assert (result == PROP_ENABLE_TOOLTIPS);
1036 * GtkSettings:toolbar-style:
1038 * The size of icons in default toolbars.
1040 result = settings_install_property_parser (class,
1041 g_param_spec_enum ("gtk-toolbar-style",
1042 P_("Toolbar style"),
1043 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1044 GTK_TYPE_TOOLBAR_STYLE,
1046 GTK_PARAM_READWRITE),
1047 gtk_rc_property_parse_enum);
1048 g_assert (result == PROP_TOOLBAR_STYLE);
1051 * GtkSettings:toolbar-icon-size:
1053 * The size of icons in default toolbars.
1055 result = settings_install_property_parser (class,
1056 g_param_spec_enum ("gtk-toolbar-icon-size",
1057 P_("Toolbar Icon Size"),
1058 P_("The size of icons in default toolbars."),
1060 GTK_ICON_SIZE_LARGE_TOOLBAR,
1061 GTK_PARAM_READWRITE),
1062 gtk_rc_property_parse_enum);
1063 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1066 * GtkSettings:gtk-auto-mnemonics:
1068 * Whether mnemonics should be automatically shown and hidden when the user
1069 * presses the mnemonic activator.
1073 result = settings_install_property_parser (class,
1074 g_param_spec_boolean ("gtk-auto-mnemonics",
1075 P_("Auto Mnemonics"),
1076 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1078 GTK_PARAM_READWRITE),
1080 g_assert (result == PROP_AUTO_MNEMONICS);
1083 * GtkSettings:gtk-application-prefer-dark-theme:
1085 * Whether the application prefers to use a dark theme. If a GTK+ theme
1086 * includes a dark variant, it will be used instead of the configured
1089 * Some applications benefit from minimizing the amount of light pollution that
1090 * interferes with the content. Good candidates for dark themes are photo and
1091 * video editors that make the actual content get all the attention and minimize
1092 * the distraction of the chrome.
1094 * Dark themes should not be used for documents, where large spaces are white/light
1095 * and the dark chrome creates too much contrast (web browser, text editor...).
1099 result = settings_install_property_parser (class,
1100 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1101 P_("Application prefers a dark theme"),
1102 P_("Whether the application prefers to have a dark theme."),
1104 GTK_PARAM_READWRITE),
1106 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1109 * GtkSettings::gtk-button-images:
1111 * Whether images should be shown on buttons
1115 result = settings_install_property_parser (class,
1116 g_param_spec_boolean ("gtk-button-images",
1117 P_("Show button images"),
1118 P_("Whether images should be shown on buttons"),
1120 GTK_PARAM_READWRITE),
1122 g_assert (result == PROP_BUTTON_IMAGES);
1124 result = settings_install_property_parser (class,
1125 g_param_spec_boolean ("gtk-entry-select-on-focus",
1126 P_("Select on focus"),
1127 P_("Whether to select the contents of an entry when it is focused"),
1129 GTK_PARAM_READWRITE),
1131 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1134 * GtkSettings:gtk-entry-password-hint-timeout:
1136 * How long to show the last input character in hidden
1137 * entries. This value is in milliseconds. 0 disables showing the
1138 * last char. 600 is a good value for enabling it.
1142 result = settings_install_property_parser (class,
1143 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1144 P_("Password Hint Timeout"),
1145 P_("How long to show the last input character in hidden entries"),
1148 GTK_PARAM_READWRITE),
1150 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1152 result = settings_install_property_parser (class,
1153 g_param_spec_boolean ("gtk-menu-images",
1154 P_("Show menu images"),
1155 P_("Whether images should be shown in menus"),
1157 GTK_PARAM_READWRITE),
1159 g_assert (result == PROP_MENU_IMAGES);
1161 result = settings_install_property_parser (class,
1162 g_param_spec_int ("gtk-menu-bar-popup-delay",
1163 P_("Delay before drop down menus appear"),
1164 P_("Delay before the submenus of a menu bar appear"),
1167 GTK_PARAM_READWRITE),
1169 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1172 * GtkSettings:gtk-scrolled-window-placement:
1174 * Where the contents of scrolled windows are located with respect to the
1175 * scrollbars, if not overridden by the scrolled window's own placement.
1179 result = settings_install_property_parser (class,
1180 g_param_spec_enum ("gtk-scrolled-window-placement",
1181 P_("Scrolled Window Placement"),
1182 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1183 GTK_TYPE_CORNER_TYPE,
1184 GTK_CORNER_TOP_LEFT,
1185 GTK_PARAM_READWRITE),
1186 gtk_rc_property_parse_enum);
1187 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1189 result = settings_install_property_parser (class,
1190 g_param_spec_boolean ("gtk-can-change-accels",
1191 P_("Can change accelerators"),
1192 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1194 GTK_PARAM_READWRITE),
1196 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1198 result = settings_install_property_parser (class,
1199 g_param_spec_int ("gtk-menu-popup-delay",
1200 P_("Delay before submenus appear"),
1201 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1204 GTK_PARAM_READWRITE),
1206 g_assert (result == PROP_MENU_POPUP_DELAY);
1208 result = settings_install_property_parser (class,
1209 g_param_spec_int ("gtk-menu-popdown-delay",
1210 P_("Delay before hiding a submenu"),
1211 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1214 GTK_PARAM_READWRITE),
1216 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1218 result = settings_install_property_parser (class,
1219 g_param_spec_boolean ("gtk-label-select-on-focus",
1220 P_("Select on focus"),
1221 P_("Whether to select the contents of a selectable label when it is focused"),
1223 GTK_PARAM_READWRITE),
1225 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1227 result = settings_install_property_parser (class,
1228 g_param_spec_string ("gtk-color-palette",
1229 P_("Custom palette"),
1230 P_("Palette to use in the color selector"),
1231 default_color_palette,
1232 GTK_PARAM_READWRITE),
1234 g_assert (result == PROP_COLOR_PALETTE);
1236 result = settings_install_property_parser (class,
1237 g_param_spec_enum ("gtk-im-preedit-style",
1238 P_("IM Preedit style"),
1239 P_("How to draw the input method preedit string"),
1240 GTK_TYPE_IM_PREEDIT_STYLE,
1241 GTK_IM_PREEDIT_CALLBACK,
1242 GTK_PARAM_READWRITE),
1243 gtk_rc_property_parse_enum);
1244 g_assert (result == PROP_IM_PREEDIT_STYLE);
1246 result = settings_install_property_parser (class,
1247 g_param_spec_enum ("gtk-im-status-style",
1248 P_("IM Status style"),
1249 P_("How to draw the input method statusbar"),
1250 GTK_TYPE_IM_STATUS_STYLE,
1251 GTK_IM_STATUS_CALLBACK,
1252 GTK_PARAM_READWRITE),
1253 gtk_rc_property_parse_enum);
1254 g_assert (result == PROP_IM_STATUS_STYLE);
1257 static GtkStyleProperties *
1258 gtk_settings_get_style (GtkStyleProvider *provider,
1259 GtkWidgetPath *path)
1261 PangoFontDescription *font_desc;
1262 gchar *font_name, *color_scheme;
1263 GtkSettings *settings;
1264 GtkStyleProperties *props;
1268 settings = GTK_SETTINGS (provider);
1269 props = gtk_style_properties_new ();
1271 g_object_get (settings,
1272 "gtk-font-name", &font_name,
1273 "gtk-color-scheme", &color_scheme,
1276 colors = g_strsplit_set (color_scheme, "\n;", -1);
1278 for (i = 0; colors[i]; i++)
1280 GtkSymbolicColor *color;
1288 pos = strchr (colors[i], ':');
1293 /* Set NUL after color name */
1297 /* Find start of color string */
1301 if (!*pos || !gdk_rgba_parse (&col, pos))
1304 color = gtk_symbolic_color_new_literal (&col);
1305 gtk_style_properties_map_color (props, name, color);
1306 gtk_symbolic_color_unref (color);
1309 font_desc = pango_font_description_from_string (font_name);
1311 gtk_style_properties_set (props, 0,
1315 pango_font_description_free (font_desc);
1316 g_strfreev (colors);
1317 g_free (color_scheme);
1324 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1326 iface->get_style = gtk_settings_get_style;
1330 gtk_settings_finalize (GObject *object)
1332 GtkSettings *settings = GTK_SETTINGS (object);
1335 object_list = g_slist_remove (object_list, settings);
1337 for (i = 0; i < class_n_properties; i++)
1338 g_value_unset (&settings->property_values[i].value);
1339 g_free (settings->property_values);
1341 g_datalist_clear (&settings->queued_settings);
1343 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1347 settings_init_style (GtkSettings *settings)
1349 static GtkCssProvider *css_provider = NULL;
1350 GtkCssProvider *default_provider;
1352 /* Add provider for user file */
1353 if (G_UNLIKELY (!css_provider))
1357 css_provider = gtk_css_provider_new ();
1358 css_path = g_build_filename (g_get_user_config_dir (),
1363 if (g_file_test (css_path,
1364 G_FILE_TEST_IS_REGULAR))
1365 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1370 gtk_style_context_add_provider_for_screen (settings->screen,
1371 GTK_STYLE_PROVIDER (css_provider),
1372 GTK_STYLE_PROVIDER_PRIORITY_USER);
1374 default_provider = gtk_css_provider_get_default ();
1375 gtk_style_context_add_provider_for_screen (settings->screen,
1376 GTK_STYLE_PROVIDER (default_provider),
1377 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1379 gtk_style_context_add_provider_for_screen (settings->screen,
1380 GTK_STYLE_PROVIDER (settings),
1381 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1383 settings_update_theme (settings);
1387 * gtk_settings_get_for_screen:
1388 * @screen: a #GdkScreen.
1390 * Gets the #GtkSettings object for @screen, creating it if necessary.
1392 * Return value: (transfer none): a #GtkSettings object.
1397 gtk_settings_get_for_screen (GdkScreen *screen)
1399 GtkSettings *settings;
1401 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1403 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1406 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1407 settings->screen = screen;
1408 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1409 settings, g_object_unref);
1411 settings_init_style (settings);
1412 settings_update_double_click (settings);
1413 #ifdef GDK_WINDOWING_X11
1414 settings_update_cursor_theme (settings);
1415 settings_update_resolution (settings);
1416 settings_update_font_options (settings);
1418 settings_update_color_scheme (settings);
1425 * gtk_settings_get_default:
1427 * Gets the #GtkSettings object for the default GDK screen, creating
1428 * it if necessary. See gtk_settings_get_for_screen().
1430 * Return value: (transfer none): a #GtkSettings object. If there is no default
1431 * screen, then returns %NULL.
1434 gtk_settings_get_default (void)
1436 GdkScreen *screen = gdk_screen_get_default ();
1439 return gtk_settings_get_for_screen (screen);
1445 gtk_settings_set_property (GObject *object,
1447 const GValue *value,
1450 GtkSettings *settings = GTK_SETTINGS (object);
1452 g_value_copy (value, &settings->property_values[property_id - 1].value);
1453 settings->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1455 if (pspec->param_id == PROP_COLOR_SCHEME)
1456 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1460 gtk_settings_get_property (GObject *object,
1465 GtkSettings *settings = GTK_SETTINGS (object);
1466 GType value_type = G_VALUE_TYPE (value);
1467 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1469 /* handle internal properties */
1470 switch (property_id)
1472 case PROP_COLOR_HASH:
1473 g_value_set_boxed (value, get_color_hash (settings));
1475 case PROP_COLOR_SCHEME:
1476 g_value_take_string (value, get_color_scheme (settings));
1481 /* For enums and strings, we need to get the value as a string,
1482 * not as an int, since we support using names/nicks as the setting
1485 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1486 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1487 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1488 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1490 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1491 !gdk_screen_get_setting (settings->screen, pspec->name, value))
1492 g_value_copy (&settings->property_values[property_id - 1].value, value);
1494 g_param_value_validate (pspec, value);
1498 GValue val = { 0, };
1500 /* Try to get xsetting as a string and parse it. */
1502 g_value_init (&val, G_TYPE_STRING);
1504 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1505 !gdk_screen_get_setting (settings->screen, pspec->name, &val))
1507 g_value_copy (&settings->property_values[property_id - 1].value, value);
1511 GValue tmp_value = { 0, };
1512 GValue gstring_value = { 0, };
1513 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1515 g_value_init (&gstring_value, G_TYPE_GSTRING);
1516 g_value_take_boxed (&gstring_value,
1517 g_string_new (g_value_get_string (&val)));
1519 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1521 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1524 g_value_copy (&tmp_value, value);
1525 g_param_value_validate (pspec, value);
1529 g_value_copy (&settings->property_values[property_id - 1].value, value);
1532 g_value_unset (&gstring_value);
1533 g_value_unset (&tmp_value);
1536 g_value_unset (&val);
1541 gtk_settings_notify (GObject *object,
1544 GtkSettings *settings = GTK_SETTINGS (object);
1545 guint property_id = pspec->param_id;
1547 if (settings->screen == NULL) /* initialization */
1550 switch (property_id)
1553 settings_update_modules (settings);
1555 case PROP_DOUBLE_CLICK_TIME:
1556 case PROP_DOUBLE_CLICK_DISTANCE:
1557 settings_update_double_click (settings);
1559 case PROP_COLOR_SCHEME:
1560 settings_update_color_scheme (settings);
1561 gtk_style_context_reset_widgets (settings->screen);
1563 case PROP_THEME_NAME:
1564 settings_update_theme (settings);
1566 #ifdef GDK_WINDOWING_X11
1568 settings_update_resolution (settings);
1569 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1570 * widgets with gtk_widget_style_set(), and also causes more
1571 * recomputation than necessary.
1573 gtk_style_context_reset_widgets (settings->screen);
1575 case PROP_XFT_ANTIALIAS:
1576 case PROP_XFT_HINTING:
1577 case PROP_XFT_HINTSTYLE:
1579 settings_update_font_options (settings);
1580 gtk_style_context_reset_widgets (settings->screen);
1582 case PROP_FONTCONFIG_TIMESTAMP:
1583 if (settings_update_fontconfig (settings))
1584 gtk_style_context_reset_widgets (settings->screen);
1586 case PROP_CURSOR_THEME_NAME:
1587 case PROP_CURSOR_THEME_SIZE:
1588 settings_update_cursor_theme (settings);
1590 #endif /* GDK_WINDOWING_X11 */
1595 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1596 const GValue *src_value,
1600 gboolean success = FALSE;
1602 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1607 gboolean free_gstring = TRUE;
1609 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1611 gstring = g_value_get_boxed (src_value);
1612 free_gstring = FALSE;
1614 else if (G_VALUE_HOLDS_LONG (src_value))
1616 gstring = g_string_new (NULL);
1617 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1619 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1621 gstring = g_string_new (NULL);
1622 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1624 else if (G_VALUE_HOLDS_STRING (src_value))
1626 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1628 gstring = g_string_new ("\"");
1629 g_string_append (gstring, tstr);
1630 g_string_append_c (gstring, '\"');
1635 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1636 gstring = NULL; /* silence compiler */
1639 success = (parser (pspec, gstring, dest_value) &&
1640 !g_param_value_validate (pspec, dest_value));
1643 g_string_free (gstring, TRUE);
1645 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1647 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1649 GString *gstring = g_value_get_boxed (src_value);
1651 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1652 success = !g_param_value_validate (pspec, dest_value);
1655 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1656 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1662 apply_queued_setting (GtkSettings *data,
1664 GtkSettingsValuePrivate *qvalue)
1666 GValue tmp_value = { 0, };
1667 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1669 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1670 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1673 if (pspec->param_id == PROP_COLOR_SCHEME)
1674 merge_color_scheme (data, &tmp_value, qvalue->source);
1676 if (data->property_values[pspec->param_id - 1].source <= qvalue->source)
1678 g_value_copy (&tmp_value, &data->property_values[pspec->param_id - 1].value);
1679 data->property_values[pspec->param_id - 1].source = qvalue->source;
1680 g_object_notify (G_OBJECT (data), g_param_spec_get_name (pspec));
1686 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1688 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1689 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1691 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1693 G_VALUE_TYPE_NAME (&tmp_value));
1696 g_value_unset (&tmp_value);
1700 settings_install_property_parser (GtkSettingsClass *class,
1702 GtkRcPropertyParser parser)
1704 GSList *node, *next;
1706 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1708 case G_TYPE_BOOLEAN:
1721 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1729 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1730 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1734 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1736 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1741 for (node = object_list; node; node = node->next)
1742 g_object_freeze_notify (node->data);
1744 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1745 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1747 for (node = object_list; node; node = node->next)
1749 GtkSettings *settings = node->data;
1750 GtkSettingsValuePrivate *qvalue;
1752 settings->property_values = g_renew (GtkSettingsPropertyValue, settings->property_values, class_n_properties);
1753 settings->property_values[class_n_properties - 1].value.g_type = 0;
1754 g_value_init (&settings->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1755 g_param_value_set_default (pspec, &settings->property_values[class_n_properties - 1].value);
1756 settings->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1757 g_object_notify (G_OBJECT (settings), pspec->name);
1759 qvalue = g_datalist_get_data (&settings->queued_settings, pspec->name);
1761 apply_queued_setting (settings, pspec, qvalue);
1764 for (node = object_list; node; node = next)
1767 g_object_thaw_notify (node->data);
1770 return class_n_properties;
1774 _gtk_rc_property_parser_from_type (GType type)
1776 if (type == GDK_TYPE_COLOR)
1777 return gtk_rc_property_parse_color;
1778 else if (type == GTK_TYPE_REQUISITION)
1779 return gtk_rc_property_parse_requisition;
1780 else if (type == GTK_TYPE_BORDER)
1781 return gtk_rc_property_parse_border;
1782 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1783 return gtk_rc_property_parse_enum;
1784 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1785 return gtk_rc_property_parse_flags;
1791 gtk_settings_install_property (GParamSpec *pspec)
1793 static GtkSettingsClass *klass = NULL;
1795 GtkRcPropertyParser parser;
1797 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1800 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1802 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1804 settings_install_property_parser (klass, pspec, parser);
1808 gtk_settings_install_property_parser (GParamSpec *pspec,
1809 GtkRcPropertyParser parser)
1811 static GtkSettingsClass *klass = NULL;
1813 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1814 g_return_if_fail (parser != NULL);
1817 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1819 settings_install_property_parser (klass, pspec, parser);
1823 free_value (gpointer data)
1825 GtkSettingsValuePrivate *qvalue = data;
1827 g_value_unset (&qvalue->public.value);
1828 g_free (qvalue->public.origin);
1829 g_slice_free (GtkSettingsValuePrivate, qvalue);
1833 gtk_settings_set_property_value_internal (GtkSettings *settings,
1834 const gchar *prop_name,
1835 const GtkSettingsValue *new_value,
1836 GtkSettingsSource source)
1838 GtkSettingsValuePrivate *qvalue;
1843 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1844 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1845 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1846 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1848 g_warning (G_STRLOC ": value type invalid");
1852 name = g_strdup (prop_name);
1853 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1854 name_quark = g_quark_from_string (name);
1857 qvalue = g_datalist_id_get_data (&settings->queued_settings, name_quark);
1860 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1861 g_datalist_id_set_data_full (&settings->queued_settings, name_quark, qvalue, free_value);
1865 g_free (qvalue->public.origin);
1866 g_value_unset (&qvalue->public.value);
1868 qvalue->public.origin = g_strdup (new_value->origin);
1869 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1870 g_value_copy (&new_value->value, &qvalue->public.value);
1871 qvalue->source = source;
1872 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1874 apply_queued_setting (settings, pspec, qvalue);
1878 gtk_settings_set_property_value (GtkSettings *settings,
1879 const gchar *prop_name,
1880 const GtkSettingsValue *new_value)
1882 g_return_if_fail (GTK_SETTINGS (settings));
1883 g_return_if_fail (prop_name != NULL);
1884 g_return_if_fail (new_value != NULL);
1886 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1887 GTK_SETTINGS_SOURCE_APPLICATION);
1891 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1892 const gchar *prop_name,
1893 const GtkSettingsValue *new_value)
1895 g_return_if_fail (GTK_SETTINGS (settings));
1896 g_return_if_fail (prop_name != NULL);
1897 g_return_if_fail (new_value != NULL);
1899 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1900 GTK_SETTINGS_SOURCE_RC_FILE);
1904 gtk_settings_set_string_property (GtkSettings *settings,
1906 const gchar *v_string,
1907 const gchar *origin)
1909 GtkSettingsValue svalue = { NULL, { 0, }, };
1911 g_return_if_fail (GTK_SETTINGS (settings));
1912 g_return_if_fail (name != NULL);
1913 g_return_if_fail (v_string != NULL);
1915 svalue.origin = (gchar*) origin;
1916 g_value_init (&svalue.value, G_TYPE_STRING);
1917 g_value_set_static_string (&svalue.value, v_string);
1918 gtk_settings_set_property_value (settings, name, &svalue);
1919 g_value_unset (&svalue.value);
1923 gtk_settings_set_long_property (GtkSettings *settings,
1926 const gchar *origin)
1928 GtkSettingsValue svalue = { NULL, { 0, }, };
1930 g_return_if_fail (GTK_SETTINGS (settings));
1931 g_return_if_fail (name != NULL);
1933 svalue.origin = (gchar*) origin;
1934 g_value_init (&svalue.value, G_TYPE_LONG);
1935 g_value_set_long (&svalue.value, v_long);
1936 gtk_settings_set_property_value (settings, name, &svalue);
1937 g_value_unset (&svalue.value);
1941 gtk_settings_set_double_property (GtkSettings *settings,
1944 const gchar *origin)
1946 GtkSettingsValue svalue = { NULL, { 0, }, };
1948 g_return_if_fail (GTK_SETTINGS (settings));
1949 g_return_if_fail (name != NULL);
1951 svalue.origin = (gchar*) origin;
1952 g_value_init (&svalue.value, G_TYPE_DOUBLE);
1953 g_value_set_double (&svalue.value, v_double);
1954 gtk_settings_set_property_value (settings, name, &svalue);
1955 g_value_unset (&svalue.value);
1959 * gtk_rc_property_parse_color:
1960 * @pspec: a #GParamSpec
1961 * @gstring: the #GString to be parsed
1962 * @property_value: a #GValue which must hold #GdkColor values.
1964 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1965 * or gtk_widget_class_install_style_property_parser() which parses a
1966 * color given either by its name or in the form
1967 * <literal>{ red, green, blue }</literal> where %red, %green and
1968 * %blue are integers between 0 and 65535 or floating-point numbers
1971 * Return value: %TRUE if @gstring could be parsed and @property_value
1972 * has been set to the resulting #GdkColor.
1975 gtk_rc_property_parse_color (const GParamSpec *pspec,
1976 const GString *gstring,
1977 GValue *property_value)
1979 GdkColor color = { 0, 0, 0, 0, };
1983 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1984 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
1986 scanner = gtk_rc_scanner_new ();
1987 g_scanner_input_text (scanner, gstring->str, gstring->len);
1988 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
1989 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
1991 g_value_set_boxed (property_value, &color);
1996 g_scanner_destroy (scanner);
2002 * gtk_rc_property_parse_enum:
2003 * @pspec: a #GParamSpec
2004 * @gstring: the #GString to be parsed
2005 * @property_value: a #GValue which must hold enum values.
2007 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2008 * or gtk_widget_class_install_style_property_parser() which parses a single
2009 * enumeration value.
2011 * The enumeration value can be specified by its name, its nickname or
2012 * its numeric value. For consistency with flags parsing, the value
2013 * may be surrounded by parentheses.
2015 * Return value: %TRUE if @gstring could be parsed and @property_value
2016 * has been set to the resulting #GEnumValue.
2019 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2020 const GString *gstring,
2021 GValue *property_value)
2023 gboolean need_closing_brace = FALSE, success = FALSE;
2025 GEnumValue *enum_value = NULL;
2027 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2028 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2030 scanner = gtk_rc_scanner_new ();
2031 g_scanner_input_text (scanner, gstring->str, gstring->len);
2033 /* we just want to parse _one_ value, but for consistency with flags parsing
2034 * we support optional parenthesis
2036 g_scanner_get_next_token (scanner);
2037 if (scanner->token == '(')
2039 need_closing_brace = TRUE;
2040 g_scanner_get_next_token (scanner);
2042 if (scanner->token == G_TOKEN_IDENTIFIER)
2044 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2046 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2048 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2051 g_value_set_enum (property_value, enum_value->value);
2055 else if (scanner->token == G_TOKEN_INT)
2057 g_value_set_enum (property_value, scanner->value.v_int);
2060 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2062 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2065 g_scanner_destroy (scanner);
2071 parse_flags_value (GScanner *scanner,
2075 g_scanner_get_next_token (scanner);
2076 if (scanner->token == G_TOKEN_IDENTIFIER)
2078 GFlagsValue *flags_value;
2080 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2082 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2085 *number |= flags_value->value;
2086 return G_TOKEN_NONE;
2089 else if (scanner->token == G_TOKEN_INT)
2091 *number |= scanner->value.v_int;
2092 return G_TOKEN_NONE;
2094 return G_TOKEN_IDENTIFIER;
2098 * gtk_rc_property_parse_flags:
2099 * @pspec: a #GParamSpec
2100 * @gstring: the #GString to be parsed
2101 * @property_value: a #GValue which must hold flags values.
2103 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2104 * or gtk_widget_class_install_style_property_parser() which parses flags.
2106 * Flags can be specified by their name, their nickname or
2107 * numerically. Multiple flags can be specified in the form
2108 * <literal>"( flag1 | flag2 | ... )"</literal>.
2110 * Return value: %TRUE if @gstring could be parsed and @property_value
2111 * has been set to the resulting flags value.
2114 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2115 const GString *gstring,
2116 GValue *property_value)
2119 gboolean success = FALSE;
2122 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2123 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2125 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2126 scanner = gtk_rc_scanner_new ();
2127 g_scanner_input_text (scanner, gstring->str, gstring->len);
2129 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2130 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2131 scanner->next_token == G_TOKEN_INT)
2133 guint token, flags_value = 0;
2135 token = parse_flags_value (scanner, class, &flags_value);
2137 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2140 g_value_set_flags (property_value, flags_value);
2144 else if (g_scanner_get_next_token (scanner) == '(')
2146 guint token, flags_value = 0;
2148 /* parse first value */
2149 token = parse_flags_value (scanner, class, &flags_value);
2151 /* parse nth values, preceeded by '|' */
2152 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2153 token = parse_flags_value (scanner, class, &flags_value);
2155 /* done, last token must have closed expression */
2156 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2157 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2159 g_value_set_flags (property_value, flags_value);
2163 g_scanner_destroy (scanner);
2169 get_braced_int (GScanner *scanner,
2176 g_scanner_get_next_token (scanner);
2177 if (scanner->token != '{')
2181 g_scanner_get_next_token (scanner);
2182 if (scanner->token != G_TOKEN_INT)
2185 *value = scanner->value.v_int;
2189 g_scanner_get_next_token (scanner);
2190 if (scanner->token != '}')
2195 g_scanner_get_next_token (scanner);
2196 if (scanner->token != ',')
2204 * gtk_rc_property_parse_requisition:
2205 * @pspec: a #GParamSpec
2206 * @gstring: the #GString to be parsed
2207 * @property_value: a #GValue which must hold boxed values.
2209 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2210 * or gtk_widget_class_install_style_property_parser() which parses a
2211 * requisition in the form
2212 * <literal>"{ width, height }"</literal> for integers %width and %height.
2214 * Return value: %TRUE if @gstring could be parsed and @property_value
2215 * has been set to the resulting #GtkRequisition.
2218 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2219 const GString *gstring,
2220 GValue *property_value)
2222 GtkRequisition requisition;
2224 gboolean success = FALSE;
2226 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2227 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2229 scanner = gtk_rc_scanner_new ();
2230 g_scanner_input_text (scanner, gstring->str, gstring->len);
2232 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2233 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2235 g_value_set_boxed (property_value, &requisition);
2239 g_scanner_destroy (scanner);
2245 * gtk_rc_property_parse_border:
2246 * @pspec: a #GParamSpec
2247 * @gstring: the #GString to be parsed
2248 * @property_value: a #GValue which must hold boxed values.
2250 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2251 * or gtk_widget_class_install_style_property_parser() which parses
2252 * borders in the form
2253 * <literal>"{ left, right, top, bottom }"</literal> for integers
2254 * %left, %right, %top and %bottom.
2256 * Return value: %TRUE if @gstring could be parsed and @property_value
2257 * has been set to the resulting #GtkBorder.
2260 gtk_rc_property_parse_border (const GParamSpec *pspec,
2261 const GString *gstring,
2262 GValue *property_value)
2266 gboolean success = FALSE;
2267 int left, right, top, bottom;
2269 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2270 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2272 scanner = gtk_rc_scanner_new ();
2273 g_scanner_input_text (scanner, gstring->str, gstring->len);
2275 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2276 get_braced_int (scanner, FALSE, FALSE, &right) &&
2277 get_braced_int (scanner, FALSE, FALSE, &top) &&
2278 get_braced_int (scanner, FALSE, TRUE, &bottom))
2281 border.right = right;
2283 border.bottom = bottom;
2284 g_value_set_boxed (property_value, &border);
2288 g_scanner_destroy (scanner);
2294 _gtk_settings_handle_event (GdkEventSetting *event)
2296 GtkSettings *settings;
2300 settings = gtk_settings_get_for_screen (gdk_window_get_screen (event->window));
2301 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2305 property_id = pspec->param_id;
2307 if (property_id == PROP_COLOR_SCHEME)
2309 GValue value = { 0, };
2311 g_value_init (&value, G_TYPE_STRING);
2312 if (!gdk_screen_get_setting (settings->screen, pspec->name, &value))
2313 g_value_set_static_string (&value, "");
2314 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2315 g_value_unset (&value);
2317 g_object_notify (G_OBJECT (settings), pspec->name);
2322 reset_rc_values_foreach (GQuark key_id,
2326 GtkSettingsValuePrivate *qvalue = data;
2327 GSList **to_reset = user_data;
2329 if (qvalue->source == GTK_SETTINGS_SOURCE_RC_FILE)
2330 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2334 _gtk_settings_reset_rc_values (GtkSettings *settings)
2336 GSList *to_reset = NULL;
2338 GParamSpec **pspecs, **p;
2341 /* Remove any queued settings
2343 g_datalist_foreach (&settings->queued_settings,
2344 reset_rc_values_foreach,
2347 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2349 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2350 g_datalist_id_remove_data (&settings->queued_settings, key_id);
2353 g_slist_free (to_reset);
2355 /* Now reset the active settings
2357 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2360 g_object_freeze_notify (G_OBJECT (settings));
2361 for (p = pspecs; *p; p++)
2363 if (settings->property_values[i].source == GTK_SETTINGS_SOURCE_RC_FILE)
2365 GParamSpec *pspec = *p;
2367 g_param_value_set_default (pspec, &settings->property_values[i].value);
2368 g_object_notify (G_OBJECT (settings), pspec->name);
2372 g_object_thaw_notify (G_OBJECT (settings));
2377 settings_update_double_click (GtkSettings *settings)
2379 if (gdk_screen_get_number (settings->screen) == 0)
2381 GdkDisplay *display = gdk_screen_get_display (settings->screen);
2382 gint double_click_time;
2383 gint double_click_distance;
2385 g_object_get (settings,
2386 "gtk-double-click-time", &double_click_time,
2387 "gtk-double-click-distance", &double_click_distance,
2390 gdk_display_set_double_click_time (display, double_click_time);
2391 gdk_display_set_double_click_distance (display, double_click_distance);
2396 settings_update_modules (GtkSettings *settings)
2400 g_object_get (settings,
2401 "gtk-modules", &modules,
2404 _gtk_modules_settings_changed (settings, modules);
2409 #ifdef GDK_WINDOWING_X11
2411 settings_update_cursor_theme (GtkSettings *settings)
2413 GdkDisplay *display = gdk_screen_get_display (settings->screen);
2414 gchar *theme = NULL;
2417 g_object_get (settings,
2418 "gtk-cursor-theme-name", &theme,
2419 "gtk-cursor-theme-size", &size,
2422 gdk_x11_display_set_cursor_theme (display, theme, size);
2428 settings_update_font_options (GtkSettings *settings)
2431 gchar *hint_style_str;
2432 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2434 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2436 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2437 cairo_font_options_t *options;
2439 g_object_get (settings,
2440 "gtk-xft-antialias", &antialias,
2441 "gtk-xft-hinting", &hinting,
2442 "gtk-xft-hintstyle", &hint_style_str,
2443 "gtk-xft-rgba", &rgba_str,
2446 options = cairo_font_options_create ();
2448 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2450 if (hinting >= 0 && !hinting)
2452 hint_style = CAIRO_HINT_STYLE_NONE;
2454 else if (hint_style_str)
2456 if (strcmp (hint_style_str, "hintnone") == 0)
2457 hint_style = CAIRO_HINT_STYLE_NONE;
2458 else if (strcmp (hint_style_str, "hintslight") == 0)
2459 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2460 else if (strcmp (hint_style_str, "hintmedium") == 0)
2461 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2462 else if (strcmp (hint_style_str, "hintfull") == 0)
2463 hint_style = CAIRO_HINT_STYLE_FULL;
2466 g_free (hint_style_str);
2468 cairo_font_options_set_hint_style (options, hint_style);
2472 if (strcmp (rgba_str, "rgb") == 0)
2473 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2474 else if (strcmp (rgba_str, "bgr") == 0)
2475 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2476 else if (strcmp (rgba_str, "vrgb") == 0)
2477 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2478 else if (strcmp (rgba_str, "vbgr") == 0)
2479 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2484 cairo_font_options_set_subpixel_order (options, subpixel_order);
2486 if (antialias >= 0 && !antialias)
2487 antialias_mode = CAIRO_ANTIALIAS_NONE;
2488 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2489 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2490 else if (antialias >= 0)
2491 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2493 cairo_font_options_set_antialias (options, antialias_mode);
2495 gdk_screen_set_font_options (settings->screen, options);
2497 cairo_font_options_destroy (options);
2500 #ifdef GDK_WINDOWING_X11
2502 settings_update_fontconfig (GtkSettings *settings)
2504 static guint last_update_timestamp;
2505 static gboolean last_update_needed;
2509 g_object_get (settings,
2510 "gtk-fontconfig-timestamp", ×tamp,
2513 /* if timestamp is the same as last_update_timestamp, we already have
2514 * updated fontconig on this timestamp (another screen requested it perhaps?),
2515 * just return the cached result.*/
2517 if (timestamp != last_update_timestamp)
2519 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2520 gboolean update_needed = FALSE;
2523 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2525 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2526 if (FcInitReinitialize ())
2527 update_needed = TRUE;
2530 last_update_timestamp = timestamp;
2531 last_update_needed = update_needed;
2534 return last_update_needed;
2536 #endif /* GDK_WINDOWING_X11 */
2539 settings_update_resolution (GtkSettings *settings)
2544 g_object_get (settings,
2545 "gtk-xft-dpi", &dpi_int,
2549 dpi = dpi_int / 1024.;
2553 gdk_screen_set_resolution (settings->screen, dpi);
2558 GHashTable *color_hash;
2559 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2560 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2564 color_scheme_data_free (ColorSchemeData *data)
2568 g_hash_table_unref (data->color_hash);
2570 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2572 if (data->tables[i])
2573 g_hash_table_unref (data->tables[i]);
2574 g_free (data->lastentry[i]);
2577 g_slice_free (ColorSchemeData, data);
2581 settings_update_color_scheme (GtkSettings *settings)
2583 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2585 ColorSchemeData *data;
2586 GValue value = { 0, };
2588 data = g_slice_new0 (ColorSchemeData);
2589 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2590 (GDestroyNotify) gdk_color_free);
2591 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2592 data, (GDestroyNotify) color_scheme_data_free);
2594 g_value_init (&value, G_TYPE_STRING);
2595 if (gdk_screen_get_setting (settings->screen, "gtk-color-scheme", &value))
2597 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2598 g_value_unset (&value);
2604 settings_update_theme (GtkSettings *settings)
2606 static GQuark quark_theme_name = 0;
2607 GtkCssProvider *provider, *new_provider = NULL;
2608 gboolean prefer_dark_theme;
2611 if (G_UNLIKELY (!quark_theme_name))
2612 quark_theme_name = g_quark_from_static_string ("gtk-settings-theme-name");
2614 provider = g_object_get_qdata (G_OBJECT (settings), quark_theme_name);
2616 g_object_get (settings,
2617 "gtk-theme-name", &theme_name,
2618 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2621 if (theme_name && *theme_name)
2623 gchar *variant = NULL;
2625 if (prefer_dark_theme)
2628 new_provider = gtk_css_provider_get_named (theme_name, variant);
2629 g_free (theme_name);
2632 if (new_provider != provider)
2635 gtk_style_context_remove_provider_for_screen (settings->screen,
2636 GTK_STYLE_PROVIDER (provider));
2640 gtk_style_context_add_provider_for_screen (settings->screen,
2641 GTK_STYLE_PROVIDER (new_provider),
2642 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2643 g_object_ref (new_provider);
2646 g_object_set_qdata_full (G_OBJECT (settings), quark_theme_name,
2647 new_provider, (GDestroyNotify) g_object_unref);
2652 add_color_to_hash (gchar *name,
2658 old = g_hash_table_lookup (target, name);
2659 if (!old || !gdk_color_equal (old, color))
2661 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2670 add_colors_to_hash_from_string (GHashTable *hash,
2671 const gchar *colors)
2673 gchar *s, *p, *name;
2675 gboolean changed = FALSE;
2678 copy = g_strdup (colors);
2683 p = strchr (s, ':');
2698 if (*s == '\n' || *s == ';')
2707 if (gdk_color_parse (p, &color))
2708 changed |= add_color_to_hash (name, &color, hash);
2717 update_color_hash (ColorSchemeData *data,
2719 GtkSettingsSource source)
2721 gboolean changed = FALSE;
2723 GHashTable *old_hash;
2724 GHashTableIter iter;
2728 if ((str == NULL || *str == '\0') &&
2729 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2732 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2735 /* For the RC_FILE source we merge the values rather than over-writing
2736 * them, since multiple rc files might define independent sets of colors
2738 if ((source != GTK_SETTINGS_SOURCE_RC_FILE) &&
2739 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2741 g_hash_table_unref (data->tables[source]);
2742 data->tables[source] = NULL;
2743 changed = TRUE; /* We can't rely on the code below since str might be "" */
2746 if (data->tables[source] == NULL)
2747 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2749 (GDestroyNotify) gdk_color_free);
2751 g_free (data->lastentry[source]);
2752 data->lastentry[source] = g_strdup (str);
2754 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2759 /* Rebuild the merged hash table. */
2760 if (data->color_hash)
2762 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2763 (GDestroyNotify) gdk_color_free);
2765 g_hash_table_iter_init (&iter, data->color_hash);
2766 while (g_hash_table_iter_next (&iter, &name, &color))
2768 g_hash_table_insert (old_hash, name, color);
2769 g_hash_table_iter_steal (&iter);
2777 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2779 if (data->tables[i])
2780 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2786 /* now check if the merged hash has changed */
2788 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2792 GHashTableIter iter;
2793 gpointer key, value, new_value;
2795 g_hash_table_iter_init (&iter, old_hash);
2796 while (g_hash_table_iter_next (&iter, &key, &value))
2798 new_value = g_hash_table_lookup (data->color_hash, key);
2799 if (!new_value || !gdk_color_equal (value, new_value))
2807 g_hash_table_unref (old_hash);
2816 merge_color_scheme (GtkSettings *settings,
2817 const GValue *value,
2818 GtkSettingsSource source)
2820 ColorSchemeData *data;
2821 const gchar *colors;
2823 g_object_freeze_notify (G_OBJECT (settings));
2825 colors = g_value_get_string (value);
2827 settings_update_color_scheme (settings);
2829 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2830 "gtk-color-scheme");
2832 if (update_color_hash (data, colors, source))
2833 g_object_notify (G_OBJECT (settings), "color-hash");
2835 g_object_thaw_notify (G_OBJECT (settings));
2839 get_color_hash (GtkSettings *settings)
2841 ColorSchemeData *data;
2843 settings_update_color_scheme (settings);
2845 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2846 "gtk-color-scheme");
2848 return data->color_hash;
2852 append_color_scheme (gpointer key,
2856 gchar *name = (gchar *)key;
2857 GdkColor *color = (GdkColor *)value;
2858 GString *string = (GString *)data;
2860 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2861 name, color->red, color->green, color->blue);
2865 get_color_scheme (GtkSettings *settings)
2867 ColorSchemeData *data;
2870 settings_update_color_scheme (settings);
2872 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2873 "gtk-color-scheme");
2875 string = g_string_new ("");
2877 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2879 return g_string_free (string, FALSE);
2883 _gtk_settings_get_screen (GtkSettings *settings)
2885 return settings->screen;