{-# LINE 1 "Graphics/X11/Xlib/Atom.hsc" #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Graphics.X11.Xlib.Atom
-- Copyright   :  (c) Alastair Reid, 1999-2003
-- License     :  BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer  :  libraries@haskell.org
-- Stability   :  provisional
-- Portability :  portable
--
-- A collection of type declarations for interfacing with X11 Atoms.
--
-----------------------------------------------------------------------------

module Graphics.X11.Xlib.Atom(
        internAtom,
        getAtomName,
        getAtomNames,

        pRIMARY,
        sECONDARY,
        aRC,
        aTOM,
        bITMAP,
        cARDINAL,
        cOLORMAP,
        cURSOR,
        cUT_BUFFER0,
        cUT_BUFFER1,
        cUT_BUFFER2,
        cUT_BUFFER3,
        cUT_BUFFER4,
        cUT_BUFFER5,
        cUT_BUFFER6,
        cUT_BUFFER7,
        dRAWABLE,
        fONT,
        iNTEGER,
        pIXMAP,
        pOINT,
        rECTANGLE,
        rESOURCE_MANAGER,
        rGB_COLOR_MAP,
        rGB_BEST_MAP,
        rGB_BLUE_MAP,
        rGB_DEFAULT_MAP,
        rGB_GRAY_MAP,
        rGB_GREEN_MAP,
        rGB_RED_MAP,
        sTRING,
        vISUALID,
        wINDOW,
        wM_COMMAND,
        wM_HINTS,
        wM_CLIENT_MACHINE,
        wM_ICON_NAME,
        wM_ICON_SIZE,
        wM_NAME,
        wM_NORMAL_HINTS,
        wM_SIZE_HINTS,
        wM_ZOOM_HINTS,
        mIN_SPACE,
        nORM_SPACE,
        mAX_SPACE,
        eND_SPACE,
        sUPERSCRIPT_X,
        sUPERSCRIPT_Y,
        sUBSCRIPT_X,
        sUBSCRIPT_Y,
        uNDERLINE_POSITION,
        uNDERLINE_THICKNESS,
        sTRIKEOUT_ASCENT,
        sTRIKEOUT_DESCENT,
        iTALIC_ANGLE,
        x_HEIGHT,
        qUAD_WIDTH,
        wEIGHT,
        pOINT_SIZE,
        rESOLUTION,
        cOPYRIGHT,
        nOTICE,
        fONT_NAME,
        fAMILY_NAME,
        fULL_NAME,
        cAP_HEIGHT,
        wM_CLASS,
        wM_TRANSIENT_FOR,
        lAST_PREDEFINED,

        ) where

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

import Foreign hiding ( void )
import Foreign.C.Types
import Foreign.C.String



----------------------------------------------------------------
-- Atoms
----------------------------------------------------------------

-- AC, 1/9/2000: Added definition for XInternAtom

-- | interface to the X11 library function @XInternAtom()@.
internAtom :: Display -> String -> Bool -> IO Atom
internAtom :: Display -> String -> Bool -> IO Word64
internAtom Display
display String
atom_name Bool
only_if_exists =
        String -> (Ptr CChar -> IO Word64) -> IO Word64
forall a. String -> (Ptr CChar -> IO a) -> IO a
withCString String
atom_name ((Ptr CChar -> IO Word64) -> IO Word64)
-> (Ptr CChar -> IO Word64) -> IO Word64
forall a b. (a -> b) -> a -> b
$ \ Ptr CChar
c_atom_name ->
        Display -> Ptr CChar -> Bool -> IO Word64
xInternAtom Display
display Ptr CChar
c_atom_name Bool
only_if_exists
foreign import ccall unsafe "XInternAtom"
        xInternAtom :: Display -> CString -> Bool -> IO Atom

-- jrk, 22.11.2012: getAtomName{,s}

getAtomName :: Display -> Atom -> IO (Maybe String)
getAtomName :: Display -> Word64 -> IO (Maybe String)
getAtomName Display
dpy Word64
atom = do
    p <- Display -> Word64 -> IO (Ptr CChar)
cXGetAtomName Display
dpy Word64
atom
    if p == nullPtr
        then return Nothing
        else do
            res <- peekCString p
            _ <- xFree p
            return $ Just res

foreign import ccall "XGetAtomName"
    cXGetAtomName :: Display -> Atom -> IO (Ptr CChar)

getAtomNames :: Display -> [Atom] -> IO [String]
getAtomNames :: Display -> [Word64] -> IO [String]
getAtomNames Display
dpy [Word64]
atoms = (Pool -> IO [String]) -> IO [String]
forall b. (Pool -> IO b) -> IO b
withPool ((Pool -> IO [String]) -> IO [String])
-> (Pool -> IO [String]) -> IO [String]
forall a b. (a -> b) -> a -> b
$ \Pool
pool -> do
    atomsp <- (Pool -> Int -> IO (Ptr Word64)
forall a. Storable a => Pool -> Int -> IO (Ptr a)
pooledMallocArray Pool
pool (Int -> IO (Ptr Word64)) -> Int -> IO (Ptr Word64)
forall a b. (a -> b) -> a -> b
$ [Word64] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Word64]
atoms) :: IO (Ptr Atom)
    ccharp <- (pooledMallocArray pool $ length atoms) :: IO (Ptr (Ptr CChar))

    pokeArray atomsp atoms
    _ <- cXGetAtomNames dpy atomsp (fromIntegral $ length atoms :: CInt) ccharp

    res <- peekArray (length atoms) ccharp >>= mapM peekCString
    peekArray (length atoms) ccharp >>= mapM_ xFree

    return res

