Settings

Settings — Sharing settings between applications

Functions

Types and Values

Includes

#include <gtk/gtk.h>

Description

GtkSettings provide a mechanism to share global settings between applications.

On the X window system, this sharing is realized by an XSettings manager that is usually part of the desktop environment, along with utilities that let the user change these settings. In the absence of an Xsettings manager, GTK+ reads default values for settings from settings.ini files in /etc/gtk-4.0, $XDG_CONFIG_DIRS/gtk-4.0 and $XDG_CONFIG_HOME/gtk-4.0. These files must be valid key files (see GKeyFile), and have a section called Settings. Themes can also provide default values for settings by installing a settings.ini file next to their gtk.css file.

Applications can override system-wide settings by setting the property of the GtkSettings object with g_object_set(). This should be restricted to special cases though; GtkSettings are not meant as an application configuration facility. When doing so, you need to be aware that settings that are specific to individual widgets may not be available before the widget type has been realized at least once. The following example demonstrates a way to do this:

1
2
3
4
5
6
gtk_init (&argc, &argv);

// make sure the type is realized
g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));

g_object_set (gtk_settings_get_default (), "gtk-enable-animations", FALSE, NULL);

There is one GtkSettings instance per screen. It can be obtained with gtk_settings_get_for_screen(), but in many cases, it is more convenient to use gtk_widget_get_settings(). gtk_settings_get_default() returns the GtkSettings instance for the default screen.

Functions

gtk_settings_get_default ()

GtkSettings *
gtk_settings_get_default (void);

Gets the GtkSettings object for the default GDK screen, creating it if necessary. See gtk_settings_get_for_screen().

Returns

a GtkSettings object. If there is no default screen, then returns NULL.

[nullable][transfer none]


gtk_settings_get_for_screen ()

GtkSettings *
gtk_settings_get_for_screen (GdkScreen *screen);

Gets the GtkSettings object for screen , creating it if necessary.

Parameters

screen

a GdkScreen.

 

Returns

a GtkSettings object.

[transfer none]

Since: 2.2


gtk_rc_property_parse_color ()

gboolean
gtk_rc_property_parse_color (const GParamSpec *pspec,
                             const GString *gstring,
                             GValue *property_value);

gtk_rc_property_parse_enum ()

gboolean
gtk_rc_property_parse_enum (const GParamSpec *pspec,
                            const GString *gstring,
                            GValue *property_value);

A GtkRcPropertyParser for use with gtk_settings_install_property_parser() or gtk_widget_class_install_style_property_parser() which parses a single enumeration value.

The enumeration value can be specified by its name, its nickname or its numeric value. For consistency with flags parsing, the value may be surrounded by parentheses.

Parameters

pspec

a GParamSpec

 

gstring

the GString to be parsed

 

property_value

a GValue which must hold enum values.

 

Returns

TRUE if gstring could be parsed and property_value has been set to the resulting GEnumValue.


gtk_rc_property_parse_flags ()

gboolean
gtk_rc_property_parse_flags (const GParamSpec *pspec,
                             const GString *gstring,
                             GValue *property_value);

A GtkRcPropertyParser for use with gtk_settings_install_property_parser() or gtk_widget_class_install_style_property_parser() which parses flags.

Flags can be specified by their name, their nickname or numerically. Multiple flags can be specified in the form "( flag1 | flag2 | ... )".

Parameters

pspec

a GParamSpec

 

gstring

the GString to be parsed

 

property_value

a GValue which must hold flags values.

 

Returns

TRUE if gstring could be parsed and property_value has been set to the resulting flags value.


gtk_rc_property_parse_requisition ()

gboolean
gtk_rc_property_parse_requisition (const GParamSpec *pspec,
                                   const GString *gstring,
                                   GValue *property_value);

A GtkRcPropertyParser for use with gtk_settings_install_property_parser() or gtk_widget_class_install_style_property_parser() which parses a requisition in the form "{ width, height }" for integers width and height.

Parameters

pspec

a GParamSpec

 

gstring

the GString to be parsed

 

property_value

a GValue which must hold boxed values.

 

Returns

TRUE if gstring could be parsed and property_value has been set to the resulting GtkRequisition.


gtk_rc_property_parse_border ()

gboolean
gtk_rc_property_parse_border (const GParamSpec *pspec,
                              const GString *gstring,
                              GValue *property_value);

A GtkRcPropertyParser for use with gtk_settings_install_property_parser() or gtk_widget_class_install_style_property_parser() which parses borders in the form "{ left, right, top, bottom }" for integers left, right, top and bottom.

Parameters

pspec

a GParamSpec

 

gstring

the GString to be parsed

 

property_value

a GValue which must hold boxed values.

 

Returns

TRUE if gstring could be parsed and property_value has been set to the resulting GtkBorder.


gtk_settings_reset_property ()

void
gtk_settings_reset_property (GtkSettings *settings,
                             const gchar *name);

Undoes the effect of calling g_object_set() to install an application-specific value for a setting. After this call, the setting will again follow the session-wide value for this setting.

Parameters

settings

a GtkSettings object

 

name

the name of the setting to reset

 

Since: 3.20

Types and Values

GtkSettings

typedef struct {
  GObject parent_instance;
} GtkSettings;

struct GtkSettingsValue

struct GtkSettingsValue {
  /* origin should be something like "filename:linenumber" for rc files,
   * or e.g. "XProperty" for other sources
   */
  gchar *origin;

  /* valid types are LONG, DOUBLE and STRING corresponding to the token parsed,
   * or a GSTRING holding an unparsed statement
   */
  GValue value;
};

Members

gchar *origin;

Origin should be something like “filename:linenumber” for rc files, or e.g. “XProperty” for other sources.

 

GValue value;

Valid types are LONG, DOUBLE and STRING corresponding to the token parsed, or a GSTRING holding an unparsed statement