altdesktop / i3ipc-python

🐍 An improved Python library to control i3wm and sway.
http://i3ipc-python.readthedocs.io
BSD 3-Clause "New" or "Revised" License
851 stars 109 forks source link

Event change type is being ignored #126

Closed eternal-sorrow closed 5 years ago

eternal-sorrow commented 5 years ago

When I bind for example, to the window::focus event (or Event.WINDOW_FOCUS, it doesn't matter), the handler is being executed on each window event, no matter it's change type (part after ::).

budRich commented 5 years ago

was just about to post this same issue.

both these examples misbehaves: (PS, i have limited knowledge of python and asyncio stuff, the documentation is confusing with all the examples using asyncio, i first thought that was the problem...)

#!/usr/bin/env python3

import asyncio
from i3ipc.aio import Connection

def on_new_title(i3, e):
    print(f'this should only print on title change: {e.change}')

async def main():
    i3 = await Connection().connect()
    from i3ipc import Event
    i3.on(Event.WINDOW_TITLE, on_new_title)

    await i3.main()

if __name__ == "__main__":
    asyncio.run(main())
#!/usr/bin/env python3

from i3ipc import Event
from i3ipc import Connection

i3 = Connection()

def on_new_title(i3, e):
    print(f'this should only print on title change: {e.change}')

i3.on('window::title', on_new_title)

i3.main()
eternal-sorrow commented 5 years ago

Oh, it happens not only with aio, but with old API too? I didn't test it.

UPD: yes, it does.

acrisci commented 5 years ago

:+1: There's a fix in the latest release with regression tests.