{-# LINE 1 "Graphics/X11/XScreenSaver.hsc" #-}
{-# LANGUAGE DeriveDataTypeable, ForeignFunctionInterface #-}
module Graphics.X11.XScreenSaver (
getXIdleTime,
XScreenSaverState(..),
XScreenSaverKind(..),
XScreenSaverInfo(..),
XScreenSaverNotifyEvent,
xScreenSaverQueryExtension,
xScreenSaverQueryVersion,
xScreenSaverQueryInfo,
xScreenSaverSelectInput,
xScreenSaverSetAttributes,
xScreenSaverUnsetAttributes,
xScreenSaverSaverRegister,
xScreenSaverUnregister,
xScreenSaverGetRegistered,
xScreenSaverSuspend,
get_XScreenSaverNotifyEvent,
compiledWithXScreenSaver
) where
import Graphics.X11.Types
import Graphics.X11.Xlib.Types
import Foreign
import Foreign.C.Types
import Graphics.X11.Xlib
import Graphics.X11.Xlib.Internal
import Control.Monad
data XScreenSaverState
= ScreenSaverOff
| ScreenSaverOn
| ScreenSaverCycle
| ScreenSaverDisabled
deriving Show
data XScreenSaverKind
= ScreenSaverBlanked
| ScreenSaverInternal
| ScreenSaverExternal
deriving Show
data XScreenSaverInfo = XScreenSaverInfo
{ xssi_window :: !Window
, xssi_state :: !XScreenSaverState
, xssi_kind :: !XScreenSaverKind
, xssi_til_or_since :: !CULong
, xssi_idle :: !CULong
, xssi_event_mask :: !CULong
} deriving (Show)
getXIdleTime :: Display -> IO Int
getXIdleTime dpy =
maybe 0 (fromIntegral . xssi_idle) `fmap` xScreenSaverQueryInfo dpy
compiledWithXScreenSaver :: Bool
compiledWithXScreenSaver = True
{-# DEPRECATED compiledWithXScreenSaver "X11 now always compiles with XScreenSaver support" #-}
xScreenSaverState2CInt :: XScreenSaverState -> CInt
xScreenSaverState2CInt ScreenSaverOn = 1
{-# LINE 118 "Graphics/X11/XScreenSaver.hsc" #-}
xScreenSaverState2CInt ScreenSaverOff = 0
{-# LINE 119 "Graphics/X11/XScreenSaver.hsc" #-}
xScreenSaverState2CInt ScreenSaverCycle = 2
{-# LINE 120 "Graphics/X11/XScreenSaver.hsc" #-}
xScreenSaverState2CInt ScreenSaverDisabled = 3
{-# LINE 121 "Graphics/X11/XScreenSaver.hsc" #-}
cInt2XScreenSaverState :: CInt -> XScreenSaverState
cInt2XScreenSaverState (1) = ScreenSaverOn
{-# LINE 124 "Graphics/X11/XScreenSaver.hsc" #-}
cInt2XScreenSaverState (0) = ScreenSaverOff
{-# LINE 125 "Graphics/X11/XScreenSaver.hsc" #-}
cInt2XScreenSaverState (2) = ScreenSaverCycle
{-# LINE 126 "Graphics/X11/XScreenSaver.hsc" #-}
cInt2XScreenSaverState (3) = ScreenSaverDisabled
{-# LINE 127 "Graphics/X11/XScreenSaver.hsc" #-}
cInt2XScreenSaverState s = error $
"Unknown state in xScreenSaverQueryInfo for XScreenSaverState: " ++ show s
instance Storable XScreenSaverState where
sizeOf _ = sizeOf (undefined :: CInt)
alignment _ = alignment (undefined :: CInt)
poke p xsss = poke (castPtr p) (xScreenSaverState2CInt xsss)
peek p = cInt2XScreenSaverState `fmap` peek (castPtr p)
xScreenSaverKind2CInt :: XScreenSaverKind -> CInt
xScreenSaverKind2CInt ScreenSaverBlanked = 0
{-# LINE 139 "Graphics/X11/XScreenSaver.hsc" #-}
xScreenSaverKind2CInt ScreenSaverInternal = 1
{-# LINE 140 "Graphics/X11/XScreenSaver.hsc" #-}
xScreenSaverKind2CInt ScreenSaverExternal = 2
{-# LINE 141 "Graphics/X11/XScreenSaver.hsc" #-}
cInt2XScreenSaverKind :: CInt -> XScreenSaverKind
cInt2XScreenSaverKind (0) = ScreenSaverBlanked
{-# LINE 144 "Graphics/X11/XScreenSaver.hsc" #-}
cInt2XScreenSaverKind (1) = ScreenSaverInternal
{-# LINE 145 "Graphics/X11/XScreenSaver.hsc" #-}
cInt2XScreenSaverKind (2) = ScreenSaverExternal
{-# LINE 146 "Graphics/X11/XScreenSaver.hsc" #-}
cInt2XScreenSaverKind s = error $
"Unknown kind in xScreenSaverQueryInfo for XScreenSaverKind: " ++ show s
instance Storable XScreenSaverKind where
sizeOf _ = sizeOf (undefined :: CInt)
alignment _ = alignment (undefined :: CInt)
poke p xsss = poke (castPtr p) (xScreenSaverKind2CInt xsss)
peek p = cInt2XScreenSaverKind `fmap` peek (castPtr p)
instance Storable XScreenSaverInfo where
sizeOf _ = (40)
{-# LINE 158 "Graphics/X11/XScreenSaver.hsc" #-}
alignment _ = alignment (undefined :: CInt)
poke p xssi = do
(\hsc_ptr -> pokeByteOff hsc_ptr 0) p $ xssi_window xssi
{-# LINE 163 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 8) p $ xssi_state xssi
{-# LINE 164 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 12) p $ xssi_kind xssi
{-# LINE 165 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 16) p $ xssi_til_or_since xssi
{-# LINE 166 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 24) p $ xssi_idle xssi
{-# LINE 167 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 32) p $ xssi_event_mask xssi
{-# LINE 168 "Graphics/X11/XScreenSaver.hsc" #-}
peek p = return XScreenSaverInfo
`ap` ((\hsc_ptr -> peekByteOff hsc_ptr 0) p)
{-# LINE 171 "Graphics/X11/XScreenSaver.hsc" #-}
`ap` ((\hsc_ptr -> peekByteOff hsc_ptr 8) p)
{-# LINE 172 "Graphics/X11/XScreenSaver.hsc" #-}
`ap` ((\hsc_ptr -> peekByteOff hsc_ptr 12) p)
{-# LINE 173 "Graphics/X11/XScreenSaver.hsc" #-}
`ap` ((\hsc_ptr -> peekByteOff hsc_ptr 16) p)
{-# LINE 174 "Graphics/X11/XScreenSaver.hsc" #-}
`ap` ((\hsc_ptr -> peekByteOff hsc_ptr 24) p)
{-# LINE 175 "Graphics/X11/XScreenSaver.hsc" #-}
`ap` ((\hsc_ptr -> peekByteOff hsc_ptr 32) p)
{-# LINE 176 "Graphics/X11/XScreenSaver.hsc" #-}
type XScreenSaverNotifyEvent =
( Window
, Window
, CInt
, CInt
, Bool
, Time
)
pokeXScreenSaverNotifyEvent :: Ptr XScreenSaverNotifyEvent
-> XScreenSaverNotifyEvent -> IO ()
pokeXScreenSaverNotifyEvent p (window, root, state, kind, forced, time) = do
(\hsc_ptr -> pokeByteOff hsc_ptr 32) p window
{-# LINE 190 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 40) p root
{-# LINE 191 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 48) p state
{-# LINE 192 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 52) p kind
{-# LINE 193 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 56) p forced
{-# LINE 194 "Graphics/X11/XScreenSaver.hsc" #-}
(\hsc_ptr -> pokeByteOff hsc_ptr 64) p time
{-# LINE 195 "Graphics/X11/XScreenSaver.hsc" #-}
peekXScreenSaverNotifyEvent :: Ptr XScreenSaverNotifyEvent
-> IO XScreenSaverNotifyEvent
peekXScreenSaverNotifyEvent p = do
window <- ((\hsc_ptr -> peekByteOff hsc_ptr 32) p )
{-# LINE 200 "Graphics/X11/XScreenSaver.hsc" #-}
root <- ((\hsc_ptr -> peekByteOff hsc_ptr 40) p )
{-# LINE 201 "Graphics/X11/XScreenSaver.hsc" #-}
state <- ((\hsc_ptr -> peekByteOff hsc_ptr 48) p )
{-# LINE 202 "Graphics/X11/XScreenSaver.hsc" #-}
kind <- ((\hsc_ptr -> peekByteOff hsc_ptr 52) p )
{-# LINE 203 "Graphics/X11/XScreenSaver.hsc" #-}
forced <- ((\hsc_ptr -> peekByteOff hsc_ptr 56) p )
{-# LINE 204 "Graphics/X11/XScreenSaver.hsc" #-}
time <- ((\hsc_ptr -> peekByteOff hsc_ptr 64) p )
{-# LINE 205 "Graphics/X11/XScreenSaver.hsc" #-}
return (window, root, state, kind, forced, time)
get_XScreenSaverNotifyEvent :: XEventPtr -> IO XScreenSaverNotifyEvent
get_XScreenSaverNotifyEvent p = peekXScreenSaverNotifyEvent (castPtr p)
xScreenSaverQueryExtension :: Display -> IO (Maybe (CInt, CInt))
xScreenSaverQueryExtension dpy = wrapPtr2 (cXScreenSaverQueryExtension dpy) go
where go False _ _ = Nothing
go True eventbase errorbase = Just ( fromIntegral eventbase
, fromIntegral errorbase
)
xScreenSaverQueryVersion :: Display -> IO (Maybe (CInt, CInt))
xScreenSaverQueryVersion dpy = wrapPtr2 (cXScreenSaverQueryVersion dpy) go
where go False _ _ = Nothing
go True major minor = Just (fromIntegral major, fromIntegral minor)
wrapPtr2 :: (Storable a, Storable b)
=> (Ptr a -> Ptr b -> IO c) -> (c -> a -> b -> d) -> IO d
wrapPtr2 cfun f = withPool $ \pool -> do aptr <- pooledMalloc pool
bptr <- pooledMalloc pool
ret <- cfun aptr bptr
a <- peek aptr
b <- peek bptr
return (f ret a b)
xScreenSaverQueryInfo :: Display -> IO (Maybe XScreenSaverInfo)
xScreenSaverQueryInfo dpy = do
p <- cXScreenSaverAllocInfo
if p == nullPtr then return Nothing else do
s <- cXScreenSaverQueryInfo dpy (defaultRootWindow dpy) p
if s == 0 then return Nothing else do
xssi <- peek p
_ <- xFree p
return (Just xssi)
xScreenSaverSelectInput :: Display -> EventMask -> IO ()
xScreenSaverSelectInput dpy xssem = do
p <- cXScreenSaverAllocInfo
if p == nullPtr then return () else do
cXScreenSaverSelectInput dpy (defaultRootWindow dpy) xssem
xScreenSaverSetAttributes :: Display
-> Position
-> Position
-> Dimension
-> Dimension
-> Dimension
-> CInt
-> WindowClass
-> Visual
-> AttributeMask
-> Ptr SetWindowAttributes
-> IO ()
xScreenSaverSetAttributes dpy x y w h bw d wc v am pswa = do
cXScreenSaverSetAttributes dpy (defaultRootWindow dpy)
x y w h bw d wc v am pswa
xScreenSaverUnsetAttributes :: Display -> IO ()
xScreenSaverUnsetAttributes dpy =
cXScreenSaverUnsetAttributes dpy (defaultRootWindow dpy)
xScreenSaverSaverRegister :: Display -> ScreenNumber -> XID -> Atom -> IO ()
xScreenSaverSaverRegister = cXScreenSaverSaverRegister
xScreenSaverUnregister :: Display -> ScreenNumber -> IO Status
xScreenSaverUnregister = cXScreenSaverUnregister
xScreenSaverGetRegistered :: Display -> ScreenNumber -> XID -> Atom -> IO Status
xScreenSaverGetRegistered = cXScreenSaverGetRegistered
xScreenSaverSuspend :: Display -> Bool -> IO ()
xScreenSaverSuspend = cXScreenSaverSuspend
foreign import ccall "XScreenSaverQueryExtension"
cXScreenSaverQueryExtension :: Display -> Ptr CInt -> Ptr CInt -> IO Bool
foreign import ccall "XScreenSaverQueryVersion"
cXScreenSaverQueryVersion :: Display -> Ptr CInt -> Ptr CInt -> IO Bool
foreign import ccall "XScreenSaverAllocInfo"
cXScreenSaverAllocInfo :: IO (Ptr XScreenSaverInfo)
foreign import ccall "XScreenSaverQueryInfo"
cXScreenSaverQueryInfo :: Display -> Drawable -> Ptr XScreenSaverInfo
-> IO Status
foreign import ccall "XScreenSaverSelectInput"
cXScreenSaverSelectInput :: Display -> Drawable -> EventMask -> IO ()
foreign import ccall "XScreenSaverSetAttributes"
cXScreenSaverSetAttributes :: Display -> Drawable -> Position -> Position
-> Dimension -> Dimension -> Dimension
-> CInt
-> WindowClass
-> Visual
-> AttributeMask
-> Ptr SetWindowAttributes
-> IO ()
foreign import ccall "XScreenSaverUnsetAttributes"
cXScreenSaverUnsetAttributes :: Display -> Drawable -> IO ()
foreign import ccall "XScreenSaverRegister"
cXScreenSaverSaverRegister :: Display -> ScreenNumber -> XID -> Atom
-> IO ()
foreign import ccall "XScreenSaverUnregister"
cXScreenSaverUnregister :: Display -> ScreenNumber -> IO Status
foreign import ccall "XScreenSaverGetRegistered"
cXScreenSaverGetRegistered :: Display -> ScreenNumber -> XID -> Atom
-> IO Status
foreign import ccall "XScreenSaverSuspend"
cXScreenSaverSuspend :: Display -> Bool -> IO ()