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.
19 #define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
25 #include "gtkmodules.h"
26 #include "gtksettings.h"
29 #include "gtkwidget.h"
30 #include "gtkprivate.h"
33 #ifdef GDK_WINDOWING_X11
35 #include <pango/pangofc-fontmap.h>
38 #define DEFAULT_TIMEOUT_INITIAL 200
39 #define DEFAULT_TIMEOUT_REPEAT 20
40 #define DEFAULT_TIMEOUT_EXPAND 500
42 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
46 GTK_SETTINGS_SOURCE_DEFAULT,
47 GTK_SETTINGS_SOURCE_RC_FILE,
48 GTK_SETTINGS_SOURCE_XSETTING,
49 GTK_SETTINGS_SOURCE_APPLICATION
52 struct _GtkSettingsValuePrivate
54 GtkSettingsValue public;
55 GtkSettingsSource source;
58 struct _GtkSettingsPropertyValue
61 GtkSettingsSource source;
66 PROP_DOUBLE_CLICK_TIME,
67 PROP_DOUBLE_CLICK_DISTANCE,
69 PROP_CURSOR_BLINK_TIME,
70 PROP_CURSOR_BLINK_TIMEOUT,
74 PROP_FALLBACK_ICON_THEME,
77 PROP_DND_DRAG_THRESHOLD,
81 #ifdef GDK_WINDOWING_X11
87 PROP_CURSOR_THEME_NAME,
88 PROP_CURSOR_THEME_SIZE,
90 PROP_ALTERNATIVE_BUTTON_ORDER,
91 PROP_ALTERNATIVE_SORT_ARROWS,
92 PROP_SHOW_INPUT_METHOD_MENU,
93 PROP_SHOW_UNICODE_MENU,
98 PROP_ENABLE_ANIMATIONS,
99 PROP_TOUCHSCREEN_MODE,
100 PROP_TOOLTIP_TIMEOUT,
101 PROP_TOOLTIP_BROWSE_TIMEOUT,
102 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
103 PROP_KEYNAV_CURSOR_ONLY,
104 PROP_KEYNAV_WRAP_AROUND,
107 PROP_FILE_CHOOSER_BACKEND,
109 PROP_PRINT_PREVIEW_COMMAND,
110 PROP_ENABLE_MNEMONICS,
112 PROP_RECENT_FILES_LIMIT,
114 PROP_RECENT_FILES_MAX_AGE,
115 PROP_FONTCONFIG_TIMESTAMP,
116 PROP_SOUND_THEME_NAME,
117 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
118 PROP_ENABLE_EVENT_SOUNDS,
123 /* --- prototypes --- */
124 static void gtk_settings_finalize (GObject *object);
125 static void gtk_settings_get_property (GObject *object,
129 static void gtk_settings_set_property (GObject *object,
133 static void gtk_settings_notify (GObject *object,
135 static guint settings_install_property_parser (GtkSettingsClass *class,
137 GtkRcPropertyParser parser);
138 static void settings_update_double_click (GtkSettings *settings);
139 static void settings_update_modules (GtkSettings *settings);
141 #ifdef GDK_WINDOWING_X11
142 static void settings_update_cursor_theme (GtkSettings *settings);
143 static void settings_update_resolution (GtkSettings *settings);
144 static void settings_update_font_options (GtkSettings *settings);
145 static gboolean settings_update_fontconfig (GtkSettings *settings);
147 static void settings_update_color_scheme (GtkSettings *settings);
149 static void merge_color_scheme (GtkSettings *settings,
151 GtkSettingsSource source);
152 static gchar *get_color_scheme (GtkSettings *settings);
153 static GHashTable *get_color_hash (GtkSettings *settings);
156 /* --- variables --- */
157 static GQuark quark_property_parser = 0;
158 static GSList *object_list = NULL;
159 static guint class_n_properties = 0;
162 G_DEFINE_TYPE (GtkSettings, gtk_settings, G_TYPE_OBJECT)
164 /* --- functions --- */
166 gtk_settings_init (GtkSettings *settings)
168 GParamSpec **pspecs, **p;
171 g_datalist_init (&settings->queued_settings);
172 object_list = g_slist_prepend (object_list, settings);
174 /* build up property array for all yet existing properties and queue
175 * notification for them (at least notification for internal properties
176 * will instantly be caught)
178 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
179 for (p = pspecs; *p; p++)
180 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
182 settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
184 g_object_freeze_notify (G_OBJECT (settings));
185 for (p = pspecs; *p; p++)
187 GParamSpec *pspec = *p;
189 if (pspec->owner_type != G_OBJECT_TYPE (settings))
191 g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
192 g_param_value_set_default (pspec, &settings->property_values[i].value);
193 g_object_notify (G_OBJECT (settings), pspec->name);
194 settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
197 g_object_thaw_notify (G_OBJECT (settings));
202 gtk_settings_class_init (GtkSettingsClass *class)
204 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
207 gobject_class->finalize = gtk_settings_finalize;
208 gobject_class->get_property = gtk_settings_get_property;
209 gobject_class->set_property = gtk_settings_set_property;
210 gobject_class->notify = gtk_settings_notify;
212 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
213 result = settings_install_property_parser (class,
214 g_param_spec_int ("gtk-double-click-time",
215 P_("Double Click Time"),
216 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
218 GTK_PARAM_READWRITE),
220 g_assert (result == PROP_DOUBLE_CLICK_TIME);
221 result = settings_install_property_parser (class,
222 g_param_spec_int ("gtk-double-click-distance",
223 P_("Double Click Distance"),
224 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
226 GTK_PARAM_READWRITE),
228 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
231 * GtkSettings:gtk-cursor-blink:
233 * Whether the cursor should blink.
235 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
236 * which allows more flexible control over cursor blinking.
238 result = settings_install_property_parser (class,
239 g_param_spec_boolean ("gtk-cursor-blink",
241 P_("Whether the cursor should blink"),
243 GTK_PARAM_READWRITE),
245 g_assert (result == PROP_CURSOR_BLINK);
246 result = settings_install_property_parser (class,
247 g_param_spec_int ("gtk-cursor-blink-time",
248 P_("Cursor Blink Time"),
249 P_("Length of the cursor blink cycle, in milliseconds"),
251 GTK_PARAM_READWRITE),
253 g_assert (result == PROP_CURSOR_BLINK_TIME);
256 * GtkSettings:gtk-cursor-blink-timeout:
258 * Time after which the cursor stops blinking, in seconds.
259 * The timer is reset after each user interaction.
261 * Setting this to zero has the same effect as setting
262 * #GtkSettings:gtk-cursor-blink to %FALSE.
266 result = settings_install_property_parser (class,
267 g_param_spec_int ("gtk-cursor-blink-timeout",
268 P_("Cursor Blink Timeout"),
269 P_("Time after which the cursor stops blinking, in seconds"),
270 1, G_MAXINT, G_MAXINT,
271 GTK_PARAM_READWRITE),
273 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
274 result = settings_install_property_parser (class,
275 g_param_spec_boolean ("gtk-split-cursor",
277 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
279 GTK_PARAM_READWRITE),
281 g_assert (result == PROP_SPLIT_CURSOR);
282 result = settings_install_property_parser (class,
283 g_param_spec_string ("gtk-theme-name",
285 P_("Name of theme RC file to load"),
287 GTK_PARAM_READWRITE),
289 g_assert (result == PROP_THEME_NAME);
291 result = settings_install_property_parser (class,
292 g_param_spec_string ("gtk-icon-theme-name",
293 P_("Icon Theme Name"),
294 P_("Name of icon theme to use"),
296 GTK_PARAM_READWRITE),
298 g_assert (result == PROP_ICON_THEME_NAME);
300 result = settings_install_property_parser (class,
301 g_param_spec_string ("gtk-fallback-icon-theme",
302 P_("Fallback Icon Theme Name"),
303 P_("Name of a icon theme to fall back to"),
305 GTK_PARAM_READWRITE),
307 g_assert (result == PROP_FALLBACK_ICON_THEME);
309 result = settings_install_property_parser (class,
310 g_param_spec_string ("gtk-key-theme-name",
311 P_("Key Theme Name"),
312 P_("Name of key theme RC file to load"),
314 GTK_PARAM_READWRITE),
316 g_assert (result == PROP_KEY_THEME_NAME);
318 result = settings_install_property_parser (class,
319 g_param_spec_string ("gtk-menu-bar-accel",
320 P_("Menu bar accelerator"),
321 P_("Keybinding to activate the menu bar"),
323 GTK_PARAM_READWRITE),
325 g_assert (result == PROP_MENU_BAR_ACCEL);
327 result = settings_install_property_parser (class,
328 g_param_spec_int ("gtk-dnd-drag-threshold",
329 P_("Drag threshold"),
330 P_("Number of pixels the cursor can move before dragging"),
332 GTK_PARAM_READWRITE),
334 g_assert (result == PROP_DND_DRAG_THRESHOLD);
336 result = settings_install_property_parser (class,
337 g_param_spec_string ("gtk-font-name",
339 P_("Name of default font to use"),
341 GTK_PARAM_READWRITE),
343 g_assert (result == PROP_FONT_NAME);
346 * GtkSettings:gtk-icon-sizes:
348 * A list of icon sizes. The list is separated by colons, and
351 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
353 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
354 * GTK+ itself use the following named icon sizes: gtk-menu,
355 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
356 * gtk-dialog. Applications can register their own named icon
357 * sizes with gtk_icon_size_register().
359 result = settings_install_property_parser (class,
360 g_param_spec_string ("gtk-icon-sizes",
362 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
364 GTK_PARAM_READWRITE),
366 g_assert (result == PROP_ICON_SIZES);
368 result = settings_install_property_parser (class,
369 g_param_spec_string ("gtk-modules",
371 P_("List of currently active GTK modules"),
373 GTK_PARAM_READWRITE),
375 g_assert (result == PROP_MODULES);
377 #ifdef GDK_WINDOWING_X11
378 result = settings_install_property_parser (class,
379 g_param_spec_int ("gtk-xft-antialias",
381 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
383 GTK_PARAM_READWRITE),
386 g_assert (result == PROP_XFT_ANTIALIAS);
388 result = settings_install_property_parser (class,
389 g_param_spec_int ("gtk-xft-hinting",
391 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
393 GTK_PARAM_READWRITE),
396 g_assert (result == PROP_XFT_HINTING);
398 result = settings_install_property_parser (class,
399 g_param_spec_string ("gtk-xft-hintstyle",
400 P_("Xft Hint Style"),
401 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
403 GTK_PARAM_READWRITE),
406 g_assert (result == PROP_XFT_HINTSTYLE);
408 result = settings_install_property_parser (class,
409 g_param_spec_string ("gtk-xft-rgba",
411 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
413 GTK_PARAM_READWRITE),
416 g_assert (result == PROP_XFT_RGBA);
418 result = settings_install_property_parser (class,
419 g_param_spec_int ("gtk-xft-dpi",
421 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
423 GTK_PARAM_READWRITE),
426 g_assert (result == PROP_XFT_DPI);
428 result = settings_install_property_parser (class,
429 g_param_spec_string ("gtk-cursor-theme-name",
430 P_("Cursor theme name"),
431 P_("Name of the cursor theme to use, or NULL to use the default theme"),
433 GTK_PARAM_READWRITE),
435 g_assert (result == PROP_CURSOR_THEME_NAME);
437 result = settings_install_property_parser (class,
438 g_param_spec_int ("gtk-cursor-theme-size",
439 P_("Cursor theme size"),
440 P_("Size to use for cursors, or 0 to use the default size"),
442 GTK_PARAM_READWRITE),
445 g_assert (result == PROP_CURSOR_THEME_SIZE);
447 #endif /* GDK_WINDOWING_X11 */
448 result = settings_install_property_parser (class,
449 g_param_spec_boolean ("gtk-alternative-button-order",
450 P_("Alternative button order"),
451 P_("Whether buttons in dialogs should use the alternative button order"),
453 GTK_PARAM_READWRITE),
455 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
458 * GtkSettings:gtk-alternative-sort-arrows:
460 * Controls the direction of the sort indicators in sorted list and tree
461 * views. By default an arrow pointing down means the column is sorted
462 * in ascending order. When set to %TRUE, this order will be inverted.
466 result = settings_install_property_parser (class,
467 g_param_spec_boolean ("gtk-alternative-sort-arrows",
468 P_("Alternative sort indicator direction"),
469 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
471 GTK_PARAM_READWRITE),
473 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
475 result = settings_install_property_parser (class,
476 g_param_spec_boolean ("gtk-show-input-method-menu",
477 P_("Show the 'Input Methods' menu"),
478 P_("Whether the context menus of entries and text views should offer to change the input method"),
480 GTK_PARAM_READWRITE),
482 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
484 result = settings_install_property_parser (class,
485 g_param_spec_boolean ("gtk-show-unicode-menu",
486 P_("Show the 'Insert Unicode Control Character' menu"),
487 P_("Whether the context menus of entries and text views should offer to insert control characters"),
489 GTK_PARAM_READWRITE),
491 g_assert (result == PROP_SHOW_UNICODE_MENU);
493 result = settings_install_property_parser (class,
494 g_param_spec_int ("gtk-timeout-initial",
496 P_("Starting value for timeouts, when button is pressed"),
497 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
498 GTK_PARAM_READWRITE),
501 g_assert (result == PROP_TIMEOUT_INITIAL);
503 result = settings_install_property_parser (class,
504 g_param_spec_int ("gtk-timeout-repeat",
505 P_("Repeat timeout"),
506 P_("Repeat value for timeouts, when button is pressed"),
507 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
508 GTK_PARAM_READWRITE),
511 g_assert (result == PROP_TIMEOUT_REPEAT);
513 result = settings_install_property_parser (class,
514 g_param_spec_int ("gtk-timeout-expand",
515 P_("Expand timeout"),
516 P_("Expand value for timeouts, when a widget is expanding a new region"),
517 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
518 GTK_PARAM_READWRITE),
521 g_assert (result == PROP_TIMEOUT_EXPAND);
524 * GtkSettings:gtk-color-scheme:
526 * A palette of named colors for use in themes. The format of the string is
532 * Color names must be acceptable as identifiers in the
533 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
534 * color specifications must be in the format accepted by
537 * Note that due to the way the color tables from different sources are
538 * merged, color specifications will be converted to hexadecimal form
539 * when getting this property.
541 * Starting with GTK+ 2.12, the entries can alternatively be separated
542 * by ';' instead of newlines:
544 * name1: color1; name2: color2; ...
549 result = settings_install_property_parser (class,
550 g_param_spec_string ("gtk-color-scheme",
552 P_("A palette of named colors for use in themes"),
554 GTK_PARAM_READWRITE),
557 g_assert (result == PROP_COLOR_SCHEME);
559 result = settings_install_property_parser (class,
560 g_param_spec_boolean ("gtk-enable-animations",
561 P_("Enable Animations"),
562 P_("Whether to enable toolkit-wide animations."),
564 GTK_PARAM_READWRITE),
567 g_assert (result == PROP_ENABLE_ANIMATIONS);
570 * GtkSettings:gtk-touchscreen-mode:
572 * When %TRUE, there are no motion notify events delivered on this screen,
573 * and widgets can't use the pointer hovering them for any essential
578 result = settings_install_property_parser (class,
579 g_param_spec_boolean ("gtk-touchscreen-mode",
580 P_("Enable Touchscreen Mode"),
581 P_("When TRUE, there are no motion notify events delivered on this screen"),
583 GTK_PARAM_READWRITE),
586 g_assert (result == PROP_TOUCHSCREEN_MODE);
589 * GtkSettings:gtk-tooltip-timeout:
591 * Time, in milliseconds, after which a tooltip could appear if the
592 * cursor is hovering on top of a widget.
596 result = settings_install_property_parser (class,
597 g_param_spec_int ("gtk-tooltip-timeout",
598 P_("Tooltip timeout"),
599 P_("Timeout before tooltip is shown"),
602 GTK_PARAM_READWRITE),
605 g_assert (result == PROP_TOOLTIP_TIMEOUT);
608 * GtkSettings:gtk-tooltip-browse-timeout:
610 * Controls the time after which tooltips will appear when
611 * browse mode is enabled, in milliseconds.
613 * Browse mode is enabled when the mouse pointer moves off an object
614 * where a tooltip was currently being displayed. If the mouse pointer
615 * hits another object before the browse mode timeout expires (see
616 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
617 * amount of milliseconds specified by this setting to popup the tooltip
618 * for the new object.
622 result = settings_install_property_parser (class,
623 g_param_spec_int ("gtk-tooltip-browse-timeout",
624 P_("Tooltip browse timeout"),
625 P_("Timeout before tooltip is shown when browse mode is enabled"),
628 GTK_PARAM_READWRITE),
631 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
634 * GtkSettings:gtk-tooltip-browse-mode-timeout:
636 * Amount of time, in milliseconds, after which the browse mode
639 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
644 result = settings_install_property_parser (class,
645 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
646 P_("Tooltip browse mode timeout"),
647 P_("Timeout after which browse mode is disabled"),
650 GTK_PARAM_READWRITE),
653 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
656 * GtkSettings:gtk-keynav-cursor-only:
658 * When %TRUE, keyboard navigation should be able to reach all widgets
659 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
660 * to be present on the used input device.
664 result = settings_install_property_parser (class,
665 g_param_spec_boolean ("gtk-keynav-cursor-only",
666 P_("Keynav Cursor Only"),
667 P_("When TRUE, there are only cursor keys available to navigate widgets"),
669 GTK_PARAM_READWRITE),
672 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
675 * GtkSettings:gtk-keynav-wrap-around:
677 * When %TRUE, some widgets will wrap around when doing keyboard
678 * navigation, such as menus, menubars and notebooks.
682 result = settings_install_property_parser (class,
683 g_param_spec_boolean ("gtk-keynav-wrap-around",
684 P_("Keynav Wrap Around"),
685 P_("Whether to wrap around when keyboard-navigating widgets"),
687 GTK_PARAM_READWRITE),
690 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
693 * GtkSettings:gtk-error-bell:
695 * When %TRUE, keyboard navigation and other input-related errors
696 * will cause a beep. Since the error bell is implemented using
697 * gdk_window_beep(), the windowing system may offer ways to
698 * configure the error bell in many ways, such as flashing the
699 * window or similar visual effects.
703 result = settings_install_property_parser (class,
704 g_param_spec_boolean ("gtk-error-bell",
706 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
708 GTK_PARAM_READWRITE),
711 g_assert (result == PROP_ERROR_BELL);
714 * GtkSettings:color-hash:
716 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
717 * setting, mapping color names to #GdkColor<!-- -->s.
721 result = settings_install_property_parser (class,
722 g_param_spec_boxed ("color-hash",
724 P_("A hash table representation of the color scheme."),
728 g_assert (result == PROP_COLOR_HASH);
730 result = settings_install_property_parser (class,
731 g_param_spec_string ("gtk-file-chooser-backend",
732 P_("Default file chooser backend"),
733 P_("Name of the GtkFileChooser backend to use by default"),
735 GTK_PARAM_READWRITE),
737 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
740 * GtkSettings:gtk-print-backends:
742 * A comma-separated list of print backends to use in the print
743 * dialog. Available print backends depend on the GTK+ installation,
744 * and may include "pdf", "cups" or "lpr".
748 result = settings_install_property_parser (class,
749 g_param_spec_string ("gtk-print-backends",
750 P_("Default print backend"),
751 P_("List of the GtkPrintBackend backends to use by default"),
753 GTK_PARAM_READWRITE),
755 g_assert (result == PROP_PRINT_BACKENDS);
758 * GtkSettings:gtk-print-preview-command:
760 * A command to run for displaying the print preview. The command
761 * should contain a %f placeholder, which will get replaced by
762 * the path to the pdf file. The command may also contain a %s
763 * placeholder, which will get replaced by the path to a file
764 * containing the print settings in the format produced by
765 * gtk_print_settings_to_file().
767 * The preview application is responsible for removing the pdf file
768 * and the print settings file when it is done.
772 result = settings_install_property_parser (class,
773 g_param_spec_string ("gtk-print-preview-command",
774 P_("Default command to run when displaying a print preview"),
775 P_("Command to run when displaying a print preview"),
776 GTK_PRINT_PREVIEW_COMMAND,
777 GTK_PARAM_READWRITE),
779 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
782 * GtkSettings:gtk-enable-mnemonics:
784 * Whether labels and menu items should have visible mnemonics which
789 result = settings_install_property_parser (class,
790 g_param_spec_boolean ("gtk-enable-mnemonics",
791 P_("Enable Mnemonics"),
792 P_("Whether labels should have mnemonics"),
794 GTK_PARAM_READWRITE),
796 g_assert (result == PROP_ENABLE_MNEMONICS);
799 * GtkSettings:gtk-enable-accels:
801 * Whether menu items should have visible accelerators which can be
806 result = settings_install_property_parser (class,
807 g_param_spec_boolean ("gtk-enable-accels",
808 P_("Enable Accelerators"),
809 P_("Whether menu items should have accelerators"),
811 GTK_PARAM_READWRITE),
813 g_assert (result == PROP_ENABLE_ACCELS);
816 * GtkSettings:gtk-recent-files-limit:
818 * The number of recently used files that should be displayed by default by
819 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
820 * -1 means every recently used file stored.
824 result = settings_install_property_parser (class,
825 g_param_spec_int ("gtk-recent-files-limit",
826 P_("Recent Files Limit"),
827 P_("Number of recently used files"),
830 GTK_PARAM_READWRITE),
832 g_assert (result == PROP_RECENT_FILES_LIMIT);
835 * GtkSettings:gtk-im-module:
837 * Which IM module should be used by default.
839 result = settings_install_property_parser (class,
840 g_param_spec_string ("gtk-im-module",
841 P_("Default IM module"),
842 P_("Which IM module should be used by default"),
844 GTK_PARAM_READWRITE),
846 g_assert (result == PROP_IM_MODULE);
849 * GtkSettings:gtk-recent-files-max-age:
851 * The maximum age, in days, of the items inside the recently used
852 * resources list. Items older than this setting will be excised
853 * from the list. If set to 0, the list will always be empty; if
854 * set to -1, no item will be removed.
858 result = settings_install_property_parser (class,
859 g_param_spec_int ("gtk-recent-files-max-age",
860 P_("Recent Files Max Age"),
861 P_("Maximum age of recently used files, in days"),
864 GTK_PARAM_READWRITE),
866 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
868 result = settings_install_property_parser (class,
869 g_param_spec_int ("gtk-fontconfig-timestamp",
870 P_("Fontconfig configuration timestamp"),
871 P_("Timestamp of current fontconfig configuration"),
872 G_MININT, G_MAXINT, 0,
873 GTK_PARAM_READWRITE),
876 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
879 * GtkSettings:gtk-sound-theme-name:
881 * The XDG sound theme to use for event sounds.
883 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
884 * for more information on event sounds and sound themes.
886 * GTK+ itself does not support event sounds, you have to use a loadable
887 * module like the one that comes with libcanberra.
891 result = settings_install_property_parser (class,
892 g_param_spec_string ("gtk-sound-theme-name",
893 P_("Sound Theme Name"),
894 P_("XDG sound theme name"),
896 GTK_PARAM_READWRITE),
898 g_assert (result == PROP_SOUND_THEME_NAME);
901 * GtkSettings:gtk-enable-input-feedback-sounds:
903 * Whether to play event sounds as feedback to user input.
905 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
906 * for more information on event sounds and sound themes.
908 * GTK+ itself does not support event sounds, you have to use a loadable
909 * module like the one that comes with libcanberra.
913 result = settings_install_property_parser (class,
914 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
915 /* Translators: this means sounds that are played as feedback to user input */
916 P_("Aureal Input Feedback"),
917 P_("Whether to play event sounds as feedback to user input"),
919 GTK_PARAM_READWRITE),
921 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
924 * GtkSettings:gtk-enable-event-sounds:
926 * Whether to play any event sounds at all.
928 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
929 * for more information on event sounds and sound themes.
931 * GTK+ itself does not support event sounds, you have to use a loadable
932 * module like the one that comes with libcanberra.
936 result = settings_install_property_parser (class,
937 g_param_spec_boolean ("gtk-enable-event-sounds",
938 P_("Enable Event Sounds"),
939 P_("Whether to play any event sounds at all"),
941 GTK_PARAM_READWRITE),
943 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
946 * GtkSettings:gtk-enable-tooltips:
948 * Whether tooltips should be shown on widgets.
952 result = settings_install_property_parser (class,
953 g_param_spec_boolean ("gtk-enable-tooltips",
954 P_("Enable Tooltips"),
955 P_("Whether tooltips should be shown on widgets"),
957 GTK_PARAM_READWRITE),
959 g_assert (result == PROP_ENABLE_TOOLTIPS);
963 gtk_settings_finalize (GObject *object)
965 GtkSettings *settings = GTK_SETTINGS (object);
968 object_list = g_slist_remove (object_list, settings);
970 _gtk_rc_context_destroy (settings);
972 for (i = 0; i < class_n_properties; i++)
973 g_value_unset (&settings->property_values[i].value);
974 g_free (settings->property_values);
976 g_datalist_clear (&settings->queued_settings);
978 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
982 * gtk_settings_get_for_screen:
983 * @screen : a #GdkScreen.
985 * Gets the #GtkSettings object for @screen, creating it if necessary.
987 * Return value: a #GtkSettings object.
992 gtk_settings_get_for_screen (GdkScreen *screen)
994 GtkSettings *settings;
996 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
998 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1001 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1002 settings->screen = screen;
1003 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1004 settings, g_object_unref);
1006 gtk_rc_reparse_all_for_settings (settings, TRUE);
1007 settings_update_double_click (settings);
1008 #ifdef GDK_WINDOWING_X11
1009 settings_update_cursor_theme (settings);
1010 settings_update_resolution (settings);
1011 settings_update_font_options (settings);
1013 settings_update_color_scheme (settings);
1020 * gtk_settings_get_default:
1022 * Gets the #GtkSettings object for the default GDK screen, creating
1023 * it if necessary. See gtk_settings_get_for_screen().
1025 * Return value: a #GtkSettings object. If there is no default
1026 * screen, then returns %NULL.
1029 gtk_settings_get_default (void)
1031 GdkScreen *screen = gdk_screen_get_default ();
1034 return gtk_settings_get_for_screen (screen);
1040 gtk_settings_set_property (GObject *object,
1042 const GValue *value,
1045 GtkSettings *settings = GTK_SETTINGS (object);
1047 g_value_copy (value, &settings->property_values[property_id - 1].value);
1048 settings->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1050 if (pspec->param_id == PROP_COLOR_SCHEME)
1051 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1055 gtk_settings_get_property (GObject *object,
1060 GtkSettings *settings = GTK_SETTINGS (object);
1061 GType value_type = G_VALUE_TYPE (value);
1062 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1064 /* handle internal properties */
1065 switch (property_id)
1067 case PROP_COLOR_HASH:
1068 g_value_set_boxed (value, get_color_hash (settings));
1070 case PROP_COLOR_SCHEME:
1071 g_value_take_string (value, get_color_scheme (settings));
1076 /* For enums and strings, we need to get the value as a string,
1077 * not as an int, since we support using names/nicks as the setting
1080 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1081 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1082 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1083 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1085 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1086 !gdk_screen_get_setting (settings->screen, pspec->name, value))
1087 g_value_copy (&settings->property_values[property_id - 1].value, value);
1089 g_param_value_validate (pspec, value);
1093 GValue val = { 0, };
1095 /* Try to get xsetting as a string and parse it. */
1097 g_value_init (&val, G_TYPE_STRING);
1099 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1100 !gdk_screen_get_setting (settings->screen, pspec->name, &val))
1102 g_value_copy (&settings->property_values[property_id - 1].value, value);
1106 GValue tmp_value = { 0, };
1107 GValue gstring_value = { 0, };
1108 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1110 g_value_init (&gstring_value, G_TYPE_GSTRING);
1111 g_value_take_boxed (&gstring_value,
1112 g_string_new (g_value_get_string (&val)));
1114 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1116 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1119 g_value_copy (&tmp_value, value);
1120 g_param_value_validate (pspec, value);
1124 g_value_copy (&settings->property_values[property_id - 1].value, value);
1127 g_value_unset (&gstring_value);
1128 g_value_unset (&tmp_value);
1131 g_value_unset (&val);
1136 gtk_settings_notify (GObject *object,
1139 GtkSettings *settings = GTK_SETTINGS (object);
1140 guint property_id = pspec->param_id;
1142 if (settings->screen == NULL) /* initialization */
1145 switch (property_id)
1148 settings_update_modules (settings);
1150 case PROP_DOUBLE_CLICK_TIME:
1151 case PROP_DOUBLE_CLICK_DISTANCE:
1152 settings_update_double_click (settings);
1154 case PROP_COLOR_SCHEME:
1155 settings_update_color_scheme (settings);
1157 #ifdef GDK_WINDOWING_X11
1159 settings_update_resolution (settings);
1160 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1161 * widgets with gtk_widget_style_set(), and also causes more
1162 * recomputation than necessary.
1164 gtk_rc_reset_styles (GTK_SETTINGS (object));
1166 case PROP_XFT_ANTIALIAS:
1167 case PROP_XFT_HINTING:
1168 case PROP_XFT_HINTSTYLE:
1170 settings_update_font_options (settings);
1171 gtk_rc_reset_styles (GTK_SETTINGS (object));
1173 case PROP_FONTCONFIG_TIMESTAMP:
1174 if (settings_update_fontconfig (settings))
1175 gtk_rc_reset_styles (GTK_SETTINGS (object));
1177 case PROP_CURSOR_THEME_NAME:
1178 case PROP_CURSOR_THEME_SIZE:
1179 settings_update_cursor_theme (settings);
1181 #endif /* GDK_WINDOWING_X11 */
1186 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1187 const GValue *src_value,
1191 gboolean success = FALSE;
1193 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1198 gboolean free_gstring = TRUE;
1200 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1202 gstring = g_value_get_boxed (src_value);
1203 free_gstring = FALSE;
1205 else if (G_VALUE_HOLDS_LONG (src_value))
1207 gstring = g_string_new (NULL);
1208 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1210 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1212 gstring = g_string_new (NULL);
1213 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1215 else if (G_VALUE_HOLDS_STRING (src_value))
1217 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1219 gstring = g_string_new ("\"");
1220 g_string_append (gstring, tstr);
1221 g_string_append_c (gstring, '\"');
1226 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1227 gstring = NULL; /* silence compiler */
1230 success = (parser (pspec, gstring, dest_value) &&
1231 !g_param_value_validate (pspec, dest_value));
1234 g_string_free (gstring, TRUE);
1236 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1238 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1240 GString *gstring = g_value_get_boxed (src_value);
1242 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1243 success = !g_param_value_validate (pspec, dest_value);
1246 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1247 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1253 apply_queued_setting (GtkSettings *data,
1255 GtkSettingsValuePrivate *qvalue)
1257 GValue tmp_value = { 0, };
1258 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1260 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1261 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1264 if (pspec->param_id == PROP_COLOR_SCHEME)
1265 merge_color_scheme (data, &tmp_value, qvalue->source);
1267 if (data->property_values[pspec->param_id - 1].source <= qvalue->source)
1269 g_value_copy (&tmp_value, &data->property_values[pspec->param_id - 1].value);
1270 data->property_values[pspec->param_id - 1].source = qvalue->source;
1271 g_object_notify (G_OBJECT (data), g_param_spec_get_name (pspec));
1277 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1279 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1280 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1282 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1284 G_VALUE_TYPE_NAME (&tmp_value));
1287 g_value_unset (&tmp_value);
1291 settings_install_property_parser (GtkSettingsClass *class,
1293 GtkRcPropertyParser parser)
1295 GSList *node, *next;
1297 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1299 case G_TYPE_BOOLEAN:
1311 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1319 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1320 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1324 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1326 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1331 for (node = object_list; node; node = node->next)
1332 g_object_freeze_notify (node->data);
1334 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1335 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1337 for (node = object_list; node; node = node->next)
1339 GtkSettings *settings = node->data;
1340 GtkSettingsValuePrivate *qvalue;
1342 settings->property_values = g_renew (GtkSettingsPropertyValue, settings->property_values, class_n_properties);
1343 settings->property_values[class_n_properties - 1].value.g_type = 0;
1344 g_value_init (&settings->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1345 g_param_value_set_default (pspec, &settings->property_values[class_n_properties - 1].value);
1346 settings->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1347 g_object_notify (G_OBJECT (settings), pspec->name);
1349 qvalue = g_datalist_get_data (&settings->queued_settings, pspec->name);
1351 apply_queued_setting (settings, pspec, qvalue);
1354 for (node = object_list; node; node = next)
1357 g_object_thaw_notify (node->data);
1360 return class_n_properties;
1364 _gtk_rc_property_parser_from_type (GType type)
1366 if (type == GDK_TYPE_COLOR)
1367 return gtk_rc_property_parse_color;
1368 else if (type == GTK_TYPE_REQUISITION)
1369 return gtk_rc_property_parse_requisition;
1370 else if (type == GTK_TYPE_BORDER)
1371 return gtk_rc_property_parse_border;
1372 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1373 return gtk_rc_property_parse_enum;
1374 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1375 return gtk_rc_property_parse_flags;
1381 gtk_settings_install_property (GParamSpec *pspec)
1383 static GtkSettingsClass *klass = NULL;
1385 GtkRcPropertyParser parser;
1387 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1390 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1392 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1394 settings_install_property_parser (klass, pspec, parser);
1398 gtk_settings_install_property_parser (GParamSpec *pspec,
1399 GtkRcPropertyParser parser)
1401 static GtkSettingsClass *klass = NULL;
1403 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1404 g_return_if_fail (parser != NULL);
1407 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1409 settings_install_property_parser (klass, pspec, parser);
1413 free_value (gpointer data)
1415 GtkSettingsValuePrivate *qvalue = data;
1417 g_value_unset (&qvalue->public.value);
1418 g_free (qvalue->public.origin);
1419 g_slice_free (GtkSettingsValuePrivate, qvalue);
1423 gtk_settings_set_property_value_internal (GtkSettings *settings,
1424 const gchar *prop_name,
1425 const GtkSettingsValue *new_value,
1426 GtkSettingsSource source)
1428 GtkSettingsValuePrivate *qvalue;
1433 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1434 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1435 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1436 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1438 g_warning (G_STRLOC ": value type invalid");
1442 name = g_strdup (prop_name);
1443 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1444 name_quark = g_quark_from_string (name);
1447 qvalue = g_datalist_id_get_data (&settings->queued_settings, name_quark);
1450 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1451 g_datalist_id_set_data_full (&settings->queued_settings, name_quark, qvalue, free_value);
1455 g_free (qvalue->public.origin);
1456 g_value_unset (&qvalue->public.value);
1458 qvalue->public.origin = g_strdup (new_value->origin);
1459 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1460 g_value_copy (&new_value->value, &qvalue->public.value);
1461 qvalue->source = source;
1462 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1464 apply_queued_setting (settings, pspec, qvalue);
1468 gtk_settings_set_property_value (GtkSettings *settings,
1469 const gchar *prop_name,
1470 const GtkSettingsValue *new_value)
1472 g_return_if_fail (GTK_SETTINGS (settings));
1473 g_return_if_fail (prop_name != NULL);
1474 g_return_if_fail (new_value != NULL);
1476 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1477 GTK_SETTINGS_SOURCE_APPLICATION);
1481 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1482 const gchar *prop_name,
1483 const GtkSettingsValue *new_value)
1485 g_return_if_fail (GTK_SETTINGS (settings));
1486 g_return_if_fail (prop_name != NULL);
1487 g_return_if_fail (new_value != NULL);
1489 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1490 GTK_SETTINGS_SOURCE_RC_FILE);
1494 gtk_settings_set_string_property (GtkSettings *settings,
1496 const gchar *v_string,
1497 const gchar *origin)
1499 GtkSettingsValue svalue = { NULL, { 0, }, };
1501 g_return_if_fail (GTK_SETTINGS (settings));
1502 g_return_if_fail (name != NULL);
1503 g_return_if_fail (v_string != NULL);
1505 svalue.origin = (gchar*) origin;
1506 g_value_init (&svalue.value, G_TYPE_STRING);
1507 g_value_set_static_string (&svalue.value, v_string);
1508 gtk_settings_set_property_value (settings, name, &svalue);
1509 g_value_unset (&svalue.value);
1513 gtk_settings_set_long_property (GtkSettings *settings,
1516 const gchar *origin)
1518 GtkSettingsValue svalue = { NULL, { 0, }, };
1520 g_return_if_fail (GTK_SETTINGS (settings));
1521 g_return_if_fail (name != NULL);
1523 svalue.origin = (gchar*) origin;
1524 g_value_init (&svalue.value, G_TYPE_LONG);
1525 g_value_set_long (&svalue.value, v_long);
1526 gtk_settings_set_property_value (settings, name, &svalue);
1527 g_value_unset (&svalue.value);
1531 gtk_settings_set_double_property (GtkSettings *settings,
1534 const gchar *origin)
1536 GtkSettingsValue svalue = { NULL, { 0, }, };
1538 g_return_if_fail (GTK_SETTINGS (settings));
1539 g_return_if_fail (name != NULL);
1541 svalue.origin = (gchar*) origin;
1542 g_value_init (&svalue.value, G_TYPE_DOUBLE);
1543 g_value_set_double (&svalue.value, v_double);
1544 gtk_settings_set_property_value (settings, name, &svalue);
1545 g_value_unset (&svalue.value);
1549 * gtk_rc_property_parse_color:
1550 * @pspec: a #GParamSpec
1551 * @gstring: the #GString to be parsed
1552 * @property_value: a #GValue which must hold #GdkColor values.
1554 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1555 * or gtk_widget_class_install_style_property_parser() which parses a
1556 * color given either by its name or in the form
1557 * <literal>{ red, green, blue }</literal> where %red, %green and
1558 * %blue are integers between 0 and 65535 or floating-point numbers
1561 * Return value: %TRUE if @gstring could be parsed and @property_value
1562 * has been set to the resulting #GdkColor.
1565 gtk_rc_property_parse_color (const GParamSpec *pspec,
1566 const GString *gstring,
1567 GValue *property_value)
1569 GdkColor color = { 0, 0, 0, 0, };
1573 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1574 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
1576 scanner = gtk_rc_scanner_new ();
1577 g_scanner_input_text (scanner, gstring->str, gstring->len);
1578 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
1579 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
1581 g_value_set_boxed (property_value, &color);
1586 g_scanner_destroy (scanner);
1592 * gtk_rc_property_parse_enum:
1593 * @pspec: a #GParamSpec
1594 * @gstring: the #GString to be parsed
1595 * @property_value: a #GValue which must hold enum values.
1597 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1598 * or gtk_widget_class_install_style_property_parser() which parses a single
1599 * enumeration value.
1601 * The enumeration value can be specified by its name, its nickname or
1602 * its numeric value. For consistency with flags parsing, the value
1603 * may be surrounded by parentheses.
1605 * Return value: %TRUE if @gstring could be parsed and @property_value
1606 * has been set to the resulting #GEnumValue.
1609 gtk_rc_property_parse_enum (const GParamSpec *pspec,
1610 const GString *gstring,
1611 GValue *property_value)
1613 gboolean need_closing_brace = FALSE, success = FALSE;
1615 GEnumValue *enum_value = NULL;
1617 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1618 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
1620 scanner = gtk_rc_scanner_new ();
1621 g_scanner_input_text (scanner, gstring->str, gstring->len);
1623 /* we just want to parse _one_ value, but for consistency with flags parsing
1624 * we support optional parenthesis
1626 g_scanner_get_next_token (scanner);
1627 if (scanner->token == '(')
1629 need_closing_brace = TRUE;
1630 g_scanner_get_next_token (scanner);
1632 if (scanner->token == G_TOKEN_IDENTIFIER)
1634 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
1636 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
1638 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
1641 g_value_set_enum (property_value, enum_value->value);
1645 else if (scanner->token == G_TOKEN_INT)
1647 g_value_set_enum (property_value, scanner->value.v_int);
1650 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
1652 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
1655 g_scanner_destroy (scanner);
1661 parse_flags_value (GScanner *scanner,
1665 g_scanner_get_next_token (scanner);
1666 if (scanner->token == G_TOKEN_IDENTIFIER)
1668 GFlagsValue *flags_value;
1670 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
1672 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
1675 *number |= flags_value->value;
1676 return G_TOKEN_NONE;
1679 else if (scanner->token == G_TOKEN_INT)
1681 *number |= scanner->value.v_int;
1682 return G_TOKEN_NONE;
1684 return G_TOKEN_IDENTIFIER;
1688 * gtk_rc_property_parse_flags:
1689 * @pspec: a #GParamSpec
1690 * @gstring: the #GString to be parsed
1691 * @property_value: a #GValue which must hold flags values.
1693 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1694 * or gtk_widget_class_install_style_property_parser() which parses flags.
1696 * Flags can be specified by their name, their nickname or
1697 * numerically. Multiple flags can be specified in the form
1698 * <literal>"( flag1 | flag2 | ... )"</literal>.
1700 * Return value: %TRUE if @gstring could be parsed and @property_value
1701 * has been set to the resulting flags value.
1704 gtk_rc_property_parse_flags (const GParamSpec *pspec,
1705 const GString *gstring,
1706 GValue *property_value)
1709 gboolean success = FALSE;
1712 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1713 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
1715 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
1716 scanner = gtk_rc_scanner_new ();
1717 g_scanner_input_text (scanner, gstring->str, gstring->len);
1719 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
1720 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
1721 scanner->next_token == G_TOKEN_INT)
1723 guint token, flags_value = 0;
1725 token = parse_flags_value (scanner, class, &flags_value);
1727 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1730 g_value_set_flags (property_value, flags_value);
1734 else if (g_scanner_get_next_token (scanner) == '(')
1736 guint token, flags_value = 0;
1738 /* parse first value */
1739 token = parse_flags_value (scanner, class, &flags_value);
1741 /* parse nth values, preceeded by '|' */
1742 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
1743 token = parse_flags_value (scanner, class, &flags_value);
1745 /* done, last token must have closed expression */
1746 if (token == G_TOKEN_NONE && scanner->token == ')' &&
1747 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1749 g_value_set_flags (property_value, flags_value);
1753 g_scanner_destroy (scanner);
1759 get_braced_int (GScanner *scanner,
1766 g_scanner_get_next_token (scanner);
1767 if (scanner->token != '{')
1771 g_scanner_get_next_token (scanner);
1772 if (scanner->token != G_TOKEN_INT)
1775 *value = scanner->value.v_int;
1779 g_scanner_get_next_token (scanner);
1780 if (scanner->token != '}')
1785 g_scanner_get_next_token (scanner);
1786 if (scanner->token != ',')
1794 * gtk_rc_property_parse_requisition:
1795 * @pspec: a #GParamSpec
1796 * @gstring: the #GString to be parsed
1797 * @property_value: a #GValue which must hold boxed values.
1799 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1800 * or gtk_widget_class_install_style_property_parser() which parses a
1801 * requisition in the form
1802 * <literal>"{ width, height }"</literal> for integers %width and %height.
1804 * Return value: %TRUE if @gstring could be parsed and @property_value
1805 * has been set to the resulting #GtkRequisition.
1808 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
1809 const GString *gstring,
1810 GValue *property_value)
1812 GtkRequisition requisition;
1814 gboolean success = FALSE;
1816 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1817 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1819 scanner = gtk_rc_scanner_new ();
1820 g_scanner_input_text (scanner, gstring->str, gstring->len);
1822 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
1823 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
1825 g_value_set_boxed (property_value, &requisition);
1829 g_scanner_destroy (scanner);
1835 * gtk_rc_property_parse_border:
1836 * @pspec: a #GParamSpec
1837 * @gstring: the #GString to be parsed
1838 * @property_value: a #GValue which must hold boxed values.
1840 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1841 * or gtk_widget_class_install_style_property_parser() which parses
1842 * borders in the form
1843 * <literal>"{ left, right, top, bottom }"</literal> for integers
1844 * %left, %right, %top and %bottom.
1846 * Return value: %TRUE if @gstring could be parsed and @property_value
1847 * has been set to the resulting #GtkBorder.
1850 gtk_rc_property_parse_border (const GParamSpec *pspec,
1851 const GString *gstring,
1852 GValue *property_value)
1856 gboolean success = FALSE;
1858 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1859 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1861 scanner = gtk_rc_scanner_new ();
1862 g_scanner_input_text (scanner, gstring->str, gstring->len);
1864 if (get_braced_int (scanner, TRUE, FALSE, &border.left) &&
1865 get_braced_int (scanner, FALSE, FALSE, &border.right) &&
1866 get_braced_int (scanner, FALSE, FALSE, &border.top) &&
1867 get_braced_int (scanner, FALSE, TRUE, &border.bottom))
1869 g_value_set_boxed (property_value, &border);
1873 g_scanner_destroy (scanner);
1879 _gtk_settings_handle_event (GdkEventSetting *event)
1881 GtkSettings *settings;
1885 settings = gtk_settings_get_for_screen (gdk_drawable_get_screen (event->window));
1886 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
1890 property_id = pspec->param_id;
1892 if (property_id == PROP_COLOR_SCHEME)
1894 GValue value = { 0, };
1896 g_value_init (&value, G_TYPE_STRING);
1897 if (!gdk_screen_get_setting (settings->screen, pspec->name, &value))
1898 g_value_set_static_string (&value, "");
1899 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
1900 g_value_unset (&value);
1903 g_object_notify (G_OBJECT (settings), pspec->name);
1908 reset_rc_values_foreach (GQuark key_id,
1912 GtkSettingsValuePrivate *qvalue = data;
1913 GSList **to_reset = user_data;
1915 if (qvalue->source == GTK_SETTINGS_SOURCE_RC_FILE)
1916 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
1920 _gtk_settings_reset_rc_values (GtkSettings *settings)
1922 GSList *to_reset = NULL;
1924 GParamSpec **pspecs, **p;
1927 /* Remove any queued settings
1929 g_datalist_foreach (&settings->queued_settings,
1930 reset_rc_values_foreach,
1933 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
1935 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
1936 g_datalist_id_remove_data (&settings->queued_settings, key_id);
1939 g_slist_free (to_reset);
1941 /* Now reset the active settings
1943 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
1946 g_object_freeze_notify (G_OBJECT (settings));
1947 for (p = pspecs; *p; p++)
1949 if (settings->property_values[i].source == GTK_SETTINGS_SOURCE_RC_FILE)
1951 GParamSpec *pspec = *p;
1953 g_param_value_set_default (pspec, &settings->property_values[i].value);
1954 g_object_notify (G_OBJECT (settings), pspec->name);
1958 g_object_thaw_notify (G_OBJECT (settings));
1963 settings_update_double_click (GtkSettings *settings)
1965 if (gdk_screen_get_number (settings->screen) == 0)
1967 GdkDisplay *display = gdk_screen_get_display (settings->screen);
1968 gint double_click_time;
1969 gint double_click_distance;
1971 g_object_get (settings,
1972 "gtk-double-click-time", &double_click_time,
1973 "gtk-double-click-distance", &double_click_distance,
1976 gdk_display_set_double_click_time (display, double_click_time);
1977 gdk_display_set_double_click_distance (display, double_click_distance);
1982 settings_update_modules (GtkSettings *settings)
1986 g_object_get (settings,
1987 "gtk-modules", &modules,
1990 _gtk_modules_settings_changed (settings, modules);
1995 #ifdef GDK_WINDOWING_X11
1997 settings_update_cursor_theme (GtkSettings *settings)
1999 GdkDisplay *display = gdk_screen_get_display (settings->screen);
2000 gchar *theme = NULL;
2003 g_object_get (settings,
2004 "gtk-cursor-theme-name", &theme,
2005 "gtk-cursor-theme-size", &size,
2008 gdk_x11_display_set_cursor_theme (display, theme, size);
2014 settings_update_font_options (GtkSettings *settings)
2017 gchar *hint_style_str;
2018 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2020 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2022 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2023 cairo_font_options_t *options;
2025 g_object_get (settings,
2026 "gtk-xft-antialias", &antialias,
2027 "gtk-xft-hinting", &hinting,
2028 "gtk-xft-hintstyle", &hint_style_str,
2029 "gtk-xft-rgba", &rgba_str,
2032 options = cairo_font_options_create ();
2034 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2036 if (hinting >= 0 && !hinting)
2038 hint_style = CAIRO_HINT_STYLE_NONE;
2040 else if (hint_style_str)
2042 if (strcmp (hint_style_str, "hintnone") == 0)
2043 hint_style = CAIRO_HINT_STYLE_NONE;
2044 else if (strcmp (hint_style_str, "hintslight") == 0)
2045 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2046 else if (strcmp (hint_style_str, "hintmedium") == 0)
2047 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2048 else if (strcmp (hint_style_str, "hintfull") == 0)
2049 hint_style = CAIRO_HINT_STYLE_FULL;
2052 g_free (hint_style_str);
2054 cairo_font_options_set_hint_style (options, hint_style);
2058 if (strcmp (rgba_str, "rgb") == 0)
2059 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2060 else if (strcmp (rgba_str, "bgr") == 0)
2061 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2062 else if (strcmp (rgba_str, "vrgb") == 0)
2063 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2064 else if (strcmp (rgba_str, "vbgr") == 0)
2065 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2070 cairo_font_options_set_subpixel_order (options, subpixel_order);
2072 if (antialias >= 0 && !antialias)
2073 antialias_mode = CAIRO_ANTIALIAS_NONE;
2074 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2075 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2076 else if (antialias >= 0)
2077 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2079 cairo_font_options_set_antialias (options, antialias_mode);
2081 gdk_screen_set_font_options (settings->screen, options);
2083 cairo_font_options_destroy (options);
2086 #ifdef GDK_WINDOWING_X11
2088 settings_update_fontconfig (GtkSettings *settings)
2090 static guint last_update_timestamp;
2091 static gboolean last_update_needed;
2095 g_object_get (settings,
2096 "gtk-fontconfig-timestamp", ×tamp,
2099 /* if timestamp is the same as last_update_timestamp, we already have
2100 * updated fontconig on this timestamp (another screen requested it perhaps?),
2101 * just return the cached result.*/
2103 if (timestamp != last_update_timestamp)
2105 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2106 gboolean update_needed = FALSE;
2108 if (PANGO_IS_FC_FONT_MAP (fontmap) &&
2109 !FcConfigUptoDate (NULL) && FcInitReinitialize ())
2111 update_needed = TRUE;
2112 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2115 last_update_timestamp = timestamp;
2116 last_update_needed = update_needed;
2119 return last_update_needed;
2121 #endif /* GDK_WINDOWING_X11 */
2124 settings_update_resolution (GtkSettings *settings)
2129 g_object_get (settings,
2130 "gtk-xft-dpi", &dpi_int,
2134 dpi = dpi_int / 1024.;
2138 gdk_screen_set_resolution (settings->screen, dpi);
2143 GHashTable *color_hash;
2144 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2145 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2149 color_scheme_data_free (ColorSchemeData *data)
2153 g_hash_table_unref (data->color_hash);
2155 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2157 if (data->tables[i])
2158 g_hash_table_unref (data->tables[i]);
2159 g_free (data->lastentry[i]);
2162 g_slice_free (ColorSchemeData, data);
2166 settings_update_color_scheme (GtkSettings *settings)
2168 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2170 ColorSchemeData *data;
2171 GValue value = { 0, };
2173 data = g_slice_new0 (ColorSchemeData);
2174 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2175 (GDestroyNotify) gdk_color_free);
2176 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2177 data, (GDestroyNotify) color_scheme_data_free);
2179 g_value_init (&value, G_TYPE_STRING);
2180 if (gdk_screen_get_setting (settings->screen, "gtk-color-scheme", &value))
2182 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2183 g_value_unset (&value);
2189 add_color_to_hash (gchar *name,
2195 old = g_hash_table_lookup (target, name);
2196 if (!old || !gdk_color_equal (old, color))
2198 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2207 add_colors_to_hash_from_string (GHashTable *hash,
2208 const gchar *colors)
2210 gchar *s, *p, *name;
2212 gboolean changed = FALSE;
2215 copy = g_strdup (colors);
2220 p = strchr (s, ':');
2235 if (*s == '\n' || *s == ';')
2244 if (gdk_color_parse (p, &color))
2245 changed |= add_color_to_hash (name, &color, hash);
2254 update_color_hash (ColorSchemeData *data,
2256 GtkSettingsSource source)
2258 gboolean changed = FALSE;
2261 if ((str == NULL || *str == '\0') &&
2262 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2265 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2268 /* For the RC_FILE source we merge the values rather than over-writing
2269 * them, since multiple rc files might define independent sets of colors
2271 if ((source != GTK_SETTINGS_SOURCE_RC_FILE) &&
2272 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2274 g_hash_table_unref (data->tables[source]);
2275 data->tables[source] = NULL;
2276 changed = TRUE; /* We can't rely on the code below since str might be "" */
2279 if (data->tables[source] == NULL)
2280 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2282 (GDestroyNotify) gdk_color_free);
2284 g_free (data->lastentry[source]);
2285 data->lastentry[source] = g_strdup (str);
2287 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2292 /* Rebuild the merged hash table. */
2293 if (data->color_hash)
2294 g_hash_table_unref (data->color_hash);
2295 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2296 (GDestroyNotify) gdk_color_free);
2297 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2299 if (data->tables[i])
2300 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2308 merge_color_scheme (GtkSettings *settings,
2309 const GValue *value,
2310 GtkSettingsSource source)
2312 ColorSchemeData *data;
2313 const gchar *colors;
2315 g_object_freeze_notify (G_OBJECT (settings));
2317 colors = g_value_get_string (value);
2319 settings_update_color_scheme (settings);
2321 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2322 "gtk-color-scheme");
2324 if (update_color_hash (data, colors, source))
2325 g_object_notify (G_OBJECT (settings), "color-hash");
2327 g_object_thaw_notify (G_OBJECT (settings));
2331 get_color_hash (GtkSettings *settings)
2333 ColorSchemeData *data;
2335 settings_update_color_scheme (settings);
2337 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2338 "gtk-color-scheme");
2340 return data->color_hash;
2344 append_color_scheme (gpointer key,
2348 gchar *name = (gchar *)key;
2349 GdkColor *color = (GdkColor *)value;
2350 GString *string = (GString *)data;
2352 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2353 name, color->red, color->green, color->blue);
2357 get_color_scheme (GtkSettings *settings)
2359 ColorSchemeData *data;
2362 settings_update_color_scheme (settings);
2364 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2365 "gtk-color-scheme");
2367 string = g_string_new ("");
2369 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2371 return g_string_free (string, FALSE);
2375 #define __GTK_SETTINGS_C__
2376 #include "gtkaliasdef.c"