diff options
author | Alexander Polakov <plhk@sdf.org> | 2013-02-04 03:17:50 +0400 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2013-02-04 01:23:18 +0100 |
commit | 3a7859e2147e714471717d4dcb58d9a19c24cb88 (patch) | |
tree | 6e7cb6721fe2c665056723cab218137b0bd39bf1 /src | |
parent | 2991a3c18b00bb41197e6a688c4ce07ad52057c0 (diff) | |
download | xmobar-3a7859e2147e714471717d4dcb58d9a19c24cb88.tar.gz xmobar-3a7859e2147e714471717d4dcb58d9a19c24cb88.tar.bz2 |
Handle XReadBitmapFile errors
Diffstat (limited to 'src')
-rw-r--r-- | src/Bitmap.hs | 11 | ||||
-rw-r--r-- | src/XGraphic.hs | 11 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/Bitmap.hs b/src/Bitmap.hs index c512ff2..9df2f67 100644 --- a/src/Bitmap.hs +++ b/src/Bitmap.hs @@ -46,9 +46,14 @@ loadBitmap d w p = do exist <- doesFileExist p if exist then do - (bw, bh, bp, _, _) <- readBitmapFile d w p - addFinalizer bp (freePixmap d bp) - return $ Just $ Bitmap bw bh bp + bmap <- readBitmapFile d w p + case bmap of + Right (bw, bh, bp, _, _) -> do + addFinalizer bp (freePixmap d bp) + return $ Just $ Bitmap bw bh bp + Left err -> do + putStrLn err + return Nothing else return Nothing 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 |