#!/usr/bin/python3

import pyatspi

def listener(e):
    if not e.detail1:
        return

    if e.type.endswith("defunct"):
        return

    if e.source.getRole() != pyatspi.ROLE_UNKNOWN:
        return

    print(e.type, e.source, e.source.description)

pyatspi.Registry.registerEventListener(listener, "object:state-changed")
pyatspi.Registry.start()
