#!/usr/bin/python3

import pyatspi

def listener(e):
    if e.type.startswith("object:state-changed:") and not e.detail1:
        return

    if e.source.toolkitName != "gtk":
        return

    if not e.source.getRole() in [pyatspi.ROLE_MENU, pyatspi.ROLE_MENU_ITEM]:
        return

    print(e)

pyatspi.Registry.registerEventListener(
    listener,
    "object:state-changed:focused",
    "object:state-changed:selected",
    "object:selection-changed",
    "focus:")
pyatspi.Registry.start()
