From: Axel S. <A....@ke...> - 2007-06-21 14:08:08
|
On Thu, 2007-06-21 at 20:26 +1000, Mark Wassell wrote: > Hi, > > I am having a go at getting AFRP to work with Gtk2Hs. The thing I am > trying to get my head around is the following: > > AFRP supplies a function with signature: > > reactimate :: IO a > -> (Bool -> IO (DTime, Maybe a)) > -> (Bool -> b -> IO Bool) > -> SF a b > -> IO () > > The first arg is an IO action for initialization, the second is an IO > action for sensing of system input and the third is an IO action for > outputting the system output. The full comment for the function is below. > > I can supply a function that does the output, but the system input > function is the problem as there is nothing like this in Gtk2Hs (or is > there?) > > I thought of having the keyboard press callback put an event into a > queue and then have my reactimate function run in a seperate thread. My > input function to get events would then pick up from this queue the > latest set of events. The system output function is fine as I can just > call the Gtk2Hs render functions in the usual way (?). > > Is this the right way to go about it? Has anyone tried this before? My guess: for the 'sense' action, you want to run the main loop and pass back anything that has happened. You could: create one global channel and add callback for every event that you're interested in. Each callback will post into that channel. For running the loop until something interesting has happened, you can call 'Graphics.UI.Gtk.General.mainIterationDo'. Afterwards you check the global channel for any callback that have left events in there. There is no need to spawn a new process. Hope this helps, Axel. |