------------------------------------------------------------------------------- |-- Module : Graphics.HGL.Run-- Copyright : (c) Alastair Reid, 1999-2003-- License : BSD-style (see the file libraries/base/LICENSE)---- Maintainer : libraries@haskell.org-- Stability : provisional-- Portability : non-portable (requires concurrency)---- Running graphical actions.-------------------------------------------------------------------------------moduleGraphics.HGL.Run(runGraphics-- :: IO () -> IO ())where#if !X_DISPLAY_MISSINGimportGraphics.HGL.X11.Display(getDisplayName)importGraphics.HGL.X11.Window(runGraphicsEx)#elseimportGraphics.HGL.Win32.WND(handleEvents,beginGraphics,endGraphics)importGraphics.HGL.Internals.Utilities(safeTry)importControl.Concurrent(forkIO,yield)importData.IORef(newIORef,readIORef,writeIORef)importSystem.IO.Error(try)#endif------------------------------------------------------------------ Interface------------------------------------------------------------------ | Initialize the system to do graphics, run an action while collecting-- user interface events and forwarding them to the action, and then clean-- up everything else at the end.-- The other functions of the library may only be used inside 'runGraphics'.runGraphics::IO()->IO()-- SOE, p48------------------------------------------------------------------ Implementation----------------------------------------------------------------#if !X_DISPLAY_MISSINGrunGraphicsm=dodisp<-getDisplayNamerunGraphicsExdispm#else /* X_DISPLAY_MISSING */-- We took a lot of effort to make sure that we always close the-- windows - even if "m" fails.---- Note though that we use "try" instead of "safeTry" on the call to-- "m" because it is quite normal for "m" to block (and safeTry treats-- blocking as failure).runGraphicsm=dobeginGraphicsquit<-newIORefFalsesafeTry$doforkIO(trym>>writeIORefquitTrue)yieldhandleEvents(readIORefquit)endGraphics#endif /* X_DISPLAY_MISSING */