import Wayland open Wayland Protocols def Wayland.Protocols.WlDisplay.roundtrip {σ : Type} (display : WlDisplay) (handler : DisplayM σ Unit) : DisplayM σ Unit := do let callback ← display.sync callback.listen fun | .done _ => do callback.keep handler structure State where count : Int partial def nextTimer : DisplayM Int Unit := do _ ← DisplayM.registerTimer 16ms do let newCount := (← get) + 1 set newCount DisplayM.liftIO (IO.println s!"Timer tick {newCount}") nextTimer def launch : DisplayM State Unit := do _ ← DisplayM.registerSignal .SIGINT do DisplayM.liftIO (IO.println "Received SIGINT") DisplayM.requestQuit DisplayM.zoom (mk_lens count) nextTimer let disp : WlDisplay ← DisplayM.getDisplay disp.roundtrip do DisplayM.liftIO (IO.println "Roundtrip complete") def main : IO Unit := DisplayM.run launch { count := 0 }