{-# LINE 1 "Graphics/X11/XScreenSaver.hsc" #-}
{-# LANGUAGE DeriveDataTypeable, ForeignFunctionInterface #-}
--------------------------------------------------------------------
-- |
-- Module    : Graphics.X11.XScreenSaver
-- Copyright : (c) Joachim Breitner
--             (c) Jochen Keil
-- License   : BSD3
--
-- Maintainer: Joachim Breitner <mail@joachim-breitner.de>
-- Stability : provisional
-- Portability: portable
--
--------------------------------------------------------------------
--
-- Interface to XScreenSaver API
--

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

-- | XScreenSaverState is for use in both XScreenSaverNotifyEvent and
-- XScreenSaverInfo
-- ScreenSaverCycle is not a valid value for use in XScreenSaverInfo
-- ScreenSaverDisabled will not occur in an XScreenSaverNotifyEvent
data XScreenSaverState
    -- | The  screen is not currently being saved; til-or-since specifies the
    -- number of milliseconds until the screen saver is expected to activate.
    = ScreenSaverOff
    -- | The screen is currently being saved; til-or-since specifies the number
    -- of milliseconds since the screen saver activated.
    | ScreenSaverOn
    -- | If  this  bit  is  set,  ScreenSaverNotify events are generated
    -- whenever the screen saver cycle interval passes.
    | ScreenSaverCycle
    -- | The screen saver is currently disabled; til-or-since is zero.
    | ScreenSaverDisabled
    deriving Int -> XScreenSaverState -> ShowS
[XScreenSaverState] -> ShowS
XScreenSaverState -> String
(Int -> XScreenSaverState -> ShowS)
-> (XScreenSaverState -> String)
-> ([XScreenSaverState] -> ShowS)
-> Show XScreenSaverState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [XScreenSaverState] -> ShowS
$cshowList :: [XScreenSaverState] -> ShowS
show :: XScreenSaverState -> String
$cshow :: XScreenSaverState -> String
showsPrec :: Int -> XScreenSaverState -> ShowS
$cshowsPrec :: Int -> XScreenSaverState -> ShowS
Show

-- | Data type for use in a XScreenSaverInfo struct
data XScreenSaverKind
    -- | The video signal to the display monitor was disabled.
    = ScreenSaverBlanked
    -- | A server-dependent, built-in screen saver image was displayed; either
    -- no client had set the screen saver window attributes or a different
    -- client had the server grabbed when the screen saver activated.
    | ScreenSaverInternal
    -- | The screen saver window was mapped with attributes set by a client
    -- using the ScreenSaverSetAttributes request.
    | ScreenSaverExternal
    deriving Int -> XScreenSaverKind -> ShowS
[XScreenSaverKind] -> ShowS
XScreenSaverKind -> String
(Int -> XScreenSaverKind -> ShowS)
-> (XScreenSaverKind -> String)
-> ([XScreenSaverKind] -> ShowS)
-> Show XScreenSaverKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [XScreenSaverKind] -> ShowS
$cshowList :: [XScreenSaverKind] -> ShowS
show :: XScreenSaverKind -> String
$cshow :: XScreenSaverKind -> String
showsPrec :: Int -> XScreenSaverKind -> ShowS
$cshowsPrec :: Int -> XScreenSaverKind -> ShowS
Show

-- | Representation of the XScreenSaverInfo struct.
data XScreenSaverInfo = XScreenSaverInfo
    { XScreenSaverInfo -> Window
xssi_window        :: !Window
        -- | The state field specified whether or not the screen saver is
        -- currently active and how the til-or-since value should be interpreted
    , XScreenSaverInfo -> XScreenSaverState
xssi_state         :: !XScreenSaverState
        -- | The kind field specifies the mechanism that either is currently
        -- being used or would have been were the screen being saved
    , XScreenSaverInfo -> XScreenSaverKind
xssi_kind          :: !XScreenSaverKind
    , XScreenSaverInfo -> CULong
xssi_til_or_since  :: !CULong
        -- | The idle field specifies the number of milliseconds since the last
        -- input was received from the user on any of the input devices.
    , XScreenSaverInfo -> CULong
xssi_idle          :: !CULong
        -- | The event-mask field specifies which, if any, screen saver events
        -- this client has requested using ScreenSaverSelectInput.
    , XScreenSaverInfo -> CULong
xssi_event_mask    :: !CULong
    } deriving (Int -> XScreenSaverInfo -> ShowS
[XScreenSaverInfo] -> ShowS
XScreenSaverInfo -> String
(Int -> XScreenSaverInfo -> ShowS)
-> (XScreenSaverInfo -> String)
-> ([XScreenSaverInfo] -> ShowS)
-> Show XScreenSaverInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [XScreenSaverInfo] -> ShowS
$cshowList :: [XScreenSaverInfo] -> ShowS
show :: XScreenSaverInfo -> String
$cshow :: XScreenSaverInfo -> String
showsPrec :: Int -> XScreenSaverInfo -> ShowS
$cshowsPrec :: Int -> XScreenSaverInfo -> ShowS
Show)


-- | Simple wrapper around 'xScreenSaverQueryInfo' if you are only interested in
-- the idle time, in milliseconds. Returns 0 if the XScreenSaver extension is
-- not available
getXIdleTime :: Display -> IO Int
getXIdleTime :: Display -> IO Int
getXIdleTime Display
dpy =
    Int -> (XScreenSaverInfo -> Int) -> Maybe XScreenSaverInfo -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 (CULong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CULong -> Int)
-> (XScreenSaverInfo -> CULong) -> XScreenSaverInfo -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XScreenSaverInfo -> CULong
xssi_idle) (Maybe XScreenSaverInfo -> Int)
-> IO (Maybe XScreenSaverInfo) -> IO Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Display -> IO (Maybe XScreenSaverInfo)
xScreenSaverQueryInfo Display
dpy

-- | We have XScreenSaver, so the library will actually work
compiledWithXScreenSaver :: Bool
compiledWithXScreenSaver :: Bool
compiledWithXScreenSaver = Bool
True
{-# DEPRECATED compiledWithXScreenSaver "X11 now always compiles with XScreenSaver support" #-}


-- for XFree() (already included from scrnsaver.h, but I don't know if I can
-- count on that.)



xScreenSaverState2CInt :: XScreenSaverState -> CInt
xScreenSaverState2CInt :: XScreenSaverState -> CInt
xScreenSaverState2CInt XScreenSaverState
ScreenSaverOn = CInt
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 :: CInt -> XScreenSaverState
cInt2XScreenSaverState (CInt
1) = XScreenSaverState
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 :: XScreenSaverState -> Int
sizeOf    XScreenSaverState
_ = CInt -> Int
forall a. Storable a => a -> Int
sizeOf (CInt
forall a. HasCallStack => a
undefined :: CInt)
    alignment :: XScreenSaverState -> Int
alignment XScreenSaverState
_ = CInt -> Int
forall a. Storable a => a -> Int
alignment (CInt
forall a. HasCallStack => a
undefined :: CInt)
    poke :: Ptr XScreenSaverState -> XScreenSaverState -> IO ()
poke Ptr XScreenSaverState
p XScreenSaverState
xsss = Ptr CInt -> CInt -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr XScreenSaverState -> Ptr CInt
forall a b. Ptr a -> Ptr b
castPtr Ptr XScreenSaverState
p) (XScreenSaverState -> CInt
xScreenSaverState2CInt XScreenSaverState
xsss)
    peek :: Ptr XScreenSaverState -> IO XScreenSaverState
peek Ptr XScreenSaverState
p = CInt -> XScreenSaverState
cInt2XScreenSaverState (CInt -> XScreenSaverState) -> IO CInt -> IO XScreenSaverState
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek (Ptr XScreenSaverState -> Ptr CInt
forall a b. Ptr a -> Ptr b
castPtr Ptr XScreenSaverState
p)


xScreenSaverKind2CInt :: XScreenSaverKind -> CInt
xScreenSaverKind2CInt :: XScreenSaverKind -> CInt
xScreenSaverKind2CInt XScreenSaverKind
ScreenSaverBlanked = CInt
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 :: CInt -> XScreenSaverKind
cInt2XScreenSaverKind (CInt
0) = XScreenSaverKind
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 :: XScreenSaverKind -> Int
sizeOf    XScreenSaverKind
_ = CInt -> Int
forall a. Storable a => a -> Int
sizeOf (CInt
forall a. HasCallStack => a
undefined :: CInt)
    alignment :: XScreenSaverKind -> Int
alignment XScreenSaverKind
_ = CInt -> Int
forall a. Storable a => a -> Int
alignment (CInt
forall a. HasCallStack => a
undefined :: CInt)
    poke :: Ptr XScreenSaverKind -> XScreenSaverKind -> IO ()
poke Ptr XScreenSaverKind
p XScreenSaverKind
xsss = Ptr CInt -> CInt -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr XScreenSaverKind -> Ptr CInt
forall a b. Ptr a -> Ptr b
castPtr Ptr XScreenSaverKind
p) (XScreenSaverKind -> CInt
xScreenSaverKind2CInt XScreenSaverKind
xsss)
    peek :: Ptr XScreenSaverKind -> IO XScreenSaverKind
