def dispatch_event(self, event):
        """
        Takes an event dict.  Logs the event if needed and cleans up the dict
        such as setting the index needed for composits.
        """
        if self.config["debug"]:
            self.py3_wrapper.log(f"received event {event}")

        # usage variables
        event["index"] = event.get("index", "")
        instance = event.get("instance", "")
        name = event.get("name", "")

        # composites have an index which is passed to i3bar with
        # the instance.  We need to separate this out here and
        # clean up the event.  If index
        # is an integer type then cast it as such.
        if " " in instance:
            instance, index = instance.split(" ", 1)
            try:
                index = int(index)
            except ValueError:
                pass
            event["index"] = index
            event["instance"] = instance

        if self.config["debug"]:
            self.py3_wrapper.log(
                'trying to dispatch event to module "{}"'.format(f"{name} {instance}".strip())
            )

        # guess the module config name
        module_name = f"{name} {instance}".strip()

        default_event = False
        module_info = self.output_modules.get(module_name)
        module = module_info["module"]
        # execute any configured i3-msg command
        # we do not do this for containers
        # modules that have failed do not execute their config on_click
        if module.allow_config_clicks:
            button = event.get("button", 0)
            on_click = self.on_click.get(module_name, {}).get(str(button))
            if on_click:
                task = EventClickTask(module_name, event, self, on_click)
                self.py3_wrapper.timeout_queue_add(task)
            # otherwise setup default action on button 2 press
            elif button == 2:
                default_event = True

        # do the work
        task = EventTask(module_name, event, default_event, self)
        self.py3_wrapper.timeout_queue_add(task)

        Takes an event dict.  Logs the event if needed and cleans up the dict
        such as setting the index needed for composits.
        
py3status/events.py