# Path: tilenol/event.py
# class Event(object):
# 
#     def __init__(self, name=None):
#         self.name = name
#         self._listeners = []
#         self._worker = None
# 
#     def listen(self, fun):
#         self._listeners.append(fun)
# 
#     def unlisten(self, fun):
#         self._listeners.remove(fun)
# 
#     def emit(self):
#         log.debug("Emitting event %r", self.name)
#         if self._worker is None and self._listeners:
#             self._worker = gethub().do_spawn(self._do_work)
# 
#     def _do_work(self):
#         try:
#             log.debug("Processing event %r", self.name)
#             for l in self._listeners:
#                 l()
#         finally:
#             self._worker = None
# 
# Path: tilenol/xcb/core.py
# class Rectangle(namedtuple('_Rectangle', 'x y width height')):
#     __slots__ = ()
# 
# Path: tilenol/commands.py
# class CommandDispatcher(dict):
# 
#     def __init__(self):
#         self.events = Events()
# 
#     def __setitem__(self, name, value):
#         super().__setitem__(name, value)
#         ev = self.events.get(name)
#         if ev is not None:
#             ev.emit()
# 
#     def call(self, obj, meth, *args):
#         getattr(self[obj], 'cmd_' + meth)(*args)
# 
#     def callback(self, *args):
#         return partial(self.call, *args)


from zorro.di import di, has_dependencies, dependency
from tilenol.event import Event
from .xcb import Rectangle
from tilenol.commands import CommandDispatcher
        self.leftslices = []
        self.rightslices = []
        self.updated = Event('screen.updated')
        self.bars_visible = True
        self.group_hooks = []

    def add_group_hook(self, fun):
        self.group_hooks.append(fun)

    def remove_group_hook(self, fun):
        self.group_hooks.remove(fun)

    def set_group(self, group):
        self.group = group
        for h in self.group_hooks:
            h()

    def cmd_focus(self):
        self.group.focus()

    def set_bounds(self, rect):
        self.bounds = rect
        x, y, w, h = rect
        if self.bars_visible:
            for bar in self.topbars:
                bar.set_bounds(Rectangle(x, y, w, bar.height))
                y += bar.height
                h -= bar.height
            for bar in self.bottombars:
                h -= bar.height

# Path: tilenol/event.py
# class Event(object):
# 
#     def __init__(self, name=None):
#         self.name = name
#         self._listeners = []
#         self._worker = None
# 
#     def listen(self, fun):
#         self._listeners.append(fun)
# 
#     def unlisten(self, fun):
#         self._listeners.remove(fun)
# 
#     def emit(self):
#         log.debug("Emitting event %r", self.name)
#         if self._worker is None and self._listeners:
#             self._worker = gethub().do_spawn(self._do_work)
# 
#     def _do_work(self):
#         try:
#             log.debug("Processing event %r", self.name)
#             for l in self._listeners:
#                 l()
#         finally:
#             self._worker = None
# 
# Path: tilenol/xcb/core.py
# class Rectangle(namedtuple('_Rectangle', 'x y width height')):
#     __slots__ = ()
# 
# Path: tilenol/commands.py
# class CommandDispatcher(dict):
# 
#     def __init__(self):
#         self.events = Events()
# 
#     def __setitem__(self, name, value):
#         super().__setitem__(name, value)
#         ev = self.events.get(name)
#         if ev is not None:
#             ev.emit()
# 
#     def call(self, obj, meth, *args):
#         getattr(self[obj], 'cmd_' + meth)(*args)
# 
#     def callback(self, *args):
#         return partial(self.call, *args)


# Path: tilenol/screen.py
from zorro.di import di, has_dependencies, dependency
from tilenol.event import Event
from .xcb import Rectangle
from tilenol.commands import CommandDispatcher

        self.leftslices = []
        self.rightslices = []
        self.updated = Event('screen.updated')
        self.bars_visible = True
        self.group_hooks = []

    def add_group_hook(self, fun):
        self.group_hooks.append(fun)

    def remove_group_hook(self, fun):
        self.group_hooks.remove(fun)

    def set_group(self, group):
        self.group = group
        for h in self.group_hooks:
            h()

    def cmd_focus(self):
        self.group.focus()

    def set_bounds(self, rect):
        self.bounds = rect
        x, y, w, h = rect
        if self.bars_visible:
            for bar in self.topbars:
                bar.set_bounds(Rectangle(x, y, w, bar.height))
                y += bar.height
                h -= bar.height
            for bar in self.bottombars:
                h -= bar.height

                bar.set_bounds(Rectangle(x, y+h, w, bar.height))