ratpoison-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RP] [PATCH] if compiling with xft, hardcode encoding to utf-8


From: Bernhard R. Link
Subject: [RP] [PATCH] if compiling with xft, hardcode encoding to utf-8
Date: Wed, 27 Jun 2012 18:29:09 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Unlike the X primitives, Xft does not seem to support
utf-8 when drawing a string encoded according to the current
locale. So if compiling with Xft, hardcode the encoding to be
used to utf-8.
---
 src/events.c  |    4 ++++
 src/globals.c |   12 ++++++++----
 src/manage.c  |    4 ++++
 3 files changed, 16 insertions(+), 4 deletions(-)

 This has the side effect of command line utilities always
 outputting everything as utf-8 -- no matter what the locale is.
 (But as they use the locale of the ratpoison running as WM
 and not the one outputting the data, I guess that is not much worse).

diff --git a/src/events.c b/src/events.c
index 0a5d759..1154190 100644
--- a/src/events.c
+++ b/src/events.c
@@ -776,7 +776,11 @@ selection_request (XSelectionRequestEvent *rq)
         : XStdICCTextStyle;
     }
     cl[0] = selection.text;
+#ifdef USE_XFT_FONT
+    Xutf8TextListToTextProperty(dpy, cl, 1, style, &ct);
+#else
     XmbTextListToTextProperty(dpy, cl, 1, style, &ct);
+#endif
     XChangeProperty(dpy, rq->requestor, rq->property,
                     target, 8, PropModeReplace,
                     ct.value, ct.nitems);
diff --git a/src/globals.c b/src/globals.c
index 3029aef..c9e1bfd 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -289,15 +289,17 @@ 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);
+          XftDrawStringUtf8 (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
+    Xutf8DrawString (dpy, d, defaults.font, style == STYLE_NORMAL ? 
s->normal_gc:s->inverse_gc, x, y, string, length);
+#else
     XmbDrawString (dpy, d, defaults.font, style == STYLE_NORMAL ? 
s->normal_gc:s->inverse_gc, x, y, string, length);
+#endif
 }
 
 int
@@ -314,11 +316,13 @@ 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);
+      XftTextExtentsUtf8 (dpy, s->xft_font, (FcChar8*) string, count, 
&extents);
       return extents.xOff;
     }
   else
-#endif
+    return Xutf8TextEscapement (font, string, count);
+#else
     return XmbTextEscapement (font, string, count);
+#endif
 }
 
diff --git a/src/manage.c b/src/manage.c
index f822c53..60443ca 100644
--- a/src/manage.c
+++ b/src/manage.c
@@ -204,7 +204,11 @@ get_wmname (Window w)
   char** cl;
 
   if (XGetWMName(dpy, w, &text_prop) != 0) {
+#ifdef USE_XFT_FONT
+    status = Xutf8TextPropertyToTextList(dpy, &text_prop, &cl, &n);
+#else
     status = XmbTextPropertyToTextList(dpy, &text_prop, &cl, &n);
+#endif
     if (status == Success && cl && n > 0) {
       name = xstrdup(cl[0]);
       XFreeStringList(cl);
-- 
1.7.10




reply via email to

[Prev in Thread] Current Thread [Next in Thread]