# Path: pwm/ffi/xcb.py
# class XcbError(Exception):
# class Cookie:
# class Xcb:
#     def __init__(self, error):
#     def __str__(self):
#     def __init__(self, name, value):
#     def __getattr__(self, name):
#     def reply(self):
#     def check(self):
#     def __init__(self):
#     def __getattr__(self, name):
#         def request(func, *args, **kwargs):
#     def connect(self, display=None):
#     def mask(self, masks):


from pwm.ffi.xcb import xcb
    """Query the X server for an ATOM identifier using a name. If we've already
    cached the identifier, then don't contact the X server.

    If the identifier is not cached, it is added to the cache.

    If 'only_if_exists' is false, then the atom is created if it does not exist
    already.
    """
    global _atom_cache

    if atom_name in _atom_cache:
        return _atom_cache[atom_name]

    atom = xcb.core.intern_atom_unchecked(only_if_exists, len(atom_name),
                                          atom_name.encode("UTF-8"))
    atom = atom.reply().atom
    _atom_cache[atom_name] = atom

    return atom


def get_name(atom):
    try:
        reply = xcb.core.get_atom_name(atom).reply()
    except:
        reply = None

    if not reply:
        return ""


# Path: pwm/ffi/xcb.py
# class XcbError(Exception):
# class Cookie:
# class Xcb:
#     def __init__(self, error):
#     def __str__(self):
#     def __init__(self, name, value):
#     def __getattr__(self, name):
#     def reply(self):
#     def check(self):
#     def __init__(self):
#     def __getattr__(self, name):
#         def request(func, *args, **kwargs):
#     def connect(self, display=None):
#     def mask(self, masks):


# Path: pwm/atom.py
from pwm.ffi.xcb import xcb

    """Query the X server for an ATOM identifier using a name. If we've already
    cached the identifier, then don't contact the X server.

    If the identifier is not cached, it is added to the cache.

    If 'only_if_exists' is false, then the atom is created if it does not exist
    already.
    """
    global _atom_cache

    if atom_name in _atom_cache:
        return _atom_cache[atom_name]

    atom = xcb.core.intern_atom_unchecked(only_if_exists, len(atom_name),
                                          atom_name.encode("UTF-8"))
    atom = atom.reply().atom
    _atom_cache[atom_name] = atom

    return atom


def get_name(atom):
    try:
        reply = xcb.core.get_atom_name(atom).reply()
    except:
        reply = None

    if not reply:
        return ""


    name = xcb.ffi.string(xcb.get_atom_name_name(reply), reply.name_len)