diff options
Diffstat (limited to 'src/xsettings.c')
| -rw-r--r-- | src/xsettings.c | 419 |
1 files changed, 343 insertions, 76 deletions
diff --git a/src/xsettings.c b/src/xsettings.c index 5412cf426f8..dadbe68b4cb 100644 --- a/src/xsettings.c +++ b/src/xsettings.c | |||
| @@ -34,9 +34,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 34 | 34 | ||
| 35 | #include <X11/Xproto.h> | 35 | #include <X11/Xproto.h> |
| 36 | 36 | ||
| 37 | #ifdef HAVE_GSETTINGS | ||
| 38 | #include <glib-object.h> | ||
| 39 | #include <gio/gio.h> | ||
| 40 | #endif | ||
| 41 | |||
| 37 | #ifdef HAVE_GCONF | 42 | #ifdef HAVE_GCONF |
| 38 | #include <gconf/gconf-client.h> | 43 | #include <gconf/gconf-client.h> |
| 39 | #endif | 44 | #endif |
| 45 | |||
| 40 | #ifdef HAVE_XFT | 46 | #ifdef HAVE_XFT |
| 41 | #include <X11/Xft/Xft.h> | 47 | #include <X11/Xft/Xft.h> |
| 42 | #endif | 48 | #endif |
| @@ -48,10 +54,7 @@ static Lisp_Object Qmonospace_font_name, Qfont_name, Qfont_render, | |||
| 48 | Qtool_bar_style; | 54 | Qtool_bar_style; |
| 49 | static Lisp_Object current_tool_bar_style; | 55 | static Lisp_Object current_tool_bar_style; |
| 50 | 56 | ||
| 51 | #ifdef HAVE_GCONF | 57 | /* Store an config changed event in to the event queue. */ |
| 52 | static GConfClient *gconf_client; | ||
| 53 | #endif | ||
| 54 | |||
| 55 | 58 | ||
| 56 | static void | 59 | static void |
| 57 | store_config_changed_event (Lisp_Object arg, Lisp_Object display_name) | 60 | store_config_changed_event (Lisp_Object arg, Lisp_Object display_name) |
| @@ -64,6 +67,99 @@ store_config_changed_event (Lisp_Object arg, Lisp_Object display_name) | |||
| 64 | kbd_buffer_store_event (&event); | 67 | kbd_buffer_store_event (&event); |
| 65 | } | 68 | } |
| 66 | 69 | ||
| 70 | /* Return non-zero if DPYINFO is still valid. */ | ||
| 71 | static int | ||
| 72 | dpyinfo_valid (struct x_display_info *dpyinfo) | ||
| 73 | { | ||
| 74 | int found = 0; | ||
| 75 | if (dpyinfo != NULL) | ||
| 76 | { | ||
| 77 | struct x_display_info *d; | ||
| 78 | for (d = x_display_list; !found && d; d = d->next) | ||
| 79 | found = d == dpyinfo && d->display == dpyinfo->display; | ||
| 80 | } | ||
| 81 | return found; | ||
| 82 | } | ||
| 83 | |||
| 84 | /* Store a monospace font change event if the monospaced font changed. */ | ||
| 85 | |||
| 86 | #if defined HAVE_XFT && (defined HAVE_GSETTINGS || defined HAVE_GCONF) | ||
| 87 | static void | ||
| 88 | store_monospaced_changed (const char *newfont) | ||
| 89 | { | ||
| 90 | if (current_mono_font != NULL && strcmp (newfont, current_mono_font) == 0) | ||
| 91 | return; /* No change. */ | ||
| 92 | |||
| 93 | xfree (current_mono_font); | ||
| 94 | current_mono_font = xstrdup (newfont); | ||
| 95 | |||
| 96 | if (dpyinfo_valid (first_dpyinfo) && use_system_font) | ||
| 97 | { | ||
| 98 | store_config_changed_event (Qmonospace_font_name, | ||
| 99 | XCAR (first_dpyinfo->name_list_element)); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | #endif | ||
| 103 | |||
| 104 | /* Store a font name change event if the font name changed. */ | ||
| 105 | |||
| 106 | #ifdef HAVE_XFT | ||
| 107 | static void | ||
| 108 | store_font_name_changed (const char *newfont) | ||
| 109 | { | ||
| 110 | if (current_font != NULL && strcmp (newfont, current_font) == 0) | ||
| 111 | return; /* No change. */ | ||
| 112 | |||
| 113 | xfree (current_font); | ||
| 114 | current_font = xstrdup (newfont); | ||
| 115 | |||
| 116 | if (dpyinfo_valid (first_dpyinfo)) | ||
| 117 | { | ||
| 118 | store_config_changed_event (Qfont_name, | ||
| 119 | XCAR (first_dpyinfo->name_list_element)); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | #endif /* HAVE_XFT */ | ||
| 123 | |||
| 124 | /* Map TOOL_BAR_STYLE from a string to its correspinding Lisp value. | ||
| 125 | Return Qnil if TOOL_BAR_STYLE is not known. */ | ||
| 126 | |||
| 127 | static Lisp_Object | ||
| 128 | map_tool_bar_style (const char *tool_bar_style) | ||
| 129 | { | ||
| 130 | Lisp_Object style = Qnil; | ||
| 131 | if (tool_bar_style) | ||
| 132 | { | ||
| 133 | if (strcmp (tool_bar_style, "both") == 0) | ||
| 134 | style = Qboth; | ||
| 135 | else if (strcmp (tool_bar_style, "both-horiz") == 0) | ||
| 136 | style = Qboth_horiz; | ||
| 137 | else if (strcmp (tool_bar_style, "icons") == 0) | ||
| 138 | style = Qimage; | ||
| 139 | else if (strcmp (tool_bar_style, "text") == 0) | ||
| 140 | style = Qtext; | ||
| 141 | } | ||
| 142 | |||
| 143 | return style; | ||
| 144 | } | ||
| 145 | |||
| 146 | /* Store a tool bar style change event if the tool bar style changed. */ | ||
| 147 | |||
| 148 | static void | ||
| 149 | store_tool_bar_style_changed (const char *newstyle, | ||
| 150 | struct x_display_info *dpyinfo) | ||
| 151 | { | ||
| 152 | Lisp_Object style = map_tool_bar_style (newstyle); | ||
| 153 | if (EQ (current_tool_bar_style, style)) | ||
| 154 | return; /* No change. */ | ||
| 155 | |||
| 156 | current_tool_bar_style = style; | ||
| 157 | if (dpyinfo_valid (dpyinfo)) | ||
| 158 | store_config_changed_event (Qtool_bar_style, | ||
| 159 | XCAR (dpyinfo->name_list_element)); | ||
| 160 | } | ||
| 161 | |||
| 162 | |||
| 67 | #define XSETTINGS_FONT_NAME "Gtk/FontName" | 163 | #define XSETTINGS_FONT_NAME "Gtk/FontName" |
| 68 | #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle" | 164 | #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle" |
| 69 | 165 | ||
| @@ -83,55 +179,128 @@ struct xsettings | |||
| 83 | FcBool aa, hinting; | 179 | FcBool aa, hinting; |
| 84 | int rgba, lcdfilter, hintstyle; | 180 | int rgba, lcdfilter, hintstyle; |
| 85 | double dpi; | 181 | double dpi; |
| 86 | #endif | ||
| 87 | 182 | ||
| 88 | char *font; | 183 | char *font; |
| 184 | #endif | ||
| 185 | |||
| 89 | char *tb_style; | 186 | char *tb_style; |
| 90 | 187 | ||
| 91 | unsigned seen; | 188 | unsigned seen; |
| 92 | }; | 189 | }; |
| 93 | 190 | ||
| 191 | #ifdef HAVE_GSETTINGS | ||
| 192 | #define GSETTINGS_SCHEMA "org.gnome.desktop.interface" | ||
| 193 | #define GSETTINGS_TOOL_BAR_STYLE "toolbar-style" | ||
| 194 | |||
| 195 | #ifdef HAVE_XFT | ||
| 196 | #define GSETTINGS_MONO_FONT "monospace-font-name" | ||
| 197 | #define GSETTINGS_FONT_NAME "font-name" | ||
| 198 | #endif | ||
| 199 | |||
| 200 | |||
| 201 | /* The single GSettings instance, or NULL if not connected to GSettings. */ | ||
| 202 | |||
| 203 | static GSettings *gsettings_client; | ||
| 204 | |||
| 205 | /* Callback called when something changed in GSettings. */ | ||
| 206 | |||
| 207 | static void | ||
| 208 | something_changed_gsettingsCB (GSettings *settings, | ||
| 209 | gchar *key, | ||
| 210 | gpointer user_data) | ||
| 211 | { | ||
| 212 | GVariant *val; | ||
| 213 | |||
| 214 | if (strcmp (key, GSETTINGS_TOOL_BAR_STYLE) == 0) | ||
| 215 | { | ||
| 216 | val = g_settings_get_value (settings, GSETTINGS_TOOL_BAR_STYLE); | ||
| 217 | if (val) | ||
| 218 | { | ||
| 219 | g_variant_ref_sink (val); | ||
| 220 | if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) | ||
| 221 | { | ||
| 222 | const gchar *newstyle = g_variant_get_string (val, NULL); | ||
| 223 | store_tool_bar_style_changed (newstyle, first_dpyinfo); | ||
| 224 | } | ||
| 225 | g_variant_unref (val); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | #ifdef HAVE_XFT | ||
| 229 | else if (strcmp (key, GSETTINGS_MONO_FONT) == 0) | ||
| 230 | { | ||
| 231 | val = g_settings_get_value (settings, GSETTINGS_MONO_FONT); | ||
| 232 | if (val) | ||
| 233 | { | ||
| 234 | g_variant_ref_sink (val); | ||
| 235 | if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) | ||
| 236 | { | ||
| 237 | const gchar *newfont = g_variant_get_string (val, NULL); | ||
| 238 | store_monospaced_changed (newfont); | ||
| 239 | } | ||
| 240 | g_variant_unref (val); | ||
| 241 | } | ||
| 242 | } | ||
| 243 | else if (strcmp (key, GSETTINGS_FONT_NAME) == 0) | ||
| 244 | { | ||
| 245 | val = g_settings_get_value (settings, GSETTINGS_FONT_NAME); | ||
| 246 | if (val) | ||
| 247 | { | ||
| 248 | g_variant_ref_sink (val); | ||
| 249 | if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) | ||
| 250 | { | ||
| 251 | const gchar *newfont = g_variant_get_string (val, NULL); | ||
| 252 | store_font_name_changed (newfont); | ||
| 253 | } | ||
| 254 | g_variant_unref (val); | ||
| 255 | } | ||
| 256 | } | ||
| 257 | #endif /* HAVE_XFT */ | ||
| 258 | } | ||
| 259 | |||
| 260 | #endif /* HAVE_GSETTINGS */ | ||
| 261 | |||
| 94 | #ifdef HAVE_GCONF | 262 | #ifdef HAVE_GCONF |
| 263 | #define GCONF_TOOL_BAR_STYLE "/desktop/gnome/interface/toolbar_style" | ||
| 264 | #ifdef HAVE_XFT | ||
| 265 | #define GCONF_MONO_FONT "/desktop/gnome/interface/monospace_font_name" | ||
| 266 | #define GCONF_FONT_NAME "/desktop/gnome/interface/font_name" | ||
| 267 | #endif | ||
| 95 | 268 | ||
| 96 | #define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name" | 269 | /* The single GConf instance, or NULL if not connected to GConf. */ |
| 97 | #define SYSTEM_FONT "/desktop/gnome/interface/font_name" | 270 | |
| 271 | static GConfClient *gconf_client; | ||
| 98 | 272 | ||
| 99 | /* Callback called when something changed in GConf that we care about, | 273 | /* Callback called when something changed in GConf that we care about. */ |
| 100 | that is SYSTEM_MONO_FONT. */ | ||
| 101 | 274 | ||
| 102 | static void | 275 | static void |
| 103 | something_changedCB (GConfClient *client, | 276 | something_changed_gconfCB (GConfClient *client, |
| 104 | guint cnxn_id, | 277 | guint cnxn_id, |
| 105 | GConfEntry *entry, | 278 | GConfEntry *entry, |
| 106 | gpointer user_data) | 279 | gpointer user_data) |
| 107 | { | 280 | { |
| 108 | GConfValue *v = gconf_entry_get_value (entry); | 281 | GConfValue *v = gconf_entry_get_value (entry); |
| 282 | const char *key = gconf_entry_get_key (entry); | ||
| 109 | 283 | ||
| 110 | if (!v) return; | 284 | if (!v || v->type != GCONF_VALUE_STRING || ! key) return; |
| 111 | if (v->type == GCONF_VALUE_STRING) | 285 | if (strcmp (key, GCONF_TOOL_BAR_STYLE) == 0) |
| 112 | { | 286 | { |
| 113 | const char *value = gconf_value_get_string (v); | 287 | const char *value = gconf_value_get_string (v); |
| 114 | if (current_mono_font != NULL && strcmp (value, current_mono_font) == 0) | 288 | store_tool_bar_style_changed (value, first_dpyinfo); |
| 115 | return; /* No change. */ | ||
| 116 | |||
| 117 | xfree (current_mono_font); | ||
| 118 | current_mono_font = xstrdup (value); | ||
| 119 | } | 289 | } |
| 120 | 290 | #ifdef HAVE_XFT | |
| 121 | 291 | else if (strcmp (key, GCONF_MONO_FONT) == 0) | |
| 122 | if (first_dpyinfo != NULL) | 292 | { |
| 293 | const char *value = gconf_value_get_string (v); | ||
| 294 | store_monospaced_changed (value); | ||
| 295 | } | ||
| 296 | else if (strcmp (key, GCONF_FONT_NAME) == 0) | ||
| 123 | { | 297 | { |
| 124 | /* Check if display still open */ | 298 | const char *value = gconf_value_get_string (v); |
| 125 | struct x_display_info *dpyinfo; | 299 | store_font_name_changed (value); |
| 126 | int found = 0; | ||
| 127 | for (dpyinfo = x_display_list; !found && dpyinfo; dpyinfo = dpyinfo->next) | ||
| 128 | found = dpyinfo == first_dpyinfo; | ||
| 129 | |||
| 130 | if (found && use_system_font) | ||
| 131 | store_config_changed_event (Qmonospace_font_name, | ||
| 132 | XCAR (first_dpyinfo->name_list_element)); | ||
| 133 | } | 300 | } |
| 301 | #endif /* HAVE_XFT */ | ||
| 134 | } | 302 | } |
| 303 | |||
| 135 | #endif /* HAVE_GCONF */ | 304 | #endif /* HAVE_GCONF */ |
| 136 | 305 | ||
| 137 | #ifdef HAVE_XFT | 306 | #ifdef HAVE_XFT |
| @@ -277,10 +446,10 @@ parse_settings (unsigned char *prop, | |||
| 277 | want_this = | 446 | want_this = |
| 278 | #ifdef HAVE_XFT | 447 | #ifdef HAVE_XFT |
| 279 | (nlen > 6 && strncmp (name, "Xft/", 4) == 0) | 448 | (nlen > 6 && strncmp (name, "Xft/", 4) == 0) |
| 449 | || strcmp (XSETTINGS_FONT_NAME, name) == 0 | ||
| 280 | || | 450 | || |
| 281 | #endif | 451 | #endif |
| 282 | (strcmp (XSETTINGS_FONT_NAME, name) == 0) | 452 | strcmp (XSETTINGS_TOOL_BAR_STYLE, name) == 0; |
| 283 | || (strcmp (XSETTINGS_TOOL_BAR_STYLE, name) == 0); | ||
| 284 | 453 | ||
| 285 | switch (type) | 454 | switch (type) |
| 286 | { | 455 | { |
| @@ -322,17 +491,17 @@ parse_settings (unsigned char *prop, | |||
| 322 | if (want_this) | 491 | if (want_this) |
| 323 | { | 492 | { |
| 324 | ++settings_seen; | 493 | ++settings_seen; |
| 325 | if (strcmp (name, XSETTINGS_FONT_NAME) == 0) | 494 | if (strcmp (name, XSETTINGS_TOOL_BAR_STYLE) == 0) |
| 326 | { | ||
| 327 | settings->font = xstrdup (sval); | ||
| 328 | settings->seen |= SEEN_FONT; | ||
| 329 | } | ||
| 330 | else if (strcmp (name, XSETTINGS_TOOL_BAR_STYLE) == 0) | ||
| 331 | { | 495 | { |
| 332 | settings->tb_style = xstrdup (sval); | 496 | settings->tb_style = xstrdup (sval); |
| 333 | settings->seen |= SEEN_TB_STYLE; | 497 | settings->seen |= SEEN_TB_STYLE; |
| 334 | } | 498 | } |
| 335 | #ifdef HAVE_XFT | 499 | #ifdef HAVE_XFT |
| 500 | else if (strcmp (name, XSETTINGS_FONT_NAME) == 0) | ||
| 501 | { | ||
| 502 | settings->font = xstrdup (sval); | ||
| 503 | settings->seen |= SEEN_FONT; | ||
| 504 | } | ||
| 336 | else if (strcmp (name, "Xft/Antialias") == 0) | 505 | else if (strcmp (name, "Xft/Antialias") == 0) |
| 337 | { | 506 | { |
| 338 | settings->seen |= SEEN_AA; | 507 | settings->seen |= SEEN_AA; |
| @@ -397,6 +566,10 @@ parse_settings (unsigned char *prop, | |||
| 397 | return settings_seen; | 566 | return settings_seen; |
| 398 | } | 567 | } |
| 399 | 568 | ||
| 569 | /* Read settings from the XSettings property window on display for DPYINFO. | ||
| 570 | Store settings read in SETTINGS. | ||
| 571 | Return non-zero if successful, zero if not. */ | ||
| 572 | |||
| 400 | static int | 573 | static int |
| 401 | read_settings (struct x_display_info *dpyinfo, struct xsettings *settings) | 574 | read_settings (struct x_display_info *dpyinfo, struct xsettings *settings) |
| 402 | { | 575 | { |
| @@ -426,6 +599,8 @@ read_settings (struct x_display_info *dpyinfo, struct xsettings *settings) | |||
| 426 | return rc != 0; | 599 | return rc != 0; |
| 427 | } | 600 | } |
| 428 | 601 | ||
| 602 | /* Apply Xft settings in SETTINGS to the Xft library. | ||
| 603 | If SEND_EVENT_P is non-zero store a Lisp event that Xft settings changed. */ | ||
| 429 | 604 | ||
| 430 | static void | 605 | static void |
| 431 | apply_xft_settings (struct x_display_info *dpyinfo, | 606 | apply_xft_settings (struct x_display_info *dpyinfo, |
| @@ -444,9 +619,9 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 444 | pat); | 619 | pat); |
| 445 | FcPatternGetBool (pat, FC_ANTIALIAS, 0, &oldsettings.aa); | 620 | FcPatternGetBool (pat, FC_ANTIALIAS, 0, &oldsettings.aa); |
| 446 | FcPatternGetBool (pat, FC_HINTING, 0, &oldsettings.hinting); | 621 | FcPatternGetBool (pat, FC_HINTING, 0, &oldsettings.hinting); |
| 447 | # ifdef FC_HINT_STYLE | 622 | #ifdef FC_HINT_STYLE |
| 448 | FcPatternGetInteger (pat, FC_HINT_STYLE, 0, &oldsettings.hintstyle); | 623 | FcPatternGetInteger (pat, FC_HINT_STYLE, 0, &oldsettings.hintstyle); |
| 449 | # endif | 624 | #endif |
| 450 | FcPatternGetInteger (pat, FC_LCD_FILTER, 0, &oldsettings.lcdfilter); | 625 | FcPatternGetInteger (pat, FC_LCD_FILTER, 0, &oldsettings.lcdfilter); |
| 451 | FcPatternGetInteger (pat, FC_RGBA, 0, &oldsettings.rgba); | 626 | FcPatternGetInteger (pat, FC_RGBA, 0, &oldsettings.rgba); |
| 452 | FcPatternGetDouble (pat, FC_DPI, 0, &oldsettings.dpi); | 627 | FcPatternGetDouble (pat, FC_DPI, 0, &oldsettings.dpi); |
| @@ -485,7 +660,7 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 485 | oldsettings.lcdfilter = settings->lcdfilter; | 660 | oldsettings.lcdfilter = settings->lcdfilter; |
| 486 | } | 661 | } |
| 487 | 662 | ||
| 488 | # ifdef FC_HINT_STYLE | 663 | #ifdef FC_HINT_STYLE |
| 489 | if ((settings->seen & SEEN_HINTSTYLE) != 0 | 664 | if ((settings->seen & SEEN_HINTSTYLE) != 0 |
| 490 | && oldsettings.hintstyle != settings->hintstyle) | 665 | && oldsettings.hintstyle != settings->hintstyle) |
| 491 | { | 666 | { |
| @@ -494,7 +669,7 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 494 | ++changed; | 669 | ++changed; |
| 495 | oldsettings.hintstyle = settings->hintstyle; | 670 | oldsettings.hintstyle = settings->hintstyle; |
| 496 | } | 671 | } |
| 497 | # endif | 672 | #endif |
| 498 | 673 | ||
| 499 | if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi | 674 | if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi |
| 500 | && settings->dpi > 0) | 675 | && settings->dpi > 0) |
| @@ -545,11 +720,13 @@ apply_xft_settings (struct x_display_info *dpyinfo, | |||
| 545 | #endif /* HAVE_XFT */ | 720 | #endif /* HAVE_XFT */ |
| 546 | } | 721 | } |
| 547 | 722 | ||
| 723 | /* Read XSettings from the display for DPYINFO. | ||
| 724 | If SEND_EVENT_P is non-zero store a Lisp event settings that changed. */ | ||
| 725 | |||
| 548 | static void | 726 | static void |
| 549 | read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p) | 727 | read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p) |
| 550 | { | 728 | { |
| 551 | struct xsettings settings; | 729 | struct xsettings settings; |
| 552 | Lisp_Object dpyname = XCAR (dpyinfo->name_list_element); | ||
| 553 | 730 | ||
| 554 | if (!read_settings (dpyinfo, &settings)) | 731 | if (!read_settings (dpyinfo, &settings)) |
| 555 | return; | 732 | return; |
| @@ -557,38 +734,29 @@ read_and_apply_settings (struct x_display_info *dpyinfo, int send_event_p) | |||
| 557 | apply_xft_settings (dpyinfo, True, &settings); | 734 | apply_xft_settings (dpyinfo, True, &settings); |
| 558 | if (settings.seen & SEEN_TB_STYLE) | 735 | if (settings.seen & SEEN_TB_STYLE) |
| 559 | { | 736 | { |
| 560 | Lisp_Object style = Qnil; | 737 | if (send_event_p) |
| 561 | if (strcmp (settings.tb_style, "both") == 0) | 738 | store_tool_bar_style_changed (settings.tb_style, dpyinfo); |
| 562 | style = Qboth; | 739 | else |
| 563 | else if (strcmp (settings.tb_style, "both-horiz") == 0) | 740 | current_tool_bar_style = map_tool_bar_style (settings.tb_style); |
| 564 | style = Qboth_horiz; | ||
| 565 | else if (strcmp (settings.tb_style, "icons") == 0) | ||
| 566 | style = Qimage; | ||
| 567 | else if (strcmp (settings.tb_style, "text") == 0) | ||
| 568 | style = Qtext; | ||
| 569 | if (!NILP (style) && !EQ (style, current_tool_bar_style)) | ||
| 570 | { | ||
| 571 | current_tool_bar_style = style; | ||
| 572 | if (send_event_p) | ||
| 573 | store_config_changed_event (Qtool_bar_style, dpyname); | ||
| 574 | } | ||
| 575 | xfree (settings.tb_style); | 741 | xfree (settings.tb_style); |
| 576 | } | 742 | } |
| 577 | 743 | #ifdef HAVE_XFT | |
| 578 | if (settings.seen & SEEN_FONT) | 744 | if (settings.seen & SEEN_FONT) |
| 579 | { | 745 | { |
| 580 | if (!current_font || strcmp (current_font, settings.font) != 0) | 746 | if (send_event_p) |
| 747 | store_font_name_changed (settings.font); | ||
| 748 | else | ||
| 581 | { | 749 | { |
| 582 | xfree (current_font); | 750 | xfree (current_font); |
| 583 | current_font = settings.font; | 751 | current_font = xstrdup (settings.font); |
| 584 | if (send_event_p) | ||
| 585 | store_config_changed_event (Qfont_name, dpyname); | ||
| 586 | } | 752 | } |
| 587 | else | 753 | xfree (settings.font); |
| 588 | xfree (settings.font); | ||
| 589 | } | 754 | } |
| 755 | #endif | ||
| 590 | } | 756 | } |
| 591 | 757 | ||
| 758 | /* Check if EVENT for the display in DPYINFO is XSettings related. */ | ||
| 759 | |||
| 592 | void | 760 | void |
| 593 | xft_settings_event (struct x_display_info *dpyinfo, XEvent *event) | 761 | xft_settings_event (struct x_display_info *dpyinfo, XEvent *event) |
| 594 | { | 762 | { |
| @@ -630,41 +798,130 @@ xft_settings_event (struct x_display_info *dpyinfo, XEvent *event) | |||
| 630 | read_and_apply_settings (dpyinfo, True); | 798 | read_and_apply_settings (dpyinfo, True); |
| 631 | } | 799 | } |
| 632 | 800 | ||
| 801 | /* Initialize GSettings and read startup values. */ | ||
| 802 | |||
| 803 | static void | ||
| 804 | init_gsettings (void) | ||
| 805 | { | ||
| 806 | #ifdef HAVE_GSETTINGS | ||
| 807 | GVariant *val; | ||
| 808 | const gchar *const *schemas; | ||
| 809 | int schema_found = 0; | ||
| 810 | |||
| 811 | #ifdef HAVE_G_TYPE_INIT | ||
| 812 | g_type_init (); | ||
| 813 | #endif | ||
| 814 | |||
| 815 | schemas = g_settings_list_schemas(); | ||
| 816 | if (schemas == NULL) return; | ||
| 817 | while (! schema_found && *schemas != NULL) | ||
| 818 | schema_found = strcmp (*schemas++, GSETTINGS_SCHEMA) == 0; | ||
| 819 | if (!schema_found) return; | ||
| 820 | |||
| 821 | gsettings_client = g_settings_new (GSETTINGS_SCHEMA); | ||
| 822 | if (!gsettings_client) return; | ||
| 823 | g_object_ref_sink (G_OBJECT (gsettings_client)); | ||
| 824 | g_signal_connect (G_OBJECT (gsettings_client), "changed", | ||
| 825 | G_CALLBACK (something_changed_gsettingsCB), NULL); | ||
| 826 | |||
| 827 | val = g_settings_get_value (gsettings_client, GSETTINGS_TOOL_BAR_STYLE); | ||
| 828 | if (val) | ||
| 829 | { | ||
| 830 | g_variant_ref_sink (val); | ||
| 831 | if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) | ||
| 832 | current_tool_bar_style | ||
| 833 | = map_tool_bar_style (g_variant_get_string (val, NULL)); | ||
| 834 | g_variant_unref (val); | ||
| 835 | } | ||
| 836 | |||
| 837 | #ifdef HAVE_XFT | ||
| 838 | val = g_settings_get_value (gsettings_client, GSETTINGS_MONO_FONT); | ||
| 839 | if (val) | ||
| 840 | { | ||
| 841 | g_variant_ref_sink (val); | ||
| 842 | if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) | ||
| 843 | current_mono_font = xstrdup (g_variant_get_string (val, NULL)); | ||
| 844 | g_variant_unref (val); | ||
| 845 | } | ||
| 846 | |||
| 847 | val = g_settings_get_value (gsettings_client, GSETTINGS_FONT_NAME); | ||
| 848 | if (val) | ||
| 849 | { | ||
| 850 | g_variant_ref_sink (val); | ||
| 851 | if (g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) | ||
| 852 | current_font = xstrdup (g_variant_get_string (val, NULL)); | ||
| 853 | g_variant_unref (val); | ||
| 854 | } | ||
| 855 | #endif /* HAVE_XFT */ | ||
| 856 | |||
| 857 | #endif /* HAVE_GSETTINGS */ | ||
| 858 | } | ||
| 859 | |||
| 860 | /* Init GConf and read startup values. */ | ||
| 633 | 861 | ||
| 634 | static void | 862 | static void |
| 635 | init_gconf (void) | 863 | init_gconf (void) |
| 636 | { | 864 | { |
| 637 | #if defined (HAVE_GCONF) && defined (HAVE_XFT) | 865 | #if defined (HAVE_GCONF) |
| 638 | char *s; | 866 | char *s; |
| 639 | 867 | ||
| 640 | #ifdef HAVE_G_TYPE_INIT | 868 | #ifdef HAVE_G_TYPE_INIT |
| 641 | g_type_init (); | 869 | g_type_init (); |
| 642 | #endif | 870 | #endif |
| 871 | |||
| 643 | gconf_client = gconf_client_get_default (); | 872 | gconf_client = gconf_client_get_default (); |
| 644 | s = gconf_client_get_string (gconf_client, SYSTEM_MONO_FONT, NULL); | 873 | gconf_client_set_error_handling (gconf_client, GCONF_CLIENT_HANDLE_NONE); |
| 874 | gconf_client_add_dir (gconf_client, | ||
| 875 | GCONF_TOOL_BAR_STYLE, | ||
| 876 | GCONF_CLIENT_PRELOAD_ONELEVEL, | ||
| 877 | NULL); | ||
| 878 | gconf_client_notify_add (gconf_client, | ||
| 879 | GCONF_TOOL_BAR_STYLE, | ||
| 880 | something_changed_gconfCB, | ||
| 881 | NULL, NULL, NULL); | ||
| 882 | |||
| 883 | s = gconf_client_get_string (gconf_client, GCONF_TOOL_BAR_STYLE, NULL); | ||
| 884 | if (s) | ||
| 885 | { | ||
| 886 | current_tool_bar_style = map_tool_bar_style (s); | ||
| 887 | g_free (s); | ||
| 888 | } | ||
| 889 | |||
| 890 | #ifdef HAVE_XFT | ||
| 891 | s = gconf_client_get_string (gconf_client, GCONF_MONO_FONT, NULL); | ||
| 645 | if (s) | 892 | if (s) |
| 646 | { | 893 | { |
| 647 | current_mono_font = xstrdup (s); | 894 | current_mono_font = xstrdup (s); |
| 648 | g_free (s); | 895 | g_free (s); |
| 649 | } | 896 | } |
| 650 | s = gconf_client_get_string (gconf_client, SYSTEM_FONT, NULL); | 897 | s = gconf_client_get_string (gconf_client, GCONF_FONT_NAME, NULL); |
| 651 | if (s) | 898 | if (s) |
| 652 | { | 899 | { |
| 653 | current_font = xstrdup (s); | 900 | current_font = xstrdup (s); |
| 654 | g_free (s); | 901 | g_free (s); |
| 655 | } | 902 | } |
| 656 | gconf_client_set_error_handling (gconf_client, GCONF_CLIENT_HANDLE_NONE); | ||
| 657 | gconf_client_add_dir (gconf_client, | 903 | gconf_client_add_dir (gconf_client, |
| 658 | SYSTEM_MONO_FONT, | 904 | GCONF_MONO_FONT, |
| 905 | GCONF_CLIENT_PRELOAD_ONELEVEL, | ||
| 906 | NULL); | ||
| 907 | gconf_client_notify_add (gconf_client, | ||
| 908 | GCONF_MONO_FONT, | ||
| 909 | something_changed_gconfCB, | ||
| 910 | NULL, NULL, NULL); | ||
| 911 | gconf_client_add_dir (gconf_client, | ||
| 912 | GCONF_FONT_NAME, | ||
| 659 | GCONF_CLIENT_PRELOAD_ONELEVEL, | 913 | GCONF_CLIENT_PRELOAD_ONELEVEL, |
| 660 | NULL); | 914 | NULL); |
| 661 | gconf_client_notify_add (gconf_client, | 915 | gconf_client_notify_add (gconf_client, |
| 662 | SYSTEM_MONO_FONT, | 916 | GCONF_FONT_NAME, |
| 663 | something_changedCB, | 917 | something_changed_gconfCB, |
| 664 | NULL, NULL, NULL); | 918 | NULL, NULL, NULL); |
| 665 | #endif /* HAVE_GCONF && HAVE_XFT */ | 919 | #endif /* HAVE_XFT */ |
| 920 | #endif /* HAVE_GCONF */ | ||
| 666 | } | 921 | } |
| 667 | 922 | ||
| 923 | /* Init Xsettings and read startup values. */ | ||
| 924 | |||
| 668 | static void | 925 | static void |
| 669 | init_xsettings (struct x_display_info *dpyinfo) | 926 | init_xsettings (struct x_display_info *dpyinfo) |
| 670 | { | 927 | { |
| @@ -689,8 +946,12 @@ xsettings_initialize (struct x_display_info *dpyinfo) | |||
| 689 | if (first_dpyinfo == NULL) first_dpyinfo = dpyinfo; | 946 | if (first_dpyinfo == NULL) first_dpyinfo = dpyinfo; |
| 690 | init_gconf (); | 947 | init_gconf (); |
| 691 | init_xsettings (dpyinfo); | 948 | init_xsettings (dpyinfo); |
| 949 | init_gsettings (); | ||
| 692 | } | 950 | } |
| 693 | 951 | ||
| 952 | /* Return the system monospaced font. | ||
| 953 | May be NULL if not known. */ | ||
| 954 | |||
| 694 | const char * | 955 | const char * |
| 695 | xsettings_get_system_font (void) | 956 | xsettings_get_system_font (void) |
| 696 | { | 957 | { |
| @@ -698,6 +959,9 @@ xsettings_get_system_font (void) | |||
| 698 | } | 959 | } |
| 699 | 960 | ||
| 700 | #ifdef USE_LUCID | 961 | #ifdef USE_LUCID |
| 962 | /* Return the system font. | ||
| 963 | May be NULL if not known. */ | ||
| 964 | |||
| 701 | const char * | 965 | const char * |
| 702 | xsettings_get_system_normal_font (void) | 966 | xsettings_get_system_normal_font (void) |
| 703 | { | 967 | { |
| @@ -746,6 +1010,9 @@ syms_of_xsettings (void) | |||
| 746 | current_mono_font = NULL; | 1010 | current_mono_font = NULL; |
| 747 | current_font = NULL; | 1011 | current_font = NULL; |
| 748 | first_dpyinfo = NULL; | 1012 | first_dpyinfo = NULL; |
| 1013 | #ifdef HAVE_GSETTINGS | ||
| 1014 | gsettings_client = NULL; | ||
| 1015 | #endif | ||
| 749 | #ifdef HAVE_GCONF | 1016 | #ifdef HAVE_GCONF |
| 750 | gconf_client = NULL; | 1017 | gconf_client = NULL; |
| 751 | #endif | 1018 | #endif |
| @@ -769,7 +1036,7 @@ If this variable is nil, Emacs ignores system font changes. */); | |||
| 769 | 1036 | ||
| 770 | #ifdef HAVE_XFT | 1037 | #ifdef HAVE_XFT |
| 771 | Fprovide (intern_c_string ("font-render-setting"), Qnil); | 1038 | Fprovide (intern_c_string ("font-render-setting"), Qnil); |
| 772 | #ifdef HAVE_GCONF | 1039 | #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS) |
| 773 | Fprovide (intern_c_string ("system-font-setting"), Qnil); | 1040 | Fprovide (intern_c_string ("system-font-setting"), Qnil); |
| 774 | #endif | 1041 | #endif |
| 775 | #endif | 1042 | #endif |