diff --git a/autogen.sh b/autogen.sh index 5a1be80..d6cbd45 100755 --- a/autogen.sh +++ b/autogen.sh @@ -28,4 +28,4 @@ if [ x"$1" = x-f ] else am_opt='--copy' fi -aclocal && autoheader && automake -a $am_opt && autoconf +aclocal -I m4 && autoheader && automake -a $am_opt && autoconf diff --git a/configure.in b/configure.in index 08f4ee8..51cf3ad 100644 --- a/configure.in +++ b/configure.in @@ -148,6 +148,6 @@ dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for library functions. AC_CHECK_FUNCS(getopt getopt_long setsid setpgid setpgrp putenv vsnprintf usleep getline) -AC_TYPE_SIGNAL +AM_LANGINFO_CODESET AC_OUTPUT(Makefile doc/Makefile src/Makefile contrib/Makefile) diff --git a/m4/codeset.m4 b/m4/codeset.m4 new file mode 100644 index 0000000..a53c042 --- /dev/null +++ b/m4/codeset.m4 @@ -0,0 +1,21 @@ +# codeset.m4 serial 4 (gettext-0.18) +dnl Copyright (C) 2000-2002, 2006, 2008-2010 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +AC_DEFUN([AM_LANGINFO_CODESET], +[ + AC_CACHE_CHECK([for nl_langinfo and CODESET], [am_cv_langinfo_codeset], + [AC_TRY_LINK([#include ], + [char* cs = nl_langinfo(CODESET); return !cs;], + [am_cv_langinfo_codeset=yes], + [am_cv_langinfo_codeset=no]) + ]) + if test $am_cv_langinfo_codeset = yes; then + AC_DEFINE([HAVE_LANGINFO_CODESET], [1], + [Define if you have and nl_langinfo(CODESET).]) + fi +]) diff --git a/src/data.h b/src/data.h index 541ca9e..4251d3f 100644 --- a/src/data.h +++ b/src/data.h @@ -235,6 +235,9 @@ struct rp_defaults XFontSet font; char *font_string; +#ifdef USE_XFT_FONT + int utf8_xft; +#endif char *fgcolor_string; char *bgcolor_string; diff --git a/src/globals.c b/src/globals.c index 3029aef..7b679bf 100644 --- a/src/globals.c +++ b/src/globals.c @@ -289,15 +289,23 @@ rp_draw_string (rp_screen *s, Drawable d, int style, int x, int y, char *string, DefaultColormap (dpy, s->screen_num)); if (draw) { - XftDrawString8 (draw, style == STYLE_NORMAL ? &s->xft_fg_color:&s->xft_bg_color, s->xft_font, x, y, (FcChar8*) string, length); + if (defaults.utf8_xft) + XftDrawStringUtf8 (draw, style == STYLE_NORMAL ? &s->xft_fg_color:&s->xft_bg_color, s->xft_font, x, y, (FcChar8*) string, length); + else + XftDrawString8 (draw, style == STYLE_NORMAL ? &s->xft_fg_color:&s->xft_bg_color, s->xft_font, x, y, (FcChar8*) string, length); XftDrawDestroy (draw); } else PRINT_ERROR(("Failed to allocate XftDraw object\n")); } else -#endif - XmbDrawString (dpy, d, defaults.font, style == STYLE_NORMAL ? s->normal_gc:s->inverse_gc, x, y, string, length); +# ifdef X_HAVE_UTF8_STRING + if (defaults.utf8_xft) + Xutf8DrawString (dpy, d, defaults.font, style == STYLE_NORMAL ? s->normal_gc:s->inverse_gc, x, y, string, length); + else +# endif /* X_HAVE_UTF8_STRING */ +#endif /* USE_XFT_FONT */ + XmbDrawString (dpy, d, defaults.font, style == STYLE_NORMAL ? s->normal_gc:s->inverse_gc, x, y, string, length); } int @@ -314,11 +322,19 @@ rp_text_width (rp_screen *s UNUSED, XFontSet font, char *string, int count) if (s->xft_font) { XGlyphInfo extents; - XftTextExtents8 (dpy, s->xft_font, (FcChar8*) string, count, &extents); + if (defaults.utf8_xft) + XftTextExtentsUtf8 (dpy, s->xft_font, (FcChar8*) string, count, &extents); + else + XftTextExtents8 (dpy, s->xft_font, (FcChar8*) string, count, &extents); return extents.xOff; } else -#endif - return XmbTextEscapement (font, string, count); +# ifdef X_HAVE_UTF8_STRING + if (defaults.utf8_xft) + return Xutf8TextEscapement (font, string, count); + else +# endif /* X_HAVE_UTF8_STRING */ +#endif /* USE_XFT_FONT */ + return XmbTextEscapement (font, string, count); } diff --git a/src/main.c b/src/main.c index 417fc1a..688a355 100644 --- a/src/main.c +++ b/src/main.c @@ -38,6 +38,10 @@ #include "ratpoison.h" +#ifdef HAVE_LANGINFO_CODESET +# include +#endif + /* Several systems seem not to have WAIT_ANY defined, so define it if it isn't. */ #ifndef WAIT_ANY @@ -169,7 +173,7 @@ strtok_ws (char *s) if (s) pointer = s; - + /* skip to first non-whitespace char. */ while (*pointer && isspace (*pointer)) pointer++; @@ -528,6 +532,9 @@ init_defaults (void) #ifdef USE_XFT_FONT defaults.font_string = xstrdup (DEFAULT_XFT_FONT); +# ifdef HAVE_LANGINFO_CODESET + defaults.utf8_xft = !strcmp (nl_langinfo (CODESET), "UTF-8"); +# endif /* default to 0 if nl_langinfo is unavailable */ #else /* Attempt to load a font */ defaults.font = load_query_font_set (dpy, DEFAULT_FONT); diff --git a/src/manage.c b/src/manage.c index f822c53..d9eb630 100644 --- a/src/manage.c +++ b/src/manage.c @@ -204,7 +204,12 @@ get_wmname (Window w) char** cl; if (XGetWMName(dpy, w, &text_prop) != 0) { - status = XmbTextPropertyToTextList(dpy, &text_prop, &cl, &n); +#if defined (USE_XFT_FONT) && defined (X_HAVE_UTF8_STRING) + if (defaults.utf8_xft) + status = Xutf8TextPropertyToTextList (dpy, &text_prop, &cl, &n); + else +#endif + status = XmbTextPropertyToTextList(dpy, &text_prop, &cl, &n); if (status == Success && cl && n > 0) { name = xstrdup(cl[0]); XFreeStringList(cl);