diff options
author | Edward O'Callaghan <victoredwardocallaghan@gmail.com> | 2013-01-21 06:19:26 +1100 |
---|---|---|
committer | Alexander Polakov <plhk@sdf.org> | 2013-01-27 02:05:57 +0400 |
commit | cfd729999901c39f6e0aac1c271d56ae6e704d3e (patch) | |
tree | 09aa95e118b7c409b8bc4f92850577712a2ae3df /src/XGraphic.hs | |
parent | 8c208d5e5ef970f465c4ee903367de8a8b41879a (diff) | |
download | xmobar-cfd729999901c39f6e0aac1c271d56ae6e704d3e.tar.gz xmobar-cfd729999901c39f6e0aac1c271d56ae6e704d3e.tar.bz2 |
XBM icon support
<icon=/path/to/icon>
Diffstat (limited to 'src/XGraphic.hs')
-rw-r--r-- | src/XGraphic.hs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/XGraphic.hs b/src/XGraphic.hs new file mode 100644 index 0000000..9343580 --- /dev/null +++ b/src/XGraphic.hs @@ -0,0 +1,47 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +----------------------------------------------------------------------------- +-- | +-- Module : XGraphic +-- Copyright : Copyright © 2013 Edward O'Callaghan. All Rights Reserved. +-- License : BSD3 +-- +-- Maintainer : Edward O'Callaghan - <victoredwardocallaghan@gmail.com> +-- Stability : unstable +-- Portability : unportable +-- +----------------------------------------------------------------------------- + +module XGraphic + ( readBitmapFile + ) where + +import Graphics.X11.Xlib +--import Graphics.X11.Xlib.Misc +import Foreign +import Foreign.C + +-- | interface to the X11 library function @XWriteBitmapFile@. +readBitmapFile :: Display -> Drawable -> String + -> IO (Dimension, Dimension, Pixmap, Maybe CInt, Maybe CInt) +readBitmapFile display d filename = + withCString filename $ \ c_filename -> + alloca $ \ width_return -> + alloca $ \ height_return -> + alloca $ \ bitmap_return -> + alloca $ \ x_hot_return -> + alloca $ \ y_hot_return -> do + _ <- 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 + bitmap <- peek bitmap_return + x_hot <- peek x_hot_return + y_hot <- peek y_hot_return + let m_x_hot | x_hot == -1 = Nothing + | 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) +foreign import ccall unsafe "X11/Xlib.h XReadBitmapFile" + xReadBitmapFile :: Display -> Drawable -> CString -> Ptr CInt -> Ptr CInt + -> Ptr Pixmap -> Ptr CInt -> Ptr CInt -> IO CInt |