summaryrefslogtreecommitdiffhomepage
path: root/src/XGraphic.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/XGraphic.hs')
-rw-r--r--src/XGraphic.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/XGraphic.hs b/src/XGraphic.hs
index 9343580..416177f 100644
--- a/src/XGraphic.hs
+++ b/src/XGraphic.hs
@@ -22,7 +22,7 @@ import Foreign.C
-- | interface to the X11 library function @XWriteBitmapFile@.
readBitmapFile :: Display -> Drawable -> String
- -> IO (Dimension, Dimension, Pixmap, Maybe CInt, Maybe CInt)
+ -> IO (Either String (Dimension, Dimension, Pixmap, Maybe CInt, Maybe CInt))
readBitmapFile display d filename =
withCString filename $ \ c_filename ->
alloca $ \ width_return ->
@@ -30,7 +30,7 @@ readBitmapFile display d filename =
alloca $ \ bitmap_return ->
alloca $ \ x_hot_return ->
alloca $ \ y_hot_return -> do
- _ <- xReadBitmapFile display d c_filename width_return height_return
+ rv <- xReadBitmapFile display d c_filename width_return height_return
bitmap_return x_hot_return y_hot_return
width <- peek width_return
height <- peek height_return
@@ -41,7 +41,12 @@ readBitmapFile display d filename =
| otherwise = Just x_hot
m_y_hot | y_hot == -1 = Nothing
| otherwise = Just y_hot
- return (fromIntegral width, fromIntegral height, bitmap, m_x_hot, m_y_hot)
+ case rv of
+ 0 -> return $ Right (fromIntegral width, fromIntegral height, bitmap, m_x_hot, m_y_hot)
+ 1 -> return $ Left "readBitmapFile: BitmapOpenFailed"
+ 2 -> return $ Left "readBitmapFile: BitmapFileInvalid"
+ 3 -> return $ Left "readBitmapFile: BitmapNoMemory"
+ _ -> return $ Left "readBitmapFile: BitmapUnknownError"
foreign import ccall unsafe "X11/Xlib.h XReadBitmapFile"
xReadBitmapFile :: Display -> Drawable -> CString -> Ptr CInt -> Ptr CInt
-> Ptr Pixmap -> Ptr CInt -> Ptr CInt -> IO CInt