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 "gtkversion.h"
36 #ifdef GDK_WINDOWING_X11
38 #include <pango/pangofc-fontmap.h>
44 * @Short_description: Sharing settings between applications
47 * GtkSettings provide a mechanism to share global settings between applications.
48 * On the X window system, this sharing is realized by an
49 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
50 * manager that is usually part of the desktop environment, along with utilities
51 * that let the user change these settings. In the absence of an Xsettings manager,
52 * settings can also be specified in RC files.
54 * Applications can override system-wide settings with gtk_settings_set_string_property(),
55 * gtk_settings_set_long_property(), etc. This should be restricted to special
56 * cases though; GtkSettings are not meant as an application configuration
57 * facility. When doing so, you need to be aware that settings that are specific
58 * to individual widgets may not be available before the widget type has been
59 * realized at least once. The following example demonstrates a way to do this:
60 * <informalexample><programlisting>
61 * gtk_init (&argc, &argv);
63 * /* make sure the type is realized */
64 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
66 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
67 * </programlisting></informalexample>
69 * There is one GtkSettings instance per screen. It can be obtained with
70 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
71 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
72 * GtkSettings instance for the default screen.
76 #ifdef GDK_WINDOWING_QUARTZ
77 #define DEFAULT_KEY_THEME "Mac"
79 #define DEFAULT_KEY_THEME NULL
82 #define DEFAULT_TIMEOUT_INITIAL 200
83 #define DEFAULT_TIMEOUT_REPEAT 20
84 #define DEFAULT_TIMEOUT_EXPAND 500
86 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
90 GTK_SETTINGS_SOURCE_DEFAULT,
91 GTK_SETTINGS_SOURCE_RC_FILE,
92 GTK_SETTINGS_SOURCE_XSETTING,
93 GTK_SETTINGS_SOURCE_APPLICATION
96 struct _GtkSettingsValuePrivate
98 GtkSettingsValue public;
99 GtkSettingsSource source;
102 struct _GtkSettingsPropertyValue
105 GtkSettingsSource source;
110 PROP_DOUBLE_CLICK_TIME,
111 PROP_DOUBLE_CLICK_DISTANCE,
113 PROP_CURSOR_BLINK_TIME,
114 PROP_CURSOR_BLINK_TIMEOUT,
117 PROP_ICON_THEME_NAME,
118 PROP_FALLBACK_ICON_THEME,
121 PROP_DND_DRAG_THRESHOLD,
125 #ifdef GDK_WINDOWING_X11
131 PROP_CURSOR_THEME_NAME,
132 PROP_CURSOR_THEME_SIZE,
134 PROP_ALTERNATIVE_BUTTON_ORDER,
135 PROP_ALTERNATIVE_SORT_ARROWS,
136 PROP_SHOW_INPUT_METHOD_MENU,
137 PROP_SHOW_UNICODE_MENU,
138 PROP_TIMEOUT_INITIAL,
142 PROP_ENABLE_ANIMATIONS,
143 PROP_TOUCHSCREEN_MODE,
144 PROP_TOOLTIP_TIMEOUT,
145 PROP_TOOLTIP_BROWSE_TIMEOUT,
146 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
147 PROP_KEYNAV_CURSOR_ONLY,
148 PROP_KEYNAV_WRAP_AROUND,
151 PROP_FILE_CHOOSER_BACKEND,
153 PROP_PRINT_PREVIEW_COMMAND,
154 PROP_ENABLE_MNEMONICS,
156 PROP_RECENT_FILES_LIMIT,
158 PROP_RECENT_FILES_MAX_AGE,
159 PROP_FONTCONFIG_TIMESTAMP,
160 PROP_SOUND_THEME_NAME,
161 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
162 PROP_ENABLE_EVENT_SOUNDS,
163 PROP_ENABLE_TOOLTIPS,
165 PROP_TOOLBAR_ICON_SIZE,
167 PROP_APPLICATION_PREFER_DARK_THEME,
169 PROP_ENTRY_SELECT_ON_FOCUS,
170 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
172 PROP_MENU_BAR_POPUP_DELAY,
173 PROP_SCROLLED_WINDOW_PLACEMENT,
174 PROP_CAN_CHANGE_ACCELS,
175 PROP_MENU_POPUP_DELAY,
176 PROP_MENU_POPDOWN_DELAY,
177 PROP_LABEL_SELECT_ON_FOCUS,
179 PROP_IM_PREEDIT_STYLE,
183 /* --- prototypes --- */
184 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
186 static void gtk_settings_finalize (GObject *object);
187 static void gtk_settings_get_property (GObject *object,
191 static void gtk_settings_set_property (GObject *object,
195 static void gtk_settings_notify (GObject *object,
197 static guint settings_install_property_parser (GtkSettingsClass *class,
199 GtkRcPropertyParser parser);
200 static void settings_update_double_click (GtkSettings *settings);
201 static void settings_update_modules (GtkSettings *settings);
203 #ifdef GDK_WINDOWING_X11
204 static void settings_update_cursor_theme (GtkSettings *settings);
205 static void settings_update_resolution (GtkSettings *settings);
206 static void settings_update_font_options (GtkSettings *settings);
207 static gboolean settings_update_fontconfig (GtkSettings *settings);
209 static void settings_update_color_scheme (GtkSettings *settings);
210 static void settings_update_theme (GtkSettings *settings);
212 static void merge_color_scheme (GtkSettings *settings,
214 GtkSettingsSource source);
215 static gchar *get_color_scheme (GtkSettings *settings);
216 static GHashTable *get_color_hash (GtkSettings *settings);
218 /* the default palette for GtkColorSelelection */
219 static const gchar default_color_palette[] =
220 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
221 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
223 /* --- variables --- */
224 static GQuark quark_property_parser = 0;
225 static GSList *object_list = NULL;
226 static guint class_n_properties = 0;
229 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
230 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
231 gtk_settings_provider_iface_init));
233 /* --- functions --- */
235 gtk_settings_init (GtkSettings *settings)
237 GParamSpec **pspecs, **p;
240 g_datalist_init (&settings->queued_settings);
241 object_list = g_slist_prepend (object_list, settings);
243 /* build up property array for all yet existing properties and queue
244 * notification for them (at least notification for internal properties
245 * will instantly be caught)
247 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
248 for (p = pspecs; *p; p++)
249 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
251 settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
253 g_object_freeze_notify (G_OBJECT (settings));
254 for (p = pspecs; *p; p++)
256 GParamSpec *pspec = *p;
258 if (pspec->owner_type != G_OBJECT_TYPE (settings))
260 g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
261 g_param_value_set_default (pspec, &settings->property_values[i].value);
262 g_object_notify (G_OBJECT (settings), pspec->name);
263 settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
266 g_object_thaw_notify (G_OBJECT (settings));
271 gtk_settings_class_init (GtkSettingsClass *class)
273 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
276 gobject_class->finalize = gtk_settings_finalize;
277 gobject_class->get_property = gtk_settings_get_property;
278 gobject_class->set_property = gtk_settings_set_property;
279 gobject_class->notify = gtk_settings_notify;
281 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
282 result = settings_install_property_parser (class,
283 g_param_spec_int ("gtk-double-click-time",
284 P_("Double Click Time"),
285 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
287 GTK_PARAM_READWRITE),
289 g_assert (result == PROP_DOUBLE_CLICK_TIME);
290 result = settings_install_property_parser (class,
291 g_param_spec_int ("gtk-double-click-distance",
292 P_("Double Click Distance"),
293 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
295 GTK_PARAM_READWRITE),
297 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
300 * GtkSettings:gtk-cursor-blink:
302 * Whether the cursor should blink.
304 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
305 * which allows more flexible control over cursor blinking.
307 result = settings_install_property_parser (class,
308 g_param_spec_boolean ("gtk-cursor-blink",
310 P_("Whether the cursor should blink"),
312 GTK_PARAM_READWRITE),
314 g_assert (result == PROP_CURSOR_BLINK);
315 result = settings_install_property_parser (class,
316 g_param_spec_int ("gtk-cursor-blink-time",
317 P_("Cursor Blink Time"),
318 P_("Length of the cursor blink cycle, in milliseconds"),
320 GTK_PARAM_READWRITE),
322 g_assert (result == PROP_CURSOR_BLINK_TIME);
325 * GtkSettings:gtk-cursor-blink-timeout:
327 * Time after which the cursor stops blinking, in seconds.
328 * The timer is reset after each user interaction.
330 * Setting this to zero has the same effect as setting
331 * #GtkSettings:gtk-cursor-blink to %FALSE.
335 result = settings_install_property_parser (class,
336 g_param_spec_int ("gtk-cursor-blink-timeout",
337 P_("Cursor Blink Timeout"),
338 P_("Time after which the cursor stops blinking, in seconds"),
339 1, G_MAXINT, G_MAXINT,
340 GTK_PARAM_READWRITE),
342 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
343 result = settings_install_property_parser (class,
344 g_param_spec_boolean ("gtk-split-cursor",
346 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
348 GTK_PARAM_READWRITE),
350 g_assert (result == PROP_SPLIT_CURSOR);
351 result = settings_install_property_parser (class,
352 g_param_spec_string ("gtk-theme-name",
354 P_("Name of theme RC file to load"),
356 GTK_PARAM_READWRITE),
358 g_assert (result == PROP_THEME_NAME);
360 result = settings_install_property_parser (class,
361 g_param_spec_string ("gtk-icon-theme-name",
362 P_("Icon Theme Name"),
363 P_("Name of icon theme to use"),
365 GTK_PARAM_READWRITE),
367 g_assert (result == PROP_ICON_THEME_NAME);
369 result = settings_install_property_parser (class,
370 g_param_spec_string ("gtk-fallback-icon-theme",
371 P_("Fallback Icon Theme Name"),
372 P_("Name of a icon theme to fall back to"),
374 GTK_PARAM_READWRITE),
376 g_assert (result == PROP_FALLBACK_ICON_THEME);
378 result = settings_install_property_parser (class,
379 g_param_spec_string ("gtk-key-theme-name",
380 P_("Key Theme Name"),
381 P_("Name of key theme RC file to load"),
383 GTK_PARAM_READWRITE),
385 g_assert (result == PROP_KEY_THEME_NAME);
387 result = settings_install_property_parser (class,
388 g_param_spec_string ("gtk-menu-bar-accel",
389 P_("Menu bar accelerator"),
390 P_("Keybinding to activate the menu bar"),
392 GTK_PARAM_READWRITE),
394 g_assert (result == PROP_MENU_BAR_ACCEL);
396 result = settings_install_property_parser (class,
397 g_param_spec_int ("gtk-dnd-drag-threshold",
398 P_("Drag threshold"),
399 P_("Number of pixels the cursor can move before dragging"),
401 GTK_PARAM_READWRITE),
403 g_assert (result == PROP_DND_DRAG_THRESHOLD);
405 result = settings_install_property_parser (class,
406 g_param_spec_string ("gtk-font-name",
408 P_("Name of default font to use"),
410 GTK_PARAM_READWRITE),
412 g_assert (result == PROP_FONT_NAME);
415 * GtkSettings:gtk-icon-sizes:
417 * A list of icon sizes. The list is separated by colons, and
420 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
422 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
423 * GTK+ itself use the following named icon sizes: gtk-menu,
424 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
425 * gtk-dialog. Applications can register their own named icon
426 * sizes with gtk_icon_size_register().
428 result = settings_install_property_parser (class,
429 g_param_spec_string ("gtk-icon-sizes",
431 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
433 GTK_PARAM_READWRITE),
435 g_assert (result == PROP_ICON_SIZES);
437 result = settings_install_property_parser (class,
438 g_param_spec_string ("gtk-modules",
440 P_("List of currently active GTK modules"),
442 GTK_PARAM_READWRITE),
444 g_assert (result == PROP_MODULES);
446 #ifdef GDK_WINDOWING_X11
447 result = settings_install_property_parser (class,
448 g_param_spec_int ("gtk-xft-antialias",
450 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
452 GTK_PARAM_READWRITE),
455 g_assert (result == PROP_XFT_ANTIALIAS);
457 result = settings_install_property_parser (class,
458 g_param_spec_int ("gtk-xft-hinting",
460 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
462 GTK_PARAM_READWRITE),
465 g_assert (result == PROP_XFT_HINTING);
467 result = settings_install_property_parser (class,
468 g_param_spec_string ("gtk-xft-hintstyle",
469 P_("Xft Hint Style"),
470 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
472 GTK_PARAM_READWRITE),
475 g_assert (result == PROP_XFT_HINTSTYLE);
477 result = settings_install_property_parser (class,
478 g_param_spec_string ("gtk-xft-rgba",
480 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
482 GTK_PARAM_READWRITE),
485 g_assert (result == PROP_XFT_RGBA);
487 result = settings_install_property_parser (class,
488 g_param_spec_int ("gtk-xft-dpi",
490 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
492 GTK_PARAM_READWRITE),
495 g_assert (result == PROP_XFT_DPI);
497 result = settings_install_property_parser (class,
498 g_param_spec_string ("gtk-cursor-theme-name",
499 P_("Cursor theme name"),
500 P_("Name of the cursor theme to use, or NULL to use the default theme"),
502 GTK_PARAM_READWRITE),
504 g_assert (result == PROP_CURSOR_THEME_NAME);
506 result = settings_install_property_parser (class,
507 g_param_spec_int ("gtk-cursor-theme-size",
508 P_("Cursor theme size"),
509 P_("Size to use for cursors, or 0 to use the default size"),
511 GTK_PARAM_READWRITE),
514 g_assert (result == PROP_CURSOR_THEME_SIZE);
516 #endif /* GDK_WINDOWING_X11 */
517 result = settings_install_property_parser (class,
518 g_param_spec_boolean ("gtk-alternative-button-order",
519 P_("Alternative button order"),
520 P_("Whether buttons in dialogs should use the alternative button order"),
522 GTK_PARAM_READWRITE),
524 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
527 * GtkSettings:gtk-alternative-sort-arrows:
529 * Controls the direction of the sort indicators in sorted list and tree
530 * views. By default an arrow pointing down means the column is sorted
531 * in ascending order. When set to %TRUE, this order will be inverted.
535 result = settings_install_property_parser (class,
536 g_param_spec_boolean ("gtk-alternative-sort-arrows",
537 P_("Alternative sort indicator direction"),
538 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
540 GTK_PARAM_READWRITE),
542 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
544 result = settings_install_property_parser (class,
545 g_param_spec_boolean ("gtk-show-input-method-menu",
546 P_("Show the 'Input Methods' menu"),
547 P_("Whether the context menus of entries and text views should offer to change the input method"),
549 GTK_PARAM_READWRITE),
551 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
553 result = settings_install_property_parser (class,
554 g_param_spec_boolean ("gtk-show-unicode-menu",
555 P_("Show the 'Insert Unicode Control Character' menu"),
556 P_("Whether the context menus of entries and text views should offer to insert control characters"),
558 GTK_PARAM_READWRITE),
560 g_assert (result == PROP_SHOW_UNICODE_MENU);
562 result = settings_install_property_parser (class,
563 g_param_spec_int ("gtk-timeout-initial",
565 P_("Starting value for timeouts, when button is pressed"),
566 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
567 GTK_PARAM_READWRITE),
570 g_assert (result == PROP_TIMEOUT_INITIAL);
572 result = settings_install_property_parser (class,
573 g_param_spec_int ("gtk-timeout-repeat",
574 P_("Repeat timeout"),
575 P_("Repeat value for timeouts, when button is pressed"),
576 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
577 GTK_PARAM_READWRITE),
580 g_assert (result == PROP_TIMEOUT_REPEAT);
582 result = settings_install_property_parser (class,
583 g_param_spec_int ("gtk-timeout-expand",
584 P_("Expand timeout"),
585 P_("Expand value for timeouts, when a widget is expanding a new region"),
586 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
587 GTK_PARAM_READWRITE),
590 g_assert (result == PROP_TIMEOUT_EXPAND);
593 * GtkSettings:gtk-color-scheme:
595 * A palette of named colors for use in themes. The format of the string is
601 * Color names must be acceptable as identifiers in the
602 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
603 * color specifications must be in the format accepted by
606 * Note that due to the way the color tables from different sources are
607 * merged, color specifications will be converted to hexadecimal form
608 * when getting this property.
610 * Starting with GTK+ 2.12, the entries can alternatively be separated
611 * by ';' instead of newlines:
613 * name1: color1; name2: color2; ...
618 result = settings_install_property_parser (class,
619 g_param_spec_string ("gtk-color-scheme",
621 P_("A palette of named colors for use in themes"),
623 GTK_PARAM_READWRITE),
626 g_assert (result == PROP_COLOR_SCHEME);
628 result = settings_install_property_parser (class,
629 g_param_spec_boolean ("gtk-enable-animations",
630 P_("Enable Animations"),
631 P_("Whether to enable toolkit-wide animations."),
633 GTK_PARAM_READWRITE),
636 g_assert (result == PROP_ENABLE_ANIMATIONS);
639 * GtkSettings:gtk-touchscreen-mode:
641 * When %TRUE, there are no motion notify events delivered on this screen,
642 * and widgets can't use the pointer hovering them for any essential
647 result = settings_install_property_parser (class,
648 g_param_spec_boolean ("gtk-touchscreen-mode",
649 P_("Enable Touchscreen Mode"),
650 P_("When TRUE, there are no motion notify events delivered on this screen"),
652 GTK_PARAM_READWRITE),
655 g_assert (result == PROP_TOUCHSCREEN_MODE);
658 * GtkSettings:gtk-tooltip-timeout:
660 * Time, in milliseconds, after which a tooltip could appear if the
661 * cursor is hovering on top of a widget.
665 result = settings_install_property_parser (class,
666 g_param_spec_int ("gtk-tooltip-timeout",
667 P_("Tooltip timeout"),
668 P_("Timeout before tooltip is shown"),
671 GTK_PARAM_READWRITE),
674 g_assert (result == PROP_TOOLTIP_TIMEOUT);
677 * GtkSettings:gtk-tooltip-browse-timeout:
679 * Controls the time after which tooltips will appear when
680 * browse mode is enabled, in milliseconds.
682 * Browse mode is enabled when the mouse pointer moves off an object
683 * where a tooltip was currently being displayed. If the mouse pointer
684 * hits another object before the browse mode timeout expires (see
685 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
686 * amount of milliseconds specified by this setting to popup the tooltip
687 * for the new object.
691 result = settings_install_property_parser (class,
692 g_param_spec_int ("gtk-tooltip-browse-timeout",
693 P_("Tooltip browse timeout"),
694 P_("Timeout before tooltip is shown when browse mode is enabled"),
697 GTK_PARAM_READWRITE),
700 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
703 * GtkSettings:gtk-tooltip-browse-mode-timeout:
705 * Amount of time, in milliseconds, after which the browse mode
708 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
713 result = settings_install_property_parser (class,
714 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
715 P_("Tooltip browse mode timeout"),
716 P_("Timeout after which browse mode is disabled"),
719 GTK_PARAM_READWRITE),
722 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
725 * GtkSettings:gtk-keynav-cursor-only:
727 * When %TRUE, keyboard navigation should be able to reach all widgets
728 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
729 * to be present on the used input device.
733 result = settings_install_property_parser (class,
734 g_param_spec_boolean ("gtk-keynav-cursor-only",
735 P_("Keynav Cursor Only"),
736 P_("When TRUE, there are only cursor keys available to navigate widgets"),
738 GTK_PARAM_READWRITE),
741 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
744 * GtkSettings:gtk-keynav-wrap-around:
746 * When %TRUE, some widgets will wrap around when doing keyboard
747 * navigation, such as menus, menubars and notebooks.
751 result = settings_install_property_parser (class,
752 g_param_spec_boolean ("gtk-keynav-wrap-around",
753 P_("Keynav Wrap Around"),
754 P_("Whether to wrap around when keyboard-navigating widgets"),
756 GTK_PARAM_READWRITE),
759 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
762 * GtkSettings:gtk-error-bell:
764 * When %TRUE, keyboard navigation and other input-related errors
765 * will cause a beep. Since the error bell is implemented using
766 * gdk_window_beep(), the windowing system may offer ways to
767 * configure the error bell in many ways, such as flashing the
768 * window or similar visual effects.
772 result = settings_install_property_parser (class,
773 g_param_spec_boolean ("gtk-error-bell",
775 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
777 GTK_PARAM_READWRITE),
780 g_assert (result == PROP_ERROR_BELL);
783 * GtkSettings:color-hash:
785 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
786 * setting, mapping color names to #GdkColor<!-- -->s.
790 result = settings_install_property_parser (class,
791 g_param_spec_boxed ("color-hash",
793 P_("A hash table representation of the color scheme."),
797 g_assert (result == PROP_COLOR_HASH);
799 result = settings_install_property_parser (class,
800 g_param_spec_string ("gtk-file-chooser-backend",
801 P_("Default file chooser backend"),
802 P_("Name of the GtkFileChooser backend to use by default"),
804 GTK_PARAM_READWRITE),
806 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
809 * GtkSettings:gtk-print-backends:
811 * A comma-separated list of print backends to use in the print
812 * dialog. Available print backends depend on the GTK+ installation,
813 * and may include "file", "cups", "lpr" or "papi".
817 result = settings_install_property_parser (class,
818 g_param_spec_string ("gtk-print-backends",
819 P_("Default print backend"),
820 P_("List of the GtkPrintBackend backends to use by default"),
822 GTK_PARAM_READWRITE),
824 g_assert (result == PROP_PRINT_BACKENDS);
827 * GtkSettings:gtk-print-preview-command:
829 * A command to run for displaying the print preview. The command
830 * should contain a %f placeholder, which will get replaced by
831 * the path to the pdf file. The command may also contain a %s
832 * placeholder, which will get replaced by the path to a file
833 * containing the print settings in the format produced by
834 * gtk_print_settings_to_file().
836 * The preview application is responsible for removing the pdf file
837 * and the print settings file when it is done.
841 result = settings_install_property_parser (class,
842 g_param_spec_string ("gtk-print-preview-command",
843 P_("Default command to run when displaying a print preview"),
844 P_("Command to run when displaying a print preview"),
845 GTK_PRINT_PREVIEW_COMMAND,
846 GTK_PARAM_READWRITE),
848 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
851 * GtkSettings:gtk-enable-mnemonics:
853 * Whether labels and menu items should have visible mnemonics which
858 result = settings_install_property_parser (class,
859 g_param_spec_boolean ("gtk-enable-mnemonics",
860 P_("Enable Mnemonics"),
861 P_("Whether labels should have mnemonics"),
863 GTK_PARAM_READWRITE),
865 g_assert (result == PROP_ENABLE_MNEMONICS);
868 * GtkSettings:gtk-enable-accels:
870 * Whether menu items should have visible accelerators which can be
875 result = settings_install_property_parser (class,
876 g_param_spec_boolean ("gtk-enable-accels",
877 P_("Enable Accelerators"),
878 P_("Whether menu items should have accelerators"),
880 GTK_PARAM_READWRITE),
882 g_assert (result == PROP_ENABLE_ACCELS);
885 * GtkSettings:gtk-recent-files-limit:
887 * The number of recently used files that should be displayed by default by
888 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
889 * -1 means every recently used file stored.
893 result = settings_install_property_parser (class,
894 g_param_spec_int ("gtk-recent-files-limit",
895 P_("Recent Files Limit"),
896 P_("Number of recently used files"),
899 GTK_PARAM_READWRITE),
901 g_assert (result == PROP_RECENT_FILES_LIMIT);
904 * GtkSettings:gtk-im-module:
906 * Which IM (input method) module should be used by default. This is the
907 * input method that will be used if the user has not explicitly chosen
908 * another input method from the IM context menu.
910 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
912 result = settings_install_property_parser (class,
913 g_param_spec_string ("gtk-im-module",
914 P_("Default IM module"),
915 P_("Which IM module should be used by default"),
917 GTK_PARAM_READWRITE),
919 g_assert (result == PROP_IM_MODULE);
922 * GtkSettings:gtk-recent-files-max-age:
924 * The maximum age, in days, of the items inside the recently used
925 * resources list. Items older than this setting will be excised
926 * from the list. If set to 0, the list will always be empty; if
927 * set to -1, no item will be removed.
931 result = settings_install_property_parser (class,
932 g_param_spec_int ("gtk-recent-files-max-age",
933 P_("Recent Files Max Age"),
934 P_("Maximum age of recently used files, in days"),
937 GTK_PARAM_READWRITE),
939 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
941 result = settings_install_property_parser (class,
942 g_param_spec_uint ("gtk-fontconfig-timestamp",
943 P_("Fontconfig configuration timestamp"),
944 P_("Timestamp of current fontconfig configuration"),
946 GTK_PARAM_READWRITE),
949 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
952 * GtkSettings:gtk-sound-theme-name:
954 * The XDG sound theme to use for event sounds.
956 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
957 * for more information on event sounds and sound themes.
959 * GTK+ itself does not support event sounds, you have to use a loadable
960 * module like the one that comes with libcanberra.
964 result = settings_install_property_parser (class,
965 g_param_spec_string ("gtk-sound-theme-name",
966 P_("Sound Theme Name"),
967 P_("XDG sound theme name"),
969 GTK_PARAM_READWRITE),
971 g_assert (result == PROP_SOUND_THEME_NAME);
974 * GtkSettings:gtk-enable-input-feedback-sounds:
976 * Whether to play event sounds as feedback to user input.
978 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
979 * for more information on event sounds and sound themes.
981 * GTK+ itself does not support event sounds, you have to use a loadable
982 * module like the one that comes with libcanberra.
986 result = settings_install_property_parser (class,
987 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
988 /* Translators: this means sounds that are played as feedback to user input */
989 P_("Audible Input Feedback"),
990 P_("Whether to play event sounds as feedback to user input"),
992 GTK_PARAM_READWRITE),
994 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
997 * GtkSettings:gtk-enable-event-sounds:
999 * Whether to play any event sounds at all.
1001 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1002 * for more information on event sounds and sound themes.
1004 * GTK+ itself does not support event sounds, you have to use a loadable
1005 * module like the one that comes with libcanberra.
1009 result = settings_install_property_parser (class,
1010 g_param_spec_boolean ("gtk-enable-event-sounds",
1011 P_("Enable Event Sounds"),
1012 P_("Whether to play any event sounds at all"),
1014 GTK_PARAM_READWRITE),
1016 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1019 * GtkSettings:gtk-enable-tooltips:
1021 * Whether tooltips should be shown on widgets.
1025 result = settings_install_property_parser (class,
1026 g_param_spec_boolean ("gtk-enable-tooltips",
1027 P_("Enable Tooltips"),
1028 P_("Whether tooltips should be shown on widgets"),
1030 GTK_PARAM_READWRITE),
1032 g_assert (result == PROP_ENABLE_TOOLTIPS);
1035 * GtkSettings:toolbar-style:
1037 * The size of icons in default toolbars.
1039 result = settings_install_property_parser (class,
1040 g_param_spec_enum ("gtk-toolbar-style",
1041 P_("Toolbar style"),
1042 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1043 GTK_TYPE_TOOLBAR_STYLE,
1045 GTK_PARAM_READWRITE),
1046 gtk_rc_property_parse_enum);
1047 g_assert (result == PROP_TOOLBAR_STYLE);
1050 * GtkSettings:toolbar-icon-size:
1052 * The size of icons in default toolbars.
1054 result = settings_install_property_parser (class,
1055 g_param_spec_enum ("gtk-toolbar-icon-size",
1056 P_("Toolbar Icon Size"),
1057 P_("The size of icons in default toolbars."),
1059 GTK_ICON_SIZE_LARGE_TOOLBAR,
1060 GTK_PARAM_READWRITE),
1061 gtk_rc_property_parse_enum);
1062 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1065 * GtkSettings:gtk-auto-mnemonics:
1067 * Whether mnemonics should be automatically shown and hidden when the user
1068 * presses the mnemonic activator.
1072 result = settings_install_property_parser (class,
1073 g_param_spec_boolean ("gtk-auto-mnemonics",
1074 P_("Auto Mnemonics"),
1075 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1077 GTK_PARAM_READWRITE),
1079 g_assert (result == PROP_AUTO_MNEMONICS);
1082 * GtkSettings:gtk-application-prefer-dark-theme:
1084 * Whether the application prefers to use a dark theme. If a GTK+ theme
1085 * includes a dark variant, it will be used instead of the configured
1088 * Some applications benefit from minimizing the amount of light pollution that
1089 * interferes with the content. Good candidates for dark themes are photo and
1090 * video editors that make the actual content get all the attention and minimize
1091 * the distraction of the chrome.
1093 * Dark themes should not be used for documents, where large spaces are white/light
1094 * and the dark chrome creates too much contrast (web browser, text editor...).
1098 result = settings_install_property_parser (class,
1099 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1100 P_("Application prefers a dark theme"),
1101 P_("Whether the application prefers to have a dark theme."),
1103 GTK_PARAM_READWRITE),
1105 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1108 * GtkSettings::gtk-button-images:
1110 * Whether images should be shown on buttons
1114 result = settings_install_property_parser (class,
1115 g_param_spec_boolean ("gtk-button-images",
1116 P_("Show button images"),
1117 P_("Whether images should be shown on buttons"),
1119 GTK_PARAM_READWRITE),
1121 g_assert (result == PROP_BUTTON_IMAGES);
1123 result = settings_install_property_parser (class,
1124 g_param_spec_boolean ("gtk-entry-select-on-focus",
1125 P_("Select on focus"),
1126 P_("Whether to select the contents of an entry when it is focused"),
1128 GTK_PARAM_READWRITE),
1130 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1133 * GtkSettings:gtk-entry-password-hint-timeout:
1135 * How long to show the last input character in hidden
1136 * entries. This value is in milliseconds. 0 disables showing the
1137 * last char. 600 is a good value for enabling it.
1141 result = settings_install_property_parser (class,
1142 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1143 P_("Password Hint Timeout"),
1144 P_("How long to show the last input character in hidden entries"),
1147 GTK_PARAM_READWRITE),
1149 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1151 result = settings_install_property_parser (class,
1152 g_param_spec_boolean ("gtk-menu-images",
1153 P_("Show menu images"),
1154 P_("Whether images should be shown in menus"),
1156 GTK_PARAM_READWRITE),
1158 g_assert (result == PROP_MENU_IMAGES);
1160 result = settings_install_property_parser (class,
1161 g_param_spec_int ("gtk-menu-bar-popup-delay",
1162 P_("Delay before drop down menus appear"),
1163 P_("Delay before the submenus of a menu bar appear"),
1166 GTK_PARAM_READWRITE),
1168 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1171 * GtkSettings:gtk-scrolled-window-placement:
1173 * Where the contents of scrolled windows are located with respect to the
1174 * scrollbars, if not overridden by the scrolled window's own placement.
1178 result = settings_install_property_parser (class,
1179 g_param_spec_enum ("gtk-scrolled-window-placement",
1180 P_("Scrolled Window Placement"),
1181 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1182 GTK_TYPE_CORNER_TYPE,
1183 GTK_CORNER_TOP_LEFT,
1184 GTK_PARAM_READWRITE),
1185 gtk_rc_property_parse_enum);
1186 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1188 result = settings_install_property_parser (class,
1189 g_param_spec_boolean ("gtk-can-change-accels",
1190 P_("Can change accelerators"),
1191 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1193 GTK_PARAM_READWRITE),
1195 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1197 result = settings_install_property_parser (class,
1198 g_param_spec_int ("gtk-menu-popup-delay",
1199 P_("Delay before submenus appear"),
1200 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1203 GTK_PARAM_READWRITE),
1205 g_assert (result == PROP_MENU_POPUP_DELAY);
1207 result = settings_install_property_parser (class,
1208 g_param_spec_int ("gtk-menu-popdown-delay",
1209 P_("Delay before hiding a submenu"),
1210 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1213 GTK_PARAM_READWRITE),
1215 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1217 result = settings_install_property_parser (class,
1218 g_param_spec_boolean ("gtk-label-select-on-focus",
1219 P_("Select on focus"),
1220 P_("Whether to select the contents of a selectable label when it is focused"),
1222 GTK_PARAM_READWRITE),
1224 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1226 result = settings_install_property_parser (class,
1227 g_param_spec_string ("gtk-color-palette",
1228 P_("Custom palette"),
1229 P_("Palette to use in the color selector"),
1230 default_color_palette,
1231 GTK_PARAM_READWRITE),
1233 g_assert (result == PROP_COLOR_PALETTE);
1235 result = settings_install_property_parser (class,
1236 g_param_spec_enum ("gtk-im-preedit-style",
1237 P_("IM Preedit style"),
1238 P_("How to draw the input method preedit string"),
1239 GTK_TYPE_IM_PREEDIT_STYLE,
1240 GTK_IM_PREEDIT_CALLBACK,
1241 GTK_PARAM_READWRITE),
1242 gtk_rc_property_parse_enum);
1243 g_assert (result == PROP_IM_PREEDIT_STYLE);
1245 result = settings_install_property_parser (class,
1246 g_param_spec_enum ("gtk-im-status-style",
1247 P_("IM Status style"),
1248 P_("How to draw the input method statusbar"),
1249 GTK_TYPE_IM_STATUS_STYLE,
1250 GTK_IM_STATUS_CALLBACK,
1251 GTK_PARAM_READWRITE),
1252 gtk_rc_property_parse_enum);
1253 g_assert (result == PROP_IM_STATUS_STYLE);
1256 static GtkStyleProperties *
1257 gtk_settings_get_style (GtkStyleProvider *provider,
1258 GtkWidgetPath *path)
1260 PangoFontDescription *font_desc;
1261 gchar *font_name, *color_scheme;
1262 GtkSettings *settings;
1263 GtkStyleProperties *props;
1267 settings = GTK_SETTINGS (provider);
1268 props = gtk_style_properties_new ();
1270 g_object_get (settings,
1271 "gtk-font-name", &font_name,
1272 "gtk-color-scheme", &color_scheme,
1275 colors = g_strsplit_set (color_scheme, "\n;", -1);
1277 for (i = 0; colors[i]; i++)
1279 GtkSymbolicColor *color;
1287 pos = strchr (colors[i], ':');
1292 /* Set NUL after color name */
1296 /* Find start of color string */
1300 if (!*pos || !gdk_rgba_parse (&col, pos))
1303 color = gtk_symbolic_color_new_literal (&col);
1304 gtk_style_properties_map_color (props, name, color);
1305 gtk_symbolic_color_unref (color);
1308 font_desc = pango_font_description_from_string (font_name);
1310 gtk_style_properties_set (props, 0,
1314 pango_font_description_free (font_desc);
1315 g_strfreev (colors);
1316 g_free (color_scheme);
1323 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1325 iface->get_style = gtk_settings_get_style;
1329 gtk_settings_finalize (GObject *object)
1331 GtkSettings *settings = GTK_SETTINGS (object);
1334 object_list = g_slist_remove (object_list, settings);
1336 _gtk_rc_context_destroy (settings);
1338 for (i = 0; i < class_n_properties; i++)
1339 g_value_unset (&settings->property_values[i].value);
1340 g_free (settings->property_values);
1342 g_datalist_clear (&settings->queued_settings);
1344 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1348 settings_init_style (GtkSettings *settings)
1350 static GtkCssProvider *css_provider = NULL;
1351 GtkCssProvider *default_provider;
1353 /* Add provider for user file */
1354 if (G_UNLIKELY (!css_provider))
1356 GFile *home_dir, *css_file;
1358 css_provider = gtk_css_provider_new ();
1360 home_dir = g_file_new_for_path (g_get_home_dir ());
1361 css_file = g_file_get_child (home_dir, ".gtk-3.0.css");
1363 if (g_file_query_exists (css_file, NULL))
1364 gtk_css_provider_load_from_file (css_provider, css_file, NULL);
1366 g_object_unref (home_dir);
1367 g_object_unref (css_file);
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_rc_reset_styles (GTK_SETTINGS (object));
1575 case PROP_XFT_ANTIALIAS:
1576 case PROP_XFT_HINTING:
1577 case PROP_XFT_HINTSTYLE:
1579 settings_update_font_options (settings);
1580 gtk_rc_reset_styles (GTK_SETTINGS (object));
1582 case PROP_FONTCONFIG_TIMESTAMP:
1583 if (settings_update_fontconfig (settings))
1584 gtk_rc_reset_styles (GTK_SETTINGS (object));
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));
2639 gtk_style_context_add_provider_for_screen (settings->screen,
2640 GTK_STYLE_PROVIDER (new_provider),
2641 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS + 1);
2643 g_object_set_qdata_full (G_OBJECT (settings), quark_theme_name,
2644 new_provider, (GDestroyNotify) g_object_unref);
2649 add_color_to_hash (gchar *name,
2655 old = g_hash_table_lookup (target, name);
2656 if (!old || !gdk_color_equal (old, color))
2658 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2667 add_colors_to_hash_from_string (GHashTable *hash,
2668 const gchar *colors)
2670 gchar *s, *p, *name;
2672 gboolean changed = FALSE;
2675 copy = g_strdup (colors);
2680 p = strchr (s, ':');
2695 if (*s == '\n' || *s == ';')
2704 if (gdk_color_parse (p, &color))
2705 changed |= add_color_to_hash (name, &color, hash);
2714 update_color_hash (ColorSchemeData *data,
2716 GtkSettingsSource source)
2718 gboolean changed = FALSE;
2720 GHashTable *old_hash;
2721 GHashTableIter iter;
2725 if ((str == NULL || *str == '\0') &&
2726 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2729 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2732 /* For the RC_FILE source we merge the values rather than over-writing
2733 * them, since multiple rc files might define independent sets of colors
2735 if ((source != GTK_SETTINGS_SOURCE_RC_FILE) &&
2736 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2738 g_hash_table_unref (data->tables[source]);
2739 data->tables[source] = NULL;
2740 changed = TRUE; /* We can't rely on the code below since str might be "" */
2743 if (data->tables[source] == NULL)
2744 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2746 (GDestroyNotify) gdk_color_free);
2748 g_free (data->lastentry[source]);
2749 data->lastentry[source] = g_strdup (str);
2751 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2756 /* Rebuild the merged hash table. */
2757 if (data->color_hash)
2759 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2760 (GDestroyNotify) gdk_color_free);
2762 g_hash_table_iter_init (&iter, data->color_hash);
2763 while (g_hash_table_iter_next (&iter, &name, &color))
2765 g_hash_table_insert (old_hash, name, color);
2766 g_hash_table_iter_steal (&iter);
2774 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2776 if (data->tables[i])
2777 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2783 /* now check if the merged hash has changed */
2785 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2789 GHashTableIter iter;
2790 gpointer key, value, new_value;
2792 g_hash_table_iter_init (&iter, old_hash);
2793 while (g_hash_table_iter_next (&iter, &key, &value))
2795 new_value = g_hash_table_lookup (data->color_hash, key);
2796 if (!new_value || !gdk_color_equal (value, new_value))
2804 g_hash_table_unref (old_hash);
2813 merge_color_scheme (GtkSettings *settings,
2814 const GValue *value,
2815 GtkSettingsSource source)
2817 ColorSchemeData *data;
2818 const gchar *colors;
2820 g_object_freeze_notify (G_OBJECT (settings));
2822 colors = g_value_get_string (value);
2824 settings_update_color_scheme (settings);
2826 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2827 "gtk-color-scheme");
2829 if (update_color_hash (data, colors, source))
2830 g_object_notify (G_OBJECT (settings), "color-hash");
2832 g_object_thaw_notify (G_OBJECT (settings));
2836 get_color_hash (GtkSettings *settings)
2838 ColorSchemeData *data;
2840 settings_update_color_scheme (settings);
2842 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2843 "gtk-color-scheme");
2845 return data->color_hash;
2849 append_color_scheme (gpointer key,
2853 gchar *name = (gchar *)key;
2854 GdkColor *color = (GdkColor *)value;
2855 GString *string = (GString *)data;
2857 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2858 name, color->red, color->green, color->blue);
2862 get_color_scheme (GtkSettings *settings)
2864 ColorSchemeData *data;
2867 settings_update_color_scheme (settings);
2869 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2870 "gtk-color-scheme");
2872 string = g_string_new ("");
2874 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2876 return g_string_free (string, FALSE);