    {-# LINE 1 "Graphics/X11/Xlib/Types.hsc" #-}
    {-# LANGUAGE DeriveDataTypeable #-}
    {-# LINE 2 "Graphics/X11/Xlib/Types.hsc" #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.X11.Xlib.Types
    -- Copyright   :  (c) Alastair Reid, 1999-2003
    -- License     :  BSD-style (see the file libraries/base/LICENSE)
    --
    -- Maintainer  :  libraries@haskell.org
    -- Stability   :  provisional
    -- Portability :  portable
    --
    -- A collection of type declarations for interfacing with Xlib.
    --
    -----------------------------------------------------------------------------

    -- #hide
    module Graphics.X11.Xlib.Types(
            Display(..), Screen(..), Visual(..), GC(..), GCValues, SetWindowAttributes,
            VisualInfo(..),
            Image(..), Point(..), Rectangle(..), Arc(..), Segment(..), Color(..),
            Pixel, Position, Dimension, Angle, ScreenNumber, Buffer
            ) where

    import Graphics.X11.Types

    -- import Control.Monad( zipWithM_ )
    import Data.Int
    import Data.Word
    import Foreign.C.Types
    -- import Foreign.Marshal.Alloc( allocaBytes )
    import Foreign.Ptr
    import Foreign.Storable( Storable(..) )

    {-# LINE 35 "Graphics/X11/Xlib/Types.hsc" #-}
    import Data.Data

    {-# LINE 37 "Graphics/X11/Xlib/Types.hsc" #-}

    {-# LINE 39 "Graphics/X11/Xlib/Types.hsc" #-}

    ----------------------------------------------------------------
    -- Types
    ----------------------------------------------------------------

    -- | pointer to an X11 @Display@ structure
    newtype Display    = Display    (Ptr Display)

    {-# LINE 47 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Ord, Show, Typeable, Data)

    {-# LINE 51 "Graphics/X11/Xlib/Types.hsc" #-}

    -- | pointer to an X11 @Screen@ structure
    newtype Screen     = Screen     (Ptr Screen)

    {-# LINE 55 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Ord, Show, Typeable, Data)

    {-# LINE 59 "Graphics/X11/Xlib/Types.hsc" #-}

    -- | pointer to an X11 @Visual@ structure
    newtype Visual     = Visual     (Ptr Visual)

    {-# LINE 63 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Ord, Show, Typeable, Data)

    {-# LINE 67 "Graphics/X11/Xlib/Types.hsc" #-}

    -- | pointer to an X11 @GC@ structure
    newtype GC         = GC         (Ptr GC)

    {-# LINE 71 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Ord, Show, Typeable, Data)

    {-# LINE 75 "Graphics/X11/Xlib/Types.hsc" #-}

    -- | pointer to an X11 @XGCValues@ structure
    newtype GCValues   = GCValues  (Ptr GCValues)

    {-# LINE 79 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Ord, Show, Typeable, Data)

    {-# LINE 83 "Graphics/X11/Xlib/Types.hsc" #-}

    -- | pointer to an X11 @XSetWindowAttributes@ structure
    newtype SetWindowAttributes = SetWindowAttributes (Ptr SetWindowAttributes)

    {-# LINE 87 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Ord, Show, Typeable, Data)

    {-# LINE 91 "Graphics/X11/Xlib/Types.hsc" #-}

    -- | counterpart of an X11 @XVisualInfo@ structure
    data VisualInfo = VisualInfo {
            visualInfo_visual :: Visual,
            visualInfo_visualID :: VisualID,
            visualInfo_screen :: ScreenNumber,
            visualInfo_depth :: CInt,
            visualInfo_class :: CInt,
            visualInfo_redMask :: CULong,
            visualInfo_greenMask :: CULong,
            visualInfo_blueMask :: CULong,
            visualInfo_colormapSize :: CInt,
            visualInfo_bitsPerRGB :: CInt
            }

    {-# LINE 106 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Show, Typeable)

    {-# LINE 110 "Graphics/X11/Xlib/Types.hsc" #-}

    instance Storable VisualInfo where
            sizeOf _ = (40)
    {-# LINE 113 "Graphics/X11/Xlib/Types.hsc" #-}
            alignment _ = alignment (undefined::CInt)
            peek p = do
                    visual <- Visual `fmap` (\hsc_ptr -> peekByteOff hsc_ptr 0) p
    {-# LINE 116 "Graphics/X11/Xlib/Types.hsc" #-}
                    visualID <- (\hsc_ptr -> peekByteOff hsc_ptr 4) p
    {-# LINE 117 "Graphics/X11/Xlib/Types.hsc" #-}
                    screen <- (\hsc_ptr -> peekByteOff hsc_ptr 8) p
    {-# LINE 118 "Graphics/X11/Xlib/Types.hsc" #-}
                    depth <- (\hsc_ptr -> peekByteOff hsc_ptr 12) p
    {-# LINE 119 "Graphics/X11/Xlib/Types.hsc" #-}
                    class_ <- (\hsc_ptr -> peekByteOff hsc_ptr 16) p
    {-# LINE 120 "Graphics/X11/Xlib/Types.hsc" #-}
                    redMask <- (\hsc_ptr -> peekByteOff hsc_ptr 20) p
    {-# LINE 121 "Graphics/X11/Xlib/Types.hsc" #-}
                    greenMask <- (\hsc_ptr -> peekByteOff hsc_ptr 24) p
    {-# LINE 122 "Graphics/X11/Xlib/Types.hsc" #-}
                    blueMask <- (\hsc_ptr -> peekByteOff hsc_ptr 28) p
    {-# LINE 123 "Graphics/X11/Xlib/Types.hsc" #-}
                    colormapSize <- (\hsc_ptr -> peekByteOff hsc_ptr 32) p
    {-# LINE 124 "Graphics/X11/Xlib/Types.hsc" #-}
                    bitsPerRGB <- (\hsc_ptr -> peekByteOff hsc_ptr 36) p
    {-# LINE 125 "Graphics/X11/Xlib/Types.hsc" #-}
                    return $ VisualInfo {
                            visualInfo_visual = visual,
                            visualInfo_visualID = visualID,
                            visualInfo_screen = screen,
                            visualInfo_depth = depth,
                            visualInfo_class = class_,
                            visualInfo_redMask = redMask,
                            visualInfo_greenMask = greenMask,
                            visualInfo_blueMask = blueMask,
                            visualInfo_colormapSize = colormapSize,
                            visualInfo_bitsPerRGB = bitsPerRGB
                            }
            poke p info = do
                    (\hsc_ptr -> pokeByteOff hsc_ptr 0) p visualPtr
    {-# LINE 139 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 4) p $ visualInfo_visualID info
    {-# LINE 140 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 8) p $ visualInfo_screen info
    {-# LINE 141 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 12) p $ visualInfo_depth info
    {-# LINE 142 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 16) p $ visualInfo_class info
    {-# LINE 143 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 20) p $ visualInfo_redMask info
    {-# LINE 144 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 24) p $ visualInfo_greenMask info
    {-# LINE 145 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 28) p $ visualInfo_blueMask info
    {-# LINE 146 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 32) p $
    {-# LINE 147 "Graphics/X11/Xlib/Types.hsc" #-}
                            visualInfo_colormapSize info
                    (\hsc_ptr -> pokeByteOff hsc_ptr 36) p $
    {-# LINE 149 "Graphics/X11/Xlib/Types.hsc" #-}
                            visualInfo_bitsPerRGB info
                    where
                            ~(Visual visualPtr) = visualInfo_visual info

    -- | pointer to an X11 @XImage@ structure
    newtype Image    = Image    (Ptr Image)

    {-# LINE 156 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Ord, Show, Typeable, Data)

    {-# LINE 160 "Graphics/X11/Xlib/Types.hsc" #-}

    type Pixel         = Word32
    {-# LINE 162 "Graphics/X11/Xlib/Types.hsc" #-}
    type Position      = Int32
    {-# LINE 163 "Graphics/X11/Xlib/Types.hsc" #-}
    type Dimension     = Word32
    {-# LINE 164 "Graphics/X11/Xlib/Types.hsc" #-}
    type Angle         = CInt
    type ScreenNumber  = Word32
    type Buffer        = CInt

    ----------------------------------------------------------------
    -- Short forms used in structs
    ----------------------------------------------------------------

    type ShortPosition = CShort
    type ShortDimension = CUShort
    type ShortAngle    = CShort

    peekPositionField :: Ptr a -> CInt -> IO Position
    peekPositionField ptr off = do
            v <- peekByteOff ptr (fromIntegral off)
            return (fromIntegral (v::ShortPosition))

    peekDimensionField :: Ptr a -> CInt -> IO Dimension
    peekDimensionField ptr off = do
            v <- peekByteOff ptr (fromIntegral off)
            return (fromIntegral (v::ShortDimension))

    peekAngleField :: Ptr a -> CInt -> IO Angle
    peekAngleField ptr off = do
            v <- peekByteOff ptr (fromIntegral off)
            return (fromIntegral (v::ShortAngle))

    pokePositionField :: Ptr a -> CInt -> Position -> IO ()
    pokePositionField ptr off v =
            pokeByteOff ptr (fromIntegral off) (fromIntegral v::ShortPosition)

    pokeDimensionField :: Ptr a -> CInt -> Dimension -> IO ()
    pokeDimensionField ptr off v =
            pokeByteOff ptr (fromIntegral off) (fromIntegral v::ShortDimension)

    pokeAngleField :: Ptr a -> CInt -> Angle -> IO ()
    pokeAngleField ptr off v =
            pokeByteOff ptr (fromIntegral off) (fromIntegral v::ShortAngle)

    ----------------------------------------------------------------
    -- Point
    ----------------------------------------------------------------

    -- | counterpart of an X11 @XPoint@ structure
    data Point = Point { pt_x :: !Position, pt_y :: !Position }

    {-# LINE 210 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Show, Typeable, Data)

    {-# LINE 214 "Graphics/X11/Xlib/Types.hsc" #-}

    instance Storable Point where
            sizeOf _ = (4)
    {-# LINE 217 "Graphics/X11/Xlib/Types.hsc" #-}
            alignment _ = alignment (undefined::CInt)
            peek p = do
                    x <- peekPositionField p (0)
    {-# LINE 220 "Graphics/X11/Xlib/Types.hsc" #-}
                    y <- peekPositionField p (2)
    {-# LINE 221 "Graphics/X11/Xlib/Types.hsc" #-}
                    return (Point x y)
            poke p (Point x y) = do
                    pokePositionField p (0) x
    {-# LINE 224 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokePositionField p (2) y
    {-# LINE 225 "Graphics/X11/Xlib/Types.hsc" #-}

    ----------------------------------------------------------------
    -- Rectangle
    ----------------------------------------------------------------

    -- | counterpart of an X11 @XRectangle@ structure
    data Rectangle = Rectangle {
            rect_x      :: !Position,
            rect_y      :: !Position,
            rect_width  :: !Dimension,
            rect_height :: !Dimension
            }

    {-# LINE 238 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Read, Show, Typeable, Data)

    {-# LINE 242 "Graphics/X11/Xlib/Types.hsc" #-}

    instance Storable Rectangle where
            sizeOf _ = (8)
    {-# LINE 245 "Graphics/X11/Xlib/Types.hsc" #-}
            alignment _ = alignment (undefined::CInt)
            peek p = do
                    x       <- peekPositionField p (0)
    {-# LINE 248 "Graphics/X11/Xlib/Types.hsc" #-}
                    y       <- peekPositionField p (2)
    {-# LINE 249 "Graphics/X11/Xlib/Types.hsc" #-}
                    width   <- peekDimensionField p (4)
    {-# LINE 250 "Graphics/X11/Xlib/Types.hsc" #-}
                    height  <- peekDimensionField p (6)
    {-# LINE 251 "Graphics/X11/Xlib/Types.hsc" #-}
                    return (Rectangle x y width height)
            poke p (Rectangle x y width height) = do
                    pokePositionField p (0) x
    {-# LINE 254 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokePositionField p (2) y
    {-# LINE 255 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokeDimensionField p (4) width
    {-# LINE 256 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokeDimensionField p (6) height
    {-# LINE 257 "Graphics/X11/Xlib/Types.hsc" #-}

    ----------------------------------------------------------------
    -- Arc
    ----------------------------------------------------------------

    -- | counterpart of an X11 @XArc@ structure
    data Arc = Arc {
            arc_x :: Position,
            arc_y :: Position,
            arc_width :: Dimension,
            arc_height :: Dimension,
            arc_angle1 :: Angle,
            arc_angle2 :: Angle
            }

    {-# LINE 272 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Show, Typeable)

    {-# LINE 276 "Graphics/X11/Xlib/Types.hsc" #-}

    instance Storable Arc where
            sizeOf _ = (12)
    {-# LINE 279 "Graphics/X11/Xlib/Types.hsc" #-}
            alignment _ = alignment (undefined::CInt)
            peek p = do
                    x       <- peekPositionField p (0)
    {-# LINE 282 "Graphics/X11/Xlib/Types.hsc" #-}
                    y       <- peekPositionField p (2)
    {-# LINE 283 "Graphics/X11/Xlib/Types.hsc" #-}
                    width   <- peekDimensionField p (4)
    {-# LINE 284 "Graphics/X11/Xlib/Types.hsc" #-}
                    height  <- peekDimensionField p (6)
    {-# LINE 285 "Graphics/X11/Xlib/Types.hsc" #-}
                    angle1  <- peekAngleField p (8)
    {-# LINE 286 "Graphics/X11/Xlib/Types.hsc" #-}
                    angle2  <- peekAngleField p (10)
    {-# LINE 287 "Graphics/X11/Xlib/Types.hsc" #-}
                    return (Arc x y width height angle1 angle2)
            poke p (Arc x y width height angle1 angle2) = do
                    pokePositionField p (0) x
    {-# LINE 290 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokePositionField p (2) y
    {-# LINE 291 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokeDimensionField p (4) width
    {-# LINE 292 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokeDimensionField p (6) height
    {-# LINE 293 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokeAngleField p (8) angle1
    {-# LINE 294 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokeAngleField p (10) angle2
    {-# LINE 295 "Graphics/X11/Xlib/Types.hsc" #-}

    ----------------------------------------------------------------
    -- Segment
    ----------------------------------------------------------------

    -- | counterpart of an X11 @XSegment@ structure
    data Segment = Segment {
            seg_x1 :: Position,
            seg_y1 :: Position,
            seg_x2 :: Position,
            seg_y2 :: Position
            }

    {-# LINE 308 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Show, Typeable, Data)

    {-# LINE 312 "Graphics/X11/Xlib/Types.hsc" #-}

    instance Storable Segment where
            sizeOf _ = (8)
    {-# LINE 315 "Graphics/X11/Xlib/Types.hsc" #-}
            alignment _ = alignment (undefined::CInt)
            peek p = do
                    x1 <- peekPositionField p (0)
    {-# LINE 318 "Graphics/X11/Xlib/Types.hsc" #-}
                    y1 <- peekPositionField p (2)
    {-# LINE 319 "Graphics/X11/Xlib/Types.hsc" #-}
                    x2 <- peekPositionField p (4)
    {-# LINE 320 "Graphics/X11/Xlib/Types.hsc" #-}
                    y2 <- peekPositionField p (6)
    {-# LINE 321 "Graphics/X11/Xlib/Types.hsc" #-}
                    return (Segment x1 y1 x2 y2)
            poke p (Segment x1 y1 x2 y2) = do
                    pokePositionField p (0) x1
    {-# LINE 324 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokePositionField p (2) y1
    {-# LINE 325 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokePositionField p (4) x2
    {-# LINE 326 "Graphics/X11/Xlib/Types.hsc" #-}
                    pokePositionField p (6) y2
    {-# LINE 327 "Graphics/X11/Xlib/Types.hsc" #-}

    ----------------------------------------------------------------
    -- Color
    ----------------------------------------------------------------

    -- | counterpart of an X11 @XColor@ structure
    data Color = Color {
            color_pixel :: Pixel,
            color_red :: Word16,
            color_green :: Word16,
            color_blue :: Word16,
            color_flags :: Word8
            }

    {-# LINE 341 "Graphics/X11/Xlib/Types.hsc" #-}
            deriving (Eq, Show, Typeable, Data)

    {-# LINE 345 "Graphics/X11/Xlib/Types.hsc" #-}

    instance Storable Color where
            sizeOf _ = (12)
    {-# LINE 348 "Graphics/X11/Xlib/Types.hsc" #-}
            alignment _ = alignment (undefined::CInt)
            peek p = do
                    pixel   <- (\hsc_ptr -> peekByteOff hsc_ptr 0) p
    {-# LINE 351 "Graphics/X11/Xlib/Types.hsc" #-}
                    red     <- (\hsc_ptr -> peekByteOff hsc_ptr 4)   p
    {-# LINE 352 "Graphics/X11/Xlib/Types.hsc" #-}
                    green   <- (\hsc_ptr -> peekByteOff hsc_ptr 6) p
    {-# LINE 353 "Graphics/X11/Xlib/Types.hsc" #-}
                    blue    <- (\hsc_ptr -> peekByteOff hsc_ptr 8)  p
    {-# LINE 354 "Graphics/X11/Xlib/Types.hsc" #-}
                    flags   <- (\hsc_ptr -> peekByteOff hsc_ptr 10) p
    {-# LINE 355 "Graphics/X11/Xlib/Types.hsc" #-}
                    return (Color pixel red green blue flags)
            poke p (Color pixel red green blue flags) = do
                    (\hsc_ptr -> pokeByteOff hsc_ptr 0)    p pixel
    {-# LINE 358 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 4)      p red
    {-# LINE 359 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 6)    p green
    {-# LINE 360 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 8)     p blue
    {-# LINE 361 "Graphics/X11/Xlib/Types.hsc" #-}
                    (\hsc_ptr -> pokeByteOff hsc_ptr 10)    p flags
    {-# LINE 362 "Graphics/X11/Xlib/Types.hsc" #-}

    ----------------------------------------------------------------
    -- End
    ----------------------------------------------------------------