{-# 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
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> 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 = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String
"unknown " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show EventType
x) forall a. a -> a
id forall a b. (a -> b) -> a -> b
$ forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup EventType
x [(EventType, String)]
eventTable
 where x :: EventType
x = forall a b. (Integral a, Num b) => a -> b
fromIntegral 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.
    EventType
type_      <- (\XEventPtr
hsc_ptr -> 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 :: Bool
rrHasExtension = forall a. Maybe a -> Bool
isJust Maybe (CInt, CInt)
rrData
    let rrEventBase :: EventType
rrEventBase    = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a -> a
fromMaybe (CInt
0, CInt
0) Maybe (CInt, CInt)
rrData
    case () of

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

          ------------------
          -- ConfigureEvent:
          ------------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
configureNotify -> do
            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)
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\XEventPtr
hsc_ptr -> 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_ forall a. Eq a => a -> a -> Bool
== EventType
mapRequest -> do
            XID
parent <- (\XEventPtr
hsc_ptr -> 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" #-}
            XID
window <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
40) XEventPtr
p
{-# LINE 429 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ MapRequestEvent
                        { 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_parent :: XID
ev_parent        = XID
parent
                        , ev_window :: XID
ev_window        = XID
window
                        }

          -------------------
          -- MapNotifyEvent
          -------------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
mapNotify -> do
            XID
event             <- (\XEventPtr
hsc_ptr -> 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" #-}
            XID
window            <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
40) XEventPtr
p
{-# LINE 444 "Graphics/X11/Xlib/Extras.hsc" #-}
            Bool
override_redirect <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
48) XEventPtr
p
{-# LINE 445 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ MapNotifyEvent
                        { 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_event :: XID
ev_event             = XID
event
                        , ev_window :: XID
ev_window            = XID
window
                        , ev_override_redirect :: Bool
ev_override_redirect = Bool
override_redirect
                        }

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

            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ MappingNotifyEvent
                        { 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_request :: CInt
ev_request       = CInt
request
                        , ev_first_keycode :: KeyCode
ev_first_keycode = KeyCode
first_keycode
                        , ev_count :: CInt
ev_count         = CInt
count
                        }

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

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

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

            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ButtonEvent
                        { 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_root :: XID
ev_root          = XID
root
                        , ev_subwindow :: XID
ev_subwindow     = XID
subwindow
                        , ev_time :: XID
ev_time          = XID
time
                        , ev_x :: CInt
ev_x             = CInt
x
                        , ev_y :: CInt
ev_y             = CInt
y
                        , ev_x_root :: CInt
ev_x_root        = CInt
x_root
                        , ev_y_root :: CInt
ev_y_root        = CInt
y_root
                        , ev_state :: KeyMask
ev_state         = forall a b. (Integral a, Num b) => a -> b
fromIntegral KeyMask
state
                        , ev_button :: EventType
ev_button        = EventType
button
                        , ev_same_screen :: Bool
ev_same_screen   = Bool
same_screen
                        }

          ---------------
          -- MotionEvent:
          ---------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
motionNotify -> do
            XID
window <- (\XEventPtr
hsc_ptr -> 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" #-}
            CInt
x      <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
64) XEventPtr
p
{-# LINE 549 "Graphics/X11/Xlib/Extras.hsc" #-}
            CInt
y      <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
68) XEventPtr
p
{-# LINE 550 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ MotionEvent
                        { 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_x :: CInt
ev_x             = CInt
x
                        , ev_y :: CInt
ev_y             = CInt
y
                        , ev_window :: XID
ev_window        = XID
window
                        }


          ----------------------
          -- DestroyWindowEvent:
          ----------------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
destroyNotify -> do
            XID
event  <- (\XEventPtr
hsc_ptr -> 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" #-}
            XID
window <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
40) XEventPtr
p
{-# LINE 567 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ DestroyWindowEvent
                        { 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_event :: XID
ev_event         = XID
event
                        , ev_window :: XID
ev_window        = XID
window
                        }


          --------------------
          -- UnmapNotifyEvent:
          --------------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
unmapNotify -> do
            XID
event          <- (\XEventPtr
hsc_ptr -> 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" #-}
            XID
window         <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
40) XEventPtr
p
{-# LINE 583 "Graphics/X11/Xlib/Extras.hsc" #-}
            Bool
from_configure <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
48) XEventPtr
p
{-# LINE 584 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ UnmapEvent
                        { 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_event :: XID
ev_event         = XID
event
                        , ev_window :: XID
ev_window        = XID
window
                        , ev_from_configure :: Bool
ev_from_configure = Bool
from_configure
                        }

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

            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CrossingEvent
                        { 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_root :: XID
ev_root          = XID
root
                        , ev_subwindow :: XID
ev_subwindow     = XID
subwindow
                        , ev_time :: XID
ev_time          = XID
time
                        , ev_x :: CInt
ev_x             = CInt
x
                        , ev_y :: CInt
ev_y             = CInt
y
                        , ev_x_root :: CInt
ev_x_root        = CInt
x_root
                        , ev_y_root :: CInt
ev_y_root        = CInt
y_root
                        , ev_mode :: CInt
ev_mode          = CInt
mode
                        , ev_detail :: CInt
ev_detail        = CInt
detail
                        , ev_same_screen :: Bool
ev_same_screen   = Bool
same_screen
                        , ev_focus :: Bool
ev_focus         = Bool
focus
                        , ev_state :: KeyMask
ev_state         = forall a b. (Integral a, Num b) => a -> b
fromIntegral KeyMask
state
                        }

          -------------------------
          -- SelectionRequestEvent:
          -------------------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
selectionRequest -> do
            XID
owner          <- (\XEventPtr
hsc_ptr -> 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" #-}
            XID
requestor      <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
40) XEventPtr
p
{-# LINE 638 "Graphics/X11/Xlib/Extras.hsc" #-}
            XID
selection      <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
48) XEventPtr
p
{-# LINE 639 "Graphics/X11/Xlib/Extras.hsc" #-}
            XID
target         <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
56) XEventPtr
p
{-# LINE 640 "Graphics/X11/Xlib/Extras.hsc" #-}
            XID
property       <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
64) XEventPtr
p
{-# LINE 641 "Graphics/X11/Xlib/Extras.hsc" #-}
            XID
time           <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
72) XEventPtr
p
{-# LINE 642 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ SelectionRequest
                        { 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_owner :: XID
ev_owner         = XID
owner
                        , ev_requestor :: XID
ev_requestor     = XID
requestor
                        , ev_selection :: XID
ev_selection     = XID
selection
                        , ev_target :: XID
ev_target        = XID
target
                        , ev_property :: XID
ev_property      = XID
property
                        , ev_time :: XID
ev_time          = XID
time
                        }

          -------------------------
          -- SelectionClearEvent:
          -------------------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
selectionClear -> do
            XID
window <- (\XEventPtr
hsc_ptr -> 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" #-}
            XID
atom   <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
40) XEventPtr
p
{-# LINE 661 "Graphics/X11/Xlib/Extras.hsc" #-}
            XID
time   <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
48) XEventPtr
p
{-# LINE 662 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ SelectionClear
                        { 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_selection :: XID
ev_selection     = XID
atom
                        , ev_time :: XID
ev_time          = XID
time
                        }
          -------------------------
          -- PropertyEvent
          -------------------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
propertyNotify -> do
            XID
window <- (\XEventPtr
hsc_ptr -> 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" #-}
            XID
atom   <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
40) XEventPtr
p
{-# LINE 677 "Graphics/X11/Xlib/Extras.hsc" #-}
            XID
time   <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
48) XEventPtr
p
{-# LINE 678 "Graphics/X11/Xlib/Extras.hsc" #-}
            CInt
state  <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
56) XEventPtr
p
{-# LINE 679 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ PropertyEvent
                        { 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_atom :: XID
ev_atom          = XID
atom
                        , ev_time :: XID
ev_time          = XID
time
                        , ev_propstate :: CInt
ev_propstate     = CInt
state
                        }

          -------------------------
          -- ExposeEvent
          -------------------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
expose -> do
            XID
window <- (\XEventPtr
hsc_ptr -> 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" #-}
            CInt
x      <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
40) XEventPtr
p
{-# LINE 696 "Graphics/X11/Xlib/Extras.hsc" #-}
            CInt
y      <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
44) XEventPtr
p
{-# LINE 697 "Graphics/X11/Xlib/Extras.hsc" #-}
            CInt
width  <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
48) XEventPtr
p
{-# LINE 698 "Graphics/X11/Xlib/Extras.hsc" #-}
            CInt
height <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
52) XEventPtr
p
{-# LINE 699 "Graphics/X11/Xlib/Extras.hsc" #-}
            CInt
count  <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
56) XEventPtr
p
{-# LINE 700 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ExposeEvent
                        { 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_x :: CInt
ev_x             = CInt
x
                        , ev_y :: CInt
ev_y             = CInt
y
                        , ev_width :: CInt
ev_width         = CInt
width
                        , ev_height :: CInt
ev_height        = CInt
height
                        , ev_count :: CInt
ev_count         = CInt
count
                        }

          -------------------------
          -- FocusChangeEvent
          -------------------------
          | EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
focusIn Bool -> Bool -> Bool
|| EventType
type_ forall a. Eq a => a -> a -> Bool
== EventType
focusOut -> do
            XID
window <- (\XEventPtr
hsc_ptr -> 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" #-}
            CInt
mode   <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
40) XEventPtr
p
{-# LINE 719 "Graphics/X11/Xlib/Extras.hsc" #-}
            CInt
detail <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
44) XEventPtr
p
{-# LINE 720 "Graphics/X11/Xlib/Extras.hsc" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ FocusChangeEvent
                        { 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_mode :: CInt
ev_mode          = CInt
mode
                        , ev_detail :: CInt
ev_detail        = CInt
detail
                        }

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

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

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

                  | EventType
subtype_ forall a. Eq a => a -> a -> Bool
== EventType
rrNotifyOutputChange -> do
                    XID
output         <- (\XEventPtr
hsc_ptr -> 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" #-}
                    XID
crtc           <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
56) XEventPtr
p
{-# LINE 826 "Graphics/X11/Xlib/Extras.hsc" #-}
                    XID
mode           <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
64) XEventPtr
p
{-# LINE 827 "Graphics/X11/Xlib/Extras.hsc" #-}
                    Word16
rotation       <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
72) XEventPtr
p
{-# LINE 828 "Graphics/X11/Xlib/Extras.hsc" #-}
                    Word16
connection     <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
74) XEventPtr
p
{-# LINE 829 "Graphics/X11/Xlib/Extras.hsc" #-}
                    Word16
subpixel_order <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
76) XEventPtr
p
{-# LINE 830 "Graphics/X11/Xlib/Extras.hsc" #-}
                    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ RROutputChangeNotifyEvent
                             { 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
                             , ev_output :: XID
ev_output         = XID
output
                             , ev_crtc :: XID
ev_crtc           = XID
crtc
                             , ev_rr_mode :: XID
ev_rr_mode        = XID
mode
                             , ev_rotation :: Word16
ev_rotation       = Word16
rotation
                             , ev_connection :: Word16
ev_connection     = Word16
connection
                             , ev_subpixel_order :: Word16
ev_subpixel_order = Word16
subpixel_order
                             }

                  | EventType
subtype_ forall a. Eq a => a -> a -> Bool
== EventType
rrNotifyOutputProperty -> do
                    XID
output         <- (\XEventPtr
hsc_ptr -> 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" #-}
                    XID
property       <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
56) XEventPtr
p
{-# LINE 848 "Graphics/X11/Xlib/Extras.hsc" #-}
                    XID
timestamp      <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
64) XEventPtr
p
{-# LINE 849 "Graphics/X11/Xlib/Extras.hsc" #-}
                    CInt
state          <- (\XEventPtr
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff XEventPtr
hsc_ptr Int
72) XEventPtr
p
{-# LINE 850 "Graphics/X11/Xlib/Extras.hsc" #-}
                    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ RROutputPropertyNotifyEvent
                             { 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
                             , ev_output :: XID
ev_output        = XID
output
                             , ev_property :: XID
ev_property      = XID
property
                             , ev_timestamp :: XID
ev_timestamp     = XID
timestamp
                             , ev_rr_state :: CInt
ev_rr_state      = CInt
state
                             }

                  -- We don't handle this event specifically, so return the generic
                  -- RRNotifyEvent.
                  | Bool
otherwise -> do
                    forall (m :: * -> *) a. Monad m => a -> m a
return 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_ forall a. Eq a => a -> a -> Bool
== EventType
screenSaverNotify -> do
            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)
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\XEventPtr
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\XEventPtr
hsc_ptr -> 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
            XID
window <- (\XEventPtr
hsc_ptr -> 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" #-}
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ AnyEvent
                        { 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
                        }

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
_ = forall a. Storable a => a -> Int
alignment (forall a. HasCallStack => a
undefined :: CInt)

    poke :: Ptr WindowChanges -> WindowChanges -> IO ()
poke Ptr WindowChanges
p WindowChanges
wc = do
        (\Ptr WindowChanges
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WindowChanges
hsc_ptr Int
0) Ptr WindowChanges
p forall a b. (a -> b) -> a -> b
$ WindowChanges -> CInt
wc_x WindowChanges
wc
{-# LINE 917 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\Ptr WindowChanges
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WindowChanges
hsc_ptr Int
4) Ptr WindowChanges
p forall a b. (a -> b) -> a -> b
$ WindowChanges -> CInt
wc_y WindowChanges
wc
{-# LINE 918 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\Ptr WindowChanges
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WindowChanges
hsc_ptr Int
8) Ptr WindowChanges
p forall a b. (a -> b) -> a -> b
$ WindowChanges -> CInt
wc_width WindowChanges
wc
{-# LINE 919 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\Ptr WindowChanges
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WindowChanges
hsc_ptr Int
12) Ptr WindowChanges
p forall a b. (a -> b) -> a -> b
$ WindowChanges -> CInt
wc_height WindowChanges
wc
{-# LINE 920 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\Ptr WindowChanges
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WindowChanges
hsc_ptr Int
16) Ptr WindowChanges
p 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 -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WindowChanges
hsc_ptr Int
24) Ptr WindowChanges
p forall a b. (a -> b) -> a -> b
$ WindowChanges -> XID
wc_sibling WindowChanges
wc
{-# LINE 922 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\Ptr WindowChanges
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WindowChanges
hsc_ptr Int
32) Ptr WindowChanges
p 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 = forall (m :: * -> *) a. Monad m => a -> m a
return CInt
-> CInt -> CInt -> CInt -> CInt -> XID -> CInt -> WindowChanges
WindowChanges
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr WindowChanges
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr WindowChanges
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr WindowChanges
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr WindowChanges
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr WindowChanges
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr WindowChanges
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr WindowChanges
hsc_ptr -> 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 = 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
    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)
    forall (m :: * -> *) a. Monad m => a -> m a
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 =
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr XID
root_return ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr XID
parent_return ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr XID)
children_return ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
nchildren_return -> do
        ()
_ <- String -> IO CInt -> IO ()
throwIfZero String
"queryTree" 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
        Ptr XID
p <- forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr XID)
children_return
        Int
n <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
nchildren_return
        [XID]
ws <- forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
n Ptr XID
p
        CInt
_ <- forall a. Ptr a -> IO CInt
xFree Ptr XID
p
        forall (m :: * -> *) a1 a2 a3 r.
Monad m =>
(a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
liftM3 (,,) (forall a. Storable a => Ptr a -> IO a
peek Ptr XID
root_return) (forall a. Storable a => Ptr a -> IO a
peek Ptr XID
parent_return) (forall (m :: * -> *) a. Monad m => a -> m a
return [XID]
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   = 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
_ = forall a. Storable a => a -> Int
alignment (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 = forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr WindowAttributes
p -> do
    ()
_ <- String -> IO CInt -> IO ()
throwIfZero String
"getWindowAttributes" forall a b. (a -> b) -> a -> b
$ Display -> XID -> Ptr WindowAttributes -> IO CInt
xGetWindowAttributes Display
d XID
w Ptr WindowAttributes
p
    forall a. Storable a => Ptr a -> IO a
peek Ptr WindowAttributes
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 =
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr TextProperty
textp -> do
        CInt
_ <- forall a. (a -> Bool) -> (a -> String) -> IO a -> IO a
throwIf (CInt
0forall a. Eq a => a -> a -> Bool
==) (forall a b. a -> b -> a
const String
"getTextProperty") forall a b. (a -> b) -> a -> b
$ Display -> XID -> Ptr TextProperty -> XID -> IO CInt
xGetTextProperty Display
d XID
w Ptr TextProperty
textp XID
a
        forall a. Storable a => Ptr a -> IO a
peek Ptr TextProperty
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 =
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca    forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CWString)
listp  ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca    forall a b. (a -> b) -> a -> b
$ \Ptr CInt
countp ->
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with TextProperty
prop forall a b. (a -> b) -> a -> b
$ \Ptr TextProperty
propp  -> do
        CInt
_ <- forall a. (a -> Bool) -> (a -> String) -> IO a -> IO a
throwIf (CInt
successforall a. Ord a => a -> a -> Bool
>) (forall a b. a -> b -> a
const String
"wcTextPropertyToTextList") 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
        CInt
count <- forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
countp
        Ptr CWString
list  <- forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr CWString)
listp
        [String]
texts <- forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM [Int
0..forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
count forall a. Num a => a -> a -> a
- Int
1] forall a b. (a -> b) -> a -> b
$ \Int
i ->
                     forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff Ptr CWString
list Int
i forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CWString -> IO String
peekCWString
        Ptr CWString -> IO ()
wcFreeStringList Ptr CWString
list
        forall (m :: * -> *) a. Monad m => a -> m a
return [String]
texts

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

newtype FontSet = FontSet (Ptr FontSet)
    deriving (FontSet -> FontSet -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FontSet -> FontSet -> Bool
$c/= :: FontSet -> FontSet -> Bool
== :: FontSet -> FontSet -> Bool
$c== :: FontSet -> FontSet -> Bool
Eq, Eq 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
min :: FontSet -> FontSet -> FontSet
$cmin :: FontSet -> FontSet -> FontSet
max :: FontSet -> FontSet -> FontSet
$cmax :: FontSet -> FontSet -> FontSet
>= :: FontSet -> FontSet -> Bool
$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
compare :: FontSet -> FontSet -> Ordering
$ccompare :: FontSet -> FontSet -> Ordering
Ord, Int -> FontSet -> ShowS
[FontSet] -> ShowS
FontSet -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FontSet] -> ShowS
$cshowList :: [FontSet] -> ShowS
show :: FontSet -> String
$cshow :: FontSet -> String
showsPrec :: Int -> FontSet -> ShowS
$cshowsPrec :: Int -> 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 =
    forall a. String -> (CString -> IO a) -> IO a
withCString String
fn forall a b. (a -> b) -> a -> b
$ \CString
fontp  ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca         forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CString)
listp  ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca         forall a b. (a -> b) -> a -> b
$ \Ptr CInt
countp ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca         forall a b. (a -> b) -> a -> b
$ \Ptr CString
defp   -> do
        Ptr FontSet
fs      <- forall a. String -> IO (Ptr a) -> IO (Ptr a)
throwIfNull String
"createFontSet" 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
        CInt
count   <- forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
countp
        Ptr CString
list    <- forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr CString)
listp
        [String]
missing <- forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM [Int
0..forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
count forall a. Num a => a -> a -> a
- Int
1] forall a b. (a -> b) -> a -> b
$ \Int
i ->
                       forall a. Storable a => Ptr a -> Int -> IO a
peekElemOff Ptr CString
list Int
i forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CString -> IO String
peekCString
        String
def     <- forall a. Storable a => Ptr a -> IO a
peek Ptr CString
defp forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CString -> IO String
peekCString
        Ptr CString -> IO ()
freeStringList Ptr CString
list
        forall (m :: * -> *) a. Monad m => a -> m a
return ([String]
missing, String
def, Ptr FontSet -> FontSet
FontSet Ptr 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 = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$
    forall a. String -> (CWStringLen -> IO a) -> IO a
withCWStringLen String
text forall a b. (a -> b) -> a -> b
$ \(CWString
textp, Int
len) ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca               forall a b. (a -> b) -> a -> b
$ \Ptr Rectangle
inkp          ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca               forall a b. (a -> b) -> a -> b
$ \Ptr Rectangle
logicalp      -> do
        CInt
_ <- FontSet
-> CWString -> CInt -> Ptr Rectangle -> Ptr Rectangle -> IO CInt
xwcTextExtents FontSet
fs CWString
textp (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
len) Ptr Rectangle
inkp Ptr Rectangle
logicalp
        (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall a. Storable a => Ptr a -> IO a
peek Ptr Rectangle
inkp forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` forall a. Storable a => Ptr a -> IO a
peek Ptr Rectangle
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 =
    forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. String -> (CWStringLen -> IO a) -> IO a
withCWStringLen 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 (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 =
    forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. String -> (CWStringLen -> IO a) -> IO a
withCWStringLen 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 (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 = forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$
    forall a. String -> (CWStringLen -> IO a) -> IO a
withCWStringLen String
string forall a b. (a -> b) -> a -> b
$ \ (CWString
c_string, Int
len) ->
    FontSet -> CWString -> CInt -> IO Position
xwcTextEscapement FontSet
font_set CWString
c_string (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 = forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CString
p -> do
    CInt
_ <- Display -> XID -> Ptr CString -> IO CInt
xFetchName Display
d XID
w Ptr CString
p
    CString
cstr <- forall a. Storable a => Ptr a -> IO a
peek Ptr CString
p
    if CString
cstr forall a. Eq a => a -> a -> Bool
== forall {b}. Ptr b
nullPtr
        then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
        else do
            String
str <- CString -> IO String
peekCString CString
cstr
            CInt
_ <- forall a. Ptr a -> IO CInt
xFree CString
cstr
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just String
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 = forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr XID
wp -> do
    CInt
status <- Display -> XID -> Ptr XID -> IO CInt
xGetTransientForHint Display
d XID
w Ptr XID
wp
    if CInt
status forall a. Eq a => a -> a -> Bool
== CInt
0
        then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
        else forall a. a -> Maybe a
Just forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` forall a. Storable a => Ptr a -> IO a
peek Ptr XID
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
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr XID)
atom_ptr_ptr ->
      forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
count_ptr -> do

       CInt
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 CInt
st forall a. Eq a => a -> a -> Bool
== CInt
0
            then forall (m :: * -> *) a. Monad m => a -> m a
return []
            else do CInt
sz       <- forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
count_ptr
                    Ptr XID
atom_ptr <- forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr XID)
atom_ptr_ptr
                    [XID]
atoms    <- forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray (forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
sz) Ptr XID
atom_ptr
                    CInt
_ <- forall a. Ptr a -> IO CInt
xFree Ptr XID
atom_ptr
                    forall (m :: * -> *) a. Monad m => a -> m a
return [XID]
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 -> 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 -> 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 [forall a b. (Integral a, Num b) => a -> b
fromIntegral XID
l_0_, 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 -> 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 -> 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 -> 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)})
 = forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes (Int
56) 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
_ = 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 =
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr XID
actual_type_return ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CInt
actual_format_return ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CULong
nitems_return ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CULong
bytes_after_return ->
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CUChar)
prop_return -> do
        CInt
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 CInt
ret forall a. Eq a => a -> a -> Bool
/= CInt
0
            then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
            else do
                Ptr CUChar
prop_ptr      <- forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr CUChar)
prop_return
                Int
actual_format <- forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall a. Storable a => Ptr a -> IO a
peek Ptr CInt
actual_format_return
                Int
nitems        <- forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall a. Storable a => Ptr a -> IO a
peek Ptr CULong
nitems_return
                forall {a} {a}. Storable a => Ptr a -> Int -> Int -> IO (Maybe [a])
getprop Ptr CUChar
prop_ptr Int
nitems Int
actual_format
  where
    getprop :: Ptr a -> Int -> Int -> IO (Maybe [a])
getprop Ptr a
prop_ptr Int
nitems Int
actual_format
        | Int
actual_format forall a. Eq a => a -> a -> Bool
== Int
0    = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing -- Property not found
        | Int
actual_format forall a. Eq a => a -> a -> Bool
/= Int
bits = forall a. Ptr a -> IO CInt
xFree Ptr a
prop_ptr forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
        | Bool
otherwise = do
            [a]
retval <- forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray Int
nitems (forall a b. Ptr a -> Ptr b
castPtr Ptr a
prop_ptr)
            CInt
_ <- forall a. Ptr a -> IO CInt
xFree Ptr a
prop_ptr
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just [a]
retval

getWindowProperty8 :: Display -> Atom -> Window -> IO (Maybe [CChar])
getWindowProperty8 :: Display -> XID -> XID -> IO (Maybe [CChar])
getWindowProperty8 = 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 = 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 = 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 =
    forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
withArrayLen [CChar]
dat forall a b. (a -> b) -> a -> b
$ \ Int
len CString
ptr -> do
        CInt
_ <- Display
-> XID
-> XID
-> XID
-> CInt
-> CInt
-> Ptr CUChar
-> CInt
-> IO CInt
xChangeProperty Display
dpy XID
w XID
prop XID
typ CInt
8 CInt
mode (forall a b. Ptr a -> Ptr b
castPtr CString
ptr) (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
len)
        forall (m :: * -> *) a. Monad m => a -> m a
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 =
    forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
withArrayLen [CShort]
dat forall a b. (a -> b) -> a -> b
$ \ Int
len Ptr CShort
ptr -> do
        CInt
_ <- Display
-> XID
-> XID
-> XID
-> CInt
-> CInt
-> Ptr CUChar
-> CInt
-> IO CInt
xChangeProperty Display
dpy XID
w XID
prop XID
typ CInt
16 CInt
mode (forall a b. Ptr a -> Ptr b
castPtr Ptr CShort
ptr) (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
len)
        forall (m :: * -> *) a. Monad m => a -> m a
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 =
    forall a b. Storable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
withArrayLen [CLong]
dat forall a b. (a -> b) -> a -> b
$ \ Int
len Ptr CLong
ptr -> do
        CInt
_ <- Display
-> XID
-> XID
-> XID
-> CInt
-> CInt
-> Ptr CUChar
-> CInt
-> IO CInt
xChangeProperty Display
dpy XID
w XID
prop XID
typ CInt
32 CInt
mode (forall a b. Ptr a -> Ptr b
castPtr Ptr CLong
ptr) (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
len)
        forall (m :: * -> *) a. Monad m => a -> m a
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
    CInt
_ <- Display -> XID -> XID -> IO CInt
xDeleteProperty Display
dpy XID
w XID
prop
    forall (m :: * -> *) a. Monad m => a -> m a
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 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> 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
_ = forall a. Storable a => a -> Int
alignment (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 = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (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 CLong
flag <- (\Ptr SizeHints
hsc_ptr -> 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 -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr SizeHints
hsc_ptr Int
0) Ptr SizeHints
p (forall a. Bits a => a -> Int -> a
setBit CLong
flag Int
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
      CLong
flags <- (\Ptr SizeHints
hsc_ptr -> 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
      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
         forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` forall {m :: * -> *} {a1}. Monad m => Int -> m a1 -> m (Maybe a1)
whenBit Int
pMinSizeBit    (do forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) ((\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
24) Ptr SizeHints
p)
{-# LINE 1503 "Graphics/X11/Xlib/Extras.hsc" #-}
                                                    ((\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
28) Ptr SizeHints
p))
{-# LINE 1504 "Graphics/X11/Xlib/Extras.hsc" #-}
         forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` forall {m :: * -> *} {a1}. Monad m => Int -> m a1 -> m (Maybe a1)
whenBit Int
pMaxSizeBit    (do forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) ((\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
32) Ptr SizeHints
p)
{-# LINE 1505 "Graphics/X11/Xlib/Extras.hsc" #-}
                                                    ((\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
36) Ptr SizeHints
p))
{-# LINE 1506 "Graphics/X11/Xlib/Extras.hsc" #-}
         forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` forall {m :: * -> *} {a1}. Monad m => Int -> m a1 -> m (Maybe a1)
whenBit Int
pResizeIncBit  (do forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) ((\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
40) Ptr SizeHints
p)
{-# LINE 1507 "Graphics/X11/Xlib/Extras.hsc" #-}
                                                    ((\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
44) Ptr SizeHints
p))
{-# LINE 1508 "Graphics/X11/Xlib/Extras.hsc" #-}
         forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` forall {m :: * -> *} {a1}. Monad m => Int -> m a1 -> m (Maybe a1)
whenBit Int
pAspectBit     (do EventType
minx <- (\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
48) Ptr SizeHints
p
{-# LINE 1509 "Graphics/X11/Xlib/Extras.hsc" #-}
                                         EventType
miny <- (\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
52) Ptr SizeHints
p
{-# LINE 1510 "Graphics/X11/Xlib/Extras.hsc" #-}
                                         EventType
maxx <- (\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
56) Ptr SizeHints
p
{-# LINE 1511 "Graphics/X11/Xlib/Extras.hsc" #-}
                                         EventType
maxy <- (\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
60) Ptr SizeHints
p
{-# LINE 1512 "Graphics/X11/Xlib/Extras.hsc" #-}
                                         forall (m :: * -> *) a. Monad m => a -> m a
return ((EventType
minx, EventType
miny), (EventType
maxx, EventType
maxy)))
         forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` forall {m :: * -> *} {a1}. Monad m => Int -> m a1 -> m (Maybe a1)
whenBit Int
pBaseSizeBit   (do forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 (,) ((\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
64) Ptr SizeHints
p)
{-# LINE 1514 "Graphics/X11/Xlib/Extras.hsc" #-}
                                                    ((\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
68) Ptr SizeHints
p))
{-# LINE 1515 "Graphics/X11/Xlib/Extras.hsc" #-}
         forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` forall {m :: * -> *} {a1}. Monad m => Int -> m a1 -> m (Maybe a1)
whenBit Int
pWinGravityBit ((\Ptr SizeHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr SizeHints
hsc_ptr Int
72) Ptr SizeHints
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
    = forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr SizeHints
sh -> do
        forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr CLong
supplied_return -> do
          -- what's the purpose of supplied_return?
          CInt
status <- Display -> XID -> Ptr SizeHints -> Ptr CLong -> IO CInt
xGetWMNormalHints Display
d XID
w Ptr SizeHints
sh Ptr CLong
supplied_return
          case CInt
status of
            CInt
0 -> 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 forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing forall a. Maybe a
Nothing)
            CInt
_ -> 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 SizeHints
ptr_hints <- forall a. String -> IO (Ptr a) -> IO (Ptr a)
throwIfNull String
"xAllocSizeHints" IO (Ptr SizeHints)
xAllocSizeHints
    forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr SizeHints
ptr_hints SizeHints
hints
    Display -> XID -> Ptr SizeHints -> IO ()
xSetWMNormalHints Display
dpy XID
win Ptr SizeHints
ptr_hints
    CInt
_ <- forall a. Ptr a -> IO CInt
xFree Ptr SizeHints
ptr_hints
    forall (m :: * -> *) a. Monad m => a -> m a
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 =  forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes ((Int
16)) 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) =
    forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes ((Int
16)) forall a b. (a -> b) -> a -> b
$ \Ptr ClassHint
ptr -> do
{-# LINE 1570 "Graphics/X11/Xlib/Extras.hsc" #-}
        forall a. String -> (CString -> IO a) -> IO a
withCString String
name forall a b. (a -> b) -> a -> b
$ \CString
c_name -> forall a. String -> (CString -> IO a) -> IO a
withCString String
cl forall a b. (a -> b) -> a -> b
$ \CString
c_cl -> do
            (\Ptr ClassHint
hsc_ptr -> 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 -> 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
_ = forall a. Storable a => a -> Int
alignment (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 = forall (m :: * -> *) a. Monad m => a -> m a
return CLong
-> Bool
-> CInt
-> XID
-> XID
-> CInt
-> CInt
-> XID
-> XID
-> WMHints
WMHints
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\Ptr WMHints
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\Ptr WMHints
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\Ptr WMHints
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\Ptr WMHints
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\Ptr WMHints
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\Ptr WMHints
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\Ptr WMHints
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\Ptr WMHints
hsc_ptr -> 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" #-}
                forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` (\Ptr WMHints
hsc_ptr -> 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 -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WMHints
hsc_ptr Int
0)         Ptr WMHints
p forall a b. (a -> b) -> a -> b
$ WMHints -> CLong
wmh_flags         WMHints
wmh
{-# LINE 1636 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\Ptr WMHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WMHints
hsc_ptr Int
8)         Ptr WMHints
p forall a b. (a -> b) -> a -> b
$ WMHints -> Bool
wmh_input         WMHints
wmh
{-# LINE 1637 "Graphics/X11/Xlib/Extras.hsc" #-}
        (\Ptr WMHints
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WMHints
hsc_ptr Int
12) Ptr WMHints
p 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 -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WMHints
hsc_ptr Int
16)   Ptr WMHints
p 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 -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WMHints
hsc_ptr Int
24)   Ptr WMHints
p 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 -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WMHints
hsc_ptr Int
32)        Ptr WMHints
p 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 -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WMHints
hsc_ptr Int
36)        Ptr WMHints
p 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 -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WMHints
hsc_ptr Int
40)     Ptr WMHints
p 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 -> forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr WMHints
hsc_ptr Int
48)  Ptr WMHints
p 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
    Ptr WMHints
p <- Display -> XID -> IO (Ptr WMHints)
xGetWMHints Display
dpy XID
w
    if Ptr WMHints
p forall a. Eq a => a -> a -> Bool
== forall {b}. Ptr b
nullPtr
        then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CLong
-> Bool
-> CInt
-> XID
-> XID
-> CInt
-> CInt
-> XID
-> XID
-> WMHints
WMHints CLong
0 Bool
False CInt
0 XID
0 XID
0 CInt
0 CInt
0 XID
0 XID
0
        else do WMHints
x <- forall a. Storable a => Ptr a -> IO a
peek Ptr WMHints
p; CInt
_ <- forall a. Ptr a -> IO CInt
xFree Ptr WMHints
p; forall (m :: * -> *) a. Monad m => a -> m a
return WMHints
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
    Ptr WMHints
p_wmh <- IO (Ptr WMHints)
xAllocWMHints
    forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr WMHints
p_wmh WMHints
wmh
    CInt
res <- Display -> XID -> Ptr WMHints -> IO CInt
xSetWMHints Display
dpy XID
w Ptr WMHints
p_wmh
    CInt
_ <- forall a. Ptr a -> IO CInt
xFree Ptr WMHints
p_wmh
    forall (m :: * -> *) a. Monad m => a -> m a
return CInt
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