diff options
Diffstat (limited to 'lib/Phi/Widget.hs')
-rw-r--r-- | lib/Phi/Widget.hs | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/lib/Phi/Widget.hs b/lib/Phi/Widget.hs index 218dea1..48ab536 100644 --- a/lib/Phi/Widget.hs +++ b/lib/Phi/Widget.hs @@ -3,6 +3,8 @@ module Phi.Widget ( Display(..) , withDisplay , getAtoms + , getScreens + , unionArea , Widget(..) , WidgetClass(..) , WidgetState(..) @@ -19,24 +21,42 @@ import Control.Monad.IO.Class import Data.Traversable -import qualified Graphics.X11.Xlib +import qualified Graphics.X11.Xlib as Xlib import Graphics.Rendering.Cairo import Phi.Phi import Phi.X11.Atoms -data Display = Display (MVar Graphics.X11.Xlib.Display) Atoms +data Display = Display (MVar Xlib.Display) Atoms [Xlib.Rectangle] -withDisplay :: MonadIO m => Display -> (Graphics.X11.Xlib.Display -> m a) -> m a -withDisplay (Display dispvar _) f = do +withDisplay :: MonadIO m => Display -> (Xlib.Display -> m a) -> m a +withDisplay (Display dispvar _ _) f = do disp <- liftIO $ takeMVar dispvar a <- f disp liftIO $ putMVar dispvar disp return a getAtoms :: Display -> Atoms -getAtoms (Display _ atoms) = atoms +getAtoms (Display _ atoms _) = atoms + +getScreens :: Display -> [Xlib.Rectangle] +getScreens (Display _ _ screens) = screens + +unionArea :: Xlib.Rectangle -> Xlib.Rectangle -> Int +unionArea a b = fromIntegral $ uw*uh + where + uw = max 0 $ (min ax2 bx2) - (max ax1 bx1) + uh = max 0 $ (min ay2 by2) - (max ay1 by1) + + Xlib.Rectangle ax1 ay1 aw ah = a + Xlib.Rectangle bx1 by1 bw bh = b + + ax2 = ax1 + fromIntegral aw + ay2 = ay1 + fromIntegral ah + + bx2 = bx1 + fromIntegral bw + by2 = by1 + fromIntegral bh class Show a => WidgetClass a where @@ -52,7 +72,7 @@ class Show a => WidgetClass a where layout :: a -> WidgetData a -> Int -> Int -> WidgetData a layout _ priv _ _ = priv - render :: a -> WidgetData a -> Int -> Int -> Render () + render :: a -> WidgetData a -> Int -> Int -> Xlib.Rectangle -> Render () handleMessage :: a -> WidgetData a -> Message -> WidgetData a handleMessage _ priv _ = priv @@ -102,16 +122,16 @@ layoutWidgets widgets x y width height = snd $ mapAccumL layoutWidgetAndX x widg nneg :: (Num a, Ord a) => a -> a nneg x = max 0 x -renderWidgets :: [WidgetState] -> Render () -renderWidgets widgets = forM_ widgets $ \WidgetState { stateWidget = widget - , stateX = x - , stateY = y - , stateWidth = w - , stateHeight = h - , statePrivateData = priv } -> do +renderWidgets :: [WidgetState] -> Xlib.Rectangle -> Render () +renderWidgets widgets screen = forM_ widgets $ \WidgetState { stateWidget = widget + , stateX = x + , stateY = y + , stateWidth = w + , stateHeight = h + , statePrivateData = priv } -> do save translate (fromIntegral x) (fromIntegral y) - render widget priv w h + render widget priv w h screen restore handleMessageWidgets :: Message -> [WidgetState] -> [WidgetState] @@ -127,7 +147,7 @@ instance WidgetClass Separator where minSize (Separator s _) = s weight (Separator _ w) = w - render _ _ _ _ = return () + render _ _ _ _ _ = return () separator :: Int -> Float -> Widget separator s w = Widget $ Separator s w |