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