6518264e87f83e36c29e6e40b116f96c6bda5647
[framework/uifw/ecore.git] / src / lib / ecore_x / xlib / ecore_x_atoms.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #ifdef HAVE_ALLOCA_H
6 # include <alloca.h>
7 #elif defined __GNUC__
8 # define alloca __builtin_alloca
9 #elif defined _AIX
10 # define alloca __alloca
11 #elif defined _MSC_VER
12 # include <malloc.h>
13 # define alloca _alloca
14 #else /* ifdef HAVE_ALLOCA_H */
15 # include <stddef.h>
16 # ifdef  __cplusplus
17 extern "C"
18 # endif /* ifdef  __cplusplus */
19 void *alloca(size_t);
20 #endif /* ifdef HAVE_ALLOCA_H */
21
22 #include <string.h>
23
24 #include "Ecore.h"
25 #include "ecore_x_private.h"
26 #include "Ecore_X.h"
27 #include "Ecore_X_Atoms.h"
28 #include "ecore_x_atoms_decl.h"
29
30 void
31 _ecore_x_atoms_init(void)
32 {
33    Atom *atoms;
34    char **names;
35    int i, num;
36
37    num = sizeof(atom_items) / sizeof(Atom_Item);
38    atoms = alloca(num * sizeof(Atom));
39    names = alloca(num * sizeof(char *));
40    for (i = 0; i < num; i++)
41      names[i] = (char *) atom_items[i].name;
42    XInternAtoms(_ecore_x_disp, names, num, False, atoms);
43    for (i = 0; i < num; i++)
44      *(atom_items[i].atom) = atoms[i];
45 }
46
47 /**
48  * Retrieves the atom value associated with the given name.
49  * @param  name The given name.
50  * @return Associated atom value.
51  */
52 EAPI Ecore_X_Atom
53 ecore_x_atom_get(const char *name)
54 {
55    if (!_ecore_x_disp)
56      return 0;
57
58    LOGFN(__FILE__, __LINE__, __FUNCTION__);
59    return XInternAtom(_ecore_x_disp, name, False);
60 }
61
62 EAPI void
63 ecore_x_atoms_get(const char **names,
64                   int num,
65                   Ecore_X_Atom *atoms)
66 {
67    Atom *atoms_int;
68    int i;
69
70    if (!_ecore_x_disp)
71      return;
72
73    LOGFN(__FILE__, __LINE__, __FUNCTION__);
74    atoms_int = alloca(num * sizeof(Atom));
75    XInternAtoms(_ecore_x_disp, (char **)names, num, False, atoms_int);
76    for (i = 0; i < num; i++)
77      atoms[i] = atoms_int[i];
78 }
79
80 EAPI char *
81 ecore_x_atom_name_get(Ecore_X_Atom atom)
82 {
83    char *name;
84    char *xname;
85
86    if (!_ecore_x_disp)
87      return NULL;
88
89    LOGFN(__FILE__, __LINE__, __FUNCTION__);
90
91    xname = XGetAtomName(_ecore_x_disp, atom);
92    if (!xname)
93      return NULL;
94
95    name = strdup(xname);
96    XFree(xname);
97
98    return name;
99 }
100