aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Djärv2010-04-08 18:20:32 +0200
committerJan Djärv2010-04-08 18:20:32 +0200
commit99852628a828979c55c96d7def6c5a21f2b32af5 (patch)
tree31090fefe3468ad6d12495d2e65596dc939b41d2
parent9a15cc5a6837f39eaefd28ab607fc39dffcc11b3 (diff)
downloademacs-99852628a828979c55c96d7def6c5a21f2b32af5.tar.gz
emacs-99852628a828979c55c96d7def6c5a21f2b32af5.zip
Lucid menus can now use Xft for fonts.
* xsettings.c (current_font, SYSTEM_FONT, XSETTINGS_FONT_NAME): New. (parse_xft_settings): Also check for XSETTINGS_FONT_NAME and save that in current_font. (init_gconf): Read value of SYSTEM_FONT and save it in current_font. (Ffont_get_system_normal_font, xsettings_get_system_normal_font): New functions. (syms_of_xsettings): Initialize current_font. defsubr Sfont_get_system_normal_font. * xsettings.h (Ffont_get_system_normal_font, xsettings_get_system_normal_font): Declare. * xfns.c (extern xlwmenu_default_font): Remove. (Fx_create_frame): Remove setting of xlwmenu_default_font, moved to xlwmenu.c. * menu.c (digest_single_submenu): If USE_LUCID and HAVE_XFT, encode menu items in UTF-8. * xmenu.c: include xsettings.h and xlwmenu.h if USE_LUCID. (apply_systemfont_to_menu): New function. (set_frame_menubar, create_and_show_popup_menu): Call apply_systemfont_to_menu. * xlwmenu.c (xlwmenu_default_font): Make static. (xlwMenuResources): Add XtNfaceName and XtNdefaultFace. (string_width): Use XftTextExtentsUtf8 if HAVE_XFT. (MENU_FONT_HEIGHT, MENU_FONT_ASCENT): Add versions for HAVE_XFT. (size_menu): Set max_rest_width in window_state structure. (display_menu_item): If HAVE_XFT and xft_draw is set, use XftDrawRect and XftDrawStringUtf8 to draw text. (make_windows_if_needed): Set max_rest_width and xft_draw in windows[i]. (openXftFont): New. (XlwMenuInitialize): Call openXftFont if HAVE_XFT. If mw->menu.font is not set, load font fixed and save it in xlwmenu_default_font. (XlwMenuInitialize): Set max_rest_width and xft_draw in windows[0]. (XlwMenuClassInitialize): Initialize xlwmenu_default_font. (XlwMenuRealize): Set xft_fg, xft_bg, xft_disabled_fg and windows[0].xft_draw if xft_font is set. (XlwMenuDestroy): Destroy all xft_draw and close xft_font. (facename_changed): New. (XlwMenuSetValues): Call facename_changed. If face name did change, close old fonts and destroy xft_draw:s. Then create new ones. * xlwmenu.h (XtNfaceName, XtCFaceName, XtNdefaultFace, XtCDefaultFace): New. * xlwmenuP.h (_window_state): Add max_rest_width and xft_draw. (_XlwMenu_part): Add faceName,xft_fg, xft_bg, xft_disabled_fg and xft_font. * xresources.texi (Lucid Resources): Mention faceName to set Xft fonts.
-rw-r--r--doc/emacs/ChangeLog4
-rw-r--r--doc/emacs/xresources.texi43
-rw-r--r--etc/NEWS2
-rw-r--r--lwlib/ChangeLog31
-rw-r--r--lwlib/xlwmenu.c242
-rw-r--r--lwlib/xlwmenu.h4
-rw-r--r--lwlib/xlwmenuP.h13
-rw-r--r--src/ChangeLog26
-rw-r--r--src/menu.c18
-rw-r--r--src/xfns.c13
-rw-r--r--src/xmenu.c35
-rw-r--r--src/xsettings.c48
-rw-r--r--src/xsettings.h3
13 files changed, 441 insertions, 41 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index c0a0539a018..8cb082d64e2 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,7 @@
12010-04-08 Jan Djärv <jan.h.d@swipnet.se>
2
3 * xresources.texi (Lucid Resources): Mention faceName to set Xft fonts.
4
12010-03-30 Eli Zaretskii <eliz@gnu.org> 52010-03-30 Eli Zaretskii <eliz@gnu.org>
2 6
3 * mule.texi (Input Methods): Mention "C-x 8 RET" and add a 7 * mule.texi (Input Methods): Mention "C-x 8 RET" and add a
diff --git a/doc/emacs/xresources.texi b/doc/emacs/xresources.texi
index 75b6e3bbe4c..4e4f3ad87a2 100644
--- a/doc/emacs/xresources.texi
+++ b/doc/emacs/xresources.texi
@@ -415,7 +415,7 @@ Emacs.pane.menubar.@var{resource}: @var{value}
415@end example 415@end example
416 416
417@noindent 417@noindent
418For example, to specify the font @samp{8x16} for the menu-bar items, 418For example, to specify the font @samp{Courier-12} for the menu-bar items,
419write this: 419write this:
420@end ifnottex 420@end ifnottex
421@iftex 421@iftex
@@ -423,32 +423,35 @@ write this:
423with the Lucid menu widgets, then the menu bar is a separate widget 423with the Lucid menu widgets, then the menu bar is a separate widget
424and has its own resources. The resource specifications start with 424and has its own resources. The resource specifications start with
425@samp{Emacs.pane.menubar}---for instance, to specify the font 425@samp{Emacs.pane.menubar}---for instance, to specify the font
426@samp{8x16} for the menu-bar items, write this: 426@samp{Courier-12} for the menu-bar items, write this:
427@end iftex 427@end iftex
428 428
429@example 429@example
430Emacs.pane.menubar.font: 8x16 430Emacs.pane.menubar.faceName: Courier-12
431@end example 431@end example
432 432
433@noindent 433@noindent
434Resources for @emph{non-menubar} toolkit pop-up menus have 434To specify a font, use fontconfig font names as values to the @code{faceName}
435@samp{menu*} instead of @samp{pane.menubar}. For example, to specify 435resource.
436the font @samp{8x16} for the pop-up menu items, write this: 436
437If Emacs is not built with the Xft library, Lucid menus can only display
438old style fonts. If Emacs is built with Xft and you prefer the old fonts,
439you have to specify @samp{none} to @code{faceName}:
437 440
438@example 441@example
439Emacs.menu*.font: 8x16 442Emacs.pane.menubar.faceName: none
440@end example 443@end example
441 444
442@noindent 445@noindent
443For dialog boxes, use @samp{dialog*}: 446To specify a non-Xft font, use @code{font}. For example:
444 447
445@example 448@example
446Emacs.dialog*.font: 8x16 449Emacs.pane.menubar.font: lucidasanstypewriter-10
447@end example 450@end example
448 451
449@noindent 452@noindent
450The Lucid menus can display multilingual text in your locale. For 453The Lucid menus can display multilingual text in your locale with old style
451more information about fontsets see the man page for 454fonts. For more information about fontsets see the man page for
452@code{XCreateFontSet}. To enable multilingual menu text you specify a 455@code{XCreateFontSet}. To enable multilingual menu text you specify a
453@code{fontSet} resource instead of the font resource. If both 456@code{fontSet} resource instead of the font resource. If both
454@code{font} and @code{fontSet} resources are specified, the 457@code{font} and @code{fontSet} resources are specified, the
@@ -462,6 +465,22 @@ Emacs*menu*fontSet: -*-helvetica-medium-r-*--*-120-*-*-*-*-*-*,*
462@end example 465@end example
463 466
464@noindent 467@noindent
468Resources for @emph{non-menubar} toolkit pop-up menus have
469@samp{menu*} instead of @samp{pane.menubar}. For example, to specify
470the font @samp{8x16} for the pop-up menu items, write this:
471
472@example
473Emacs.menu*.font: 8x16
474@end example
475
476@noindent
477For dialog boxes, use @samp{dialog*}:
478
479@example
480Emacs.dialog*.font: 8x16
481@end example
482
483@noindent
465The @samp{*menu*} as a wildcard matches @samp{pane.menubar} and 484The @samp{*menu*} as a wildcard matches @samp{pane.menubar} and
466@samp{menu@dots{}}. 485@samp{menu@dots{}}.
467 486
@@ -473,6 +492,8 @@ approach should work on both kinds of systems.
473 Here is a list of the specific resources for menu bars and pop-up menus: 492 Here is a list of the specific resources for menu bars and pop-up menus:
474 493
475@table @code 494@table @code
495@item faceName
496Xft font for menu item text.
476@item font 497@item font
477Font for menu item text. 498Font for menu item text.
478@item fontSet 499@item fontSet
diff --git a/etc/NEWS b/etc/NEWS
index f555c8689a3..a21f7967c2f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -65,6 +65,8 @@ Algorithm.
65** GTK scroll-bars are now placed on the right by default. 65** GTK scroll-bars are now placed on the right by default.
66Use `set-scroll-bar-mode' to change this. 66Use `set-scroll-bar-mode' to change this.
67 67
68** Lucid menus can display antialiased fonts if Emacs is build with Xft.
69
68** New scrolling commands `scroll-up-command' and `scroll-down-command' 70** New scrolling commands `scroll-up-command' and `scroll-down-command'
69(bound to [next] and [prior]) does not signal errors at top/bottom 71(bound to [next] and [prior]) does not signal errors at top/bottom
70of buffer at first key-press (instead moves to top/bottom of buffer). 72of buffer at first key-press (instead moves to top/bottom of buffer).
diff --git a/lwlib/ChangeLog b/lwlib/ChangeLog
index 9bea2c13dbd..189e2c65e10 100644
--- a/lwlib/ChangeLog
+++ b/lwlib/ChangeLog
@@ -1,3 +1,34 @@
12010-04-08 Jan Djärv <jan.h.d@swipnet.se>
2
3 * xlwmenu.c (xlwmenu_default_font): Make static.
4 (xlwMenuResources): Add XtNfaceName and XtNdefaultFace.
5 (string_width): Use XftTextExtentsUtf8 if HAVE_XFT.
6 (MENU_FONT_HEIGHT, MENU_FONT_ASCENT): Add versions for
7 HAVE_XFT.
8 (size_menu): Set max_rest_width in window_state structure.
9 (display_menu_item): If HAVE_XFT and xft_draw is set, use
10 XftDrawRect and XftDrawStringUtf8 to draw text.
11 (make_windows_if_needed): Set max_rest_width and xft_draw
12 in windows[i].
13 (openXftFont): New.
14 (XlwMenuInitialize): Call openXftFont if HAVE_XFT. If mw->menu.font
15 is not set, load font fixed and save it in xlwmenu_default_font.
16 (XlwMenuInitialize): Set max_rest_width and xft_draw in windows[0].
17 (XlwMenuClassInitialize): Initialize xlwmenu_default_font.
18 (XlwMenuRealize): Set xft_fg, xft_bg, xft_disabled_fg and
19 windows[0].xft_draw if xft_font is set.
20 (XlwMenuDestroy): Destroy all xft_draw and close xft_font.
21 (facename_changed): New.
22 (XlwMenuSetValues): Call facename_changed. If face name did change,
23 close old fonts and destroy xft_draw:s. Then create new ones.
24
25 * xlwmenu.h (XtNfaceName, XtCFaceName, XtNdefaultFace,
26 XtCDefaultFace): New.
27
28 * xlwmenuP.h (_window_state): Add max_rest_width and xft_draw.
29 (_XlwMenu_part): Add faceName,xft_fg, xft_bg, xft_disabled_fg and
30 xft_font.
31
12010-03-10 Chong Yidong <cyd@stupidchicken.com> 322010-03-10 Chong Yidong <cyd@stupidchicken.com>
2 33
3 * Branch for 23.2. 34 * Branch for 23.2.
diff --git a/lwlib/xlwmenu.c b/lwlib/xlwmenu.c
index 2ae7ae57e79..3e8259f9a19 100644
--- a/lwlib/xlwmenu.c
+++ b/lwlib/xlwmenu.c
@@ -30,6 +30,7 @@ Boston, MA 02110-1301, USA. */
30#include "lisp.h" 30#include "lisp.h"
31 31
32#include <stdio.h> 32#include <stdio.h>
33#include <ctype.h>
33 34
34#include <sys/types.h> 35#include <sys/types.h>
35#if (defined __sun) && !(defined SUNOS41) 36#if (defined __sun) && !(defined SUNOS41)
@@ -69,7 +70,7 @@ extern char *gray_bitmap_bits;
69static int pointer_grabbed; 70static int pointer_grabbed;
70static XEvent menu_post_event; 71static XEvent menu_post_event;
71 72
72XFontStruct *xlwmenu_default_font; 73static XFontStruct *xlwmenu_default_font;
73 74
74static char 75static char
75xlwMenuTranslations [] = 76xlwMenuTranslations [] =
@@ -128,6 +129,13 @@ xlwMenuResources[] =
128 {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet), 129 {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet),
129 offset(menu.fontSet), XtRFontSet, NULL}, 130 offset(menu.fontSet), XtRFontSet, NULL},
130#endif 131#endif
132#ifdef HAVE_XFT
133#define DEFAULT_FACENAME "Sans-10"
134 {XtNfaceName, XtCFaceName, XtRString, sizeof(String),
135 offset(menu.faceName), XtRString, DEFAULT_FACENAME},
136 {XtNdefaultFace, XtCDefaultFace, XtRInt, sizeof(int),
137 offset(menu.default_face), XtRImmediate, (XtPointer)1},
138#endif
131 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), 139 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
132 offset(menu.font), XtRString, "XtDefaultFont"}, 140 offset(menu.font), XtRString, "XtDefaultFont"},
133 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), 141 {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
@@ -352,10 +360,20 @@ string_width (mw, s)
352{ 360{
353 XCharStruct xcs; 361 XCharStruct xcs;
354 int drop; 362 int drop;
363#ifdef HAVE_XFT
364 if (mw->menu.xft_font)
365 {
366 XGlyphInfo gi;
367 XftTextExtentsUtf8 (XtDisplay (mw), mw->menu.xft_font,
368 (FcChar8 *) s,
369 strlen (s), &gi);
370 return gi.width;
371 }
372#endif
355#ifdef HAVE_X_I18N 373#ifdef HAVE_X_I18N
356 XRectangle ink, logical;
357 if (mw->menu.fontSet) 374 if (mw->menu.fontSet)
358 { 375 {
376 XRectangle ink, logical;
359 XmbTextExtents (mw->menu.fontSet, s, strlen (s), &ink, &logical); 377 XmbTextExtents (mw->menu.fontSet, s, strlen (s), &ink, &logical);
360 return logical.width; 378 return logical.width;
361 } 379 }
@@ -366,6 +384,20 @@ string_width (mw, s)
366 384
367} 385}
368 386
387#ifdef HAVE_XFT
388#define MENU_FONT_HEIGHT(mw) \
389 ((mw)->menu.xft_font != NULL \
390 ? (mw)->menu.xft_font->height \
391 : ((mw)->menu.fontSet != NULL \
392 ? (mw)->menu.font_extents->max_logical_extent.height \
393 : (mw)->menu.font->ascent + (mw)->menu.font->descent))
394#define MENU_FONT_ASCENT(mw) \
395 ((mw)->menu.xft_font != NULL \
396 ? (mw)->menu.xft_font->ascent \
397 : ((mw)->menu.fontSet != NULL \
398 ? - (mw)->menu.font_extents->max_logical_extent.y \
399 : (mw)->menu.font->ascent))
400#else
369#ifdef HAVE_X_I18N 401#ifdef HAVE_X_I18N
370#define MENU_FONT_HEIGHT(mw) \ 402#define MENU_FONT_HEIGHT(mw) \
371 ((mw)->menu.fontSet != NULL \ 403 ((mw)->menu.fontSet != NULL \
@@ -380,6 +412,7 @@ string_width (mw, s)
380 ((mw)->menu.font->ascent + (mw)->menu.font->descent) 412 ((mw)->menu.font->ascent + (mw)->menu.font->descent)
381#define MENU_FONT_ASCENT(mw) ((mw)->menu.font->ascent) 413#define MENU_FONT_ASCENT(mw) ((mw)->menu.font->ascent)
382#endif 414#endif
415#endif
383 416
384static int 417static int
385arrow_width (mw) 418arrow_width (mw)
@@ -559,6 +592,7 @@ size_menu (mw, level)
559 592
560 ws->width += 2 * mw->menu.shadow_thickness; 593 ws->width += 2 * mw->menu.shadow_thickness;
561 ws->height += 2 * mw->menu.shadow_thickness; 594 ws->height += 2 * mw->menu.shadow_thickness;
595 ws->max_rest_width = max_rest_width;
562 596
563 if (horizontal_p) 597 if (horizontal_p)
564 { 598 {
@@ -987,6 +1021,9 @@ display_menu_item (mw, val, ws, where, highlighted_p, horizontal_p,
987 int width; 1021 int width;
988 enum menu_separator separator; 1022 enum menu_separator separator;
989 int separator_p = lw_separator_p (val->name, &separator, 0); 1023 int separator_p = lw_separator_p (val->name, &separator, 0);
1024#ifdef HAVE_XFT
1025 XftColor *xftfg;
1026#endif
990 1027
991 /* compute the sizes of the item */ 1028 /* compute the sizes of the item */
992 size_menu_item (mw, val, horizontal_p, &label_width, &rest_width, 1029 size_menu_item (mw, val, horizontal_p, &label_width, &rest_width,
@@ -1024,6 +1061,9 @@ display_menu_item (mw, val, ws, where, highlighted_p, horizontal_p,
1024 else 1061 else
1025 text_gc = mw->menu.disabled_gc; 1062 text_gc = mw->menu.disabled_gc;
1026 deco_gc = mw->menu.foreground_gc; 1063 deco_gc = mw->menu.foreground_gc;
1064#ifdef HAVE_XFT
1065 xftfg = val->enabled ? &mw->menu.xft_fg : &mw->menu.xft_disabled_fg;
1066#endif
1027 1067
1028 if (separator_p) 1068 if (separator_p)
1029 { 1069 {
@@ -1048,6 +1088,21 @@ display_menu_item (mw, val, ws, where, highlighted_p, horizontal_p,
1048 x_offset += ws->button_width; 1088 x_offset += ws->button_width;
1049 1089
1050 1090
1091#ifdef HAVE_XFT
1092 if (ws->xft_draw)
1093 {
1094 int draw_y = y + v_spacing + shadow;
1095 XftDrawRect (ws->xft_draw, &mw->menu.xft_bg,
1096 x_offset, draw_y,
1097 ws->width, font_height);
1098 XftDrawStringUtf8 (ws->xft_draw, xftfg,
1099 mw->menu.xft_font,
1100 x_offset, draw_y + font_ascent,
1101 (unsigned char *) display_string,
1102 strlen (display_string));
1103 }
1104 else
1105#endif
1051#ifdef HAVE_X_I18N 1106#ifdef HAVE_X_I18N
1052 if (mw->menu.fontSet) 1107 if (mw->menu.fontSet)
1053 XmbDrawString (XtDisplay (mw), ws->window, mw->menu.fontSet, 1108 XmbDrawString (XtDisplay (mw), ws->window, mw->menu.fontSet,
@@ -1082,6 +1137,21 @@ display_menu_item (mw, val, ws, where, highlighted_p, horizontal_p,
1082 } 1137 }
1083 else if (val->key) 1138 else if (val->key)
1084 { 1139 {
1140#ifdef HAVE_XFT
1141 if (ws->xft_draw)
1142 {
1143 XGlyphInfo gi;
1144 int draw_x = ws->width - ws->max_rest_width
1145 + mw->menu.arrow_spacing;
1146 int draw_y = y + v_spacing + shadow + font_ascent;
1147 XftDrawStringUtf8 (ws->xft_draw, xftfg,
1148 mw->menu.xft_font,
1149 draw_x, draw_y,
1150 (unsigned char *) val->key,
1151 strlen (val->key));
1152 }
1153 else
1154#endif
1085#ifdef HAVE_X_I18N 1155#ifdef HAVE_X_I18N
1086 if (mw->menu.fontSet) 1156 if (mw->menu.fontSet)
1087 XmbDrawString (XtDisplay (mw), ws->window, 1157 XmbDrawString (XtDisplay (mw), ws->window,
@@ -1242,6 +1312,9 @@ make_windows_if_needed (mw, n)
1242 int mask; 1312 int mask;
1243 Window root = RootWindowOfScreen (DefaultScreenOfDisplay (XtDisplay (mw))); 1313 Window root = RootWindowOfScreen (DefaultScreenOfDisplay (XtDisplay (mw)));
1244 window_state* windows; 1314 window_state* windows;
1315#ifdef HAVE_XFT
1316 int screen = XScreenNumberOfScreen (mw->core.screen);
1317#endif
1245 1318
1246 if (mw->menu.windows_length >= n) 1319 if (mw->menu.windows_length >= n)
1247 return; 1320 return;
@@ -1280,10 +1353,21 @@ make_windows_if_needed (mw, n)
1280 windows [i].y = 0; 1353 windows [i].y = 0;
1281 windows [i].width = 1; 1354 windows [i].width = 1;
1282 windows [i].height = 1; 1355 windows [i].height = 1;
1356 windows [i].max_rest_width = 0;
1283 windows [i].window = 1357 windows [i].window =
1284 XCreateWindow (XtDisplay (mw), root, 0, 0, 1, 1, 1358 XCreateWindow (XtDisplay (mw), root, 0, 0, 1, 1,
1285 0, 0, CopyFromParent, CopyFromParent, mask, &xswa); 1359 0, 0, CopyFromParent, CopyFromParent, mask, &xswa);
1286 } 1360#ifdef HAVE_XFT
1361 if (mw->menu.xft_font)
1362 mw->menu.windows [i].xft_draw
1363 = XftDrawCreate (XtDisplay (mw),
1364 windows [i].window,
1365 DefaultVisual (XtDisplay (mw), screen),
1366 mw->core.colormap);
1367 else
1368 mw->menu.windows [i].xft_draw = 0;
1369#endif
1370 }
1287} 1371}
1288 1372
1289/* Value is non-zero if WINDOW is part of menu bar widget W. */ 1373/* Value is non-zero if WINDOW is part of menu bar widget W. */
@@ -1758,6 +1842,44 @@ release_shadow_gcs (mw)
1758 XtReleaseGC ((Widget) mw, mw->menu.shadow_bottom_gc); 1842 XtReleaseGC ((Widget) mw, mw->menu.shadow_bottom_gc);
1759} 1843}
1760 1844
1845#ifdef HAVE_XFT
1846static int
1847openXftFont (mw)
1848 XlwMenuWidget mw;
1849{
1850 char *fname = mw->menu.faceName;
1851
1852 mw->menu.xft_font = 0;
1853 mw->menu.default_face = fname && strcmp (fname, DEFAULT_FACENAME) == 0;
1854
1855 if (fname && strcmp (fname, "none") != 0)
1856 {
1857 int screen = XScreenNumberOfScreen (mw->core.screen);
1858 int len = strlen (fname), i = len-1;
1859 /* Try to convert Gtk-syntax (Sans 9) to Xft syntax Sans-9. */
1860 while (i > 0 && isdigit (fname[i]))
1861 --i;
1862 if (fname[i] == ' ')
1863 {
1864 fname = xstrdup (mw->menu.faceName);
1865 fname[i] = '-';
1866 }
1867
1868 mw->menu.xft_font = XftFontOpenName (XtDisplay (mw), screen, fname);
1869 if (!mw->menu.xft_font)
1870 {
1871 fprintf (stderr, "Can't find font '%s'\n", fname);
1872 mw->menu.xft_font = XftFontOpenName (XtDisplay (mw), screen,
1873 DEFAULT_FACENAME);
1874 }
1875 }
1876
1877 if (fname != mw->menu.faceName) free (fname);
1878
1879 return mw->menu.xft_font != 0;
1880}
1881#endif
1882
1761static void 1883static void
1762XlwMenuInitialize (request, mw, args, num_args) 1884XlwMenuInitialize (request, mw, args, num_args)
1763 Widget request; 1885 Widget request;
@@ -1779,7 +1901,7 @@ XlwMenuInitialize (request, mw, args, num_args)
1779 mw->menu.contents = tem; 1901 mw->menu.contents = tem;
1780#endif 1902#endif
1781 1903
1782/* mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */ 1904 /* mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */
1783 mw->menu.cursor = mw->menu.cursor_shape; 1905 mw->menu.cursor = mw->menu.cursor_shape;
1784 1906
1785 mw->menu.gray_pixmap 1907 mw->menu.gray_pixmap
@@ -1787,11 +1909,24 @@ XlwMenuInitialize (request, mw, args, num_args)
1787 gray_bitmap_width, gray_bitmap_height, 1909 gray_bitmap_width, gray_bitmap_height,
1788 (unsigned long)1, (unsigned long)0, 1); 1910 (unsigned long)1, (unsigned long)0, 1);
1789 1911
1790 /* I don't understand why this ends up 0 sometimes, 1912#ifdef HAVE_XFT
1791 but it does. This kludge works around it. 1913 if (openXftFont (mw))
1792 Can anyone find a real fix? -- rms. */ 1914 ;
1793 if (mw->menu.font == 0) 1915 else
1794 mw->menu.font = xlwmenu_default_font; 1916#endif
1917
1918 if (!mw->menu.font)
1919 {
1920 if (!xlwmenu_default_font)
1921 xlwmenu_default_font = XLoadQueryFont (display, "fixed");
1922 mw->menu.font = xlwmenu_default_font;
1923 if (!mw->menu.font)
1924 {
1925 fprintf (stderr, "Menu font fixed not found, can't continue.\n");
1926 abort ();
1927 }
1928 }
1929
1795#ifdef HAVE_X_I18N 1930#ifdef HAVE_X_I18N
1796 if (mw->menu.fontSet) 1931 if (mw->menu.fontSet)
1797 mw->menu.font_extents = XExtentsOfFontSet (mw->menu.fontSet); 1932 mw->menu.font_extents = XExtentsOfFontSet (mw->menu.fontSet);
@@ -1818,6 +1953,10 @@ XlwMenuInitialize (request, mw, args, num_args)
1818 mw->menu.windows [0].y = 0; 1953 mw->menu.windows [0].y = 0;
1819 mw->menu.windows [0].width = 0; 1954 mw->menu.windows [0].width = 0;
1820 mw->menu.windows [0].height = 0; 1955 mw->menu.windows [0].height = 0;
1956 mw->menu.windows [0].max_rest_width = 0;
1957#ifdef HAVE_XFT
1958 mw->menu.windows [0].xft_draw = 0;
1959#endif
1821 size_menu (mw, 0); 1960 size_menu (mw, 0);
1822 1961
1823 mw->core.width = mw->menu.windows [0].width; 1962 mw->core.width = mw->menu.windows [0].width;
@@ -1827,6 +1966,7 @@ XlwMenuInitialize (request, mw, args, num_args)
1827static void 1966static void
1828XlwMenuClassInitialize () 1967XlwMenuClassInitialize ()
1829{ 1968{
1969 xlwmenu_default_font = 0;
1830} 1970}
1831 1971
1832static void 1972static void
@@ -1861,6 +2001,38 @@ XlwMenuRealize (w, valueMask, attributes)
1861 mw->menu.windows [0].y = w->core.y; 2001 mw->menu.windows [0].y = w->core.y;
1862 mw->menu.windows [0].width = w->core.width; 2002 mw->menu.windows [0].width = w->core.width;
1863 mw->menu.windows [0].height = w->core.height; 2003 mw->menu.windows [0].height = w->core.height;
2004
2005#ifdef HAVE_XFT
2006 if (mw->menu.xft_font)
2007 {
2008 XColor colors[3];
2009 int screen = XScreenNumberOfScreen (mw->core.screen);
2010 mw->menu.windows [0].xft_draw
2011 = XftDrawCreate (XtDisplay (w),
2012 mw->menu.windows [0].window,
2013 DefaultVisual (XtDisplay (w), screen),
2014 mw->core.colormap);
2015 colors[0].pixel = mw->menu.xft_fg.pixel = mw->menu.foreground;
2016 colors[1].pixel = mw->menu.xft_bg.pixel = mw->core.background_pixel;
2017 colors[2].pixel = mw->menu.xft_disabled_fg.pixel
2018 = mw->menu.disabled_foreground;
2019 XQueryColors (XtDisplay (mw), mw->core.colormap, colors, 3);
2020 mw->menu.xft_fg.color.alpha = 0xFFFF;
2021 mw->menu.xft_fg.color.red = colors[0].red;
2022 mw->menu.xft_fg.color.green = colors[0].green;
2023 mw->menu.xft_fg.color.blue = colors[0].blue;
2024 mw->menu.xft_bg.color.alpha = 0xFFFF;
2025 mw->menu.xft_bg.color.red = colors[1].red;
2026 mw->menu.xft_bg.color.green = colors[1].green;
2027 mw->menu.xft_bg.color.blue = colors[1].blue;
2028 mw->menu.xft_disabled_fg.color.alpha = 0xFFFF;
2029 mw->menu.xft_disabled_fg.color.red = colors[2].red;
2030 mw->menu.xft_disabled_fg.color.green = colors[2].green;
2031 mw->menu.xft_disabled_fg.color.blue = colors[2].blue;
2032 }
2033 else
2034 mw->menu.windows [0].xft_draw = 0;
2035#endif
1864} 2036}
1865 2037
1866/* Only the toplevel menubar/popup is a widget so it's the only one that 2038/* Only the toplevel menubar/popup is a widget so it's the only one that
@@ -1942,13 +2114,37 @@ XlwMenuDestroy (w)
1942 client exits. Nice, eh? 2114 client exits. Nice, eh?
1943 */ 2115 */
1944 2116
2117#ifdef HAVE_XFT
2118 if (mw->menu.windows [0].xft_draw)
2119 XftDrawDestroy (mw->menu.windows [0].xft_draw);
2120 if (mw->menu.xft_font)
2121 XftFontClose (XtDisplay (mw), mw->menu.xft_font);
2122#endif
2123
1945 /* start from 1 because the one in slot 0 is w->core.window */ 2124 /* start from 1 because the one in slot 0 is w->core.window */
1946 for (i = 1; i < mw->menu.windows_length; i++) 2125 for (i = 1; i < mw->menu.windows_length; i++)
1947 XDestroyWindow (XtDisplay (mw), mw->menu.windows [i].window); 2126 {
2127 XDestroyWindow (XtDisplay (mw), mw->menu.windows [i].window);
2128#ifdef HAVE_XFT
2129 if (mw->menu.windows [i].xft_draw)
2130 XftDrawDestroy (mw->menu.windows [i].xft_draw);
2131#endif
2132 }
2133
1948 if (mw->menu.windows) 2134 if (mw->menu.windows)
1949 XtFree ((char *) mw->menu.windows); 2135 XtFree ((char *) mw->menu.windows);
1950} 2136}
1951 2137
2138static int
2139facename_changed (XlwMenuWidget newmw,
2140 XlwMenuWidget oldmw)
2141{
2142 /* This will fore a new XftFont even if the same sting is set.
2143 This is good, as rendering parameters may have changed and
2144 we just want to do a redisplay. */
2145 return newmw->menu.faceName != oldmw->menu.faceName;
2146}
2147
1952static Boolean 2148static Boolean
1953XlwMenuSetValues (current, request, new) 2149XlwMenuSetValues (current, request, new)
1954 Widget current; 2150 Widget current;
@@ -1972,6 +2168,9 @@ XlwMenuSetValues (current, request, new)
1972 2168
1973 if (newmw->core.background_pixel != oldmw->core.background_pixel 2169 if (newmw->core.background_pixel != oldmw->core.background_pixel
1974 || newmw->menu.foreground != oldmw->menu.foreground 2170 || newmw->menu.foreground != oldmw->menu.foreground
2171#ifdef HAVE_XFT
2172 || facename_changed (newmw, oldmw)
2173#endif
1975#ifdef HAVE_X_I18N 2174#ifdef HAVE_X_I18N
1976 || newmw->menu.fontSet != oldmw->menu.fontSet 2175 || newmw->menu.fontSet != oldmw->menu.fontSet
1977 || (newmw->menu.fontSet == NULL && newmw->menu.font != oldmw->menu.font) 2176 || (newmw->menu.fontSet == NULL && newmw->menu.font != oldmw->menu.font)
@@ -2004,6 +2203,29 @@ XlwMenuSetValues (current, request, new)
2004 } 2203 }
2005 } 2204 }
2006 2205
2206#ifdef HAVE_XFT
2207 if (facename_changed (newmw, oldmw))
2208 {
2209 int i;
2210 int screen = XScreenNumberOfScreen (newmw->core.screen);
2211 if (newmw->menu.xft_font)
2212 XftFontClose (XtDisplay (newmw), newmw->menu.xft_font);
2213 openXftFont (newmw);
2214 for (i = 0; i < newmw->menu.windows_length; i++)
2215 {
2216 if (newmw->menu.windows [i].xft_draw)
2217 XftDrawDestroy (newmw->menu.windows [i].xft_draw);
2218 newmw->menu.windows [i].xft_draw = 0;
2219 }
2220 if (newmw->menu.xft_font)
2221 for (i = 0; i < newmw->menu.windows_length; i++)
2222 newmw->menu.windows [i].xft_draw
2223 = XftDrawCreate (XtDisplay (newmw),
2224 newmw->menu.windows [i].window,
2225 DefaultVisual (XtDisplay (newmw), screen),
2226 newmw->core.colormap);
2227 }
2228#endif
2007#ifdef HAVE_X_I18N 2229#ifdef HAVE_X_I18N
2008 if (newmw->menu.fontSet != oldmw->menu.fontSet && newmw->menu.fontSet != NULL) 2230 if (newmw->menu.fontSet != oldmw->menu.fontSet && newmw->menu.fontSet != NULL)
2009 { 2231 {
diff --git a/lwlib/xlwmenu.h b/lwlib/xlwmenu.h
index 4f2c6cc4452..a58fd00c1e3 100644
--- a/lwlib/xlwmenu.h
+++ b/lwlib/xlwmenu.h
@@ -58,6 +58,10 @@ Boston, MA 02110-1301, USA. */
58#define XtCResizeToPreferred "ResizeToPreferred" 58#define XtCResizeToPreferred "ResizeToPreferred"
59#define XtNallowResize "allowResize" 59#define XtNallowResize "allowResize"
60#define XtCAllowResize "AllowResize" 60#define XtCAllowResize "AllowResize"
61#define XtNfaceName "faceName"
62#define XtCFaceName "FaceName"
63#define XtNdefaultFace "defaultFace"
64#define XtCDefaultFace "DefaultFace"
61 65
62/* Motif-compatible resource names */ 66/* Motif-compatible resource names */
63#define XmNshadowThickness "shadowThickness" 67#define XmNshadowThickness "shadowThickness"
diff --git a/lwlib/xlwmenuP.h b/lwlib/xlwmenuP.h
index e98d657bfa0..39afcc6ca7f 100644
--- a/lwlib/xlwmenuP.h
+++ b/lwlib/xlwmenuP.h
@@ -25,6 +25,9 @@ Boston, MA 02110-1301, USA. */
25 25
26#include "xlwmenu.h" 26#include "xlwmenu.h"
27#include <X11/CoreP.h> 27#include <X11/CoreP.h>
28#ifdef HAVE_XFT
29#include <X11/Xft/Xft.h>
30#endif
28 31
29/* Elements in the stack arrays. */ 32/* Elements in the stack arrays. */
30typedef struct _window_state 33typedef struct _window_state
@@ -35,9 +38,13 @@ typedef struct _window_state
35 Dimension width; 38 Dimension width;
36 Dimension height; 39 Dimension height;
37 Dimension label_width; 40 Dimension label_width;
41 int max_rest_width;
38 42
39 /* Width of toggle buttons or radio buttons. */ 43 /* Width of toggle buttons or radio buttons. */
40 Dimension button_width; 44 Dimension button_width;
45#ifdef HAVE_XFT
46 XftDraw* xft_draw;
47#endif
41} window_state; 48} window_state;
42 49
43 50
@@ -49,6 +56,12 @@ typedef struct _XlwMenu_part
49 XFontSet fontSet; 56 XFontSet fontSet;
50 XFontSetExtents *font_extents; 57 XFontSetExtents *font_extents;
51#endif 58#endif
59#ifdef HAVE_XFT
60 String faceName;
61 int default_face;
62 XftFont* xft_font;
63 XftColor xft_fg, xft_bg, xft_disabled_fg;
64#endif
52 XFontStruct* font; 65 XFontStruct* font;
53 Pixel foreground; 66 Pixel foreground;
54 Pixel disabled_foreground; 67 Pixel disabled_foreground;
diff --git a/src/ChangeLog b/src/ChangeLog
index 455deff0aae..51ed028b9d5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,29 @@
12010-04-08 Jan Djärv <jan.h.d@swipnet.se>
2
3 * xsettings.c (current_font, SYSTEM_FONT, XSETTINGS_FONT_NAME): New.
4 (parse_xft_settings): Also check for XSETTINGS_FONT_NAME and save that
5 in current_font.
6 (init_gconf): Read value of SYSTEM_FONT and save it in current_font.
7 (Ffont_get_system_normal_font, xsettings_get_system_normal_font): New
8 functions.
9 (syms_of_xsettings): Initialize current_font. defsubr
10 Sfont_get_system_normal_font.
11
12 * xsettings.h (Ffont_get_system_normal_font,
13 xsettings_get_system_normal_font): Declare.
14
15 * xfns.c (extern xlwmenu_default_font): Remove.
16 (Fx_create_frame): Remove setting of xlwmenu_default_font, moved
17 to xlwmenu.c.
18
19 * menu.c (digest_single_submenu): If USE_LUCID and HAVE_XFT, encode
20 menu items in UTF-8.
21
22 * xmenu.c: include xsettings.h and xlwmenu.h if USE_LUCID.
23 (apply_systemfont_to_menu): New function.
24 (set_frame_menubar, create_and_show_popup_menu): Call
25 apply_systemfont_to_menu.
26
12010-04-07 Jan Djärv <jan.h.d@swipnet.se> 272010-04-07 Jan Djärv <jan.h.d@swipnet.se>
2 28
3 * frame.h (FRAME_TEXT_LINES_TO_PIXEL_HEIGHT): Don't use 29 * frame.h (FRAME_TEXT_LINES_TO_PIXEL_HEIGHT): Don't use
diff --git a/src/menu.c b/src/menu.c
index bfe54a53328..ca00c06a98b 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -697,6 +697,12 @@ digest_single_submenu (start, end, top_level_items)
697 697
698 ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name); 698 ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name);
699 } 699 }
700#elif defined (USE_LUCID) && defined (HAVE_XFT)
701 if (STRINGP (pane_name))
702 {
703 pane_name = ENCODE_UTF_8 (pane_name);
704 ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name);
705 }
700#elif !defined (HAVE_MULTILINGUAL_MENU) 706#elif !defined (HAVE_MULTILINGUAL_MENU)
701 if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name)) 707 if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name))
702 { 708 {
@@ -770,6 +776,18 @@ digest_single_submenu (start, end, top_level_items)
770 descrip = ENCODE_SYSTEM (descrip); 776 descrip = ENCODE_SYSTEM (descrip);
771 ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip); 777 ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip);
772 } 778 }
779#elif USE_LUCID
780 if (STRINGP (item_name))
781 {
782 item_name = ENCODE_UTF_8 (item_name);
783 ASET (menu_items, i + MENU_ITEMS_ITEM_NAME, item_name);
784 }
785
786 if (STRINGP (descrip))
787 {
788 descrip = ENCODE_UTF_8 (descrip);
789 ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip);
790 }
773#elif !defined (HAVE_MULTILINGUAL_MENU) 791#elif !defined (HAVE_MULTILINGUAL_MENU)
774 if (STRING_MULTIBYTE (item_name)) 792 if (STRING_MULTIBYTE (item_name))
775 { 793 {
diff --git a/src/xfns.c b/src/xfns.c
index 4ec13b7e50d..647526cc22b 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -110,11 +110,6 @@ extern void _XEditResCheckMessages ();
110 110
111extern LWLIB_ID widget_id_tick; 111extern LWLIB_ID widget_id_tick;
112 112
113#ifdef USE_LUCID
114/* This is part of a kludge--see lwlib/xlwmenu.c. */
115extern XFontStruct *xlwmenu_default_font;
116#endif
117
118extern void free_frame_menubar (); 113extern void free_frame_menubar ();
119extern double atof (); 114extern double atof ();
120 115
@@ -3379,14 +3374,6 @@ This function is an internal primitive--use `make-frame' instead. */)
3379 error ("Invalid frame font"); 3374 error ("Invalid frame font");
3380 } 3375 }
3381 3376
3382#ifdef USE_LUCID
3383 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3384 whereby it fails to get any font. */
3385 BLOCK_INPUT;
3386 xlwmenu_default_font = XLoadQueryFont (FRAME_X_DISPLAY (f), "fixed");
3387 UNBLOCK_INPUT;
3388#endif
3389
3390 /* Frame contents get displaced if an embedded X window has a border. */ 3377 /* Frame contents get displaced if an embedded X window has a border. */
3391 if (! FRAME_X_EMBEDDED_P (f)) 3378 if (! FRAME_X_EMBEDDED_P (f))
3392 x_default_parameter (f, parms, Qborder_width, make_number (2), 3379 x_default_parameter (f, parms, Qborder_width, make_number (2),
diff --git a/src/xmenu.c b/src/xmenu.c
index 64e55b7413c..de2f4eb6815 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -81,6 +81,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
81#include <X11/StringDefs.h> 81#include <X11/StringDefs.h>
82#include <X11/Shell.h> 82#include <X11/Shell.h>
83#ifdef USE_LUCID 83#ifdef USE_LUCID
84#include "xsettings.h"
85#include "../lwlib/xlwmenu.h"
84#ifdef HAVE_XAW3D 86#ifdef HAVE_XAW3D
85#include <X11/Xaw3d/Paned.h> 87#include <X11/Xaw3d/Paned.h>
86#else /* !HAVE_XAW3D */ 88#else /* !HAVE_XAW3D */
@@ -950,6 +952,36 @@ update_frame_menubar (f)
950 return 1; 952 return 1;
951} 953}
952 954
955#ifdef USE_LUCID
956static void
957apply_systemfont_to_menu (w)
958 Widget w;
959{
960 const char *fn = xsettings_get_system_normal_font ();
961 int defflt;
962
963 if (!fn) return;
964
965 if (XtIsShell (w)) /* popup menu */
966 {
967 Widget *childs[1];
968 int num = 0;
969
970 XtVaGetValues (w, XtNnumChildren, &num, NULL);
971 if (num != 1) return; /* Should only be one. */
972
973 childs[0] = 0;
974 XtVaGetValues (w, XtNchildren, childs, NULL);
975 if (childs[0] && *childs[0]) w = *childs[0];
976 }
977
978 /* Only use system font if the default is used for the menu. */
979 XtVaGetValues (w, XtNdefaultFace, &defflt, NULL);
980 if (defflt)
981 XtVaSetValues (w, XtNfaceName, fn, NULL);
982}
983#endif
984
953/* Set the contents of the menubar widgets of frame F. 985/* Set the contents of the menubar widgets of frame F.
954 The argument FIRST_TIME is currently ignored; 986 The argument FIRST_TIME is currently ignored;
955 it is set the first time this is called, from initialize_frame_menubar. */ 987 it is set the first time this is called, from initialize_frame_menubar. */
@@ -1262,6 +1294,7 @@ set_frame_menubar (f, first_time, deep_p)
1262 1294
1263 /* Make menu pop down on C-g. */ 1295 /* Make menu pop down on C-g. */
1264 XtOverrideTranslations (menubar_widget, override); 1296 XtOverrideTranslations (menubar_widget, override);
1297 apply_systemfont_to_menu (menubar_widget);
1265 } 1298 }
1266 1299
1267 { 1300 {
@@ -1608,6 +1641,8 @@ create_and_show_popup_menu (f, first_wv, x, y, for_click, timestamp)
1608 popup_deactivate_callback, 1641 popup_deactivate_callback,
1609 menu_highlight_callback); 1642 menu_highlight_callback);
1610 1643
1644 apply_systemfont_to_menu (menu);
1645
1611 dummy.type = ButtonPress; 1646 dummy.type = ButtonPress;
1612 dummy.serial = 0; 1647 dummy.serial = 0;
1613 dummy.send_event = 0; 1648 dummy.send_event = 0;
diff --git a/src/xsettings.c b/src/xsettings.c
index 945007db2f0..b71871df573 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -39,6 +39,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
39#endif 39#endif
40 40
41static char *current_mono_font; 41static char *current_mono_font;
42static char *current_font;
42static struct x_display_info *first_dpyinfo; 43static struct x_display_info *first_dpyinfo;
43static Lisp_Object Qfont_name, Qfont_render; 44static Lisp_Object Qfont_name, Qfont_render;
44static int use_system_font; 45static int use_system_font;
@@ -65,7 +66,9 @@ store_font_changed_event (arg, display_name)
65 66
66#ifdef HAVE_GCONF 67#ifdef HAVE_GCONF
67 68
68#define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name" 69#define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
70#define SYSTEM_FONT "/desktop/gnome/interface/font_name"
71#define XSETTINGS_FONT_NAME "Gtk/FontName"
69 72
70/* Callback called when something changed in GConf that we care about, 73/* Callback called when something changed in GConf that we care about,
71 that is SYSTEM_MONO_FONT. */ 74 that is SYSTEM_MONO_FONT. */
@@ -235,7 +238,7 @@ parse_xft_settings (prop, bytes, settings)
235 238
236 memset (settings, 0, sizeof (*settings)); 239 memset (settings, 0, sizeof (*settings));
237 240
238 while (bytes_parsed+4 < bytes && settings_seen < 6 241 while (bytes_parsed+4 < bytes && settings_seen < 7
239 && i < n_settings) 242 && i < n_settings)
240 { 243 {
241 int type = prop[bytes_parsed++]; 244 int type = prop[bytes_parsed++];
@@ -243,7 +246,7 @@ parse_xft_settings (prop, bytes, settings)
243 CARD32 vlen, ival = 0; 246 CARD32 vlen, ival = 0;
244 char name[128]; /* The names we are looking for are not this long. */ 247 char name[128]; /* The names we are looking for are not this long. */
245 char sval[128]; /* The values we are looking for are not this long. */ 248 char sval[128]; /* The values we are looking for are not this long. */
246 int is_xft; 249 int want_this;
247 int to_cpy; 250 int to_cpy;
248 251
249 sval[0] = '\0'; 252 sval[0] = '\0';
@@ -264,13 +267,14 @@ parse_xft_settings (prop, bytes, settings)
264 bytes_parsed += 4; /* Skip serial for this value */ 267 bytes_parsed += 4; /* Skip serial for this value */
265 if (bytes_parsed > bytes) return BadLength; 268 if (bytes_parsed > bytes) return BadLength;
266 269
267 is_xft = nlen > 6 && strncmp (name, "Xft/", 4) == 0; 270 want_this = (nlen > 6 && strncmp (name, "Xft/", 4) == 0)
271 || (strcmp (XSETTINGS_FONT_NAME, name) == 0);
268 272
269 switch (type) 273 switch (type)
270 { 274 {
271 case 0: /* Integer */ 275 case 0: /* Integer */
272 if (bytes_parsed+4 > bytes) return BadLength; 276 if (bytes_parsed+4 > bytes) return BadLength;
273 if (is_xft) 277 if (want_this)
274 { 278 {
275 memcpy (&ival, prop+bytes_parsed, 4); 279 memcpy (&ival, prop+bytes_parsed, 4);
276 if (my_bo != that_bo) ival = SWAP32 (ival); 280 if (my_bo != that_bo) ival = SWAP32 (ival);
@@ -283,7 +287,7 @@ parse_xft_settings (prop, bytes, settings)
283 memcpy (&vlen, prop+bytes_parsed, 4); 287 memcpy (&vlen, prop+bytes_parsed, 4);
284 bytes_parsed += 4; 288 bytes_parsed += 4;
285 if (my_bo != that_bo) vlen = SWAP32 (vlen); 289 if (my_bo != that_bo) vlen = SWAP32 (vlen);
286 if (is_xft) 290 if (want_this)
287 { 291 {
288 to_cpy = vlen > 127 ? 127 : vlen; 292 to_cpy = vlen > 127 ? 127 : vlen;
289 memcpy (sval, prop+bytes_parsed, to_cpy); 293 memcpy (sval, prop+bytes_parsed, to_cpy);
@@ -303,7 +307,7 @@ parse_xft_settings (prop, bytes, settings)
303 return BadValue; 307 return BadValue;
304 } 308 }
305 309
306 if (is_xft) 310 if (want_this)
307 { 311 {
308 ++settings_seen; 312 ++settings_seen;
309 if (strcmp (name, "Xft/Antialias") == 0) 313 if (strcmp (name, "Xft/Antialias") == 0)
@@ -361,6 +365,11 @@ parse_xft_settings (prop, bytes, settings)
361 else 365 else
362 settings->seen &= ~SEEN_LCDFILTER; 366 settings->seen &= ~SEEN_LCDFILTER;
363 } 367 }
368 else if (strcmp (name, XSETTINGS_FONT_NAME) == 0)
369 {
370 free (current_font);
371 current_font = xstrdup (sval);
372 }
364 } 373 }
365 } 374 }
366 375
@@ -571,6 +580,12 @@ init_gconf ()
571 current_mono_font = xstrdup (s); 580 current_mono_font = xstrdup (s);
572 g_free (s); 581 g_free (s);
573 } 582 }
583 s = gconf_client_get_string (gconf_client, SYSTEM_FONT, NULL);
584 if (s)
585 {
586 current_font = xstrdup (s);
587 g_free (s);
588 }
574 gconf_client_set_error_handling (gconf_client, GCONF_CLIENT_HANDLE_NONE); 589 gconf_client_set_error_handling (gconf_client, GCONF_CLIENT_HANDLE_NONE);
575 gconf_client_add_dir (gconf_client, 590 gconf_client_add_dir (gconf_client,
576 SYSTEM_MONO_FONT, 591 SYSTEM_MONO_FONT,
@@ -635,6 +650,23 @@ xsettings_get_system_font ()
635 return current_mono_font; 650 return current_mono_font;
636} 651}
637 652
653const char *
654xsettings_get_system_normal_font ()
655{
656 return current_font;
657}
658
659DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font,
660 Sfont_get_system_normal_font,
661 0, 0, 0,
662 doc: /* Get the system default font. */)
663 ()
664{
665 return current_font && use_system_font
666 ? make_string (current_font, strlen (current_font))
667 : Qnil;
668}
669
638DEFUN ("font-get-system-font", Ffont_get_system_font, Sfont_get_system_font, 670DEFUN ("font-get-system-font", Ffont_get_system_font, Sfont_get_system_font,
639 0, 0, 0, 671 0, 0, 0,
640 doc: /* Get the system default monospaced font. */) 672 doc: /* Get the system default monospaced font. */)
@@ -649,6 +681,7 @@ void
649syms_of_xsettings () 681syms_of_xsettings ()
650{ 682{
651 current_mono_font = NULL; 683 current_mono_font = NULL;
684 current_font = NULL;
652 first_dpyinfo = NULL; 685 first_dpyinfo = NULL;
653#ifdef HAVE_GCONF 686#ifdef HAVE_GCONF
654 gconf_client = NULL; 687 gconf_client = NULL;
@@ -659,6 +692,7 @@ syms_of_xsettings ()
659 Qfont_render = intern_c_string ("font-render"); 692 Qfont_render = intern_c_string ("font-render");
660 staticpro (&Qfont_render); 693 staticpro (&Qfont_render);
661 defsubr (&Sfont_get_system_font); 694 defsubr (&Sfont_get_system_font);
695 defsubr (&Sfont_get_system_normal_font);
662 696
663 DEFVAR_BOOL ("font-use-system-font", &use_system_font, 697 DEFVAR_BOOL ("font-use-system-font", &use_system_font,
664 doc: /* *Non-nil means to use the system defined font. */); 698 doc: /* *Non-nil means to use the system defined font. */);
diff --git a/src/xsettings.h b/src/xsettings.h
index 6c603e5bbd9..f6399ea1bcc 100644
--- a/src/xsettings.h
+++ b/src/xsettings.h
@@ -21,10 +21,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21#define XSETTINGS_H 21#define XSETTINGS_H
22 22
23EXFUN (Ffont_get_system_font, 0); 23EXFUN (Ffont_get_system_font, 0);
24EXFUN (Ffont_get_system_normal_font, 0);
25
24extern void xsettings_initialize P_ ((struct x_display_info *dpyinfo)); 26extern void xsettings_initialize P_ ((struct x_display_info *dpyinfo));
25extern void xft_settings_event P_ ((struct x_display_info *dpyinfo, 27extern void xft_settings_event P_ ((struct x_display_info *dpyinfo,
26 XEvent *)); 28 XEvent *));
27extern const char *xsettings_get_system_font P_ ((void)); 29extern const char *xsettings_get_system_font P_ ((void));
30extern const char *xsettings_get_system_normal_font P_ ((void));
28 31
29 32
30#endif /* XSETTINGS_H */ 33#endif /* XSETTINGS_H */