1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #define PANGO_ENABLE_BACKEND /* for pango_fc_font_map_cache_clear() */
26 #include "gtkmodules.h"
27 #include "gtkmodulesprivate.h"
28 #include "gtksettingsprivate.h"
30 #include "gtkwidget.h"
31 #include "gtkprivate.h"
32 #include "gtkcssproviderprivate.h"
33 #include "gtksymboliccolor.h"
34 #include "gtktypebuiltins.h"
35 #include "gtkversion.h"
37 #ifdef GDK_WINDOWING_X11
39 #include <pango/pangofc-fontmap.h>
42 #ifdef GDK_WINDOWING_QUARTZ
43 #include "quartz/gdkquartz.h"
49 * @Short_description: Sharing settings between applications
52 * GtkSettings provide a mechanism to share global settings between
55 * On the X window system, this sharing is realized by an
56 * <ulink url="http://www.freedesktop.org/wiki/Specifications/xsettings-spec">XSettings</ulink>
57 * manager that is usually part of the desktop environment, along with
58 * utilities that let the user change these settings. In the absence of
59 * an Xsettings manager, GTK+ reads default values for settings from
60 * <filename>settings.ini</filename> files in
61 * <filename>/etc/gtk-3.0</filename> and <filename>$XDG_CONFIG_HOME/gtk-3.0</filename>. These files must be valid key files (see #GKeyFile), and have
62 * a section called Settings. Themes can also provide default values
63 * for settings by installing a <filename>settings.ini</filename> file
64 * next to their <filename>gtk.css</filename> file.
66 * Applications can override system-wide settings with
67 * gtk_settings_set_string_property(), gtk_settings_set_long_property(),
68 * etc. This should be restricted to special cases though; GtkSettings are
69 * not meant as an application configuration facility. When doing so, you
70 * need to be aware that settings that are specific to individual widgets
71 * may not be available before the widget type has been realized at least
72 * once. The following example demonstrates a way to do this:
73 * <informalexample><programlisting>
74 * gtk_init (&argc, &argv);
76 * /* make sure the type is realized */
77 * g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));
79 * g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);
80 * </programlisting></informalexample>
82 * There is one GtkSettings instance per screen. It can be obtained with
83 * gtk_settings_get_for_screen(), but in many cases, it is more convenient
84 * to use gtk_widget_get_settings(). gtk_settings_get_default() returns the
85 * GtkSettings instance for the default screen.
89 #define DEFAULT_TIMEOUT_INITIAL 200
90 #define DEFAULT_TIMEOUT_REPEAT 20
91 #define DEFAULT_TIMEOUT_EXPAND 500
93 typedef struct _GtkSettingsPropertyValue GtkSettingsPropertyValue;
94 typedef struct _GtkSettingsValuePrivate GtkSettingsValuePrivate;
96 struct _GtkSettingsPrivate
98 GData *queued_settings; /* of type GtkSettingsValue* */
99 GtkSettingsPropertyValue *property_values;
101 GtkCssProvider *theme_provider;
102 GtkCssProvider *key_theme_provider;
107 GTK_SETTINGS_SOURCE_DEFAULT,
108 GTK_SETTINGS_SOURCE_THEME,
109 GTK_SETTINGS_SOURCE_XSETTING,
110 GTK_SETTINGS_SOURCE_APPLICATION
113 struct _GtkSettingsValuePrivate
115 GtkSettingsValue public;
116 GtkSettingsSource source;
119 struct _GtkSettingsPropertyValue
122 GtkSettingsSource source;
127 PROP_DOUBLE_CLICK_TIME,
128 PROP_DOUBLE_CLICK_DISTANCE,
130 PROP_CURSOR_BLINK_TIME,
131 PROP_CURSOR_BLINK_TIMEOUT,
134 PROP_ICON_THEME_NAME,
135 PROP_FALLBACK_ICON_THEME,
138 PROP_DND_DRAG_THRESHOLD,
147 PROP_CURSOR_THEME_NAME,
148 PROP_CURSOR_THEME_SIZE,
149 PROP_ALTERNATIVE_BUTTON_ORDER,
150 PROP_ALTERNATIVE_SORT_ARROWS,
151 PROP_SHOW_INPUT_METHOD_MENU,
152 PROP_SHOW_UNICODE_MENU,
153 PROP_TIMEOUT_INITIAL,
157 PROP_ENABLE_ANIMATIONS,
158 PROP_TOUCHSCREEN_MODE,
159 PROP_TOOLTIP_TIMEOUT,
160 PROP_TOOLTIP_BROWSE_TIMEOUT,
161 PROP_TOOLTIP_BROWSE_MODE_TIMEOUT,
162 PROP_KEYNAV_CURSOR_ONLY,
163 PROP_KEYNAV_WRAP_AROUND,
166 PROP_FILE_CHOOSER_BACKEND,
168 PROP_PRINT_PREVIEW_COMMAND,
169 PROP_ENABLE_MNEMONICS,
171 PROP_RECENT_FILES_LIMIT,
173 PROP_RECENT_FILES_MAX_AGE,
174 PROP_FONTCONFIG_TIMESTAMP,
175 PROP_SOUND_THEME_NAME,
176 PROP_ENABLE_INPUT_FEEDBACK_SOUNDS,
177 PROP_ENABLE_EVENT_SOUNDS,
178 PROP_ENABLE_TOOLTIPS,
180 PROP_TOOLBAR_ICON_SIZE,
183 PROP_APPLICATION_PREFER_DARK_THEME,
185 PROP_ENTRY_SELECT_ON_FOCUS,
186 PROP_ENTRY_PASSWORD_HINT_TIMEOUT,
188 PROP_MENU_BAR_POPUP_DELAY,
189 PROP_SCROLLED_WINDOW_PLACEMENT,
190 PROP_CAN_CHANGE_ACCELS,
191 PROP_MENU_POPUP_DELAY,
192 PROP_MENU_POPDOWN_DELAY,
193 PROP_LABEL_SELECT_ON_FOCUS,
195 PROP_IM_PREEDIT_STYLE,
199 /* --- prototypes --- */
200 static void gtk_settings_provider_iface_init (GtkStyleProviderIface *iface);
202 static void gtk_settings_finalize (GObject *object);
203 static void gtk_settings_get_property (GObject *object,
207 static void gtk_settings_set_property (GObject *object,
211 static void gtk_settings_notify (GObject *object,
213 static guint settings_install_property_parser (GtkSettingsClass *class,
215 GtkRcPropertyParser parser);
216 static void settings_update_double_click (GtkSettings *settings);
217 static void settings_update_modules (GtkSettings *settings);
219 static void settings_update_cursor_theme (GtkSettings *settings);
220 static void settings_update_resolution (GtkSettings *settings);
221 static void settings_update_font_options (GtkSettings *settings);
222 static gboolean settings_update_fontconfig (GtkSettings *settings);
223 static void settings_update_color_scheme (GtkSettings *settings);
224 static void settings_update_theme (GtkSettings *settings);
225 static void settings_update_key_theme (GtkSettings *settings);
227 static void merge_color_scheme (GtkSettings *settings,
229 GtkSettingsSource source);
230 static gchar *get_color_scheme (GtkSettings *settings);
231 static GHashTable *get_color_hash (GtkSettings *settings);
232 static void gtk_settings_load_from_key_file (GtkSettings *settings,
234 GtkSettingsSource source);
236 /* the default palette for GtkColorSelelection */
237 static const gchar default_color_palette[] =
238 "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:"
239 "lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90";
241 /* --- variables --- */
242 static GQuark quark_property_parser = 0;
243 static GSList *object_list = NULL;
244 static guint class_n_properties = 0;
247 G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
248 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
249 gtk_settings_provider_iface_init));
251 /* --- functions --- */
253 gtk_settings_init (GtkSettings *settings)
255 GtkSettingsPrivate *priv;
256 GParamSpec **pspecs, **p;
260 priv = G_TYPE_INSTANCE_GET_PRIVATE (settings,
264 settings->priv = priv;
265 g_datalist_init (&priv->queued_settings);
266 object_list = g_slist_prepend (object_list, settings);
268 /* build up property array for all yet existing properties and queue
269 * notification for them (at least notification for internal properties
270 * will instantly be caught)
272 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
273 for (p = pspecs; *p; p++)
274 if ((*p)->owner_type == G_OBJECT_TYPE (settings))
276 priv->property_values = g_new0 (GtkSettingsPropertyValue, i);
278 g_object_freeze_notify (G_OBJECT (settings));
280 for (p = pspecs; *p; p++)
282 GParamSpec *pspec = *p;
283 GType value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
285 if (pspec->owner_type != G_OBJECT_TYPE (settings))
287 g_value_init (&priv->property_values[i].value, value_type);
288 g_param_value_set_default (pspec, &priv->property_values[i].value);
290 g_object_notify (G_OBJECT (settings), pspec->name);
291 priv->property_values[i].source = GTK_SETTINGS_SOURCE_DEFAULT;
296 path = g_build_filename (_gtk_get_sysconfdir (), "gtk-3.0", "settings.ini", NULL);
297 if (g_file_test (path, G_FILE_TEST_EXISTS))
298 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
301 path = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "settings.ini", NULL);
302 if (g_file_test (path, G_FILE_TEST_EXISTS))
303 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
306 g_object_thaw_notify (G_OBJECT (settings));
310 gtk_settings_class_init (GtkSettingsClass *class)
312 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
315 gobject_class->finalize = gtk_settings_finalize;
316 gobject_class->get_property = gtk_settings_get_property;
317 gobject_class->set_property = gtk_settings_set_property;
318 gobject_class->notify = gtk_settings_notify;
320 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
321 result = settings_install_property_parser (class,
322 g_param_spec_int ("gtk-double-click-time",
323 P_("Double Click Time"),
324 P_("Maximum time allowed between two clicks for them to be considered a double click (in milliseconds)"),
326 GTK_PARAM_READWRITE),
328 g_assert (result == PROP_DOUBLE_CLICK_TIME);
329 result = settings_install_property_parser (class,
330 g_param_spec_int ("gtk-double-click-distance",
331 P_("Double Click Distance"),
332 P_("Maximum distance allowed between two clicks for them to be considered a double click (in pixels)"),
334 GTK_PARAM_READWRITE),
336 g_assert (result == PROP_DOUBLE_CLICK_DISTANCE);
339 * GtkSettings:gtk-cursor-blink:
341 * Whether the cursor should blink.
343 * Also see the #GtkSettings:gtk-cursor-blink-timeout setting,
344 * which allows more flexible control over cursor blinking.
346 result = settings_install_property_parser (class,
347 g_param_spec_boolean ("gtk-cursor-blink",
349 P_("Whether the cursor should blink"),
351 GTK_PARAM_READWRITE),
353 g_assert (result == PROP_CURSOR_BLINK);
354 result = settings_install_property_parser (class,
355 g_param_spec_int ("gtk-cursor-blink-time",
356 P_("Cursor Blink Time"),
357 P_("Length of the cursor blink cycle, in milliseconds"),
359 GTK_PARAM_READWRITE),
361 g_assert (result == PROP_CURSOR_BLINK_TIME);
364 * GtkSettings:gtk-cursor-blink-timeout:
366 * Time after which the cursor stops blinking, in seconds.
367 * The timer is reset after each user interaction.
369 * Setting this to zero has the same effect as setting
370 * #GtkSettings:gtk-cursor-blink to %FALSE.
374 result = settings_install_property_parser (class,
375 g_param_spec_int ("gtk-cursor-blink-timeout",
376 P_("Cursor Blink Timeout"),
377 P_("Time after which the cursor stops blinking, in seconds"),
378 1, G_MAXINT, G_MAXINT,
379 GTK_PARAM_READWRITE),
381 g_assert (result == PROP_CURSOR_BLINK_TIMEOUT);
382 result = settings_install_property_parser (class,
383 g_param_spec_boolean ("gtk-split-cursor",
385 P_("Whether two cursors should be displayed for mixed left-to-right and right-to-left text"),
387 GTK_PARAM_READWRITE),
389 g_assert (result == PROP_SPLIT_CURSOR);
390 result = settings_install_property_parser (class,
391 g_param_spec_string ("gtk-theme-name",
393 P_("Name of theme to load"),
395 GTK_PARAM_READWRITE),
397 g_assert (result == PROP_THEME_NAME);
399 result = settings_install_property_parser (class,
400 g_param_spec_string ("gtk-icon-theme-name",
401 P_("Icon Theme Name"),
402 P_("Name of icon theme to use"),
404 GTK_PARAM_READWRITE),
406 g_assert (result == PROP_ICON_THEME_NAME);
408 result = settings_install_property_parser (class,
409 g_param_spec_string ("gtk-fallback-icon-theme",
410 P_("Fallback Icon Theme Name"),
411 P_("Name of a icon theme to fall back to"),
413 GTK_PARAM_READWRITE),
415 g_assert (result == PROP_FALLBACK_ICON_THEME);
417 result = settings_install_property_parser (class,
418 g_param_spec_string ("gtk-key-theme-name",
419 P_("Key Theme Name"),
420 P_("Name of key theme to load"),
422 GTK_PARAM_READWRITE),
424 g_assert (result == PROP_KEY_THEME_NAME);
426 result = settings_install_property_parser (class,
427 g_param_spec_string ("gtk-menu-bar-accel",
428 P_("Menu bar accelerator"),
429 P_("Keybinding to activate the menu bar"),
431 GTK_PARAM_READWRITE),
433 g_assert (result == PROP_MENU_BAR_ACCEL);
435 result = settings_install_property_parser (class,
436 g_param_spec_int ("gtk-dnd-drag-threshold",
437 P_("Drag threshold"),
438 P_("Number of pixels the cursor can move before dragging"),
440 GTK_PARAM_READWRITE),
442 g_assert (result == PROP_DND_DRAG_THRESHOLD);
444 result = settings_install_property_parser (class,
445 g_param_spec_string ("gtk-font-name",
447 P_("Name of default font to use"),
449 GTK_PARAM_READWRITE),
451 g_assert (result == PROP_FONT_NAME);
454 * GtkSettings:gtk-icon-sizes:
456 * A list of icon sizes. The list is separated by colons, and
459 * <replaceable>size-name</replaceable> = <replaceable>width</replaceable> , <replaceable>height</replaceable>
461 * E.g. "gtk-menu=16,16:gtk-button=20,20:gtk-dialog=48,48".
462 * GTK+ itself use the following named icon sizes: gtk-menu,
463 * gtk-button, gtk-small-toolbar, gtk-large-toolbar, gtk-dnd,
464 * gtk-dialog. Applications can register their own named icon
465 * sizes with gtk_icon_size_register().
467 result = settings_install_property_parser (class,
468 g_param_spec_string ("gtk-icon-sizes",
470 P_("List of icon sizes (gtk-menu=16,16:gtk-button=20,20..."),
472 GTK_PARAM_READWRITE),
474 g_assert (result == PROP_ICON_SIZES);
476 result = settings_install_property_parser (class,
477 g_param_spec_string ("gtk-modules",
479 P_("List of currently active GTK modules"),
481 GTK_PARAM_READWRITE),
483 g_assert (result == PROP_MODULES);
485 result = settings_install_property_parser (class,
486 g_param_spec_int ("gtk-xft-antialias",
488 P_("Whether to antialias Xft fonts; 0=no, 1=yes, -1=default"),
490 GTK_PARAM_READWRITE),
493 g_assert (result == PROP_XFT_ANTIALIAS);
495 result = settings_install_property_parser (class,
496 g_param_spec_int ("gtk-xft-hinting",
498 P_("Whether to hint Xft fonts; 0=no, 1=yes, -1=default"),
500 GTK_PARAM_READWRITE),
503 g_assert (result == PROP_XFT_HINTING);
505 result = settings_install_property_parser (class,
506 g_param_spec_string ("gtk-xft-hintstyle",
507 P_("Xft Hint Style"),
508 P_("What degree of hinting to use; hintnone, hintslight, hintmedium, or hintfull"),
510 GTK_PARAM_READWRITE),
513 g_assert (result == PROP_XFT_HINTSTYLE);
515 result = settings_install_property_parser (class,
516 g_param_spec_string ("gtk-xft-rgba",
518 P_("Type of subpixel antialiasing; none, rgb, bgr, vrgb, vbgr"),
520 GTK_PARAM_READWRITE),
523 g_assert (result == PROP_XFT_RGBA);
525 result = settings_install_property_parser (class,
526 g_param_spec_int ("gtk-xft-dpi",
528 P_("Resolution for Xft, in 1024 * dots/inch. -1 to use default value"),
530 GTK_PARAM_READWRITE),
533 g_assert (result == PROP_XFT_DPI);
535 result = settings_install_property_parser (class,
536 g_param_spec_string ("gtk-cursor-theme-name",
537 P_("Cursor theme name"),
538 P_("Name of the cursor theme to use, or NULL to use the default theme"),
540 GTK_PARAM_READWRITE),
542 g_assert (result == PROP_CURSOR_THEME_NAME);
544 result = settings_install_property_parser (class,
545 g_param_spec_int ("gtk-cursor-theme-size",
546 P_("Cursor theme size"),
547 P_("Size to use for cursors, or 0 to use the default size"),
549 GTK_PARAM_READWRITE),
552 g_assert (result == PROP_CURSOR_THEME_SIZE);
554 result = settings_install_property_parser (class,
555 g_param_spec_boolean ("gtk-alternative-button-order",
556 P_("Alternative button order"),
557 P_("Whether buttons in dialogs should use the alternative button order"),
559 GTK_PARAM_READWRITE),
561 g_assert (result == PROP_ALTERNATIVE_BUTTON_ORDER);
564 * GtkSettings:gtk-alternative-sort-arrows:
566 * Controls the direction of the sort indicators in sorted list and tree
567 * views. By default an arrow pointing down means the column is sorted
568 * in ascending order. When set to %TRUE, this order will be inverted.
572 result = settings_install_property_parser (class,
573 g_param_spec_boolean ("gtk-alternative-sort-arrows",
574 P_("Alternative sort indicator direction"),
575 P_("Whether the direction of the sort indicators in list and tree views is inverted compared to the default (where down means ascending)"),
577 GTK_PARAM_READWRITE),
579 g_assert (result == PROP_ALTERNATIVE_SORT_ARROWS);
581 result = settings_install_property_parser (class,
582 g_param_spec_boolean ("gtk-show-input-method-menu",
583 P_("Show the 'Input Methods' menu"),
584 P_("Whether the context menus of entries and text views should offer to change the input method"),
586 GTK_PARAM_READWRITE),
588 g_assert (result == PROP_SHOW_INPUT_METHOD_MENU);
590 result = settings_install_property_parser (class,
591 g_param_spec_boolean ("gtk-show-unicode-menu",
592 P_("Show the 'Insert Unicode Control Character' menu"),
593 P_("Whether the context menus of entries and text views should offer to insert control characters"),
595 GTK_PARAM_READWRITE),
597 g_assert (result == PROP_SHOW_UNICODE_MENU);
599 result = settings_install_property_parser (class,
600 g_param_spec_int ("gtk-timeout-initial",
602 P_("Starting value for timeouts, when button is pressed"),
603 0, G_MAXINT, DEFAULT_TIMEOUT_INITIAL,
604 GTK_PARAM_READWRITE),
607 g_assert (result == PROP_TIMEOUT_INITIAL);
609 result = settings_install_property_parser (class,
610 g_param_spec_int ("gtk-timeout-repeat",
611 P_("Repeat timeout"),
612 P_("Repeat value for timeouts, when button is pressed"),
613 0, G_MAXINT, DEFAULT_TIMEOUT_REPEAT,
614 GTK_PARAM_READWRITE),
617 g_assert (result == PROP_TIMEOUT_REPEAT);
619 result = settings_install_property_parser (class,
620 g_param_spec_int ("gtk-timeout-expand",
621 P_("Expand timeout"),
622 P_("Expand value for timeouts, when a widget is expanding a new region"),
623 0, G_MAXINT, DEFAULT_TIMEOUT_EXPAND,
624 GTK_PARAM_READWRITE),
627 g_assert (result == PROP_TIMEOUT_EXPAND);
630 * GtkSettings:gtk-color-scheme:
632 * A palette of named colors for use in themes. The format of the string is
638 * Color names must be acceptable as identifiers in the
639 * <link linkend="gtk-Resource-Files">gtkrc</link> syntax, and
640 * color specifications must be in the format accepted by
643 * Note that due to the way the color tables from different sources are
644 * merged, color specifications will be converted to hexadecimal form
645 * when getting this property.
647 * Starting with GTK+ 2.12, the entries can alternatively be separated
648 * by ';' instead of newlines:
650 * name1: color1; name2: color2; ...
655 result = settings_install_property_parser (class,
656 g_param_spec_string ("gtk-color-scheme",
658 P_("A palette of named colors for use in themes"),
660 GTK_PARAM_READWRITE),
663 g_assert (result == PROP_COLOR_SCHEME);
665 result = settings_install_property_parser (class,
666 g_param_spec_boolean ("gtk-enable-animations",
667 P_("Enable Animations"),
668 P_("Whether to enable toolkit-wide animations."),
670 GTK_PARAM_READWRITE),
673 g_assert (result == PROP_ENABLE_ANIMATIONS);
676 * GtkSettings:gtk-touchscreen-mode:
678 * When %TRUE, there are no motion notify events delivered on this screen,
679 * and widgets can't use the pointer hovering them for any essential
684 result = settings_install_property_parser (class,
685 g_param_spec_boolean ("gtk-touchscreen-mode",
686 P_("Enable Touchscreen Mode"),
687 P_("When TRUE, there are no motion notify events delivered on this screen"),
689 GTK_PARAM_READWRITE),
692 g_assert (result == PROP_TOUCHSCREEN_MODE);
695 * GtkSettings:gtk-tooltip-timeout:
697 * Time, in milliseconds, after which a tooltip could appear if the
698 * cursor is hovering on top of a widget.
702 result = settings_install_property_parser (class,
703 g_param_spec_int ("gtk-tooltip-timeout",
704 P_("Tooltip timeout"),
705 P_("Timeout before tooltip is shown"),
708 GTK_PARAM_READWRITE),
711 g_assert (result == PROP_TOOLTIP_TIMEOUT);
714 * GtkSettings:gtk-tooltip-browse-timeout:
716 * Controls the time after which tooltips will appear when
717 * browse mode is enabled, in milliseconds.
719 * Browse mode is enabled when the mouse pointer moves off an object
720 * where a tooltip was currently being displayed. If the mouse pointer
721 * hits another object before the browse mode timeout expires (see
722 * #GtkSettings:gtk-tooltip-browse-mode-timeout), it will take the
723 * amount of milliseconds specified by this setting to popup the tooltip
724 * for the new object.
728 result = settings_install_property_parser (class,
729 g_param_spec_int ("gtk-tooltip-browse-timeout",
730 P_("Tooltip browse timeout"),
731 P_("Timeout before tooltip is shown when browse mode is enabled"),
734 GTK_PARAM_READWRITE),
737 g_assert (result == PROP_TOOLTIP_BROWSE_TIMEOUT);
740 * GtkSettings:gtk-tooltip-browse-mode-timeout:
742 * Amount of time, in milliseconds, after which the browse mode
745 * See #GtkSettings:gtk-tooltip-browse-timeout for more information
750 result = settings_install_property_parser (class,
751 g_param_spec_int ("gtk-tooltip-browse-mode-timeout",
752 P_("Tooltip browse mode timeout"),
753 P_("Timeout after which browse mode is disabled"),
756 GTK_PARAM_READWRITE),
759 g_assert (result == PROP_TOOLTIP_BROWSE_MODE_TIMEOUT);
762 * GtkSettings:gtk-keynav-cursor-only:
764 * When %TRUE, keyboard navigation should be able to reach all widgets
765 * by using the cursor keys only. Tab, Shift etc. keys can't be expected
766 * to be present on the used input device.
770 result = settings_install_property_parser (class,
771 g_param_spec_boolean ("gtk-keynav-cursor-only",
772 P_("Keynav Cursor Only"),
773 P_("When TRUE, there are only cursor keys available to navigate widgets"),
775 GTK_PARAM_READWRITE),
778 g_assert (result == PROP_KEYNAV_CURSOR_ONLY);
781 * GtkSettings:gtk-keynav-wrap-around:
783 * When %TRUE, some widgets will wrap around when doing keyboard
784 * navigation, such as menus, menubars and notebooks.
788 result = settings_install_property_parser (class,
789 g_param_spec_boolean ("gtk-keynav-wrap-around",
790 P_("Keynav Wrap Around"),
791 P_("Whether to wrap around when keyboard-navigating widgets"),
793 GTK_PARAM_READWRITE),
796 g_assert (result == PROP_KEYNAV_WRAP_AROUND);
799 * GtkSettings:gtk-error-bell:
801 * When %TRUE, keyboard navigation and other input-related errors
802 * will cause a beep. Since the error bell is implemented using
803 * gdk_window_beep(), the windowing system may offer ways to
804 * configure the error bell in many ways, such as flashing the
805 * window or similar visual effects.
809 result = settings_install_property_parser (class,
810 g_param_spec_boolean ("gtk-error-bell",
812 P_("When TRUE, keyboard navigation and other errors will cause a beep"),
814 GTK_PARAM_READWRITE),
817 g_assert (result == PROP_ERROR_BELL);
820 * GtkSettings:color-hash:
822 * Holds a hash table representation of the #GtkSettings:gtk-color-scheme
823 * setting, mapping color names to #GdkColor<!-- -->s.
827 result = settings_install_property_parser (class,
828 g_param_spec_boxed ("color-hash",
830 P_("A hash table representation of the color scheme."),
834 g_assert (result == PROP_COLOR_HASH);
836 result = settings_install_property_parser (class,
837 g_param_spec_string ("gtk-file-chooser-backend",
838 P_("Default file chooser backend"),
839 P_("Name of the GtkFileChooser backend to use by default"),
841 GTK_PARAM_READWRITE),
843 g_assert (result == PROP_FILE_CHOOSER_BACKEND);
846 * GtkSettings:gtk-print-backends:
848 * A comma-separated list of print backends to use in the print
849 * dialog. Available print backends depend on the GTK+ installation,
850 * and may include "file", "cups", "lpr" or "papi".
854 result = settings_install_property_parser (class,
855 g_param_spec_string ("gtk-print-backends",
856 P_("Default print backend"),
857 P_("List of the GtkPrintBackend backends to use by default"),
859 GTK_PARAM_READWRITE),
861 g_assert (result == PROP_PRINT_BACKENDS);
864 * GtkSettings:gtk-print-preview-command:
866 * A command to run for displaying the print preview. The command
867 * should contain a %f placeholder, which will get replaced by
868 * the path to the pdf file. The command may also contain a %s
869 * placeholder, which will get replaced by the path to a file
870 * containing the print settings in the format produced by
871 * gtk_print_settings_to_file().
873 * The preview application is responsible for removing the pdf file
874 * and the print settings file when it is done.
878 result = settings_install_property_parser (class,
879 g_param_spec_string ("gtk-print-preview-command",
880 P_("Default command to run when displaying a print preview"),
881 P_("Command to run when displaying a print preview"),
882 GTK_PRINT_PREVIEW_COMMAND,
883 GTK_PARAM_READWRITE),
885 g_assert (result == PROP_PRINT_PREVIEW_COMMAND);
888 * GtkSettings:gtk-enable-mnemonics:
890 * Whether labels and menu items should have visible mnemonics which
895 result = settings_install_property_parser (class,
896 g_param_spec_boolean ("gtk-enable-mnemonics",
897 P_("Enable Mnemonics"),
898 P_("Whether labels should have mnemonics"),
900 GTK_PARAM_READWRITE),
902 g_assert (result == PROP_ENABLE_MNEMONICS);
905 * GtkSettings:gtk-enable-accels:
907 * Whether menu items should have visible accelerators which can be
912 result = settings_install_property_parser (class,
913 g_param_spec_boolean ("gtk-enable-accels",
914 P_("Enable Accelerators"),
915 P_("Whether menu items should have accelerators"),
917 GTK_PARAM_READWRITE),
919 g_assert (result == PROP_ENABLE_ACCELS);
922 * GtkSettings:gtk-recent-files-limit:
924 * The number of recently used files that should be displayed by default by
925 * #GtkRecentChooser implementations and by the #GtkFileChooser. A value of
926 * -1 means every recently used file stored.
930 result = settings_install_property_parser (class,
931 g_param_spec_int ("gtk-recent-files-limit",
932 P_("Recent Files Limit"),
933 P_("Number of recently used files"),
936 GTK_PARAM_READWRITE),
938 g_assert (result == PROP_RECENT_FILES_LIMIT);
941 * GtkSettings:gtk-im-module:
943 * Which IM (input method) module should be used by default. This is the
944 * input method that will be used if the user has not explicitly chosen
945 * another input method from the IM context menu.
947 * See #GtkIMContext and see the #GtkSettings:gtk-show-input-method-menu property.
949 result = settings_install_property_parser (class,
950 g_param_spec_string ("gtk-im-module",
951 P_("Default IM module"),
952 P_("Which IM module should be used by default"),
954 GTK_PARAM_READWRITE),
956 g_assert (result == PROP_IM_MODULE);
959 * GtkSettings:gtk-recent-files-max-age:
961 * The maximum age, in days, of the items inside the recently used
962 * resources list. Items older than this setting will be excised
963 * from the list. If set to 0, the list will always be empty; if
964 * set to -1, no item will be removed.
968 result = settings_install_property_parser (class,
969 g_param_spec_int ("gtk-recent-files-max-age",
970 P_("Recent Files Max Age"),
971 P_("Maximum age of recently used files, in days"),
974 GTK_PARAM_READWRITE),
976 g_assert (result == PROP_RECENT_FILES_MAX_AGE);
978 result = settings_install_property_parser (class,
979 g_param_spec_uint ("gtk-fontconfig-timestamp",
980 P_("Fontconfig configuration timestamp"),
981 P_("Timestamp of current fontconfig configuration"),
983 GTK_PARAM_READWRITE),
986 g_assert (result == PROP_FONTCONFIG_TIMESTAMP);
989 * GtkSettings:gtk-sound-theme-name:
991 * The XDG sound theme to use for event sounds.
993 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
994 * for more information on event sounds and sound themes.
996 * GTK+ itself does not support event sounds, you have to use a loadable
997 * module like the one that comes with libcanberra.
1001 result = settings_install_property_parser (class,
1002 g_param_spec_string ("gtk-sound-theme-name",
1003 P_("Sound Theme Name"),
1004 P_("XDG sound theme name"),
1006 GTK_PARAM_READWRITE),
1008 g_assert (result == PROP_SOUND_THEME_NAME);
1011 * GtkSettings:gtk-enable-input-feedback-sounds:
1013 * Whether to play event sounds as feedback to user input.
1015 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1016 * for more information on event sounds and sound themes.
1018 * GTK+ itself does not support event sounds, you have to use a loadable
1019 * module like the one that comes with libcanberra.
1023 result = settings_install_property_parser (class,
1024 g_param_spec_boolean ("gtk-enable-input-feedback-sounds",
1025 /* Translators: this means sounds that are played as feedback to user input */
1026 P_("Audible Input Feedback"),
1027 P_("Whether to play event sounds as feedback to user input"),
1029 GTK_PARAM_READWRITE),
1031 g_assert (result == PROP_ENABLE_INPUT_FEEDBACK_SOUNDS);
1034 * GtkSettings:gtk-enable-event-sounds:
1036 * Whether to play any event sounds at all.
1038 * See the <ulink url="http://www.freedesktop.org/wiki/Specifications/sound-theme-spec">Sound Theme spec</ulink>
1039 * for more information on event sounds and sound themes.
1041 * GTK+ itself does not support event sounds, you have to use a loadable
1042 * module like the one that comes with libcanberra.
1046 result = settings_install_property_parser (class,
1047 g_param_spec_boolean ("gtk-enable-event-sounds",
1048 P_("Enable Event Sounds"),
1049 P_("Whether to play any event sounds at all"),
1051 GTK_PARAM_READWRITE),
1053 g_assert (result == PROP_ENABLE_EVENT_SOUNDS);
1056 * GtkSettings:gtk-enable-tooltips:
1058 * Whether tooltips should be shown on widgets.
1062 result = settings_install_property_parser (class,
1063 g_param_spec_boolean ("gtk-enable-tooltips",
1064 P_("Enable Tooltips"),
1065 P_("Whether tooltips should be shown on widgets"),
1067 GTK_PARAM_READWRITE),
1069 g_assert (result == PROP_ENABLE_TOOLTIPS);
1072 * GtkSettings:gtk-toolbar-style:
1074 * The size of icons in default toolbars.
1076 result = settings_install_property_parser (class,
1077 g_param_spec_enum ("gtk-toolbar-style",
1078 P_("Toolbar style"),
1079 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
1080 GTK_TYPE_TOOLBAR_STYLE,
1082 GTK_PARAM_READWRITE),
1083 gtk_rc_property_parse_enum);
1084 g_assert (result == PROP_TOOLBAR_STYLE);
1087 * GtkSettings:gtk-toolbar-icon-size:
1089 * The size of icons in default toolbars.
1091 result = settings_install_property_parser (class,
1092 g_param_spec_enum ("gtk-toolbar-icon-size",
1093 P_("Toolbar Icon Size"),
1094 P_("The size of icons in default toolbars."),
1096 GTK_ICON_SIZE_LARGE_TOOLBAR,
1097 GTK_PARAM_READWRITE),
1098 gtk_rc_property_parse_enum);
1099 g_assert (result == PROP_TOOLBAR_ICON_SIZE);
1102 * GtkSettings:gtk-auto-mnemonics:
1104 * Whether mnemonics should be automatically shown and hidden when the user
1105 * presses the mnemonic activator.
1109 result = settings_install_property_parser (class,
1110 g_param_spec_boolean ("gtk-auto-mnemonics",
1111 P_("Auto Mnemonics"),
1112 P_("Whether mnemonics should be automatically shown and hidden when the user presses the mnemonic activator."),
1114 GTK_PARAM_READWRITE),
1116 g_assert (result == PROP_AUTO_MNEMONICS);
1119 * GtkSettings:gtk-visible-focus:
1121 * Whether 'focus rectangles' should be always visible, never visible,
1122 * or hidden until the user starts to use the keyboard.
1126 result = settings_install_property_parser (class,
1127 g_param_spec_enum ("gtk-visible-focus",
1128 P_("Visible Focus"),
1129 P_("Whether 'focus rectangles' should be hidden until the user starts to use the keyboard."),
1130 GTK_TYPE_POLICY_TYPE,
1132 GTK_PARAM_READWRITE),
1133 gtk_rc_property_parse_enum);
1134 g_assert (result == PROP_VISIBLE_FOCUS);
1137 * GtkSettings:gtk-application-prefer-dark-theme:
1139 * Whether the application prefers to use a dark theme. If a GTK+ theme
1140 * includes a dark variant, it will be used instead of the configured
1143 * Some applications benefit from minimizing the amount of light pollution that
1144 * interferes with the content. Good candidates for dark themes are photo and
1145 * video editors that make the actual content get all the attention and minimize
1146 * the distraction of the chrome.
1148 * Dark themes should not be used for documents, where large spaces are white/light
1149 * and the dark chrome creates too much contrast (web browser, text editor...).
1153 result = settings_install_property_parser (class,
1154 g_param_spec_boolean ("gtk-application-prefer-dark-theme",
1155 P_("Application prefers a dark theme"),
1156 P_("Whether the application prefers to have a dark theme."),
1158 GTK_PARAM_READWRITE),
1160 g_assert (result == PROP_APPLICATION_PREFER_DARK_THEME);
1163 * GtkSettings::gtk-button-images:
1165 * Whether images should be shown on buttons
1169 result = settings_install_property_parser (class,
1170 g_param_spec_boolean ("gtk-button-images",
1171 P_("Show button images"),
1172 P_("Whether images should be shown on buttons"),
1174 GTK_PARAM_READWRITE),
1176 g_assert (result == PROP_BUTTON_IMAGES);
1178 result = settings_install_property_parser (class,
1179 g_param_spec_boolean ("gtk-entry-select-on-focus",
1180 P_("Select on focus"),
1181 P_("Whether to select the contents of an entry when it is focused"),
1183 GTK_PARAM_READWRITE),
1185 g_assert (result == PROP_ENTRY_SELECT_ON_FOCUS);
1188 * GtkSettings:gtk-entry-password-hint-timeout:
1190 * How long to show the last input character in hidden
1191 * entries. This value is in milliseconds. 0 disables showing the
1192 * last char. 600 is a good value for enabling it.
1196 result = settings_install_property_parser (class,
1197 g_param_spec_uint ("gtk-entry-password-hint-timeout",
1198 P_("Password Hint Timeout"),
1199 P_("How long to show the last input character in hidden entries"),
1202 GTK_PARAM_READWRITE),
1204 g_assert (result == PROP_ENTRY_PASSWORD_HINT_TIMEOUT);
1206 result = settings_install_property_parser (class,
1207 g_param_spec_boolean ("gtk-menu-images",
1208 P_("Show menu images"),
1209 P_("Whether images should be shown in menus"),
1211 GTK_PARAM_READWRITE),
1213 g_assert (result == PROP_MENU_IMAGES);
1215 result = settings_install_property_parser (class,
1216 g_param_spec_int ("gtk-menu-bar-popup-delay",
1217 P_("Delay before drop down menus appear"),
1218 P_("Delay before the submenus of a menu bar appear"),
1221 GTK_PARAM_READWRITE),
1223 g_assert (result == PROP_MENU_BAR_POPUP_DELAY);
1226 * GtkSettings:gtk-scrolled-window-placement:
1228 * Where the contents of scrolled windows are located with respect to the
1229 * scrollbars, if not overridden by the scrolled window's own placement.
1233 result = settings_install_property_parser (class,
1234 g_param_spec_enum ("gtk-scrolled-window-placement",
1235 P_("Scrolled Window Placement"),
1236 P_("Where the contents of scrolled windows are located with respect to the scrollbars, if not overridden by the scrolled window's own placement."),
1237 GTK_TYPE_CORNER_TYPE,
1238 GTK_CORNER_TOP_LEFT,
1239 GTK_PARAM_READWRITE),
1240 gtk_rc_property_parse_enum);
1241 g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
1243 result = settings_install_property_parser (class,
1244 g_param_spec_boolean ("gtk-can-change-accels",
1245 P_("Can change accelerators"),
1246 P_("Whether menu accelerators can be changed by pressing a key over the menu item"),
1248 GTK_PARAM_READWRITE),
1250 g_assert (result == PROP_CAN_CHANGE_ACCELS);
1252 result = settings_install_property_parser (class,
1253 g_param_spec_int ("gtk-menu-popup-delay",
1254 P_("Delay before submenus appear"),
1255 P_("Minimum time the pointer must stay over a menu item before the submenu appear"),
1258 GTK_PARAM_READWRITE),
1260 g_assert (result == PROP_MENU_POPUP_DELAY);
1262 result = settings_install_property_parser (class,
1263 g_param_spec_int ("gtk-menu-popdown-delay",
1264 P_("Delay before hiding a submenu"),
1265 P_("The time before hiding a submenu when the pointer is moving towards the submenu"),
1268 GTK_PARAM_READWRITE),
1270 g_assert (result == PROP_MENU_POPDOWN_DELAY);
1272 result = settings_install_property_parser (class,
1273 g_param_spec_boolean ("gtk-label-select-on-focus",
1274 P_("Select on focus"),
1275 P_("Whether to select the contents of a selectable label when it is focused"),
1277 GTK_PARAM_READWRITE),
1279 g_assert (result == PROP_LABEL_SELECT_ON_FOCUS);
1281 result = settings_install_property_parser (class,
1282 g_param_spec_string ("gtk-color-palette",
1283 P_("Custom palette"),
1284 P_("Palette to use in the color selector"),
1285 default_color_palette,
1286 GTK_PARAM_READWRITE),
1288 g_assert (result == PROP_COLOR_PALETTE);
1290 result = settings_install_property_parser (class,
1291 g_param_spec_enum ("gtk-im-preedit-style",
1292 P_("IM Preedit style"),
1293 P_("How to draw the input method preedit string"),
1294 GTK_TYPE_IM_PREEDIT_STYLE,
1295 GTK_IM_PREEDIT_CALLBACK,
1296 GTK_PARAM_READWRITE),
1297 gtk_rc_property_parse_enum);
1298 g_assert (result == PROP_IM_PREEDIT_STYLE);
1300 result = settings_install_property_parser (class,
1301 g_param_spec_enum ("gtk-im-status-style",
1302 P_("IM Status style"),
1303 P_("How to draw the input method statusbar"),
1304 GTK_TYPE_IM_STATUS_STYLE,
1305 GTK_IM_STATUS_CALLBACK,
1306 GTK_PARAM_READWRITE),
1307 gtk_rc_property_parse_enum);
1308 g_assert (result == PROP_IM_STATUS_STYLE);
1310 g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
1313 static GtkStyleProperties *
1314 gtk_settings_get_style (GtkStyleProvider *provider,
1315 GtkWidgetPath *path)
1317 PangoFontDescription *font_desc;
1318 gchar *font_name, *color_scheme;
1319 GtkSettings *settings;
1320 GtkStyleProperties *props;
1324 settings = GTK_SETTINGS (provider);
1325 props = gtk_style_properties_new ();
1327 g_object_get (settings,
1328 "gtk-font-name", &font_name,
1329 "gtk-color-scheme", &color_scheme,
1332 colors = g_strsplit_set (color_scheme, "\n;", -1);
1334 for (i = 0; colors[i]; i++)
1336 GtkSymbolicColor *color;
1344 pos = strchr (colors[i], ':');
1349 /* Set NUL after color name */
1353 /* Find start of color string */
1357 if (!*pos || !gdk_rgba_parse (&col, pos))
1360 color = gtk_symbolic_color_new_literal (&col);
1361 gtk_style_properties_map_color (props, name, color);
1362 gtk_symbolic_color_unref (color);
1365 font_desc = pango_font_description_from_string (font_name);
1367 /* Unset normal attributes from this description,
1368 * so they do not override theme values */
1369 if (pango_font_description_get_weight (font_desc) == PANGO_WEIGHT_NORMAL)
1370 pango_font_description_unset_fields (font_desc,
1371 PANGO_FONT_MASK_WEIGHT);
1373 if (pango_font_description_get_stretch (font_desc) == PANGO_STRETCH_NORMAL)
1374 pango_font_description_unset_fields (font_desc,
1375 PANGO_FONT_MASK_STRETCH);
1377 if (pango_font_description_get_variant (font_desc) == PANGO_VARIANT_NORMAL)
1378 pango_font_description_unset_fields (font_desc,
1379 PANGO_FONT_MASK_VARIANT);
1381 if (pango_font_description_get_style (font_desc) == PANGO_STYLE_NORMAL)
1382 pango_font_description_unset_fields (font_desc,
1383 PANGO_FONT_MASK_STYLE);
1385 gtk_style_properties_set (props, 0,
1389 pango_font_description_free (font_desc);
1390 g_strfreev (colors);
1391 g_free (color_scheme);
1398 gtk_settings_provider_iface_init (GtkStyleProviderIface *iface)
1400 iface->get_style = gtk_settings_get_style;
1404 gtk_settings_finalize (GObject *object)
1406 GtkSettings *settings = GTK_SETTINGS (object);
1407 GtkSettingsPrivate *priv = settings->priv;
1410 object_list = g_slist_remove (object_list, settings);
1412 for (i = 0; i < class_n_properties; i++)
1413 g_value_unset (&priv->property_values[i].value);
1414 g_free (priv->property_values);
1416 g_datalist_clear (&priv->queued_settings);
1418 if (priv->theme_provider)
1419 g_object_unref (priv->theme_provider);
1421 if (priv->key_theme_provider)
1422 g_object_unref (priv->key_theme_provider);
1424 G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
1428 settings_init_style (GtkSettings *settings)
1430 static GtkCssProvider *css_provider = NULL;
1432 GdkScreen *screen = settings->priv->screen;
1433 GtkCssProvider *default_provider;
1435 /* Add provider for user file */
1436 if (G_UNLIKELY (!css_provider))
1440 css_provider = gtk_css_provider_new ();
1441 css_path = g_build_filename (g_get_user_config_dir (),
1446 if (g_file_test (css_path,
1447 G_FILE_TEST_IS_REGULAR))
1448 gtk_css_provider_load_from_path (css_provider, css_path, NULL);
1453 gtk_style_context_add_provider_for_screen (screen,
1454 GTK_STYLE_PROVIDER (css_provider),
1455 GTK_STYLE_PROVIDER_PRIORITY_USER);
1457 default_provider = gtk_css_provider_get_default ();
1458 gtk_style_context_add_provider_for_screen (screen,
1459 GTK_STYLE_PROVIDER (default_provider),
1460 GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
1462 gtk_style_context_add_provider_for_screen (screen,
1463 GTK_STYLE_PROVIDER (settings),
1464 GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
1466 settings_update_theme (settings);
1467 settings_update_key_theme (settings);
1471 * gtk_settings_get_for_screen:
1472 * @screen: a #GdkScreen.
1474 * Gets the #GtkSettings object for @screen, creating it if necessary.
1476 * Return value: (transfer none): a #GtkSettings object.
1481 gtk_settings_get_for_screen (GdkScreen *screen)
1483 GtkSettings *settings;
1485 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1487 settings = g_object_get_data (G_OBJECT (screen), "gtk-settings");
1490 #ifdef GDK_WINDOWING_QUARTZ
1491 if (GDK_IS_QUARTZ_SCREEN (screen))
1492 settings = g_object_new (GTK_TYPE_SETTINGS, "gtk-key-theme-name", "Mac", NULL);
1495 settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
1496 settings->priv->screen = screen;
1497 g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"),
1498 settings, g_object_unref);
1500 settings_init_style (settings);
1501 settings_update_double_click (settings);
1502 settings_update_cursor_theme (settings);
1503 settings_update_resolution (settings);
1504 settings_update_font_options (settings);
1505 settings_update_color_scheme (settings);
1512 * gtk_settings_get_default:
1514 * Gets the #GtkSettings object for the default GDK screen, creating
1515 * it if necessary. See gtk_settings_get_for_screen().
1517 * Return value: (transfer none): a #GtkSettings object. If there is no default
1518 * screen, then returns %NULL.
1521 gtk_settings_get_default (void)
1523 GdkScreen *screen = gdk_screen_get_default ();
1526 return gtk_settings_get_for_screen (screen);
1532 gtk_settings_set_property (GObject *object,
1534 const GValue *value,
1537 GtkSettings *settings = GTK_SETTINGS (object);
1538 GtkSettingsPrivate *priv = settings->priv;
1540 g_value_copy (value, &priv->property_values[property_id - 1].value);
1541 priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
1543 if (pspec->param_id == PROP_COLOR_SCHEME)
1544 merge_color_scheme (settings, value, GTK_SETTINGS_SOURCE_APPLICATION);
1548 gtk_settings_get_property (GObject *object,
1553 GtkSettings *settings = GTK_SETTINGS (object);
1554 GtkSettingsPrivate *priv = settings->priv;
1555 GType value_type = G_VALUE_TYPE (value);
1556 GType fundamental_type = G_TYPE_FUNDAMENTAL (value_type);
1558 /* handle internal properties */
1559 switch (property_id)
1561 case PROP_COLOR_HASH:
1562 g_value_set_boxed (value, get_color_hash (settings));
1564 case PROP_COLOR_SCHEME:
1565 g_value_take_string (value, get_color_scheme (settings));
1570 /* For enums and strings, we need to get the value as a string,
1571 * not as an int, since we support using names/nicks as the setting
1574 if ((g_value_type_transformable (G_TYPE_INT, value_type) &&
1575 !(fundamental_type == G_TYPE_ENUM || fundamental_type == G_TYPE_FLAGS)) ||
1576 g_value_type_transformable (G_TYPE_STRING, G_VALUE_TYPE (value)) ||
1577 g_value_type_transformable (GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1579 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1580 !gdk_screen_get_setting (priv->screen, pspec->name, value))
1581 g_value_copy (&priv->property_values[property_id - 1].value, value);
1583 g_param_value_validate (pspec, value);
1587 GValue val = G_VALUE_INIT;
1589 /* Try to get xsetting as a string and parse it. */
1591 g_value_init (&val, G_TYPE_STRING);
1593 if (priv->property_values[property_id - 1].source == GTK_SETTINGS_SOURCE_APPLICATION ||
1594 !gdk_screen_get_setting (priv->screen, pspec->name, &val))
1596 g_value_copy (&priv->property_values[property_id - 1].value, value);
1600 GValue tmp_value = G_VALUE_INIT;
1601 GValue gstring_value = G_VALUE_INIT;
1602 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1604 g_value_init (&gstring_value, G_TYPE_GSTRING);
1605 g_value_take_boxed (&gstring_value,
1606 g_string_new (g_value_get_string (&val)));
1608 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1610 if (parser && _gtk_settings_parse_convert (parser, &gstring_value,
1613 g_value_copy (&tmp_value, value);
1614 g_param_value_validate (pspec, value);
1618 g_value_copy (&priv->property_values[property_id - 1].value, value);
1621 g_value_unset (&gstring_value);
1622 g_value_unset (&tmp_value);
1625 g_value_unset (&val);
1630 gtk_settings_notify (GObject *object,
1633 GtkSettings *settings = GTK_SETTINGS (object);
1634 GtkSettingsPrivate *priv = settings->priv;
1635 guint property_id = pspec->param_id;
1637 if (priv->screen == NULL) /* initialization */
1640 switch (property_id)
1643 settings_update_modules (settings);
1645 case PROP_DOUBLE_CLICK_TIME:
1646 case PROP_DOUBLE_CLICK_DISTANCE:
1647 settings_update_double_click (settings);
1649 case PROP_COLOR_SCHEME:
1650 settings_update_color_scheme (settings);
1651 gtk_style_context_reset_widgets (priv->screen);
1653 case PROP_FONT_NAME:
1654 gtk_style_context_reset_widgets (priv->screen);
1656 case PROP_KEY_THEME_NAME:
1657 settings_update_key_theme (settings);
1659 case PROP_THEME_NAME:
1660 case PROP_APPLICATION_PREFER_DARK_THEME:
1661 settings_update_theme (settings);
1664 settings_update_resolution (settings);
1665 /* This is a hack because with gtk_rc_reset_styles() doesn't get
1666 * widgets with gtk_widget_style_set(), and also causes more
1667 * recomputation than necessary.
1669 gtk_style_context_reset_widgets (priv->screen);
1671 case PROP_XFT_ANTIALIAS:
1672 case PROP_XFT_HINTING:
1673 case PROP_XFT_HINTSTYLE:
1675 settings_update_font_options (settings);
1676 gtk_style_context_reset_widgets (priv->screen);
1678 case PROP_FONTCONFIG_TIMESTAMP:
1679 if (settings_update_fontconfig (settings))
1680 gtk_style_context_reset_widgets (priv->screen);
1682 case PROP_CURSOR_THEME_NAME:
1683 case PROP_CURSOR_THEME_SIZE:
1684 settings_update_cursor_theme (settings);
1690 _gtk_settings_parse_convert (GtkRcPropertyParser parser,
1691 const GValue *src_value,
1695 gboolean success = FALSE;
1697 g_return_val_if_fail (G_VALUE_HOLDS (dest_value, G_PARAM_SPEC_VALUE_TYPE (pspec)), FALSE);
1702 gboolean free_gstring = TRUE;
1704 if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1706 gstring = g_value_get_boxed (src_value);
1707 free_gstring = FALSE;
1709 else if (G_VALUE_HOLDS_LONG (src_value))
1711 gstring = g_string_new (NULL);
1712 g_string_append_printf (gstring, "%ld", g_value_get_long (src_value));
1714 else if (G_VALUE_HOLDS_DOUBLE (src_value))
1716 gstring = g_string_new (NULL);
1717 g_string_append_printf (gstring, "%f", g_value_get_double (src_value));
1719 else if (G_VALUE_HOLDS_STRING (src_value))
1721 gchar *tstr = g_strescape (g_value_get_string (src_value), NULL);
1723 gstring = g_string_new (NULL);
1724 g_string_append_c (gstring, '\"');
1725 g_string_append (gstring, tstr);
1726 g_string_append_c (gstring, '\"');
1731 g_return_val_if_fail (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING), FALSE);
1732 gstring = NULL; /* silence compiler */
1735 success = (parser (pspec, gstring, dest_value) &&
1736 !g_param_value_validate (pspec, dest_value));
1739 g_string_free (gstring, TRUE);
1741 else if (G_VALUE_HOLDS (src_value, G_TYPE_GSTRING))
1743 if (G_VALUE_HOLDS (dest_value, G_TYPE_STRING))
1745 GString *gstring = g_value_get_boxed (src_value);
1747 g_value_set_string (dest_value, gstring ? gstring->str : NULL);
1748 success = !g_param_value_validate (pspec, dest_value);
1751 else if (g_value_type_transformable (G_VALUE_TYPE (src_value), G_VALUE_TYPE (dest_value)))
1752 success = g_param_value_convert (pspec, src_value, dest_value, TRUE);
1758 apply_queued_setting (GtkSettings *settings,
1760 GtkSettingsValuePrivate *qvalue)
1762 GtkSettingsPrivate *priv = settings->priv;
1763 GValue tmp_value = G_VALUE_INIT;
1764 GtkRcPropertyParser parser = (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser);
1766 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1767 if (_gtk_settings_parse_convert (parser, &qvalue->public.value,
1770 if (pspec->param_id == PROP_COLOR_SCHEME)
1771 merge_color_scheme (settings, &tmp_value, qvalue->source);
1773 if (priv->property_values[pspec->param_id - 1].source <= qvalue->source)
1775 g_value_copy (&tmp_value, &priv->property_values[pspec->param_id - 1].value);
1776 priv->property_values[pspec->param_id - 1].source = qvalue->source;
1777 g_object_notify (G_OBJECT (settings), g_param_spec_get_name (pspec));
1783 gchar *debug = g_strdup_value_contents (&qvalue->public.value);
1785 g_message ("%s: failed to retrieve property `%s' of type `%s' from rc file value \"%s\" of type `%s'",
1786 qvalue->public.origin ? qvalue->public.origin : "(for origin information, set GTK_DEBUG)",
1788 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1790 G_VALUE_TYPE_NAME (&tmp_value));
1793 g_value_unset (&tmp_value);
1797 settings_install_property_parser (GtkSettingsClass *class,
1799 GtkRcPropertyParser parser)
1801 GSList *node, *next;
1803 switch (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (pspec)))
1805 case G_TYPE_BOOLEAN:
1818 if (strcmp (g_param_spec_get_name (pspec), "color-hash") == 0)
1826 g_warning (G_STRLOC ": parser needs to be specified for property \"%s\" of type `%s'",
1827 pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
1831 if (g_object_class_find_property (G_OBJECT_CLASS (class), pspec->name))
1833 g_warning (G_STRLOC ": an rc-data property \"%s\" already exists",
1838 for (node = object_list; node; node = node->next)
1839 g_object_freeze_notify (node->data);
1841 g_object_class_install_property (G_OBJECT_CLASS (class), ++class_n_properties, pspec);
1842 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
1844 for (node = object_list; node; node = node->next)
1846 GtkSettings *settings = node->data;
1847 GtkSettingsPrivate *priv = settings->priv;
1848 GtkSettingsValuePrivate *qvalue;
1850 priv->property_values = g_renew (GtkSettingsPropertyValue, priv->property_values, class_n_properties);
1851 priv->property_values[class_n_properties - 1].value.g_type = 0;
1852 g_value_init (&priv->property_values[class_n_properties - 1].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1853 g_param_value_set_default (pspec, &priv->property_values[class_n_properties - 1].value);
1854 priv->property_values[class_n_properties - 1].source = GTK_SETTINGS_SOURCE_DEFAULT;
1855 g_object_notify (G_OBJECT (settings), pspec->name);
1857 qvalue = g_datalist_get_data (&priv->queued_settings, pspec->name);
1859 apply_queued_setting (settings, pspec, qvalue);
1862 for (node = object_list; node; node = next)
1865 g_object_thaw_notify (node->data);
1868 return class_n_properties;
1872 _gtk_rc_property_parser_from_type (GType type)
1874 if (type == GDK_TYPE_COLOR)
1875 return gtk_rc_property_parse_color;
1876 else if (type == GTK_TYPE_REQUISITION)
1877 return gtk_rc_property_parse_requisition;
1878 else if (type == GTK_TYPE_BORDER)
1879 return gtk_rc_property_parse_border;
1880 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_ENUM && G_TYPE_IS_DERIVED (type))
1881 return gtk_rc_property_parse_enum;
1882 else if (G_TYPE_FUNDAMENTAL (type) == G_TYPE_FLAGS && G_TYPE_IS_DERIVED (type))
1883 return gtk_rc_property_parse_flags;
1889 gtk_settings_install_property (GParamSpec *pspec)
1891 static GtkSettingsClass *klass = NULL;
1893 GtkRcPropertyParser parser;
1895 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1898 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1900 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
1902 settings_install_property_parser (klass, pspec, parser);
1906 * gtk_settings_install_property_parser:
1908 * @parser: (scope call):
1911 gtk_settings_install_property_parser (GParamSpec *pspec,
1912 GtkRcPropertyParser parser)
1914 static GtkSettingsClass *klass = NULL;
1916 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
1917 g_return_if_fail (parser != NULL);
1920 klass = g_type_class_ref (GTK_TYPE_SETTINGS);
1922 settings_install_property_parser (klass, pspec, parser);
1926 free_value (gpointer data)
1928 GtkSettingsValuePrivate *qvalue = data;
1930 g_value_unset (&qvalue->public.value);
1931 g_free (qvalue->public.origin);
1932 g_slice_free (GtkSettingsValuePrivate, qvalue);
1936 gtk_settings_set_property_value_internal (GtkSettings *settings,
1937 const gchar *prop_name,
1938 const GtkSettingsValue *new_value,
1939 GtkSettingsSource source)
1941 GtkSettingsPrivate *priv = settings->priv;
1942 GtkSettingsValuePrivate *qvalue;
1947 if (!G_VALUE_HOLDS_LONG (&new_value->value) &&
1948 !G_VALUE_HOLDS_DOUBLE (&new_value->value) &&
1949 !G_VALUE_HOLDS_STRING (&new_value->value) &&
1950 !G_VALUE_HOLDS (&new_value->value, G_TYPE_GSTRING))
1952 g_warning (G_STRLOC ": value type invalid (%s)", g_type_name (G_VALUE_TYPE (&new_value->value)));
1956 name = g_strdup (prop_name);
1957 g_strcanon (name, G_CSET_DIGITS "-" G_CSET_a_2_z G_CSET_A_2_Z, '-');
1958 name_quark = g_quark_from_string (name);
1961 qvalue = g_datalist_id_get_data (&priv->queued_settings, name_quark);
1964 qvalue = g_slice_new0 (GtkSettingsValuePrivate);
1965 g_datalist_id_set_data_full (&priv->queued_settings, name_quark, qvalue, free_value);
1969 g_free (qvalue->public.origin);
1970 g_value_unset (&qvalue->public.value);
1972 qvalue->public.origin = g_strdup (new_value->origin);
1973 g_value_init (&qvalue->public.value, G_VALUE_TYPE (&new_value->value));
1974 g_value_copy (&new_value->value, &qvalue->public.value);
1975 qvalue->source = source;
1976 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), g_quark_to_string (name_quark));
1978 apply_queued_setting (settings, pspec, qvalue);
1982 gtk_settings_set_property_value (GtkSettings *settings,
1983 const gchar *prop_name,
1984 const GtkSettingsValue *new_value)
1986 g_return_if_fail (GTK_SETTINGS (settings));
1987 g_return_if_fail (prop_name != NULL);
1988 g_return_if_fail (new_value != NULL);
1990 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
1991 GTK_SETTINGS_SOURCE_APPLICATION);
1995 _gtk_settings_set_property_value_from_rc (GtkSettings *settings,
1996 const gchar *prop_name,
1997 const GtkSettingsValue *new_value)
1999 g_return_if_fail (GTK_SETTINGS (settings));
2000 g_return_if_fail (prop_name != NULL);
2001 g_return_if_fail (new_value != NULL);
2003 gtk_settings_set_property_value_internal (settings, prop_name, new_value,
2004 GTK_SETTINGS_SOURCE_THEME);
2008 gtk_settings_set_string_property (GtkSettings *settings,
2010 const gchar *v_string,
2011 const gchar *origin)
2013 GtkSettingsValue svalue = { NULL, { 0, }, };
2015 g_return_if_fail (GTK_SETTINGS (settings));
2016 g_return_if_fail (name != NULL);
2017 g_return_if_fail (v_string != NULL);
2019 svalue.origin = (gchar*) origin;
2020 g_value_init (&svalue.value, G_TYPE_STRING);
2021 g_value_set_static_string (&svalue.value, v_string);
2022 gtk_settings_set_property_value (settings, name, &svalue);
2023 g_value_unset (&svalue.value);
2027 gtk_settings_set_long_property (GtkSettings *settings,
2030 const gchar *origin)
2032 GtkSettingsValue svalue = { NULL, { 0, }, };
2034 g_return_if_fail (GTK_SETTINGS (settings));
2035 g_return_if_fail (name != NULL);
2037 svalue.origin = (gchar*) origin;
2038 g_value_init (&svalue.value, G_TYPE_LONG);
2039 g_value_set_long (&svalue.value, v_long);
2040 gtk_settings_set_property_value (settings, name, &svalue);
2041 g_value_unset (&svalue.value);
2045 gtk_settings_set_double_property (GtkSettings *settings,
2048 const gchar *origin)
2050 GtkSettingsValue svalue = { NULL, { 0, }, };
2052 g_return_if_fail (GTK_SETTINGS (settings));
2053 g_return_if_fail (name != NULL);
2055 svalue.origin = (gchar*) origin;
2056 g_value_init (&svalue.value, G_TYPE_DOUBLE);
2057 g_value_set_double (&svalue.value, v_double);
2058 gtk_settings_set_property_value (settings, name, &svalue);
2059 g_value_unset (&svalue.value);
2063 * gtk_rc_property_parse_color:
2064 * @pspec: a #GParamSpec
2065 * @gstring: the #GString to be parsed
2066 * @property_value: a #GValue which must hold #GdkColor values.
2068 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2069 * or gtk_widget_class_install_style_property_parser() which parses a
2070 * color given either by its name or in the form
2071 * <literal>{ red, green, blue }</literal> where %red, %green and
2072 * %blue are integers between 0 and 65535 or floating-point numbers
2075 * Return value: %TRUE if @gstring could be parsed and @property_value
2076 * has been set to the resulting #GdkColor.
2079 gtk_rc_property_parse_color (const GParamSpec *pspec,
2080 const GString *gstring,
2081 GValue *property_value)
2083 GdkColor color = { 0, 0, 0, 0, };
2087 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2088 g_return_val_if_fail (G_VALUE_HOLDS (property_value, GDK_TYPE_COLOR), FALSE);
2090 scanner = gtk_rc_scanner_new ();
2091 g_scanner_input_text (scanner, gstring->str, gstring->len);
2092 if (gtk_rc_parse_color (scanner, &color) == G_TOKEN_NONE &&
2093 g_scanner_get_next_token (scanner) == G_TOKEN_EOF)
2095 g_value_set_boxed (property_value, &color);
2100 g_scanner_destroy (scanner);
2106 * gtk_rc_property_parse_enum:
2107 * @pspec: a #GParamSpec
2108 * @gstring: the #GString to be parsed
2109 * @property_value: a #GValue which must hold enum values.
2111 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2112 * or gtk_widget_class_install_style_property_parser() which parses a single
2113 * enumeration value.
2115 * The enumeration value can be specified by its name, its nickname or
2116 * its numeric value. For consistency with flags parsing, the value
2117 * may be surrounded by parentheses.
2119 * Return value: %TRUE if @gstring could be parsed and @property_value
2120 * has been set to the resulting #GEnumValue.
2123 gtk_rc_property_parse_enum (const GParamSpec *pspec,
2124 const GString *gstring,
2125 GValue *property_value)
2127 gboolean need_closing_brace = FALSE, success = FALSE;
2129 GEnumValue *enum_value = NULL;
2131 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2132 g_return_val_if_fail (G_VALUE_HOLDS_ENUM (property_value), FALSE);
2134 scanner = gtk_rc_scanner_new ();
2135 g_scanner_input_text (scanner, gstring->str, gstring->len);
2137 /* we just want to parse _one_ value, but for consistency with flags parsing
2138 * we support optional parenthesis
2140 g_scanner_get_next_token (scanner);
2141 if (scanner->token == '(')
2143 need_closing_brace = TRUE;
2144 g_scanner_get_next_token (scanner);
2146 if (scanner->token == G_TOKEN_IDENTIFIER)
2148 GEnumClass *class = G_PARAM_SPEC_ENUM (pspec)->enum_class;
2150 enum_value = g_enum_get_value_by_name (class, scanner->value.v_identifier);
2152 enum_value = g_enum_get_value_by_nick (class, scanner->value.v_identifier);
2155 g_value_set_enum (property_value, enum_value->value);
2159 else if (scanner->token == G_TOKEN_INT)
2161 g_value_set_enum (property_value, scanner->value.v_int);
2164 if (need_closing_brace && g_scanner_get_next_token (scanner) != ')')
2166 if (g_scanner_get_next_token (scanner) != G_TOKEN_EOF)
2169 g_scanner_destroy (scanner);
2175 parse_flags_value (GScanner *scanner,
2179 g_scanner_get_next_token (scanner);
2180 if (scanner->token == G_TOKEN_IDENTIFIER)
2182 GFlagsValue *flags_value;
2184 flags_value = g_flags_get_value_by_name (class, scanner->value.v_identifier);
2186 flags_value = g_flags_get_value_by_nick (class, scanner->value.v_identifier);
2189 *number |= flags_value->value;
2190 return G_TOKEN_NONE;
2193 else if (scanner->token == G_TOKEN_INT)
2195 *number |= scanner->value.v_int;
2196 return G_TOKEN_NONE;
2198 return G_TOKEN_IDENTIFIER;
2202 * gtk_rc_property_parse_flags:
2203 * @pspec: a #GParamSpec
2204 * @gstring: the #GString to be parsed
2205 * @property_value: a #GValue which must hold flags values.
2207 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2208 * or gtk_widget_class_install_style_property_parser() which parses flags.
2210 * Flags can be specified by their name, their nickname or
2211 * numerically. Multiple flags can be specified in the form
2212 * <literal>"( flag1 | flag2 | ... )"</literal>.
2214 * Return value: %TRUE if @gstring could be parsed and @property_value
2215 * has been set to the resulting flags value.
2218 gtk_rc_property_parse_flags (const GParamSpec *pspec,
2219 const GString *gstring,
2220 GValue *property_value)
2223 gboolean success = FALSE;
2226 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2227 g_return_val_if_fail (G_VALUE_HOLDS_FLAGS (property_value), FALSE);
2229 class = G_PARAM_SPEC_FLAGS (pspec)->flags_class;
2230 scanner = gtk_rc_scanner_new ();
2231 g_scanner_input_text (scanner, gstring->str, gstring->len);
2233 /* parse either a single flags value or a "\( ... [ \| ... ] \)" compound */
2234 if (g_scanner_peek_next_token (scanner) == G_TOKEN_IDENTIFIER ||
2235 scanner->next_token == G_TOKEN_INT)
2237 guint token, flags_value = 0;
2239 token = parse_flags_value (scanner, class, &flags_value);
2241 if (token == G_TOKEN_NONE && g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2244 g_value_set_flags (property_value, flags_value);
2248 else if (g_scanner_get_next_token (scanner) == '(')
2250 guint token, flags_value = 0;
2252 /* parse first value */
2253 token = parse_flags_value (scanner, class, &flags_value);
2255 /* parse nth values, preceeded by '|' */
2256 while (token == G_TOKEN_NONE && g_scanner_get_next_token (scanner) == '|')
2257 token = parse_flags_value (scanner, class, &flags_value);
2259 /* done, last token must have closed expression */
2260 if (token == G_TOKEN_NONE && scanner->token == ')' &&
2261 g_scanner_peek_next_token (scanner) == G_TOKEN_EOF)
2263 g_value_set_flags (property_value, flags_value);
2267 g_scanner_destroy (scanner);
2273 get_braced_int (GScanner *scanner,
2280 g_scanner_get_next_token (scanner);
2281 if (scanner->token != '{')
2285 g_scanner_get_next_token (scanner);
2286 if (scanner->token != G_TOKEN_INT)
2289 *value = scanner->value.v_int;
2293 g_scanner_get_next_token (scanner);
2294 if (scanner->token != '}')
2299 g_scanner_get_next_token (scanner);
2300 if (scanner->token != ',')
2308 * gtk_rc_property_parse_requisition:
2309 * @pspec: a #GParamSpec
2310 * @gstring: the #GString to be parsed
2311 * @property_value: a #GValue which must hold boxed values.
2313 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2314 * or gtk_widget_class_install_style_property_parser() which parses a
2315 * requisition in the form
2316 * <literal>"{ width, height }"</literal> for integers %width and %height.
2318 * Return value: %TRUE if @gstring could be parsed and @property_value
2319 * has been set to the resulting #GtkRequisition.
2322 gtk_rc_property_parse_requisition (const GParamSpec *pspec,
2323 const GString *gstring,
2324 GValue *property_value)
2326 GtkRequisition requisition;
2328 gboolean success = FALSE;
2330 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2331 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2333 scanner = gtk_rc_scanner_new ();
2334 g_scanner_input_text (scanner, gstring->str, gstring->len);
2336 if (get_braced_int (scanner, TRUE, FALSE, &requisition.width) &&
2337 get_braced_int (scanner, FALSE, TRUE, &requisition.height))
2339 g_value_set_boxed (property_value, &requisition);
2343 g_scanner_destroy (scanner);
2349 * gtk_rc_property_parse_border:
2350 * @pspec: a #GParamSpec
2351 * @gstring: the #GString to be parsed
2352 * @property_value: a #GValue which must hold boxed values.
2354 * A #GtkRcPropertyParser for use with gtk_settings_install_property_parser()
2355 * or gtk_widget_class_install_style_property_parser() which parses
2356 * borders in the form
2357 * <literal>"{ left, right, top, bottom }"</literal> for integers
2358 * %left, %right, %top and %bottom.
2360 * Return value: %TRUE if @gstring could be parsed and @property_value
2361 * has been set to the resulting #GtkBorder.
2364 gtk_rc_property_parse_border (const GParamSpec *pspec,
2365 const GString *gstring,
2366 GValue *property_value)
2370 gboolean success = FALSE;
2371 int left, right, top, bottom;
2373 g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
2374 g_return_val_if_fail (G_VALUE_HOLDS_BOXED (property_value), FALSE);
2376 scanner = gtk_rc_scanner_new ();
2377 g_scanner_input_text (scanner, gstring->str, gstring->len);
2379 if (get_braced_int (scanner, TRUE, FALSE, &left) &&
2380 get_braced_int (scanner, FALSE, FALSE, &right) &&
2381 get_braced_int (scanner, FALSE, FALSE, &top) &&
2382 get_braced_int (scanner, FALSE, TRUE, &bottom))
2385 border.right = right;
2387 border.bottom = bottom;
2388 g_value_set_boxed (property_value, &border);
2392 g_scanner_destroy (scanner);
2398 _gtk_settings_handle_event (GdkEventSetting *event)
2401 GtkSettings *settings;
2405 screen = gdk_window_get_screen (event->window);
2406 settings = gtk_settings_get_for_screen (screen);
2407 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), event->name);
2411 property_id = pspec->param_id;
2413 if (property_id == PROP_COLOR_SCHEME)
2415 GValue value = G_VALUE_INIT;
2417 g_value_init (&value, G_TYPE_STRING);
2418 if (!gdk_screen_get_setting (screen, pspec->name, &value))
2419 g_value_set_static_string (&value, "");
2420 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2421 g_value_unset (&value);
2423 g_object_notify (G_OBJECT (settings), pspec->name);
2428 reset_rc_values_foreach (GQuark key_id,
2432 GtkSettingsValuePrivate *qvalue = data;
2433 GSList **to_reset = user_data;
2435 if (qvalue->source == GTK_SETTINGS_SOURCE_THEME)
2436 *to_reset = g_slist_prepend (*to_reset, GUINT_TO_POINTER (key_id));
2440 _gtk_settings_reset_rc_values (GtkSettings *settings)
2442 GtkSettingsPrivate *priv = settings->priv;
2443 GSList *to_reset = NULL;
2445 GParamSpec **pspecs, **p;
2448 /* Remove any queued settings */
2449 g_datalist_foreach (&priv->queued_settings,
2450 reset_rc_values_foreach,
2453 for (tmp_list = to_reset; tmp_list; tmp_list = tmp_list->next)
2455 GQuark key_id = GPOINTER_TO_UINT (tmp_list->data);
2456 g_datalist_id_remove_data (&priv->queued_settings, key_id);
2459 g_slist_free (to_reset);
2461 /* Now reset the active settings
2463 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (settings), NULL);
2466 g_object_freeze_notify (G_OBJECT (settings));
2467 for (p = pspecs; *p; p++)
2469 if (priv->property_values[i].source == GTK_SETTINGS_SOURCE_THEME)
2471 GParamSpec *pspec = *p;
2473 g_param_value_set_default (pspec, &priv->property_values[i].value);
2474 g_object_notify (G_OBJECT (settings), pspec->name);
2478 g_object_thaw_notify (G_OBJECT (settings));
2483 settings_update_double_click (GtkSettings *settings)
2485 GtkSettingsPrivate *priv = settings->priv;
2487 if (gdk_screen_get_number (priv->screen) == 0)
2489 GdkDisplay *display = gdk_screen_get_display (priv->screen);
2490 gint double_click_time;
2491 gint double_click_distance;
2493 g_object_get (settings,
2494 "gtk-double-click-time", &double_click_time,
2495 "gtk-double-click-distance", &double_click_distance,
2498 gdk_display_set_double_click_time (display, double_click_time);
2499 gdk_display_set_double_click_distance (display, double_click_distance);
2504 settings_update_modules (GtkSettings *settings)
2508 g_object_get (settings,
2509 "gtk-modules", &modules,
2512 _gtk_modules_settings_changed (settings, modules);
2518 settings_update_cursor_theme (GtkSettings *settings)
2520 #ifdef GDK_WINDOWING_X11
2521 GdkDisplay *display = gdk_screen_get_display (settings->priv->screen);
2522 gchar *theme = NULL;
2525 if (GDK_IS_X11_DISPLAY (display))
2527 g_object_get (settings,
2528 "gtk-cursor-theme-name", &theme,
2529 "gtk-cursor-theme-size", &size,
2532 gdk_x11_display_set_cursor_theme (display, theme, size);
2540 settings_update_font_options (GtkSettings *settings)
2542 GtkSettingsPrivate *priv = settings->priv;
2544 gchar *hint_style_str;
2545 cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
2547 cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
2549 cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
2550 cairo_font_options_t *options;
2552 g_object_get (settings,
2553 "gtk-xft-antialias", &antialias,
2554 "gtk-xft-hinting", &hinting,
2555 "gtk-xft-hintstyle", &hint_style_str,
2556 "gtk-xft-rgba", &rgba_str,
2559 options = cairo_font_options_create ();
2561 cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
2563 if (hinting >= 0 && !hinting)
2565 hint_style = CAIRO_HINT_STYLE_NONE;
2567 else if (hint_style_str)
2569 if (strcmp (hint_style_str, "hintnone") == 0)
2570 hint_style = CAIRO_HINT_STYLE_NONE;
2571 else if (strcmp (hint_style_str, "hintslight") == 0)
2572 hint_style = CAIRO_HINT_STYLE_SLIGHT;
2573 else if (strcmp (hint_style_str, "hintmedium") == 0)
2574 hint_style = CAIRO_HINT_STYLE_MEDIUM;
2575 else if (strcmp (hint_style_str, "hintfull") == 0)
2576 hint_style = CAIRO_HINT_STYLE_FULL;
2579 g_free (hint_style_str);
2581 cairo_font_options_set_hint_style (options, hint_style);
2585 if (strcmp (rgba_str, "rgb") == 0)
2586 subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
2587 else if (strcmp (rgba_str, "bgr") == 0)
2588 subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
2589 else if (strcmp (rgba_str, "vrgb") == 0)
2590 subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
2591 else if (strcmp (rgba_str, "vbgr") == 0)
2592 subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
2597 cairo_font_options_set_subpixel_order (options, subpixel_order);
2599 if (antialias >= 0 && !antialias)
2600 antialias_mode = CAIRO_ANTIALIAS_NONE;
2601 else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
2602 antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
2603 else if (antialias >= 0)
2604 antialias_mode = CAIRO_ANTIALIAS_GRAY;
2606 cairo_font_options_set_antialias (options, antialias_mode);
2608 gdk_screen_set_font_options (priv->screen, options);
2610 cairo_font_options_destroy (options);
2614 settings_update_fontconfig (GtkSettings *settings)
2616 #ifdef GDK_WINDOWING_X11
2617 static guint last_update_timestamp;
2618 static gboolean last_update_needed;
2622 g_object_get (settings,
2623 "gtk-fontconfig-timestamp", ×tamp,
2626 /* if timestamp is the same as last_update_timestamp, we already have
2627 * updated fontconig on this timestamp (another screen requested it perhaps?),
2628 * just return the cached result.*/
2630 if (timestamp != last_update_timestamp)
2632 PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
2633 gboolean update_needed = FALSE;
2636 if (PANGO_IS_FC_FONT_MAP (fontmap) && !FcConfigUptoDate (NULL))
2638 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
2639 if (FcInitReinitialize ())
2640 update_needed = TRUE;
2643 last_update_timestamp = timestamp;
2644 last_update_needed = update_needed;
2647 return last_update_needed;
2650 #endif /* GDK_WINDOWING_X11 */
2654 settings_update_resolution (GtkSettings *settings)
2656 GtkSettingsPrivate *priv = settings->priv;
2660 g_object_get (settings,
2661 "gtk-xft-dpi", &dpi_int,
2665 dpi = dpi_int / 1024.;
2669 gdk_screen_set_resolution (priv->screen, dpi);
2674 GHashTable *color_hash;
2675 GHashTable *tables[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2676 gchar *lastentry[GTK_SETTINGS_SOURCE_APPLICATION + 1];
2680 color_scheme_data_free (ColorSchemeData *data)
2684 g_hash_table_unref (data->color_hash);
2686 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2688 if (data->tables[i])
2689 g_hash_table_unref (data->tables[i]);
2690 g_free (data->lastentry[i]);
2693 g_slice_free (ColorSchemeData, data);
2697 settings_update_color_scheme (GtkSettings *settings)
2699 if (!g_object_get_data (G_OBJECT (settings), "gtk-color-scheme"))
2701 GtkSettingsPrivate *priv = settings->priv;
2702 ColorSchemeData *data;
2703 GValue value = G_VALUE_INIT;
2705 data = g_slice_new0 (ColorSchemeData);
2706 data->color_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2707 (GDestroyNotify) gdk_color_free);
2708 g_object_set_data_full (G_OBJECT (settings), "gtk-color-scheme",
2709 data, (GDestroyNotify) color_scheme_data_free);
2711 g_value_init (&value, G_TYPE_STRING);
2712 if (priv->screen && gdk_screen_get_setting (priv->screen, "gtk-color-scheme", &value))
2714 merge_color_scheme (settings, &value, GTK_SETTINGS_SOURCE_XSETTING);
2715 g_value_unset (&value);
2721 settings_update_provider (GdkScreen *screen,
2722 GtkCssProvider **old,
2723 GtkCssProvider *new)
2729 gtk_style_context_remove_provider_for_screen (screen,
2730 GTK_STYLE_PROVIDER (*old));
2731 g_object_unref (*old);
2737 gtk_style_context_add_provider_for_screen (screen,
2738 GTK_STYLE_PROVIDER (new),
2739 GTK_STYLE_PROVIDER_PRIORITY_THEME);
2740 *old = g_object_ref (new);
2746 settings_update_theme (GtkSettings *settings)
2748 GtkSettingsPrivate *priv = settings->priv;
2749 GtkCssProvider *provider = NULL;
2750 gboolean prefer_dark_theme;
2753 g_object_get (settings,
2754 "gtk-theme-name", &theme_name,
2755 "gtk-application-prefer-dark-theme", &prefer_dark_theme,
2758 if (theme_name && *theme_name)
2760 if (prefer_dark_theme)
2761 provider = gtk_css_provider_get_named (theme_name, "dark");
2764 provider = gtk_css_provider_get_named (theme_name, NULL);
2767 settings_update_provider (priv->screen, &priv->theme_provider, provider);
2769 if (theme_name && *theme_name)
2774 /* reload per-theme settings */
2775 theme_dir = _gtk_css_provider_get_theme_dir ();
2776 path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
2778 if (g_file_test (path, G_FILE_TEST_EXISTS))
2779 gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
2785 g_free (theme_name);
2789 settings_update_key_theme (GtkSettings *settings)
2791 GtkSettingsPrivate *priv = settings->priv;
2792 GtkCssProvider *provider = NULL;
2793 gchar *key_theme_name;
2795 g_object_get (settings,
2796 "gtk-key-theme-name", &key_theme_name,
2799 if (key_theme_name && *key_theme_name)
2800 provider = gtk_css_provider_get_named (key_theme_name, "keys");
2802 settings_update_provider (priv->screen, &priv->key_theme_provider, provider);
2803 g_free (key_theme_name);
2807 add_color_to_hash (gchar *name,
2813 old = g_hash_table_lookup (target, name);
2814 if (!old || !gdk_color_equal (old, color))
2816 g_hash_table_insert (target, g_strdup (name), gdk_color_copy (color));
2825 add_colors_to_hash_from_string (GHashTable *hash,
2826 const gchar *colors)
2828 gchar *s, *p, *name;
2830 gboolean changed = FALSE;
2833 copy = g_strdup (colors);
2838 p = strchr (s, ':');
2853 if (*s == '\n' || *s == ';')
2862 if (gdk_color_parse (p, &color))
2863 changed |= add_color_to_hash (name, &color, hash);
2872 update_color_hash (ColorSchemeData *data,
2874 GtkSettingsSource source)
2876 gboolean changed = FALSE;
2878 GHashTable *old_hash;
2879 GHashTableIter iter;
2883 if ((str == NULL || *str == '\0') &&
2884 (data->lastentry[source] == NULL || data->lastentry[source][0] == '\0'))
2887 if (str && data->lastentry[source] && strcmp (str, data->lastentry[source]) == 0)
2890 /* For the THEME source we merge the values rather than over-writing
2891 * them, since multiple rc files might define independent sets of colors
2893 if ((source != GTK_SETTINGS_SOURCE_THEME) &&
2894 data->tables[source] && g_hash_table_size (data->tables[source]) > 0)
2896 g_hash_table_unref (data->tables[source]);
2897 data->tables[source] = NULL;
2898 changed = TRUE; /* We can't rely on the code below since str might be "" */
2901 if (data->tables[source] == NULL)
2902 data->tables[source] = g_hash_table_new_full (g_str_hash, g_str_equal,
2904 (GDestroyNotify) gdk_color_free);
2906 g_free (data->lastentry[source]);
2907 data->lastentry[source] = g_strdup (str);
2909 changed |= add_colors_to_hash_from_string (data->tables[source], str);
2914 /* Rebuild the merged hash table. */
2915 if (data->color_hash)
2917 old_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2918 (GDestroyNotify) gdk_color_free);
2920 g_hash_table_iter_init (&iter, data->color_hash);
2921 while (g_hash_table_iter_next (&iter, &name, &color))
2923 g_hash_table_insert (old_hash, name, color);
2924 g_hash_table_iter_steal (&iter);
2932 for (i = 0; i <= GTK_SETTINGS_SOURCE_APPLICATION; i++)
2934 if (data->tables[i])
2935 g_hash_table_foreach (data->tables[i], (GHFunc) add_color_to_hash,
2941 /* now check if the merged hash has changed */
2943 if (g_hash_table_size (old_hash) != g_hash_table_size (data->color_hash))
2947 GHashTableIter iter;
2948 gpointer key, value, new_value;
2950 g_hash_table_iter_init (&iter, old_hash);
2951 while (g_hash_table_iter_next (&iter, &key, &value))
2953 new_value = g_hash_table_lookup (data->color_hash, key);
2954 if (!new_value || !gdk_color_equal (value, new_value))
2962 g_hash_table_unref (old_hash);
2971 merge_color_scheme (GtkSettings *settings,
2972 const GValue *value,
2973 GtkSettingsSource source)
2975 ColorSchemeData *data;
2976 const gchar *colors;
2978 g_object_freeze_notify (G_OBJECT (settings));
2980 colors = g_value_get_string (value);
2982 settings_update_color_scheme (settings);
2984 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
2985 "gtk-color-scheme");
2987 if (update_color_hash (data, colors, source))
2988 g_object_notify (G_OBJECT (settings), "color-hash");
2990 g_object_thaw_notify (G_OBJECT (settings));
2994 get_color_hash (GtkSettings *settings)
2996 ColorSchemeData *data;
2998 settings_update_color_scheme (settings);
3000 data = (ColorSchemeData *)g_object_get_data (G_OBJECT (settings),
3001 "gtk-color-scheme");
3003 return data->color_hash;
3007 append_color_scheme (gpointer key,
3011 gchar *name = (gchar *)key;
3012 GdkColor *color = (GdkColor *)value;
3013 GString *string = (GString *)data;
3015 g_string_append_printf (string, "%s: #%04x%04x%04x\n",
3016 name, color->red, color->green, color->blue);
3020 get_color_scheme (GtkSettings *settings)
3022 ColorSchemeData *data;
3025 settings_update_color_scheme (settings);
3027 data = (ColorSchemeData *) g_object_get_data (G_OBJECT (settings),
3028 "gtk-color-scheme");
3030 string = g_string_new ("");
3032 g_hash_table_foreach (data->color_hash, append_color_scheme, string);
3034 return g_string_free (string, FALSE);
3038 _gtk_settings_get_screen (GtkSettings *settings)
3040 return settings->priv->screen;
3045 gtk_settings_load_from_key_file (GtkSettings *settings,
3047 GtkSettingsSource source)
3058 keyfile = g_key_file_new ();
3060 if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
3062 g_warning ("Failed to parse %s: %s", path, error->message);
3064 g_error_free (error);
3069 keys = g_key_file_get_keys (keyfile, "Settings", &n_keys, &error);
3072 g_warning ("Failed to parse %s: %s", path, error->message);
3073 g_error_free (error);
3077 for (i = 0; i < n_keys; i++)
3082 GtkSettingsValue svalue = { NULL, { 0, }, };
3085 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (settings), key);
3088 g_warning ("Unknown key %s in %s", key, path);
3092 if (pspec->owner_type != G_OBJECT_TYPE (settings))
3095 value_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
3098 case G_TYPE_BOOLEAN:
3102 g_value_init (&svalue.value, G_TYPE_LONG);
3103 b_val = g_key_file_get_boolean (keyfile, "Settings", key, &error);
3105 g_value_set_long (&svalue.value, b_val);
3113 g_value_init (&svalue.value, G_TYPE_LONG);
3114 i_val = g_key_file_get_integer (keyfile, "Settings", key, &error);
3116 g_value_set_long (&svalue.value, i_val);
3124 g_value_init (&svalue.value, G_TYPE_DOUBLE);
3125 d_val = g_key_file_get_double (keyfile, "Settings", key, &error);
3127 g_value_set_double (&svalue.value, d_val);
3135 g_value_init (&svalue.value, G_TYPE_GSTRING);
3136 s_val = g_key_file_get_string (keyfile, "Settings", key, &error);
3138 g_value_take_boxed (&svalue.value, g_string_new (s_val));
3145 g_warning ("Error setting %s in %s: %s", key, path, error->message);
3146 g_error_free (error);
3151 if (g_getenv ("GTK_DEBUG"))
3152 svalue.origin = (gchar *)path;
3153 gtk_settings_set_property_value_internal (settings, key, &svalue, source);
3154 g_value_unset (&svalue.value);
3160 g_key_file_free (keyfile);