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,
129 /* --- prototypes --- */
130 static void gtk_settings_finalize (GObject *object);
131 static void gtk_settings_get_property (GObject *object,
135 static void gtk_settings_set_property (GObject *object,
139 static void gtk_settings_notify (GObject *object,
141 static guint settings_install_property_parser (GtkSettingsClass *class,
143 GtkRcPropertyParser parser);
144 static void settings_update_double_click (GtkSettings *settings);
145 static void settings_update_modules (GtkSettings *settings);
147 #ifdef GDK_WINDOWING_X11
148 static void settings_update_cursor_theme (GtkSettings *settings);
149 static void settings_update_resolution (GtkSettings *settings);
150 static void settings_update_font_options (GtkSettings *settings);
151 static gboolean settings_update_fontconfig (GtkSettings *settings);
153 static void settings_update_color_scheme (GtkSettings *settings);
155 static void merge_color_scheme (GtkSettings *settings,
157 GtkSettingsSource source);
158 static gchar *get_color_scheme (GtkSettings *settings);
159 static GHashTable *get_color_hash (GtkSettings *settings);
162 /* --- variables --- */
163 static GQuark quark_property_parser = 0;
164 static GSList *object_list = NULL;
165 static guint class_n_properties = 0;
168 G_DEFINE_TYPE (GtkSettings, gtk_settings, G_TYPE_OBJECT)
170 /* --- functions --- */
172 gtk_settings_init (GtkSettings *settings)
174 GParamSpec **pspecs, **p;
177 g_datalist_init (&settings->queued_settings);
178 object_list = g_slist_prepend (object_list, settings);
180 /* build up property array for all yet existing properties and queue
181 * notification for them (at least notification for internal properties
182 * will instantly be caught)
184 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
185 for (p = pspecs; *p; p++)
186 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
188 settings->property_values = g_new0 (GtkSettingsPropertyValue, i);
190 g_object_freeze_notify (G_OBJECT (settings));
191 for (p = pspecs; *p; p++)
193 GParamSpec *pspec = *p;
195 if (pspec->owner_type != G_OBJECT_TYPE (settings))
197 g_value_init (&settings->property_values[i].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
198 g_param_value_set_default (pspec, &settings->property_values[i].value);
199 g_object_notify (G_OBJECT (settings), pspec->name);
200 settings->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
203 g_object_thaw_notify (G_OBJECT (settings));
208 gtk_settings_class_init (GtkSettingsClass *class)
210 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
213 gobject_class->finalize = gtk_settings_finalize;
214 gobject_class->get_property = gtk_settings_get_property;
215 gobject_class->set_property = gtk_settings_set_property;
216 gobject_class->notify = gtk_settings_notify;
218 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
219 result = settings_install_property_parser (class,
220 g_param_spec_int ("gtk-double-click-time",
221 P_("Double Click Time"),
222 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
224 GTK_PARAM_READWRITE),
226 g_assert (result == PROP_DOUBLE_CLICK_TIME);
227 result = settings_install_property_parser (class,
228 g_param_spec_int ("gtk-double-click-distance",
229 P_("Double Click Distance"),
230 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
232 GTK_PARAM_READWRITE),
234 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
237 * GtkSettings:gtk-cursor-blink:
239 * Whether the cursor should blink.
241 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
242 * which allows more flexible control over cursor blinking.
244 result = settings_install_property_parser (class,
245 g_param_spec_boolean ("gtk-cursor-blink",
247 P_("Whether the cursor should blink"),
249 GTK_PARAM_READWRITE),
251 g_assert (result == PROP_CURSOR_BLINK);
252 result = settings_install_property_parser (class,
253 g_param_spec_int ("gtk-cursor-blink-time",
254 P_("Cursor Blink Time"),
255 P_("Length of the cursor blink cycle, in milliseconds"),
257 GTK_PARAM_READWRITE),
259 g_assert (result == PROP_CURSOR_BLINK_TIME);
262 * GtkSettings:gtk-cursor-blink-timeout:
264 * Time after which the cursor stops blinking, in seconds.
265 * The timer is reset after each user interaction.
267 * Setting this to zero has the same effect as setting
268 * #GtkSettings:gtk-cursor-blink to %FALSE.
272 result = settings_install_property_parser (class,
273 g_param_spec_int ("gtk-cursor-blink-timeout",
274 P_("Cursor Blink Timeout"),
275 P_("Time after which the cursor stops blinking, in seconds"),
276 1, G_MAXINT, G_MAXINT,
277 GTK_PARAM_READWRITE),
279 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
280 result = settings_install_property_parser (class,
281 g_param_spec_boolean ("gtk-split-cursor",
283 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
285 GTK_PARAM_READWRITE),
287 g_assert (result == PROP_SPLIT_CURSOR);
288 result = settings_install_property_parser (class,
289 g_param_spec_string ("gtk-theme-name",
291 P_("Name of theme RC file to load"),
293 GTK_PARAM_READWRITE),
295 g_assert (result == PROP_THEME_NAME);
297 result = settings_install_property_parser (class,
298 g_param_spec_string ("gtk-icon-theme-name",
299 P_("Icon Theme Name"),
300 P_("Name of icon theme to use"),
302 GTK_PARAM_READWRITE),
304 g_assert (result == PROP_ICON_THEME_NAME);
306 result = settings_install_property_parser (class,
307 g_param_spec_string ("gtk-fallback-icon-theme",
308 P_("Fallback Icon Theme Name"),
309 P_("Name of a icon theme to fall back to"),
311 GTK_PARAM_READWRITE),
313 g_assert (result == PROP_FALLBACK_ICON_THEME);
315 result = settings_install_property_parser (class,
316 g_param_spec_string ("gtk-key-theme-name",
317 P_("Key Theme Name"),
318 P_("Name of key theme RC file to load"),
320 GTK_PARAM_READWRITE),
322 g_assert (result == PROP_KEY_THEME_NAME);
324 result = settings_install_property_parser (class,
325 g_param_spec_string ("gtk-menu-bar-accel",
326 P_("Menu bar accelerator"),
327 P_("Keybinding to activate the menu bar"),
329 GTK_PARAM_READWRITE),
331 g_assert (result == PROP_MENU_BAR_ACCEL);
333 result = settings_install_property_parser (class,
334 g_param_spec_int ("gtk-dnd-drag-threshold",
335 P_("Drag threshold"),
336 P_("Number of pixels the cursor can move before dragging"),
338 GTK_PARAM_READWRITE),
340 g_assert (result == PROP_DND_DRAG_THRESHOLD);
342 result = settings_install_property_parser (class,
343 g_param_spec_string ("gtk-font-name",
345 P_("Name of default font to use"),
347 GTK_PARAM_READWRITE),
349 g_assert (result == PROP_FONT_NAME);
352 * GtkSettings:gtk-icon-sizes:
354 * A list of icon sizes. The list is separated by colons, and
357 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
359 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
360 * GTK+ itself use the following named icon sizes: gtk-menu,
361 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
362 * gtk-dialog. Applications can register their own named icon
363 * sizes with gtk_icon_size_register().
365 result = settings_install_property_parser (class,
366 g_param_spec_string ("gtk-icon-sizes",
368 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
370 GTK_PARAM_READWRITE),
372 g_assert (result == PROP_ICON_SIZES);
374 result = settings_install_property_parser (class,
375 g_param_spec_string ("gtk-modules",
377 P_("List of currently active GTK modules"),
379 GTK_PARAM_READWRITE),
381 g_assert (result == PROP_MODULES);
383 #ifdef GDK_WINDOWING_X11
384 result = settings_install_property_parser (class,
385 g_param_spec_int ("gtk-xft-antialias",
387 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
389 GTK_PARAM_READWRITE),
392 g_assert (result == PROP_XFT_ANTIALIAS);
394 result = settings_install_property_parser (class,
395 g_param_spec_int ("gtk-xft-hinting",
397 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
399 GTK_PARAM_READWRITE),
402 g_assert (result == PROP_XFT_HINTING);
404 result = settings_install_property_parser (class,
405 g_param_spec_string ("gtk-xft-hintstyle",
406 P_("Xft Hint Style"),
407 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
409 GTK_PARAM_READWRITE),
412 g_assert (result == PROP_XFT_HINTSTYLE);
414 result = settings_install_property_parser (class,
415 g_param_spec_string ("gtk-xft-rgba",
417 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
419 GTK_PARAM_READWRITE),
422 g_assert (result == PROP_XFT_RGBA);
424 result = settings_install_property_parser (class,
425 g_param_spec_int ("gtk-xft-dpi",
427 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
429 GTK_PARAM_READWRITE),
432 g_assert (result == PROP_XFT_DPI);
434 result = settings_install_property_parser (class,
435 g_param_spec_string ("gtk-cursor-theme-name",
436 P_("Cursor theme name"),
437 P_("Name of the cursor theme to use, or NULL to use the default theme"),
439 GTK_PARAM_READWRITE),
441 g_assert (result == PROP_CURSOR_THEME_NAME);
443 result = settings_install_property_parser (class,
444 g_param_spec_int ("gtk-cursor-theme-size",
445 P_("Cursor theme size"),
446 P_("Size to use for cursors, or 0 to use the default size"),
448 GTK_PARAM_READWRITE),
451 g_assert (result == PROP_CURSOR_THEME_SIZE);
453 #endif /* GDK_WINDOWING_X11 */
454 result = settings_install_property_parser (class,
455 g_param_spec_boolean ("gtk-alternative-button-order",
456 P_("Alternative button order"),
457 P_("Whether buttons in dialogs should use the alternative button order"),
459 GTK_PARAM_READWRITE),
461 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
464 * GtkSettings:gtk-alternative-sort-arrows:
466 * Controls the direction of the sort indicators in sorted list and tree
467 * views. By default an arrow pointing down means the column is sorted
468 * in ascending order. When set to %TRUE, this order will be inverted.
472 result = settings_install_property_parser (class,
473 g_param_spec_boolean ("gtk-alternative-sort-arrows",
474 P_("Alternative sort indicator direction"),
475 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
477 GTK_PARAM_READWRITE),
479 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
481 result = settings_install_property_parser (class,
482 g_param_spec_boolean ("gtk-show-input-method-menu",
483 P_("Show the 'Input Methods' menu"),
484 P_("Whether the context menus of entries and text views should offer to change the input method"),
486 GTK_PARAM_READWRITE),
488 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
490 result = settings_install_property_parser (class,
491 g_param_spec_boolean ("gtk-show-unicode-menu",
492 P_("Show the 'Insert Unicode Control Character' menu"),
493 P_("Whether the context menus of entries and text views should offer to insert control characters"),
495 GTK_PARAM_READWRITE),
497 g_assert (result == PROP_SHOW_UNICODE_MENU);
499 result = settings_install_property_parser (class,
500 g_param_spec_int ("gtk-timeout-initial",
502 P_("Starting value for timeouts, when button is pressed"),
503 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
504 GTK_PARAM_READWRITE),
507 g_assert (result == PROP_TIMEOUT_INITIAL);
509 result = settings_install_property_parser (class,
510 g_param_spec_int ("gtk-timeout-repeat",
511 P_("Repeat timeout"),
512 P_("Repeat value for timeouts, when button is pressed"),
513 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
514 GTK_PARAM_READWRITE),
517 g_assert (result == PROP_TIMEOUT_REPEAT);
519 result = settings_install_property_parser (class,
520 g_param_spec_int ("gtk-timeout-expand",
521 P_("Expand timeout"),
522 P_("Expand value for timeouts, when a widget is expanding a new region"),
523 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
524 GTK_PARAM_READWRITE),
527 g_assert (result == PROP_TIMEOUT_EXPAND);
530 * GtkSettings:gtk-color-scheme:
532 * A palette of named colors for use in themes. The format of the string is
538 * Color names must be acceptable as identifiers in the
539 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
540 * color specifications must be in the format accepted by
543 * Note that due to the way the color tables from different sources are
544 * merged, color specifications will be converted to hexadecimal form
545 * when getting this property.
547 * Starting with GTK+ 2.12, the entries can alternatively be separated
548 * by ';' instead of newlines:
550 * name1: color1; name2: color2; ...
555 result = settings_install_property_parser (class,
556 g_param_spec_string ("gtk-color-scheme",
558 P_("A palette of named colors for use in themes"),
560 GTK_PARAM_READWRITE),
563 g_assert (result == PROP_COLOR_SCHEME);
565 result = settings_install_property_parser (class,
566 g_param_spec_boolean ("gtk-enable-animations",
567 P_("Enable Animations"),
568 P_("Whether to enable toolkit-wide animations."),
570 GTK_PARAM_READWRITE),
573 g_assert (result == PROP_ENABLE_ANIMATIONS);
576 * GtkSettings:gtk-touchscreen-mode:
578 * When %TRUE, there are no motion notify events delivered on this screen,
579 * and widgets can't use the pointer hovering them for any essential
584 result = settings_install_property_parser (class,
585 g_param_spec_boolean ("gtk-touchscreen-mode",
586 P_("Enable Touchscreen Mode"),
587 P_("When TRUE, there are no motion notify events delivered on this screen"),
589 GTK_PARAM_READWRITE),
592 g_assert (result == PROP_TOUCHSCREEN_MODE);
595 * GtkSettings:gtk-tooltip-timeout:
597 * Time, in milliseconds, after which a tooltip could appear if the
598 * cursor is hovering on top of a widget.
602 result = settings_install_property_parser (class,
603 g_param_spec_int ("gtk-tooltip-timeout",
604 P_("Tooltip timeout"),
605 P_("Timeout before tooltip is shown"),
608 GTK_PARAM_READWRITE),
611 g_assert (result == PROP_TOOLTIP_TIMEOUT);
614 * GtkSettings:gtk-tooltip-browse-timeout:
616 * Controls the time after which tooltips will appear when
617 * browse mode is enabled, in milliseconds.
619 * Browse mode is enabled when the mouse pointer moves off an object
620 * where a tooltip was currently being displayed. If the mouse pointer
621 * hits another object before the browse mode timeout expires (see
622 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
623 * amount of milliseconds specified by this setting to popup the tooltip
624 * for the new object.
628 result = settings_install_property_parser (class,
629 g_param_spec_int ("gtk-tooltip-browse-timeout",
630 P_("Tooltip browse timeout"),
631 P_("Timeout before tooltip is shown when browse mode is enabled"),
634 GTK_PARAM_READWRITE),
637 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
640 * GtkSettings:gtk-tooltip-browse-mode-timeout:
642 * Amount of time, in milliseconds, after which the browse mode
645 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
650 result = settings_install_property_parser (class,
651 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
652 P_("Tooltip browse mode timeout"),
653 P_("Timeout after which browse mode is disabled"),
656 GTK_PARAM_READWRITE),
659 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
662 * GtkSettings:gtk-keynav-cursor-only:
664 * When %TRUE, keyboard navigation should be able to reach all widgets
665 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
666 * to be present on the used input device.
670 result = settings_install_property_parser (class,
671 g_param_spec_boolean ("gtk-keynav-cursor-only",
672 P_("Keynav Cursor Only"),
673 P_("When TRUE, there are only cursor keys available to navigate widgets"),
675 GTK_PARAM_READWRITE),
678 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
681 * GtkSettings:gtk-keynav-wrap-around:
683 * When %TRUE, some widgets will wrap around when doing keyboard
684 * navigation, such as menus, menubars and notebooks.
688 result = settings_install_property_parser (class,
689 g_param_spec_boolean ("gtk-keynav-wrap-around",
690 P_("Keynav Wrap Around"),
691 P_("Whether to wrap around when keyboard-navigating widgets"),
693 GTK_PARAM_READWRITE),
696 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
699 * GtkSettings:gtk-error-bell:
701 * When %TRUE, keyboard navigation and other input-related errors
702 * will cause a beep. Since the error bell is implemented using
703 * gdk_window_beep(), the windowing system may offer ways to
704 * configure the error bell in many ways, such as flashing the
705 * window or similar visual effects.
709 result = settings_install_property_parser (class,
710 g_param_spec_boolean ("gtk-error-bell",
712 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
714 GTK_PARAM_READWRITE),
717 g_assert (result == PROP_ERROR_BELL);
720 * GtkSettings:color-hash:
722 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
723 * setting, mapping color names to #GdkColor<!-- -->s.
727 result = settings_install_property_parser (class,
728 g_param_spec_boxed ("color-hash",
730 P_("A hash table representation of the color scheme."),
734 g_assert (result == PROP_COLOR_HASH);
736 result = settings_install_property_parser (class,
737 g_param_spec_string ("gtk-file-chooser-backend",
738 P_("Default file chooser backend"),
739 P_("Name of the GtkFileChooser backend to use by default"),
741 GTK_PARAM_READWRITE),
743 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
746 * GtkSettings:gtk-print-backends:
748 * A comma-separated list of print backends to use in the print
749 * dialog. Available print backends depend on the GTK+ installation,
750 * and may include "file", "cups", "lpr" or "papi".
754 result = settings_install_property_parser (class,
755 g_param_spec_string ("gtk-print-backends",
756 P_("Default print backend"),
757 P_("List of the GtkPrintBackend backends to use by default"),
759 GTK_PARAM_READWRITE),
761 g_assert (result == PROP_PRINT_BACKENDS);
764 * GtkSettings:gtk-print-preview-command:
766 * A command to run for displaying the print preview. The command
767 * should contain a %f placeholder, which will get replaced by
768 * the path to the pdf file. The command may also contain a %s
769 * placeholder, which will get replaced by the path to a file
770 * containing the print settings in the format produced by
771 * gtk_print_settings_to_file().
773 * The preview application is responsible for removing the pdf file
774 * and the print settings file when it is done.
778 result = settings_install_property_parser (class,
779 g_param_spec_string ("gtk-print-preview-command",
780 P_("Default command to run when displaying a print preview"),
781 P_("Command to run when displaying a print preview"),
782 GTK_PRINT_PREVIEW_COMMAND,
783 GTK_PARAM_READWRITE),
785 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
788 * GtkSettings:gtk-enable-mnemonics:
790 * Whether labels and menu items should have visible mnemonics which
795 result = settings_install_property_parser (class,
796 g_param_spec_boolean ("gtk-enable-mnemonics",
797 P_("Enable Mnemonics"),
798 P_("Whether labels should have mnemonics"),
800 GTK_PARAM_READWRITE),
802 g_assert (result == PROP_ENABLE_MNEMONICS);
805 * GtkSettings:gtk-enable-accels:
807 * Whether menu items should have visible accelerators which can be
812 result = settings_install_property_parser (class,
813 g_param_spec_boolean ("gtk-enable-accels",
814 P_("Enable Accelerators"),
815 P_("Whether menu items should have accelerators"),
817 GTK_PARAM_READWRITE),
819 g_assert (result == PROP_ENABLE_ACCELS);
822 * GtkSettings:gtk-recent-files-limit:
824 * The number of recently used files that should be displayed by default by
825 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
826 * -1 means every recently used file stored.
830 result = settings_install_property_parser (class,
831 g_param_spec_int ("gtk-recent-files-limit",
832 P_("Recent Files Limit"),
833 P_("Number of recently used files"),
836 GTK_PARAM_READWRITE),
838 g_assert (result == PROP_RECENT_FILES_LIMIT);
841 * GtkSettings:gtk-im-module:
843 * Which IM (input method) module should be used by default. This is the
844 * input method that will be used if the user has not explicitly chosen
845 * another input method from the IM context menu.
847 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
849 result = settings_install_property_parser (class,
850 g_param_spec_string ("gtk-im-module",
851 P_("Default IM module"),
852 P_("Which IM module should be used by default"),
854 GTK_PARAM_READWRITE),
856 g_assert (result == PROP_IM_MODULE);
859 * GtkSettings:gtk-recent-files-max-age:
861 * The maximum age, in days, of the items inside the recently used
862 * resources list. Items older than this setting will be excised
863 * from the list. If set to 0, the list will always be empty; if
864 * set to -1, no item will be removed.
868 result = settings_install_property_parser (class,
869 g_param_spec_int ("gtk-recent-files-max-age",
870 P_("Recent Files Max Age"),
871 P_("Maximum age of recently used files, in days"),
874 GTK_PARAM_READWRITE),
876 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
878 result = settings_install_property_parser (class,
879 g_param_spec_uint ("gtk-fontconfig-timestamp",
880 P_("Fontconfig configuration timestamp"),
881 P_("Timestamp of current fontconfig configuration"),
883 GTK_PARAM_READWRITE),
886 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
889 * GtkSettings:gtk-sound-theme-name:
891 * The XDG sound theme to use for event sounds.
893 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
894 * for more information on event sounds and sound themes.
896 * GTK+ itself does not support event sounds, you have to use a loadable
897 * module like the one that comes with libcanberra.
901 result = settings_install_property_parser (class,
902 g_param_spec_string ("gtk-sound-theme-name",
903 P_("Sound Theme Name"),
904 P_("XDG sound theme name"),
906 GTK_PARAM_READWRITE),
908 g_assert (result == PROP_SOUND_THEME_NAME);
911 * GtkSettings:gtk-enable-input-feedback-sounds:
913 * Whether to play event sounds as feedback to user input.
915 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
916 * for more information on event sounds and sound themes.
918 * GTK+ itself does not support event sounds, you have to use a loadable
919 * module like the one that comes with libcanberra.
923 result = settings_install_property_parser (class,
924 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
925 /* Translators: this means sounds that are played as feedback to user input */
926 P_("Audible Input Feedback"),
927 P_("Whether to play event sounds as feedback to user input"),
929 GTK_PARAM_READWRITE),
931 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
934 * GtkSettings:gtk-enable-event-sounds:
936 * Whether to play any event sounds at all.
938 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
939 * for more information on event sounds and sound themes.
941 * GTK+ itself does not support event sounds, you have to use a loadable
942 * module like the one that comes with libcanberra.
946 result = settings_install_property_parser (class,
947 g_param_spec_boolean ("gtk-enable-event-sounds",
948 P_("Enable Event Sounds"),
949 P_("Whether to play any event sounds at all"),
951 GTK_PARAM_READWRITE),
953 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
956 * GtkSettings:gtk-enable-tooltips:
958 * Whether tooltips should be shown on widgets.
962 result = settings_install_property_parser (class,
963 g_param_spec_boolean ("gtk-enable-tooltips",
964 P_("Enable Tooltips"),
965 P_("Whether tooltips should be shown on widgets"),
967 GTK_PARAM_READWRITE),
969 g_assert (result == PROP_ENABLE_TOOLTIPS);
973 gtk_settings_finalize (GObject *object)
975 GtkSettings *settings = GTK_SETTINGS (object);
978 object_list = g_slist_remove (object_list, settings);
980 _gtk_rc_context_destroy (settings);
982 for (i = 0; i < class_n_properties; i++)
983 g_value_unset (&settings->property_values[i].value);
984 g_free (settings->property_values);
986 g_datalist_clear (&settings->queued_settings);
988 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
992 * gtk_settings_get_for_screen:
993 * @screen : a #GdkScreen.
995 * Gets the #GtkSettings object for @screen, creating it if necessary.
997 * Return value: a #GtkSettings object.
1002 gtk_settings_get_for_screen (GdkScreen *screen)
1004 GtkSettings *settings;
1006 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1008 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1011 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1012 settings->screen = screen;
1013 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1014 settings, g_object_unref);
1016 gtk_rc_reparse_all_for_settings (settings, TRUE);
1017 settings_update_double_click (settings);
1018 #ifdef GDK_WINDOWING_X11
1019 settings_update_cursor_theme (settings);
1020 settings_update_resolution (settings);
1021 settings_update_font_options (settings);
1023 settings_update_color_scheme (settings);
1030 * gtk_settings_get_default:
1032 * Gets the #GtkSettings object for the default GDK screen, creating
1033 * it if necessary. See gtk_settings_get_for_screen().
1035 * Return value: a #GtkSettings object. If there is no default
1036 * screen, then returns %NULL.
1039 gtk_settings_get_default (void)
1041 GdkScreen *screen = gdk_screen_get_default ();
1044 return gtk_settings_get_for_screen (screen);
1050 gtk_settings_set_property (GObject *object,
1052 const GValue *value,
1055 GtkSettings *settings = GTK_SETTINGS (object);
1057 g_value_copy (value, &settings->property_values[property_id - 1].value);
1058 settings->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1060 if (pspec->param_id == PROP_COLOR_SCHEME)
1061 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1065 gtk_settings_get_property (GObject *object,
1070 GtkSettings *settings = GTK_SETTINGS (object);
1071 GType value_type = G_VALUE_TYPE (value);
1072 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1074 /* handle internal properties */
1075 switch (property_id)
1077 case PROP_COLOR_HASH:
1078 g_value_set_boxed (value, get_color_hash (settings));
1080 case PROP_COLOR_SCHEME:
1081 g_value_take_string (value, get_color_scheme (settings));
1086 /* For enums and strings, we need to get the value as a string,
1087 * not as an int, since we support using names/nicks as the setting
1090 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1091 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1092 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1093 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1095 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1096 !gdk_screen_get_setting (settings->screen, pspec->name, value))
1097 g_value_copy (&settings->property_values[property_id - 1].value, value);
1099 g_param_value_validate (pspec, value);
1103 GValue val = { 0, };
1105 /* Try to get xsetting as a string and parse it. */
1107 g_value_init (&val, G_TYPE_STRING);
1109 if (settings->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1110 !gdk_screen_get_setting (settings->screen, pspec->name, &val))
1112 g_value_copy (&settings->property_values[property_id - 1].value, value);
1116 GValue tmp_value = { 0, };
1117 GValue gstring_value = { 0, };
1118 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1120 g_value_init (&gstring_value, G_TYPE_GSTRING);
1121 g_value_take_boxed (&gstring_value,
1122 g_string_new (g_value_get_string (&val)));
1124 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1126 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1129 g_value_copy (&tmp_value, value);
1130 g_param_value_validate (pspec, value);
1134 g_value_copy (&settings->property_values[property_id - 1].value, value);
1137 g_value_unset (&gstring_value);
1138 g_value_unset (&tmp_value);
1141 g_value_unset (&val);
1146 gtk_settings_notify (GObject *object,
1149 GtkSettings *settings = GTK_SETTINGS (object);
1150 guint property_id = pspec->param_id;
1152 if (settings->screen == NULL) /* initialization */
1155 switch (property_id)
1158 settings_update_modules (settings);
1160 case PROP_DOUBLE_CLICK_TIME:
1161 case PROP_DOUBLE_CLICK_DISTANCE:
1162 settings_update_double_click (settings);
1164 case PROP_COLOR_SCHEME:
1165 settings_update_color_scheme (settings);
1167 #ifdef GDK_WINDOWING_X11
1169 settings_update_resolution (settings);
1170 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1171 * widgets with gtk_widget_style_set(), and also causes more
1172 * recomputation than necessary.
1174 gtk_rc_reset_styles (GTK_SETTINGS (object));
1176 case PROP_XFT_ANTIALIAS:
1177 case PROP_XFT_HINTING:
1178 case PROP_XFT_HINTSTYLE:
1180 settings_update_font_options (settings);
1181 gtk_rc_reset_styles (GTK_SETTINGS (object));
1183 case PROP_FONTCONFIG_TIMESTAMP:
1184 if (settings_update_fontconfig (settings))
1185 gtk_rc_reset_styles (GTK_SETTINGS (object));
1187 case PROP_CURSOR_THEME_NAME:
1188 case PROP_CURSOR_THEME_SIZE:
1189 settings_update_cursor_theme (settings);
1191 #endif /* GDK_WINDOWING_X11 */
1196 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1197 const GValue *src_value,
1201 gboolean success = FALSE;
1203 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1208 gboolean free_gstring = TRUE;
1210 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1212 gstring = g_value_get_boxed (src_value);
1213 free_gstring = FALSE;
1215 else if (G_VALUE_HOLDS_LONG (src_value))
1217 gstring = g_string_new (NULL);
1218 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1220 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1222 gstring = g_string_new (NULL);
1223 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1225 else if (G_VALUE_HOLDS_STRING (src_value))
1227 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1229 gstring = g_string_new ("\"");
1230 g_string_append (gstring, tstr);
1231 g_string_append_c (gstring, '\"');
1236 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1237 gstring = NULL; /* silence compiler */
1240 success = (parser (pspec, gstring, dest_value) &&
1241 !g_param_value_validate (pspec, dest_value));
1244 g_string_free (gstring, TRUE);
1246 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1248 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1250 GString *gstring = g_value_get_boxed (src_value);
1252 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1253 success = !g_param_value_validate (pspec, dest_value);
1256 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1257 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1263 apply_queued_setting (GtkSettings *data,
1265 GtkSettingsValuePrivate *qvalue)
1267 GValue tmp_value = { 0, };
1268 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1270 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1271 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1274 if (pspec->param_id == PROP_COLOR_SCHEME)
1275 merge_color_scheme (data, &tmp_value, qvalue->source);
1277 if (data->property_values[pspec->param_id - 1].source <= qvalue->source)
1279 g_value_copy (&tmp_value, &data->property_values[pspec->param_id - 1].value);
1280 data->property_values[pspec->param_id - 1].source = qvalue->source;
1281 g_object_notify (G_OBJECT (data), g_param_spec_get_name (pspec));
1287 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1289 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1290 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1292 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1294 G_VALUE_TYPE_NAME (&tmp_value));
1297 g_value_unset (&tmp_value);
1301 settings_install_property_parser (GtkSettingsClass *class,
1303 GtkRcPropertyParser parser)
1305 GSList *node, *next;
1307 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1309 case G_TYPE_BOOLEAN:
1321 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1329 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1330 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1334 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1336 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1341 for (node = object_list; node; node = node->next)
1342 g_object_freeze_notify (node->data);
1344 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1345 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1347 for (node = object_list; node; node = node->next)
1349 GtkSettings *settings = node->data;
1350 GtkSettingsValuePrivate *qvalue;
1352 settings->property_values = g_renew (GtkSettingsPropertyValue, settings->property_values, class_n_properties);
1353 settings->property_values[class_n_properties - 1].value.g_type = 0;
1354 g_value_init (&settings->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1355 g_param_value_set_default (pspec, &settings->property_values[class_n_properties - 1].value);
1356 settings->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1357 g_object_notify (G_OBJECT (settings), pspec->name);
1359 qvalue = g_datalist_get_data (&settings->queued_settings, pspec->name);
1361 apply_queued_setting (settings, pspec, qvalue);
1364 for (node = object_list; node; node = next)
1367 g_object_thaw_notify (node->data);
1370 return class_n_properties;
1374 _gtk_rc_property_parser_from_type (GType type)
1376 if (type == GDK_TYPE_COLOR)
1377 return gtk_rc_property_parse_color;
1378 else if (type == GTK_TYPE_REQUISITION)
1379 return gtk_rc_property_parse_requisition;
1380 else if (type == GTK_TYPE_BORDER)
1381 return gtk_rc_property_parse_border;
1382 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1383 return gtk_rc_property_parse_enum;
1384 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1385 return gtk_rc_property_parse_flags;
1391 gtk_settings_install_property (GParamSpec *pspec)
1393 static GtkSettingsClass *klass = NULL;
1395 GtkRcPropertyParser parser;
1397 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1400 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1402 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1404 settings_install_property_parser (klass, pspec, parser);
1408 gtk_settings_install_property_parser (GParamSpec *pspec,
1409 GtkRcPropertyParser parser)
1411 static GtkSettingsClass *klass = NULL;
1413 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1414 g_return_if_fail (parser != NULL);
1417 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1419 settings_install_property_parser (klass, pspec, parser);
1423 free_value (gpointer data)
1425 GtkSettingsValuePrivate *qvalue = data;
1427 g_value_unset (&qvalue->public.value);
1428 g_free (qvalue->public.origin);
1429 g_slice_free (GtkSettingsValuePrivate, qvalue);
1433 gtk_settings_set_property_value_internal (GtkSettings *settings,
1434 const gchar *prop_name,
1435 const GtkSettingsValue *new_value,
1436 GtkSettingsSource source)
1438 GtkSettingsValuePrivate *qvalue;
1443 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1444 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1445 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1446 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1448 g_warning (G_STRLOC ": value type invalid");
1452 name = g_strdup (prop_name);
1453 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1454 name_quark = g_quark_from_string (name);
1457 qvalue = g_datalist_id_get_data (&settings->queued_settings, name_quark);
1460 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1461 g_datalist_id_set_data_full (&settings->queued_settings, name_quark, qvalue, free_value);
1465 g_free (qvalue->public.origin);
1466 g_value_unset (&qvalue->public.value);
1468 qvalue->public.origin = g_strdup (new_value->origin);
1469 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1470 g_value_copy (&new_value->value, &qvalue->public.value);
1471 qvalue->source = source;
1472 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1474 apply_queued_setting (settings, pspec, qvalue);
1478 gtk_settings_set_property_value (GtkSettings *settings,
1479 const gchar *prop_name,
1480 const GtkSettingsValue *new_value)
1482 g_return_if_fail (GTK_SETTINGS (settings));
1483 g_return_if_fail (prop_name != NULL);
1484 g_return_if_fail (new_value != NULL);
1486 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1487 GTK_SETTINGS_SOURCE_APPLICATION);
1491 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1492 const gchar *prop_name,
1493 const GtkSettingsValue *new_value)
1495 g_return_if_fail (GTK_SETTINGS (settings));
1496 g_return_if_fail (prop_name != NULL);
1497 g_return_if_fail (new_value != NULL);
1499 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1500 GTK_SETTINGS_SOURCE_RC_FILE);
1504 gtk_settings_set_string_property (GtkSettings *settings,
1506 const gchar *v_string,
1507 const gchar *origin)
1509 GtkSettingsValue svalue = { NULL, { 0, }, };
1511 g_return_if_fail (GTK_SETTINGS (settings));
1512 g_return_if_fail (name != NULL);
1513 g_return_if_fail (v_string != NULL);
1515 svalue.origin = (gchar*) origin;
1516 g_value_init (&svalue.value, G_TYPE_STRING);
1517 g_value_set_static_string (&svalue.value, v_string);
1518 gtk_settings_set_property_value (settings, name, &svalue);
1519 g_value_unset (&svalue.value);
1523 gtk_settings_set_long_property (GtkSettings *settings,
1526 const gchar *origin)
1528 GtkSettingsValue svalue = { NULL, { 0, }, };
1530 g_return_if_fail (GTK_SETTINGS (settings));
1531 g_return_if_fail (name != NULL);
1533 svalue.origin = (gchar*) origin;
1534 g_value_init (&svalue.value, G_TYPE_LONG);
1535 g_value_set_long (&svalue.value, v_long);
1536 gtk_settings_set_property_value (settings, name, &svalue);
1537 g_value_unset (&svalue.value);
1541 gtk_settings_set_double_property (GtkSettings *settings,
1544 const gchar *origin)
1546 GtkSettingsValue svalue = { NULL, { 0, }, };
1548 g_return_if_fail (GTK_SETTINGS (settings));
1549 g_return_if_fail (name != NULL);
1551 svalue.origin = (gchar*) origin;
1552 g_value_init (&svalue.value, G_TYPE_DOUBLE);
1553 g_value_set_double (&svalue.value, v_double);
1554 gtk_settings_set_property_value (settings, name, &svalue);
1555 g_value_unset (&svalue.value);
1559 * gtk_rc_property_parse_color:
1560 * @pspec: a #GParamSpec
1561 * @gstring: the #GString to be parsed
1562 * @property_value: a #GValue which must hold #GdkColor values.
1564 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1565 * or gtk_widget_class_install_style_property_parser() which parses a
1566 * color given either by its name or in the form
1567 * <literal>{ red, green, blue }</literal> where %red, %green and
1568 * %blue are integers between 0 and 65535 or floating-point numbers
1571 * Return value: %TRUE if @gstring could be parsed and @property_value
1572 * has been set to the resulting #GdkColor.
1575 gtk_rc_property_parse_color (const GParamSpec *pspec,
1576 const GString *gstring,
1577 GValue *property_value)
1579 GdkColor color = { 0, 0, 0, 0, };
1583 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1584 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
1586 scanner = gtk_rc_scanner_new ();
1587 g_scanner_input_text (scanner, gstring->str, gstring->len);
1588 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
1589 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
1591 g_value_set_boxed (property_value, &color);
1596 g_scanner_destroy (scanner);
1602 * gtk_rc_property_parse_enum:
1603 * @pspec: a #GParamSpec
1604 * @gstring: the #GString to be parsed
1605 * @property_value: a #GValue which must hold enum values.
1607 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1608 * or gtk_widget_class_install_style_property_parser() which parses a single
1609 * enumeration value.
1611 * The enumeration value can be specified by its name, its nickname or
1612 * its numeric value. For consistency with flags parsing, the value
1613 * may be surrounded by parentheses.
1615 * Return value: %TRUE if @gstring could be parsed and @property_value
1616 * has been set to the resulting #GEnumValue.
1619 gtk_rc_property_parse_enum (const GParamSpec *pspec,
1620 const GString *gstring,
1621 GValue *property_value)
1623 gboolean need_closing_brace = FALSE, success = FALSE;
1625 GEnumValue *enum_value = NULL;
1627 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1628 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
1630 scanner = gtk_rc_scanner_new ();
1631 g_scanner_input_text (scanner, gstring->str, gstring->len);
1633 /* we just want to parse _one_ value, but for consistency with flags parsing
1634 * we support optional parenthesis
1636 g_scanner_get_next_token (scanner);
1637 if (scanner->token == '(')
1639 need_closing_brace = TRUE;
1640 g_scanner_get_next_token (scanner);
1642 if (scanner->token == G_TOKEN_IDENTIFIER)
1644 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
1646 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
1648 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
1651 g_value_set_enum (property_value, enum_value->value);
1655 else if (scanner->token == G_TOKEN_INT)
1657 g_value_set_enum (property_value, scanner->value.v_int);
1660 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
1662 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
1665 g_scanner_destroy (scanner);
1671 parse_flags_value (GScanner *scanner,
1675 g_scanner_get_next_token (scanner);
1676 if (scanner->token == G_TOKEN_IDENTIFIER)
1678 GFlagsValue *flags_value;
1680 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
1682 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
1685 *number |= flags_value->value;
1686 return G_TOKEN_NONE;
1689 else if (scanner->token == G_TOKEN_INT)
1691 *number |= scanner->value.v_int;
1692 return G_TOKEN_NONE;
1694 return G_TOKEN_IDENTIFIER;
1698 * gtk_rc_property_parse_flags:
1699 * @pspec: a #GParamSpec
1700 * @gstring: the #GString to be parsed
1701 * @property_value: a #GValue which must hold flags values.
1703 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1704 * or gtk_widget_class_install_style_property_parser() which parses flags.
1706 * Flags can be specified by their name, their nickname or
1707 * numerically. Multiple flags can be specified in the form
1708 * <literal>"( flag1 | flag2 | ... )"</literal>.
1710 * Return value: %TRUE if @gstring could be parsed and @property_value
1711 * has been set to the resulting flags value.
1714 gtk_rc_property_parse_flags (const GParamSpec *pspec,
1715 const GString *gstring,
1716 GValue *property_value)
1719 gboolean success = FALSE;
1722 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1723 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
1725 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
1726 scanner = gtk_rc_scanner_new ();
1727 g_scanner_input_text (scanner, gstring->str, gstring->len);
1729 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
1730 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
1731 scanner->next_token == G_TOKEN_INT)
1733 guint token, flags_value = 0;
1735 token = parse_flags_value (scanner, class, &flags_value);
1737 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1740 g_value_set_flags (property_value, flags_value);
1744 else if (g_scanner_get_next_token (scanner) == '(')
1746 guint token, flags_value = 0;
1748 /* parse first value */
1749 token = parse_flags_value (scanner, class, &flags_value);
1751 /* parse nth values, preceeded by '|' */
1752 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
1753 token = parse_flags_value (scanner, class, &flags_value);
1755 /* done, last token must have closed expression */
1756 if (token == G_TOKEN_NONE && scanner->token == ')' &&
1757 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
1759 g_value_set_flags (property_value, flags_value);
1763 g_scanner_destroy (scanner);
1769 get_braced_int (GScanner *scanner,
1776 g_scanner_get_next_token (scanner);
1777 if (scanner->token != '{')
1781 g_scanner_get_next_token (scanner);
1782 if (scanner->token != G_TOKEN_INT)
1785 *value = scanner->value.v_int;
1789 g_scanner_get_next_token (scanner);
1790 if (scanner->token != '}')
1795 g_scanner_get_next_token (scanner);
1796 if (scanner->token != ',')
1804 * gtk_rc_property_parse_requisition:
1805 * @pspec: a #GParamSpec
1806 * @gstring: the #GString to be parsed
1807 * @property_value: a #GValue which must hold boxed values.
1809 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1810 * or gtk_widget_class_install_style_property_parser() which parses a
1811 * requisition in the form
1812 * <literal>"{ width, height }"</literal> for integers %width and %height.
1814 * Return value: %TRUE if @gstring could be parsed and @property_value
1815 * has been set to the resulting #GtkRequisition.
1818 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
1819 const GString *gstring,
1820 GValue *property_value)
1822 GtkRequisition requisition;
1824 gboolean success = FALSE;
1826 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1827 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1829 scanner = gtk_rc_scanner_new ();
1830 g_scanner_input_text (scanner, gstring->str, gstring->len);
1832 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
1833 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
1835 g_value_set_boxed (property_value, &requisition);
1839 g_scanner_destroy (scanner);
1845 * gtk_rc_property_parse_border:
1846 * @pspec: a #GParamSpec
1847 * @gstring: the #GString to be parsed
1848 * @property_value: a #GValue which must hold boxed values.
1850 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
1851 * or gtk_widget_class_install_style_property_parser() which parses
1852 * borders in the form
1853 * <literal>"{ left, right, top, bottom }"</literal> for integers
1854 * %left, %right, %top and %bottom.
1856 * Return value: %TRUE if @gstring could be parsed and @property_value
1857 * has been set to the resulting #GtkBorder.
1860 gtk_rc_property_parse_border (const GParamSpec *pspec,
1861 const GString *gstring,
1862 GValue *property_value)
1866 gboolean success = FALSE;
1868 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
1869 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
1871 scanner = gtk_rc_scanner_new ();
1872 g_scanner_input_text (scanner, gstring->str, gstring->len);
1874 if (get_braced_int (scanner, TRUE, FALSE, &border.left) &&
1875 get_braced_int (scanner, FALSE, FALSE, &border.right) &&
1876 get_braced_int (scanner, FALSE, FALSE, &border.top) &&
1877 get_braced_int (scanner, FALSE, TRUE, &border.bottom))
1879 g_value_set_boxed (property_value, &border);
1883 g_scanner_destroy (scanner);
1889 _gtk_settings_handle_event (GdkEventSetting *event)
1891 GtkSettings *settings;
1895 settings = gtk_settings_get_for_screen (gdk_drawable_get_screen (event->window));
1896 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
1900 property_id = pspec->param_id;
1902 if (property_id == PROP_COLOR_SCHEME)
1904 GValue value = { 0, };
1906 g_value_init (&value, G_TYPE_STRING);
1907 if (!gdk_screen_get_setting (settings->screen, pspec->name, &value))
1908 g_value_set_static_string (&value, "");
1909 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
1910 g_value_unset (&value);
1912 g_object_notify (G_OBJECT (settings), pspec->name);
1917 reset_rc_values_foreach (GQuark key_id,
1921 GtkSettingsValuePrivate *qvalue = data;
1922 GSList **to_reset = user_data;
1924 if (qvalue->source == GTK_SETTINGS_SOURCE_RC_FILE)
1925 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
1929 _gtk_settings_reset_rc_values (GtkSettings *settings)
1931 GSList *to_reset = NULL;
1933 GParamSpec **pspecs, **p;
1936 /* Remove any queued settings
1938 g_datalist_foreach (&settings->queued_settings,
1939 reset_rc_values_foreach,
1942 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
1944 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
1945 g_datalist_id_remove_data (&settings->queued_settings, key_id);
1948 g_slist_free (to_reset);
1950 /* Now reset the active settings
1952 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
1955 g_object_freeze_notify (G_OBJECT (settings));
1956 for (p = pspecs; *p; p++)
1958 if (settings->property_values[i].source == GTK_SETTINGS_SOURCE_RC_FILE)
1960 GParamSpec *pspec = *p;
1962 g_param_value_set_default (pspec, &settings->property_values[i].value);
1963 g_object_notify (G_OBJECT (settings), pspec->name);
1967 g_object_thaw_notify (G_OBJECT (settings));
1972 settings_update_double_click (GtkSettings *settings)
1974 if (gdk_screen_get_number (settings->screen) == 0)
1976 GdkDisplay *display = gdk_screen_get_display (settings->screen);
1977 gint double_click_time;
1978 gint double_click_distance;
1980 g_object_get (settings,
1981 "gtk-double-click-time", &double_click_time,
1982 "gtk-double-click-distance", &double_click_distance,
1985 gdk_display_set_double_click_time (display, double_click_time);
1986 gdk_display_set_double_click_distance (display, double_click_distance);
1991 settings_update_modules (GtkSettings *settings)
1995 g_object_get (settings,
1996 "gtk-modules", &modules,
1999 _gtk_modules_settings_changed (settings, modules);
2004 #ifdef GDK_WINDOWING_X11
2006 settings_update_cursor_theme (GtkSettings *settings)
2008 GdkDisplay *display = gdk_screen_get_display (settings->screen);
2009 gchar *theme = NULL;
2012 g_object_get (settings,
2013 "gtk-cursor-theme-name", &theme,
2014 "gtk-cursor-theme-size", &size,
2017 gdk_x11_display_set_cursor_theme (display, theme, size);
2023 settings_update_font_options (GtkSettings *settings)
2026 gchar *hint_style_str;
2027 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2029 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2031 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2032 cairo_font_options_t *options;
2034 g_object_get (settings,
2035 "gtk-xft-antialias", &antialias,
2036 "gtk-xft-hinting", &hinting,
2037 "gtk-xft-hintstyle", &hint_style_str,
2038 "gtk-xft-rgba", &rgba_str,
2041 options = cairo_font_options_create ();
2043 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2045 if (hinting >= 0 && !hinting)
2047 hint_style = CAIRO_HINT_STYLE_NONE;
2049 else if (hint_style_str)
2051 if (strcmp (hint_style_str, "hintnone") == 0)
2052 hint_style = CAIRO_HINT_STYLE_NONE;
2053 else if (strcmp (hint_style_str, "hintslight") == 0)
2054 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2055 else if (strcmp (hint_style_str, "hintmedium") == 0)
2056 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2057 else if (strcmp (hint_style_str, "hintfull") == 0)
2058 hint_style = CAIRO_HINT_STYLE_FULL;
2061 g_free (hint_style_str);
2063 cairo_font_options_set_hint_style (options, hint_style);
2067 if (strcmp (rgba_str, "rgb") == 0)
2068 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2069 else if (strcmp (rgba_str, "bgr") == 0)
2070 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2071 else if (strcmp (rgba_str, "vrgb") == 0)
2072 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2073 else if (strcmp (rgba_str, "vbgr") == 0)
2074 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2079 cairo_font_options_set_subpixel_order (options, subpixel_order);
2081 if (antialias >= 0 && !antialias)
2082 antialias_mode = CAIRO_ANTIALIAS_NONE;
2083 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2084 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2085 else if (antialias >= 0)
2086 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2088 cairo_font_options_set_antialias (options, antialias_mode);
2090 gdk_screen_set_font_options (settings->screen, options);
2092 cairo_font_options_destroy (options);
2095 #ifdef GDK_WINDOWING_X11
2097 settings_update_fontconfig (GtkSettings *settings)
2099 static guint last_update_timestamp;
2100 static gboolean last_update_needed;
2104 g_object_get (settings,
2105 "gtk-fontconfig-timestamp", ×tamp,
2108 /* if timestamp is the same as last_update_timestamp, we already have
2109 * updated fontconig on this timestamp (another screen requested it perhaps?),
2110 * just return the cached result.*/
2112 if (timestamp != last_update_timestamp)
2114 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2115 gboolean update_needed = FALSE;
2118 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2120 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2121 if (FcInitReinitialize ())
2122 update_needed = TRUE;
2125 last_update_timestamp = timestamp;
2126 last_update_needed = update_needed;
2129 return last_update_needed;
2131 #endif /* GDK_WINDOWING_X11 */
2134 settings_update_resolution (GtkSettings *settings)
2139 g_object_get (settings,
2140 "gtk-xft-dpi", &dpi_int,
2144 dpi = dpi_int / 1024.;
2148 gdk_screen_set_resolution (settings->screen, dpi);
2153 GHashTable *color_hash;
2154 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2155 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2159 color_scheme_data_free (ColorSchemeData *data)
2163 g_hash_table_unref (data->color_hash);
2165 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2167 if (data->tables[i])
2168 g_hash_table_unref (data->tables[i]);
2169 g_free (data->lastentry[i]);
2172 g_slice_free (ColorSchemeData, data);
2176 settings_update_color_scheme (GtkSettings *settings)
2178 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2180 ColorSchemeData *data;
2181 GValue value = { 0, };
2183 data = g_slice_new0 (ColorSchemeData);
2184 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2185 (GDestroyNotify) gdk_color_free);
2186 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2187 data, (GDestroyNotify) color_scheme_data_free);
2189 g_value_init (&value, G_TYPE_STRING);
2190 if (gdk_screen_get_setting (settings->screen, "gtk-color-scheme", &value))
2192 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2193 g_value_unset (&value);
2199 add_color_to_hash (gchar *name,
2205 old = g_hash_table_lookup (target, name);
2206 if (!old || !gdk_color_equal (old, color))
2208 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2217 add_colors_to_hash_from_string (GHashTable *hash,
2218 const gchar *colors)
2220 gchar *s, *p, *name;
2222 gboolean changed = FALSE;
2225 copy = g_strdup (colors);
2230 p = strchr (s, ':');
2245 if (*s == '\n' || *s == ';')
2254 if (gdk_color_parse (p, &color))
2255 changed |= add_color_to_hash (name, &color, hash);
2264 update_color_hash (ColorSchemeData *data,
2266 GtkSettingsSource source)
2268 gboolean changed = FALSE;
2270 GHashTable *old_hash;
2271 GHashTableIter iter;
2275 if ((str == NULL || *str == '\0') &&
2276 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2279 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2282 /* For the RC_FILE source we merge the values rather than over-writing
2283 * them, since multiple rc files might define independent sets of colors
2285 if ((source != GTK_SETTINGS_SOURCE_RC_FILE) &&
2286 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2288 g_hash_table_unref (data->tables[source]);
2289 data->tables[source] = NULL;
2290 changed = TRUE; /* We can't rely on the code below since str might be "" */
2293 if (data->tables[source] == NULL)
2294 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2296 (GDestroyNotify) gdk_color_free);
2298 g_free (data->lastentry[source]);
2299 data->lastentry[source] = g_strdup (str);
2301 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2306 /* Rebuild the merged hash table. */
2307 if (data->color_hash)
2309 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2310 (GDestroyNotify) gdk_color_free);
2312 g_hash_table_iter_init (&iter, data->color_hash);
2313 while (g_hash_table_iter_next (&iter, &name, &color))
2315 g_hash_table_insert (old_hash, name, color);
2316 g_hash_table_iter_steal (&iter);
2324 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2326 if (data->tables[i])
2327 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2333 /* now check if the merged hash has changed */
2335 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2339 GHashTableIter iter;
2340 gpointer key, value, new_value;
2342 g_hash_table_iter_init (&iter, old_hash);
2343 while (g_hash_table_iter_next (&iter, &key, &value))
2345 new_value = g_hash_table_lookup (data->color_hash, key);
2346 if (!new_value || !gdk_color_equal (value, new_value))
2354 g_hash_table_unref (old_hash);
2363 merge_color_scheme (GtkSettings *settings,
2364 const GValue *value,
2365 GtkSettingsSource source)
2367 ColorSchemeData *data;
2368 const gchar *colors;
2370 g_object_freeze_notify (G_OBJECT (settings));
2372 colors = g_value_get_string (value);
2374 settings_update_color_scheme (settings);
2376 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2377 "gtk-color-scheme");
2379 if (update_color_hash (data, colors, source))
2380 g_object_notify (G_OBJECT (settings), "color-hash");
2382 g_object_thaw_notify (G_OBJECT (settings));
2386 get_color_hash (GtkSettings *settings)
2388 ColorSchemeData *data;
2390 settings_update_color_scheme (settings);
2392 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
2393 "gtk-color-scheme");
2395 return data->color_hash;
2399 append_color_scheme (gpointer key,
2403 gchar *name = (gchar *)key;
2404 GdkColor *color = (GdkColor *)value;
2405 GString *string = (GString *)data;
2407 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
2408 name, color->red, color->green, color->blue);
2412 get_color_scheme (GtkSettings *settings)
2414 ColorSchemeData *data;
2417 settings_update_color_scheme (settings);
2419 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2420 "gtk-color-scheme");
2422 string = g_string_new ("");
2424 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
2426 return g_string_free (string, FALSE);
2430 #define __GTK_SETTINGS_C__
2431 #include "gtkaliasdef.c"