summaryrefslogtreecommitdiff
path: root/xhsb/XProto.hs
blob: 43d25ebeca36e6972c97bd371240ad0536a543c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{-# OPTIONS -fglasgow-exts -ffi #-}
module XProto(internAtom, Atom, InternAtomReply(..)) where

import XCB
import XCBExt
import CForeign
import Foreign
import Data.Generics

foreign import ccall "XProto.glue.h" _internAtom :: Ptr XCBConnection -> Word8 -> Word16 -> CString -> IO Word32

type Atom = Word32

data InternAtomReply = InternAtomReply { internAtomResponseType :: Word8, internAtomSequence :: Word16, internAtomLength :: Word32, internAtomAtom :: Atom }
    deriving (Typeable, Data)

internAtom :: Ptr XCBConnection -> Bool -> String -> IO InternAtomReply
internAtom c onlyIfExists name =
        requestWithReply c reader $ withCStringLen name (\(name, name_len)-> _internAtom c (fromBool onlyIfExists) (toEnum name_len) name)
    where reader = do
            responseType <- readStorable
            sequence <- readStorable
            length <- readStorable
            atom <- readStorable
            return $ InternAtomReply responseType sequence length atom