diff options
| author | Jan Djärv | 2011-07-01 11:18:46 +0200 |
|---|---|---|
| committer | Jan Djärv | 2011-07-01 11:18:46 +0200 |
| commit | 0949d2b6ba1027bce991b2f3f7a4ce92b7adf620 (patch) | |
| tree | 8b84e14d700f5d399ae49f69f7b2fe57dcd808de /src/xsettings.c | |
| parent | 36b148cf16f468ffb7731c0f1e0c49ceb8a7deb0 (diff) | |
| download | emacs-0949d2b6ba1027bce991b2f3f7a4ce92b7adf620.tar.gz emacs-0949d2b6ba1027bce991b2f3f7a4ce92b7adf620.zip | |
* process.c: Add defined (HAVE_GSETTINGS) for xgselect.h
(wait_reading_process_output): Add defined (HAVE_GSETTINGS) for
xg_select.
* xgselect.c: Add defined (HAVE_GSETTINGS).
(xgselect_initialize): Ditto.
* xsettings.c (store_monospaced_changed): Take new font as arg and
check for change against current_mono_font.
(EMACS_TYPE_SETTINGS): Remove this and related defines.
(emacs_settings_constructor, emacs_settings_get_property)
(emacs_settings_set_property, emacs_settings_class_init)
(emacs_settings_init, gsettings_obj): Remove.
(something_changedCB): New function for HAVE_GSETTINGS.
(something_changedCB): HAVE_GCONF: Call store_monospaced_changed
with value as argument.
(init_gsettings): Check that GSETTINGS_SCHEMA exists before calling
g_settings_new. Do not create gsettings_obj.
Remove calls to g_settings_bind. Connect something_changedCB to
"changed".
Fixes: debbugs:8967
Diffstat (limited to 'src/xsettings.c')
| -rw-r--r-- | src/xsettings.c | 189 |
1 files changed, 41 insertions, 148 deletions
diff --git a/src/xsettings.c b/src/xsettings.c index 5df05e3e50e..4162912f2c1 100644 --- a/src/xsettings.c +++ b/src/xsettings.c | |||
| @@ -66,9 +66,15 @@ store_config_changed_event (Lisp_Object arg, Lisp_Object display_name) | |||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | static void | 68 | static void |
| 69 | store_monospaced_changed (void) | 69 | store_monospaced_changed (const char *newfont) |
| 70 | { | 70 | { |
| 71 | if (first_dpyinfo != NULL) | 71 | if (current_mono_font != NULL && strcmp (newfont, current_mono_font) == 0) |
| 72 | return; /* No change. */ | ||
| 73 | |||
| 74 | xfree (current_mono_font); | ||
| 75 | current_mono_font = xstrdup (newfont); | ||
| 76 | |||
| 77 | if (first_dpyinfo != NULL && use_system_font) | ||
| 72 | { | 78 | { |
| 73 | /* Check if display still open */ | 79 | /* Check if display still open */ |
| 74 | struct x_display_info *dpyinfo; | 80 | struct x_display_info *dpyinfo; |
| @@ -76,7 +82,7 @@ store_monospaced_changed (void) | |||
| 76 | for (dpyinfo = x_display_list; !found && dpyinfo; dpyinfo = dpyinfo->next) | 82 | for (dpyinfo = x_display_list; !found && dpyinfo; dpyinfo = dpyinfo->next) |
| 77 | found = dpyinfo == first_dpyinfo; | 83 | found = dpyinfo == first_dpyinfo; |
| 78 | 84 | ||
| 79 | if (found && use_system_font) | 85 | if (found) |
| 80 | store_config_changed_event (Qmonospace_font_name, | 86 | store_config_changed_event (Qmonospace_font_name, |
| 81 | XCAR (first_dpyinfo->name_list_element)); | 87 | XCAR (first_dpyinfo->name_list_element)); |
| 82 | } | 88 | } |
| @@ -84,133 +90,7 @@ store_monospaced_changed (void) | |||
| 84 | 90 | ||
| 85 | 91 | ||
| 86 | #ifdef HAVE_GSETTINGS | 92 | #ifdef HAVE_GSETTINGS |
| 87 | |||
| 88 | #define EMACS_TYPE_SETTINGS (emacs_settings_get_type ()) | ||
| 89 | #define EMACS_SETTINGS(obj) \ | ||
| 90 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMACS_TYPE_SETTINGS, EmacsSettings)) | ||
| 91 | #define EMACS_IS_SETTINGS(obj) \ | ||
| 92 | (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMACS_TYPE_SETTINGS)) | ||
| 93 | #define EMACS_SETTINGS_CLASS(klass) \ | ||
| 94 | (G_TYPE_CHECK_CLASS_CAST ((klass), EMACS_TYPE_SETTINGS, EmacsSettingsClass)) | ||
| 95 | #define EMACS_IS_SETTINGS_CLASS(klass) \ | ||
| 96 | (G_TYPE_CHECK_CLASS_TYPE ((klass), EMACS_TYPE_SETTINGS)) | ||
| 97 | #define EMACS_SETTINGS_GET_CLASS(obj) \ | ||
| 98 | (G_TYPE_INSTANCE_GET_CLASS ((obj), EMACS_TYPE_SETTINGS, EmacsSettingsClass)) | ||
| 99 | |||
| 100 | typedef struct _EmacsSettings EmacsSettings; | ||
| 101 | typedef struct _EmacsSettingsClass EmacsSettingsClass; | ||
| 102 | |||
| 103 | struct _EmacsSettings | ||
| 104 | { | ||
| 105 | GObject parent_instance; | ||
| 106 | }; | ||
| 107 | |||
| 108 | struct _EmacsSettingsClass | ||
| 109 | { | ||
| 110 | GObjectClass parent_class; | ||
| 111 | }; | ||
| 112 | |||
| 113 | /* will create emacs_settings_get_type and set emacs_settings_parent_class */ | ||
| 114 | G_DEFINE_TYPE (EmacsSettings, emacs_settings, G_TYPE_OBJECT); | ||
| 115 | |||
| 116 | static GObject * | ||
| 117 | emacs_settings_constructor (GType gtype, | ||
| 118 | guint n_properties, | ||
| 119 | GObjectConstructParam *properties) | ||
| 120 | { | ||
| 121 | GObject *obj; | ||
| 122 | |||
| 123 | /* Always chain up to the parent constructor */ | ||
| 124 | obj = G_OBJECT_CLASS (emacs_settings_parent_class) | ||
| 125 | ->constructor (gtype, n_properties, properties); | ||
| 126 | |||
| 127 | /* update the object state depending on constructor properties */ | ||
| 128 | |||
| 129 | return obj; | ||
| 130 | } | ||
| 131 | |||
| 132 | enum { PROP_MONO = 1, PROP_FONT }; | ||
| 133 | |||
| 134 | static void | ||
| 135 | emacs_settings_get_property (GObject *object, | ||
| 136 | guint property_id, | ||
| 137 | GValue *value, | ||
| 138 | GParamSpec *pspec) | ||
| 139 | { | ||
| 140 | switch (property_id) | ||
| 141 | { | ||
| 142 | case PROP_MONO: | ||
| 143 | g_value_set_string (value, current_mono_font); | ||
| 144 | break; | ||
| 145 | case PROP_FONT: | ||
| 146 | g_value_set_string (value, current_font); | ||
| 147 | break; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | static void | ||
| 152 | emacs_settings_set_property (GObject *object, | ||
| 153 | guint property_id, | ||
| 154 | const GValue *value, | ||
| 155 | GParamSpec *pspec) | ||
| 156 | { | ||
| 157 | const char *newfont; | ||
| 158 | switch (property_id) | ||
| 159 | { | ||
| 160 | case PROP_MONO: | ||
| 161 | xfree (current_mono_font); | ||
| 162 | newfont = g_value_get_string (value); | ||
| 163 | if (current_mono_font != NULL && strcmp (newfont, current_mono_font) == 0) | ||
| 164 | return; /* No change. */ | ||
| 165 | |||
| 166 | current_mono_font = xstrdup (newfont); | ||
| 167 | store_monospaced_changed (); | ||
| 168 | break; | ||
| 169 | |||
| 170 | case PROP_FONT: | ||
| 171 | xfree (current_font); | ||
| 172 | current_font = xstrdup (g_value_get_string (value)); | ||
| 173 | break; | ||
| 174 | } | ||
| 175 | } | ||
| 176 | |||
| 177 | static void | ||
| 178 | emacs_settings_class_init (EmacsSettingsClass *klass) | ||
| 179 | { | ||
| 180 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | ||
| 181 | |||
| 182 | gobject_class->constructor = emacs_settings_constructor; | ||
| 183 | gobject_class->set_property = emacs_settings_set_property; | ||
| 184 | gobject_class->get_property = emacs_settings_get_property; | ||
| 185 | |||
| 186 | g_object_class_install_property | ||
| 187 | (gobject_class, | ||
| 188 | PROP_MONO, | ||
| 189 | g_param_spec_string ("monospace-font", | ||
| 190 | "Monospace-font", | ||
| 191 | "System monospace font", | ||
| 192 | "", | ||
| 193 | G_PARAM_READWRITE)); | ||
| 194 | g_object_class_install_property | ||
| 195 | (gobject_class, | ||
| 196 | PROP_FONT, | ||
| 197 | g_param_spec_string ("font", | ||
| 198 | "Font", | ||
| 199 | "System font", | ||
| 200 | "", | ||
| 201 | G_PARAM_READWRITE)); | ||
| 202 | |||
| 203 | } | ||
| 204 | |||
| 205 | static void | ||
| 206 | emacs_settings_init (EmacsSettings *self) | ||
| 207 | { | ||
| 208 | } | ||
| 209 | |||
| 210 | |||
| 211 | static GSettings *gsettings_client; | 93 | static GSettings *gsettings_client; |
| 212 | static EmacsSettings *gsettings_obj; | ||
| 213 | |||
| 214 | #else | 94 | #else |
| 215 | #ifdef HAVE_GCONF | 95 | #ifdef HAVE_GCONF |
| 216 | static GConfClient *gconf_client; | 96 | static GConfClient *gconf_client; |
| @@ -250,6 +130,26 @@ struct xsettings | |||
| 250 | #define SYSTEM_MONO_FONT "monospace-font-name" | 130 | #define SYSTEM_MONO_FONT "monospace-font-name" |
| 251 | #define SYSTEM_FONT "font-name" | 131 | #define SYSTEM_FONT "font-name" |
| 252 | 132 | ||
| 133 | static void | ||
| 134 | something_changedCB (GSettings *settings, | ||
| 135 | gchar *key, | ||
| 136 | gpointer user_data) | ||
| 137 | { | ||
| 138 | GVariant *val; | ||
| 139 | if (strcmp (key, SYSTEM_MONO_FONT) != 0) return; | ||
| 140 | val = g_settings_get_value (settings, SYSTEM_MONO_FONT); | ||
| 141 | if (val) | ||
| 142 | { | ||
| 143 | g_variant_ref_sink (val); | ||
| 144 | if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) | ||
| 145 | { | ||
| 146 | const gchar *newfont = g_variant_get_string (val, NULL); | ||
| 147 | store_monospaced_changed (newfont); | ||
| 148 | } | ||
| 149 | g_variant_unref (val); | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 253 | #else | 153 | #else |
| 254 | #ifdef HAVE_GCONF | 154 | #ifdef HAVE_GCONF |
| 255 | #define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name" | 155 | #define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name" |
| @@ -270,12 +170,7 @@ something_changedCB (GConfClient *client, | |||
| 270 | if (v->type == GCONF_VALUE_STRING) | 170 | if (v->type == GCONF_VALUE_STRING) |
| 271 | { | 171 | { |
| 272 | const char *value = gconf_value_get_string (v); | 172 | const char *value = gconf_value_get_string (v); |
| 273 | if (current_mono_font != NULL && strcmp (value, current_mono_font) == 0) | 173 | store_monospaced_changed (value); |
| 274 | return; /* No change. */ | ||
| 275 | |||
| 276 | xfree (current_mono_font); | ||
| 277 | current_mono_font = xstrdup (value); | ||
| 278 | store_monospaced_changed (); | ||
| 279 | } | 174 | } |
| 280 | } | 175 | } |
| 281 | 176 | ||
| @@ -784,22 +679,23 @@ init_gsettings (void) | |||
| 784 | { | 679 | { |
| 785 | #ifdef HAVE_GSETTINGS | 680 | #ifdef HAVE_GSETTINGS |
| 786 | GVariant *val; | 681 | GVariant *val; |
| 682 | const gchar *const *schemas; | ||
| 683 | int schema_found = 0; | ||
| 684 | |||
| 787 | #ifdef HAVE_G_TYPE_INIT | 685 | #ifdef HAVE_G_TYPE_INIT |
| 788 | g_type_init (); | 686 | g_type_init (); |
| 789 | #endif | 687 | #endif |
| 790 | 688 | ||
| 689 | schemas = g_settings_list_schemas(); | ||
| 690 | if (schemas == NULL) return; | ||
| 691 | while (! schema_found && *schemas != NULL) | ||
| 692 | schema_found = strcmp (*schemas++, GSETTINGS_SCHEMA) == 0; | ||
| 693 | if (!schema_found) return; | ||
| 694 | |||
| 791 | gsettings_client = g_settings_new (GSETTINGS_SCHEMA); | 695 | gsettings_client = g_settings_new (GSETTINGS_SCHEMA); |
| 792 | if (!gsettings_client) return; | 696 | if (!gsettings_client) return; |
| 793 | g_object_ref_sink (G_OBJECT (gsettings_client)); | 697 | g_object_ref_sink (G_OBJECT (gsettings_client)); |
| 794 | 698 | ||
| 795 | gsettings_obj = g_object_new (EMACS_TYPE_SETTINGS, NULL); | ||
| 796 | if (!gsettings_obj) | ||
| 797 | { | ||
| 798 | g_object_unref (G_OBJECT (gsettings_client)); | ||
| 799 | return; | ||
| 800 | } | ||
| 801 | g_object_ref_sink (G_OBJECT (gsettings_obj)); | ||
| 802 | |||
| 803 | val = g_settings_get_value (gsettings_client, SYSTEM_MONO_FONT); | 699 | val = g_settings_get_value (gsettings_client, SYSTEM_MONO_FONT); |
| 804 | if (val) | 700 | if (val) |
| 805 | { | 701 | { |
| @@ -809,10 +705,8 @@ init_gsettings (void) | |||
| 809 | g_variant_unref (val); | 705 | g_variant_unref (val); |
| 810 | } | 706 | } |
| 811 | 707 | ||
| 812 | g_settings_bind (gsettings_client, SYSTEM_MONO_FONT, gsettings_obj, | 708 | g_signal_connect (G_OBJECT (gsettings_client), "changed", |
| 813 | "monospace-font", G_SETTINGS_BIND_GET); | 709 | G_CALLBACK (something_changedCB), NULL); |
| 814 | g_settings_bind (gsettings_client, SYSTEM_FONT, gsettings_obj, | ||
| 815 | "font", G_SETTINGS_BIND_GET); | ||
| 816 | #endif /* HAVE_GSETTINGS */ | 710 | #endif /* HAVE_GSETTINGS */ |
| 817 | } | 711 | } |
| 818 | 712 | ||
| @@ -935,7 +829,6 @@ syms_of_xsettings (void) | |||
| 935 | first_dpyinfo = NULL; | 829 | first_dpyinfo = NULL; |
| 936 | #ifdef HAVE_GSETTINGS | 830 | #ifdef HAVE_GSETTINGS |
| 937 | gsettings_client = NULL; | 831 | gsettings_client = NULL; |
| 938 | gsettings_obj = NULL; | ||
| 939 | #else | 832 | #else |
| 940 | #ifdef HAVE_GCONF | 833 | #ifdef HAVE_GCONF |
| 941 | gconf_client = NULL; | 834 | gconf_client = NULL; |