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"
34 #ifdef GDK_WINDOWING_X11
36 #include <pango/pangofc-fontmap.h>
42 * @Short_description: Sharing settings between applications
45 * GtkSettings provide a mechanism to share global settings between applications.
46 * On the X window system, this sharing is realized by an
47 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
48 * manager that is usually part of the desktop environment, along with utilities
49 * that let the user change these settings. In the absence of an Xsettings manager,
50 * settings can also be specified in RC files.
52 * Applications can override system-wide settings with gtk_settings_set_string_property(),
53 * gtk_settings_set_long_property(), etc. This should be restricted to special
54 * cases though; GtkSettings are not meant as an application configuration
55 * facility. When doing so, you need to be aware that settings that are specific
56 * to individual widgets may not be available before the widget type has been
57 * realized at least once. The following example demonstrates a way to do this:
58 * <informalexample><programlisting>
59 * gtk_init (&argc, &argv);
61 * /* make sure the type is realized */
62 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
64 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
65 * </programlisting></informalexample>
67 * There is one GtkSettings instance per screen. It can be obtained with
68 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
69 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
70 * GtkSettings instance for the default screen.
74 #ifdef GDK_WINDOWING_QUARTZ
75 #define DEFAULT_KEY_THEME "Mac"
77 #define DEFAULT_KEY_THEME NULL
80 #define DEFAULT_TIMEOUT_INITIAL 200
81 #define DEFAULT_TIMEOUT_REPEAT 20
82 #define DEFAULT_TIMEOUT_EXPAND 500
84 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
88 GTK_SETTINGS_SOURCE_DEFAULT,
89 GTK_SETTINGS_SOURCE_RC_FILE,
90 GTK_SETTINGS_SOURCE_XSETTING,
91 GTK_SETTINGS_SOURCE_APPLICATION
94 struct _GtkSettingsValuePrivate
96 GtkSettingsValue public;
97 GtkSettingsSource source;
100 struct _GtkSettingsPropertyValue
103 GtkSettingsSource source;
108 PROP_DOUBLE_CLICK_TIME,
109 PROP_DOUBLE_CLICK_DISTANCE,
111 PROP_CURSOR_BLINK_TIME,
112 PROP_CURSOR_BLINK_TIMEOUT,
115 PROP_ICON_THEME_NAME,
116 PROP_FALLBACK_ICON_THEME,
119 PROP_DND_DRAG_THRESHOLD,
123 #ifdef GDK_WINDOWING_X11
129 PROP_CURSOR_THEME_NAME,
130 PROP_CURSOR_THEME_SIZE,
132 PROP_ALTERNATIVE_BUTTON_ORDER,
133 PROP_ALTERNATIVE_SORT_ARROWS,
134 PROP_SHOW_INPUT_METHOD_MENU,
135 PROP_SHOW_UNICODE_MENU,
136 PROP_TIMEOUT_INITIAL,
140 PROP_ENABLE_ANIMATIONS,
141 PROP_TOUCHSCREEN_MODE,
142 PROP_TOOLTIP_TIMEOUT,
143 PROP_TOOLTIP_BROWSE_TIMEOUT,
144 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
145 PROP_KEYNAV_CURSOR_ONLY,
146 PROP_KEYNAV_WRAP_AROUND,
149 PROP_FILE_CHOOSER_BACKEND,
151 PROP_PRINT_PREVIEW_COMMAND,
152 PROP_ENABLE_MNEMONICS,
154 PROP_RECENT_FILES_LIMIT,
156 PROP_RECENT_FILES_MAX_AGE,
157 PROP_FONTCONFIG_TIMESTAMP,
158 PROP_SOUND_THEME_NAME,
159 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
160 PROP_ENABLE_EVENT_SOUNDS,
161 PROP_ENABLE_TOOLTIPS,
163 PROP_TOOLBAR_ICON_SIZE,
165 PROP_APPLICATION_PREFER_DARK_THEME,
167 PROP_ENTRY_SELECT_ON_FOCUS,
168 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
170 PROP_MENU_BAR_POPUP_DELAY,
171 PROP_SCROLLED_WINDOW_PLACEMENT,
172 PROP_CAN_CHANGE_ACCELS,
173 PROP_MENU_POPUP_DELAY,
174 PROP_MENU_POPDOWN_DELAY,
175 PROP_LABEL_SELECT_ON_FOCUS,
177 PROP_IM_PREEDIT_STYLE,
181 /* --- prototypes --- */
182 static void gtk_settings_finalize (GObject *object);
183 static void gtk_settings_get_property (GObject *object,
187 static void gtk_settings_set_property (GObject *object,
191 static void gtk_settings_notify (GObject *object,
193 static guint settings_install_property_parser (GtkSettingsClass *class,
195 GtkRcPropertyParser parser);
196 static void settings_update_double_click (GtkSettings *settings);
197 static void settings_update_modules (GtkSettings *settings);
199 #ifdef GDK_WINDOWING_X11
200 static void settings_update_cursor_theme (GtkSettings *settings);
201 static void settings_update_resolution (GtkSettings *settings);
202 static void settings_update_font_options (GtkSettings *settings);
203 static gboolean settings_update_fontconfig (GtkSettings *settings);
205 static void settings_update_color_scheme (GtkSettings *settings);
207 static void merge_color_scheme (GtkSettings *settings,
209 GtkSettingsSource source);
210 static gchar *get_color_scheme (GtkSettings *settings);
211 static GHashTable *get_color_hash (GtkSettings *settings);
213 /* the default palette for GtkColorSelelection */
214 static const gchar default_color_palette[] =
215 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
216 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
218 /* --- variables --- */
219 static GQuark quark_property_parser = 0;
220 static GSList *object_list = NULL;
221 static guint class_n_properties = 0;
224 G_DEFINE_TYPE (GtkSettings, gtk_settings, G_TYPE_OBJECT)
226 /* --- functions --- */
228 gtk_settings_init (GtkSettings *settings)
230 GParamSpec **pspecs, **p;
233 g_datalist_init (&settings->queued_settings);
234 object_list = g_slist_prepend (object_list, settings);
236 /* build up property array for all yet existing properties and queue
237 * notification for them (at least notification for internal properties
238 * will instantly be caught)
240 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
241 for (p = pspecs; *p; p++)
242 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
244 settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
246 g_object_freeze_notify (G_OBJECT (settings));
247 for (p = pspecs; *p; p++)
249 GParamSpec *pspec = *p;
251 if (pspec->owner_type != G_OBJECT_TYPE (settings))
253 g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
254 g_param_value_set_default (pspec, &settings->property_values[i].value);
255 g_object_notify (G_OBJECT (settings), pspec->name);
256 settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
259 g_object_thaw_notify (G_OBJECT (settings));
264 gtk_settings_class_init (GtkSettingsClass *class)
266 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
269 gobject_class->finalize = gtk_settings_finalize;
270 gobject_class->get_property = gtk_settings_get_property;
271 gobject_class->set_property = gtk_settings_set_property;
272 gobject_class->notify = gtk_settings_notify;
274 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
275 result = settings_install_property_parser (class,
276 g_param_spec_int ("gtk-double-click-time",
277 P_("Double Click Time"),
278 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
280 GTK_PARAM_READWRITE),
282 g_assert (result == PROP_DOUBLE_CLICK_TIME);
283 result = settings_install_property_parser (class,
284 g_param_spec_int ("gtk-double-click-distance",
285 P_("Double Click Distance"),
286 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
288 GTK_PARAM_READWRITE),
290 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
293 * GtkSettings:gtk-cursor-blink:
295 * Whether the cursor should blink.
297 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
298 * which allows more flexible control over cursor blinking.
300 result = settings_install_property_parser (class,
301 g_param_spec_boolean ("gtk-cursor-blink",
303 P_("Whether the cursor should blink"),
305 GTK_PARAM_READWRITE),
307 g_assert (result == PROP_CURSOR_BLINK);
308 result = settings_install_property_parser (class,
309 g_param_spec_int ("gtk-cursor-blink-time",
310 P_("Cursor Blink Time"),
311 P_("Length of the cursor blink cycle, in milliseconds"),
313 GTK_PARAM_READWRITE),
315 g_assert (result == PROP_CURSOR_BLINK_TIME);
318 * GtkSettings:gtk-cursor-blink-timeout:
320 * Time after which the cursor stops blinking, in seconds.
321 * The timer is reset after each user interaction.
323 * Setting this to zero has the same effect as setting
324 * #GtkSettings:gtk-cursor-blink to %FALSE.
328 result = settings_install_property_parser (class,
329 g_param_spec_int ("gtk-cursor-blink-timeout",
330 P_("Cursor Blink Timeout"),
331 P_("Time after which the cursor stops blinking, in seconds"),
332 1, G_MAXINT, G_MAXINT,
333 GTK_PARAM_READWRITE),
335 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
336 result = settings_install_property_parser (class,
337 g_param_spec_boolean ("gtk-split-cursor",
339 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
341 GTK_PARAM_READWRITE),
343 g_assert (result == PROP_SPLIT_CURSOR);
344 result = settings_install_property_parser (class,
345 g_param_spec_string ("gtk-theme-name",
347 P_("Name of theme RC file to load"),
349 GTK_PARAM_READWRITE),
351 g_assert (result == PROP_THEME_NAME);
353 result = settings_install_property_parser (class,
354 g_param_spec_string ("gtk-icon-theme-name",
355 P_("Icon Theme Name"),
356 P_("Name of icon theme to use"),
358 GTK_PARAM_READWRITE),
360 g_assert (result == PROP_ICON_THEME_NAME);
362 result = settings_install_property_parser (class,
363 g_param_spec_string ("gtk-fallback-icon-theme",
364 P_("Fallback Icon Theme Name"),
365 P_("Name of a icon theme to fall back to"),
367 GTK_PARAM_READWRITE),
369 g_assert (result == PROP_FALLBACK_ICON_THEME);
371 result = settings_install_property_parser (class,
372 g_param_spec_string ("gtk-key-theme-name",
373 P_("Key Theme Name"),
374 P_("Name of key theme RC file to load"),
376 GTK_PARAM_READWRITE),
378 g_assert (result == PROP_KEY_THEME_NAME);
380 result = settings_install_property_parser (class,
381 g_param_spec_string ("gtk-menu-bar-accel",
382 P_("Menu bar accelerator"),
383 P_("Keybinding to activate the menu bar"),
385 GTK_PARAM_READWRITE),
387 g_assert (result == PROP_MENU_BAR_ACCEL);
389 result = settings_install_property_parser (class,
390 g_param_spec_int ("gtk-dnd-drag-threshold",
391 P_("Drag threshold"),
392 P_("Number of pixels the cursor can move before dragging"),
394 GTK_PARAM_READWRITE),
396 g_assert (result == PROP_DND_DRAG_THRESHOLD);
398 result = settings_install_property_parser (class,
399 g_param_spec_string ("gtk-font-name",
401 P_("Name of default font to use"),
403 GTK_PARAM_READWRITE),
405 g_assert (result == PROP_FONT_NAME);
408 * GtkSettings:gtk-icon-sizes:
410 * A list of icon sizes. The list is separated by colons, and
413 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
415 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
416 * GTK+ itself use the following named icon sizes: gtk-menu,
417 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
418 * gtk-dialog. Applications can register their own named icon
419 * sizes with gtk_icon_size_register().
421 result = settings_install_property_parser (class,
422 g_param_spec_string ("gtk-icon-sizes",
424 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
426 GTK_PARAM_READWRITE),
428 g_assert (result == PROP_ICON_SIZES);
430 result = settings_install_property_parser (class,
431 g_param_spec_string ("gtk-modules",
433 P_("List of currently active GTK modules"),
435 GTK_PARAM_READWRITE),
437 g_assert (result == PROP_MODULES);
439 #ifdef GDK_WINDOWING_X11
440 result = settings_install_property_parser (class,
441 g_param_spec_int ("gtk-xft-antialias",
443 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
445 GTK_PARAM_READWRITE),
448 g_assert (result == PROP_XFT_ANTIALIAS);
450 result = settings_install_property_parser (class,
451 g_param_spec_int ("gtk-xft-hinting",
453 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
455 GTK_PARAM_READWRITE),
458 g_assert (result == PROP_XFT_HINTING);
460 result = settings_install_property_parser (class,
461 g_param_spec_string ("gtk-xft-hintstyle",
462 P_("Xft Hint Style"),
463 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
465 GTK_PARAM_READWRITE),
468 g_assert (result == PROP_XFT_HINTSTYLE);
470 result = settings_install_property_parser (class,
471 g_param_spec_string ("gtk-xft-rgba",
473 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
475 GTK_PARAM_READWRITE),
478 g_assert (result == PROP_XFT_RGBA);
480 result = settings_install_property_parser (class,
481 g_param_spec_int ("gtk-xft-dpi",
483 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
485 GTK_PARAM_READWRITE),
488 g_assert (result == PROP_XFT_DPI);
490 result = settings_install_property_parser (class,
491 g_param_spec_string ("gtk-cursor-theme-name",
492 P_("Cursor theme name"),
493 P_("Name of the cursor theme to use, or NULL to use the default theme"),
495 GTK_PARAM_READWRITE),
497 g_assert (result == PROP_CURSOR_THEME_NAME);
499 result = settings_install_property_parser (class,
500 g_param_spec_int ("gtk-cursor-theme-size",
501 P_("Cursor theme size"),
502 P_("Size to use for cursors, or 0 to use the default size"),
504 GTK_PARAM_READWRITE),
507 g_assert (result == PROP_CURSOR_THEME_SIZE);
509 #endif /* GDK_WINDOWING_X11 */
510 result = settings_install_property_parser (class,
511 g_param_spec_boolean ("gtk-alternative-button-order",
512 P_("Alternative button order"),
513 P_("Whether buttons in dialogs should use the alternative button order"),
515 GTK_PARAM_READWRITE),
517 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
520 * GtkSettings:gtk-alternative-sort-arrows:
522 * Controls the direction of the sort indicators in sorted list and tree
523 * views. By default an arrow pointing down means the column is sorted
524 * in ascending order. When set to %TRUE, this order will be inverted.
528 result = settings_install_property_parser (class,
529 g_param_spec_boolean ("gtk-alternative-sort-arrows",
530 P_("Alternative sort indicator direction"),
531 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
533 GTK_PARAM_READWRITE),
535 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
537 result = settings_install_property_parser (class,
538 g_param_spec_boolean ("gtk-show-input-method-menu",
539 P_("Show the 'Input Methods' menu"),
540 P_("Whether the context menus of entries and text views should offer to change the input method"),
542 GTK_PARAM_READWRITE),
544 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
546 result = settings_install_property_parser (class,
547 g_param_spec_boolean ("gtk-show-unicode-menu",
548 P_("Show the 'Insert Unicode Control Character' menu"),
549 P_("Whether the context menus of entries and text views should offer to insert control characters"),
551 GTK_PARAM_READWRITE),
553 g_assert (result == PROP_SHOW_UNICODE_MENU);
555 result = settings_install_property_parser (class,
556 g_param_spec_int ("gtk-timeout-initial",
558 P_("Starting value for timeouts, when button is pressed"),
559 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
560 GTK_PARAM_READWRITE),
563 g_assert (result == PROP_TIMEOUT_INITIAL);
565 result = settings_install_property_parser (class,
566 g_param_spec_int ("gtk-timeout-repeat",
567 P_("Repeat timeout"),
568 P_("Repeat value for timeouts, when button is pressed"),
569 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
570 GTK_PARAM_READWRITE),
573 g_assert (result == PROP_TIMEOUT_REPEAT);
575 result = settings_install_property_parser (class,
576 g_param_spec_int ("gtk-timeout-expand",
577 P_("Expand timeout"),
578 P_("Expand value for timeouts, when a widget is expanding a new region"),
579 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
580 GTK_PARAM_READWRITE),
583 g_assert (result == PROP_TIMEOUT_EXPAND);
586 * GtkSettings:gtk-color-scheme:
588 * A palette of named colors for use in themes. The format of the string is
594 * Color names must be acceptable as identifiers in the
595 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
596 * color specifications must be in the format accepted by
599 * Note that due to the way the color tables from different sources are
600 * merged, color specifications will be converted to hexadecimal form
601 * when getting this property.
603 * Starting with GTK+ 2.12, the entries can alternatively be separated
604 * by ';' instead of newlines:
606 * name1: color1; name2: color2; ...
611 result = settings_install_property_parser (class,
612 g_param_spec_string ("gtk-color-scheme",
614 P_("A palette of named colors for use in themes"),
616 GTK_PARAM_READWRITE),
619 g_assert (result == PROP_COLOR_SCHEME);
621 result = settings_install_property_parser (class,
622 g_param_spec_boolean ("gtk-enable-animations",
623 P_("Enable Animations"),
624 P_("Whether to enable toolkit-wide animations."),
626 GTK_PARAM_READWRITE),
629 g_assert (result == PROP_ENABLE_ANIMATIONS);
632 * GtkSettings:gtk-touchscreen-mode:
634 * When %TRUE, there are no motion notify events delivered on this screen,
635 * and widgets can't use the pointer hovering them for any essential
640 result = settings_install_property_parser (class,
641 g_param_spec_boolean ("gtk-touchscreen-mode",
642 P_("Enable Touchscreen Mode"),
643 P_("When TRUE, there are no motion notify events delivered on this screen"),
645 GTK_PARAM_READWRITE),
648 g_assert (result == PROP_TOUCHSCREEN_MODE);
651 * GtkSettings:gtk-tooltip-timeout:
653 * Time, in milliseconds, after which a tooltip could appear if the
654 * cursor is hovering on top of a widget.
658 result = settings_install_property_parser (class,
659 g_param_spec_int ("gtk-tooltip-timeout",
660 P_("Tooltip timeout"),
661 P_("Timeout before tooltip is shown"),
664 GTK_PARAM_READWRITE),
667 g_assert (result == PROP_TOOLTIP_TIMEOUT);
670 * GtkSettings:gtk-tooltip-browse-timeout:
672 * Controls the time after which tooltips will appear when
673 * browse mode is enabled, in milliseconds.
675 * Browse mode is enabled when the mouse pointer moves off an object
676 * where a tooltip was currently being displayed. If the mouse pointer
677 * hits another object before the browse mode timeout expires (see
678 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
679 * amount of milliseconds specified by this setting to popup the tooltip
680 * for the new object.
684 result = settings_install_property_parser (class,
685 g_param_spec_int ("gtk-tooltip-browse-timeout",
686 P_("Tooltip browse timeout"),
687 P_("Timeout before tooltip is shown when browse mode is enabled"),
690 GTK_PARAM_READWRITE),
693 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
696 * GtkSettings:gtk-tooltip-browse-mode-timeout:
698 * Amount of time, in milliseconds, after which the browse mode
701 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
706 result = settings_install_property_parser (class,
707 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
708 P_("Tooltip browse mode timeout"),
709 P_("Timeout after which browse mode is disabled"),
712 GTK_PARAM_READWRITE),
715 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
718 * GtkSettings:gtk-keynav-cursor-only:
720 * When %TRUE, keyboard navigation should be able to reach all widgets
721 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
722 * to be present on the used input device.
726 result = settings_install_property_parser (class,
727 g_param_spec_boolean ("gtk-keynav-cursor-only",
728 P_("Keynav Cursor Only"),
729 P_("When TRUE, there are only cursor keys available to navigate widgets"),
731 GTK_PARAM_READWRITE),
734 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
737 * GtkSettings:gtk-keynav-wrap-around:
739 * When %TRUE, some widgets will wrap around when doing keyboard
740 * navigation, such as menus, menubars and notebooks.
744 result = settings_install_property_parser (class,
745 g_param_spec_boolean ("gtk-keynav-wrap-around",
746 P_("Keynav Wrap Around"),
747 P_("Whether to wrap around when keyboard-navigating widgets"),
749 GTK_PARAM_READWRITE),
752 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
755 * GtkSettings:gtk-error-bell:
757 * When %TRUE, keyboard navigation and other input-related errors
758 * will cause a beep. Since the error bell is implemented using
759 * gdk_window_beep(), the windowing system may offer ways to
760 * configure the error bell in many ways, such as flashing the
761 * window or similar visual effects.
765 result = settings_install_property_parser (class,
766 g_param_spec_boolean ("gtk-error-bell",
768 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
770 GTK_PARAM_READWRITE),
773 g_assert (result == PROP_ERROR_BELL);
776 * GtkSettings:color-hash:
778 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
779 * setting, mapping color names to #GdkColor<!-- -->s.
783 result = settings_install_property_parser (class,
784 g_param_spec_boxed ("color-hash",
786 P_("A hash table representation of the color scheme."),
790 g_assert (result == PROP_COLOR_HASH);
792 result = settings_install_property_parser (class,
793 g_param_spec_string ("gtk-file-chooser-backend",
794 P_("Default file chooser backend"),
795 P_("Name of the GtkFileChooser backend to use by default"),
797 GTK_PARAM_READWRITE),
799 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
802 * GtkSettings:gtk-print-backends:
804 * A comma-separated list of print backends to use in the print
805 * dialog. Available print backends depend on the GTK+ installation,
806 * and may include "file", "cups", "lpr" or "papi".
810 result = settings_install_property_parser (class,
811 g_param_spec_string ("gtk-print-backends",
812 P_("Default print backend"),
813 P_("List of the GtkPrintBackend backends to use by default"),
815 GTK_PARAM_READWRITE),
817 g_assert (result == PROP_PRINT_BACKENDS);
820 * GtkSettings:gtk-print-preview-command:
822 * A command to run for displaying the print preview. The command
823 * should contain a %f placeholder, which will get replaced by
824 * the path to the pdf file. The command may also contain a %s
825 * placeholder, which will get replaced by the path to a file
826 * containing the print settings in the format produced by
827 * gtk_print_settings_to_file().
829 * The preview application is responsible for removing the pdf file
830 * and the print settings file when it is done.
834 result = settings_install_property_parser (class,
835 g_param_spec_string ("gtk-print-preview-command",
836 P_("Default command to run when displaying a print preview"),
837 P_("Command to run when displaying a print preview"),
838 GTK_PRINT_PREVIEW_COMMAND,
839 GTK_PARAM_READWRITE),
841 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
844 * GtkSettings:gtk-enable-mnemonics:
846 * Whether labels and menu items should have visible mnemonics which
851 result = settings_install_property_parser (class,
852 g_param_spec_boolean ("gtk-enable-mnemonics",
853 P_("Enable Mnemonics"),
854 P_("Whether labels should have mnemonics"),
856 GTK_PARAM_READWRITE),
858 g_assert (result == PROP_ENABLE_MNEMONICS);
861 * GtkSettings:gtk-enable-accels:
863 * Whether menu items should have visible accelerators which can be
868 result = settings_install_property_parser (class,
869 g_param_spec_boolean ("gtk-enable-accels",
870 P_("Enable Accelerators"),
871 P_("Whether menu items should have accelerators"),
873 GTK_PARAM_READWRITE),
875 g_assert (result == PROP_ENABLE_ACCELS);
878 * GtkSettings:gtk-recent-files-limit:
880 * The number of recently used files that should be displayed by default by
881 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
882 * -1 means every recently used file stored.
886 result = settings_install_property_parser (class,
887 g_param_spec_int ("gtk-recent-files-limit",
888 P_("Recent Files Limit"),
889 P_("Number of recently used files"),
892 GTK_PARAM_READWRITE),
894 g_assert (result == PROP_RECENT_FILES_LIMIT);
897 * GtkSettings:gtk-im-module:
899 * Which IM (input method) module should be used by default. This is the
900 * input method that will be used if the user has not explicitly chosen
901 * another input method from the IM context menu.
903 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
905 result = settings_install_property_parser (class,
906 g_param_spec_string ("gtk-im-module",
907 P_("Default IM module"),
908 P_("Which IM module should be used by default"),
910 GTK_PARAM_READWRITE),
912 g_assert (result == PROP_IM_MODULE);
915 * GtkSettings:gtk-recent-files-max-age:
917 * The maximum age, in days, of the items inside the recently used
918 * resources list. Items older than this setting will be excised
919 * from the list. If set to 0, the list will always be empty; if
920 * set to -1, no item will be removed.
924 result = settings_install_property_parser (class,
925 g_param_spec_int ("gtk-recent-files-max-age",
926 P_("Recent Files Max Age"),
927 P_("Maximum age of recently used files, in days"),
930 GTK_PARAM_READWRITE),
932 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
934 result = settings_install_property_parser (class,
935 g_param_spec_uint ("gtk-fontconfig-timestamp",
936 P_("Fontconfig configuration timestamp"),
937 P_("Timestamp of current fontconfig configuration"),
939 GTK_PARAM_READWRITE),
942 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
945 * GtkSettings:gtk-sound-theme-name:
947 * The XDG sound theme to use for event sounds.
949 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
950 * for more information on event sounds and sound themes.
952 * GTK+ itself does not support event sounds, you have to use a loadable
953 * module like the one that comes with libcanberra.
957 result = settings_install_property_parser (class,
958 g_param_spec_string ("gtk-sound-theme-name",
959 P_("Sound Theme Name"),
960 P_("XDG sound theme name"),
962 GTK_PARAM_READWRITE),
964 g_assert (result == PROP_SOUND_THEME_NAME);
967 * GtkSettings:gtk-enable-input-feedback-sounds:
969 * Whether to play event sounds as feedback to user input.
971 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
972 * for more information on event sounds and sound themes.
974 * GTK+ itself does not support event sounds, you have to use a loadable
975 * module like the one that comes with libcanberra.
979 result = settings_install_property_parser (class,
980 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
981 /* Translators: this means sounds that are played as feedback to user input */
982 P_("Audible Input Feedback"),
983 P_("Whether to play event sounds as feedback to user input"),
985 GTK_PARAM_READWRITE),
987 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
990 * GtkSettings:gtk-enable-event-sounds:
992 * Whether to play any event sounds at all.
994 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
995 * for more information on event sounds and sound themes.
997 * GTK+ itself does not support event sounds, you have to use a loadable
998 * module like the one that comes with libcanberra.
1002 result = settings_install_property_parser (class,
1003 g_param_spec_boolean ("gtk-enable-event-sounds",
1004 P_("Enable Event Sounds"),
1005 P_("Whether to play any event sounds at all"),
1007 GTK_PARAM_READWRITE),
1009 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1012 * GtkSettings:gtk-enable-tooltips:
1014 * Whether tooltips should be shown on widgets.
1018 result = settings_install_property_parser (class,
1019 g_param_spec_boolean ("gtk-enable-tooltips",
1020 P_("Enable Tooltips"),
1021 P_("Whether tooltips should be shown on widgets"),
1023 GTK_PARAM_READWRITE),
1025 g_assert (result == PROP_ENABLE_TOOLTIPS);
1028 * GtkSettings:toolbar-style:
1030 * The size of icons in default toolbars.
1032 result = settings_install_property_parser (class,
1033 g_param_spec_enum ("gtk-toolbar-style",
1034 P_("Toolbar style"),
1035 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1036 GTK_TYPE_TOOLBAR_STYLE,
1038 GTK_PARAM_READWRITE),
1039 gtk_rc_property_parse_enum);
1040 g_assert (result == PROP_TOOLBAR_STYLE);
1043 * GtkSettings:toolbar-icon-size:
1045 * The size of icons in default toolbars.
1047 result = settings_install_property_parser (class,
1048 g_param_spec_enum ("gtk-toolbar-icon-size",
1049 P_("Toolbar Icon Size"),
1050 P_("The size of icons in default toolbars."),
1052 GTK_ICON_SIZE_LARGE_TOOLBAR,
1053 GTK_PARAM_READWRITE),
1054 gtk_rc_property_parse_enum);
1055 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1058 * GtkSettings:gtk-auto-mnemonics:
1060 * Whether mnemonics should be automatically shown and hidden when the user
1061 * presses the mnemonic activator.
1065 result = settings_install_property_parser (class,
1066 g_param_spec_boolean ("gtk-auto-mnemonics",
1067 P_("Auto Mnemonics"),
1068 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1070 GTK_PARAM_READWRITE),
1072 g_assert (result == PROP_AUTO_MNEMONICS);
1075 * GtkSettings:gtk-application-prefer-dark-theme:
1077 * Whether the application prefers to use a dark theme. If a GTK+ theme
1078 * includes a dark variant, it will be used instead of the configured
1081 * Some applications benefit from minimizing the amount of light pollution that
1082 * interferes with the content. Good candidates for dark themes are photo and
1083 * video editors that make the actual content get all the attention and minimize
1084 * the distraction of the chrome.
1086 * Dark themes should not be used for documents, where large spaces are white/light
1087 * and the dark chrome creates too much contrast (web browser, text editor...).
1091 result = settings_install_property_parser (class,
1092 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1093 P_("Application prefers a dark theme"),
1094 P_("Whether the application prefers to have a dark theme."),
1096 GTK_PARAM_READWRITE),
1098 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1101 * GtkSettings::gtk-button-images:
1103 * Whether images should be shown on buttons
1107 result = settings_install_property_parser (class,
1108 g_param_spec_boolean ("gtk-button-images",
1109 P_("Show button images"),
1110 P_("Whether images should be shown on buttons"),
1112 GTK_PARAM_READWRITE),
1114 g_assert (result == PROP_BUTTON_IMAGES);
1116 result = settings_install_property_parser (class,
1117 g_param_spec_boolean ("gtk-entry-select-on-focus",
1118 P_("Select on focus"),
1119 P_("Whether to select the contents of an entry when it is focused"),
1121 GTK_PARAM_READWRITE),
1123 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1126 * GtkSettings:gtk-entry-password-hint-timeout:
1128 * How long to show the last input character in hidden
1129 * entries. This value is in milliseconds. 0 disables showing the
1130 * last char. 600 is a good value for enabling it.
1134 result = settings_install_property_parser (class,
1135 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1136 P_("Password Hint Timeout"),
1137 P_("How long to show the last input character in hidden entries"),
1140 GTK_PARAM_READWRITE),
1142 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1144 result = settings_install_property_parser (class,
1145 g_param_spec_boolean ("gtk-menu-images",
1146 P_("Show menu images"),
1147 P_("Whether images should be shown in menus"),
1149 GTK_PARAM_READWRITE),
1151 g_assert (result == PROP_MENU_IMAGES);
1153 result = settings_install_property_parser (class,
1154 g_param_spec_int ("gtk-menu-bar-popup-delay",
1155 P_("Delay before drop down menus appear"),
1156 P_("Delay before the submenus of a menu bar appear"),
1159 GTK_PARAM_READWRITE),
1161 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1164 * GtkSettings:gtk-scrolled-window-placement:
1166 * Where the contents of scrolled windows are located with respect to the
1167 * scrollbars, if not overridden by the scrolled window's own placement.
1171 result = settings_install_property_parser (class,
1172 g_param_spec_enum ("gtk-scrolled-window-placement",
1173 P_("Scrolled Window Placement"),
1174 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1175 GTK_TYPE_CORNER_TYPE,
1176 GTK_CORNER_TOP_LEFT,
1177 GTK_PARAM_READWRITE),
1178 gtk_rc_property_parse_enum);
1179 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1181 result = settings_install_property_parser (class,
1182 g_param_spec_boolean ("gtk-can-change-accels",
1183 P_("Can change accelerators"),
1184 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1186 GTK_PARAM_READWRITE),
1188 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1190 result = settings_install_property_parser (class,
1191 g_param_spec_int ("gtk-menu-popup-delay",
1192 P_("Delay before submenus appear"),
1193 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1196 GTK_PARAM_READWRITE),
1198 g_assert (result == PROP_MENU_POPUP_DELAY);
1200 result = settings_install_property_parser (class,
1201 g_param_spec_int ("gtk-menu-popdown-delay",
1202 P_("Delay before hiding a submenu"),
1203 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1206 GTK_PARAM_READWRITE),
1208 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1210 result = settings_install_property_parser (class,
1211 g_param_spec_boolean ("gtk-label-select-on-focus",
1212 P_("Select on focus"),
1213 P_("Whether to select the contents of a selectable label when it is focused"),
1215 GTK_PARAM_READWRITE),
1217 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1219 result = settings_install_property_parser (class,
1220 g_param_spec_string ("gtk-color-palette",
1221 P_("Custom palette"),
1222 P_("Palette to use in the color selector"),
1223 default_color_palette,
1224 GTK_PARAM_READWRITE),
1226 g_assert (result == PROP_COLOR_PALETTE);
1228 result = settings_install_property_parser (class,
1229 g_param_spec_enum ("gtk-im-preedit-style",
1230 P_("IM Preedit style"),
1231 P_("How to draw the input method preedit string"),
1232 GTK_TYPE_IM_PREEDIT_STYLE,
1233 GTK_IM_PREEDIT_CALLBACK,
1234 GTK_PARAM_READWRITE),
1235 gtk_rc_property_parse_enum);
1236 g_assert (result == PROP_IM_PREEDIT_STYLE);
1238 result = settings_install_property_parser (class,
1239 g_param_spec_enum ("gtk-im-status-style",
1240 P_("IM Status style"),
1241 P_("How to draw the input method statusbar"),
1242 GTK_TYPE_IM_STATUS_STYLE,
1243 GTK_IM_STATUS_CALLBACK,
1244 GTK_PARAM_READWRITE),
1245 gtk_rc_property_parse_enum);
1246 g_assert (result == PROP_IM_STATUS_STYLE);
1250 gtk_settings_finalize (GObject *object)
1252 GtkSettings *settings = GTK_SETTINGS (object);
1255 object_list = g_slist_remove (object_list, settings);
1257 _gtk_rc_context_destroy (settings);
1259 for (i = 0; i < class_n_properties; i++)
1260 g_value_unset (&settings->property_values[i].value);
1261 g_free (settings->property_values);
1263 g_datalist_clear (&settings->queued_settings);
1265 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1269 * gtk_settings_get_for_screen:
1270 * @screen: a #GdkScreen.
1272 * Gets the #GtkSettings object for @screen, creating it if necessary.
1274 * Return value: (transfer none): a #GtkSettings object.
1279 gtk_settings_get_for_screen (GdkScreen *screen)
1281 GtkSettings *settings;
1283 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1285 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1288 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1289 settings->screen = screen;
1290 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1291 settings, g_object_unref);
1293 gtk_rc_reparse_all_for_settings (settings, TRUE);
1294 settings_update_double_click (settings);
1295 #ifdef GDK_WINDOWING_X11
1296 settings_update_cursor_theme (settings);
1297 settings_update_resolution (settings);
1298 settings_update_font_options (settings);
1300 settings_update_color_scheme (settings);
1307 * gtk_settings_get_default:
1309 * Gets the #GtkSettings object for the default GDK screen, creating
1310 * it if necessary. See gtk_settings_get_for_screen().
1312 * Return value: (transfer none): a #GtkSettings object. If there is no default
1313 * screen, then returns %NULL.
1316 gtk_settings_get_default (void)
1318 GdkScreen *screen = gdk_screen_get_default ();
1321 return gtk_settings_get_for_screen (screen);
1327 gtk_settings_set_property (GObject *object,
1329 const GValue *value,
1332 GtkSettings *settings = GTK_SETTINGS (object);
1334 g_value_copy (value, &settings->property_values[property_id - 1].value);
1335 settings->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1337 if (pspec->param_id == PROP_COLOR_SCHEME)
1338 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1342 gtk_settings_get_property (GObject *object,
1347 GtkSettings *settings = GTK_SETTINGS (object);
1348 GType value_type = G_VALUE_TYPE (value);
1349 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1351 /* handle internal properties */
1352 switch (property_id)
1354 case PROP_COLOR_HASH:
1355 g_value_set_boxed (value, get_color_hash (settings));
1357 case PROP_COLOR_SCHEME:
1358 g_value_take_string (value, get_color_scheme (settings));
1363 /* For enums and strings, we need to get the value as a string,
1364 * not as an int, since we support using names/nicks as the setting
1367 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1368 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1369 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1370 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1372 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1373 !gdk_screen_get_setting (settings->screen, pspec->name, value))
1374 g_value_copy (&settings->property_values[property_id - 1].value, value);
1376 g_param_value_validate (pspec, value);
1380 GValue val = { 0, };
1382 /* Try to get xsetting as a string and parse it. */
1384 g_value_init (&val, G_TYPE_STRING);
1386 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1387 !gdk_screen_get_setting (settings->screen, pspec->name, &val))
1389 g_value_copy (&settings->property_values[property_id - 1].value, value);
1393 GValue tmp_value = { 0, };
1394 GValue gstring_value = { 0, };
1395 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1397 g_value_init (&gstring_value, G_TYPE_GSTRING);
1398 g_value_take_boxed (&gstring_value,
1399 g_string_new (g_value_get_string (&val)));
1401 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1403 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1406 g_value_copy (&tmp_value, value);
1407 g_param_value_validate (pspec, value);
1411 g_value_copy (&settings->property_values[property_id - 1].value, value);
1414 g_value_unset (&gstring_value);
1415 g_value_unset (&tmp_value);
1418 g_value_unset (&val);
1423 gtk_settings_notify (GObject *object,
1426 GtkSettings *settings = GTK_SETTINGS (object);
1427 guint property_id = pspec->param_id;
1429 if (settings->screen == NULL) /* initialization */
1432 switch (property_id)
1435 settings_update_modules (settings);
1437 case PROP_DOUBLE_CLICK_TIME:
1438 case PROP_DOUBLE_CLICK_DISTANCE:
1439 settings_update_double_click (settings);
1441 case PROP_COLOR_SCHEME:
1442 settings_update_color_scheme (settings);
1444 #ifdef GDK_WINDOWING_X11
1446 settings_update_resolution (settings);
1447 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1448 * widgets with gtk_widget_style_set(), and also causes more
1449 * recomputation than necessary.
1451 gtk_rc_reset_styles (GTK_SETTINGS (object));
1453 case PROP_XFT_ANTIALIAS:
1454 case PROP_XFT_HINTING:
1455 case PROP_XFT_HINTSTYLE:
1457 settings_update_font_options (settings);
1458 gtk_rc_reset_styles (GTK_SETTINGS (object));
1460 case PROP_FONTCONFIG_TIMESTAMP:
1461 if (settings_update_fontconfig (settings))
1462 gtk_rc_reset_styles (GTK_SETTINGS (object));
1464 case PROP_CURSOR_THEME_NAME:
1465 case PROP_CURSOR_THEME_SIZE:
1466 settings_update_cursor_theme (settings);
1468 #endif /* GDK_WINDOWING_X11 */
1473 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1474 const GValue *src_value,
1478 gboolean success = FALSE;
1480 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1485 gboolean free_gstring = TRUE;
1487 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1489 gstring = g_value_get_boxed (src_value);
1490 free_gstring = FALSE;
1492 else if (G_VALUE_HOLDS_LONG (src_value))
1494 gstring = g_string_new (NULL);
1495 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1497 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1499 gstring = g_string_new (NULL);
1500 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1502 else if (G_VALUE_HOLDS_STRING (src_value))
1504 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1506 gstring = g_string_new ("\"");
1507 g_string_append (gstring, tstr);
1508 g_string_append_c (gstring, '\"');
1513 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1514 gstring = NULL; /* silence compiler */
1517 success = (parser (pspec, gstring, dest_value) &&
1518 !g_param_value_validate (pspec, dest_value));
1521 g_string_free (gstring, TRUE);
1523 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1525 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1527 GString *gstring = g_value_get_boxed (src_value);
1529 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1530 success = !g_param_value_validate (pspec, dest_value);
1533 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1534 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1540 apply_queued_setting (GtkSettings *data,
1542 GtkSettingsValuePrivate *qvalue)
1544 GValue tmp_value = { 0, };
1545 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1547 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1548 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1551 if (pspec->param_id == PROP_COLOR_SCHEME)
1552 merge_color_scheme (data, &tmp_value, qvalue->source);
1554 if (data->property_values[pspec->param_id - 1].source <= qvalue->source)
1556 g_value_copy (&tmp_value, &data->property_values[pspec->param_id - 1].value);
1557 data->property_values[pspec->param_id - 1].source = qvalue->source;
1558 g_object_notify (G_OBJECT (data), g_param_spec_get_name (pspec));
1564 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1566 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1567 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1569 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1571 G_VALUE_TYPE_NAME (&tmp_value));
1574 g_value_unset (&tmp_value);
1578 settings_install_property_parser (GtkSettingsClass *class,
1580 GtkRcPropertyParser parser)
1582 GSList *node, *next;
1584 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1586 case G_TYPE_BOOLEAN:
1599 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1607 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1608 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1612 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1614 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1619 for (node = object_list; node; node = node->next)
1620 g_object_freeze_notify (node->data);
1622 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1623 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1625 for (node = object_list; node; node = node->next)
1627 GtkSettings *settings = node->data;
1628 GtkSettingsValuePrivate *qvalue;
1630 settings->property_values = g_renew (GtkSettingsPropertyValue, settings->property_values, class_n_properties);
1631 settings->property_values[class_n_properties - 1].value.g_type = 0;
1632 g_value_init (&settings->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1633 g_param_value_set_default (pspec, &settings->property_values[class_n_properties - 1].value);
1634 settings->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1635 g_object_notify (G_OBJECT (settings), pspec->name);
1637 qvalue = g_datalist_get_data (&settings->queued_settings, pspec->name);
1639 apply_queued_setting (settings, pspec, qvalue);
1642 for (node = object_list; node; node = next)
1645 g_object_thaw_notify (node->data);
1648 return class_n_properties;
1652 _gtk_rc_property_parser_from_type (GType type)
1654 if (type == GDK_TYPE_COLOR)
1655 return gtk_rc_property_parse_color;
1656 else if (type == GTK_TYPE_REQUISITION)
1657 return gtk_rc_property_parse_requisition;
1658 else if (type == GTK_TYPE_BORDER)
1659 return gtk_rc_property_parse_border;
1660 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1661 return gtk_rc_property_parse_enum;
1662 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1663 return gtk_rc_property_parse_flags;
1669 gtk_settings_install_property (GParamSpec *pspec)
1671 static GtkSettingsClass *klass = NULL;
1673 GtkRcPropertyParser parser;
1675 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1678 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1680 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1682 settings_install_property_parser (klass, pspec, parser);
1686 gtk_settings_install_property_parser (GParamSpec *pspec,
1687 GtkRcPropertyParser parser)
1689 static GtkSettingsClass *klass = NULL;
1691 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1692 g_return_if_fail (parser != NULL);
1695 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1697 settings_install_property_parser (klass, pspec, parser);
1701 free_value (gpointer data)
1703 GtkSettingsValuePrivate *qvalue = data;
1705 g_value_unset (&qvalue->public.value);
1706 g_free (qvalue->public.origin);
1707 g_slice_free (GtkSettingsValuePrivate, qvalue);
1711 gtk_settings_set_property_value_internal (GtkSettings *settings,
1712 const gchar *prop_name,
1713 const GtkSettingsValue *new_value,
1714 GtkSettingsSource source)
1716 GtkSettingsValuePrivate *qvalue;
1721 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1722 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1723 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1724 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1726 g_warning (G_STRLOC ": value type invalid");
1730 name = g_strdup (prop_name);
1731 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1732 name_quark = g_quark_from_string (name);
1735 qvalue = g_datalist_id_get_data (&settings->queued_settings, name_quark);
1738 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1739 g_datalist_id_set_data_full (&settings->queued_settings, name_quark, qvalue, free_value);
1743 g_free (qvalue->public.origin);
1744 g_value_unset (&qvalue->public.value);
1746 qvalue->public.origin = g_strdup (new_value->origin);
1747 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1748 g_value_copy (&new_value->value, &qvalue->public.value);
1749 qvalue->source = source;
1750 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1752 apply_queued_setting (settings, pspec, qvalue);
1756 gtk_settings_set_property_value (GtkSettings *settings,
1757 const gchar *prop_name,
1758 const GtkSettingsValue *new_value)
1760 g_return_if_fail (GTK_SETTINGS (settings));
1761 g_return_if_fail (prop_name != NULL);
1762 g_return_if_fail (new_value != NULL);
1764 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1765 GTK_SETTINGS_SOURCE_APPLICATION);
1769 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1770 const gchar *prop_name,
1771 const GtkSettingsValue *new_value)
1773 g_return_if_fail (GTK_SETTINGS (settings));
1774 g_return_if_fail (prop_name != NULL);
1775 g_return_if_fail (new_value != NULL);
1777 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1778 GTK_SETTINGS_SOURCE_RC_FILE);
1782 gtk_settings_set_string_property (GtkSettings *settings,
1784 const gchar *v_string,
1785 const gchar *origin)
1787 GtkSettingsValue svalue = { NULL, { 0, }, };
1789 g_return_if_fail (GTK_SETTINGS (settings));
1790 g_return_if_fail (name != NULL);
1791 g_return_if_fail (v_string != NULL);
1793 svalue.origin = (gchar*) origin;
1794 g_value_init (&svalue.value, G_TYPE_STRING);
1795 g_value_set_static_string (&svalue.value, v_string);
1796 gtk_settings_set_property_value (settings, name, &svalue);
1797 g_value_unset (&svalue.value);
1801 gtk_settings_set_long_property (GtkSettings *settings,
1804 const gchar *origin)
1806 GtkSettingsValue svalue = { NULL, { 0, }, };
1808 g_return_if_fail (GTK_SETTINGS (settings));
1809 g_return_if_fail (name != NULL);
1811 svalue.origin = (gchar*) origin;
1812 g_value_init (&svalue.value, G_TYPE_LONG);
1813 g_value_set_long (&svalue.value, v_long);
1814 gtk_settings_set_property_value (settings, name, &svalue);
1815 g_value_unset (&svalue.value);
1819 gtk_settings_set_double_property (GtkSettings *settings,
1822 const gchar *origin)
1824 GtkSettingsValue svalue = { NULL, { 0, }, };
1826 g_return_if_fail (GTK_SETTINGS (settings));
1827 g_return_if_fail (name != NULL);
1829 svalue.origin = (gchar*) origin;
1830 g_value_init (&svalue.value, G_TYPE_DOUBLE);
1831 g_value_set_double (&svalue.value, v_double);
1832 gtk_settings_set_property_value (settings, name, &svalue);
1833 g_value_unset (&svalue.value);
1837 * gtk_rc_property_parse_color:
1838 * @pspec: a #GParamSpec
1839 * @gstring: the #GString to be parsed
1840 * @property_value: a #GValue which must hold #GdkColor values.
1842 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1843 * or gtk_widget_class_install_style_property_parser() which parses a
1844 * color given either by its name or in the form
1845 * <literal>{ red, green, blue }</literal> where %red, %green and
1846 * %blue are integers between 0 and 65535 or floating-point numbers
1849 * Return value: %TRUE if @gstring could be parsed and @property_value
1850 * has been set to the resulting #GdkColor.
1853 gtk_rc_property_parse_color (const GParamSpec *pspec,
1854 const GString *gstring,
1855 GValue *property_value)
1857 GdkColor color = { 0, 0, 0, 0, };
1861 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1862 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
1864 scanner = gtk_rc_scanner_new ();
1865 g_scanner_input_text (scanner, gstring->str, gstring->len);
1866 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
1867 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
1869 g_value_set_boxed (property_value, &color);
1874 g_scanner_destroy (scanner);
1880 * gtk_rc_property_parse_enum:
1881 * @pspec: a #GParamSpec
1882 * @gstring: the #GString to be parsed
1883 * @property_value: a #GValue which must hold enum values.
1885 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1886 * or gtk_widget_class_install_style_property_parser() which parses a single
1887 * enumeration value.
1889 * The enumeration value can be specified by its name, its nickname or
1890 * its numeric value. For consistency with flags parsing, the value
1891 * may be surrounded by parentheses.
1893 * Return value: %TRUE if @gstring could be parsed and @property_value
1894 * has been set to the resulting #GEnumValue.
1897 gtk_rc_property_parse_enum (const GParamSpec *pspec,
1898 const GString *gstring,
1899 GValue *property_value)
1901 gboolean need_closing_brace = FALSE, success = FALSE;
1903 GEnumValue *enum_value = NULL;
1905 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1906 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
1908 scanner = gtk_rc_scanner_new ();
1909 g_scanner_input_text (scanner, gstring->str, gstring->len);
1911 /* we just want to parse _one_ value, but for consistency with flags parsing
1912 * we support optional parenthesis
1914 g_scanner_get_next_token (scanner);
1915 if (scanner->token == '(')
1917 need_closing_brace = TRUE;
1918 g_scanner_get_next_token (scanner);
1920 if (scanner->token == G_TOKEN_IDENTIFIER)
1922 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
1924 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
1926 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
1929 g_value_set_enum (property_value, enum_value->value);
1933 else if (scanner->token == G_TOKEN_INT)
1935 g_value_set_enum (property_value, scanner->value.v_int);
1938 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
1940 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
1943 g_scanner_destroy (scanner);
1949 parse_flags_value (GScanner *scanner,
1953 g_scanner_get_next_token (scanner);
1954 if (scanner->token == G_TOKEN_IDENTIFIER)
1956 GFlagsValue *flags_value;
1958 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
1960 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
1963 *number |= flags_value->value;
1964 return G_TOKEN_NONE;
1967 else if (scanner->token == G_TOKEN_INT)
1969 *number |= scanner->value.v_int;
1970 return G_TOKEN_NONE;
1972 return G_TOKEN_IDENTIFIER;
1976 * gtk_rc_property_parse_flags:
1977 * @pspec: a #GParamSpec
1978 * @gstring: the #GString to be parsed
1979 * @property_value: a #GValue which must hold flags values.
1981 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1982 * or gtk_widget_class_install_style_property_parser() which parses flags.
1984 * Flags can be specified by their name, their nickname or
1985 * numerically. Multiple flags can be specified in the form
1986 * <literal>"( flag1 | flag2 | ... )"</literal>.
1988 * Return value: %TRUE if @gstring could be parsed and @property_value
1989 * has been set to the resulting flags value.
1992 gtk_rc_property_parse_flags (const GParamSpec *pspec,
1993 const GString *gstring,
1994 GValue *property_value)
1997 gboolean success = FALSE;
2000 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2001 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2003 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2004 scanner = gtk_rc_scanner_new ();
2005 g_scanner_input_text (scanner, gstring->str, gstring->len);
2007 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2008 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2009 scanner->next_token == G_TOKEN_INT)
2011 guint token, flags_value = 0;
2013 token = parse_flags_value (scanner, class, &flags_value);
2015 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2018 g_value_set_flags (property_value, flags_value);
2022 else if (g_scanner_get_next_token (scanner) == '(')
2024 guint token, flags_value = 0;
2026 /* parse first value */
2027 token = parse_flags_value (scanner, class, &flags_value);
2029 /* parse nth values, preceeded by '|' */
2030 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2031 token = parse_flags_value (scanner, class, &flags_value);
2033 /* done, last token must have closed expression */
2034 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2035 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2037 g_value_set_flags (property_value, flags_value);
2041 g_scanner_destroy (scanner);
2047 get_braced_int (GScanner *scanner,
2054 g_scanner_get_next_token (scanner);
2055 if (scanner->token != '{')
2059 g_scanner_get_next_token (scanner);
2060 if (scanner->token != G_TOKEN_INT)
2063 *value = scanner->value.v_int;
2067 g_scanner_get_next_token (scanner);
2068 if (scanner->token != '}')
2073 g_scanner_get_next_token (scanner);
2074 if (scanner->token != ',')
2082 * gtk_rc_property_parse_requisition:
2083 * @pspec: a #GParamSpec
2084 * @gstring: the #GString to be parsed
2085 * @property_value: a #GValue which must hold boxed values.
2087 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2088 * or gtk_widget_class_install_style_property_parser() which parses a
2089 * requisition in the form
2090 * <literal>"{ width, height }"</literal> for integers %width and %height.
2092 * Return value: %TRUE if @gstring could be parsed and @property_value
2093 * has been set to the resulting #GtkRequisition.
2096 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2097 const GString *gstring,
2098 GValue *property_value)
2100 GtkRequisition requisition;
2102 gboolean success = FALSE;
2104 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2105 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2107 scanner = gtk_rc_scanner_new ();
2108 g_scanner_input_text (scanner, gstring->str, gstring->len);
2110 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2111 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2113 g_value_set_boxed (property_value, &requisition);
2117 g_scanner_destroy (scanner);
2123 * gtk_rc_property_parse_border:
2124 * @pspec: a #GParamSpec
2125 * @gstring: the #GString to be parsed
2126 * @property_value: a #GValue which must hold boxed values.
2128 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2129 * or gtk_widget_class_install_style_property_parser() which parses
2130 * borders in the form
2131 * <literal>"{ left, right, top, bottom }"</literal> for integers
2132 * %left, %right, %top and %bottom.
2134 * Return value: %TRUE if @gstring could be parsed and @property_value
2135 * has been set to the resulting #GtkBorder.
2138 gtk_rc_property_parse_border (const GParamSpec *pspec,
2139 const GString *gstring,
2140 GValue *property_value)
2144 gboolean success = FALSE;
2145 int left, right, top, bottom;
2147 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2148 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2150 scanner = gtk_rc_scanner_new ();
2151 g_scanner_input_text (scanner, gstring->str, gstring->len);
2153 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2154 get_braced_int (scanner, FALSE, FALSE, &right) &&
2155 get_braced_int (scanner, FALSE, FALSE, &top) &&
2156 get_braced_int (scanner, FALSE, TRUE, &bottom))
2159 border.right = right;
2161 border.bottom = bottom;
2162 g_value_set_boxed (property_value, &border);
2166 g_scanner_destroy (scanner);
2172 _gtk_settings_handle_event (GdkEventSetting *event)
2174 GtkSettings *settings;
2178 settings = gtk_settings_get_for_screen (gdk_window_get_screen (event->window));
2179 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2183 property_id = pspec->param_id;
2185 if (property_id == PROP_COLOR_SCHEME)
2187 GValue value = { 0, };
2189 g_value_init (&value, G_TYPE_STRING);
2190 if (!gdk_screen_get_setting (settings->screen, pspec->name, &value))
2191 g_value_set_static_string (&value, "");
2192 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2193 g_value_unset (&value);
2195 g_object_notify (G_OBJECT (settings), pspec->name);
2200 reset_rc_values_foreach (GQuark key_id,
2204 GtkSettingsValuePrivate *qvalue = data;
2205 GSList **to_reset = user_data;
2207 if (qvalue->source == GTK_SETTINGS_SOURCE_RC_FILE)
2208 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2212 _gtk_settings_reset_rc_values (GtkSettings *settings)
2214 GSList *to_reset = NULL;
2216 GParamSpec **pspecs, **p;
2219 /* Remove any queued settings
2221 g_datalist_foreach (&settings->queued_settings,
2222 reset_rc_values_foreach,
2225 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2227 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2228 g_datalist_id_remove_data (&settings->queued_settings, key_id);
2231 g_slist_free (to_reset);
2233 /* Now reset the active settings
2235 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2238 g_object_freeze_notify (G_OBJECT (settings));
2239 for (p = pspecs; *p; p++)
2241 if (settings->property_values[i].source == GTK_SETTINGS_SOURCE_RC_FILE)
2243 GParamSpec *pspec = *p;
2245 g_param_value_set_default (pspec, &settings->property_values[i].value);
2246 g_object_notify (G_OBJECT (settings), pspec->name);
2250 g_object_thaw_notify (G_OBJECT (settings));
2255 settings_update_double_click (GtkSettings *settings)
2257 if (gdk_screen_get_number (settings->screen) == 0)
2259 GdkDisplay *display = gdk_screen_get_display (settings->screen);
2260 gint double_click_time;
2261 gint double_click_distance;
2263 g_object_get (settings,
2264 "gtk-double-click-time", &double_click_time,
2265 "gtk-double-click-distance", &double_click_distance,
2268 gdk_display_set_double_click_time (display, double_click_time);
2269 gdk_display_set_double_click_distance (display, double_click_distance);
2274 settings_update_modules (GtkSettings *settings)
2278 g_object_get (settings,
2279 "gtk-modules", &modules,
2282 _gtk_modules_settings_changed (settings, modules);
2287 #ifdef GDK_WINDOWING_X11
2289 settings_update_cursor_theme (GtkSettings *settings)
2291 GdkDisplay *display = gdk_screen_get_display (settings->screen);
2292 gchar *theme = NULL;
2295 g_object_get (settings,
2296 "gtk-cursor-theme-name", &theme,
2297 "gtk-cursor-theme-size", &size,
2300 gdk_x11_display_set_cursor_theme (display, theme, size);
2306 settings_update_font_options (GtkSettings *settings)
2309 gchar *hint_style_str;
2310 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2312 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2314 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2315 cairo_font_options_t *options;
2317 g_object_get (settings,
2318 "gtk-xft-antialias", &antialias,
2319 "gtk-xft-hinting", &hinting,
2320 "gtk-xft-hintstyle", &hint_style_str,
2321 "gtk-xft-rgba", &rgba_str,
2324 options = cairo_font_options_create ();
2326 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2328 if (hinting >= 0 && !hinting)
2330 hint_style = CAIRO_HINT_STYLE_NONE;
2332 else if (hint_style_str)
2334 if (strcmp (hint_style_str, "hintnone") == 0)
2335 hint_style = CAIRO_HINT_STYLE_NONE;
2336 else if (strcmp (hint_style_str, "hintslight") == 0)
2337 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2338 else if (strcmp (hint_style_str, "hintmedium") == 0)
2339 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2340 else if (strcmp (hint_style_str, "hintfull") == 0)
2341 hint_style = CAIRO_HINT_STYLE_FULL;
2344 g_free (hint_style_str);
2346 cairo_font_options_set_hint_style (options, hint_style);
2350 if (strcmp (rgba_str, "rgb") == 0)
2351 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2352 else if (strcmp (rgba_str, "bgr") == 0)
2353 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2354 else if (strcmp (rgba_str, "vrgb") == 0)
2355 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2356 else if (strcmp (rgba_str, "vbgr") == 0)
2357 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2362 cairo_font_options_set_subpixel_order (options, subpixel_order);
2364 if (antialias >= 0 && !antialias)
2365 antialias_mode = CAIRO_ANTIALIAS_NONE;
2366 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2367 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2368 else if (antialias >= 0)
2369 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2371 cairo_font_options_set_antialias (options, antialias_mode);
2373 gdk_screen_set_font_options (settings->screen, options);
2375 cairo_font_options_destroy (options);
2378 #ifdef GDK_WINDOWING_X11
2380 settings_update_fontconfig (GtkSettings *settings)
2382 static guint last_update_timestamp;
2383 static gboolean last_update_needed;
2387 g_object_get (settings,
2388 "gtk-fontconfig-timestamp", ×tamp,
2391 /* if timestamp is the same as last_update_timestamp, we already have
2392 * updated fontconig on this timestamp (another screen requested it perhaps?),
2393 * just return the cached result.*/
2395 if (timestamp != last_update_timestamp)
2397 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2398 gboolean update_needed = FALSE;
2401 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2403 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2404 if (FcInitReinitialize ())
2405 update_needed = TRUE;
2408 last_update_timestamp = timestamp;
2409 last_update_needed = update_needed;
2412 return last_update_needed;
2414 #endif /* GDK_WINDOWING_X11 */
2417 settings_update_resolution (GtkSettings *settings)
2422 g_object_get (settings,
2423 "gtk-xft-dpi", &dpi_int,
2427 dpi = dpi_int / 1024.;
2431 gdk_screen_set_resolution (settings->screen, dpi);
2436 GHashTable *color_hash;
2437 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2438 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2442 color_scheme_data_free (ColorSchemeData *data)
2446 g_hash_table_unref (data->color_hash);
2448 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2450 if (data->tables[i])
2451 g_hash_table_unref (data->tables[i]);
2452 g_free (data->lastentry[i]);
2455 g_slice_free (ColorSchemeData, data);
2459 settings_update_color_scheme (GtkSettings *settings)
2461 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2463 ColorSchemeData *data;
2464 GValue value = { 0, };
2466 data = g_slice_new0 (ColorSchemeData);
2467 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2468 (GDestroyNotify) gdk_color_free);
2469 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2470 data, (GDestroyNotify) color_scheme_data_free);
2472 g_value_init (&value, G_TYPE_STRING);
2473 if (gdk_screen_get_setting (settings->screen, "gtk-color-scheme", &value))
2475 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2476 g_value_unset (&value);
2482 add_color_to_hash (gchar *name,
2488 old = g_hash_table_lookup (target, name);
2489 if (!old || !gdk_color_equal (old, color))
2491 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2500 add_colors_to_hash_from_string (GHashTable *hash,
2501 const gchar *colors)
2503 gchar *s, *p, *name;
2505 gboolean changed = FALSE;
2508 copy = g_strdup (colors);
2513 p = strchr (s, ':');
2528 if (*s == '\n' || *s == ';')
2537 if (gdk_color_parse (p, &color))
2538 changed |= add_color_to_hash (name, &color, hash);
2547 update_color_hash (ColorSchemeData *data,
2549 GtkSettingsSource source)
2551 gboolean changed = FALSE;
2553 GHashTable *old_hash;
2554 GHashTableIter iter;
2558 if ((str == NULL || *str == '\0') &&
2559 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2562 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2565 /* For the RC_FILE source we merge the values rather than over-writing
2566 * them, since multiple rc files might define independent sets of colors
2568 if ((source != GTK_SETTINGS_SOURCE_RC_FILE) &&
2569 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2571 g_hash_table_unref (data->tables[source]);
2572 data->tables[source] = NULL;
2573 changed = TRUE; /* We can't rely on the code below since str might be "" */
2576 if (data->tables[source] == NULL)
2577 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2579 (GDestroyNotify) gdk_color_free);
2581 g_free (data->lastentry[source]);
2582 data->lastentry[source] = g_strdup (str);
2584 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2589 /* Rebuild the merged hash table. */
2590 if (data->color_hash)
2592 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2593 (GDestroyNotify) gdk_color_free);
2595 g_hash_table_iter_init (&iter, data->color_hash);
2596 while (g_hash_table_iter_next (&iter, &name, &color))
2598 g_hash_table_insert (old_hash, name, color);
2599 g_hash_table_iter_steal (&iter);
2607 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2609 if (data->tables[i])
2610 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2616 /* now check if the merged hash has changed */
2618 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2622 GHashTableIter iter;
2623 gpointer key, value, new_value;
2625 g_hash_table_iter_init (&iter, old_hash);
2626 while (g_hash_table_iter_next (&iter, &key, &value))
2628 new_value = g_hash_table_lookup (data->color_hash, key);
2629 if (!new_value || !gdk_color_equal (value, new_value))
2637 g_hash_table_unref (old_hash);
2646 merge_color_scheme (GtkSettings *settings,
2647 const GValue *value,
2648 GtkSettingsSource source)
2650 ColorSchemeData *data;
2651 const gchar *colors;
2653 g_object_freeze_notify (G_OBJECT (settings));
2655 colors = g_value_get_string (value);
2657 settings_update_color_scheme (settings);
2659 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2660 "gtk-color-scheme");
2662 if (update_color_hash (data, colors, source))
2663 g_object_notify (G_OBJECT (settings), "color-hash");
2665 g_object_thaw_notify (G_OBJECT (settings));
2669 get_color_hash (GtkSettings *settings)
2671 ColorSchemeData *data;
2673 settings_update_color_scheme (settings);
2675 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2676 "gtk-color-scheme");
2678 return data->color_hash;
2682 append_color_scheme (gpointer key,
2686 gchar *name = (gchar *)key;
2687 GdkColor *color = (GdkColor *)value;
2688 GString *string = (GString *)data;
2690 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2691 name, color->red, color->green, color->blue);
2695 get_color_scheme (GtkSettings *settings)
2697 ColorSchemeData *data;
2700 settings_update_color_scheme (settings);
2702 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2703 "gtk-color-scheme");
2705 string = g_string_new ("");
2707 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2709 return g_string_free (string, FALSE);