From 73e02934d68dfaf04bbb36dbb2e3b52b042c65bb Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Sun, 9 Aug 2020 12:21:37 +0530 Subject: Conditional encoding of xft string --- src/Xmobar/X11/MinXft.hsc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Xmobar/X11/MinXft.hsc b/src/Xmobar/X11/MinXft.hsc index acc60b2..22edf8f 100644 --- a/src/Xmobar/X11/MinXft.hsc +++ b/src/Xmobar/X11/MinXft.hsc @@ -161,10 +161,16 @@ withAXftDraw d p v c act = do foreign import ccall "XftDrawStringUtf8" cXftDrawStringUtf8 :: AXftDraw -> AXftColor -> AXftFont -> CInt -> CInt -> Ptr (#type FcChar8) -> CInt -> IO () +utf8EncodeString :: Num b => String -> [b] +utf8EncodeString str = if UTF8.isUTF8Encoded str + then map (fi . ord) str + else map fi (UTF8.encode str) + + drawXftString :: (Integral a1, Integral a) => AXftDraw -> AXftColor -> AXftFont -> a -> a1 -> String -> IO () drawXftString d c f x y string = - withArrayLen (map (fi . ord) string) + withArrayLen (utf8EncodeString string) (\len ptr -> cXftDrawStringUtf8 d c f (fi x) (fi y) ptr (fi len)) drawXftString' :: AXftDraw -> -- cgit v1.2.3