# 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 queue import Queue
from pwm.ffi.xcb import xcb
import threading
import logging

tasks = Queue()
_thread = None


class ExitWorker(Exception):
    pass


def start():
    global _thread
    _thread = threading.Thread(target=_loop)
    _thread.daemon = True
    _thread.start()


def destroy():
    tasks.put(ExitWorker)
    _thread.join()


def _loop():
    while True:
        try:
            work = tasks.get()
            if work is ExitWorker:
                raise ExitWorker()
            work()
            xcb.core.flush()
            tasks.task_done()

# 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/worker.py
from queue import Queue
from pwm.ffi.xcb import xcb
import threading
import logging


tasks = Queue()
_thread = None


class ExitWorker(Exception):
    pass


def start():
    global _thread
    _thread = threading.Thread(target=_loop)
    _thread.daemon = True
    _thread.start()


def destroy():
    tasks.put(ExitWorker)
    _thread.join()


def _loop():
    while True:
        try:
            work = tasks.get()
            if work is ExitWorker:
                raise ExitWorker()
            work()
            xcb.core.flush()
            tasks.task_done()

        except ExitWorker: