wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

xatom.c (660B)


      1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
      2  * See LICENSE file for license details.
      3  */
      4 #include "x11.h"
      5 
      6 Atom
      7 xatom(const char *name) {
      8 	void **e, **f;
      9 
     10 	e = hash_get(&atommap, name, true);
     11 	if(*e == nil) {
     12 		*e = (void*)XInternAtom(display, name, false);
     13 		f = map_get(&atomnamemap, (ulong)*e, true);
     14 		if(*f == nil)
     15 			*f = (void*)(uintptr_t)name;
     16 	}
     17 	return (Atom)*e;
     18 }
     19 
     20 char*
     21 atomname(ulong atom) {
     22 	void **e;
     23 
     24 	e = map_get(&atomnamemap, atom, true);
     25 	if(*e == nil) {
     26 		*e = XGetAtomName(display, atom);
     27 		if(*e == nil) {
     28 			map_rm(&atomnamemap, atom);
     29 			return nil;
     30 		}
     31 		*hash_get(&atommap, *e, true) = (void*)atom;
     32 	}
     33 	return *e;
     34 }
     35