xhb-atom-cache-0.1.0.2: Atom cache for XHB

Safe HaskellNone
LanguageHaskell2010

Graphics.XHB.AtomCache

Synopsis

Documentation

data AtomId Source

Constructors

forall l . AtomLike l => AtomId l 

class (Eq l, Hashable l, Typeable l) => AtomLike l where Source

Minimal complete definition

toAtomName

newtype AtomCacheT m a Source

Constructors

AtomCacheT 

Fields

unAtomT :: StateT AtomCache m a
 

seedAtoms :: (AtomLike l, Applicative m, MonadIO m) => Connection -> [l] -> AtomCacheT m a -> AtomCacheT m (Either SomeError a) Source

Preseed the atom cache with AtomLikes. Example:

{-# LANGUAGE DeriveDataTypeable #-}

import Data.Typeable (Typeable)
import Data.Hashable (Hashable(..))
import Control.Monad (forM_, void)
import Control.Monad.IO.Class (liftIO)
import Graphics.XHB (connect)
import Graphics.XHB.AtomCache

data ATOMS = NET_CLIENT_LIST | NET_NUMBER_OF_DESKTOPS
    deriving (Eq, Show, Typeable)

instance Hashable ATOMS where
    hashWithSalt s = hashWithSalt s . show

instance AtomLike ATOMS where
    toAtomName a = '_' : show a

atoms :: [ATOMS]
atoms = [NET_CLIENT_LIST, NET_NUMBER_OF_DESKTOPS]

main :: IO ()
main = do
    Just c <- connect
    void $ runAtomCacheT . seedAtoms c atoms $ do
        forM_ atoms $ \a -> unsafeLookupATOM a >>= liftIO . print

tryLookupAtom :: (AtomLike l, AtomCacheCtx m, MonadIO m) => Connection -> l -> m (Either SomeError ATOM) Source

Lookup AtomName in cache first, if that fails, try to fetch from the X server and put it into the cache