New patches: [Add functions to draw text in the user's locale Mats Jansborg **20070818235123 Added the FontSet type as well as the functions createFontSet, freeFontSet, wcTextExtents and wcDrawString that can be used to draw internationalised text. ] { hunk ./Graphics/X11/Xlib/Extras.hsc 667 -foreign import ccall unsafe "XlibExtras.h XFetchName" - xFetchName :: Display -> Window -> Ptr CString -> IO Status - hunk ./Graphics/X11/Xlib/Extras.hsc 716 +newtype FontSet = FontSet (Ptr FontSet) + deriving (Eq, Ord, Show) + +foreign import ccall unsafe "XlibExtras.h XCreateFontSet" + xCreateFontSet :: Display -> CString -> Ptr (Ptr CString) -> Ptr CInt -> Ptr CString -> IO (Ptr FontSet) + +createFontSet :: Display -> String -> IO ([String], String, FontSet) +createFontSet d fn = + withCString fn $ \fontp -> + alloca $ \listp -> + alloca $ \countp -> + alloca $ \defp -> do + fs <- throwIfNull "createFontSet" $ + xCreateFontSet d fontp listp countp defp + count <- peek countp + list <- peek listp + missing <- flip mapM [0..fromIntegral count - 1] $ \i -> + peekElemOff list i >>= peekCString + def <- peek defp >>= peekCString + freeStringList list + return (missing, def, FontSet fs) + +foreign import ccall unsafe "XlibExtras.h XFreeStringList" + freeStringList :: Ptr CString -> IO () + +foreign import ccall unsafe "XlibExtras.h XFreeFontSet" + freeFontSet :: Display -> FontSet -> IO () + +foreign import ccall unsafe "XlibExtras.h XwcTextExtents" + xwcTextExtents :: FontSet -> CWString -> CInt -> Ptr Rectangle -> Ptr Rectangle -> IO CInt + +wcTextExtents :: FontSet -> String -> (Rectangle, Rectangle) +wcTextExtents fs text = unsafePerformIO $ + withCWStringLen text $ \(textp, len) -> + alloca $ \inkp -> + alloca $ \logicalp -> do + xwcTextExtents fs textp (fromIntegral len) inkp logicalp + (,) `fmap` peek inkp `ap` peek logicalp + +foreign import ccall unsafe "XlibExtras.h XwcDrawString" + xwcDrawString :: Display -> Drawable -> FontSet -> GC -> CInt -> CInt -> CWString -> CInt -> IO () + +wcDrawString :: Display -> Drawable -> FontSet -> GC -> CInt -> CInt -> String -> IO () +wcDrawString d w fs gc x y = + flip withCWStringLen $ \(s, len) -> + xwcDrawString d w fs gc x y s (fromIntegral len) + +foreign import ccall unsafe "XlibExtras.h XFetchName" + xFetchName :: Display -> Window -> Ptr CString -> IO Status + } [Add getGCForeground which returns the foreground pixel of a GC Mats Jansborg **20070818235447] { hunk ./Graphics/X11/Xlib/Extras.hsc 762 + +foreign import ccall unsafe "XlibExtras.h XGetGCValues" + xGetGCValues :: Display -> GC -> #{type unsigned long} -> Ptr () -> IO Status + +getGCForeground :: Display -> GC -> IO Pixel +getGCForeground dpy gc = + allocaBytes #{size XGCValues} $ \vals -> do + throwIf (0==) (const "getGCForeground") $ + xGetGCValues dpy gc #{const GCForeground} vals + #{peek XGCValues, foreground} vals } [Added wcDrawImageString and wcTextEscapement Andrea Rossato **20070913182805] { hunk ./Graphics/X11/Xlib/Extras.hsc 756 - xwcDrawString :: Display -> Drawable -> FontSet -> GC -> CInt -> CInt -> CWString -> CInt -> IO () + xwcDrawString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> CWString -> CInt -> IO () hunk ./Graphics/X11/Xlib/Extras.hsc 758 -wcDrawString :: Display -> Drawable -> FontSet -> GC -> CInt -> CInt -> String -> IO () +wcDrawString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> String -> IO () hunk ./Graphics/X11/Xlib/Extras.hsc 763 +foreign import ccall unsafe "Xlib.h XwcDrawImageString" + xwcDrawImageString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> CWString -> CInt -> IO () + +wcDrawImageString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> String -> IO () +wcDrawImageString d w fs gc x y = + flip withCWStringLen $ \(s, len) -> + xwcDrawImageString d w fs gc x y s (fromIntegral len) + +foreign import ccall unsafe "Xlib.h XwcTextEscapement" + xwcTextEscapement :: FontSet -> CWString -> CInt -> IO Int32 + +wcTextEscapement :: FontSet -> String -> Int32 +wcTextEscapement font_set string = unsafePerformIO $ + withCWStringLen string $ \ (c_string, len) -> + xwcTextEscapement font_set c_string (fromIntegral len) + } Context: [Added support for parsing SelectionRequest and building SelectionNotify events Matthew Sackman **20070909220631] [TAG 0.3 Spencer Janssen **20070903215156] Patch bundle hash: f4281ad839972f370afde06a7cbd87b148b08339