module Graphics.Wayland.Internal.Util (
CInterface(..), Client(..),
Fixed256, Precision256,
Time, millisecondsToTime, timeToMilliseconds, diffTimeToTime, timeToDiffTime
) where
import Data.Ratio ((%))
import Data.Time.Clock (DiffTime)
import Data.Fixed (Fixed(..), HasResolution(..), Milli(..))
import Data.Typeable
import Data.Functor
import Foreign
import Foreign.C.Types
import Foreign.C.String
newtype CInterface = CInterface (Ptr (CInterface))
newtype Client = Client (Ptr Client) deriving (Eq)
data Precision256 = Precision256 deriving (Typeable)
instance HasResolution Precision256 where
resolution _ = 256
type Fixed256 = Fixed Precision256
type Time = Milli
millisecondsToTime :: CUInt -> Time
millisecondsToTime = MkFixed . fromIntegral
timeToMilliseconds :: Time -> CUInt
timeToMilliseconds (MkFixed n) = fromIntegral n
timeToDiffTime :: Time -> DiffTime
timeToDiffTime (MkFixed n) = fromRational (n % 1000)
diffTimeToTime :: DiffTime -> Time
diffTimeToTime = fromRational . toRational