eolian: rename is_ref API to is_ptr to match syntax
[platform/upstream/efl.git] / src / lib / ecore_x / ecore_x_atoms.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #ifdef STDC_HEADERS
6 # include <stdlib.h>
7 # include <stddef.h>
8 #else
9 # ifdef HAVE_STDLIB_H
10 #  include <stdlib.h>
11 # endif
12 #endif
13
14 #include <string.h>
15
16 #include "Ecore.h"
17 #include "ecore_x_private.h"
18 #include "Ecore_X.h"
19 #include "Ecore_X_Atoms.h"
20 #include "ecore_x_atoms_decl.h"
21
22 void
23 _ecore_x_atoms_init(void)
24 {
25    Atom *atoms;
26    char **names;
27    int i, num;
28
29    num = sizeof(atom_items) / sizeof(Atom_Item);
30    atoms = alloca(num * sizeof(Atom));
31    names = alloca(num * sizeof(char *));
32    for (i = 0; i < num; i++)
33      names[i] = (char *) atom_items[i].name;
34    XInternAtoms(_ecore_x_disp, names, num, False, atoms);
35    for (i = 0; i < num; i++)
36      *(atom_items[i].atom) = atoms[i];
37 }
38
39 /**
40  * Retrieves the atom value associated with the given name.
41  * @param  name The given name.
42  * @return Associated atom value.
43  */
44 EAPI Ecore_X_Atom
45 ecore_x_atom_get(const char *name)
46 {
47    Ecore_X_Atom atom;
48
49    LOGFN(__FILE__, __LINE__, __FUNCTION__);
50    EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
51    atom = XInternAtom(_ecore_x_disp, name, False);
52    if (_ecore_xlib_sync) ecore_x_sync();
53    return atom;
54 }
55
56 EAPI void
57 ecore_x_atoms_get(const char **names,
58                   int num,
59                   Ecore_X_Atom *atoms)
60 {
61    Atom *atoms_int;
62    int i;
63
64    LOGFN(__FILE__, __LINE__, __FUNCTION__);
65    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
66    atoms_int = alloca(num * sizeof(Atom));
67    XInternAtoms(_ecore_x_disp, (char **)names, num, False, atoms_int);
68    for (i = 0; i < num; i++)
69      atoms[i] = atoms_int[i];
70    if (_ecore_xlib_sync) ecore_x_sync();
71 }
72
73 EAPI char *
74 ecore_x_atom_name_get(Ecore_X_Atom atom)
75 {
76    char *name;
77    char *xname;
78
79    LOGFN(__FILE__, __LINE__, __FUNCTION__);
80
81    EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, NULL);
82
83    xname = XGetAtomName(_ecore_x_disp, atom);
84    if (_ecore_xlib_sync) ecore_x_sync();
85    if (!xname)
86      return NULL;
87
88    name = strdup(xname);
89    XFree(xname);
90
91    return name;
92 }
93