{-# LINE 1 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Graphics.UI.Gtk.Gdk.Events (
Modifier(..),
TimeStamp,
currentTime,
Event(..),
EventButton,
EventScroll,
EventMotion,
EventExpose,
EventKey,
EventConfigure,
EventCrossing,
EventFocus,
EventProperty,
EventProximity,
EventVisibility,
EventWindowState,
EventGrabBroken,
marshExposeRect,
marshalEvent,
VisibilityState(..),
CrossingMode(..),
NotifyType(..),
WindowState(..),
ScrollDirection(..),
MouseButton(..),
Click(..),
Rectangle(..)
) where
import System.IO.Unsafe (unsafeInterleaveIO)
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Flags
import Graphics.UI.Gtk.Gdk.Keys (KeyVal, keyvalToChar, keyvalName)
{-# LINE 77 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
import Graphics.UI.Gtk.Gdk.Enums (Modifier(..),
VisibilityState(..),
CrossingMode(..),
NotifyType(..),
WindowState(..),
ScrollDirection(..))
import Graphics.UI.Gtk.General.Enums (MouseButton(..), Click(..))
import Graphics.UI.Gtk.General.Structs (Rectangle(..))
type TimeStamp = Word32
currentTime :: TimeStamp
currentTime = 0
{-# LINE 95 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
type EventButton = Event
type EventScroll = Event
type EventMotion = Event
type EventExpose = Event
type EventKey = Event
type EventConfigure = Event
type EventCrossing = Event
type EventFocus = Event
type EventProperty = Event
type EventProximity = Event
type EventVisibility = Event
type EventWindowState = Event
type EventGrabBroken = Event
data Event =
Event { eventSent :: Bool }
| Expose {
eventSent :: Bool,
eventArea :: Rectangle,
{-# LINE 204 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
eventCount :: Int }
| Motion {
eventSent :: Bool,
eventTime :: TimeStamp,
eventX,eventY :: Double,
eventModifier :: [Modifier],
eventIsHint :: Bool,
eventXRoot,
eventYRoot :: Double }
| Button {
eventSent :: Bool,
eventClick :: Click,
eventTime :: TimeStamp,
eventX,eventY :: Double,
eventModifier :: [Modifier],
eventButton :: MouseButton,
eventXRoot,
eventYRoot :: Double }
| Key {
eventRelease :: Bool,
eventSent :: Bool,
eventTime :: TimeStamp,
eventModifier :: [Modifier],
eventWithCapsLock :: Bool,
eventWithNumLock :: Bool,
eventWithScrollLock :: Bool,
eventKeyVal :: KeyVal,
eventKeyName :: DefaultGlibString,
eventKeyChar :: Maybe Char }
| Crossing {
eventSent :: Bool,
eventTime :: TimeStamp,
eventX,eventY :: Double,
eventXRoot,
eventYRoot :: Double,
eventLeaves :: Bool,
eventCrossingMode :: CrossingMode,
eventNotifyType :: NotifyType,
eventModifier :: [Modifier]}
| Focus {
eventSent :: Bool,
eventInFocus :: Bool}
| Configure {
eventSent :: Bool,
eventXParent :: Int,
eventYParent :: Int,
eventWidth :: Int,
eventHeight :: Int}
| Visibility {
eventSent :: Bool,
eventVisible :: VisibilityState }
| Scroll {
eventSent :: Bool,
eventTime :: TimeStamp,
eventX,eventY :: Double,
eventDirection :: ScrollDirection,
eventXRoot,
eventYRoot :: Double}
| WindowState {
eventSent :: Bool,
eventWindowMask :: [WindowState],
eventWindowState :: [WindowState]}
| Proximity {
eventSent :: Bool,
eventTime :: TimeStamp,
eventInContact :: Bool
} deriving Show
marshalEvent :: Ptr Event -> IO Event
marshalEvent ptr = do
(eType::Int32) <- (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 391 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(case eType of
0 -> marshAny
{-# LINE 393 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
1 -> marshAny
{-# LINE 394 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
2 -> marshExpose
{-# LINE 395 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
3 -> marshMotion
{-# LINE 396 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
4 -> marshButton SingleClick
{-# LINE 397 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
5 -> marshButton DoubleClick
{-# LINE 398 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
6 -> marshButton TripleClick
{-# LINE 399 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
7 -> marshButton ReleaseClick
{-# LINE 400 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
8 -> marshKey False
{-# LINE 401 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
9 -> marshKey True
{-# LINE 402 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
10 -> marshCrossing False
{-# LINE 403 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
11 -> marshCrossing True
{-# LINE 404 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
12 -> marshFocus
{-# LINE 405 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
13 -> marshConfigure
{-# LINE 406 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
14 -> marshAny
{-# LINE 407 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
15 -> marshAny
{-# LINE 408 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
20 -> marshProximity True
{-# LINE 410 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
21 -> marshProximity False
{-# LINE 411 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
29-> marshVisibility
{-# LINE 412 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
31 -> marshScroll
{-# LINE 413 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
32 -> marshWindowState
{-# LINE 414 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
code -> \_ -> fail $
"marshalEvent: unhandled event type " ++ show code ++
"\nplease report this as a bug to gtk2hs-devel@lists.sourceforge.net"
) ptr
marshAny ptr = do
(sent ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 421 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return Event {
eventSent = toBool sent
}
marshExpose ptr = do
(2::Int32) <- (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 427 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 428 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(area_ ::Rectangle) <- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 429 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
{-# LINE 434 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(count_ ::Int32) <- (\hsc_ptr -> peekByteOff hsc_ptr 48) ptr
{-# LINE 435 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ Expose {
eventSent = toBool sent_,
eventArea = area_,
{-# LINE 441 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
eventCount = fromIntegral count_}
{-# LINE 447 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
marshExposeRect :: Ptr Event -> IO Rectangle
marshExposeRect ptr = do
(2::Int32) <- (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 451 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(area_ ::Rectangle) <- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 452 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return area_
marshMotion ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 456 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(time_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 457 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(x_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 458 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(y_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 459 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(modif_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 48) ptr
{-# LINE 460 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(isHint_ ::Int16) <- (\hsc_ptr -> peekByteOff hsc_ptr 52) ptr
{-# LINE 461 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(xRoot_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 64) ptr
{-# LINE 462 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(yRoot_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 72) ptr
{-# LINE 463 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ Motion {
eventSent = toBool sent_,
eventTime = fromIntegral time_,
eventX = realToFrac x_,
eventY = realToFrac y_,
eventModifier = (toFlags . fromIntegral) modif_,
eventIsHint = toBool isHint_,
eventXRoot = realToFrac xRoot_,
eventYRoot = realToFrac yRoot_}
marshButton but ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 475 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(time_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 476 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(x_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 477 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(y_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 478 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(modif_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 48) ptr
{-# LINE 479 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(button_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 52) ptr
{-# LINE 480 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(xRoot_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 64) ptr
{-# LINE 481 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(yRoot_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 72) ptr
{-# LINE 482 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ Button {
eventClick = but,
eventSent = toBool sent_,
eventTime = fromIntegral time_,
eventX = realToFrac x_,
eventY = realToFrac y_,
eventModifier = (toFlags . fromIntegral) modif_,
eventButton = (toEnum.fromIntegral) button_,
eventXRoot = realToFrac xRoot_,
eventYRoot = realToFrac yRoot_}
marshKey up ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 496 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(time_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 497 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(modif_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 498 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(keyval_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 28) ptr
{-# LINE 499 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(length_ ::Int32) <- (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 501 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
keyChar <- keyvalToChar keyval_
keyName <- unsafeInterleaveIO $ keyvalName keyval_
return $ Key {
eventRelease = up,
eventSent = toBool sent_,
eventTime = fromIntegral time_,
eventModifier = (toFlags . fromIntegral) modif_,
eventWithCapsLock = (modif_ .&. 2)/=0,
{-# LINE 509 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
eventWithNumLock = (modif_ .&. 16)/=0,
{-# LINE 510 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
eventWithScrollLock = (modif_ .&. 32)/=0,
{-# LINE 511 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
eventKeyVal = keyval_,
eventKeyName = keyName,
eventKeyChar = keyChar }
marshCrossing leave ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 517 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(time_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 518 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(x_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 40) ptr
{-# LINE 519 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(y_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 48) ptr
{-# LINE 520 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(modif_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 84) ptr
{-# LINE 521 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(xRoot_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 56) ptr
{-# LINE 522 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(yRoot_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 64) ptr
{-# LINE 523 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(cMode_ ::Word32)
{-# LINE 524 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
<- (\hsc_ptr -> peekByteOff hsc_ptr 72) ptr
{-# LINE 525 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(nType_ ::Word32)
{-# LINE 526 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
<- (\hsc_ptr -> peekByteOff hsc_ptr 76) ptr
{-# LINE 527 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(modif_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 84) ptr
{-# LINE 528 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ Crossing {
eventSent = toBool sent_,
eventTime = fromIntegral time_,
eventX = realToFrac x_,
eventY = realToFrac y_,
eventXRoot = realToFrac xRoot_,
eventYRoot = realToFrac yRoot_,
eventLeaves = leave,
eventCrossingMode = (toEnum.fromIntegral) cMode_,
eventNotifyType = (toEnum.fromIntegral) nType_,
eventModifier = (toFlags . fromIntegral) modif_}
marshFocus ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 543 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(inFocus_::Int16) <- (\hsc_ptr -> peekByteOff hsc_ptr 18) ptr
{-# LINE 544 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ Focus {
eventSent = toBool sent_,
eventInFocus= toBool inFocus_}
marshConfigure ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 550 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(xPar_ ::Int32) <- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 551 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(yPar_ ::Int32) <- (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 552 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(width_ ::Int32) <- (\hsc_ptr -> peekByteOff hsc_ptr 28) ptr
{-# LINE 553 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(height_ ::Int32) <- (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 554 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ Configure {
eventSent = toBool sent_,
eventXParent = fromIntegral xPar_,
eventYParent = fromIntegral yPar_,
eventWidth = fromIntegral width_,
eventHeight = fromIntegral height_}
marshProximity contact ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 572 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(time_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 573 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ Proximity {
eventSent = toBool sent_,
eventTime = fromIntegral time_,
eventInContact = contact}
marshVisibility ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 580 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(state_ ::Word32)
{-# LINE 581 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
<- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 582 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ Visibility {
eventSent = toBool sent_,
eventVisible= (toEnum.fromIntegral) state_}
marshScroll ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 588 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(time_ ::Word32) <- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 589 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(x_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 590 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(y_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 591 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(direc_ ::Word32)
{-# LINE 592 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
<- (\hsc_ptr -> peekByteOff hsc_ptr 44) ptr
{-# LINE 593 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(xRoot_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 56) ptr
{-# LINE 594 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(yRoot_ ::Double) <- (\hsc_ptr -> peekByteOff hsc_ptr 64) ptr
{-# LINE 595 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ Scroll {
eventSent = toBool sent_,
eventTime = fromIntegral time_,
eventX = realToFrac x_,
eventY = realToFrac y_,
eventDirection = (toEnum.fromIntegral) direc_,
eventXRoot = realToFrac xRoot_,
eventYRoot = realToFrac yRoot_}
marshWindowState ptr = do
(sent_ ::Int8) <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 607 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(wMask_ ::Word32)
{-# LINE 608 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
<- (\hsc_ptr -> peekByteOff hsc_ptr 20) ptr
{-# LINE 609 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
(wState_ ::Word32)
{-# LINE 610 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
<- (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 611 "Graphics/UI/Gtk/Gdk/Events.hsc" #-}
return $ WindowState {
eventSent = toBool sent_,
eventWindowMask = (toFlags.fromIntegral) wMask_,
eventWindowState = (toFlags.fromIntegral) wState_}