Closed sloonz closed 3 years ago
This is working :
import asyncio
from pywayland.client import Display
display = Display()
display.connect()
loop = asyncio.new_event_loop()
loop.add_reader(display.get_fd(), lambda: display.dispatch(block=True))
reg = display.get_registry()
reg.dispatcher["global"] = print
display.flush()
loop.run_forever()
Two "traps" that are not obvious (at least for me !) and may be made more explicit somewhere (where ?) in the documentation :
get_registry()
) are not sent to the server immediately, they are sent on display.flush()
. And yes, display.get_registry()
returns a valid registry handle before the request is even sent to the server — so just because display.get_registry()
returns an handle does not means that the get_registry
request has actually been sent to the server. Blocking dispatch and roundtrip implicitly call flush (which is why the non-asyncio event loop works fine), but if you use polling (as with asyncio) instead of blocking dispatch for your event loop, you want to call display.flush()
every time you give the control back to the asyncio event loopblock=True
for display.dispatch
: without blocking, dispatch does not read anything at all from the socket
The documentation states that
Display.get_fd()
can be used to integrate the client into the program event loop ; however I cannot make it work :handle_global()
callback is never called until the wayland event loop (as opposite to the wayland event loop) is called.