{-# LANGUAGE ForeignFunctionInterface, RecordWildCards #-}

module Blucontrol.Recolor.X.Internal (
  XRRGamma (..)
, xrrSetGamma
) where

import Control.DeepSeq
import Foreign.Ptr
import GHC.Generics

import Graphics.X11.Types
import Graphics.X11.Xlib.Types

data XRRGamma = XRRGamma { XRRGamma -> Float
xrr_gamma_red :: Float
                         , XRRGamma -> Float
xrr_gamma_green :: Float
                         , XRRGamma -> Float
xrr_gamma_blue :: Float
                         }
  deriving (XRRGamma -> XRRGamma -> Bool
(XRRGamma -> XRRGamma -> Bool)
-> (XRRGamma -> XRRGamma -> Bool) -> Eq XRRGamma
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: XRRGamma -> XRRGamma -> Bool
$c/= :: XRRGamma -> XRRGamma -> Bool
== :: XRRGamma -> XRRGamma -> Bool
$c== :: XRRGamma -> XRRGamma -> Bool
Eq, (forall x. XRRGamma -> Rep XRRGamma x)
-> (forall x. Rep XRRGamma x -> XRRGamma) -> Generic XRRGamma
forall x. Rep XRRGamma x -> XRRGamma
forall x. XRRGamma -> Rep XRRGamma x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep XRRGamma x -> XRRGamma
$cfrom :: forall x. XRRGamma -> Rep XRRGamma x
Generic, Eq XRRGamma
Eq XRRGamma
-> (XRRGamma -> XRRGamma -> Ordering)
-> (XRRGamma -> XRRGamma -> Bool)
-> (XRRGamma -> XRRGamma -> Bool)
-> (XRRGamma -> XRRGamma -> Bool)
-> (XRRGamma -> XRRGamma -> Bool)
-> (XRRGamma -> XRRGamma -> XRRGamma)
-> (XRRGamma -> XRRGamma -> XRRGamma)
-> Ord XRRGamma
XRRGamma -> XRRGamma -> Bool
XRRGamma -> XRRGamma -> Ordering
XRRGamma -> XRRGamma -> XRRGamma
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 :: XRRGamma -> XRRGamma -> XRRGamma
$cmin :: XRRGamma -> XRRGamma -> XRRGamma
max :: XRRGamma -> XRRGamma -> XRRGamma
$cmax :: XRRGamma -> XRRGamma -> XRRGamma
>= :: XRRGamma -> XRRGamma -> Bool
$c>= :: XRRGamma -> XRRGamma -> Bool
> :: XRRGamma -> XRRGamma -> Bool
$c> :: XRRGamma -> XRRGamma -> Bool
<= :: XRRGamma -> XRRGamma -> Bool
$c<= :: XRRGamma -> XRRGamma -> Bool
< :: XRRGamma -> XRRGamma -> Bool
$c< :: XRRGamma -> XRRGamma -> Bool
compare :: XRRGamma -> XRRGamma -> Ordering
$ccompare :: XRRGamma -> XRRGamma -> Ordering
$cp1Ord :: Eq XRRGamma
Ord, ReadPrec [XRRGamma]
ReadPrec XRRGamma
Int -> ReadS XRRGamma
ReadS [XRRGamma]
(Int -> ReadS XRRGamma)
-> ReadS [XRRGamma]
-> ReadPrec XRRGamma
-> ReadPrec [XRRGamma]
-> Read XRRGamma
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [XRRGamma]
$creadListPrec :: ReadPrec [XRRGamma]
readPrec :: ReadPrec XRRGamma
$creadPrec :: ReadPrec XRRGamma
readList :: ReadS [XRRGamma]
$creadList :: ReadS [XRRGamma]
readsPrec :: Int -> ReadS XRRGamma
$creadsPrec :: Int -> ReadS XRRGamma
Read, Int -> XRRGamma -> ShowS
[XRRGamma] -> ShowS
XRRGamma -> String
(Int -> XRRGamma -> ShowS)
-> (XRRGamma -> String) -> ([XRRGamma] -> ShowS) -> Show XRRGamma
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [XRRGamma] -> ShowS
$cshowList :: [XRRGamma] -> ShowS
show :: XRRGamma -> String
$cshow :: XRRGamma -> String
showsPrec :: Int -> XRRGamma -> ShowS
$cshowsPrec :: Int -> XRRGamma -> ShowS
Show)

instance NFData XRRGamma

xrrSetGamma :: XRRGamma -> Display -> Window -> IO ()
xrrSetGamma :: XRRGamma -> Display -> Window -> IO ()
xrrSetGamma XRRGamma {Float
xrr_gamma_blue :: Float
xrr_gamma_green :: Float
xrr_gamma_red :: Float
xrr_gamma_blue :: XRRGamma -> Float
xrr_gamma_green :: XRRGamma -> Float
xrr_gamma_red :: XRRGamma -> Float
..} (Display Ptr Display
display) Window
window = do
  Ptr Int
res <- Ptr Display -> Window -> IO (Ptr Int)
_XRRGetScreenResourcesCurrent Ptr Display
display Window
window
  Float -> Float -> Float -> Ptr Int -> Ptr Display -> IO ()
_setGamma Float
xrr_gamma_red Float
xrr_gamma_green Float
xrr_gamma_blue Ptr Int
res Ptr Display
display

foreign import ccall "XrandrGamma.h setGamma" _setGamma :: Float -> Float -> Float -> Ptr Int -> Ptr Display -> IO ()
foreign import ccall "<X11/extensions/Xrandr.h> XRRGetScreenResourcesCurrent" _XRRGetScreenResourcesCurrent :: Ptr Display -> Window -> IO (Ptr Int)