Move LIBXTR6 from cpp to autoconf.
[bpt/emacs.git] / src / xsettings.c
1 /* Functions for handle font changes dynamically.
2 Copyright (C) 2009, 2010
3 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "config.h"
21 #include <setjmp.h>
22 #include <fcntl.h>
23 #include "lisp.h"
24 #include "xterm.h"
25 #include "xsettings.h"
26 #include "frame.h"
27 #include "keyboard.h"
28 #include "blockinput.h"
29 #include "termhooks.h"
30 #include "termopts.h"
31
32 #include <X11/Xproto.h>
33
34 #ifdef HAVE_GCONF
35 #include <gconf/gconf-client.h>
36 #endif
37 #ifdef HAVE_XFT
38 #include <X11/Xft/Xft.h>
39 #endif
40
41 static char *current_mono_font;
42 static char *current_font;
43 static struct x_display_info *first_dpyinfo;
44 static Lisp_Object Qmonospace_font_name, Qfont_name, Qfont_render,
45 Qtool_bar_style;
46 static int use_system_font;
47 static Lisp_Object Vxft_settings;
48 static Lisp_Object current_tool_bar_style;
49
50 #ifdef HAVE_GCONF
51 static GConfClient *gconf_client;
52 #endif
53
54
55 static void
56 store_config_changed_event (arg, display_name)
57 Lisp_Object arg;
58 Lisp_Object display_name;
59 {
60 struct input_event event;
61 EVENT_INIT (event);
62 event.kind = CONFIG_CHANGED_EVENT;
63 event.frame_or_window = display_name;
64 event.arg = arg;
65 kbd_buffer_store_event (&event);
66 }
67
68 #define XSETTINGS_FONT_NAME "Gtk/FontName"
69 #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle"
70
71 enum {
72 SEEN_AA = 0x01,
73 SEEN_HINTING = 0x02,
74 SEEN_RGBA = 0x04,
75 SEEN_LCDFILTER = 0x08,
76 SEEN_HINTSTYLE = 0x10,
77 SEEN_DPI = 0x20,
78 SEEN_FONT = 0x40,
79 SEEN_TB_STYLE = 0x80,
80 };
81 struct xsettings
82 {
83 #ifdef HAVE_XFT
84 FcBool aa, hinting;
85 int rgba, lcdfilter, hintstyle;
86 double dpi;
87 #endif
88
89 char *font;
90 char *tb_style;
91
92 unsigned seen;
93 };
94
95 #ifdef HAVE_GCONF
96
97 #define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
98 #define SYSTEM_FONT "/desktop/gnome/interface/font_name"
99
100 /* Callback called when something changed in GConf that we care about,
101 that is SYSTEM_MONO_FONT. */
102
103 static void
104 something_changedCB (client, cnxn_id, entry, user_data)
105 GConfClient *client;
106 guint cnxn_id;
107 GConfEntry *entry;
108 gpointer user_data;
109 {
110 GConfValue *v = gconf_entry_get_value (entry);
111
112 if (!v) return;
113 if (v->type == GCONF_VALUE_STRING)
114 {
115 const char *value = gconf_value_get_string (v);
116 int i;
117 if (current_mono_font != NULL && strcmp (value, current_mono_font) == 0)
118 return; /* No change. */
119
120 xfree (current_mono_font);
121 current_mono_font = xstrdup (value);
122 }
123
124
125 if (first_dpyinfo != NULL)
126 {
127 /* Check if display still open */
128 struct x_display_info *dpyinfo;
129 int found = 0;
130 for (dpyinfo = x_display_list; !found && dpyinfo; dpyinfo = dpyinfo->next)
131 found = dpyinfo == first_dpyinfo;
132
133 if (found && use_system_font)
134 store_config_changed_event (Qmonospace_font_name,
135 XCAR (first_dpyinfo->name_list_element));
136 }
137 }
138 #endif /* HAVE_GCONF */
139
140 #ifdef HAVE_XFT
141
142 /* Older fontconfig versions don't have FC_LCD_*. */
143 #ifndef FC_LCD_NONE
144 #define FC_LCD_NONE 0
145 #endif
146 #ifndef FC_LCD_DEFAULT
147 #define FC_LCD_DEFAULT 1
148 #endif
149 #ifndef FC_LCD_FILTER
150 #define FC_LCD_FILTER "lcdfilter"
151 #endif
152
153 #endif /* HAVE_XFT */
154
155 /* Find the window that contains the XSETTINGS property values. */
156
157 static void
158 get_prop_window (dpyinfo)
159 struct x_display_info *dpyinfo;
160 {
161 Display *dpy = dpyinfo->display;
162
163 XGrabServer (dpy);
164 dpyinfo->xsettings_window = XGetSelectionOwner (dpy,
165 dpyinfo->Xatom_xsettings_sel);
166 if (dpyinfo->xsettings_window != None)
167 /* Select events so we can detect if window is deleted or if settings
168 are changed. */
169 XSelectInput (dpy, dpyinfo->xsettings_window,
170 PropertyChangeMask|StructureNotifyMask);
171
172 XUngrabServer (dpy);
173 }
174
175 #define SWAP32(nr) (((nr) << 24) | (((nr) << 8) & 0xff0000) \
176 | (((nr) >> 8) & 0xff00) | ((nr) >> 24))
177 #define SWAP16(nr) (((nr) << 8) | ((nr) >> 8))
178 #define PAD(nr) (((nr) + 3) & ~3)
179
180 /* Parse xsettings and extract those that deal with Xft.
181 See http://freedesktop.org/wiki/Specifications/XSettingsRegistry
182 and http://standards.freedesktop.org/xsettings-spec/xsettings-spec-0.5.html.
183
184 Layout of prop. First is a header:
185
186 bytes type what
187 ------------------------------------
188 1 CARD8 byte-order
189 3 unused
190 4 CARD32 SERIAL
191 4 CARD32 N_SETTINGS
192
193 Then N_SETTINGS records, with header:
194
195 bytes type what
196 ------------------------------------
197 1 SETTING_TYPE type (0 = integer, 1 = string, 2 RGB color).
198 1 unused
199 2 CARD16 n == name-length
200 n STRING8 name
201 p unused, p=pad_to_even_4(n)
202 4 CARD32 last-change-serial
203
204 and then the value, For string:
205
206 bytes type what
207 ------------------------------------
208 4 CARD32 n = value-length
209 n STRING8 value
210 p unused, p=pad_to_even_4(n)
211
212 For integer:
213
214 bytes type what
215 ------------------------------------
216 4 INT32 value
217
218 For RGB color:
219
220 bytes type what
221 ------------------------------------
222 2 CARD16 red
223 2 CARD16 blue
224 2 CARD16 green
225 2 CARD16 alpha
226
227 Returns non-zero if some Xft settings was seen, zero otherwise.
228 */
229
230 static int
231 parse_settings (prop, bytes, settings)
232 unsigned char *prop;
233 unsigned long bytes;
234 struct xsettings *settings;
235 {
236 Lisp_Object byteorder = Fbyteorder ();
237 int my_bo = XFASTINT (byteorder) == 'B' ? MSBFirst : LSBFirst;
238 int that_bo = prop[0];
239 CARD32 n_settings;
240 int bytes_parsed = 0;
241 int settings_seen = 0;
242 int i = 0;
243
244 /* First 4 bytes is a serial number, skip that. */
245
246 if (bytes < 12) return BadLength;
247 memcpy (&n_settings, prop+8, 4);
248 if (my_bo != that_bo) n_settings = SWAP32 (n_settings);
249 bytes_parsed = 12;
250
251 memset (settings, 0, sizeof (*settings));
252
253 while (bytes_parsed+4 < bytes && settings_seen < 7
254 && i < n_settings)
255 {
256 int type = prop[bytes_parsed++];
257 CARD16 nlen;
258 CARD32 vlen, ival = 0;
259 char name[128]; /* The names we are looking for are not this long. */
260 char sval[128]; /* The values we are looking for are not this long. */
261 int want_this;
262 int to_cpy;
263
264 sval[0] = '\0';
265 ++i;
266 ++bytes_parsed; /* Padding */
267
268 memcpy (&nlen, prop+bytes_parsed, 2);
269 bytes_parsed += 2;
270 if (my_bo != that_bo) nlen = SWAP16 (nlen);
271 if (bytes_parsed+nlen > bytes) return BadLength;
272 to_cpy = nlen > 127 ? 127 : nlen;
273 memcpy (name, prop+bytes_parsed, to_cpy);
274 name[to_cpy] = '\0';
275
276 bytes_parsed += nlen;
277 bytes_parsed = PAD (bytes_parsed);
278
279 bytes_parsed += 4; /* Skip serial for this value */
280 if (bytes_parsed > bytes) return BadLength;
281
282 want_this =
283 #ifdef HAVE_XFT
284 (nlen > 6 && strncmp (name, "Xft/", 4) == 0)
285 ||
286 #endif
287 (strcmp (XSETTINGS_FONT_NAME, name) == 0)
288 || (strcmp (XSETTINGS_TOOL_BAR_STYLE, name) == 0);
289
290 switch (type)
291 {
292 case 0: /* Integer */
293 if (bytes_parsed+4 > bytes) return BadLength;
294 if (want_this)
295 {
296 memcpy (&ival, prop+bytes_parsed, 4);
297 if (my_bo != that_bo) ival = SWAP32 (ival);
298 }
299 bytes_parsed += 4;
300 break;
301
302 case 1: /* String */
303 if (bytes_parsed+4 > bytes) return BadLength;
304 memcpy (&vlen, prop+bytes_parsed, 4);
305 bytes_parsed += 4;
306 if (my_bo != that_bo) vlen = SWAP32 (vlen);
307 if (want_this)
308 {
309 to_cpy = vlen > 127 ? 127 : vlen;
310 memcpy (sval, prop+bytes_parsed, to_cpy);
311 sval[to_cpy] = '\0';
312 }
313 bytes_parsed += vlen;
314 bytes_parsed = PAD (bytes_parsed);
315 break;
316
317 case 2: /* RGB value */
318 /* No need to parse this */
319 if (bytes_parsed+8 > bytes) return BadLength;
320 bytes_parsed += 8; /* 4 values (r, b, g, alpha), 2 bytes each. */
321 break;
322
323 default: /* Parse Error */
324 return BadValue;
325 }
326
327 if (want_this)
328 {
329 ++settings_seen;
330 if (strcmp (name, XSETTINGS_FONT_NAME) == 0)
331 {
332 settings->font = xstrdup (sval);
333 settings->seen |= SEEN_FONT;
334 }
335 else if (strcmp (name, XSETTINGS_TOOL_BAR_STYLE) == 0)
336 {
337 settings->tb_style = xstrdup (sval);
338 settings->seen |= SEEN_TB_STYLE;
339 }
340 #ifdef HAVE_XFT
341 else if (strcmp (name, "Xft/Antialias") == 0)
342 {
343 settings->seen |= SEEN_AA;
344 settings->aa = ival != 0;
345 }
346 else if (strcmp (name, "Xft/Hinting") == 0)
347 {
348 settings->seen |= SEEN_HINTING;
349 settings->hinting = ival != 0;
350 }
351 else if (strcmp (name, "Xft/HintStyle") == 0)
352 {
353 settings->seen |= SEEN_HINTSTYLE;
354 if (strcmp (sval, "hintnone") == 0)
355 settings->hintstyle = FC_HINT_NONE;
356 else if (strcmp (sval, "hintslight") == 0)
357 settings->hintstyle = FC_HINT_SLIGHT;
358 else if (strcmp (sval, "hintmedium") == 0)
359 settings->hintstyle = FC_HINT_MEDIUM;
360 else if (strcmp (sval, "hintfull") == 0)
361 settings->hintstyle = FC_HINT_FULL;
362 else
363 settings->seen &= ~SEEN_HINTSTYLE;
364 }
365 else if (strcmp (name, "Xft/RGBA") == 0)
366 {
367 settings->seen |= SEEN_RGBA;
368 if (strcmp (sval, "none") == 0)
369 settings->rgba = FC_RGBA_NONE;
370 else if (strcmp (sval, "rgb") == 0)
371 settings->rgba = FC_RGBA_RGB;
372 else if (strcmp (sval, "bgr") == 0)
373 settings->rgba = FC_RGBA_BGR;
374 else if (strcmp (sval, "vrgb") == 0)
375 settings->rgba = FC_RGBA_VRGB;
376 else if (strcmp (sval, "vbgr") == 0)
377 settings->rgba = FC_RGBA_VBGR;
378 else
379 settings->seen &= ~SEEN_RGBA;
380 }
381 else if (strcmp (name, "Xft/DPI") == 0)
382 {
383 settings->seen |= SEEN_DPI;
384 settings->dpi = (double)ival/1024.0;
385 }
386 else if (strcmp (name, "Xft/lcdfilter") == 0)
387 {
388 settings->seen |= SEEN_LCDFILTER;
389 if (strcmp (sval, "none") == 0)
390 settings->lcdfilter = FC_LCD_NONE;
391 else if (strcmp (sval, "lcddefault") == 0)
392 settings->lcdfilter = FC_LCD_DEFAULT;
393 else
394 settings->seen &= ~SEEN_LCDFILTER;
395 }
396 #endif /* HAVE_XFT */
397 }
398 }
399
400 return settings_seen;
401 }
402
403 static int
404 read_settings (dpyinfo, settings)
405 struct x_display_info *dpyinfo;
406 struct xsettings *settings;
407 {
408 long long_len;
409 Atom act_type;
410 int act_form;
411 unsigned long nitems, bytes_after;
412 unsigned char *prop = NULL;
413 Display *dpy = dpyinfo->display;
414 int rc;
415
416 x_catch_errors (dpy);
417 rc = XGetWindowProperty (dpy,
418 dpyinfo->xsettings_window,
419 dpyinfo->Xatom_xsettings_prop,
420 0, LONG_MAX, False, AnyPropertyType,
421 &act_type, &act_form, &nitems, &bytes_after,
422 &prop);
423
424 if (rc == Success && prop != NULL && act_form == 8 && nitems > 0
425 && act_type == dpyinfo->Xatom_xsettings_prop)
426 rc = parse_settings (prop, nitems, settings);
427
428 XFree (prop);
429
430 x_uncatch_errors ();
431
432 return rc != 0;
433 }
434
435
436 static void
437 apply_xft_settings (dpyinfo, send_event_p, settings)
438 struct x_display_info *dpyinfo;
439 int send_event_p;
440 struct xsettings *settings;
441 {
442 #ifdef HAVE_XFT
443 FcPattern *pat;
444 struct xsettings oldsettings;
445 int changed = 0;
446 char buf[256];
447
448 memset (&oldsettings, 0, sizeof (oldsettings));
449 buf[0] = '\0';
450 pat = FcPatternCreate ();
451 XftDefaultSubstitute (dpyinfo->display,
452 XScreenNumberOfScreen (dpyinfo->screen),
453 pat);
454 FcPatternGetBool (pat, FC_ANTIALIAS, 0, &oldsettings.aa);
455 FcPatternGetBool (pat, FC_HINTING, 0, &oldsettings.hinting);
456 FcPatternGetInteger (pat, FC_HINT_STYLE, 0, &oldsettings.hintstyle);
457 FcPatternGetInteger (pat, FC_LCD_FILTER, 0, &oldsettings.lcdfilter);
458 FcPatternGetInteger (pat, FC_RGBA, 0, &oldsettings.rgba);
459 FcPatternGetDouble (pat, FC_DPI, 0, &oldsettings.dpi);
460
461 if ((settings->seen & SEEN_AA) != 0 && oldsettings.aa != settings->aa)
462 {
463 FcPatternDel (pat, FC_ANTIALIAS);
464 FcPatternAddBool (pat, FC_ANTIALIAS, settings->aa);
465 ++changed;
466 oldsettings.aa = settings->aa;
467 }
468 sprintf (buf, "Antialias: %d", oldsettings.aa);
469
470 if ((settings->seen & SEEN_HINTING) != 0
471 && oldsettings.hinting != settings->hinting)
472 {
473 FcPatternDel (pat, FC_HINTING);
474 FcPatternAddBool (pat, FC_HINTING, settings->hinting);
475 ++changed;
476 oldsettings.hinting = settings->hinting;
477 }
478 if (strlen (buf) > 0) strcat (buf, ", ");
479 sprintf (buf+strlen (buf), "Hinting: %d", oldsettings.hinting);
480 if ((settings->seen & SEEN_RGBA) != 0 && oldsettings.rgba != settings->rgba)
481 {
482 FcPatternDel (pat, FC_RGBA);
483 FcPatternAddInteger (pat, FC_RGBA, settings->rgba);
484 oldsettings.rgba = settings->rgba;
485 ++changed;
486 }
487 if (strlen (buf) > 0) strcat (buf, ", ");
488 sprintf (buf+strlen (buf), "RGBA: %d", oldsettings.rgba);
489
490 /* Older fontconfig versions don't have FC_LCD_FILTER. */
491 if ((settings->seen & SEEN_LCDFILTER) != 0
492 && oldsettings.lcdfilter != settings->lcdfilter)
493 {
494 FcPatternDel (pat, FC_LCD_FILTER);
495 FcPatternAddInteger (pat, FC_LCD_FILTER, settings->lcdfilter);
496 ++changed;
497 oldsettings.lcdfilter = settings->lcdfilter;
498 }
499 if (strlen (buf) > 0) strcat (buf, ", ");
500 sprintf (buf+strlen (buf), "LCDFilter: %d", oldsettings.lcdfilter);
501
502 if ((settings->seen & SEEN_HINTSTYLE) != 0
503 && oldsettings.hintstyle != settings->hintstyle)
504 {
505 FcPatternDel (pat, FC_HINT_STYLE);
506 FcPatternAddInteger (pat, FC_HINT_STYLE, settings->hintstyle);
507 ++changed;
508 oldsettings.hintstyle = settings->hintstyle;
509 }
510 if (strlen (buf) > 0) strcat (buf, ", ");
511 sprintf (buf+strlen (buf), "Hintstyle: %d", oldsettings.hintstyle);
512
513 if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi
514 && settings->dpi > 0)
515 {
516 Lisp_Object frame, tail;
517
518 FcPatternDel (pat, FC_DPI);
519 FcPatternAddDouble (pat, FC_DPI, settings->dpi);
520 ++changed;
521 oldsettings.dpi = settings->dpi;
522
523 /* Change the DPI on this display and all frames on the display. */
524 dpyinfo->resy = dpyinfo->resx = settings->dpi;
525 FOR_EACH_FRAME (tail, frame)
526 if (FRAME_X_P (XFRAME (frame))
527 && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo)
528 XFRAME (frame)->resy = XFRAME (frame)->resx = settings->dpi;
529 }
530
531 if (strlen (buf) > 0) strcat (buf, ", ");
532 sprintf (buf+strlen (buf), "DPI: %lf", oldsettings.dpi);
533
534 if (changed)
535 {
536 XftDefaultSet (dpyinfo->display, pat);
537 if (send_event_p)
538 store_config_changed_event (Qfont_render,
539 XCAR (dpyinfo->name_list_element));
540 Vxft_settings = make_string (buf, strlen (buf));
541 }
542 else
543 FcPatternDestroy (pat);
544 #endif /* HAVE_XFT */
545 }
546
547 static void
548 read_and_apply_settings (dpyinfo, send_event_p)
549 struct x_display_info *dpyinfo;
550 int send_event_p;
551 {
552 struct xsettings settings;
553 Lisp_Object dpyname = XCAR (dpyinfo->name_list_element);
554
555 if (!read_settings (dpyinfo, &settings))
556 return;
557
558 apply_xft_settings (dpyinfo, True, &settings);
559 if (settings.seen & SEEN_TB_STYLE)
560 {
561 Lisp_Object style = Qnil;
562 if (strcmp (settings.tb_style, "both") == 0)
563 style = Qboth;
564 else if (strcmp (settings.tb_style, "both-horiz") == 0)
565 style = Qboth_horiz;
566 else if (strcmp (settings.tb_style, "icons") == 0)
567 style = Qimage;
568 else if (strcmp (settings.tb_style, "text") == 0)
569 style = Qtext;
570 if (!NILP (style) && !EQ (style, current_tool_bar_style))
571 {
572 current_tool_bar_style = style;
573 if (send_event_p)
574 store_config_changed_event (Qtool_bar_style, dpyname);
575 }
576 free (settings.tb_style);
577 }
578
579 if (settings.seen & SEEN_FONT)
580 {
581 if (!current_font || strcmp (current_font, settings.font) != 0)
582 {
583 free (current_font);
584 current_font = settings.font;
585 if (send_event_p)
586 store_config_changed_event (Qfont_name, dpyname);
587 }
588 else
589 free (settings.font);
590 }
591 }
592
593 void
594 xft_settings_event (dpyinfo, event)
595 struct x_display_info *dpyinfo;
596 XEvent *event;
597 {
598 int check_window_p = 0;
599 int apply_settings = 0;
600
601 switch (event->type)
602 {
603 case DestroyNotify:
604 if (dpyinfo->xsettings_window == event->xany.window)
605 check_window_p = 1;
606 break;
607
608 case ClientMessage:
609 if (event->xclient.message_type == dpyinfo->Xatom_xsettings_mgr
610 && event->xclient.data.l[1] == dpyinfo->Xatom_xsettings_sel
611 && event->xclient.window == dpyinfo->root_window)
612 check_window_p = 1;
613 break;
614
615 case PropertyNotify:
616 if (event->xproperty.window == dpyinfo->xsettings_window
617 && event->xproperty.state == PropertyNewValue
618 && event->xproperty.atom == dpyinfo->Xatom_xsettings_prop)
619 apply_settings = 1;
620 break;
621 }
622
623
624 if (check_window_p)
625 {
626 dpyinfo->xsettings_window = None;
627 get_prop_window (dpyinfo);
628 if (dpyinfo->xsettings_window != None)
629 apply_settings = 1;
630 }
631
632 if (apply_settings)
633 read_and_apply_settings (dpyinfo, True);
634 }
635
636
637 static void
638 init_gconf ()
639 {
640 #if defined (HAVE_GCONF) && defined (HAVE_XFT)
641 int i;
642 char *s;
643
644 g_type_init ();
645 gconf_client = gconf_client_get_default ();
646 s = gconf_client_get_string (gconf_client, SYSTEM_MONO_FONT, NULL);
647 if (s)
648 {
649 current_mono_font = xstrdup (s);
650 g_free (s);
651 }
652 s = gconf_client_get_string (gconf_client, SYSTEM_FONT, NULL);
653 if (s)
654 {
655 current_font = xstrdup (s);
656 g_free (s);
657 }
658 gconf_client_set_error_handling (gconf_client, GCONF_CLIENT_HANDLE_NONE);
659 gconf_client_add_dir (gconf_client,
660 SYSTEM_MONO_FONT,
661 GCONF_CLIENT_PRELOAD_ONELEVEL,
662 NULL);
663 gconf_client_notify_add (gconf_client,
664 SYSTEM_MONO_FONT,
665 something_changedCB,
666 NULL, NULL, NULL);
667 #endif /* HAVE_GCONF && HAVE_XFT */
668 }
669
670 static void
671 init_xsettings (dpyinfo)
672 struct x_display_info *dpyinfo;
673 {
674 char sel[64];
675 Display *dpy = dpyinfo->display;
676
677 BLOCK_INPUT;
678
679 sprintf (sel, "_XSETTINGS_S%d", XScreenNumberOfScreen (dpyinfo->screen));
680 dpyinfo->Xatom_xsettings_sel = XInternAtom (dpy, sel, False);
681 dpyinfo->Xatom_xsettings_prop = XInternAtom (dpy,
682 "_XSETTINGS_SETTINGS",
683 False);
684 dpyinfo->Xatom_xsettings_mgr = XInternAtom (dpy, "MANAGER", False);
685
686 /* Select events so we can detect client messages sent when selection
687 owner changes. */
688 XSelectInput (dpy, dpyinfo->root_window, StructureNotifyMask);
689
690 get_prop_window (dpyinfo);
691 if (dpyinfo->xsettings_window != None)
692 read_and_apply_settings (dpyinfo, False);
693
694 UNBLOCK_INPUT;
695 }
696
697 void
698 xsettings_initialize (dpyinfo)
699 struct x_display_info *dpyinfo;
700 {
701 if (first_dpyinfo == NULL) first_dpyinfo = dpyinfo;
702 init_gconf ();
703 init_xsettings (dpyinfo);
704 }
705
706 const char *
707 xsettings_get_system_font ()
708 {
709 return current_mono_font;
710 }
711
712 const char *
713 xsettings_get_system_normal_font ()
714 {
715 return current_font;
716 }
717
718 DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font,
719 Sfont_get_system_normal_font,
720 0, 0, 0,
721 doc: /* Get the system default font. */)
722 ()
723 {
724 return current_font && use_system_font
725 ? make_string (current_font, strlen (current_font))
726 : Qnil;
727 }
728
729 DEFUN ("font-get-system-font", Ffont_get_system_font, Sfont_get_system_font,
730 0, 0, 0,
731 doc: /* Get the system default monospaced font. */)
732 ()
733 {
734 return current_mono_font && use_system_font
735 ? make_string (current_mono_font, strlen (current_mono_font))
736 : Qnil;
737 }
738
739 DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style, Stool_bar_get_system_style,
740 0, 0, 0,
741 doc: /* Get the system tool bar style.
742 If no system tool bar style is known, return `tool-bar-style' is set to a
743 known style. Otherwise return image. */)
744 ()
745 {
746 if (EQ (Vtool_bar_style, Qimage)
747 || EQ (Vtool_bar_style, Qtext)
748 || EQ (Vtool_bar_style, Qboth)
749 || EQ (Vtool_bar_style, Qboth_horiz))
750 return Vtool_bar_style;
751 if (!NILP (current_tool_bar_style))
752 return current_tool_bar_style;
753 return Qimage;
754 }
755
756 void
757 syms_of_xsettings ()
758 {
759 current_mono_font = NULL;
760 current_font = NULL;
761 first_dpyinfo = NULL;
762 #ifdef HAVE_GCONF
763 gconf_client = NULL;
764 #endif
765
766 Qmonospace_font_name = intern_c_string ("monospace-font-name");
767 staticpro (&Qmonospace_font_name);
768 Qfont_name = intern_c_string ("font-name");
769 staticpro (&Qfont_name);
770 Qfont_render = intern_c_string ("font-render");
771 staticpro (&Qfont_render);
772 defsubr (&Sfont_get_system_font);
773 defsubr (&Sfont_get_system_normal_font);
774
775 DEFVAR_BOOL ("font-use-system-font", &use_system_font,
776 doc: /* *Non-nil means to use the system defined font. */);
777 use_system_font = 0;
778
779 DEFVAR_LISP ("xft-settings", &Vxft_settings,
780 doc: /* Font settings applied to Xft. */);
781 Vxft_settings = make_string ("", 0);
782
783 #ifdef HAVE_XFT
784 Fprovide (intern_c_string ("font-render-setting"), Qnil);
785 #ifdef HAVE_GCONF
786 Fprovide (intern_c_string ("system-font-setting"), Qnil);
787 #endif
788 #endif
789
790 current_tool_bar_style = Qnil;
791 Qtool_bar_style = intern_c_string ("tool-bar-style");
792 staticpro (&Qtool_bar_style);
793 defsubr (&Stool_bar_get_system_style);
794
795 Fprovide (intern_c_string ("dynamic-setting"), Qnil);
796 }
797
798 /* arch-tag: 541716ed-2e6b-42e1-8212-3197e01ea61d
799 (do not change this comment) */