    {-# LINE 1 "Graphics/X11/Xlib/Extras.hsc" #-}
    {-# LANGUAGE DeriveDataTypeable #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      : Graphics.X11.Xlib.Extras
    -- Copyright   : 2007 (c) Spencer Janssen
    -- License     : BSD3-style (see LICENSE)
    -- Stability   : experimental
    --
    -----------------------------------------------------------------------------
    --
    -- missing functionality from the X11 library
    --

    module Graphics.X11.Xlib.Extras (
      module Graphics.X11.Xlib.Extras,
      module Graphics.X11.Xlib.Internal
      ) where

    import Data.Maybe
    import Data.Typeable ( Typeable )
    import Graphics.X11.Xrandr
    import Graphics.X11.XScreenSaver
    import Graphics.X11.Xlib
    import Graphics.X11.Xlib.Internal
    import Graphics.X11.Xlib.Types
    import Foreign (Storable, Ptr, peek, poke, pokeArray, peekElemOff, peekByteOff, pokeByteOff, peekArray, throwIfNull, nullPtr, sizeOf, alignment, alloca, with, throwIf, Word8, Word16, Word64, Int32, plusPtr, castPtr, withArrayLen, setBit, testBit, allocaBytes, FunPtr)
    {-# LINE 27 "Graphics/X11/Xlib/Extras.hsc" #-}
    import Foreign.C.Types
    import Foreign.C.String
    import Control.Monad

    import System.IO.Unsafe

    data Event
        = AnyEvent
            { Event -> EventType
    ev_event_type            :: !EventType
            , Event -> CULong
    ev_serial                :: !CULong
            , Event -> Bool
    ev_send_event            :: !Bool
            , Event -> Display
    ev_event_display         :: Display
            , Event -> XID
    ev_window                :: !Window
            }
        | ConfigureRequestEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , Event -> XID
    ev_parent                :: !Window
            , ev_window                :: !Window
            , Event -> CInt
    ev_x                     :: !CInt
            , Event -> CInt
    ev_y                     :: !CInt
            , Event -> CInt
    ev_width                 :: !CInt
            , Event -> CInt
    ev_height                :: !CInt
            , Event -> CInt
    ev_border_width          :: !CInt
            , Event -> XID
    ev_above                 :: !Window
            , Event -> CInt
    ev_detail                :: !NotifyDetail
            , Event -> CULong
    ev_value_mask            :: !CULong
            }
        | ConfigureEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , Event -> XID
    ev_event                 :: !Window
            , ev_window                :: !Window
            , ev_x                     :: !CInt
            , ev_y                     :: !CInt
            , ev_width                 :: !CInt
            , ev_height                :: !CInt
            , ev_border_width          :: !CInt
            , ev_above                 :: !Window
            , Event -> Bool
    ev_override_redirect     :: !Bool
            }
        | MapRequestEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_parent                :: !Window
            , ev_window                :: !Window
            }
        | KeyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , Event -> XID
    ev_root                  :: !Window
            , Event -> XID
    ev_subwindow             :: !Window
            , Event -> XID
    ev_time                  :: !Time
            , ev_x                     :: !CInt
            , ev_y                     :: !CInt
            , Event -> CInt
    ev_x_root                :: !CInt
            , Event -> CInt
    ev_y_root                :: !CInt
            , Event -> KeyMask
    ev_state                 :: !KeyMask
            , Event -> KeyCode
    ev_keycode               :: !KeyCode
            , Event -> Bool
    ev_same_screen           :: !Bool
            }
        | ButtonEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_root                  :: !Window
            , ev_subwindow             :: !Window
            , ev_time                  :: !Time
            , ev_x                     :: !CInt
            , ev_y                     :: !CInt
            , ev_x_root                :: !CInt
            , ev_y_root                :: !CInt
            , ev_state                 :: !KeyMask
            , Event -> EventType
    ev_button                :: !Button
            , ev_same_screen           :: !Bool
            }
        | MotionEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_x                     :: !CInt
            , ev_y                     :: !CInt
            , ev_window                :: !Window
            }
        | DestroyWindowEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_event                 :: !Window
            , ev_window                :: !Window
            }
        | UnmapEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_event                 :: !Window
            , ev_window                :: !Window
            , Event -> Bool
    ev_from_configure        :: !Bool
            }
        | MapNotifyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_event                 :: !Window
            , ev_window                :: !Window
            , ev_override_redirect     :: !Bool
            }
        | MappingNotifyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , Event -> CInt
    ev_request               :: !MappingRequest
            , Event -> KeyCode
    ev_first_keycode         :: !KeyCode
            , Event -> CInt
    ev_count                 :: !CInt
            }
        | CrossingEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_root                  :: !Window
            , ev_subwindow             :: !Window
            , ev_time                  :: !Time
            , ev_x                     :: !CInt
            , ev_y                     :: !CInt
            , ev_x_root                :: !CInt
            , ev_y_root                :: !CInt
            , Event -> CInt
    ev_mode                  :: !NotifyMode
            , ev_detail                :: !NotifyDetail
            , ev_same_screen           :: !Bool
            , Event -> Bool
    ev_focus                 :: !Bool
            , ev_state                 :: !Modifier
            }
        | SelectionRequest
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , Event -> XID
    ev_owner                 :: !Window
            , Event -> XID
    ev_requestor             :: !Window
            , Event -> XID
    ev_selection             :: !Atom
            , Event -> XID
    ev_target                :: !Atom
            , Event -> XID
    ev_property              :: !Atom
            , ev_time                  :: !Time
            }
        | SelectionClear
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_selection             :: !Atom
            , ev_time                  :: !Time
            }
        | PropertyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , Event -> XID
    ev_atom                  :: !Atom
            , ev_time                  :: !Time
            , Event -> CInt
    ev_propstate             :: !CInt
            }
        | ExposeEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_x                     :: !CInt
            , ev_y                     :: !CInt
            , ev_width                 :: !CInt
            , ev_height                :: !CInt
            , ev_count                 :: !CInt
            }
        | FocusChangeEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_mode                  :: !NotifyMode
            , ev_detail                :: !NotifyDetail
            }
        | ClientMessageEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , Event -> XID
    ev_message_type          :: !Atom
            , Event -> [CInt]
    ev_data                  :: ![CInt]
            }
        | RRScreenChangeNotifyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_root                  :: !Window
            , Event -> XID
    ev_timestamp             :: !Time
            , Event -> XID
    ev_config_timestamp      :: !Time
            , Event -> Word16
    ev_size_index            :: !SizeID
            , Event -> Word16
    ev_subpixel_order        :: !SubpixelOrder
            , Event -> Word16
    ev_rotation              :: !Rotation
            , ev_width                 :: !CInt
            , ev_height                :: !CInt
            , Event -> CInt
    ev_mwidth                :: !CInt
            , Event -> CInt
    ev_mheight               :: !CInt
            }
        | RRNotifyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , Event -> CInt
    ev_subtype               :: !CInt
            }
        | RRCrtcChangeNotifyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_subtype               :: !CInt
            , Event -> XID
    ev_crtc                  :: !RRCrtc
            , Event -> XID
    ev_rr_mode               :: !RRMode
            , ev_rotation              :: !Rotation
            , ev_x                     :: !CInt
            , ev_y                     :: !CInt
            , Event -> KeyMask
    ev_rr_width              :: !CUInt
            , Event -> KeyMask
    ev_rr_height             :: !CUInt
            }
        | RROutputChangeNotifyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_subtype               :: !CInt
            , Event -> XID
    ev_output                :: !RROutput
            , ev_crtc                  :: !RRCrtc
            , ev_rr_mode               :: !RRMode
            , ev_rotation              :: !Rotation
            , Event -> Word16
    ev_connection            :: !Connection
            , ev_subpixel_order        :: !SubpixelOrder
            }
        | RROutputPropertyNotifyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_subtype               :: !CInt
            , ev_output                :: !RROutput
            , ev_property              :: !Atom
            , ev_timestamp             :: !Time
            , Event -> CInt
    ev_rr_state              :: !CInt
            }
        | ScreenSaverNotifyEvent
            { ev_event_type            :: !EventType
            , ev_serial                :: !CULong
            , ev_send_event            :: !Bool
            , ev_event_display         :: Display
            , ev_window                :: !Window
            , ev_root                  :: !Window
            , Event -> XScreenSaverState
    ev_ss_state              :: !XScreenSaverState
            , Event -> XScreenSaverKind
    ev_ss_kind               :: !XScreenSaverKind
            , Event -> Bool
    ev_forced                :: !Bool
            , ev_time                  :: !Time
            }
        deriving ( Int -> Event -> ShowS
    [Event] -> ShowS
    Event -> String
    (Int -> Event -> ShowS)
    -> (Event -> String) -> ([Event] -> ShowS) -> Show Event
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Event -> ShowS
    showsPrec :: Int -> Event -> ShowS
    $cshow :: Event -> String
    show :: Event -> String
    $cshowList :: [Event] -> ShowS
    showList :: [Event] -> ShowS
    Show, Typeable )

    eventTable :: [(EventType, String)]
    eventTable :: [(EventType, String)]
    eventTable =
        [ (EventType
    keyPress             , String
    "KeyPress")
        , (EventType
    keyRelease           , String
    "KeyRelease")
        , (EventType
    buttonPress          , String
    "ButtonPress")
        , (EventType
    buttonRelease        , String
    "ButtonRelease")
        , (EventType
    motionNotify         , String
    "MotionNotify")
        , (EventType
    enterNotify          , String
    "EnterNotify")
        , (EventType
    leaveNotify          , String
    "LeaveNotify")
        , (EventType
    focusIn              , String
    "FocusIn")
        , (EventType
    focusOut             , String
    "FocusOut")
        , (EventType
    keymapNotify         , String
    "KeymapNotify")
        , (EventType
    expose               , String
    "Expose")
        , (EventType
    graphicsExpose       , String
    "GraphicsExpose")
        , (EventType
    noExpose             , String
    "NoExpose")
        , (EventType
    visibilityNotify     , String
    "VisibilityNotify")
        , (EventType
    createNotify         , String
    "CreateNotify")
        , (EventType
    destroyNotify        , String
    "DestroyNotify")
        , (EventType
    unmapNotify          , String
    "UnmapNotify")
        , (EventType
    mapNotify            , String
    "MapNotify")
        , (EventType
    mapRequest           , String
    "MapRequest")
        , (EventType
    reparentNotify       , String
    "ReparentNotify")
        , (EventType
    configureNotify      , String
    "ConfigureNotify")
        , (EventType
    configureRequest     , String
    "ConfigureRequest")
        , (EventType
    gravityNotify        , String
    "GravityNotify")
        , (EventType
    resizeRequest        , String
    "ResizeRequest")
        , (EventType
    circulateNotify      , String
    "CirculateNotify")
        , (EventType
    circulateRequest     , String
    "CirculateRequest")
        , (EventType
    propertyNotify       , String
    "PropertyNotify")
        , (EventType
    selectionClear       , String
    "SelectionClear")
        , (EventType
    selectionRequest     , String
    "SelectionRequest")
        , (EventType
    selectionNotify      , String
    "SelectionNotify")
        , (EventType
    colormapNotify       , String
    "ColormapNotify")
        , (EventType
    clientMessage        , String
    "ClientMessage")
        , (EventType
    mappingNotify        , String
    "MappingNotify")
        , (EventType
    lASTEvent            , String
    "LASTEvent")
        , (EventType
    screenSaverNotify    , String
    "ScreenSaverNotify")
        ]

    eventName :: Event -> String
    eventName :: Event -> String
    eventName Event
    e = String -> ShowS -> Maybe String -> String
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (String
    "unknown " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ EventType -> String
    forall a. Show a => a -> String
    show EventType
    x) ShowS
    forall a. a -> a
    id (Maybe String -> String) -> Maybe String -> String
    forall a b. (a -> b) -> a -> b
    $ EventType -> [(EventType, String)] -> Maybe String
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup EventType
    x [(EventType, String)]
    eventTable
     where x :: EventType
    x = EventType -> EventType
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (EventType -> EventType) -> EventType -> EventType
    forall a b. (a -> b) -> a -> b
    $ Event -> EventType
    ev_event_type Event
    e

    getEvent :: XEventPtr -> IO Event
    getEvent :: XEventPtr -> IO Event
    getEvent XEventPtr
    p = do
        -- All events share this layout and naming convention, there is also a
        -- common Window field, but the names for this field vary.
        type_      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    0) XEventPtr
    p
    {-# LINE 369 "Graphics/X11/Xlib/Extras.hsc" #-}
        serial     <- (\hsc_ptr -> peekByteOff hsc_ptr 8) p
    {-# LINE 370 "Graphics/X11/Xlib/Extras.hsc" #-}
        send_event <- (\hsc_ptr -> peekByteOff hsc_ptr 16) p
    {-# LINE 371 "Graphics/X11/Xlib/Extras.hsc" #-}
        display    <- fmap Display ((\hsc_ptr -> peekByteOff hsc_ptr 24) p)
    {-# LINE 372 "Graphics/X11/Xlib/Extras.hsc" #-}
        rrData     <- xrrQueryExtension display
        let rrHasExtension = Maybe (CInt, CInt) -> Bool
    forall a. Maybe a -> Bool
    isJust Maybe (CInt, CInt)
    rrData
        let rrEventBase    = CInt -> EventType
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (CInt -> EventType) -> CInt -> EventType
    forall a b. (a -> b) -> a -> b
    $ (CInt, CInt) -> CInt
    forall a b. (a, b) -> a
    fst ((CInt, CInt) -> CInt) -> (CInt, CInt) -> CInt
    forall a b. (a -> b) -> a -> b
    $ (CInt, CInt) -> Maybe (CInt, CInt) -> (CInt, CInt)
    forall a. a -> Maybe a -> a
    fromMaybe (CInt
    0, CInt
    0) Maybe (CInt, CInt)
    rrData
        case () of

            -------------------------
            -- ConfigureRequestEvent:
            -------------------------
            ()
    _ | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    configureRequest -> do
                parent       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 382 "Graphics/X11/Xlib/Extras.hsc" #-}
                window       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 383 "Graphics/X11/Xlib/Extras.hsc" #-}
                x            <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 384 "Graphics/X11/Xlib/Extras.hsc" #-}
                y            <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    52) p
    {-# LINE 385 "Graphics/X11/Xlib/Extras.hsc" #-}
                width        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 386 "Graphics/X11/Xlib/Extras.hsc" #-}
                height       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    60) p
    {-# LINE 387 "Graphics/X11/Xlib/Extras.hsc" #-}
                border_width <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) p
    {-# LINE 388 "Graphics/X11/Xlib/Extras.hsc" #-}
                above        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) p
    {-# LINE 389 "Graphics/X11/Xlib/Extras.hsc" #-}
                detail       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    80) p
    {-# LINE 390 "Graphics/X11/Xlib/Extras.hsc" #-}
                value_mask   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CULong
    forall b. Ptr b -> Int -> IO CULong
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    88) p
    {-# LINE 391 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ ConfigureRequestEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_parent        = parent
                            , ev_window        = window
                            , ev_x             = x
                            , ev_y             = y
                            , ev_width         = width
                            , ev_height        = height
                            , ev_border_width  = border_width
                            , ev_above         = above
                            , ev_detail        = detail
                            , ev_value_mask    = value_mask
                            }

              ------------------
              -- ConfigureEvent:
              ------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    configureNotify -> do
                (XID
     -> XID
     -> CInt
     -> CInt
     -> CInt
     -> CInt
     -> CInt
     -> XID
     -> Bool
     -> Event)
    -> IO
         (XID
          -> XID
          -> CInt
          -> CInt
          -> CInt
          -> CInt
          -> CInt
          -> XID
          -> Bool
          -> Event)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (EventType
    -> CULong
    -> Bool
    -> Display
    -> XID
    -> XID
    -> CInt
    -> CInt
    -> CInt
    -> CInt
    -> CInt
    -> XID
    -> Bool
    -> Event
    ConfigureEvent EventType
    type_ CULong
    serial Bool
    send_event Display
    display)
                    IO
      (XID
       -> XID
       -> CInt
       -> CInt
       -> CInt
       -> CInt
       -> CInt
       -> XID
       -> Bool
       -> Event)
    -> IO XID
    -> IO
         (XID
          -> CInt -> CInt -> CInt -> CInt -> CInt -> XID -> Bool -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 414 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO
      (XID
       -> CInt -> CInt -> CInt -> CInt -> CInt -> XID -> Bool -> Event)
    -> IO XID
    -> IO
         (CInt -> CInt -> CInt -> CInt -> CInt -> XID -> Bool -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) XEventPtr
    p
    {-# LINE 415 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> CInt -> CInt -> CInt -> CInt -> XID -> Bool -> Event)
    -> IO CInt
    -> IO (CInt -> CInt -> CInt -> CInt -> XID -> Bool -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) XEventPtr
    p
    {-# LINE 416 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> CInt -> CInt -> CInt -> XID -> Bool -> Event)
    -> IO CInt -> IO (CInt -> CInt -> CInt -> XID -> Bool -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    52) XEventPtr
    p
    {-# LINE 417 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> CInt -> CInt -> XID -> Bool -> Event)
    -> IO CInt -> IO (CInt -> CInt -> XID -> Bool -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) XEventPtr
    p
    {-# LINE 418 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> CInt -> XID -> Bool -> Event)
    -> IO CInt -> IO (CInt -> XID -> Bool -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    60) XEventPtr
    p
    {-# LINE 419 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> XID -> Bool -> Event)
    -> IO CInt -> IO (XID -> Bool -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) XEventPtr
    p
    {-# LINE 420 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (XID -> Bool -> Event) -> IO XID -> IO (Bool -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) XEventPtr
    p
    {-# LINE 421 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (Bool -> Event) -> IO Bool -> IO Event
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Bool
    forall b. Ptr b -> Int -> IO Bool
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    80) XEventPtr
    p
    {-# LINE 422 "Graphics/X11/Xlib/Extras.hsc" #-}

              -------------------
              -- MapRequestEvent:
              -------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    mapRequest -> do
                parent <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 428 "Graphics/X11/Xlib/Extras.hsc" #-}
                window <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 429 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ MapRequestEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_parent        = parent
                            , ev_window        = window
                            }

              -------------------
              -- MapNotifyEvent
              -------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    mapNotify -> do
                event             <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32)  XEventPtr
    p
    {-# LINE 443 "Graphics/X11/Xlib/Extras.hsc" #-}
                window            <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 444 "Graphics/X11/Xlib/Extras.hsc" #-}
                override_redirect <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Bool
    forall b. Ptr b -> Int -> IO Bool
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 445 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ MapNotifyEvent
                            { ev_event_type        = type_
                            , ev_serial            = serial
                            , ev_send_event        = send_event
                            , ev_event_display     = display
                            , ev_event             = event
                            , ev_window            = window
                            , ev_override_redirect = override_redirect
                            }

              -------------------
              -- MappingNotifyEvent
              -------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    mappingNotify -> do
                window        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32)          XEventPtr
    p
    {-# LINE 460 "Graphics/X11/Xlib/Extras.hsc" #-}
                request       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40)         p
    {-# LINE 461 "Graphics/X11/Xlib/Extras.hsc" #-}
                first_keycode <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO KeyCode
    forall b. Ptr b -> Int -> IO KeyCode
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    44)   p
    {-# LINE 462 "Graphics/X11/Xlib/Extras.hsc" #-}
                count         <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48)           p
    {-# LINE 463 "Graphics/X11/Xlib/Extras.hsc" #-}

                return $ MappingNotifyEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            , ev_request       = request
                            , ev_first_keycode = first_keycode
                            , ev_count         = count
                            }

              ------------
              -- KeyEvent:
              ------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    keyPress Bool -> Bool -> Bool
    || EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    keyRelease -> do
                window      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 480 "Graphics/X11/Xlib/Extras.hsc" #-}
                root        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 481 "Graphics/X11/Xlib/Extras.hsc" #-}
                subwindow   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 482 "Graphics/X11/Xlib/Extras.hsc" #-}
                time        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 483 "Graphics/X11/Xlib/Extras.hsc" #-}
                x           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) p
    {-# LINE 484 "Graphics/X11/Xlib/Extras.hsc" #-}
                y           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    68) p
    {-# LINE 485 "Graphics/X11/Xlib/Extras.hsc" #-}
                x_root      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) p
    {-# LINE 486 "Graphics/X11/Xlib/Extras.hsc" #-}
                y_root      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    76) p
    {-# LINE 487 "Graphics/X11/Xlib/Extras.hsc" #-}
                state       <- ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO KeyMask
    forall b. Ptr b -> Int -> IO KeyMask
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    80) p) :: IO CUInt
    {-# LINE 488 "Graphics/X11/Xlib/Extras.hsc" #-}
                keycode     <- ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO KeyMask
    forall b. Ptr b -> Int -> IO KeyMask
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    84) p) :: IO CUInt
    {-# LINE 489 "Graphics/X11/Xlib/Extras.hsc" #-}
                same_screen <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Bool
    forall b. Ptr b -> Int -> IO Bool
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    88) p
    {-# LINE 490 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ KeyEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            , ev_root          = root
                            , ev_subwindow     = subwindow
                            , ev_time          = time
                            , ev_x             = x
                            , ev_y             = y
                            , ev_x_root        = x_root
                            , ev_y_root        = y_root
                            , ev_state         = fromIntegral state
                            , ev_keycode       = fromIntegral keycode
                            , ev_same_screen   = same_screen
                            }

              ---------------
              -- ButtonEvent:
              ---------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    buttonPress Bool -> Bool -> Bool
    || EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    buttonRelease -> do

                window      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 514 "Graphics/X11/Xlib/Extras.hsc" #-}
                root        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 515 "Graphics/X11/Xlib/Extras.hsc" #-}
                subwindow   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 516 "Graphics/X11/Xlib/Extras.hsc" #-}
                time        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 517 "Graphics/X11/Xlib/Extras.hsc" #-}
                x           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) p
    {-# LINE 518 "Graphics/X11/Xlib/Extras.hsc" #-}
                y           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    68) p
    {-# LINE 519 "Graphics/X11/Xlib/Extras.hsc" #-}
                x_root      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) p
    {-# LINE 520 "Graphics/X11/Xlib/Extras.hsc" #-}
                y_root      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    76) p
    {-# LINE 521 "Graphics/X11/Xlib/Extras.hsc" #-}
                state       <- ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO KeyMask
    forall b. Ptr b -> Int -> IO KeyMask
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    80) p) :: IO CUInt
    {-# LINE 522 "Graphics/X11/Xlib/Extras.hsc" #-}
                button      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    84) p
    {-# LINE 523 "Graphics/X11/Xlib/Extras.hsc" #-}
                same_screen <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Bool
    forall b. Ptr b -> Int -> IO Bool
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    88) p
    {-# LINE 524 "Graphics/X11/Xlib/Extras.hsc" #-}

                return $ ButtonEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            , ev_root          = root
                            , ev_subwindow     = subwindow
                            , ev_time          = time
                            , ev_x             = x
                            , ev_y             = y
                            , ev_x_root        = x_root
                            , ev_y_root        = y_root
                            , ev_state         = fromIntegral state
                            , ev_button        = button
                            , ev_same_screen   = same_screen
                            }

              ---------------
              -- MotionEvent:
              ---------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    motionNotify -> do
                window <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 548 "Graphics/X11/Xlib/Extras.hsc" #-}
                x      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) p
    {-# LINE 549 "Graphics/X11/Xlib/Extras.hsc" #-}
                y      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    68) p
    {-# LINE 550 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ MotionEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_x             = x
                            , ev_y             = y
                            , ev_window        = window
                            }

              ----------------------
              -- DestroyWindowEvent:
              ----------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    destroyNotify -> do
                event  <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 566 "Graphics/X11/Xlib/Extras.hsc" #-}
                window <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 567 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ DestroyWindowEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_event         = event
                            , ev_window        = window
                            }

              --------------------
              -- UnmapNotifyEvent:
              --------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    unmapNotify -> do
                event          <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 582 "Graphics/X11/Xlib/Extras.hsc" #-}
                window         <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 583 "Graphics/X11/Xlib/Extras.hsc" #-}
                from_configure <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Bool
    forall b. Ptr b -> Int -> IO Bool
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 584 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ UnmapEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_event         = event
                            , ev_window        = window
                            , ev_from_configure = from_configure
                            }

              --------------------
              -- CrossingEvent
              --------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    enterNotify Bool -> Bool -> Bool
    || EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    leaveNotify -> do
                window        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 599 "Graphics/X11/Xlib/Extras.hsc" #-}
                root          <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 600 "Graphics/X11/Xlib/Extras.hsc" #-}
                subwindow     <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 601 "Graphics/X11/Xlib/Extras.hsc" #-}
                time          <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 602 "Graphics/X11/Xlib/Extras.hsc" #-}
                x             <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) p
    {-# LINE 603 "Graphics/X11/Xlib/Extras.hsc" #-}
                y             <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    68) p
    {-# LINE 604 "Graphics/X11/Xlib/Extras.hsc" #-}
                x_root        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) p
    {-# LINE 605 "Graphics/X11/Xlib/Extras.hsc" #-}
                y_root        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    76) p
    {-# LINE 606 "Graphics/X11/Xlib/Extras.hsc" #-}
                mode          <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    80) p
    {-# LINE 607 "Graphics/X11/Xlib/Extras.hsc" #-}
                detail        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    84) p
    {-# LINE 608 "Graphics/X11/Xlib/Extras.hsc" #-}
                same_screen   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Bool
    forall b. Ptr b -> Int -> IO Bool
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    88) p
    {-# LINE 609 "Graphics/X11/Xlib/Extras.hsc" #-}
                focus         <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Bool
    forall b. Ptr b -> Int -> IO Bool
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    92) p
    {-# LINE 610 "Graphics/X11/Xlib/Extras.hsc" #-}
                state         <- ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO KeyMask
    forall b. Ptr b -> Int -> IO KeyMask
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    96) p) :: IO CUInt
    {-# LINE 611 "Graphics/X11/Xlib/Extras.hsc" #-}

                return $ CrossingEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            , ev_root          = root
                            , ev_subwindow     = subwindow
                            , ev_time          = time
                            , ev_x             = x
                            , ev_y             = y
                            , ev_x_root        = x_root
                            , ev_y_root        = y_root
                            , ev_mode          = mode
                            , ev_detail        = detail
                            , ev_same_screen   = same_screen
                            , ev_focus         = focus
                            , ev_state         = fromIntegral state
                            }

              -------------------------
              -- SelectionRequestEvent:
              -------------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    selectionRequest -> do
                owner          <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 637 "Graphics/X11/Xlib/Extras.hsc" #-}
                requestor      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 638 "Graphics/X11/Xlib/Extras.hsc" #-}
                selection      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 639 "Graphics/X11/Xlib/Extras.hsc" #-}
                target         <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 640 "Graphics/X11/Xlib/Extras.hsc" #-}
                property       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) p
    {-# LINE 641 "Graphics/X11/Xlib/Extras.hsc" #-}
                time           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) p
    {-# LINE 642 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ SelectionRequest
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_owner         = owner
                            , ev_requestor     = requestor
                            , ev_selection     = selection
                            , ev_target        = target
                            , ev_property      = property
                            , ev_time          = time
                            }

              -------------------------
              -- SelectionClearEvent:
              -------------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    selectionClear -> do
                window <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 660 "Graphics/X11/Xlib/Extras.hsc" #-}
                atom   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 661 "Graphics/X11/Xlib/Extras.hsc" #-}
                time   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 662 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ SelectionClear
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            , ev_selection     = atom
                            , ev_time          = time
                            }
              -------------------------
              -- PropertyEvent
              -------------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    propertyNotify -> do
                window <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 676 "Graphics/X11/Xlib/Extras.hsc" #-}
                atom   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 677 "Graphics/X11/Xlib/Extras.hsc" #-}
                time   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 678 "Graphics/X11/Xlib/Extras.hsc" #-}
                state  <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 679 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ PropertyEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            , ev_atom          = atom
                            , ev_time          = time
                            , ev_propstate     = state
                            }

              -------------------------
              -- ExposeEvent
              -------------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    expose -> do
                window <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 695 "Graphics/X11/Xlib/Extras.hsc" #-}
                x      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 696 "Graphics/X11/Xlib/Extras.hsc" #-}
                y      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    44) p
    {-# LINE 697 "Graphics/X11/Xlib/Extras.hsc" #-}
                width  <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 698 "Graphics/X11/Xlib/Extras.hsc" #-}
                height <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    52) p
    {-# LINE 699 "Graphics/X11/Xlib/Extras.hsc" #-}
                count  <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 700 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ ExposeEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            , ev_x             = x
                            , ev_y             = y
                            , ev_width         = width
                            , ev_height        = height
                            , ev_count         = count
                            }

              -------------------------
              -- FocusChangeEvent
              -------------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    focusIn Bool -> Bool -> Bool
    || EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    focusOut -> do
                window <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 718 "Graphics/X11/Xlib/Extras.hsc" #-}
                mode   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 719 "Graphics/X11/Xlib/Extras.hsc" #-}
                detail <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    44) p
    {-# LINE 720 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ FocusChangeEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            , ev_mode          = mode
                            , ev_detail        = detail
                            }

              -------------------------
              -- ClientMessageEvent
              -------------------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    clientMessage -> do
                window       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 735 "Graphics/X11/Xlib/Extras.hsc" #-}
                message_type <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 736 "Graphics/X11/Xlib/Extras.hsc" #-}
                format       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 737 "Graphics/X11/Xlib/Extras.hsc" #-}
                let datPtr =    (\XEventPtr
    hsc_ptr -> XEventPtr
    hsc_ptr XEventPtr -> Int -> Ptr b
    forall a b. Ptr a -> Int -> Ptr b
    `plusPtr` Int
    56) XEventPtr
    p
    {-# LINE 738 "Graphics/X11/Xlib/Extras.hsc" #-}
                dat          <- case (format::CInt) of
                            CInt
    8  -> do a <- Int -> Ptr KeyCode -> IO [KeyCode]
    forall a. Storable a => Int -> Ptr a -> IO [a]
    peekArray Int
    20 Ptr KeyCode
    forall {b}. Ptr b
    datPtr
                                     return $ map fromIntegral (a::[Word8])
                            CInt
    16 -> do a <- Int -> Ptr Word16 -> IO [Word16]
    forall a. Storable a => Int -> Ptr a -> IO [a]
    peekArray Int
    10 Ptr Word16
    forall {b}. Ptr b
    datPtr
                                     return $ map fromIntegral (a::[Word16])
                            CInt
    32 -> do a <- Int -> Ptr CLong -> IO [CLong]
    forall a. Storable a => Int -> Ptr a -> IO [a]
    peekArray Int
    5 Ptr CLong
    forall {b}. Ptr b
    datPtr
                                     return $ map fromIntegral (a::[CLong])
                            CInt
    _  -> String -> IO [CInt]
    forall a. HasCallStack => String -> a
    error String
    "X11.Extras.clientMessage: illegal value"
                return $ ClientMessageEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            , ev_message_type  = message_type
                            , ev_data          = dat
                            }

              -------------------------
              -- RRScreenChangeNotify
              -------------------------
              | Bool
    rrHasExtension Bool -> Bool -> Bool
    &&
                EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    rrEventBase EventType -> EventType -> EventType
    forall a. Num a => a -> a -> a
    + EventType
    rrScreenChangeNotify -> do
                window           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 762 "Graphics/X11/Xlib/Extras.hsc" #-}
                root             <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 763 "Graphics/X11/Xlib/Extras.hsc" #-}
                timestamp        <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) p
    {-# LINE 764 "Graphics/X11/Xlib/Extras.hsc" #-}
                config_timestamp <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 765 "Graphics/X11/Xlib/Extras.hsc" #-}
                size_index       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 766 "Graphics/X11/Xlib/Extras.hsc" #-}
                subpixel_order   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    66) p
    {-# LINE 767 "Graphics/X11/Xlib/Extras.hsc" #-}
                rotation         <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    68) p
    {-# LINE 768 "Graphics/X11/Xlib/Extras.hsc" #-}
                width            <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) p
    {-# LINE 769 "Graphics/X11/Xlib/Extras.hsc" #-}
                height           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    76) p
    {-# LINE 770 "Graphics/X11/Xlib/Extras.hsc" #-}
                mwidth           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    80) p
    {-# LINE 771 "Graphics/X11/Xlib/Extras.hsc" #-}
                mheight          <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    84) p
    {-# LINE 772 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ RRScreenChangeNotifyEvent
                            { ev_event_type       = type_
                            , ev_serial           = serial
                            , ev_send_event       = send_event
                            , ev_event_display    = display
                            , ev_window           = window
                            , ev_root             = root
                            , ev_timestamp        = timestamp
                            , ev_config_timestamp = config_timestamp
                            , ev_size_index       = size_index
                            , ev_subpixel_order   = subpixel_order
                            , ev_rotation         = rotation
                            , ev_width            = width
                            , ev_height           = height
                            , ev_mwidth           = mwidth
                            , ev_mheight          = mheight
                            }

              -------------------------
              -- RRNotify
              -------------------------
              | Bool
    rrHasExtension Bool -> Bool -> Bool
    &&
                EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    rrEventBase EventType -> EventType -> EventType
    forall a. Num a => a -> a -> a
    + EventType
    rrNotify -> do
                window   <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 796 "Graphics/X11/Xlib/Extras.hsc" #-}
                subtype  <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) p
    {-# LINE 797 "Graphics/X11/Xlib/Extras.hsc" #-}
                let subtype_ = CInt -> EventType
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    subtype
                case () of
                    ()
    _ | EventType
    subtype_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    rrNotifyCrtcChange -> do
                        crtc           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) XEventPtr
    p
    {-# LINE 801 "Graphics/X11/Xlib/Extras.hsc" #-}
                        mode           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 802 "Graphics/X11/Xlib/Extras.hsc" #-}
                        rotation       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) p
    {-# LINE 803 "Graphics/X11/Xlib/Extras.hsc" #-}
                        x              <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    68) p
    {-# LINE 804 "Graphics/X11/Xlib/Extras.hsc" #-}
                        y              <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) p
    {-# LINE 805 "Graphics/X11/Xlib/Extras.hsc" #-}
                        width          <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO KeyMask
    forall b. Ptr b -> Int -> IO KeyMask
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    76) p
    {-# LINE 806 "Graphics/X11/Xlib/Extras.hsc" #-}
                        height         <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO KeyMask
    forall b. Ptr b -> Int -> IO KeyMask
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    80) p
    {-# LINE 807 "Graphics/X11/Xlib/Extras.hsc" #-}
                        return $ RRCrtcChangeNotifyEvent
                                 { ev_event_type    = type_
                                 , ev_serial        = serial
                                 , ev_send_event    = send_event
                                 , ev_event_display = display
                                 , ev_window        = window
                                 , ev_subtype       = subtype
                                 , ev_crtc          = crtc
                                 , ev_rr_mode       = mode
                                 , ev_rotation      = rotation
                                 , ev_x             = x
                                 , ev_y             = y
                                 , ev_rr_width      = width
                                 , ev_rr_height     = height
                                 }

                      | EventType
    subtype_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    rrNotifyOutputChange -> do
                        output         <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) XEventPtr
    p
    {-# LINE 825 "Graphics/X11/Xlib/Extras.hsc" #-}
                        crtc           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 826 "Graphics/X11/Xlib/Extras.hsc" #-}
                        mode           <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) p
    {-# LINE 827 "Graphics/X11/Xlib/Extras.hsc" #-}
                        rotation       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) p
    {-# LINE 828 "Graphics/X11/Xlib/Extras.hsc" #-}
                        connection     <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    74) p
    {-# LINE 829 "Graphics/X11/Xlib/Extras.hsc" #-}
                        subpixel_order <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    76) p
    {-# LINE 830 "Graphics/X11/Xlib/Extras.hsc" #-}
                        return $ RROutputChangeNotifyEvent
                                 { ev_event_type     = type_
                                 , ev_serial         = serial
                                 , ev_send_event     = send_event
                                 , ev_event_display  = display
                                 , ev_window         = window
                                 , ev_subtype        = subtype
                                 , ev_output         = output
                                 , ev_crtc           = crtc
                                 , ev_rr_mode        = mode
                                 , ev_rotation       = rotation
                                 , ev_connection     = connection
                                 , ev_subpixel_order = subpixel_order
                                 }

                      | EventType
    subtype_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    rrNotifyOutputProperty -> do
                        output         <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) XEventPtr
    p
    {-# LINE 847 "Graphics/X11/Xlib/Extras.hsc" #-}
                        property       <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) p
    {-# LINE 848 "Graphics/X11/Xlib/Extras.hsc" #-}
                        timestamp      <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) p
    {-# LINE 849 "Graphics/X11/Xlib/Extras.hsc" #-}
                        state          <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    72) p
    {-# LINE 850 "Graphics/X11/Xlib/Extras.hsc" #-}
                        return $ RROutputPropertyNotifyEvent
                                 { ev_event_type    = type_
                                 , ev_serial        = serial
                                 , ev_send_event    = send_event
                                 , ev_event_display = display
                                 , ev_window        = window
                                 , ev_subtype       = subtype
                                 , ev_output        = output
                                 , ev_property      = property
                                 , ev_timestamp     = timestamp
                                 , ev_rr_state      = state
                                 }

                      -- We don't handle this event specifically, so return the generic
                      -- RRNotifyEvent.
                      | Bool
    otherwise -> do
                        Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $ RRNotifyEvent
                                    { ev_event_type :: EventType
    ev_event_type    = EventType
    type_
                                    , ev_serial :: CULong
    ev_serial        = CULong
    serial
                                    , ev_send_event :: Bool
    ev_send_event    = Bool
    send_event
                                    , ev_event_display :: Display
    ev_event_display = Display
    display
                                    , ev_window :: XID
    ev_window        = XID
    window
                                    , ev_subtype :: CInt
    ev_subtype       = CInt
    subtype
                                    }

              -----------------
              -- ScreenSaverNotifyEvent:
              -----------------
              | EventType
    type_ EventType -> EventType -> Bool
    forall a. Eq a => a -> a -> Bool
    == EventType
    screenSaverNotify -> do
                (XID
     -> XID
     -> XScreenSaverState
     -> XScreenSaverKind
     -> Bool
     -> XID
     -> Event)
    -> IO
         (XID
          -> XID
          -> XScreenSaverState
          -> XScreenSaverKind
          -> Bool
          -> XID
          -> Event)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (EventType
    -> CULong
    -> Bool
    -> Display
    -> XID
    -> XID
    -> XScreenSaverState
    -> XScreenSaverKind
    -> Bool
    -> XID
    -> Event
    ScreenSaverNotifyEvent EventType
    type_ CULong
    serial Bool
    send_event Display
    display)
                    IO
      (XID
       -> XID
       -> XScreenSaverState
       -> XScreenSaverKind
       -> Bool
       -> XID
       -> Event)
    -> IO XID
    -> IO
         (XID
          -> XScreenSaverState -> XScreenSaverKind -> Bool -> XID -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p )
    {-# LINE 881 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO
      (XID
       -> XScreenSaverState -> XScreenSaverKind -> Bool -> XID -> Event)
    -> IO XID
    -> IO
         (XScreenSaverState -> XScreenSaverKind -> Bool -> XID -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    40) XEventPtr
    p )
    {-# LINE 882 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (XScreenSaverState -> XScreenSaverKind -> Bool -> XID -> Event)
    -> IO XScreenSaverState
    -> IO (XScreenSaverKind -> Bool -> XID -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XScreenSaverState
    forall b. Ptr b -> Int -> IO XScreenSaverState
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    48) XEventPtr
    p )
    {-# LINE 883 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (XScreenSaverKind -> Bool -> XID -> Event)
    -> IO XScreenSaverKind -> IO (Bool -> XID -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XScreenSaverKind
    forall b. Ptr b -> Int -> IO XScreenSaverKind
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    52) XEventPtr
    p )
    {-# LINE 884 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (Bool -> XID -> Event) -> IO Bool -> IO (XID -> Event)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO Bool
    forall b. Ptr b -> Int -> IO Bool
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    56) XEventPtr
    p )
    {-# LINE 885 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (XID -> Event) -> IO XID -> IO Event
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    64) XEventPtr
    p )
    {-# LINE 886 "Graphics/X11/Xlib/Extras.hsc" #-}

              -- We don't handle this event specifically, so return the generic
              -- AnyEvent.
              | Bool
    otherwise -> do
                window <- (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p
    {-# LINE 891 "Graphics/X11/Xlib/Extras.hsc" #-}
                return $ AnyEvent
                            { ev_event_type    = type_
                            , ev_serial        = serial
                            , ev_send_event    = send_event
                            , ev_event_display = display
                            , ev_window        = window
                            }

    data WindowChanges = WindowChanges
                            { WindowChanges -> CInt
    wc_x :: CInt
                            , WindowChanges -> CInt
    wc_y :: CInt
                            , WindowChanges -> CInt
    wc_width :: CInt
                            , WindowChanges -> CInt
    wc_height:: CInt
                            , WindowChanges -> CInt
    wc_border_width :: CInt
                            , WindowChanges -> XID
    wc_sibling :: Window
                            , WindowChanges -> CInt
    wc_stack_mode :: CInt
                            }

    instance Storable WindowChanges where
        sizeOf :: WindowChanges -> Int
    sizeOf WindowChanges
    _ = (Int
    40)
    {-# LINE 911 "Graphics/X11/Xlib/Extras.hsc" #-}

        -- I really hope this is right:
        alignment :: WindowChanges -> Int
    alignment WindowChanges
    _ = CInt -> Int
    forall a. Storable a => a -> Int
    alignment (CInt
    forall a. HasCallStack => a
    undefined :: CInt)

        poke :: Ptr WindowChanges -> WindowChanges -> IO ()
    poke Ptr WindowChanges
    p WindowChanges
    wc = do
            (\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> CInt -> IO ()
    forall b. Ptr b -> Int -> CInt -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WindowChanges
    hsc_ptr Int
    0) Ptr WindowChanges
    p (CInt -> IO ()) -> CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WindowChanges -> CInt
    wc_x WindowChanges
    wc
    {-# LINE 917 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> CInt -> IO ()
    forall b. Ptr b -> Int -> CInt -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WindowChanges
    hsc_ptr Int
    4) Ptr WindowChanges
    p (CInt -> IO ()) -> CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WindowChanges -> CInt
    wc_y WindowChanges
    wc
    {-# LINE 918 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> CInt -> IO ()
    forall b. Ptr b -> Int -> CInt -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WindowChanges
    hsc_ptr Int
    8) Ptr WindowChanges
    p (CInt -> IO ()) -> CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WindowChanges -> CInt
    wc_width WindowChanges
    wc
    {-# LINE 919 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> CInt -> IO ()
    forall b. Ptr b -> Int -> CInt -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WindowChanges
    hsc_ptr Int
    12) Ptr WindowChanges
    p (CInt -> IO ()) -> CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WindowChanges -> CInt
    wc_height WindowChanges
    wc
    {-# LINE 920 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> CInt -> IO ()
    forall b. Ptr b -> Int -> CInt -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WindowChanges
    hsc_ptr Int
    16) Ptr WindowChanges
    p (CInt -> IO ()) -> CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WindowChanges -> CInt
    wc_border_width WindowChanges
    wc
    {-# LINE 921 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> XID -> IO ()
    forall b. Ptr b -> Int -> XID -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WindowChanges
    hsc_ptr Int
    24) Ptr WindowChanges
    p (XID -> IO ()) -> XID -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WindowChanges -> XID
    wc_sibling WindowChanges
    wc
    {-# LINE 922 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> CInt -> IO ()
    forall b. Ptr b -> Int -> CInt -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WindowChanges
    hsc_ptr Int
    32) Ptr WindowChanges
    p (CInt -> IO ()) -> CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WindowChanges -> CInt
    wc_stack_mode WindowChanges
    wc
    {-# LINE 923 "Graphics/X11/Xlib/Extras.hsc" #-}

        peek :: Ptr WindowChanges -> IO WindowChanges
    peek Ptr WindowChanges
    p = (CInt
     -> CInt -> CInt -> CInt -> CInt -> XID -> CInt -> WindowChanges)
    -> IO
         (CInt
          -> CInt -> CInt -> CInt -> CInt -> XID -> CInt -> WindowChanges)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CInt
    -> CInt -> CInt -> CInt -> CInt -> XID -> CInt -> WindowChanges
    WindowChanges
                    IO
      (CInt
       -> CInt -> CInt -> CInt -> CInt -> XID -> CInt -> WindowChanges)
    -> IO CInt
    -> IO
         (CInt -> CInt -> CInt -> CInt -> XID -> CInt -> WindowChanges)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WindowChanges
    hsc_ptr Int
    0) Ptr WindowChanges
    p)
    {-# LINE 926 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> CInt -> CInt -> CInt -> XID -> CInt -> WindowChanges)
    -> IO CInt
    -> IO (CInt -> CInt -> CInt -> XID -> CInt -> WindowChanges)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WindowChanges
    hsc_ptr Int
    4) Ptr WindowChanges
    p)
    {-# LINE 927 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> CInt -> CInt -> XID -> CInt -> WindowChanges)
    -> IO CInt -> IO (CInt -> CInt -> XID -> CInt -> WindowChanges)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WindowChanges
    hsc_ptr Int
    8) Ptr WindowChanges
    p)
    {-# LINE 928 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> CInt -> XID -> CInt -> WindowChanges)
    -> IO CInt -> IO (CInt -> XID -> CInt -> WindowChanges)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WindowChanges
    hsc_ptr Int
    12) Ptr WindowChanges
    p)
    {-# LINE 929 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> XID -> CInt -> WindowChanges)
    -> IO CInt -> IO (XID -> CInt -> WindowChanges)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WindowChanges
    hsc_ptr Int
    16) Ptr WindowChanges
    p)
    {-# LINE 930 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (XID -> CInt -> WindowChanges)
    -> IO XID -> IO (CInt -> WindowChanges)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WindowChanges
    hsc_ptr Int
    24) Ptr WindowChanges
    p)
    {-# LINE 931 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> WindowChanges) -> IO CInt -> IO WindowChanges
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` ((\Ptr WindowChanges
    hsc_ptr -> Ptr WindowChanges -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WindowChanges
    hsc_ptr Int
    32) Ptr WindowChanges
    p)
    {-# LINE 932 "Graphics/X11/Xlib/Extras.hsc" #-}

    --
    -- Some extra constants
    --

    none :: XID
    none :: XID
    none = XID
    0
    {-# LINE 939 "Graphics/X11/Xlib/Extras.hsc" #-}

    anyButton :: Button
    anyButton :: EventType
    anyButton = EventType
    0
    {-# LINE 942 "Graphics/X11/Xlib/Extras.hsc" #-}

    anyKey :: KeyCode
    anyKey :: KeyCode
    anyKey = Int -> KeyCode
    forall a. Enum a => Int -> a
    toEnum Int
    0
    {-# LINE 945 "Graphics/X11/Xlib/Extras.hsc" #-}

    currentTime :: Time
    currentTime :: XID
    currentTime = XID
    0
    {-# LINE 948 "Graphics/X11/Xlib/Extras.hsc" #-}

    --
    -- The use of Int rather than CInt isn't 64 bit clean.
    --

    foreign import ccall unsafe "XlibExtras.h XConfigureWindow"
        xConfigureWindow :: Display -> Window -> CULong -> Ptr WindowChanges -> IO CInt

    foreign import ccall unsafe "XlibExtras.h XKillClient"
        killClient :: Display -> Window -> IO CInt

    configureWindow :: Display -> Window -> CULong -> WindowChanges -> IO ()
    configureWindow :: Display -> XID -> CULong -> WindowChanges -> IO ()
    configureWindow Display
    d XID
    w CULong
    m WindowChanges
    c = do
        _ <- WindowChanges -> (Ptr WindowChanges -> IO CInt) -> IO CInt
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with WindowChanges
    c (Display -> XID -> CULong -> Ptr WindowChanges -> IO CInt
    xConfigureWindow Display
    d XID
    w CULong
    m)
        return ()

    foreign import ccall unsafe "XlibExtras.h XQueryTree"
        xQueryTree :: Display -> Window -> Ptr Window -> Ptr Window -> Ptr (Ptr Window) -> Ptr CInt -> IO Status

    queryTree :: Display -> Window -> IO (Window, Window, [Window])
    queryTree :: Display -> XID -> IO (XID, XID, [XID])
    queryTree Display
    d XID
    w =
        (Ptr XID -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr XID -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID]))
    -> (Ptr XID -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID])
    forall a b. (a -> b) -> a -> b
    $ \Ptr XID
    root_return ->
        (Ptr XID -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr XID -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID]))
    -> (Ptr XID -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID])
    forall a b. (a -> b) -> a -> b
    $ \Ptr XID
    parent_return ->
        (Ptr (Ptr XID) -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr (Ptr XID) -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID]))
    -> (Ptr (Ptr XID) -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID])
    forall a b. (a -> b) -> a -> b
    $ \Ptr (Ptr XID)
    children_return ->
        (Ptr CInt -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CInt -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID]))
    -> (Ptr CInt -> IO (XID, XID, [XID])) -> IO (XID, XID, [XID])
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    nchildren_return -> do
            _ <- String -> IO CInt -> IO ()
    throwIfZero String
    "queryTree" (IO CInt -> IO ()) -> IO CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Display
    -> XID
    -> Ptr XID
    -> Ptr XID
    -> Ptr (Ptr XID)
    -> Ptr CInt
    -> IO CInt
    xQueryTree Display
    d XID
    w Ptr XID
    root_return Ptr XID
    parent_return Ptr (Ptr XID)
    children_return Ptr CInt
    nchildren_return
            p <- peek children_return
            n <- fmap fromIntegral $ peek nchildren_return
            ws <- peekArray n p
            _ <- xFree p
            liftM3 (,,) (peek root_return) (peek parent_return) (return ws)

    -- TODO: this data type is incomplete wrt. the C struct
    data WindowAttributes = WindowAttributes
                { WindowAttributes -> CInt
    wa_x, WindowAttributes -> CInt
    wa_y, WindowAttributes -> CInt
    wa_width, WindowAttributes -> CInt
    wa_height, WindowAttributes -> CInt
    wa_border_width :: CInt
                , WindowAttributes -> XID
    wa_colormap :: Colormap
                , WindowAttributes -> Bool
    wa_map_installed :: Bool
                , WindowAttributes -> CInt
    wa_map_state :: CInt
                , WindowAttributes -> XID
    wa_all_event_masks :: EventMask
                , WindowAttributes -> XID
    wa_your_event_mask :: EventMask
                , WindowAttributes -> XID
    wa_do_not_propagate_mask :: EventMask
                , WindowAttributes -> Bool
    wa_override_redirect :: Bool
                }

    --
    -- possible map_states'
    --
    waIsUnmapped, waIsUnviewable, waIsViewable :: CInt
    waIsUnmapped :: CInt
    waIsUnmapped   = CInt -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral ( CInt
    0   :: CInt )  -- 0
    {-# LINE 997 "Graphics/X11/Xlib/Extras.hsc" #-}
    waIsUnviewable = fromIntegral ( 1 :: CInt )  -- 1
    {-# LINE 998 "Graphics/X11/Xlib/Extras.hsc" #-}
    waIsViewable   = fromIntegral ( 2   :: CInt )  -- 2
    {-# LINE 999 "Graphics/X11/Xlib/Extras.hsc" #-}

    instance Storable WindowAttributes where
        -- this might be incorrect
        alignment :: WindowAttributes -> Int
    alignment WindowAttributes
    _ = CInt -> Int
    forall a. Storable a => a -> Int
    alignment (CInt
    forall a. HasCallStack => a
    undefined :: CInt)
        sizeOf :: WindowAttributes -> Int
    sizeOf WindowAttributes
    _ = (Int
    136)
    {-# LINE 1004 "Graphics/X11/Xlib/Extras.hsc" #-}
        peek p = return WindowAttributes
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 0) p)
    {-# LINE 1006 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 4) p)
    {-# LINE 1007 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 8) p)
    {-# LINE 1008 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 12) p)
    {-# LINE 1009 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 16) p)
    {-# LINE 1010 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 80) p)
    {-# LINE 1011 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 88) p)
    {-# LINE 1012 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 92) p)
    {-# LINE 1013 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 96) p)
    {-# LINE 1014 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 104) p)
    {-# LINE 1015 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 112) p)
    {-# LINE 1016 "Graphics/X11/Xlib/Extras.hsc" #-}
                    `ap` ((\hsc_ptr -> peekByteOff hsc_ptr 120) p)
    {-# LINE 1017 "Graphics/X11/Xlib/Extras.hsc" #-}
        poke p wa = do
            (\hsc_ptr -> pokeByteOff hsc_ptr 0) p $ wa_x wa
    {-# LINE 1019 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 4) p $ wa_y wa
    {-# LINE 1020 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 8) p $ wa_width wa
    {-# LINE 1021 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 12) p $ wa_height wa
    {-# LINE 1022 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 16) p $ wa_border_width wa
    {-# LINE 1023 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 80) p $ wa_colormap wa
    {-# LINE 1024 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 88) p $ wa_map_installed wa
    {-# LINE 1025 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 92) p $ wa_map_state wa
    {-# LINE 1026 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 96) p $ wa_all_event_masks wa
    {-# LINE 1027 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 104) p $ wa_your_event_mask wa
    {-# LINE 1028 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 112) p $ wa_do_not_propagate_mask wa
    {-# LINE 1029 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 120) p $ wa_override_redirect wa
    {-# LINE 1030 "Graphics/X11/Xlib/Extras.hsc" #-}

    foreign import ccall unsafe "XlibExtras.h XGetWindowAttributes"
        xGetWindowAttributes :: Display -> Window -> Ptr (WindowAttributes) -> IO Status

    getWindowAttributes :: Display -> Window -> IO WindowAttributes
    getWindowAttributes :: Display -> XID -> IO WindowAttributes
    getWindowAttributes Display
    d XID
    w = (Ptr WindowAttributes -> IO WindowAttributes)
    -> IO WindowAttributes
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr WindowAttributes -> IO WindowAttributes)
     -> IO WindowAttributes)
    -> (Ptr WindowAttributes -> IO WindowAttributes)
    -> IO WindowAttributes
    forall a b. (a -> b) -> a -> b
    $ \Ptr WindowAttributes
    p -> do
        _ <- String -> IO CInt -> IO ()
    throwIfZero String
    "getWindowAttributes" (IO CInt -> IO ()) -> IO CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ Display -> XID -> Ptr WindowAttributes -> IO CInt
    xGetWindowAttributes Display
    d XID
    w Ptr WindowAttributes
    p
        peek p

    -- | interface to the X11 library function @XChangeWindowAttributes()@.
    foreign import ccall unsafe "XlibExtras.h XChangeWindowAttributes"
            changeWindowAttributes :: Display -> Window -> AttributeMask -> Ptr SetWindowAttributes -> IO ()

    -- | Run an action with the server
    withServer :: Display -> IO () -> IO ()
    withServer :: Display -> IO () -> IO ()
    withServer Display
    dpy IO ()
    f = do
        Display -> IO ()
    grabServer Display
    dpy
        IO ()
    f
        Display -> IO ()
    ungrabServer Display
    dpy

    data TextProperty = TextProperty {
            TextProperty -> CString
    tp_value    :: CString,
            TextProperty -> XID
    tp_encoding :: Atom,
            TextProperty -> CInt
    tp_format   :: CInt,
            TextProperty -> XID
    tp_nitems   :: Word64
    {-# LINE 1055 "Graphics/X11/Xlib/Extras.hsc" #-}
        }

    instance Storable TextProperty where
        sizeOf :: TextProperty -> Int
    sizeOf    TextProperty
    _ = (Int
    32)
    {-# LINE 1059 "Graphics/X11/Xlib/Extras.hsc" #-}
        alignment _ = alignment (undefined :: Word64)
    {-# LINE 1060 "Graphics/X11/Xlib/Extras.hsc" #-}
        peek p = TextProperty `fmap` (\hsc_ptr -> peekByteOff hsc_ptr 0) p
    {-# LINE 1061 "Graphics/X11/Xlib/Extras.hsc" #-}
                              `ap`   (\hsc_ptr -> peekByteOff hsc_ptr 8) p
    {-# LINE 1062 "Graphics/X11/Xlib/Extras.hsc" #-}
                              `ap`   (\hsc_ptr -> peekByteOff hsc_ptr 16) p
    {-# LINE 1063 "Graphics/X11/Xlib/Extras.hsc" #-}
                              `ap`   (\hsc_ptr -> peekByteOff hsc_ptr 24) p
    {-# LINE 1064 "Graphics/X11/Xlib/Extras.hsc" #-}
        poke p (TextProperty val enc fmt nitems) = do
            (\hsc_ptr -> pokeByteOff hsc_ptr 0) p val
    {-# LINE 1066 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 8) p enc
    {-# LINE 1067 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 16) p fmt
    {-# LINE 1068 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 24) p nitems
    {-# LINE 1069 "Graphics/X11/Xlib/Extras.hsc" #-}

    foreign import ccall unsafe "XlibExtras.h XGetTextProperty"
        xGetTextProperty :: Display -> Window -> Ptr TextProperty -> Atom -> IO Status

    getTextProperty :: Display -> Window -> Atom -> IO TextProperty
    getTextProperty :: Display -> XID -> XID -> IO TextProperty
    getTextProperty Display
    d XID
    w XID
    a =
        (Ptr TextProperty -> IO TextProperty) -> IO TextProperty
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr TextProperty -> IO TextProperty) -> IO TextProperty)
    -> (Ptr TextProperty -> IO TextProperty) -> IO TextProperty
    forall a b. (a -> b) -> a -> b
    $ \Ptr TextProperty
    textp -> do
            _ <- (CInt -> Bool) -> (CInt -> String) -> IO CInt -> IO CInt
    forall a. (a -> Bool) -> (a -> String) -> IO a -> IO a
    throwIf (CInt
    0CInt -> CInt -> Bool
    forall a. Eq a => a -> a -> Bool
    ==) (String -> CInt -> String
    forall a b. a -> b -> a
    const String
    "getTextProperty") (IO CInt -> IO CInt) -> IO CInt -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ Display -> XID -> Ptr TextProperty -> XID -> IO CInt
    xGetTextProperty Display
    d XID
    w Ptr TextProperty
    textp XID
    a
            peek textp

    foreign import ccall unsafe "XlibExtras.h XwcTextPropertyToTextList"
        xwcTextPropertyToTextList :: Display -> Ptr TextProperty -> Ptr (Ptr CWString) -> Ptr CInt -> IO CInt

    wcTextPropertyToTextList :: Display -> TextProperty -> IO [String]
    wcTextPropertyToTextList :: Display -> TextProperty -> IO [String]
    wcTextPropertyToTextList Display
    d TextProperty
    prop =
        (Ptr (Ptr CWString) -> IO [String]) -> IO [String]
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca    ((Ptr (Ptr CWString) -> IO [String]) -> IO [String])
    -> (Ptr (Ptr CWString) -> IO [String]) -> IO [String]
    forall a b. (a -> b) -> a -> b
    $ \Ptr (Ptr CWString)
    listp  ->
        (Ptr CInt -> IO [String]) -> IO [String]
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca    ((Ptr CInt -> IO [String]) -> IO [String])
    -> (Ptr CInt -> IO [String]) -> IO [String]
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    countp ->
        TextProperty -> (Ptr TextProperty -> IO [String]) -> IO [String]
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with TextProperty
    prop ((Ptr TextProperty -> IO [String]) -> IO [String])
    -> (Ptr TextProperty -> IO [String]) -> IO [String]
    forall a b. (a -> b) -> a -> b
    $ \Ptr TextProperty
    propp  -> do
            _ <- (CInt -> Bool) -> (CInt -> String) -> IO CInt -> IO CInt
    forall a. (a -> Bool) -> (a -> String) -> IO a -> IO a
    throwIf (CInt
    successCInt -> CInt -> Bool
    forall a. Ord a => a -> a -> Bool
    >) (String -> CInt -> String
    forall a b. a -> b -> a
    const String
    "wcTextPropertyToTextList") (IO CInt -> IO CInt) -> IO CInt -> IO CInt
    forall a b. (a -> b) -> a -> b
    $
                Display
    -> Ptr TextProperty -> Ptr (Ptr CWString) -> Ptr CInt -> IO CInt
    xwcTextPropertyToTextList Display
    d Ptr TextProperty
    propp Ptr (Ptr CWString)
    listp Ptr CInt
    countp
            count <- peek countp
            list  <- peek listp
            texts <- flip mapM [0..fromIntegral count - 1] $ \Int
    i ->
                         Ptr CWString -> Int -> IO CWString
    forall a. Storable a => Ptr a -> Int -> IO a
    peekElemOff Ptr CWString
    list Int
    i IO CWString -> (CWString -> IO String) -> IO String
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= CWString -> IO String
    peekCWString
            wcFreeStringList list
            return texts

    foreign import ccall unsafe "XlibExtras.h XwcFreeStringList"
        wcFreeStringList :: Ptr CWString -> IO ()

    newtype FontSet = FontSet (Ptr FontSet)
        deriving (FontSet -> FontSet -> Bool
    (FontSet -> FontSet -> Bool)
    -> (FontSet -> FontSet -> Bool) -> Eq FontSet
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: FontSet -> FontSet -> Bool
    == :: FontSet -> FontSet -> Bool
    $c/= :: FontSet -> FontSet -> Bool
    /= :: FontSet -> FontSet -> Bool
    Eq, Eq FontSet
    Eq FontSet =>
    (FontSet -> FontSet -> Ordering)
    -> (FontSet -> FontSet -> Bool)
    -> (FontSet -> FontSet -> Bool)
    -> (FontSet -> FontSet -> Bool)
    -> (FontSet -> FontSet -> Bool)
    -> (FontSet -> FontSet -> FontSet)
    -> (FontSet -> FontSet -> FontSet)
    -> Ord FontSet
    FontSet -> FontSet -> Bool
    FontSet -> FontSet -> Ordering
    FontSet -> FontSet -> FontSet
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: FontSet -> FontSet -> Ordering
    compare :: FontSet -> FontSet -> Ordering
    $c< :: FontSet -> FontSet -> Bool
    < :: FontSet -> FontSet -> Bool
    $c<= :: FontSet -> FontSet -> Bool
    <= :: FontSet -> FontSet -> Bool
    $c> :: FontSet -> FontSet -> Bool
    > :: FontSet -> FontSet -> Bool
    $c>= :: FontSet -> FontSet -> Bool
    >= :: FontSet -> FontSet -> Bool
    $cmax :: FontSet -> FontSet -> FontSet
    max :: FontSet -> FontSet -> FontSet
    $cmin :: FontSet -> FontSet -> FontSet
    min :: FontSet -> FontSet -> FontSet
    Ord, Int -> FontSet -> ShowS
    [FontSet] -> ShowS
    FontSet -> String
    (Int -> FontSet -> ShowS)
    -> (FontSet -> String) -> ([FontSet] -> ShowS) -> Show FontSet
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> FontSet -> ShowS
    showsPrec :: Int -> FontSet -> ShowS
    $cshow :: FontSet -> String
    show :: FontSet -> String
    $cshowList :: [FontSet] -> ShowS
    showList :: [FontSet] -> ShowS
    Show)

    foreign import ccall unsafe "XlibExtras.h XCreateFontSet"
        xCreateFontSet :: Display -> CString -> Ptr (Ptr CString) -> Ptr CInt -> Ptr CString -> IO (Ptr FontSet)

    createFontSet :: Display -> String -> IO ([String], String, FontSet)
    createFontSet :: Display -> String -> IO ([String], String, FontSet)
    createFontSet Display
    d String
    fn =
        String
    -> (CString -> IO ([String], String, FontSet))
    -> IO ([String], String, FontSet)
    forall a. String -> (CString -> IO a) -> IO a
    withCString String
    fn ((CString -> IO ([String], String, FontSet))
     -> IO ([String], String, FontSet))
    -> (CString -> IO ([String], String, FontSet))
    -> IO ([String], String, FontSet)
    forall a b. (a -> b) -> a -> b
    $ \CString
    fontp  ->
        (Ptr (Ptr CString) -> IO ([String], String, FontSet))
    -> IO ([String], String, FontSet)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca         ((Ptr (Ptr CString) -> IO ([String], String, FontSet))
     -> IO ([String], String, FontSet))
    -> (Ptr (Ptr CString) -> IO ([String], String, FontSet))
    -> IO ([String], String, FontSet)
    forall a b. (a -> b) -> a -> b
    $ \Ptr (Ptr CString)
    listp  ->
        (Ptr CInt -> IO ([String], String, FontSet))
    -> IO ([String], String, FontSet)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca         ((Ptr CInt -> IO ([String], String, FontSet))
     -> IO ([String], String, FontSet))
    -> (Ptr CInt -> IO ([String], String, FontSet))
    -> IO ([String], String, FontSet)
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    countp ->
        (Ptr CString -> IO ([String], String, FontSet))
    -> IO ([String], String, FontSet)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca         ((Ptr CString -> IO ([String], String, FontSet))
     -> IO ([String], String, FontSet))
    -> (Ptr CString -> IO ([String], String, FontSet))
    -> IO ([String], String, FontSet)
    forall a b. (a -> b) -> a -> b
    $ \Ptr CString
    defp   -> do
            fs      <- String -> IO (Ptr FontSet) -> IO (Ptr FontSet)
    forall a. String -> IO (Ptr a) -> IO (Ptr a)
    throwIfNull String
    "createFontSet" (IO (Ptr FontSet) -> IO (Ptr FontSet))
    -> IO (Ptr FontSet) -> IO (Ptr FontSet)
    forall a b. (a -> b) -> a -> b
    $
                           Display
    -> CString
    -> Ptr (Ptr CString)
    -> Ptr CInt
    -> Ptr CString
    -> IO (Ptr FontSet)
    xCreateFontSet Display
    d CString
    fontp Ptr (Ptr CString)
    listp Ptr CInt
    countp Ptr CString
    defp
            count   <- peek countp
            list    <- peek listp
            missing <- flip mapM [0..fromIntegral count - 1] $ \Int
    i ->
                           Ptr CString -> Int -> IO CString
    forall a. Storable a => Ptr a -> Int -> IO a
    peekElemOff Ptr CString
    list Int
    i IO CString -> (CString -> IO String) -> IO String
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= CString -> IO String
    peekCString
            def     <- peek defp >>= peekCString
            freeStringList list
            return (missing, def, FontSet fs)

    foreign import ccall unsafe "XlibExtras.h XFreeStringList"
        freeStringList :: Ptr CString -> IO ()

    foreign import ccall unsafe "XlibExtras.h XFreeFontSet"
        freeFontSet :: Display -> FontSet -> IO ()

    foreign import ccall unsafe "XlibExtras.h XwcTextExtents"
        xwcTextExtents :: FontSet -> CWString -> CInt -> Ptr Rectangle -> Ptr Rectangle -> IO CInt

    wcTextExtents :: FontSet -> String -> (Rectangle, Rectangle)
    wcTextExtents :: FontSet -> String -> (Rectangle, Rectangle)
    wcTextExtents FontSet
    fs String
    text = IO (Rectangle, Rectangle) -> (Rectangle, Rectangle)
    forall a. IO a -> a
    unsafePerformIO (IO (Rectangle, Rectangle) -> (Rectangle, Rectangle))
    -> IO (Rectangle, Rectangle) -> (Rectangle, Rectangle)
    forall a b. (a -> b) -> a -> b
    $
        String
    -> (CWStringLen -> IO (Rectangle, Rectangle))
    -> IO (Rectangle, Rectangle)
    forall a. String -> (CWStringLen -> IO a) -> IO a
    withCWStringLen String
    text ((CWStringLen -> IO (Rectangle, Rectangle))
     -> IO (Rectangle, Rectangle))
    -> (CWStringLen -> IO (Rectangle, Rectangle))
    -> IO (Rectangle, Rectangle)
    forall a b. (a -> b) -> a -> b
    $ \(CWString
    textp, Int
    len) ->
        (Ptr Rectangle -> IO (Rectangle, Rectangle))
    -> IO (Rectangle, Rectangle)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca               ((Ptr Rectangle -> IO (Rectangle, Rectangle))
     -> IO (Rectangle, Rectangle))
    -> (Ptr Rectangle -> IO (Rectangle, Rectangle))
    -> IO (Rectangle, Rectangle)
    forall a b. (a -> b) -> a -> b
    $ \Ptr Rectangle
    inkp          ->
        (Ptr Rectangle -> IO (Rectangle, Rectangle))
    -> IO (Rectangle, Rectangle)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca               ((Ptr Rectangle -> IO (Rectangle, Rectangle))
     -> IO (Rectangle, Rectangle))
    -> (Ptr Rectangle -> IO (Rectangle, Rectangle))
    -> IO (Rectangle, Rectangle)
    forall a b. (a -> b) -> a -> b
    $ \Ptr Rectangle
    logicalp      -> do
            _ <- FontSet
    -> CWString -> CInt -> Ptr Rectangle -> Ptr Rectangle -> IO CInt
    xwcTextExtents FontSet
    fs CWString
    textp (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    len) Ptr Rectangle
    inkp Ptr Rectangle
    logicalp
            (,) `fmap` peek inkp `ap` peek logicalp

    foreign import ccall unsafe "XlibExtras.h XwcDrawString"
        xwcDrawString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> CWString -> CInt -> IO ()

    wcDrawString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> String -> IO ()
    wcDrawString :: Display
    -> XID -> FontSet -> GC -> Position -> Position -> String -> IO ()
    wcDrawString Display
    d XID
    w FontSet
    fs GC
    gc Position
    x Position
    y =
        (String -> (CWStringLen -> IO ()) -> IO ())
    -> (CWStringLen -> IO ()) -> String -> IO ()
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip String -> (CWStringLen -> IO ()) -> IO ()
    forall a. String -> (CWStringLen -> IO a) -> IO a
    withCWStringLen ((CWStringLen -> IO ()) -> String -> IO ())
    -> (CWStringLen -> IO ()) -> String -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \(CWString
    s, Int
    len) ->
            Display
    -> XID
    -> FontSet
    -> GC
    -> Position
    -> Position
    -> CWString
    -> CInt
    -> IO ()
    xwcDrawString Display
    d XID
    w FontSet
    fs GC
    gc Position
    x Position
    y CWString
    s (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    len)

    foreign import ccall unsafe "XlibExtras.h XwcDrawImageString"
        xwcDrawImageString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> CWString -> CInt -> IO ()

    wcDrawImageString :: Display -> Drawable -> FontSet -> GC -> Position -> Position -> String -> IO ()
    wcDrawImageString :: Display
    -> XID -> FontSet -> GC -> Position -> Position -> String -> IO ()
    wcDrawImageString Display
    d XID
    w FontSet
    fs GC
    gc Position
    x Position
    y =
        (String -> (CWStringLen -> IO ()) -> IO ())
    -> (CWStringLen -> IO ()) -> String -> IO ()
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip String -> (CWStringLen -> IO ()) -> IO ()
    forall a. String -> (CWStringLen -> IO a) -> IO a
    withCWStringLen ((CWStringLen -> IO ()) -> String -> IO ())
    -> (CWStringLen -> IO ()) -> String -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \(CWString
    s, Int
    len) ->
            Display
    -> XID
    -> FontSet
    -> GC
    -> Position
    -> Position
    -> CWString
    -> CInt
    -> IO ()
    xwcDrawImageString Display
    d XID
    w FontSet
    fs GC
    gc Position
    x Position
    y CWString
    s (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    len)

    foreign import ccall unsafe "XlibExtras.h XwcTextEscapement"
        xwcTextEscapement :: FontSet -> CWString -> CInt -> IO Int32

    wcTextEscapement :: FontSet -> String -> Int32
    wcTextEscapement :: FontSet -> String -> Position
    wcTextEscapement FontSet
    font_set String
    string = IO Position -> Position
    forall a. IO a -> a
    unsafePerformIO (IO Position -> Position) -> IO Position -> Position
    forall a b. (a -> b) -> a -> b
    $
        String -> (CWStringLen -> IO Position) -> IO Position
    forall a. String -> (CWStringLen -> IO a) -> IO a
    withCWStringLen String
    string ((CWStringLen -> IO Position) -> IO Position)
    -> (CWStringLen -> IO Position) -> IO Position
    forall a b. (a -> b) -> a -> b
    $ \ (CWString
    c_string, Int
    len) ->
        FontSet -> CWString -> CInt -> IO Position
    xwcTextEscapement FontSet
    font_set CWString
    c_string (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    len)

    foreign import ccall unsafe "XlibExtras.h XFetchName"
        xFetchName :: Display -> Window -> Ptr CString -> IO Status

    fetchName :: Display -> Window -> IO (Maybe String)
    fetchName :: Display -> XID -> IO (Maybe String)
    fetchName Display
    d XID
    w = (Ptr CString -> IO (Maybe String)) -> IO (Maybe String)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CString -> IO (Maybe String)) -> IO (Maybe String))
    -> (Ptr CString -> IO (Maybe String)) -> IO (Maybe String)
    forall a b. (a -> b) -> a -> b
    $ \Ptr CString
    p -> do
        _ <- Display -> XID -> Ptr CString -> IO CInt
    xFetchName Display
    d XID
    w Ptr CString
    p
        cstr <- peek p
        if cstr == nullPtr
            then return Nothing
            else do
                str <- peekCString cstr
                _ <- xFree cstr
                return $ Just str

    foreign import ccall unsafe "XlibExtras.h XGetTransientForHint"
        xGetTransientForHint :: Display -> Window -> Ptr Window -> IO Status

    getTransientForHint :: Display -> Window -> IO (Maybe Window)
    getTransientForHint :: Display -> XID -> IO (Maybe XID)
    getTransientForHint Display
    d XID
    w = (Ptr XID -> IO (Maybe XID)) -> IO (Maybe XID)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr XID -> IO (Maybe XID)) -> IO (Maybe XID))
    -> (Ptr XID -> IO (Maybe XID)) -> IO (Maybe XID)
    forall a b. (a -> b) -> a -> b
    $ \Ptr XID
    wp -> do
        status <- Display -> XID -> Ptr XID -> IO CInt
    xGetTransientForHint Display
    d XID
    w Ptr XID
    wp
        if status == 0
            then return Nothing
            else Just `liftM` peek wp

    ------------------------------------------------------------------------
    -- setWMProtocols :: Display -> Window -> [Atom] -> IO ()

    {-
    setWMProtocols :: Display -> Window -> [Atom] -> IO ()
    setWMProtocols display w protocols =
        withArray protocols $ \ protocol_array ->
        xSetWMProtocols display w protocol_array (length protocols)
    foreign import ccall unsafe "HsXlib.h XSetWMProtocols"
        xSetWMProtocols :: Display -> Window -> Ptr Atom -> CInt -> IO ()
    -}

    -- | The XGetWMProtocols function returns the list of atoms
    -- stored in the WM_PROTOCOLS property on the specified window.
    -- These atoms describe window manager protocols in
    -- which the owner of this window is willing to participate.
    -- If the property exists, is of type ATOM, is of format 32,
    -- and the atom WM_PROTOCOLS can be interned, XGetWMProtocols
    -- sets the protocols_return argument to a list of atoms,
    -- sets the count_return argument to the number of elements
    -- in the list, and returns a nonzero status.  Otherwise, it
    -- sets neither of the return arguments and returns a zero
    -- status.  To release the list of atoms, use XFree.
    --
    getWMProtocols :: Display -> Window -> IO [Atom]
    getWMProtocols :: Display -> XID -> IO [XID]
    getWMProtocols Display
    display XID
    w = do
        (Ptr (Ptr XID) -> IO [XID]) -> IO [XID]
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr (Ptr XID) -> IO [XID]) -> IO [XID])
    -> (Ptr (Ptr XID) -> IO [XID]) -> IO [XID]
    forall a b. (a -> b) -> a -> b
    $ \Ptr (Ptr XID)
    atom_ptr_ptr ->
          (Ptr CInt -> IO [XID]) -> IO [XID]
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CInt -> IO [XID]) -> IO [XID])
    -> (Ptr CInt -> IO [XID]) -> IO [XID]
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    count_ptr -> do

           st <- Display -> XID -> Ptr (Ptr XID) -> Ptr CInt -> IO CInt
    xGetWMProtocols Display
    display XID
    w Ptr (Ptr XID)
    atom_ptr_ptr Ptr CInt
    count_ptr
           if st == 0
                then return []
                else do sz       <- peek count_ptr
                        atom_ptr <- peek atom_ptr_ptr
                        atoms    <- peekArray (fromIntegral sz) atom_ptr
                        _ <- xFree atom_ptr
                        return atoms

    foreign import ccall unsafe "HsXlib.h XGetWMProtocols"
        xGetWMProtocols :: Display -> Window -> Ptr (Ptr Atom) -> Ptr CInt -> IO Status

    ------------------------------------------------------------------------
    -- Creating events

    setEventType :: XEventPtr -> EventType -> IO ()
    setEventType :: XEventPtr -> EventType -> IO ()
    setEventType = (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> EventType -> IO ()
    forall b. Ptr b -> Int -> EventType -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff XEventPtr
    hsc_ptr Int
    0)
    {-# LINE 1233 "Graphics/X11/Xlib/Extras.hsc" #-}

    {-
    typedef struct {
            int type;               /* SelectionNotify */
            unsigned long serial;   /* # of last request processed by server */
            Bool send_event;        /* true if this came from a SendEvent request */
            Display *display;       /* Display the event was read from */
            Window requestor;
            Atom selection;
            Atom target;
            Atom property;          /* atom or None */
            Time time;
    } XSelectionEvent;
    -}

    setSelectionNotify :: XEventPtr -> Window -> Atom -> Atom -> Atom -> Time -> IO ()
    setSelectionNotify :: XEventPtr -> XID -> XID -> XID -> XID -> XID -> IO ()
    setSelectionNotify XEventPtr
    p XID
    requestor XID
    selection XID
    target XID
    property XID
    time = do
        XEventPtr -> EventType -> IO ()
    setEventType XEventPtr
    p EventType
    selectionNotify
        (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> XID -> IO ()
    forall b. Ptr b -> Int -> XID -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff XEventPtr
    hsc_ptr Int
    32)    XEventPtr
    p XID
    requestor
    {-# LINE 1252 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 40)    p selection
    {-# LINE 1253 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 48)       p target
    {-# LINE 1254 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 56)     p property
    {-# LINE 1255 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 64)         p time
    {-# LINE 1256 "Graphics/X11/Xlib/Extras.hsc" #-}

    -- hacky way to set up an XClientMessageEvent
    -- Should have a Storable instance for XEvent/Event?
    setClientMessageEvent :: XEventPtr -> Window -> Atom -> CInt -> Atom -> Time -> IO ()
    setClientMessageEvent :: XEventPtr -> XID -> XID -> CInt -> XID -> XID -> IO ()
    setClientMessageEvent XEventPtr
    p XID
    window XID
    message_type CInt
    format XID
    l_0_ XID
    l_1_ = do
        XEventPtr -> XID -> XID -> CInt -> [CInt] -> IO ()
    setClientMessageEvent' XEventPtr
    p XID
    window XID
    message_type CInt
    format [XID -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral XID
    l_0_, XID -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral XID
    l_1_]

    -- slightly less hacky way to set up an XClientMessageEvent
    setClientMessageEvent' :: XEventPtr -> Window -> Atom -> CInt -> [CInt] -> IO ()
    setClientMessageEvent' :: XEventPtr -> XID -> XID -> CInt -> [CInt] -> IO ()
    setClientMessageEvent' XEventPtr
    p XID
    window XID
    message_type CInt
    format [CInt]
    dat = do
        (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> XID -> IO ()
    forall b. Ptr b -> Int -> XID -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff XEventPtr
    hsc_ptr Int
    32)         XEventPtr
    p XID
    window
    {-# LINE 1267 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 40)   p message_type
    {-# LINE 1268 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 48)         p format
    {-# LINE 1269 "Graphics/X11/Xlib/Extras.hsc" #-}
        case format of
            8  -> do let datap = (\hsc_ptr -> hsc_ptr `plusPtr` 56) p :: Ptr Word8
    {-# LINE 1271 "Graphics/X11/Xlib/Extras.hsc" #-}
                     pokeArray datap $ take 20 $ map fromIntegral dat ++ repeat 0
            16 -> do let datap = (\hsc_ptr -> hsc_ptr `plusPtr` 56) p :: Ptr Word16
    {-# LINE 1273 "Graphics/X11/Xlib/Extras.hsc" #-}
                     pokeArray datap $ take 10 $ map fromIntegral dat ++ repeat 0
            32 -> do let datap = (\hsc_ptr -> hsc_ptr `plusPtr` 56) p :: Ptr CLong
    {-# LINE 1275 "Graphics/X11/Xlib/Extras.hsc" #-}
                     pokeArray datap $ take 5  $ map fromIntegral dat ++ repeat 0
            _  -> error "X11.Extras.setClientMessageEvent': illegal format"

    setConfigureEvent :: XEventPtr -> Window -> Window -> CInt -> CInt -> CInt -> CInt -> CInt -> Window -> Bool -> IO ()
    setConfigureEvent :: XEventPtr
    -> XID
    -> XID
    -> CInt
    -> CInt
    -> CInt
    -> CInt
    -> CInt
    -> XID
    -> Bool
    -> IO ()
    setConfigureEvent XEventPtr
    p XID
    ev XID
    win CInt
    x CInt
    y CInt
    w CInt
    h CInt
    bw XID
    abv Bool
    org = do
        (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> XID -> IO ()
    forall b. Ptr b -> Int -> XID -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p XID
    ev
    {-# LINE 1281 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 40) p win
    {-# LINE 1282 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 48) p x
    {-# LINE 1283 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 52) p y
    {-# LINE 1284 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 56) p w
    {-# LINE 1285 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 60) p h
    {-# LINE 1286 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 64) p bw
    {-# LINE 1287 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 72) p abv
    {-# LINE 1288 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 80) p (if org then 1 else 0 :: CInt)
    {-# LINE 1289 "Graphics/X11/Xlib/Extras.hsc" #-}

    setKeyEvent :: XEventPtr -> Window -> Window -> Window -> KeyMask -> KeyCode -> Bool -> IO ()
    setKeyEvent :: XEventPtr
    -> XID -> XID -> XID -> KeyMask -> KeyCode -> Bool -> IO ()
    setKeyEvent XEventPtr
    p XID
    win XID
    root XID
    subwin KeyMask
    state KeyCode
    keycode Bool
    sameScreen = do
        (\XEventPtr
    hsc_ptr -> XEventPtr -> Int -> XID -> IO ()
    forall b. Ptr b -> Int -> XID -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff XEventPtr
    hsc_ptr Int
    32) XEventPtr
    p XID
    win
    {-# LINE 1293 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 40) p root
    {-# LINE 1294 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 48) p subwin
    {-# LINE 1295 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 56) p currentTime
    {-# LINE 1296 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 64) p (1 :: CInt)
    {-# LINE 1297 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 68) p (1 :: CInt)
    {-# LINE 1298 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 72) p (1 :: CInt)
    {-# LINE 1299 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 76) p (1 :: CInt)
    {-# LINE 1300 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 80) p state
    {-# LINE 1301 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 84) p keycode
    {-# LINE 1302 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 88) p sameScreen
    {-# LINE 1303 "Graphics/X11/Xlib/Extras.hsc" #-}
        return ()

    {-
           typedef struct {
                int type;                /* ClientMessage */
                unsigned long serial;    /* # of last request processed by server */
                Bool send_event;         /* true if this came from a SendEvent request */
                Display *display;        /* Display the event was read from */
                Window window;
                Atom message_type;
                int format;
                union {
                     char b[20];
                     short s[10];
                     long l[5];
                        } data;
           } XClientMessageEvent;

    -}

    ------------------------------------------------------------------------
    -- XErrorEvents
    --
    -- I'm too lazy to write the binding
    --

    foreign import ccall unsafe "XlibExtras.h x11_extras_set_error_handler"
        xSetErrorHandler   :: IO ()

    -- | refreshKeyboardMapping.  TODO Remove this binding when the fix has been commited to
    -- X11
    refreshKeyboardMapping :: Event -> IO ()
    refreshKeyboardMapping :: Event -> IO ()
    refreshKeyboardMapping ev :: Event
    ev@(MappingNotifyEvent {ev_event_display :: Event -> Display
    ev_event_display = (Display Ptr Display
    d)})
     = Int -> (Ptr () -> IO ()) -> IO ()
    forall a b. Int -> (Ptr a -> IO b) -> IO b
    allocaBytes (Int
    56) ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr ()
    p -> do
    {-# LINE 1337 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 0) p $ ev_event_type    ev
    {-# LINE 1338 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 8) p $ ev_serial        ev
    {-# LINE 1339 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 16) p $ ev_send_event    ev
    {-# LINE 1340 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 24) p $ d
    {-# LINE 1341 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 32) p $ ev_window        ev
    {-# LINE 1342 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 40) p $ ev_request       ev
    {-# LINE 1343 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 44) p $ ev_first_keycode ev
    {-# LINE 1344 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\hsc_ptr -> pokeByteOff hsc_ptr 48) p $ ev_count         ev
    {-# LINE 1345 "Graphics/X11/Xlib/Extras.hsc" #-}
        _ <- xRefreshKeyboardMapping p
        return ()
    refreshKeyboardMapping Event
    _ = () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()

    foreign import ccall unsafe "XlibExtras.h XRefreshKeyboardMapping"
        xRefreshKeyboardMapping :: Ptr () -> IO CInt

    -- Properties

    anyPropertyType :: Atom
    anyPropertyType :: XID
    anyPropertyType = XID
    0
    {-# LINE 1356 "Graphics/X11/Xlib/Extras.hsc" #-}

    foreign import ccall unsafe "XlibExtras.h XChangeProperty"
        xChangeProperty :: Display -> Window -> Atom -> Atom -> CInt -> CInt -> Ptr CUChar -> CInt -> IO Status

    foreign import ccall unsafe "XlibExtras.h XDeleteProperty"
        xDeleteProperty :: Display -> Window -> Atom -> IO Status

    foreign import ccall unsafe "XlibExtras.h XGetWindowProperty"
        xGetWindowProperty :: Display -> Window -> Atom -> CLong -> CLong -> Bool -> Atom -> Ptr Atom -> Ptr CInt -> Ptr CULong -> Ptr CULong -> Ptr (Ptr CUChar) -> IO Status

    rawGetWindowProperty :: Storable a => Int -> Display -> Atom -> Window -> IO (Maybe [a])
    rawGetWindowProperty :: forall a.
    Storable a =>
    Int -> Display -> XID -> XID -> IO (Maybe [a])
    rawGetWindowProperty Int
    bits Display
    d XID
    atom XID
    w =
        (Ptr XID -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr XID -> IO (Maybe [a])) -> IO (Maybe [a]))
    -> (Ptr XID -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. (a -> b) -> a -> b
    $ \Ptr XID
    actual_type_return ->
        (Ptr CInt -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CInt -> IO (Maybe [a])) -> IO (Maybe [a]))
    -> (Ptr CInt -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    actual_format_return ->
        (Ptr CULong -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CULong -> IO (Maybe [a])) -> IO (Maybe [a]))
    -> (Ptr CULong -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. (a -> b) -> a -> b
    $ \Ptr CULong
    nitems_return ->
        (Ptr CULong -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CULong -> IO (Maybe [a])) -> IO (Maybe [a]))
    -> (Ptr CULong -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. (a -> b) -> a -> b
    $ \Ptr CULong
    bytes_after_return ->
        (Ptr (Ptr CUChar) -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr (Ptr CUChar) -> IO (Maybe [a])) -> IO (Maybe [a]))
    -> (Ptr (Ptr CUChar) -> IO (Maybe [a])) -> IO (Maybe [a])
    forall a b. (a -> b) -> a -> b
    $ \Ptr (Ptr CUChar)
    prop_return -> do
            ret <- Display
    -> XID
    -> XID
    -> CLong
    -> CLong
    -> Bool
    -> XID
    -> Ptr XID
    -> Ptr CInt
    -> Ptr CULong
    -> Ptr CULong
    -> Ptr (Ptr CUChar)
    -> IO CInt
    xGetWindowProperty Display
    d XID
    w XID
    atom CLong
    0 CLong
    0xFFFFFFFF Bool
    False XID
    anyPropertyType
                               Ptr XID
    actual_type_return
                               Ptr CInt
    actual_format_return
                               Ptr CULong
    nitems_return
                               Ptr CULong
    bytes_after_return
                               Ptr (Ptr CUChar)
    prop_return

            if ret /= 0
                then return Nothing
                else do
                    prop_ptr      <- peek prop_return
                    actual_format <- fromIntegral `fmap` peek actual_format_return
                    nitems        <- fromIntegral `fmap` peek nitems_return
                    getprop prop_ptr nitems actual_format
      where
        getprop :: Ptr a -> Int -> Int -> IO (Maybe [a])
    getprop Ptr a
    prop_ptr Int
    nitems Int
    actual_format
            | Int
    actual_format Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    == Int
    0    = Maybe [a] -> IO (Maybe [a])
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe [a]
    forall a. Maybe a
    Nothing -- Property not found
            | Int
    actual_format Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Int
    bits = Ptr a -> IO CInt
    forall a. Ptr a -> IO CInt
    xFree Ptr a
    prop_ptr IO CInt -> IO (Maybe [a]) -> IO (Maybe [a])
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Maybe [a] -> IO (Maybe [a])
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe [a]
    forall a. Maybe a
    Nothing
            | Bool
    otherwise = do
                retval <- Int -> Ptr a -> IO [a]
    forall a. Storable a => Int -> Ptr a -> IO [a]
    peekArray Int
    nitems (Ptr a -> Ptr a
    forall a b. Ptr a -> Ptr b
    castPtr Ptr a
    prop_ptr)
                _ <- xFree prop_ptr
                return $ Just retval

    getWindowProperty8 :: Display -> Atom -> Window -> IO (Maybe [CChar])
    getWindowProperty8 :: Display -> XID -> XID -> IO (Maybe [CChar])
    getWindowProperty8 = Int -> Display -> XID -> XID -> IO (Maybe [CChar])
    forall a.
    Storable a =>
    Int -> Display -> XID -> XID -> IO (Maybe [a])
    rawGetWindowProperty Int
    8

    getWindowProperty16 :: Display -> Atom -> Window -> IO (Maybe [CShort])
    getWindowProperty16 :: Display -> XID -> XID -> IO (Maybe [CShort])
    getWindowProperty16 = Int -> Display -> XID -> XID -> IO (Maybe [CShort])
    forall a.
    Storable a =>
    Int -> Display -> XID -> XID -> IO (Maybe [a])
    rawGetWindowProperty Int
    16

    getWindowProperty32 :: Display -> Atom -> Window -> IO (Maybe [CLong])
    getWindowProperty32 :: Display -> XID -> XID -> IO (Maybe [CLong])
    getWindowProperty32 = Int -> Display -> XID -> XID -> IO (Maybe [CLong])
    forall a.
    Storable a =>
    Int -> Display -> XID -> XID -> IO (Maybe [a])
    rawGetWindowProperty Int
    32

    -- this assumes bytes are 8 bits.  I hope X isn't more portable than that :(

    changeProperty8 :: Display -> Window -> Atom -> Atom -> CInt -> [CChar] -> IO ()
    changeProperty8 :: Display -> XID -> XID -> XID -> CInt -> [CChar] -> IO ()
    changeProperty8 Display
    dpy XID
    w XID
    prop XID
    typ CInt
    mode [CChar]
    dat =
        [CChar] -> (Int -> CString -> IO ()) -> IO ()
    forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
    withArrayLen [CChar]
    dat ((Int -> CString -> IO ()) -> IO ())
    -> (Int -> CString -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \ Int
    len CString
    ptr -> do
            _ <- Display
    -> XID
    -> XID
    -> XID
    -> CInt
    -> CInt
    -> Ptr CUChar
    -> CInt
    -> IO CInt
    xChangeProperty Display
    dpy XID
    w XID
    prop XID
    typ CInt
    8 CInt
    mode (CString -> Ptr CUChar
    forall a b. Ptr a -> Ptr b
    castPtr CString
    ptr) (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    len)
            return ()

    changeProperty16 :: Display -> Window -> Atom -> Atom -> CInt -> [CShort] -> IO ()
    changeProperty16 :: Display -> XID -> XID -> XID -> CInt -> [CShort] -> IO ()
    changeProperty16 Display
    dpy XID
    w XID
    prop XID
    typ CInt
    mode [CShort]
    dat =
        [CShort] -> (Int -> Ptr CShort -> IO ()) -> IO ()
    forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
    withArrayLen [CShort]
    dat ((Int -> Ptr CShort -> IO ()) -> IO ())
    -> (Int -> Ptr CShort -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \ Int
    len Ptr CShort
    ptr -> do
            _ <- Display
    -> XID
    -> XID
    -> XID
    -> CInt
    -> CInt
    -> Ptr CUChar
    -> CInt
    -> IO CInt
    xChangeProperty Display
    dpy XID
    w XID
    prop XID
    typ CInt
    16 CInt
    mode (Ptr CShort -> Ptr CUChar
    forall a b. Ptr a -> Ptr b
    castPtr Ptr CShort
    ptr) (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    len)
            return ()

    changeProperty32 :: Display -> Window -> Atom -> Atom -> CInt -> [CLong] -> IO ()
    changeProperty32 :: Display -> XID -> XID -> XID -> CInt -> [CLong] -> IO ()
    changeProperty32 Display
    dpy XID
    w XID
    prop XID
    typ CInt
    mode [CLong]
    dat =
        [CLong] -> (Int -> Ptr CLong -> IO ()) -> IO ()
    forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
    withArrayLen [CLong]
    dat ((Int -> Ptr CLong -> IO ()) -> IO ())
    -> (Int -> Ptr CLong -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \ Int
    len Ptr CLong
    ptr -> do
            _ <- Display
    -> XID
    -> XID
    -> XID
    -> CInt
    -> CInt
    -> Ptr CUChar
    -> CInt
    -> IO CInt
    xChangeProperty Display
    dpy XID
    w XID
    prop XID
    typ CInt
    32 CInt
    mode (Ptr CLong -> Ptr CUChar
    forall a b. Ptr a -> Ptr b
    castPtr Ptr CLong
    ptr) (Int -> CInt
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    len)
            return ()

    propModeReplace, propModePrepend, propModeAppend :: CInt
    propModeReplace :: CInt
    propModeReplace = CInt
    0
    {-# LINE 1427 "Graphics/X11/Xlib/Extras.hsc" #-}
    propModePrepend = 1
    {-# LINE 1428 "Graphics/X11/Xlib/Extras.hsc" #-}
    propModeAppend = 2
    {-# LINE 1429 "Graphics/X11/Xlib/Extras.hsc" #-}

    deleteProperty :: Display -> Window -> Atom -> IO ()
    deleteProperty :: Display -> XID -> XID -> IO ()
    deleteProperty Display
    dpy XID
    w XID
    prop = do
        _ <- Display -> XID -> XID -> IO CInt
    xDeleteProperty Display
    dpy XID
    w XID
    prop
        return ()

    -- Windows

    foreign import ccall unsafe "XlibExtras.h XUnmapWindow"
        xUnmapWindow :: Display -> Window -> IO CInt

    unmapWindow :: Display -> Window -> IO ()
    unmapWindow :: Display -> XID -> IO ()
    unmapWindow Display
    d XID
    w = Display -> XID -> IO CInt
    xUnmapWindow Display
    d XID
    w IO CInt -> IO () -> IO ()
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()

    ------------------------------------------------------------------------
    -- Size hints

    data SizeHints = SizeHints
                       { SizeHints -> Maybe (EventType, EventType)
    sh_min_size     :: Maybe (Dimension, Dimension)
                       , SizeHints -> Maybe (EventType, EventType)
    sh_max_size     :: Maybe (Dimension, Dimension)
                       , SizeHints -> Maybe (EventType, EventType)
    sh_resize_inc   :: Maybe (Dimension, Dimension)
                       , SizeHints -> Maybe ((EventType, EventType), (EventType, EventType))
    sh_aspect       :: Maybe ((Dimension, Dimension), (Dimension, Dimension))
                       , SizeHints -> Maybe (EventType, EventType)
    sh_base_size    :: Maybe (Dimension, Dimension)
                       , SizeHints -> Maybe CInt
    sh_win_gravity  :: Maybe (BitGravity)
                       }

    pMinSizeBit, pMaxSizeBit, pResizeIncBit, pAspectBit, pBaseSizeBit, pWinGravityBit :: Int
    pMinSizeBit :: Int
    pMinSizeBit    = Int
    4
    pMaxSizeBit :: Int
    pMaxSizeBit    = Int
    5
    pResizeIncBit :: Int
    pResizeIncBit  = Int
    6
    pAspectBit :: Int
    pAspectBit     = Int
    7
    pBaseSizeBit :: Int
    pBaseSizeBit   = Int
    8
    pWinGravityBit :: Int
    pWinGravityBit = Int
    9

    instance Storable SizeHints where
        alignment :: SizeHints -> Int
    alignment SizeHints
    _ = CInt -> Int
    forall a. Storable a => a -> Int
    alignment (CInt
    forall a. HasCallStack => a
    undefined :: CInt)
        sizeOf :: SizeHints -> Int
    sizeOf SizeHints
    _ = (Int
    80)
    {-# LINE 1466 "Graphics/X11/Xlib/Extras.hsc" #-}

        poke :: Ptr SizeHints -> SizeHints -> IO ()
    poke Ptr SizeHints
    p SizeHints
    sh = do
          let whenSet :: (SizeHints -> Maybe a) -> (a -> m ()) -> m ()
    whenSet SizeHints -> Maybe a
    f a -> m ()
    x = m () -> (a -> m ()) -> Maybe a -> m ()
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (() -> m ()
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()) a -> m ()
    x (SizeHints -> Maybe a
    f SizeHints
    sh)
          let pokeFlag :: Int -> IO ()
    pokeFlag Int
    b = do flag <- (\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO CLong
    forall b. Ptr b -> Int -> IO CLong
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    0) Ptr SizeHints
    p :: IO CLong
    {-# LINE 1470 "Graphics/X11/Xlib/Extras.hsc" #-}
                              (\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> CLong -> IO ()
    forall b. Ptr b -> Int -> CLong -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr SizeHints
    hsc_ptr Int
    0) p (setBit flag b)
    {-# LINE 1471 "Graphics/X11/Xlib/Extras.hsc" #-}
          (\hsc_ptr -> pokeByteOff hsc_ptr 0) p (0 :: CLong)
    {-# LINE 1472 "Graphics/X11/Xlib/Extras.hsc" #-}
          whenSet sh_min_size $ \(w, h) -> do
            pokeFlag pMinSizeBit
            (\hsc_ptr -> pokeByteOff hsc_ptr 24) p w
    {-# LINE 1475 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 28) p h
    {-# LINE 1476 "Graphics/X11/Xlib/Extras.hsc" #-}
          whenSet sh_max_size $ \(w, h) -> do
            pokeFlag pMaxSizeBit
            (\hsc_ptr -> pokeByteOff hsc_ptr 32) p w
    {-# LINE 1479 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 36) p h
    {-# LINE 1480 "Graphics/X11/Xlib/Extras.hsc" #-}
          whenSet sh_resize_inc $ \(w, h) -> do
            pokeFlag pResizeIncBit
            (\hsc_ptr -> pokeByteOff hsc_ptr 40) p w
    {-# LINE 1483 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 44) p h
    {-# LINE 1484 "Graphics/X11/Xlib/Extras.hsc" #-}
          whenSet sh_aspect $ \((minx, miny), (maxx, maxy)) -> do
            pokeFlag pAspectBit
            (\hsc_ptr -> pokeByteOff hsc_ptr 48) p minx
    {-# LINE 1487 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 52) p miny
    {-# LINE 1488 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 56) p maxx
    {-# LINE 1489 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 60) p maxy
    {-# LINE 1490 "Graphics/X11/Xlib/Extras.hsc" #-}
          whenSet sh_base_size $ \(w, h) -> do
            pokeFlag pBaseSizeBit
            (\hsc_ptr -> pokeByteOff hsc_ptr 64) p w
    {-# LINE 1493 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\hsc_ptr -> pokeByteOff hsc_ptr 68) p h
    {-# LINE 1494 "Graphics/X11/Xlib/Extras.hsc" #-}
          whenSet sh_win_gravity $ \g -> do
            pokeFlag pWinGravityBit
            (\hsc_ptr -> pokeByteOff hsc_ptr 72) p g
    {-# LINE 1497 "Graphics/X11/Xlib/Extras.hsc" #-}

        peek :: Ptr SizeHints -> IO SizeHints
    peek Ptr SizeHints
    p = do
          flags <- (\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO CLong
    forall b. Ptr b -> Int -> IO CLong
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    0) Ptr SizeHints
    p :: IO CLong
    {-# LINE 1500 "Graphics/X11/Xlib/Extras.hsc" #-}
          let whenBit n x = if testBit flags n then liftM Just x else return Nothing
          return SizeHints
             `ap` whenBit pMinSizeBit    (do liftM2 (,) ((\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    24) p)
    {-# LINE 1503 "Graphics/X11/Xlib/Extras.hsc" #-}
                                                        ((\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    28) p))
    {-# LINE 1504 "Graphics/X11/Xlib/Extras.hsc" #-}
             `ap` whenBit pMaxSizeBit    (do liftM2 (,) ((\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    32) p)
    {-# LINE 1505 "Graphics/X11/Xlib/Extras.hsc" #-}
                                                        ((\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    36) p))
    {-# LINE 1506 "Graphics/X11/Xlib/Extras.hsc" #-}
             `ap` whenBit pResizeIncBit  (do liftM2 (,) ((\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    40) p)
    {-# LINE 1507 "Graphics/X11/Xlib/Extras.hsc" #-}
                                                        ((\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    44) p))
    {-# LINE 1508 "Graphics/X11/Xlib/Extras.hsc" #-}
             `ap` whenBit pAspectBit     (do minx <- (\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    48) p
    {-# LINE 1509 "Graphics/X11/Xlib/Extras.hsc" #-}
                                             miny <- (\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    52) p
    {-# LINE 1510 "Graphics/X11/Xlib/Extras.hsc" #-}
                                             maxx <- (\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    56) p
    {-# LINE 1511 "Graphics/X11/Xlib/Extras.hsc" #-}
                                             maxy <- (\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    60) p
    {-# LINE 1512 "Graphics/X11/Xlib/Extras.hsc" #-}
                                             return ((minx, miny), (maxx, maxy)))
             `ap` whenBit pBaseSizeBit   (do liftM2 (,) ((\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    64) p)
    {-# LINE 1514 "Graphics/X11/Xlib/Extras.hsc" #-}
                                                        ((\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO EventType
    forall b. Ptr b -> Int -> IO EventType
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    68) p))
    {-# LINE 1515 "Graphics/X11/Xlib/Extras.hsc" #-}
             `ap` whenBit pWinGravityBit ((\Ptr SizeHints
    hsc_ptr -> Ptr SizeHints -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr SizeHints
    hsc_ptr Int
    72) p)
    {-# LINE 1516 "Graphics/X11/Xlib/Extras.hsc" #-}

    foreign import ccall unsafe "XlibExtras.h XGetWMNormalHints"
        xGetWMNormalHints :: Display -> Window -> Ptr SizeHints -> Ptr CLong -> IO Status

    getWMNormalHints :: Display -> Window -> IO SizeHints
    getWMNormalHints :: Display -> XID -> IO SizeHints
    getWMNormalHints Display
    d XID
    w
        = (Ptr SizeHints -> IO SizeHints) -> IO SizeHints
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr SizeHints -> IO SizeHints) -> IO SizeHints)
    -> (Ptr SizeHints -> IO SizeHints) -> IO SizeHints
    forall a b. (a -> b) -> a -> b
    $ \Ptr SizeHints
    sh -> do
            (Ptr CLong -> IO SizeHints) -> IO SizeHints
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CLong -> IO SizeHints) -> IO SizeHints)
    -> (Ptr CLong -> IO SizeHints) -> IO SizeHints
    forall a b. (a -> b) -> a -> b
    $ \Ptr CLong
    supplied_return -> do
              -- what's the purpose of supplied_return?
              status <- Display -> XID -> Ptr SizeHints -> Ptr CLong -> IO CInt
    xGetWMNormalHints Display
    d XID
    w Ptr SizeHints
    sh Ptr CLong
    supplied_return
              case status of
                CInt
    0 -> SizeHints -> IO SizeHints
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe (EventType, EventType)
    -> Maybe (EventType, EventType)
    -> Maybe (EventType, EventType)
    -> Maybe ((EventType, EventType), (EventType, EventType))
    -> Maybe (EventType, EventType)
    -> Maybe CInt
    -> SizeHints
    SizeHints Maybe (EventType, EventType)
    forall a. Maybe a
    Nothing Maybe (EventType, EventType)
    forall a. Maybe a
    Nothing Maybe (EventType, EventType)
    forall a. Maybe a
    Nothing Maybe ((EventType, EventType), (EventType, EventType))
    forall a. Maybe a
    Nothing Maybe (EventType, EventType)
    forall a. Maybe a
    Nothing Maybe CInt
    forall a. Maybe a
    Nothing)
                CInt
    _ -> Ptr SizeHints -> IO SizeHints
    forall a. Storable a => Ptr a -> IO a
    peek Ptr SizeHints
    sh

    foreign import ccall "XlibExtras.h XAllocSizeHints"
        xAllocSizeHints :: IO (Ptr SizeHints)

    foreign import ccall unsafe "XlibExtras.h XSetWMNormalHints"
        xSetWMNormalHints :: Display -> Window -> Ptr SizeHints -> IO ()

    setWMNormalHints :: Display -> Window -> SizeHints -> IO ()
    setWMNormalHints :: Display -> XID -> SizeHints -> IO ()
    setWMNormalHints Display
    dpy XID
    win SizeHints
    hints = do
        ptr_hints <- String -> IO (Ptr SizeHints) -> IO (Ptr SizeHints)
    forall a. String -> IO (Ptr a) -> IO (Ptr a)
    throwIfNull String
    "xAllocSizeHints" IO (Ptr SizeHints)
    xAllocSizeHints
        poke ptr_hints hints
        xSetWMNormalHints dpy win ptr_hints
        _ <- xFree ptr_hints
        return ()

    data ClassHint = ClassHint
                            { ClassHint -> String
    resName  :: String
                            , ClassHint -> String
    resClass :: String
                            }

    getClassHint :: Display -> Window -> IO ClassHint
    getClassHint :: Display -> XID -> IO ClassHint
    getClassHint Display
    d XID
    w =  Int -> (Ptr ClassHint -> IO ClassHint) -> IO ClassHint
    forall a b. Int -> (Ptr a -> IO b) -> IO b
    allocaBytes ((Int
    16)) ((Ptr ClassHint -> IO ClassHint) -> IO ClassHint)
    -> (Ptr ClassHint -> IO ClassHint) -> IO ClassHint
    forall a b. (a -> b) -> a -> b
    $ \ Ptr ClassHint
    p -> do
    {-# LINE 1552 "Graphics/X11/Xlib/Extras.hsc" #-}
        s <- xGetClassHint d w p
        if s /= 0 -- returns a nonzero status on success
            then do
                res_name_p <- (\hsc_ptr -> peekByteOff hsc_ptr 0) p
    {-# LINE 1556 "Graphics/X11/Xlib/Extras.hsc" #-}
                res_class_p <- (\hsc_ptr -> peekByteOff hsc_ptr 8) p
    {-# LINE 1557 "Graphics/X11/Xlib/Extras.hsc" #-}
                res <- liftM2 ClassHint (peekCString res_name_p) (peekCString res_class_p)
                _ <- xFree res_name_p
                _ <- xFree res_class_p
                return res
            else return $ ClassHint "" ""

    foreign import ccall unsafe "XlibExtras.h XGetClassHint"
        xGetClassHint :: Display -> Window -> Ptr ClassHint -> IO Status

    -- | Set the @WM_CLASS@ property for the given window.
    setClassHint :: Display -> Window -> ClassHint -> IO ()
    setClassHint :: Display -> XID -> ClassHint -> IO ()
    setClassHint Display
    dpy XID
    win (ClassHint String
    name String
    cl) =
        Int -> (Ptr ClassHint -> IO ()) -> IO ()
    forall a b. Int -> (Ptr a -> IO b) -> IO b
    allocaBytes ((Int
    16)) ((Ptr ClassHint -> IO ()) -> IO ())
    -> (Ptr ClassHint -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr ClassHint
    ptr -> do
    {-# LINE 1570 "Graphics/X11/Xlib/Extras.hsc" #-}
            String -> (CString -> IO ()) -> IO ()
    forall a. String -> (CString -> IO a) -> IO a
    withCString String
    name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \CString
    c_name -> String -> (CString -> IO ()) -> IO ()
    forall a. String -> (CString -> IO a) -> IO a
    withCString String
    cl ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \CString
    c_cl -> do
                (\Ptr ClassHint
    hsc_ptr -> Ptr ClassHint -> Int -> CString -> IO ()
    forall b. Ptr b -> Int -> CString -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr ClassHint
    hsc_ptr Int
    0) Ptr ClassHint
    ptr CString
    c_name
    {-# LINE 1572 "Graphics/X11/Xlib/Extras.hsc" #-}
                (\Ptr ClassHint
    hsc_ptr -> Ptr ClassHint -> Int -> CString -> IO ()
    forall b. Ptr b -> Int -> CString -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr ClassHint
    hsc_ptr Int
    8) Ptr ClassHint
    ptr CString
    c_cl
    {-# LINE 1573 "Graphics/X11/Xlib/Extras.hsc" #-}
                Display -> XID -> Ptr ClassHint -> IO ()
    xSetClassHint Display
    dpy XID
    win Ptr ClassHint
    ptr

    foreign import ccall unsafe "XlibExtras.h XSetClassHint"
        xSetClassHint :: Display -> Window -> Ptr ClassHint -> IO ()

    ------------------------------------------------------------------------
    -- WM Hints

    -- These are the documented values for a window's "WM State", set, for example,
    -- in wmh_initial_state, below. Note, you may need to play games with
    -- fromIntegral and/or fromEnum.
    withdrawnState,normalState, iconicState :: Int
    withdrawnState :: Int
    withdrawnState = Int
    0
    {-# LINE 1586 "Graphics/X11/Xlib/Extras.hsc" #-}
    normalState    = 1
    {-# LINE 1587 "Graphics/X11/Xlib/Extras.hsc" #-}
    iconicState    = 3
    {-# LINE 1588 "Graphics/X11/Xlib/Extras.hsc" #-}

    -- The following values are the documented bit positions on XWMHints's flags field.
    -- Use testBit, setBit, and clearBit to manipulate the field.
    inputHintBit,stateHintBit,iconPixmapHintBit,iconWindowHintBit,iconPositionHintBit,iconMaskHintBit,windowGroupHintBit,urgencyHintBit :: Int
    inputHintBit :: Int
    inputHintBit        = Int
    0
    stateHintBit :: Int
    stateHintBit        = Int
    1
    iconPixmapHintBit :: Int
    iconPixmapHintBit   = Int
    2
    iconWindowHintBit :: Int
    iconWindowHintBit   = Int
    3
    iconPositionHintBit :: Int
    iconPositionHintBit = Int
    4
    iconMaskHintBit :: Int
    iconMaskHintBit     = Int
    5
    windowGroupHintBit :: Int
    windowGroupHintBit  = Int
    6
    urgencyHintBit :: Int
    urgencyHintBit      = Int
    8

    -- The following bitmask tests for the presence of all bits except for the
    -- urgencyHintBit.
    allHintsBitmask :: CLong
    allHintsBitmask :: CLong
    allHintsBitmask    = CLong
    127
    {-# LINE 1605 "Graphics/X11/Xlib/Extras.hsc" #-}

    data WMHints = WMHints
                     { WMHints -> CLong
    wmh_flags         :: CLong
                     , WMHints -> Bool
    wmh_input         :: Bool
                     , WMHints -> CInt
    wmh_initial_state :: CInt
                     , WMHints -> XID
    wmh_icon_pixmap   :: Pixmap
                     , WMHints -> XID
    wmh_icon_window   :: Window
                     , WMHints -> CInt
    wmh_icon_x        :: CInt
                     , WMHints -> CInt
    wmh_icon_y        :: CInt
                     , WMHints -> XID
    wmh_icon_mask     :: Pixmap
                     , WMHints -> XID
    wmh_window_group  :: XID
                     }

    instance Storable WMHints where
        -- should align to the alignment of the largest type
        alignment :: WMHints -> Int
    alignment WMHints
    _ = CLong -> Int
    forall a. Storable a => a -> Int
    alignment (CLong
    forall a. HasCallStack => a
    undefined :: CLong)
        sizeOf :: WMHints -> Int
    sizeOf WMHints
    _ = (Int
    56)
    {-# LINE 1622 "Graphics/X11/Xlib/Extras.hsc" #-}

        peek :: Ptr WMHints -> IO WMHints
    peek Ptr WMHints
    p = (CLong
     -> Bool
     -> CInt
     -> XID
     -> XID
     -> CInt
     -> CInt
     -> XID
     -> XID
     -> WMHints)
    -> IO
         (CLong
          -> Bool
          -> CInt
          -> XID
          -> XID
          -> CInt
          -> CInt
          -> XID
          -> XID
          -> WMHints)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CLong
    -> Bool
    -> CInt
    -> XID
    -> XID
    -> CInt
    -> CInt
    -> XID
    -> XID
    -> WMHints
    WMHints
                    IO
      (CLong
       -> Bool
       -> CInt
       -> XID
       -> XID
       -> CInt
       -> CInt
       -> XID
       -> XID
       -> WMHints)
    -> IO CLong
    -> IO
         (Bool
          -> CInt -> XID -> XID -> CInt -> CInt -> XID -> XID -> WMHints)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> IO CLong
    forall b. Ptr b -> Int -> IO CLong
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WMHints
    hsc_ptr Int
    0)         Ptr WMHints
    p
    {-# LINE 1625 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO
      (Bool
       -> CInt -> XID -> XID -> CInt -> CInt -> XID -> XID -> WMHints)
    -> IO Bool
    -> IO (CInt -> XID -> XID -> CInt -> CInt -> XID -> XID -> WMHints)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> IO Bool
    forall b. Ptr b -> Int -> IO Bool
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WMHints
    hsc_ptr Int
    8)         Ptr WMHints
    p
    {-# LINE 1626 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> XID -> XID -> CInt -> CInt -> XID -> XID -> WMHints)
    -> IO CInt
    -> IO (XID -> XID -> CInt -> CInt -> XID -> XID -> WMHints)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WMHints
    hsc_ptr Int
    12) Ptr WMHints
    p
    {-# LINE 1627 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (XID -> XID -> CInt -> CInt -> XID -> XID -> WMHints)
    -> IO XID -> IO (XID -> CInt -> CInt -> XID -> XID -> WMHints)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WMHints
    hsc_ptr Int
    16)   Ptr WMHints
    p
    {-# LINE 1628 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (XID -> CInt -> CInt -> XID -> XID -> WMHints)
    -> IO XID -> IO (CInt -> CInt -> XID -> XID -> WMHints)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WMHints
    hsc_ptr Int
    24)   Ptr WMHints
    p
    {-# LINE 1629 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> CInt -> XID -> XID -> WMHints)
    -> IO CInt -> IO (CInt -> XID -> XID -> WMHints)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WMHints
    hsc_ptr Int
    32)        Ptr WMHints
    p
    {-# LINE 1630 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (CInt -> XID -> XID -> WMHints)
    -> IO CInt -> IO (XID -> XID -> WMHints)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WMHints
    hsc_ptr Int
    32)        Ptr WMHints
    p
    {-# LINE 1631 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (XID -> XID -> WMHints) -> IO XID -> IO (XID -> WMHints)
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WMHints
    hsc_ptr Int
    40)     Ptr WMHints
    p
    {-# LINE 1632 "Graphics/X11/Xlib/Extras.hsc" #-}
                    IO (XID -> WMHints) -> IO XID -> IO WMHints
    forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
    `ap` (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> IO XID
    forall b. Ptr b -> Int -> IO XID
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr WMHints
    hsc_ptr Int
    48)  Ptr WMHints
    p
    {-# LINE 1633 "Graphics/X11/Xlib/Extras.hsc" #-}

        poke :: Ptr WMHints -> WMHints -> IO ()
    poke Ptr WMHints
    p WMHints
    wmh = do
            (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> CLong -> IO ()
    forall b. Ptr b -> Int -> CLong -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WMHints
    hsc_ptr Int
    0)         Ptr WMHints
    p (CLong -> IO ()) -> CLong -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WMHints -> CLong
    wmh_flags         WMHints
    wmh
    {-# LINE 1636 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> Bool -> IO ()
    forall b. Ptr b -> Int -> Bool -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WMHints
    hsc_ptr Int
    8)         Ptr WMHints
    p (Bool -> IO ()) -> Bool -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WMHints -> Bool
    wmh_input         WMHints
    wmh
    {-# LINE 1637 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> CInt -> IO ()
    forall b. Ptr b -> Int -> CInt -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WMHints
    hsc_ptr Int
    12) Ptr WMHints
    p (CInt -> IO ()) -> CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WMHints -> CInt
    wmh_initial_state WMHints
    wmh
    {-# LINE 1638 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> XID -> IO ()
    forall b. Ptr b -> Int -> XID -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WMHints
    hsc_ptr Int
    16)   Ptr WMHints
    p (XID -> IO ()) -> XID -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WMHints -> XID
    wmh_icon_pixmap   WMHints
    wmh
    {-# LINE 1639 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> XID -> IO ()
    forall b. Ptr b -> Int -> XID -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WMHints
    hsc_ptr Int
    24)   Ptr WMHints
    p (XID -> IO ()) -> XID -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WMHints -> XID
    wmh_icon_window   WMHints
    wmh
    {-# LINE 1640 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> CInt -> IO ()
    forall b. Ptr b -> Int -> CInt -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WMHints
    hsc_ptr Int
    32)        Ptr WMHints
    p (CInt -> IO ()) -> CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WMHints -> CInt
    wmh_icon_x        WMHints
    wmh
    {-# LINE 1641 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> CInt -> IO ()
    forall b. Ptr b -> Int -> CInt -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WMHints
    hsc_ptr Int
    36)        Ptr WMHints
    p (CInt -> IO ()) -> CInt -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WMHints -> CInt
    wmh_icon_y        WMHints
    wmh
    {-# LINE 1642 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> XID -> IO ()
    forall b. Ptr b -> Int -> XID -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WMHints
    hsc_ptr Int
    40)     Ptr WMHints
    p (XID -> IO ()) -> XID -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WMHints -> XID
    wmh_icon_mask     WMHints
    wmh
    {-# LINE 1643 "Graphics/X11/Xlib/Extras.hsc" #-}
            (\Ptr WMHints
    hsc_ptr -> Ptr WMHints -> Int -> XID -> IO ()
    forall b. Ptr b -> Int -> XID -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr WMHints
    hsc_ptr Int
    48)  Ptr WMHints
    p (XID -> IO ()) -> XID -> IO ()
    forall a b. (a -> b) -> a -> b
    $ WMHints -> XID
    wmh_window_group  WMHints
    wmh
    {-# LINE 1644 "Graphics/X11/Xlib/Extras.hsc" #-}

    foreign import ccall unsafe "XlibExtras.h XGetWMHints"
        xGetWMHints :: Display -> Window -> IO (Ptr WMHints)

    getWMHints :: Display -> Window -> IO WMHints
    getWMHints :: Display -> XID -> IO WMHints
    getWMHints Display
    dpy XID
    w = do
        p <- Display -> XID -> IO (Ptr WMHints)
    xGetWMHints Display
    dpy XID
    w
        if p == nullPtr
            then return $ WMHints 0 False 0 0 0 0 0 0 0
            else do x <- peek p; _ <- xFree p; return x

    foreign import ccall unsafe "XlibExtras.h XAllocWMHints"
        xAllocWMHints :: IO (Ptr WMHints)

    foreign import ccall unsafe "XlibExtras.h XSetWMHints"
        xSetWMHints :: Display -> Window -> Ptr WMHints -> IO Status

    setWMHints :: Display -> Window -> WMHints -> IO Status
    setWMHints :: Display -> XID -> WMHints -> IO CInt
    setWMHints Display
    dpy XID
    w WMHints
    wmh = do
        p_wmh <- IO (Ptr WMHints)
    xAllocWMHints
        poke p_wmh wmh
        res <- xSetWMHints dpy w p_wmh
        _ <- xFree p_wmh
        return res

    ------------------------------------------------------------------------
    -- Keysym Macros
    --
    -- Which we have to wrap in functions, then bind here.

    foreign import ccall unsafe "XlibExtras.h x11_extras_IsCursorKey"
        isCursorKey :: KeySym -> Bool
    foreign import ccall unsafe "XlibExtras.h x11_extras_IsFunctionKey"
        isFunctionKey :: KeySym -> Bool
    foreign import ccall unsafe "XlibExtras.h x11_extras_IsKeypadKey"
        isKeypadKey :: KeySym -> Bool
    foreign import ccall unsafe "XlibExtras.h x11_extras_IsMiscFunctionKey"
        isMiscFunctionKey :: KeySym -> Bool
    foreign import ccall unsafe "XlibExtras.h x11_extras_IsModifierKey"
        isModifierKey :: KeySym -> Bool
    foreign import ccall unsafe "XlibExtras.h x11_extras_IsPFKey"
        isPFKey :: KeySym -> Bool
    foreign import ccall unsafe "XlibExtras.h x11_extras_IsPrivateKeypadKey"
        isPrivateKeypadKey :: KeySym -> Bool

    -------------------------------------------------------------------------------
    -- Selections
    --
    foreign import ccall unsafe "HsXlib.h XSetSelectionOwner"
        xSetSelectionOwner :: Display -> Atom -> Window -> Time -> IO ()

    foreign import ccall unsafe "HsXlib.h XGetSelectionOwner"
        xGetSelectionOwner :: Display -> Atom -> IO Window

    foreign import ccall unsafe "HsXlib.h XConvertSelection"
        xConvertSelection :: Display -> Atom -> Atom -> Atom -> Window -> Time -> IO ()

    -------------------------------------------------------------------------------
    -- Error handling
    --
    type XErrorEventPtr = Ptr ()
    type CXErrorHandler = Display -> XErrorEventPtr -> IO CInt
    type XErrorHandler = Display -> XErrorEventPtr -> IO ()

    data ErrorEvent = ErrorEvent {
        ErrorEvent -> CInt
    ev_type :: !CInt,
        ErrorEvent -> Display
    ev_display :: Display,
        ErrorEvent -> CULong
    ev_serialnum :: !CULong,
        ErrorEvent -> CUChar
    ev_error_code :: !CUChar,
        ErrorEvent -> CUChar
    ev_request_code :: !CUChar,
        ErrorEvent -> CUChar
    ev_minor_code :: !CUChar,
        ErrorEvent -> XID
    ev_resourceid :: !XID
    }

    foreign import ccall safe "wrapper"
        mkXErrorHandler :: CXErrorHandler -> IO (FunPtr CXErrorHandler)
    foreign import ccall safe "dynamic"
        getXErrorHandler :: FunPtr CXErrorHandler -> CXErrorHandler
    foreign import ccall safe "HsXlib.h XSetErrorHandler"
        _xSetErrorHandler :: FunPtr CXErrorHandler -> IO (FunPtr CXErrorHandler)

    -- |A binding to XSetErrorHandler.
    --  NOTE:  This is pretty experimental because of safe vs. unsafe calls.  I
    --  changed sync to a safe call, but there *might* be other calls that cause a
    --  problem
    setErrorHandler :: XErrorHandler -> IO ()
    setErrorHandler :: XErrorHandler -> IO ()
    setErrorHandler XErrorHandler
    new_handler = do
        _handler <- CXErrorHandler -> IO (FunPtr CXErrorHandler)
    mkXErrorHandler (\Display
    d -> \Ptr ()
    e -> XErrorHandler
    new_handler Display
    d Ptr ()
    e IO () -> IO CInt -> IO CInt
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> CInt -> IO CInt
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return CInt
    0)
        _ <- _xSetErrorHandler _handler
        return ()

    -- |Retrieves error event data from a pointer to an XErrorEvent and
    --  puts it into an ErrorEvent.
    getErrorEvent :: XErrorEventPtr -> IO ErrorEvent
    getErrorEvent :: Ptr () -> IO ErrorEvent
    getErrorEvent Ptr ()
    ev_ptr = do
        _type <- (\Ptr ()
    hsc_ptr -> Ptr () -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr ()
    hsc_ptr Int
    0) Ptr ()
    ev_ptr
    {-# LINE 1740 "Graphics/X11/Xlib/Extras.hsc" #-}
        serial <- (\hsc_ptr -> peekByteOff hsc_ptr 24) ev_ptr
    {-# LINE 1741 "Graphics/X11/Xlib/Extras.hsc" #-}
        dsp <- fmap Display ((\hsc_ptr -> peekByteOff hsc_ptr 8) ev_ptr)
    {-# LINE 1742 "Graphics/X11/Xlib/Extras.hsc" #-}
        error_code <- (\hsc_ptr -> peekByteOff hsc_ptr 32) ev_ptr
    {-# LINE 1743 "Graphics/X11/Xlib/Extras.hsc" #-}
        request_code <- (\hsc_ptr -> peekByteOff hsc_ptr 33) ev_ptr
    {-# LINE 1744 "Graphics/X11/Xlib/Extras.hsc" #-}
        minor_code <- (\hsc_ptr -> peekByteOff hsc_ptr 34) ev_ptr
    {-# LINE 1745 "Graphics/X11/Xlib/Extras.hsc" #-}
        resourceid <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ev_ptr
    {-# LINE 1746 "Graphics/X11/Xlib/Extras.hsc" #-}
        return $ ErrorEvent {
            ev_type = _type,
            ev_display = dsp,
            ev_serialnum = serial,
            ev_error_code = error_code,
            ev_request_code = request_code,
            ev_minor_code = minor_code,
            ev_resourceid = resourceid
        }

    -- |A binding to XMapRaised.
    foreign import ccall unsafe "HsXlib.h XMapRaised"
        mapRaised :: Display -> Window -> IO CInt

    foreign import ccall unsafe "HsXlib.h XGetCommand"
        xGetCommand :: Display -> Window -> Ptr (Ptr CWString) -> Ptr CInt -> IO Status

    getCommand :: Display -> Window -> IO [String]
    getCommand :: Display -> XID -> IO [String]
    getCommand Display
    d XID
    w =
      (Ptr (Ptr CWString) -> IO [String]) -> IO [String]
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr (Ptr CWString) -> IO [String]) -> IO [String])
    -> (Ptr (Ptr CWString) -> IO [String]) -> IO [String]
    forall a b. (a -> b) -> a -> b
    $
      \Ptr (Ptr CWString)
    argvp ->
      (Ptr CInt -> IO [String]) -> IO [String]
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CInt -> IO [String]) -> IO [String])
    -> (Ptr CInt -> IO [String]) -> IO [String]
    forall a b. (a -> b) -> a -> b
    $
      \Ptr CInt
    argcp ->
      do
        _ <- (CInt -> Bool) -> (CInt -> String) -> IO CInt -> IO CInt
    forall a. (a -> Bool) -> (a -> String) -> IO a -> IO a
    throwIf (CInt
    success CInt -> CInt -> Bool
    forall a. Ord a => a -> a -> Bool
    >) (\CInt
    status -> String
    "xGetCommand returned status: " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ CInt -> String
    forall a. Show a => a -> String
    show CInt
    status) (IO CInt -> IO CInt) -> IO CInt -> IO CInt
    forall a b. (a -> b) -> a -> b
    $ Display -> XID -> Ptr (Ptr CWString) -> Ptr CInt -> IO CInt
    xGetCommand Display
    d XID
    w Ptr (Ptr CWString)
    argvp Ptr CInt
    argcp
        argc <- peek argcp
        argv <- peek argvp
        texts <- flip mapM [0 .. fromIntegral $ pred argc] $ \Int
    i -> Ptr CWString -> Int -> IO CWString
    forall a. Storable a => Ptr a -> Int -> IO a
    peekElemOff Ptr CWString
    argv Int
    i IO CWString -> (CWString -> IO String) -> IO String
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= CWString -> IO String
    peekCWString
        wcFreeStringList argv
        return texts

    foreign import ccall unsafe "HsXlib.h XGetModifierMapping"
        xGetModifierMapping :: Display -> IO (Ptr ())

    foreign import ccall unsafe "HsXlib.h XFreeModifiermap"
        xFreeModifiermap :: Ptr () -> IO (Ptr CInt)

    getModifierMapping :: Display -> IO [(Modifier, [KeyCode])]
    getModifierMapping :: Display -> IO [(KeyMask, [KeyCode])]
    getModifierMapping Display
    d = do
        p <- Display -> IO (Ptr ())
    xGetModifierMapping Display
    d
        m' <- (\Ptr ()
    hsc_ptr -> Ptr () -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr ()
    hsc_ptr Int
    0) p :: IO CInt
    {-# LINE 1787 "Graphics/X11/Xlib/Extras.hsc" #-}
        let m = fromIntegral m'
        pks <- (\Ptr ()
    hsc_ptr -> Ptr () -> Int -> IO (Ptr KeyCode)
    forall b. Ptr b -> Int -> IO (Ptr KeyCode)
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr ()
    hsc_ptr Int
    8) p :: IO (Ptr KeyCode)
    {-# LINE 1789 "Graphics/X11/Xlib/Extras.hsc" #-}
        ks <- peekArray (m * 8) pks
        _ <- xFreeModifiermap p
        return . zip masks . map fst . tail . iterate (splitAt m . snd) $ ([], ks)
     where
        masks :: [KeyMask]
    masks = [KeyMask
    shiftMapIndex .. KeyMask
    mod5MapIndex]