{-# LANGUAGE CPP #-}
module Xmobar.X11.Draw (draw) where
import qualified Data.Map as M
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Reader (ask)
import Foreign.C.Types as FT
import qualified Graphics.X11.Xlib as X11
import qualified Xmobar.Config.Types as C
import qualified Xmobar.Draw.Types as D
import qualified Xmobar.Draw.Cairo as DC
import qualified Xmobar.X11.Bitmap as B
import qualified Xmobar.X11.Types as T
import qualified Xmobar.X11.CairoSurface as CS
#ifdef XRENDER
import qualified Xmobar.X11.XRender as XRender
#endif
drawXBitmap :: T.XConf -> X11.GC -> X11.Pixmap -> D.IconDrawer
drawXBitmap :: XConf -> GC -> Pixmap -> IconDrawer
drawXBitmap XConf
xconf GC
gc Pixmap
p Double
h Double
v String
path String
fc String
bc = do
let disp :: Display
disp = XConf -> Display
T.display XConf
xconf
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup String
path (XConf -> BitmapCache
T.iconCache XConf
xconf) of
Just Bitmap
bm -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Display
-> Pixmap
-> GC
-> String
-> String
-> Position
-> Position
-> Bitmap
-> IO ()
B.drawBitmap Display
disp Pixmap
p GC
gc String
fc String
bc (forall a b. (RealFrac a, Integral b) => a -> b
round Double
h) (forall a b. (RealFrac a, Integral b) => a -> b
round Double
v) Bitmap
bm
Maybe Bitmap
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
lookupXBitmap :: T.XConf -> String -> (Double, Double)
lookupXBitmap :: XConf -> String -> (Double, Double)
lookupXBitmap XConf
xconf String
path =
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup String
path (XConf -> BitmapCache
T.iconCache XConf
xconf) of
Just Bitmap
bm -> (forall a b. (Integral a, Num b) => a -> b
fromIntegral (Bitmap -> Dimension
B.width Bitmap
bm), forall a b. (Integral a, Num b) => a -> b
fromIntegral (Bitmap -> Dimension
B.height Bitmap
bm))
Maybe Bitmap
Nothing -> (Double
0, Double
0)
withPixmap :: X11.Display -> X11.Drawable -> X11.Rectangle -> FT.CInt
-> (X11.GC -> X11.Pixmap -> IO a) -> IO a
withPixmap :: forall a.
Display
-> Pixmap -> Rectangle -> CInt -> (GC -> Pixmap -> IO a) -> IO a
withPixmap Display
disp Pixmap
win (X11.Rectangle Position
_ Position
_ Dimension
w Dimension
h) CInt
depth GC -> Pixmap -> IO a
action = do
Pixmap
p <- Display -> Pixmap -> Dimension -> Dimension -> CInt -> IO Pixmap
X11.createPixmap Display
disp Pixmap
win Dimension
w Dimension
h CInt
depth
GC
gc <- Display -> Pixmap -> IO GC
X11.createGC Display
disp Pixmap
win
Display -> GC -> Bool -> IO ()
X11.setGraphicsExposures Display
disp GC
gc Bool
False
a
res <- GC -> Pixmap -> IO a
action GC
gc Pixmap
p
Display
-> Pixmap
-> Pixmap
-> GC
-> Position
-> Position
-> Dimension
-> Dimension
-> Position
-> Position
-> IO ()
X11.copyArea Display
disp Pixmap
p Pixmap
win GC
gc Position
0 Position
0 Dimension
w Dimension
h Position
0 Position
0
Display -> GC -> IO ()
X11.freeGC Display
disp GC
gc
Display -> Pixmap -> IO ()
X11.freePixmap Display
disp Pixmap
p
Display -> Bool -> IO ()
X11.sync Display
disp Bool
True
forall (m :: * -> *) a. Monad m => a -> m a
return a
res
draw :: [[C.Segment]] -> T.X [D.ActionPos]
draw :: [[Segment]] -> X [ActionPos]
draw [[Segment]]
segments = do
XConf
xconf <- forall r (m :: * -> *). MonadReader r m => m r
ask
let disp :: Display
disp = XConf -> Display
T.display XConf
xconf
win :: Pixmap
win = XConf -> Pixmap
T.window XConf
xconf
rect :: Rectangle
rect@(X11.Rectangle Position
_ Position
_ Dimension
w Dimension
h) = XConf -> Rectangle
T.rect XConf
xconf
screen :: Screen
screen = Display -> Screen
X11.defaultScreenOfDisplay Display
disp
depth :: CInt
depth = Screen -> CInt
X11.defaultDepthOfScreen Screen
screen
vis :: Visual
vis = Screen -> Visual
X11.defaultVisualOfScreen Screen
screen
conf :: Config
conf = XConf -> Config
T.config XConf
xconf
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a.
Display
-> Pixmap -> Rectangle -> CInt -> (GC -> Pixmap -> IO a) -> IO a
withPixmap Display
disp Pixmap
win Rectangle
rect CInt
depth forall a b. (a -> b) -> a -> b
$ \GC
gc Pixmap
p -> do
let bdraw :: IconDrawer
bdraw = XConf -> GC -> Pixmap -> IconDrawer
drawXBitmap XConf
xconf GC
gc Pixmap
p
blook :: String -> (Double, Double)
blook = XConf -> String -> (Double, Double)
lookupXBitmap XConf
xconf
dctx :: DrawContext
dctx = IconDrawer
-> (String -> (Double, Double))
-> Config
-> Double
-> Double
-> [[Segment]]
-> DrawContext
D.DC IconDrawer
bdraw String -> (Double, Double)
blook Config
conf (forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
w) (forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
h) [[Segment]]
segments
render :: Surface -> IO [ActionPos]
render = DrawContext -> Surface -> IO [ActionPos]
DC.drawSegments DrawContext
dctx
#ifdef XRENDER
color :: String
color = Config -> String
C.bgColor Config
conf
alph :: Int
alph = Config -> Int
C.alpha Config
conf
Display -> Pixmap -> String -> Int -> Rectangle -> IO ()
XRender.drawBackground Display
disp Pixmap
p String
color Int
alph Rectangle
rect
#endif
forall a.
Display
-> Pixmap -> Visual -> Int -> Int -> (Surface -> IO a) -> IO a
CS.withXlibSurface Display
disp Pixmap
p Visual
vis (forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
w) (forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
h) Surface -> IO [ActionPos]
render