peek Ptr XScreenSaverKind
p = CInt -> XScreenSaverKind
cInt2XScreenSaverKind (CInt -> XScreenSaverKind) -> IO CInt -> IO XScreenSaverKind
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Ptr CInt -> IO CInt
forall a. Storable a => Ptr a -> IO a
peek (Ptr XScreenSaverKind -> Ptr CInt
forall a b. Ptr a -> Ptr b
castPtr Ptr XScreenSaverKind
p)


instance Storable XScreenSaverInfo where
    sizeOf :: XScreenSaverInfo -> Int
sizeOf XScreenSaverInfo
_ = (Int
40)
{-# LINE 158 "Graphics/X11/XScreenSaver.hsc" #-}
    -- FIXME: Is this right?
    alignment :: XScreenSaverInfo -> Int
alignment XScreenSaverInfo
_ = CInt -> Int
forall a. Storable a => a -> Int
alignment (CInt
forall a. HasCallStack => a
undefined :: CInt)

    poke :: Ptr XScreenSaverInfo -> XScreenSaverInfo -> IO ()
poke Ptr XScreenSaverInfo
p XScreenSaverInfo
xssi = do
        (\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> Window -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverInfo
hsc_ptr Int
0) Ptr XScreenSaverInfo
p (Window -> IO ()) -> Window -> IO ()
forall a b. (a -> b) -> a -> b
$ XScreenSaverInfo -> Window
xssi_window XScreenSaverInfo
xssi
{-# LINE 163 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> XScreenSaverState -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverInfo
hsc_ptr Int
8) Ptr XScreenSaverInfo
p (XScreenSaverState -> IO ()) -> XScreenSaverState -> IO ()
forall a b. (a -> b) -> a -> b
$ XScreenSaverInfo -> XScreenSaverState
xssi_state XScreenSaverInfo
xssi
{-# LINE 164 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> XScreenSaverKind -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverInfo
hsc_ptr Int
12) Ptr XScreenSaverInfo
p (XScreenSaverKind -> IO ()) -> XScreenSaverKind -> IO ()
forall a b. (a -> b) -> a -> b
$ XScreenSaverInfo -> XScreenSaverKind
xssi_kind XScreenSaverInfo
xssi
{-# LINE 165 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> CULong -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverInfo
hsc_ptr Int
16) Ptr XScreenSaverInfo
p (CULong -> IO ()) -> CULong -> IO ()
forall a b. (a -> b) -> a -> b
$ XScreenSaverInfo -> CULong
xssi_til_or_since XScreenSaverInfo
xssi
{-# LINE 166 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> CULong -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverInfo
hsc_ptr Int
24) Ptr XScreenSaverInfo
p (CULong -> IO ()) -> CULong -> IO ()
forall a b. (a -> b) -> a -> b
$ XScreenSaverInfo -> CULong
xssi_idle XScreenSaverInfo
xssi
{-# LINE 167 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> CULong -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverInfo
hsc_ptr Int
32) Ptr XScreenSaverInfo
p (CULong -> IO ()) -> CULong -> IO ()
forall a b. (a -> b) -> a -> b
$ XScreenSaverInfo -> CULong
xssi_event_mask XScreenSaverInfo
xssi
{-# LINE 168 "Graphics/X11/XScreenSaver.hsc" #-}

    peek :: Ptr XScreenSaverInfo -> IO XScreenSaverInfo
peek Ptr XScreenSaverInfo
p = (Window
 -> XScreenSaverState
 -> XScreenSaverKind
 -> CULong
 -> CULong
 -> CULong
 -> XScreenSaverInfo)
-> IO
     (Window
      -> XScreenSaverState
      -> XScreenSaverKind
      -> CULong
      -> CULong
      -> CULong
      -> XScreenSaverInfo)
forall (m :: * -> *) a. Monad m => a -> m a
return Window
-> XScreenSaverState
-> XScreenSaverKind
-> CULong
-> CULong
-> CULong
-> XScreenSaverInfo
XScreenSaverInfo
                IO
  (Window
   -> XScreenSaverState
   -> XScreenSaverKind
   -> CULong
   -> CULong
   -> CULong
   -> XScreenSaverInfo)
-> IO Window
-> IO
     (XScreenSaverState
      -> XScreenSaverKind
      -> CULong
      -> CULong
      -> CULong
      -> XScreenSaverInfo)
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> IO Window
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverInfo
hsc_ptr Int
0) Ptr XScreenSaverInfo
p)
{-# LINE 171 "Graphics/X11/XScreenSaver.hsc" #-}
                IO
  (XScreenSaverState
   -> XScreenSaverKind
   -> CULong
   -> CULong
   -> CULong
   -> XScreenSaverInfo)
-> IO XScreenSaverState
-> IO
     (XScreenSaverKind
      -> CULong -> CULong -> CULong -> XScreenSaverInfo)
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> IO XScreenSaverState
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverInfo
hsc_ptr Int
8) Ptr XScreenSaverInfo
p)
{-# LINE 172 "Graphics/X11/XScreenSaver.hsc" #-}
                IO
  (XScreenSaverKind
   -> CULong -> CULong -> CULong -> XScreenSaverInfo)
-> IO XScreenSaverKind
-> IO (CULong -> CULong -> CULong -> XScreenSaverInfo)
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> IO XScreenSaverKind
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverInfo
hsc_ptr Int
12) Ptr XScreenSaverInfo
p)
{-# LINE 173 "Graphics/X11/XScreenSaver.hsc" #-}
                IO (CULong -> CULong -> CULong -> XScreenSaverInfo)
-> IO CULong -> IO (CULong -> CULong -> XScreenSaverInfo)
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> IO CULong
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverInfo
hsc_ptr Int
16) Ptr XScreenSaverInfo
p)
{-# LINE 174 "Graphics/X11/XScreenSaver.hsc" #-}
                IO (CULong -> CULong -> XScreenSaverInfo)
-> IO CULong -> IO (CULong -> XScreenSaverInfo)
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> IO CULong
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverInfo
hsc_ptr Int
24) Ptr XScreenSaverInfo
p)
{-# LINE 175 "Graphics/X11/XScreenSaver.hsc" #-}
                IO (CULong -> XScreenSaverInfo) -> IO CULong -> IO XScreenSaverInfo
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
`ap` ((\Ptr XScreenSaverInfo
hsc_ptr -> Ptr XScreenSaverInfo -> Int -> IO CULong
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverInfo
hsc_ptr Int
32) Ptr XScreenSaverInfo
p)
{-# LINE 176 "Graphics/X11/XScreenSaver.hsc" #-}

type XScreenSaverNotifyEvent =
    ( Window      -- screen saver window
    , Window      -- root window of event screen
    , CInt        -- State: ScreenSaver{Off,On,Cycle}
    , CInt        -- Kind:  ScreenSaver{Blanked,Internal,External}
    , Bool        -- extents of new region
    , Time        -- event timestamp
    )

pokeXScreenSaverNotifyEvent :: Ptr XScreenSaverNotifyEvent
                            -> XScreenSaverNotifyEvent -> IO ()
pokeXScreenSaverNotifyEvent :: Ptr XScreenSaverNotifyEvent -> XScreenSaverNotifyEvent -> IO ()
pokeXScreenSaverNotifyEvent Ptr XScreenSaverNotifyEvent
p (Window
window, Window
root, CInt
state, CInt
kind, Bool
forced, Window
time) = do
        (\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> Window -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
32) Ptr XScreenSaverNotifyEvent
p Window
window
{-# LINE 190 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> Window -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
40) Ptr XScreenSaverNotifyEvent
p Window
root
{-# LINE 191 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> CInt -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
48) Ptr XScreenSaverNotifyEvent
p CInt
state
{-# LINE 192 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> CInt -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
52) Ptr XScreenSaverNotifyEvent
p CInt
kind
{-# LINE 193 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> Bool -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
56) Ptr XScreenSaverNotifyEvent
p Bool
forced
{-# LINE 194 "Graphics/X11/XScreenSaver.hsc" #-}
        (\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> Window -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
64) Ptr XScreenSaverNotifyEvent
p Window
time
{-# LINE 195 "Graphics/X11/XScreenSaver.hsc" #-}

peekXScreenSaverNotifyEvent :: Ptr XScreenSaverNotifyEvent
                            -> IO XScreenSaverNotifyEvent
peekXScreenSaverNotifyEvent :: Ptr XScreenSaverNotifyEvent -> IO XScreenSaverNotifyEvent
peekXScreenSaverNotifyEvent Ptr XScreenSaverNotifyEvent
p = do
        Window
window <- ((\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> IO Window
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
32) Ptr XScreenSaverNotifyEvent
p )
{-# LINE 200 "Graphics/X11/XScreenSaver.hsc" #-}
        Window
root   <- ((\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> IO Window
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
40) Ptr XScreenSaverNotifyEvent
p )
{-# LINE 201 "Graphics/X11/XScreenSaver.hsc" #-}
        CInt
state  <- ((\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> IO CInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
48) Ptr XScreenSaverNotifyEvent
p )
{-# LINE 202 "Graphics/X11/XScreenSaver.hsc" #-}
        CInt
kind   <- ((\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> IO CInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
52) Ptr XScreenSaverNotifyEvent
p )
{-# LINE 203 "Graphics/X11/XScreenSaver.hsc" #-}
        Bool
forced <- ((\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> IO Bool
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
56) Ptr XScreenSaverNotifyEvent
p )
{-# LINE 204 "Graphics/X11/XScreenSaver.hsc" #-}
        Window
time   <- ((\Ptr XScreenSaverNotifyEvent
hsc_ptr -> Ptr XScreenSaverNotifyEvent -> Int -> IO Window
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr XScreenSaverNotifyEvent
hsc_ptr Int
64) Ptr XScreenSaverNotifyEvent
p )
{-# LINE 205 "Graphics/X11/XScreenSaver.hsc" #-}
        XScreenSaverNotifyEvent -> IO XScreenSaverNotifyEvent
forall (m :: * -> *) a. Monad m => a -> m a
return (Window
window, Window
root, CInt
state, CInt
kind, Bool
forced, Window
time)

get_XScreenSaverNotifyEvent :: XEventPtr -> IO XScreenSaverNotifyEvent
get_XScreenSaverNotifyEvent :: XEventPtr -> IO XScreenSaverNotifyEvent
get_XScreenSaverNotifyEvent XEventPtr
p = Ptr XScreenSaverNotifyEvent -> IO XScreenSaverNotifyEvent
peekXScreenSaverNotifyEvent (XEventPtr -> Ptr XScreenSaverNotifyEvent
forall a b. Ptr a -> Ptr b
castPtr XEventPtr
p)

xScreenSaverQueryExtension :: Display -> IO (Maybe (CInt, CInt))
xScreenSaverQueryExtension :: Display -> IO (Maybe (CInt, CInt))
xScreenSaverQueryExtension Display
dpy = (Ptr CInt -> Ptr CInt -> IO Bool)
-> (Bool -> CInt -> CInt -> Maybe (CInt, CInt))
-> IO (Maybe (CInt, CInt))
forall a b c d.
(Storable a, Storable b) =>
(Ptr a -> Ptr b -> IO c) -> (c -> a -> b -> d) -> IO d
wrapPtr2 (Display -> Ptr CInt -> Ptr CInt -> IO Bool
cXScreenSaverQueryExtension Display
dpy) Bool -> CInt -> CInt -> Maybe (CInt, CInt)
forall a a a b.
(Integral a, Integral a, Num a, Num b) =>
Bool -> a -> a -> Maybe (a, b)
go
    where go :: Bool -> a -> a -> Maybe (a, b)
go Bool
False a
_ a
_                = Maybe (a, b)
forall a. Maybe a
Nothing
          go Bool
True a
eventbase a
errorbase = (a, b) -> Maybe (a, b)
forall a. a -> Maybe a
Just ( a -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
eventbase
                                             , a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
errorbase
                                             )

xScreenSaverQueryVersion :: Display -> IO (Maybe (CInt, CInt))
xScreenSaverQueryVersion :: Display -> IO (Maybe (CInt, CInt))
xScreenSaverQueryVersion Display
dpy = (Ptr CInt -> Ptr CInt -> IO Bool)
-> (Bool -> CInt -> CInt -> Maybe (CInt, CInt))
-> IO (Maybe (CInt, CInt))
forall a b c d.
(Storable a, Storable b) =>
(Ptr a -> Ptr b -> IO c) -> (c -> a -> b -> d) -> IO d
wrapPtr2 (Display -> Ptr CInt -> Ptr CInt -> IO Bool
cXScreenSaverQueryVersion Display
dpy) Bool -> CInt -> CInt -> Maybe (CInt, CInt)
forall a a a b.
(Integral a, Integral a, Num a, Num b) =>
Bool -> a -> a -> Maybe (a, b)
go
    where go :: Bool -> a -> a -> Maybe (a, b)
go Bool
False a
_ a
_        = Maybe (a, b)
forall a. Maybe a
Nothing
          go Bool
True a
major a
minor = (a, b) -> Maybe (a, b)
forall a. a -> Maybe a
Just (a -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
major, a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
minor)

wrapPtr2 :: (Storable a, Storable b)
         => (Ptr a -> Ptr b -> IO c) -> (c -> a -> b -> d) -> IO d
wrapPtr2 :: (Ptr a -> Ptr b -> IO c) -> (c -> a -> b -> d) -> IO d
wrapPtr2 Ptr a -> Ptr b -> IO c
cfun c -> a -> b -> d
f = (Pool -> IO d) -> IO d
forall b. (Pool -> IO b) -> IO b
withPool ((Pool -> IO d) -> IO d) -> (Pool -> IO d) -> IO d
forall a b. (a -> b) -> a -> b
$ \Pool
pool -> do Ptr a
aptr <- Pool -> IO (Ptr a)
forall a. Storable a => Pool -> IO (Ptr a)
pooledMalloc Pool
pool
                                         Ptr b
bptr <- Pool -> IO (Ptr b)
forall a. Storable a => Pool -> IO (Ptr a)
pooledMalloc Pool
pool
                                         c
ret <- Ptr a -> Ptr b -> IO c
cfun Ptr a
aptr Ptr b
bptr
                                         a
a <- Ptr a -> IO a
forall a. Storable a => Ptr a -> IO a
peek Ptr a
aptr
                                         b
b <- Ptr b -> IO b
forall a. Storable a => Ptr a -> IO a
peek Ptr b
bptr
                                         d -> IO d
forall (m :: * -> *) a. Monad m => a -> m a
return (c -> a -> b -> d
f c
ret a
a b
b)

-- | xScreenSaverQueryInfo returns information about the current state of the
-- screen server. If the xScreenSaver extension is not available, it returns
-- Nothing
xScreenSaverQueryInfo :: Display -> IO (Maybe XScreenSaverInfo)
xScreenSaverQueryInfo :: Display -> IO (Maybe XScreenSaverInfo)
xScreenSaverQueryInfo Display
dpy = do
    Ptr XScreenSaverInfo
p <- IO (Ptr XScreenSaverInfo)
cXScreenSaverAllocInfo
    if Ptr XScreenSaverInfo
p Ptr XScreenSaverInfo -> Ptr XScreenSaverInfo -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr XScreenSaverInfo
forall a. Ptr a
nullPtr then Maybe XScreenSaverInfo -> IO (Maybe XScreenSaverInfo)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe XScreenSaverInfo
forall a. Maybe a
Nothing else do
    CInt
s <- Display -> Window -> Ptr XScreenSaverInfo -> IO CInt
cXScreenSaverQueryInfo Display
dpy (Display -> Window
defaultRootWindow Display
dpy) Ptr XScreenSaverInfo
p
    if CInt
s CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
0 then Maybe XScreenSaverInfo -> IO (Maybe XScreenSaverInfo)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe XScreenSaverInfo
forall a. Maybe a
Nothing else do
    XScreenSaverInfo
xssi <- Ptr XScreenSaverInfo -> IO XScreenSaverInfo
forall a. Storable a => Ptr a -> IO a
peek Ptr XScreenSaverInfo
p
    CInt
_ <- Ptr XScreenSaverInfo -> IO CInt
forall a. Ptr a -> IO CInt
xFree Ptr XScreenSaverInfo
p
    Maybe XScreenSaverInfo -> IO (Maybe XScreenSaverInfo)
forall (m :: * -> *) a. Monad m => a -> m a
return (XScreenSaverInfo -> Maybe XScreenSaverInfo
forall a. a -> Maybe a
Just XScreenSaverInfo
xssi)

-- | xScreenSaverSelectInput asks that events related to the screen saver be
-- generated for this client.  If no bits are set in event-mask,  then no events
-- will be generated.
xScreenSaverSelectInput :: Display -> EventMask -> IO ()
xScreenSaverSelectInput :: Display -> Window -> IO ()
xScreenSaverSelectInput Display
dpy Window
xssem = do
    Ptr XScreenSaverInfo
p <- IO (Ptr XScreenSaverInfo)
cXScreenSaverAllocInfo
    if Ptr XScreenSaverInfo
p Ptr XScreenSaverInfo -> Ptr XScreenSaverInfo -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr XScreenSaverInfo
forall a. Ptr a
nullPtr then () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return () else do
    Display -> Window -> Window -> IO ()
cXScreenSaverSelectInput Display
dpy (Display -> Window
defaultRootWindow Display
dpy) Window
xssem

-- | XScreenSaverSetAttributes sets the attributes to be used the next  time
-- the  external  screen  saver is activated.  If another client currently
-- has the attributes set, a BadAccess error is generated and the  request
-- is ignored.
--
-- Otherwise,  the specified window attributes are checked as if they were
-- used in a core CreateWindow request whose  parent  is  the  root.   The
-- override-redirect field is ignored as it is implicitly set to True.  If
-- the window attributes result in an error according  to  the  rules  for
-- CreateWindow, the request is ignored.
--
-- Otherwise,  the  attributes are stored and will take effect on the next
-- activation that occurs when  the  server  is  not  grabbed  by  another
-- client.   Any  resources  specified for the background-pixmap or cursor
-- attributes may be freed immediately.  The server is free  to  copy  the
-- background-pixmap  or  cursor resources or to use them in place; therefore,
-- the effect of changing the contents of those resources  is  undefined.
-- If  the  specified  colormap  no longer exists when the screen
-- saver activates, the parent's colormap is used instead.  If  no  errors
-- are  generated  by  this  request,  any  previous  screen  saver window
-- attributes set by this client are released.
--
-- When the screen saver next activates and the server is not  grabbed  by
-- another  client,  the screen saver window is created, if necessary, and
-- set to the specified attributes and events are generated as usual.  The
-- colormap   associated  with  the  screen  saver  window  is  installed.
-- Finally, the screen saver window is mapped.
--
-- The window remains mapped and at the top of the  stacking  order  until
-- the  screen  saver is deactivated in response to activity on any of the
-- user input devices, a ForceScreenSaver request with a value  of  Reset,
-- or any request that would cause the window to be unmapped.
--
-- If  the  screen  saver activates while the server is grabbed by another
-- client, the internal saver mechanism  is  used.   The  ForceScreenSaver
-- request  may  be used with a value of Active to deactivate the internal
-- saver and activate the external saver.
--
-- If the screen saver client's connection to the server is  broken  while
-- the  screen saver is activated and the client's close down mode has not
-- been RetainPermanent or RetainTemporary, the current  screen  saver  is
-- deactivated and the internal screen saver is immediately activated.
--
-- When  the  screen saver deactivates, the screen saver window's colormap
-- is uninstalled and the window is unmapped (except as described  below).
-- The  screen  saver  XID is disassociated with the window and the server
-- may, but is not required to, destroy the window along  with  any  children.
--
-- When the screen saver is being deactivated and then immediately reactivated
-- (such as when switching screen savers), the server may leave  the
-- screen saver window mapped (typically to avoid generating exposures).

xScreenSaverSetAttributes :: Display
                          -> Position       -- ^ x
                          -> Position       -- ^ y
                          -> Dimension      -- ^ width
                          -> Dimension      -- ^ height
                          -> Dimension      -- ^ border width
                          -> CInt           -- ^ depth ('defaultDepthOfScreen')
                          -> WindowClass    -- ^ class
                          -> Visual         -- ^ visual ('defaultVisualOfScreen')
                          -> AttributeMask  -- ^ valuemask
                          -> Ptr SetWindowAttributes
                          -> IO ()
xScreenSaverSetAttributes :: Display
-> Position
-> Position
-> Dimension
-> Dimension
-> Dimension
-> CInt
-> CInt
-> Visual
-> Window
-> Ptr SetWindowAttributes
-> IO ()
xScreenSaverSetAttributes Display
dpy Position
x Position
y Dimension
w Dimension
h Dimension
bw CInt
d CInt
wc Visual
v Window
am Ptr SetWindowAttributes
pswa = do
    Display
-> Window
-> Position
-> Position
-> Dimension
-> Dimension
-> Dimension
-> CInt
-> CInt
-> Visual
-> Window
-> Ptr SetWindowAttributes
-> IO ()
cXScreenSaverSetAttributes Display
dpy (Display -> Window
defaultRootWindow Display
dpy)
                                    Position
x Position
y Dimension
w Dimension
h Dimension
bw CInt
d CInt
wc Visual
v Window
am Ptr SetWindowAttributes
pswa

-- | XScreenSaverUnsetAttributes  instructs the server to discard any previ‐
-- ous screen saver window attributes set by this client.

xScreenSaverUnsetAttributes :: Display -> IO ()
xScreenSaverUnsetAttributes :: Display -> IO ()
xScreenSaverUnsetAttributes Display
dpy =
    Display -> Window -> IO ()
cXScreenSaverUnsetAttributes Display
dpy (Display -> Window
defaultRootWindow Display
dpy)

-- | XScreenSaverRegister stores the given XID in the _SCREEN_SAVER_ID prop‐
-- erty  (of  the  given type) on the root window of the specified screen.
-- It returns zero if an error is encountered  and  the  property  is  not
-- changed, otherwise it returns non-zero.

xScreenSaverSaverRegister :: Display -> ScreenNumber -> XID -> Atom -> IO ()
xScreenSaverSaverRegister :: Display -> Dimension -> Window -> Window -> IO ()
xScreenSaverSaverRegister = Display -> Dimension -> Window -> Window -> IO ()
cXScreenSaverSaverRegister

-- | XScreenSaverUnregister  removes any _SCREEN_SAVER_ID from the root win‐
-- dow of the specified screen.  It returns zero if an  error  is  encoun‐
-- tered and the property is changed, otherwise it returns non-zero.

xScreenSaverUnregister :: Display -> ScreenNumber -> IO Status
xScreenSaverUnregister :: Display -> Dimension -> IO CInt
xScreenSaverUnregister = Display -> Dimension -> IO CInt
cXScreenSaverUnregister

-- | XScreenSaverGetRegistered  returns  the  XID  and  type  stored  in the
-- _SCREEN_SAVER_ID property on the root window of the  specified  screen.
-- It  returns zero if an error is encountered or if the property does not
-- exist or is not of the correct format; otherwise it returns non-zero.

xScreenSaverGetRegistered :: Display -> ScreenNumber -> XID -> Atom -> IO Status
xScreenSaverGetRegistered :: Display -> Dimension -> Window -> Window -> IO CInt
xScreenSaverGetRegistered = Display -> Dimension -> Window -> Window -> IO CInt
cXScreenSaverGetRegistered

-- | XScreenSaverSuspend temporarily suspends the screensaver and DPMS timer
-- if suspend is 'True', and restarts the timer if suspend is 'False'.
-- This  function  should  be  used  by  applications  that don't want the
-- screensaver or DPMS to become activated while they're  for  example  in
-- the  process of playing a media sequence, or are otherwise continuously
-- presenting visual information to the user while  in  a  non-interactive
-- state.  This  function  is  not  intended  to  be called by an external
-- screensaver application.
--
-- If XScreenSaverSuspend is called multiple times  with  suspend  set  to
-- 'True',  it must be called an equal number of times with suspend set to
-- 'False' in order for  the  screensaver  timer  to  be  restarted.  This
-- request has no affect if a client tries to resume the screensaver with‐
-- out first having suspended it.  XScreenSaverSuspend  can  thus  not  be
-- used  by one client to resume the screensaver if it's been suspended by
-- another client.
--
-- If a client that has suspended  the  screensaver  becomes  disconnected
-- from  the  X  server,  the  screensaver  timer  will  automatically  be
-- restarted, unless it's still suspended by  another  client.  Suspending
-- the screensaver timer doesn't prevent the screensaver from being forceably
-- activated with the ForceScreenSaver request, or a DPMS  mode  from
-- being set with the DPMSForceLevel request.
--
-- XScreenSaverSuspend  also doesn't deactivate the screensaver or DPMS if
-- either is active at the time the request to suspend them is received by
-- the  X  server. But once they've been deactivated, they won't automatically
-- be activated again, until the client has canceled the suspension.

xScreenSaverSuspend :: Display -> Bool -> IO ()
xScreenSaverSuspend :: Display -> Bool -> IO ()
xScreenSaverSuspend = Display -> Bool -> IO ()
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 ()