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 #ifdef GDK_WINDOWING_QUARTZ
39 #define DEFAULT_KEY_THEME "Mac"
41 #define DEFAULT_KEY_THEME NULL
44 #define DEFAULT_TIMEOUT_INITIAL 200
45 #define DEFAULT_TIMEOUT_REPEAT 20
46 #define DEFAULT_TIMEOUT_EXPAND 500
48 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
52 GTK_SETTINGS_SOURCE_DEFAULT,
53 GTK_SETTINGS_SOURCE_RC_FILE,
54 GTK_SETTINGS_SOURCE_XSETTING,
55 GTK_SETTINGS_SOURCE_APPLICATION
58 struct _GtkSettingsValuePrivate
60 GtkSettingsValue public;
61 GtkSettingsSource source;
64 struct _GtkSettingsPropertyValue
67 GtkSettingsSource source;
72 PROP_DOUBLE_CLICK_TIME,
73 PROP_DOUBLE_CLICK_DISTANCE,
75 PROP_CURSOR_BLINK_TIME,
76 PROP_CURSOR_BLINK_TIMEOUT,
80 PROP_FALLBACK_ICON_THEME,
83 PROP_DND_DRAG_THRESHOLD,
87 #ifdef GDK_WINDOWING_X11
93 PROP_CURSOR_THEME_NAME,
94 PROP_CURSOR_THEME_SIZE,
96 PROP_ALTERNATIVE_BUTTON_ORDER,
97 PROP_ALTERNATIVE_SORT_ARROWS,
98 PROP_SHOW_INPUT_METHOD_MENU,
99 PROP_SHOW_UNICODE_MENU,
100 PROP_TIMEOUT_INITIAL,
104 PROP_ENABLE_ANIMATIONS,
105 PROP_TOUCHSCREEN_MODE,
106 PROP_TOOLTIP_TIMEOUT,
107 PROP_TOOLTIP_BROWSE_TIMEOUT,
108 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
109 PROP_KEYNAV_CURSOR_ONLY,
110 PROP_KEYNAV_WRAP_AROUND,
113 PROP_FILE_CHOOSER_BACKEND,
115 PROP_PRINT_PREVIEW_COMMAND,
116 PROP_ENABLE_MNEMONICS,
118 PROP_RECENT_FILES_LIMIT,
120 PROP_RECENT_FILES_MAX_AGE,
121 PROP_FONTCONFIG_TIMESTAMP,
122 PROP_SOUND_THEME_NAME,
123 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
124 PROP_ENABLE_EVENT_SOUNDS,
125 PROP_ENABLE_TOOLTIPS,
127 PROP_TOOLBAR_ICON_SIZE
131 /* --- prototypes --- */
132 static void gtk_settings_finalize (GObject *object);
133 static void gtk_settings_get_property (GObject *object,
137 static void gtk_settings_set_property (GObject *object,
141 static void gtk_settings_notify (GObject *object,
143 static guint settings_install_property_parser (GtkSettingsClass *class,
145 GtkRcPropertyParser parser);
146 static void settings_update_double_click (GtkSettings *settings);
147 static void settings_update_modules (GtkSettings *settings);
149 #ifdef GDK_WINDOWING_X11
150 static void settings_update_cursor_theme (GtkSettings *settings);
151 static void settings_update_resolution (GtkSettings *settings);
152 static void settings_update_font_options (GtkSettings *settings);
153 static gboolean settings_update_fontconfig (GtkSettings *settings);
155 static void settings_update_color_scheme (GtkSettings *settings);
157 static void merge_color_scheme (GtkSettings *settings,
159 GtkSettingsSource source);
160 static gchar *get_color_scheme (GtkSettings *settings);
161 static GHashTable *get_color_hash (GtkSettings *settings);
164 /* --- variables --- */
165 static GQuark quark_property_parser = 0;
166 static GSList *object_list = NULL;
167 static guint class_n_properties = 0;
170 G_DEFINE_TYPE (GtkSettings, gtk_settings, G_TYPE_OBJECT)
172 /* --- functions --- */
174 gtk_settings_init (GtkSettings *settings)
176 GParamSpec **pspecs, **p;
179 g_datalist_init (&settings->queued_settings);
180 object_list = g_slist_prepend (object_list, settings);
182 /* build up property array for all yet existing properties and queue
183 * notification for them (at least notification for internal properties
184 * will instantly be caught)
186 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
187 for (p = pspecs; *p; p++)
188 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
190 settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
192 g_object_freeze_notify (G_OBJECT (settings));
193 for (p = pspecs; *p; p++)
195 GParamSpec *pspec = *p;
197 if (pspec->owner_type != G_OBJECT_TYPE (settings))
199 g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
200 g_param_value_set_default (pspec, &settings->property_values[i].value);
201 g_object_notify (G_OBJECT (settings), pspec->name);
202 settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
205 g_object_thaw_notify (G_OBJECT (settings));
210 gtk_settings_class_init (GtkSettingsClass *class)
212 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
215 gobject_class->finalize = gtk_settings_finalize;
216 gobject_class->get_property = gtk_settings_get_property;
217 gobject_class->set_property = gtk_settings_set_property;
218 gobject_class->notify = gtk_settings_notify;
220 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
221 result = settings_install_property_parser (class,
222 g_param_spec_int ("gtk-double-click-time",
223 P_("Double Click Time"),
224 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
226 GTK_PARAM_READWRITE),
228 g_assert (result == PROP_DOUBLE_CLICK_TIME);
229 result = settings_install_property_parser (class,
230 g_param_spec_int ("gtk-double-click-distance",
231 P_("Double Click Distance"),
232 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
234 GTK_PARAM_READWRITE),
236 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
239 * GtkSettings:gtk-cursor-blink:
241 * Whether the cursor should blink.
243 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
244 * which allows more flexible control over cursor blinking.
246 result = settings_install_property_parser (class,
247 g_param_spec_boolean ("gtk-cursor-blink",
249 P_("Whether the cursor should blink"),
251 GTK_PARAM_READWRITE),
253 g_assert (result == PROP_CURSOR_BLINK);
254 result = settings_install_property_parser (class,
255 g_param_spec_int ("gtk-cursor-blink-time",
256 P_("Cursor Blink Time"),
257 P_("Length of the cursor blink cycle, in milliseconds"),
259 GTK_PARAM_READWRITE),
261 g_assert (result == PROP_CURSOR_BLINK_TIME);
264 * GtkSettings:gtk-cursor-blink-timeout:
266 * Time after which the cursor stops blinking, in seconds.
267 * The timer is reset after each user interaction.
269 * Setting this to zero has the same effect as setting
270 * #GtkSettings:gtk-cursor-blink to %FALSE.
274 result = settings_install_property_parser (class,
275 g_param_spec_int ("gtk-cursor-blink-timeout",
276 P_("Cursor Blink Timeout"),
277 P_("Time after which the cursor stops blinking, in seconds"),
278 1, G_MAXINT, G_MAXINT,
279 GTK_PARAM_READWRITE),
281 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
282 result = settings_install_property_parser (class,
283 g_param_spec_boolean ("gtk-split-cursor",
285 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
287 GTK_PARAM_READWRITE),
289 g_assert (result == PROP_SPLIT_CURSOR);
290 result = settings_install_property_parser (class,
291 g_param_spec_string ("gtk-theme-name",
293 P_("Name of theme RC file to load"),
295 GTK_PARAM_READWRITE),
297 g_assert (result == PROP_THEME_NAME);
299 result = settings_install_property_parser (class,
300 g_param_spec_string ("gtk-icon-theme-name",
301 P_("Icon Theme Name"),
302 P_("Name of icon theme to use"),
304 GTK_PARAM_READWRITE),
306 g_assert (result == PROP_ICON_THEME_NAME);
308 result = settings_install_property_parser (class,
309 g_param_spec_string ("gtk-fallback-icon-theme",
310 P_("Fallback Icon Theme Name"),
311 P_("Name of a icon theme to fall back to"),
313 GTK_PARAM_READWRITE),
315 g_assert (result == PROP_FALLBACK_ICON_THEME);
317 result = settings_install_property_parser (class,
318 g_param_spec_string ("gtk-key-theme-name",
319 P_("Key Theme Name"),
320 P_("Name of key theme RC file to load"),
322 GTK_PARAM_READWRITE),
324 g_assert (result == PROP_KEY_THEME_NAME);
326 result = settings_install_property_parser (class,
327 g_param_spec_string ("gtk-menu-bar-accel",
328 P_("Menu bar accelerator"),
329 P_("Keybinding to activate the menu bar"),
331 GTK_PARAM_READWRITE),
333 g_assert (result == PROP_MENU_BAR_ACCEL);
335 result = settings_install_property_parser (class,
336 g_param_spec_int ("gtk-dnd-drag-threshold",
337 P_("Drag threshold"),
338 P_("Number of pixels the cursor can move before dragging"),
340 GTK_PARAM_READWRITE),
342 g_assert (result == PROP_DND_DRAG_THRESHOLD);
344 result = settings_install_property_parser (class,
345 g_param_spec_string ("gtk-font-name",
347 P_("Name of default font to use"),
349 GTK_PARAM_READWRITE),
351 g_assert (result == PROP_FONT_NAME);
354 * GtkSettings:gtk-icon-sizes:
356 * A list of icon sizes. The list is separated by colons, and
359 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
361 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
362 * GTK+ itself use the following named icon sizes: gtk-menu,
363 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
364 * gtk-dialog. Applications can register their own named icon
365 * sizes with gtk_icon_size_register().
367 result = settings_install_property_parser (class,
368 g_param_spec_string ("gtk-icon-sizes",
370 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
372 GTK_PARAM_READWRITE),
374 g_assert (result == PROP_ICON_SIZES);
376 result = settings_install_property_parser (class,
377 g_param_spec_string ("gtk-modules",
379 P_("List of currently active GTK modules"),
381 GTK_PARAM_READWRITE),
383 g_assert (result == PROP_MODULES);
385 #ifdef GDK_WINDOWING_X11
386 result = settings_install_property_parser (class,
387 g_param_spec_int ("gtk-xft-antialias",
389 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
391 GTK_PARAM_READWRITE),
394 g_assert (result == PROP_XFT_ANTIALIAS);
396 result = settings_install_property_parser (class,
397 g_param_spec_int ("gtk-xft-hinting",
399 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
401 GTK_PARAM_READWRITE),
404 g_assert (result == PROP_XFT_HINTING);
406 result = settings_install_property_parser (class,
407 g_param_spec_string ("gtk-xft-hintstyle",
408 P_("Xft Hint Style"),
409 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
411 GTK_PARAM_READWRITE),
414 g_assert (result == PROP_XFT_HINTSTYLE);
416 result = settings_install_property_parser (class,
417 g_param_spec_string ("gtk-xft-rgba",
419 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
421 GTK_PARAM_READWRITE),
424 g_assert (result == PROP_XFT_RGBA);
426 result = settings_install_property_parser (class,
427 g_param_spec_int ("gtk-xft-dpi",
429 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
431 GTK_PARAM_READWRITE),
434 g_assert (result == PROP_XFT_DPI);
436 result = settings_install_property_parser (class,
437 g_param_spec_string ("gtk-cursor-theme-name",
438 P_("Cursor theme name"),
439 P_("Name of the cursor theme to use, or NULL to use the default theme"),
441 GTK_PARAM_READWRITE),
443 g_assert (result == PROP_CURSOR_THEME_NAME);
445 result = settings_install_property_parser (class,
446 g_param_spec_int ("gtk-cursor-theme-size",
447 P_("Cursor theme size"),
448 P_("Size to use for cursors, or 0 to use the default size"),
450 GTK_PARAM_READWRITE),
453 g_assert (result == PROP_CURSOR_THEME_SIZE);
455 #endif /* GDK_WINDOWING_X11 */
456 result = settings_install_property_parser (class,
457 g_param_spec_boolean ("gtk-alternative-button-order",
458 P_("Alternative button order"),
459 P_("Whether buttons in dialogs should use the alternative button order"),
461 GTK_PARAM_READWRITE),
463 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
466 * GtkSettings:gtk-alternative-sort-arrows:
468 * Controls the direction of the sort indicators in sorted list and tree
469 * views. By default an arrow pointing down means the column is sorted
470 * in ascending order. When set to %TRUE, this order will be inverted.
474 result = settings_install_property_parser (class,
475 g_param_spec_boolean ("gtk-alternative-sort-arrows",
476 P_("Alternative sort indicator direction"),
477 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
479 GTK_PARAM_READWRITE),
481 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
483 result = settings_install_property_parser (class,
484 g_param_spec_boolean ("gtk-show-input-method-menu",
485 P_("Show the 'Input Methods' menu"),
486 P_("Whether the context menus of entries and text views should offer to change the input method"),
488 GTK_PARAM_READWRITE),
490 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
492 result = settings_install_property_parser (class,
493 g_param_spec_boolean ("gtk-show-unicode-menu",
494 P_("Show the 'Insert Unicode Control Character' menu"),
495 P_("Whether the context menus of entries and text views should offer to insert control characters"),
497 GTK_PARAM_READWRITE),
499 g_assert (result == PROP_SHOW_UNICODE_MENU);
501 result = settings_install_property_parser (class,
502 g_param_spec_int ("gtk-timeout-initial",
504 P_("Starting value for timeouts, when button is pressed"),
505 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
506 GTK_PARAM_READWRITE),
509 g_assert (result == PROP_TIMEOUT_INITIAL);
511 result = settings_install_property_parser (class,
512 g_param_spec_int ("gtk-timeout-repeat",
513 P_("Repeat timeout"),
514 P_("Repeat value for timeouts, when button is pressed"),
515 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
516 GTK_PARAM_READWRITE),
519 g_assert (result == PROP_TIMEOUT_REPEAT);
521 result = settings_install_property_parser (class,
522 g_param_spec_int ("gtk-timeout-expand",
523 P_("Expand timeout"),
524 P_("Expand value for timeouts, when a widget is expanding a new region"),
525 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
526 GTK_PARAM_READWRITE),
529 g_assert (result == PROP_TIMEOUT_EXPAND);
532 * GtkSettings:gtk-color-scheme:
534 * A palette of named colors for use in themes. The format of the string is
540 * Color names must be acceptable as identifiers in the
541 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
542 * color specifications must be in the format accepted by
545 * Note that due to the way the color tables from different sources are
546 * merged, color specifications will be converted to hexadecimal form
547 * when getting this property.
549 * Starting with GTK+ 2.12, the entries can alternatively be separated
550 * by ';' instead of newlines:
552 * name1: color1; name2: color2; ...
557 result = settings_install_property_parser (class,
558 g_param_spec_string ("gtk-color-scheme",
560 P_("A palette of named colors for use in themes"),
562 GTK_PARAM_READWRITE),
565 g_assert (result == PROP_COLOR_SCHEME);
567 result = settings_install_property_parser (class,
568 g_param_spec_boolean ("gtk-enable-animations",
569 P_("Enable Animations"),
570 P_("Whether to enable toolkit-wide animations."),
572 GTK_PARAM_READWRITE),
575 g_assert (result == PROP_ENABLE_ANIMATIONS);
578 * GtkSettings:gtk-touchscreen-mode:
580 * When %TRUE, there are no motion notify events delivered on this screen,
581 * and widgets can't use the pointer hovering them for any essential
586 result = settings_install_property_parser (class,
587 g_param_spec_boolean ("gtk-touchscreen-mode",
588 P_("Enable Touchscreen Mode"),
589 P_("When TRUE, there are no motion notify events delivered on this screen"),
591 GTK_PARAM_READWRITE),
594 g_assert (result == PROP_TOUCHSCREEN_MODE);
597 * GtkSettings:gtk-tooltip-timeout:
599 * Time, in milliseconds, after which a tooltip could appear if the
600 * cursor is hovering on top of a widget.
604 result = settings_install_property_parser (class,
605 g_param_spec_int ("gtk-tooltip-timeout",
606 P_("Tooltip timeout"),
607 P_("Timeout before tooltip is shown"),
610 GTK_PARAM_READWRITE),
613 g_assert (result == PROP_TOOLTIP_TIMEOUT);
616 * GtkSettings:gtk-tooltip-browse-timeout:
618 * Controls the time after which tooltips will appear when
619 * browse mode is enabled, in milliseconds.
621 * Browse mode is enabled when the mouse pointer moves off an object
622 * where a tooltip was currently being displayed. If the mouse pointer
623 * hits another object before the browse mode timeout expires (see
624 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
625 * amount of milliseconds specified by this setting to popup the tooltip
626 * for the new object.
630 result = settings_install_property_parser (class,
631 g_param_spec_int ("gtk-tooltip-browse-timeout",
632 P_("Tooltip browse timeout"),
633 P_("Timeout before tooltip is shown when browse mode is enabled"),
636 GTK_PARAM_READWRITE),
639 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
642 * GtkSettings:gtk-tooltip-browse-mode-timeout:
644 * Amount of time, in milliseconds, after which the browse mode
647 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
652 result = settings_install_property_parser (class,
653 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
654 P_("Tooltip browse mode timeout"),
655 P_("Timeout after which browse mode is disabled"),
658 GTK_PARAM_READWRITE),
661 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
664 * GtkSettings:gtk-keynav-cursor-only:
666 * When %TRUE, keyboard navigation should be able to reach all widgets
667 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
668 * to be present on the used input device.
672 result = settings_install_property_parser (class,
673 g_param_spec_boolean ("gtk-keynav-cursor-only",
674 P_("Keynav Cursor Only"),
675 P_("When TRUE, there are only cursor keys available to navigate widgets"),
677 GTK_PARAM_READWRITE),
680 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
683 * GtkSettings:gtk-keynav-wrap-around:
685 * When %TRUE, some widgets will wrap around when doing keyboard
686 * navigation, such as menus, menubars and notebooks.
690 result = settings_install_property_parser (class,
691 g_param_spec_boolean ("gtk-keynav-wrap-around",
692 P_("Keynav Wrap Around"),
693 P_("Whether to wrap around when keyboard-navigating widgets"),
695 GTK_PARAM_READWRITE),
698 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
701 * GtkSettings:gtk-error-bell:
703 * When %TRUE, keyboard navigation and other input-related errors
704 * will cause a beep. Since the error bell is implemented using
705 * gdk_window_beep(), the windowing system may offer ways to
706 * configure the error bell in many ways, such as flashing the
707 * window or similar visual effects.
711 result = settings_install_property_parser (class,
712 g_param_spec_boolean ("gtk-error-bell",
714 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
716 GTK_PARAM_READWRITE),
719 g_assert (result == PROP_ERROR_BELL);
722 * GtkSettings:color-hash:
724 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
725 * setting, mapping color names to #GdkColor<!-- -->s.
729 result = settings_install_property_parser (class,
730 g_param_spec_boxed ("color-hash",
732 P_("A hash table representation of the color scheme."),
736 g_assert (result == PROP_COLOR_HASH);
738 result = settings_install_property_parser (class,
739 g_param_spec_string ("gtk-file-chooser-backend",
740 P_("Default file chooser backend"),
741 P_("Name of the GtkFileChooser backend to use by default"),
743 GTK_PARAM_READWRITE),
745 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
748 * GtkSettings:gtk-print-backends:
750 * A comma-separated list of print backends to use in the print
751 * dialog. Available print backends depend on the GTK+ installation,
752 * and may include "file", "cups", "lpr" or "papi".
756 result = settings_install_property_parser (class,
757 g_param_spec_string ("gtk-print-backends",
758 P_("Default print backend"),
759 P_("List of the GtkPrintBackend backends to use by default"),
761 GTK_PARAM_READWRITE),
763 g_assert (result == PROP_PRINT_BACKENDS);
766 * GtkSettings:gtk-print-preview-command:
768 * A command to run for displaying the print preview. The command
769 * should contain a %f placeholder, which will get replaced by
770 * the path to the pdf file. The command may also contain a %s
771 * placeholder, which will get replaced by the path to a file
772 * containing the print settings in the format produced by
773 * gtk_print_settings_to_file().
775 * The preview application is responsible for removing the pdf file
776 * and the print settings file when it is done.
780 result = settings_install_property_parser (class,
781 g_param_spec_string ("gtk-print-preview-command",
782 P_("Default command to run when displaying a print preview"),
783 P_("Command to run when displaying a print preview"),
784 GTK_PRINT_PREVIEW_COMMAND,
785 GTK_PARAM_READWRITE),
787 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
790 * GtkSettings:gtk-enable-mnemonics:
792 * Whether labels and menu items should have visible mnemonics which
797 result = settings_install_property_parser (class,
798 g_param_spec_boolean ("gtk-enable-mnemonics",
799 P_("Enable Mnemonics"),
800 P_("Whether labels should have mnemonics"),
802 GTK_PARAM_READWRITE),
804 g_assert (result == PROP_ENABLE_MNEMONICS);
807 * GtkSettings:gtk-enable-accels:
809 * Whether menu items should have visible accelerators which can be
814 result = settings_install_property_parser (class,
815 g_param_spec_boolean ("gtk-enable-accels",
816 P_("Enable Accelerators"),
817 P_("Whether menu items should have accelerators"),
819 GTK_PARAM_READWRITE),
821 g_assert (result == PROP_ENABLE_ACCELS);
824 * GtkSettings:gtk-recent-files-limit:
826 * The number of recently used files that should be displayed by default by
827 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
828 * -1 means every recently used file stored.
832 result = settings_install_property_parser (class,
833 g_param_spec_int ("gtk-recent-files-limit",
834 P_("Recent Files Limit"),
835 P_("Number of recently used files"),
838 GTK_PARAM_READWRITE),
840 g_assert (result == PROP_RECENT_FILES_LIMIT);
843 * GtkSettings:gtk-im-module:
845 * Which IM (input method) module should be used by default. This is the
846 * input method that will be used if the user has not explicitly chosen
847 * another input method from the IM context menu.
849 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
851 result = settings_install_property_parser (class,
852 g_param_spec_string ("gtk-im-module",
853 P_("Default IM module"),
854 P_("Which IM module should be used by default"),
856 GTK_PARAM_READWRITE),
858 g_assert (result == PROP_IM_MODULE);
861 * GtkSettings:gtk-recent-files-max-age:
863 * The maximum age, in days, of the items inside the recently used
864 * resources list. Items older than this setting will be excised
865 * from the list. If set to 0, the list will always be empty; if
866 * set to -1, no item will be removed.
870 result = settings_install_property_parser (class,
871 g_param_spec_int ("gtk-recent-files-max-age",
872 P_("Recent Files Max Age"),
873 P_("Maximum age of recently used files, in days"),
876 GTK_PARAM_READWRITE),
878 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
880 result = settings_install_property_parser (class,
881 g_param_spec_uint ("gtk-fontconfig-timestamp",
882 P_("Fontconfig configuration timestamp"),
883 P_("Timestamp of current fontconfig configuration"),
885 GTK_PARAM_READWRITE),
888 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
891 * GtkSettings:gtk-sound-theme-name:
893 * The XDG sound theme to use for event sounds.
895 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
896 * for more information on event sounds and sound themes.
898 * GTK+ itself does not support event sounds, you have to use a loadable
899 * module like the one that comes with libcanberra.
903 result = settings_install_property_parser (class,
904 g_param_spec_string ("gtk-sound-theme-name",
905 P_("Sound Theme Name"),
906 P_("XDG sound theme name"),
908 GTK_PARAM_READWRITE),
910 g_assert (result == PROP_SOUND_THEME_NAME);
913 * GtkSettings:gtk-enable-input-feedback-sounds:
915 * Whether to play event sounds as feedback to user input.
917 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
918 * for more information on event sounds and sound themes.
920 * GTK+ itself does not support event sounds, you have to use a loadable
921 * module like the one that comes with libcanberra.
925 result = settings_install_property_parser (class,
926 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
927 /* Translators: this means sounds that are played as feedback to user input */
928 P_("Audible Input Feedback"),
929 P_("Whether to play event sounds as feedback to user input"),
931 GTK_PARAM_READWRITE),
933 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
936 * GtkSettings:gtk-enable-event-sounds:
938 * Whether to play any event sounds at all.
940 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
941 * for more information on event sounds and sound themes.
943 * GTK+ itself does not support event sounds, you have to use a loadable
944 * module like the one that comes with libcanberra.
948 result = settings_install_property_parser (class,
949 g_param_spec_boolean ("gtk-enable-event-sounds",
950 P_("Enable Event Sounds"),
951 P_("Whether to play any event sounds at all"),
953 GTK_PARAM_READWRITE),
955 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
958 * GtkSettings:gtk-enable-tooltips:
960 * Whether tooltips should be shown on widgets.
964 result = settings_install_property_parser (class,
965 g_param_spec_boolean ("gtk-enable-tooltips",
966 P_("Enable Tooltips"),
967 P_("Whether tooltips should be shown on widgets"),
969 GTK_PARAM_READWRITE),
971 g_assert (result == PROP_ENABLE_TOOLTIPS);
974 * GtkSettings:toolbar-style:
976 * The size of icons in default toolbars.
978 result = settings_install_property_parser (class,
979 g_param_spec_enum ("gtk-toolbar-style",
981 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
982 GTK_TYPE_TOOLBAR_STYLE,
984 GTK_PARAM_READWRITE),
985 gtk_rc_property_parse_enum);
986 g_assert (result == PROP_TOOLBAR_STYLE);
989 * GtkSettings:toolbar-icon-size:
991 * The size of icons in default toolbars.
993 result = settings_install_property_parser (class,
994 g_param_spec_enum ("gtk-toolbar-icon-size",
995 P_("Toolbar Icon Size"),
996 P_("The size of icons in default toolbars."),
998 GTK_ICON_SIZE_LARGE_TOOLBAR,
999 GTK_PARAM_READWRITE),
1000 gtk_rc_property_parse_enum);
1001 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1005 gtk_settings_finalize (GObject *object)
1007 GtkSettings *settings = GTK_SETTINGS (object);
1010 object_list = g_slist_remove (object_list, settings);
1012 _gtk_rc_context_destroy (settings);
1014 for (i = 0; i < class_n_properties; i++)
1015 g_value_unset (&settings->property_values[i].value);
1016 g_free (settings->property_values);
1018 g_datalist_clear (&settings->queued_settings);
1020 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1024 * gtk_settings_get_for_screen:
1025 * @screen : a #GdkScreen.
1027 * Gets the #GtkSettings object for @screen, creating it if necessary.
1029 * Return value: a #GtkSettings object.
1034 gtk_settings_get_for_screen (GdkScreen *screen)
1036 GtkSettings *settings;
1038 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1040 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1043 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1044 settings->screen = screen;
1045 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1046 settings, g_object_unref);
1048 gtk_rc_reparse_all_for_settings (settings, TRUE);
1049 settings_update_double_click (settings);
1050 #ifdef GDK_WINDOWING_X11
1051 settings_update_cursor_theme (settings);
1052 settings_update_resolution (settings);
1053 settings_update_font_options (settings);
1055 settings_update_color_scheme (settings);
1062 * gtk_settings_get_default:
1064 * Gets the #GtkSettings object for the default GDK screen, creating
1065 * it if necessary. See gtk_settings_get_for_screen().
1067 * Return value: (transfer none): a #GtkSettings object. If there is no default
1068 * screen, then returns %NULL.
1071 gtk_settings_get_default (void)
1073 GdkScreen *screen = gdk_screen_get_default ();
1076 return gtk_settings_get_for_screen (screen);
1082 gtk_settings_set_property (GObject *object,
1084 const GValue *value,
1087 GtkSettings *settings = GTK_SETTINGS (object);
1089 g_value_copy (value, &settings->property_values[property_id - 1].value);
1090 settings->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1092 if (pspec->param_id == PROP_COLOR_SCHEME)
1093 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1097 gtk_settings_get_property (GObject *object,
1102 GtkSettings *settings = GTK_SETTINGS (object);
1103 GType value_type = G_VALUE_TYPE (value);
1104 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1106 /* handle internal properties */
1107 switch (property_id)
1109 case PROP_COLOR_HASH:
1110 g_value_set_boxed (value, get_color_hash (settings));
1112 case PROP_COLOR_SCHEME:
1113 g_value_take_string (value, get_color_scheme (settings));
1118 /* For enums and strings, we need to get the value as a string,
1119 * not as an int, since we support using names/nicks as the setting
1122 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1123 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1124 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1125 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1127 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1128 !gdk_screen_get_setting (settings->screen, pspec->name, value))
1129 g_value_copy (&settings->property_values[property_id - 1].value, value);
1131 g_param_value_validate (pspec, value);
1135 GValue val = { 0, };
1137 /* Try to get xsetting as a string and parse it. */
1139 g_value_init (&val, G_TYPE_STRING);
1141 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1142 !gdk_screen_get_setting (settings->screen, pspec->name, &val))
1144 g_value_copy (&settings->property_values[property_id - 1].value, value);
1148 GValue tmp_value = { 0, };
1149 GValue gstring_value = { 0, };
1150 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1152 g_value_init (&gstring_value, G_TYPE_GSTRING);
1153 g_value_take_boxed (&gstring_value,
1154 g_string_new (g_value_get_string (&val)));
1156 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1158 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1161 g_value_copy (&tmp_value, value);
1162 g_param_value_validate (pspec, value);
1166 g_value_copy (&settings->property_values[property_id - 1].value, value);
1169 g_value_unset (&gstring_value);
1170 g_value_unset (&tmp_value);
1173 g_value_unset (&val);
1178 gtk_settings_notify (GObject *object,
1181 GtkSettings *settings = GTK_SETTINGS (object);
1182 guint property_id = pspec->param_id;
1184 if (settings->screen == NULL) /* initialization */
1187 switch (property_id)
1190 settings_update_modules (settings);
1192 case PROP_DOUBLE_CLICK_TIME:
1193 case PROP_DOUBLE_CLICK_DISTANCE:
1194 settings_update_double_click (settings);
1196 case PROP_COLOR_SCHEME:
1197 settings_update_color_scheme (settings);
1199 #ifdef GDK_WINDOWING_X11
1201 settings_update_resolution (settings);
1202 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1203 * widgets with gtk_widget_style_set(), and also causes more
1204 * recomputation than necessary.
1206 gtk_rc_reset_styles (GTK_SETTINGS (object));
1208 case PROP_XFT_ANTIALIAS:
1209 case PROP_XFT_HINTING:
1210 case PROP_XFT_HINTSTYLE:
1212 settings_update_font_options (settings);
1213 gtk_rc_reset_styles (GTK_SETTINGS (object));
1215 case PROP_FONTCONFIG_TIMESTAMP:
1216 if (settings_update_fontconfig (settings))
1217 gtk_rc_reset_styles (GTK_SETTINGS (object));
1219 case PROP_CURSOR_THEME_NAME:
1220 case PROP_CURSOR_THEME_SIZE:
1221 settings_update_cursor_theme (settings);
1223 #endif /* GDK_WINDOWING_X11 */
1228 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1229 const GValue *src_value,
1233 gboolean success = FALSE;
1235 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1240 gboolean free_gstring = TRUE;
1242 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1244 gstring = g_value_get_boxed (src_value);
1245 free_gstring = FALSE;
1247 else if (G_VALUE_HOLDS_LONG (src_value))
1249 gstring = g_string_new (NULL);
1250 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1252 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1254 gstring = g_string_new (NULL);
1255 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1257 else if (G_VALUE_HOLDS_STRING (src_value))
1259 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1261 gstring = g_string_new ("\"");
1262 g_string_append (gstring, tstr);
1263 g_string_append_c (gstring, '\"');
1268 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1269 gstring = NULL; /* silence compiler */
1272 success = (parser (pspec, gstring, dest_value) &&
1273 !g_param_value_validate (pspec, dest_value));
1276 g_string_free (gstring, TRUE);
1278 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1280 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1282 GString *gstring = g_value_get_boxed (src_value);
1284 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1285 success = !g_param_value_validate (pspec, dest_value);
1288 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1289 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1295 apply_queued_setting (GtkSettings *data,
1297 GtkSettingsValuePrivate *qvalue)
1299 GValue tmp_value = { 0, };
1300 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1302 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1303 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1306 if (pspec->param_id == PROP_COLOR_SCHEME)
1307 merge_color_scheme (data, &tmp_value, qvalue->source);
1309 if (data->property_values[pspec->param_id - 1].source <= qvalue->source)
1311 g_value_copy (&tmp_value, &data->property_values[pspec->param_id - 1].value);
1312 data->property_values[pspec->param_id - 1].source = qvalue->source;
1313 g_object_notify (G_OBJECT (data), g_param_spec_get_name (pspec));
1319 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1321 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1322 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1324 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1326 G_VALUE_TYPE_NAME (&tmp_value));
1329 g_value_unset (&tmp_value);
1333 settings_install_property_parser (GtkSettingsClass *class,
1335 GtkRcPropertyParser parser)
1337 GSList *node, *next;
1339 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1341 case G_TYPE_BOOLEAN:
1354 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1362 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1363 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1367 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1369 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1374 for (node = object_list; node; node = node->next)
1375 g_object_freeze_notify (node->data);
1377 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1378 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1380 for (node = object_list; node; node = node->next)
1382 GtkSettings *settings = node->data;
1383 GtkSettingsValuePrivate *qvalue;
1385 settings->property_values = g_renew (GtkSettingsPropertyValue, settings->property_values, class_n_properties);
1386 settings->property_values[class_n_properties - 1].value.g_type = 0;
1387 g_value_init (&settings->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1388 g_param_value_set_default (pspec, &settings->property_values[class_n_properties - 1].value);
1389 settings->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1390 g_object_notify (G_OBJECT (settings), pspec->name);
1392 qvalue = g_datalist_get_data (&settings->queued_settings, pspec->name);
1394 apply_queued_setting (settings, pspec, qvalue);
1397 for (node = object_list; node; node = next)
1400 g_object_thaw_notify (node->data);
1403 return class_n_properties;
1407 _gtk_rc_property_parser_from_type (GType type)
1409 if (type == GDK_TYPE_COLOR)
1410 return gtk_rc_property_parse_color;
1411 else if (type == GTK_TYPE_REQUISITION)
1412 return gtk_rc_property_parse_requisition;
1413 else if (type == GTK_TYPE_BORDER)
1414 return gtk_rc_property_parse_border;
1415 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1416 return gtk_rc_property_parse_enum;
1417 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1418 return gtk_rc_property_parse_flags;
1424 gtk_settings_install_property (GParamSpec *pspec)
1426 static GtkSettingsClass *klass = NULL;
1428 GtkRcPropertyParser parser;
1430 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1433 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1435 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1437 settings_install_property_parser (klass, pspec, parser);
1441 gtk_settings_install_property_parser (GParamSpec *pspec,
1442 GtkRcPropertyParser parser)
1444 static GtkSettingsClass *klass = NULL;
1446 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1447 g_return_if_fail (parser != NULL);
1450 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1452 settings_install_property_parser (klass, pspec, parser);
1456 free_value (gpointer data)
1458 GtkSettingsValuePrivate *qvalue = data;
1460 g_value_unset (&qvalue->public.value);
1461 g_free (qvalue->public.origin);
1462 g_slice_free (GtkSettingsValuePrivate, qvalue);
1466 gtk_settings_set_property_value_internal (GtkSettings *settings,
1467 const gchar *prop_name,
1468 const GtkSettingsValue *new_value,
1469 GtkSettingsSource source)
1471 GtkSettingsValuePrivate *qvalue;
1476 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1477 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1478 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1479 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1481 g_warning (G_STRLOC ": value type invalid");
1485 name = g_strdup (prop_name);
1486 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1487 name_quark = g_quark_from_string (name);
1490 qvalue = g_datalist_id_get_data (&settings->queued_settings, name_quark);
1493 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1494 g_datalist_id_set_data_full (&settings->queued_settings, name_quark, qvalue, free_value);
1498 g_free (qvalue->public.origin);
1499 g_value_unset (&qvalue->public.value);
1501 qvalue->public.origin = g_strdup (new_value->origin);
1502 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1503 g_value_copy (&new_value->value, &qvalue->public.value);
1504 qvalue->source = source;
1505 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1507 apply_queued_setting (settings, pspec, qvalue);
1511 gtk_settings_set_property_value (GtkSettings *settings,
1512 const gchar *prop_name,
1513 const GtkSettingsValue *new_value)
1515 g_return_if_fail (GTK_SETTINGS (settings));
1516 g_return_if_fail (prop_name != NULL);
1517 g_return_if_fail (new_value != NULL);
1519 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1520 GTK_SETTINGS_SOURCE_APPLICATION);
1524 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1525 const gchar *prop_name,
1526 const GtkSettingsValue *new_value)
1528 g_return_if_fail (GTK_SETTINGS (settings));
1529 g_return_if_fail (prop_name != NULL);
1530 g_return_if_fail (new_value != NULL);
1532 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1533 GTK_SETTINGS_SOURCE_RC_FILE);
1537 gtk_settings_set_string_property (GtkSettings *settings,
1539 const gchar *v_string,
1540 const gchar *origin)
1542 GtkSettingsValue svalue = { NULL, { 0, }, };
1544 g_return_if_fail (GTK_SETTINGS (settings));
1545 g_return_if_fail (name != NULL);
1546 g_return_if_fail (v_string != NULL);
1548 svalue.origin = (gchar*) origin;
1549 g_value_init (&svalue.value, G_TYPE_STRING);
1550 g_value_set_static_string (&svalue.value, v_string);
1551 gtk_settings_set_property_value (settings, name, &svalue);
1552 g_value_unset (&svalue.value);
1556 gtk_settings_set_long_property (GtkSettings *settings,
1559 const gchar *origin)
1561 GtkSettingsValue svalue = { NULL, { 0, }, };
1563 g_return_if_fail (GTK_SETTINGS (settings));
1564 g_return_if_fail (name != NULL);
1566 svalue.origin = (gchar*) origin;
1567 g_value_init (&svalue.value, G_TYPE_LONG);
1568 g_value_set_long (&svalue.value, v_long);
1569 gtk_settings_set_property_value (settings, name, &svalue);
1570 g_value_unset (&svalue.value);
1574 gtk_settings_set_double_property (GtkSettings *settings,
1577 const gchar *origin)
1579 GtkSettingsValue svalue = { NULL, { 0, }, };
1581 g_return_if_fail (GTK_SETTINGS (settings));
1582 g_return_if_fail (name != NULL);
1584 svalue.origin = (gchar*) origin;
1585 g_value_init (&svalue.value, G_TYPE_DOUBLE);
1586 g_value_set_double (&svalue.value, v_double);
1587 gtk_settings_set_property_value (settings, name, &svalue);
1588 g_value_unset (&svalue.value);
1592 * gtk_rc_property_parse_color:
1593 * @pspec: a #GParamSpec
1594 * @gstring: the #GString to be parsed
1595 * @property_value: a #GValue which must hold #GdkColor values.
1597 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1598 * or gtk_widget_class_install_style_property_parser() which parses a
1599 * color given either by its name or in the form
1600 * <literal>{ red, green, blue }</literal> where %red, %green and
1601 * %blue are integers between 0 and 65535 or floating-point numbers
1604 * Return value: %TRUE if @gstring could be parsed and @property_value
1605 * has been set to the resulting #GdkColor.
1608 gtk_rc_property_parse_color (const GParamSpec *pspec,
1609 const GString *gstring,
1610 GValue *property_value)
1612 GdkColor color = { 0, 0, 0, 0, };
1616 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1617 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
1619 scanner = gtk_rc_scanner_new ();
1620 g_scanner_input_text (scanner, gstring->str, gstring->len);
1621 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
1622 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
1624 g_value_set_boxed (property_value, &color);
1629 g_scanner_destroy (scanner);
1635 * gtk_rc_property_parse_enum:
1636 * @pspec: a #GParamSpec
1637 * @gstring: the #GString to be parsed
1638 * @property_value: a #GValue which must hold enum values.
1640 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1641 * or gtk_widget_class_install_style_property_parser() which parses a single
1642 * enumeration value.
1644 * The enumeration value can be specified by its name, its nickname or
1645 * its numeric value. For consistency with flags parsing, the value
1646 * may be surrounded by parentheses.
1648 * Return value: %TRUE if @gstring could be parsed and @property_value
1649 * has been set to the resulting #GEnumValue.
1652 gtk_rc_property_parse_enum (const GParamSpec *pspec,
1653 const GString *gstring,
1654 GValue *property_value)
1656 gboolean need_closing_brace = FALSE, success = FALSE;
1658 GEnumValue *enum_value = NULL;
1660 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1661 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
1663 scanner = gtk_rc_scanner_new ();
1664 g_scanner_input_text (scanner, gstring->str, gstring->len);
1666 /* we just want to parse _one_ value, but for consistency with flags parsing
1667 * we support optional parenthesis
1669 g_scanner_get_next_token (scanner);
1670 if (scanner->token == '(')
1672 need_closing_brace = TRUE;
1673 g_scanner_get_next_token (scanner);
1675 if (scanner->token == G_TOKEN_IDENTIFIER)
1677 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
1679 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
1681 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
1684 g_value_set_enum (property_value, enum_value->value);
1688 else if (scanner->token == G_TOKEN_INT)
1690 g_value_set_enum (property_value, scanner->value.v_int);
1693 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
1695 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
1698 g_scanner_destroy (scanner);
1704 parse_flags_value (GScanner *scanner,
1708 g_scanner_get_next_token (scanner);
1709 if (scanner->token == G_TOKEN_IDENTIFIER)
1711 GFlagsValue *flags_value;
1713 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
1715 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
1718 *number |= flags_value->value;
1719 return G_TOKEN_NONE;
1722 else if (scanner->token == G_TOKEN_INT)
1724 *number |= scanner->value.v_int;
1725 return G_TOKEN_NONE;
1727 return G_TOKEN_IDENTIFIER;
1731 * gtk_rc_property_parse_flags:
1732 * @pspec: a #GParamSpec
1733 * @gstring: the #GString to be parsed
1734 * @property_value: a #GValue which must hold flags values.
1736 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1737 * or gtk_widget_class_install_style_property_parser() which parses flags.
1739 * Flags can be specified by their name, their nickname or
1740 * numerically. Multiple flags can be specified in the form
1741 * <literal>"( flag1 | flag2 | ... )"</literal>.
1743 * Return value: %TRUE if @gstring could be parsed and @property_value
1744 * has been set to the resulting flags value.
1747 gtk_rc_property_parse_flags (const GParamSpec *pspec,
1748 const GString *gstring,
1749 GValue *property_value)
1752 gboolean success = FALSE;
1755 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1756 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
1758 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
1759 scanner = gtk_rc_scanner_new ();
1760 g_scanner_input_text (scanner, gstring->str, gstring->len);
1762 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
1763 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
1764 scanner->next_token == G_TOKEN_INT)
1766 guint token, flags_value = 0;
1768 token = parse_flags_value (scanner, class, &flags_value);
1770 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1773 g_value_set_flags (property_value, flags_value);
1777 else if (g_scanner_get_next_token (scanner) == '(')
1779 guint token, flags_value = 0;
1781 /* parse first value */
1782 token = parse_flags_value (scanner, class, &flags_value);
1784 /* parse nth values, preceeded by '|' */
1785 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
1786 token = parse_flags_value (scanner, class, &flags_value);
1788 /* done, last token must have closed expression */
1789 if (token == G_TOKEN_NONE && scanner->token == ')' &&
1790 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1792 g_value_set_flags (property_value, flags_value);
1796 g_scanner_destroy (scanner);
1802 get_braced_int (GScanner *scanner,
1809 g_scanner_get_next_token (scanner);
1810 if (scanner->token != '{')
1814 g_scanner_get_next_token (scanner);
1815 if (scanner->token != G_TOKEN_INT)
1818 *value = scanner->value.v_int;
1822 g_scanner_get_next_token (scanner);
1823 if (scanner->token != '}')
1828 g_scanner_get_next_token (scanner);
1829 if (scanner->token != ',')
1837 * gtk_rc_property_parse_requisition:
1838 * @pspec: a #GParamSpec
1839 * @gstring: the #GString to be parsed
1840 * @property_value: a #GValue which must hold boxed 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 * requisition in the form
1845 * <literal>"{ width, height }"</literal> for integers %width and %height.
1847 * Return value: %TRUE if @gstring could be parsed and @property_value
1848 * has been set to the resulting #GtkRequisition.
1851 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
1852 const GString *gstring,
1853 GValue *property_value)
1855 GtkRequisition requisition;
1857 gboolean success = FALSE;
1859 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1860 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1862 scanner = gtk_rc_scanner_new ();
1863 g_scanner_input_text (scanner, gstring->str, gstring->len);
1865 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
1866 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
1868 g_value_set_boxed (property_value, &requisition);
1872 g_scanner_destroy (scanner);
1878 * gtk_rc_property_parse_border:
1879 * @pspec: a #GParamSpec
1880 * @gstring: the #GString to be parsed
1881 * @property_value: a #GValue which must hold boxed values.
1883 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1884 * or gtk_widget_class_install_style_property_parser() which parses
1885 * borders in the form
1886 * <literal>"{ left, right, top, bottom }"</literal> for integers
1887 * %left, %right, %top and %bottom.
1889 * Return value: %TRUE if @gstring could be parsed and @property_value
1890 * has been set to the resulting #GtkBorder.
1893 gtk_rc_property_parse_border (const GParamSpec *pspec,
1894 const GString *gstring,
1895 GValue *property_value)
1899 gboolean success = FALSE;
1901 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1902 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1904 scanner = gtk_rc_scanner_new ();
1905 g_scanner_input_text (scanner, gstring->str, gstring->len);
1907 if (get_braced_int (scanner, TRUE, FALSE, &border.left) &&
1908 get_braced_int (scanner, FALSE, FALSE, &border.right) &&
1909 get_braced_int (scanner, FALSE, FALSE, &border.top) &&
1910 get_braced_int (scanner, FALSE, TRUE, &border.bottom))
1912 g_value_set_boxed (property_value, &border);
1916 g_scanner_destroy (scanner);
1922 _gtk_settings_handle_event (GdkEventSetting *event)
1924 GtkSettings *settings;
1928 settings = gtk_settings_get_for_screen (gdk_drawable_get_screen (event->window));
1929 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
1933 property_id = pspec->param_id;
1935 if (property_id == PROP_COLOR_SCHEME)
1937 GValue value = { 0, };
1939 g_value_init (&value, G_TYPE_STRING);
1940 if (!gdk_screen_get_setting (settings->screen, pspec->name, &value))
1941 g_value_set_static_string (&value, "");
1942 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
1943 g_value_unset (&value);
1945 g_object_notify (G_OBJECT (settings), pspec->name);
1950 reset_rc_values_foreach (GQuark key_id,
1954 GtkSettingsValuePrivate *qvalue = data;
1955 GSList **to_reset = user_data;
1957 if (qvalue->source == GTK_SETTINGS_SOURCE_RC_FILE)
1958 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
1962 _gtk_settings_reset_rc_values (GtkSettings *settings)
1964 GSList *to_reset = NULL;
1966 GParamSpec **pspecs, **p;
1969 /* Remove any queued settings
1971 g_datalist_foreach (&settings->queued_settings,
1972 reset_rc_values_foreach,
1975 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
1977 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
1978 g_datalist_id_remove_data (&settings->queued_settings, key_id);
1981 g_slist_free (to_reset);
1983 /* Now reset the active settings
1985 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
1988 g_object_freeze_notify (G_OBJECT (settings));
1989 for (p = pspecs; *p; p++)
1991 if (settings->property_values[i].source == GTK_SETTINGS_SOURCE_RC_FILE)
1993 GParamSpec *pspec = *p;
1995 g_param_value_set_default (pspec, &settings->property_values[i].value);
1996 g_object_notify (G_OBJECT (settings), pspec->name);
2000 g_object_thaw_notify (G_OBJECT (settings));
2005 settings_update_double_click (GtkSettings *settings)
2007 if (gdk_screen_get_number (settings->screen) == 0)
2009 GdkDisplay *display = gdk_screen_get_display (settings->screen);
2010 gint double_click_time;
2011 gint double_click_distance;
2013 g_object_get (settings,
2014 "gtk-double-click-time", &double_click_time,
2015 "gtk-double-click-distance", &double_click_distance,
2018 gdk_display_set_double_click_time (display, double_click_time);
2019 gdk_display_set_double_click_distance (display, double_click_distance);
2024 settings_update_modules (GtkSettings *settings)
2028 g_object_get (settings,
2029 "gtk-modules", &modules,
2032 _gtk_modules_settings_changed (settings, modules);
2037 #ifdef GDK_WINDOWING_X11
2039 settings_update_cursor_theme (GtkSettings *settings)
2041 GdkDisplay *display = gdk_screen_get_display (settings->screen);
2042 gchar *theme = NULL;
2045 g_object_get (settings,
2046 "gtk-cursor-theme-name", &theme,
2047 "gtk-cursor-theme-size", &size,
2050 gdk_x11_display_set_cursor_theme (display, theme, size);
2056 settings_update_font_options (GtkSettings *settings)
2059 gchar *hint_style_str;
2060 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2062 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2064 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2065 cairo_font_options_t *options;
2067 g_object_get (settings,
2068 "gtk-xft-antialias", &antialias,
2069 "gtk-xft-hinting", &hinting,
2070 "gtk-xft-hintstyle", &hint_style_str,
2071 "gtk-xft-rgba", &rgba_str,
2074 options = cairo_font_options_create ();
2076 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2078 if (hinting >= 0 && !hinting)
2080 hint_style = CAIRO_HINT_STYLE_NONE;
2082 else if (hint_style_str)
2084 if (strcmp (hint_style_str, "hintnone") == 0)
2085 hint_style = CAIRO_HINT_STYLE_NONE;
2086 else if (strcmp (hint_style_str, "hintslight") == 0)
2087 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2088 else if (strcmp (hint_style_str, "hintmedium") == 0)
2089 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2090 else if (strcmp (hint_style_str, "hintfull") == 0)
2091 hint_style = CAIRO_HINT_STYLE_FULL;
2094 g_free (hint_style_str);
2096 cairo_font_options_set_hint_style (options, hint_style);
2100 if (strcmp (rgba_str, "rgb") == 0)
2101 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2102 else if (strcmp (rgba_str, "bgr") == 0)
2103 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2104 else if (strcmp (rgba_str, "vrgb") == 0)
2105 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2106 else if (strcmp (rgba_str, "vbgr") == 0)
2107 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2112 cairo_font_options_set_subpixel_order (options, subpixel_order);
2114 if (antialias >= 0 && !antialias)
2115 antialias_mode = CAIRO_ANTIALIAS_NONE;
2116 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2117 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2118 else if (antialias >= 0)
2119 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2121 cairo_font_options_set_antialias (options, antialias_mode);
2123 gdk_screen_set_font_options (settings->screen, options);
2125 cairo_font_options_destroy (options);
2128 #ifdef GDK_WINDOWING_X11
2130 settings_update_fontconfig (GtkSettings *settings)
2132 static guint last_update_timestamp;
2133 static gboolean last_update_needed;
2137 g_object_get (settings,
2138 "gtk-fontconfig-timestamp", ×tamp,
2141 /* if timestamp is the same as last_update_timestamp, we already have
2142 * updated fontconig on this timestamp (another screen requested it perhaps?),
2143 * just return the cached result.*/
2145 if (timestamp != last_update_timestamp)
2147 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2148 gboolean update_needed = FALSE;
2151 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2153 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2154 if (FcInitReinitialize ())
2155 update_needed = TRUE;
2158 last_update_timestamp = timestamp;
2159 last_update_needed = update_needed;
2162 return last_update_needed;
2164 #endif /* GDK_WINDOWING_X11 */
2167 settings_update_resolution (GtkSettings *settings)
2172 g_object_get (settings,
2173 "gtk-xft-dpi", &dpi_int,
2177 dpi = dpi_int / 1024.;
2181 gdk_screen_set_resolution (settings->screen, dpi);
2186 GHashTable *color_hash;
2187 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2188 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2192 color_scheme_data_free (ColorSchemeData *data)
2196 g_hash_table_unref (data->color_hash);
2198 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2200 if (data->tables[i])
2201 g_hash_table_unref (data->tables[i]);
2202 g_free (data->lastentry[i]);
2205 g_slice_free (ColorSchemeData, data);
2209 settings_update_color_scheme (GtkSettings *settings)
2211 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2213 ColorSchemeData *data;
2214 GValue value = { 0, };
2216 data = g_slice_new0 (ColorSchemeData);
2217 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2218 (GDestroyNotify) gdk_color_free);
2219 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2220 data, (GDestroyNotify) color_scheme_data_free);
2222 g_value_init (&value, G_TYPE_STRING);
2223 if (gdk_screen_get_setting (settings->screen, "gtk-color-scheme", &value))
2225 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2226 g_value_unset (&value);
2232 add_color_to_hash (gchar *name,
2238 old = g_hash_table_lookup (target, name);
2239 if (!old || !gdk_color_equal (old, color))
2241 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2250 add_colors_to_hash_from_string (GHashTable *hash,
2251 const gchar *colors)
2253 gchar *s, *p, *name;
2255 gboolean changed = FALSE;
2258 copy = g_strdup (colors);
2263 p = strchr (s, ':');
2278 if (*s == '\n' || *s == ';')
2287 if (gdk_color_parse (p, &color))
2288 changed |= add_color_to_hash (name, &color, hash);
2297 update_color_hash (ColorSchemeData *data,
2299 GtkSettingsSource source)
2301 gboolean changed = FALSE;
2303 GHashTable *old_hash;
2304 GHashTableIter iter;
2308 if ((str == NULL || *str == '\0') &&
2309 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2312 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2315 /* For the RC_FILE source we merge the values rather than over-writing
2316 * them, since multiple rc files might define independent sets of colors
2318 if ((source != GTK_SETTINGS_SOURCE_RC_FILE) &&
2319 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2321 g_hash_table_unref (data->tables[source]);
2322 data->tables[source] = NULL;
2323 changed = TRUE; /* We can't rely on the code below since str might be "" */
2326 if (data->tables[source] == NULL)
2327 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2329 (GDestroyNotify) gdk_color_free);
2331 g_free (data->lastentry[source]);
2332 data->lastentry[source] = g_strdup (str);
2334 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2339 /* Rebuild the merged hash table. */
2340 if (data->color_hash)
2342 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2343 (GDestroyNotify) gdk_color_free);
2345 g_hash_table_iter_init (&iter, data->color_hash);
2346 while (g_hash_table_iter_next (&iter, &name, &color))
2348 g_hash_table_insert (old_hash, name, color);
2349 g_hash_table_iter_steal (&iter);
2357 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2359 if (data->tables[i])
2360 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2366 /* now check if the merged hash has changed */
2368 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2372 GHashTableIter iter;
2373 gpointer key, value, new_value;
2375 g_hash_table_iter_init (&iter, old_hash);
2376 while (g_hash_table_iter_next (&iter, &key, &value))
2378 new_value = g_hash_table_lookup (data->color_hash, key);
2379 if (!new_value || !gdk_color_equal (value, new_value))
2387 g_hash_table_unref (old_hash);
2396 merge_color_scheme (GtkSettings *settings,
2397 const GValue *value,
2398 GtkSettingsSource source)
2400 ColorSchemeData *data;
2401 const gchar *colors;
2403 g_object_freeze_notify (G_OBJECT (settings));
2405 colors = g_value_get_string (value);
2407 settings_update_color_scheme (settings);
2409 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2410 "gtk-color-scheme");
2412 if (update_color_hash (data, colors, source))
2413 g_object_notify (G_OBJECT (settings), "color-hash");
2415 g_object_thaw_notify (G_OBJECT (settings));
2419 get_color_hash (GtkSettings *settings)
2421 ColorSchemeData *data;
2423 settings_update_color_scheme (settings);
2425 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2426 "gtk-color-scheme");
2428 return data->color_hash;
2432 append_color_scheme (gpointer key,
2436 gchar *name = (gchar *)key;
2437 GdkColor *color = (GdkColor *)value;
2438 GString *string = (GString *)data;
2440 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2441 name, color->red, color->green, color->blue);
2445 get_color_scheme (GtkSettings *settings)
2447 ColorSchemeData *data;
2450 settings_update_color_scheme (settings);
2452 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2453 "gtk-color-scheme");
2455 string = g_string_new ("");
2457 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2459 return g_string_free (string, FALSE);
2463 #define __GTK_SETTINGS_C__
2464 #include "gtkaliasdef.c"