foreign import ccall "XGetAtomNames"
    cXGetAtomNames :: Display -> Ptr Atom -> CInt -> Ptr (Ptr CChar) -> IO Status

-- XConvertSelection omitted
-- XListProperties omitted
-- XChangeProperty omitted
-- XDeleteProperty omitted

pRIMARY               :: Atom
pRIMARY :: Word64
pRIMARY               =  Word64
1
sECONDARY             :: Atom
sECONDARY :: Word64
sECONDARY             =  Word64
2
aRC                   :: Atom
aRC :: Word64
aRC                   =  Word64
3
aTOM                  :: Atom
aTOM :: Word64
aTOM                  =  Word64
4
bITMAP                :: Atom
bITMAP :: Word64
bITMAP                =  Word64
5
cARDINAL              :: Atom
cARDINAL :: Word64
cARDINAL              =  Word64
6
cOLORMAP              :: Atom
cOLORMAP :: Word64
cOLORMAP              =  Word64
7
cURSOR                :: Atom
cURSOR :: Word64
cURSOR                =  Word64
8
cUT_BUFFER0           :: Atom
cUT_BUFFER0 :: Word64
cUT_BUFFER0           =  Word64
9
cUT_BUFFER1           :: Atom
cUT_BUFFER1 :: Word64
cUT_BUFFER1           =  Word64
10
cUT_BUFFER2           :: Atom
cUT_BUFFER2 :: Word64
cUT_BUFFER2           =  Word64
11
cUT_BUFFER3           :: Atom
cUT_BUFFER3 :: Word64
cUT_BUFFER3           =  Word64
12
cUT_BUFFER4           :: Atom
cUT_BUFFER4 :: Word64
cUT_BUFFER4           =  Word64
13
cUT_BUFFER5           :: Atom
cUT_BUFFER5 :: Word64
cUT_BUFFER5           =  Word64
14
cUT_BUFFER6           :: Atom
cUT_BUFFER6 :: Word64
cUT_BUFFER6           =  Word64
15
cUT_BUFFER7           :: Atom
cUT_BUFFER7 :: Word64
cUT_BUFFER7           =  Word64
16
dRAWABLE              :: Atom
dRAWABLE :: Word64
dRAWABLE              =  Word64
17
fONT                  :: Atom
fONT :: Word64
fONT                  =  Word64
18
iNTEGER               :: Atom
iNTEGER :: Word64
iNTEGER               =  Word64
19
pIXMAP                :: Atom
pIXMAP :: Word64
pIXMAP                =  Word64
20
pOINT                 :: Atom
pOINT :: Word64
pOINT                 =  Word64
21
rECTANGLE             :: Atom
rECTANGLE :: Word64
rECTANGLE             =  Word64
22
rESOURCE_MANAGER      :: Atom
rESOURCE_MANAGER :: Word64
rESOURCE_MANAGER      =  Word64
23
rGB_COLOR_MAP         :: Atom
rGB_COLOR_MAP :: Word64
rGB_COLOR_MAP         =  Word64
24
rGB_BEST_MAP          :: Atom
rGB_BEST_MAP :: Word64
rGB_BEST_MAP          =  Word64
25
rGB_BLUE_MAP          :: Atom
rGB_BLUE_MAP :: Word64
rGB_BLUE_MAP          =  Word64
26
rGB_DEFAULT_MAP       :: Atom
rGB_DEFAULT_MAP :: Word64
rGB_DEFAULT_MAP       =  Word64
27
rGB_GRAY_MAP          :: Atom
rGB_GRAY_MAP :: Word64
rGB_GRAY_MAP          =  Word64
28
rGB_GREEN_MAP         :: Atom
rGB_GREEN_MAP :: Word64
rGB_GREEN_MAP         =  Word64
29
rGB_RED_MAP           :: Atom
rGB_RED_MAP :: Word64
rGB_RED_MAP           =  Word64
30
sTRING                :: Atom
sTRING :: Word64
sTRING                =  Word64
31
vISUALID              :: Atom
vISUALID :: Word64
vISUALID              =  Word64
32
wINDOW                :: Atom
wINDOW :: Word64
wINDOW                =  Word64
33
wM_COMMAND            :: Atom
wM_COMMAND :: Word64
wM_COMMAND            =  Word64
34
wM_HINTS              :: Atom
wM_HINTS :: Word64
wM_HINTS              =  Word64
35
wM_CLIENT_MACHINE     :: Atom
wM_CLIENT_MACHINE :: Word64
wM_CLIENT_MACHINE     =  Word64
36
wM_ICON_NAME          :: Atom
wM_ICON_NAME :: Word64
wM_ICON_NAME          =  Word64
37
wM_ICON_SIZE          :: Atom
wM_ICON_SIZE :: Word64
wM_ICON_SIZE          =  Word64
38
wM_NAME               :: Atom
wM_NAME :: Word64
wM_NAME               =  Word64
39
wM_NORMAL_HINTS       :: Atom
wM_NORMAL_HINTS :: Word64
wM_NORMAL_HINTS       =  Word64
40
wM_SIZE_HINTS         :: Atom
wM_SIZE_HINTS :: Word64
wM_SIZE_HINTS         =  Word64
41
wM_ZOOM_HINTS         :: Atom
wM_ZOOM_HINTS :: Word64
wM_ZOOM_HINTS         =  Word64
42
mIN_SPACE             :: Atom
mIN_SPACE :: Word64
mIN_SPACE             =  Word64
43
nORM_SPACE            :: Atom
nORM_SPACE :: Word64
nORM_SPACE            =  Word64
44
mAX_SPACE             :: Atom
mAX_SPACE :: Word64
mAX_SPACE             =  Word64
45
eND_SPACE             :: Atom
eND_SPACE :: Word64
eND_SPACE             =  Word64
46
sUPERSCRIPT_X         :: Atom
sUPERSCRIPT_X :: Word64
sUPERSCRIPT_X         =  Word64
47
sUPERSCRIPT_Y         :: Atom
sUPERSCRIPT_Y :: Word64
sUPERSCRIPT_Y         =  Word64
48
sUBSCRIPT_X           :: Atom
sUBSCRIPT_X :: Word64
sUBSCRIPT_X           =  Word64
49
sUBSCRIPT_Y           :: Atom
sUBSCRIPT_Y :: Word64
sUBSCRIPT_Y           =  Word64
50
uNDERLINE_POSITION    :: Atom
uNDERLINE_POSITION :: Word64
uNDERLINE_POSITION    =  Word64
51
uNDERLINE_THICKNESS   :: Atom
uNDERLINE_THICKNESS :: Word64
uNDERLINE_THICKNESS   =  Word64
52
sTRIKEOUT_ASCENT      :: Atom
sTRIKEOUT_ASCENT :: Word64
sTRIKEOUT_ASCENT      =  Word64
53
sTRIKEOUT_DESCENT     :: Atom
sTRIKEOUT_DESCENT :: Word64
sTRIKEOUT_DESCENT     =  Word64
54
iTALIC_ANGLE          :: Atom
iTALIC_ANGLE :: Word64
iTALIC_ANGLE          =  Word64
55
x_HEIGHT              :: Atom
x_HEIGHT :: Word64
x_HEIGHT              =  Word64
56
qUAD_WIDTH            :: Atom
qUAD_WIDTH :: Word64
qUAD_WIDTH            =  Word64
57
wEIGHT                :: Atom
wEIGHT :: Word64
wEIGHT                =  Word64
58
pOINT_SIZE            :: Atom
pOINT_SIZE :: Word64
pOINT_SIZE            =  Word64
59
rESOLUTION            :: Atom
rESOLUTION :: Word64
rESOLUTION            =  Word64
60
cOPYRIGHT             :: Atom
cOPYRIGHT :: Word64
cOPYRIGHT             =  Word64
61
nOTICE                :: Atom
nOTICE :: Word64
nOTICE                =  Word64
62
fONT_NAME             :: Atom
fONT_NAME :: Word64
fONT_NAME             =  Word64
63
fAMILY_NAME           :: Atom
fAMILY_NAME :: Word64
fAMILY_NAME           =  Word64
64
fULL_NAME             :: Atom
fULL_NAME :: Word64
fULL_NAME             =  Word64
65
cAP_HEIGHT            :: Atom
cAP_HEIGHT :: Word64
cAP_HEIGHT            =  Word64
66
wM_CLASS              :: Atom
wM_CLASS :: Word64
wM_CLASS              =  Word64
67
wM_TRANSIENT_FOR      :: Atom
wM_TRANSIENT_FOR :: Word64
wM_TRANSIENT_FOR      =  Word64
68
lAST_PREDEFINED       :: Atom
lAST_PREDEFINED :: Word64
lAST_PREDEFINED       =  Word64
68

{-# LINE 223 "Graphics/X11/Xlib/Atom.hsc" #-}

----------------------------------------------------------------
-- End
----------------------------------------------------------------