{-# 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 Atom
internAtom Display
display String
atom_name Bool
only_if_exists =
        String -> (Ptr CChar -> IO Atom) -> IO Atom
forall a. String -> (Ptr CChar -> IO a) -> IO a
withCString String
atom_name ((Ptr CChar -> IO Atom) -> IO Atom)
-> (Ptr CChar -> IO Atom) -> IO Atom
forall a b. (a -> b) -> a -> b
$ \ Ptr CChar
c_atom_name ->
        Display -> Ptr CChar -> Bool -> IO Atom
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 -> Atom -> IO (Maybe String)
getAtomName Display
dpy Atom
atom = do
    Ptr CChar
p <- Display -> Atom -> IO (Ptr CChar)
cXGetAtomName Display
dpy Atom
atom
    if Ptr CChar
p Ptr CChar -> Ptr CChar -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr CChar
forall a. Ptr a
nullPtr
        then Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing
        else do
            String
res <- Ptr CChar -> IO String
peekCString Ptr CChar
p
            CInt
_ <- Ptr CChar -> IO CInt
forall a. Ptr a -> IO CInt
xFree Ptr CChar
p
            Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe String -> IO (Maybe String))
-> Maybe String -> IO (Maybe String)
forall a b. (a -> b) -> a -> b
$ String -> Maybe String
forall a. a -> Maybe a
Just String
res

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

getAtomNames :: Display -> [Atom] -> IO [String]
getAtomNames :: Display -> [Atom] -> IO [String]
getAtomNames Display
dpy [Atom]
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
    Ptr Atom
atomsp <- (Pool -> Int -> IO (Ptr Atom)
forall a. Storable a => Pool -> Int -> IO (Ptr a)
pooledMallocArray Pool
pool (Int -> IO (Ptr Atom)) -> Int -> IO (Ptr Atom)
forall a b. (a -> b) -> a -> b
$ [Atom] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Atom]
atoms) :: IO (Ptr Atom)
    Ptr (Ptr CChar)
ccharp <- (Pool -> Int -> IO (Ptr (Ptr CChar))
forall a. Storable a => Pool -> Int -> IO (Ptr a)
pooledMallocArray Pool
pool (Int -> IO (Ptr (Ptr CChar))) -> Int -> IO (Ptr (Ptr CChar))
forall a b. (a -> b) -> a -> b
$ [Atom] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Atom]
atoms) :: IO (Ptr (Ptr CChar))

    Ptr Atom -> [Atom] -> IO ()
forall a. Storable a => Ptr a -> [a] -> IO ()
pokeArray Ptr Atom
atomsp [Atom]
atoms
    CInt
_ <- Display -> Ptr Atom -> CInt -> Ptr (Ptr CChar) -> IO CInt
cXGetAtomNames Display
dpy Ptr Atom
atomsp (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> Int -> CInt
forall a b. (a -> b) -> a -> b
$ [Atom] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Atom]
atoms :: CInt) Ptr (Ptr CChar)
ccharp

    [String]
res <- Int -> Ptr (Ptr CChar) -> IO [Ptr CChar]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray ([Atom] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Atom]
atoms) Ptr (Ptr CChar)
ccharp IO [Ptr CChar] -> ([Ptr CChar] -> IO [String]) -> IO [String]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Ptr CChar -> IO String) -> [Ptr CChar] -> IO [String]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Ptr CChar -> IO String
peekCString
    Int -> Ptr (Ptr CChar) -> IO [Ptr CChar]
forall a. Storable a => Int -> Ptr a -> IO [a]
peekArray ([Atom] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Atom]
atoms) Ptr (Ptr CChar)
ccharp IO [Ptr CChar] -> ([Ptr CChar] -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Ptr CChar -> IO CInt) -> [Ptr CChar] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Ptr CChar -> IO CInt
forall a. Ptr a -> IO CInt
xFree

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

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

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