On Thu, Feb 14, 2008 at 5:01 AM, MacArthur, Ian (SELEX GALILEO, UK) <[EMAIL PROTECTED]> wrote: > I'm fairly sure I have not understood your explanation, so what follows > is likley to be wrong. However, on the basis of what I *think* you > asked, I don't think this is going to work as you describe it.
Sorry, I'll be more explicit. > > I'm working on an app that drives fltk from a client program. I'd > > like to be able to pass events out to the client and also for the > > client to be able to run things in fltk. > > OK, first things first. > > Which fltk variant? > What host platform(s) are you targeting? > Do your "client" and "server" run on the same host, or over a network > from different hosts, or both? > Are you convinced you have "client" and "server" the right way round for > what you hope to achieve? This is fltk1 (latest RC as of not too long ago). I'm on OS X but would like to keep platform specific stuff to a minimum. Client and server are in the same process, but different languages. I have a set of widgets written in c++, a smallish c api to create, destroy, and modify them, and then the main body of the program in haskell that uses the c api. > > So on the client end I have > > a thread which sits in a Fl::wait() loop. When the client wants to do > > some fltk stuff, it sticks the actions in a queue and calls > > Fl::awake(0). When wait() returns, it goes through the queue and does > > the actions. Now I want to be able to pull all of the UI events that > > have happened and do something with them on the client end. > > You might have to draw me a picture of this, with bright primary > colours, as I don't think I'm following the words... Here's some pseudo code: main = do msg_chan = newChannel evt_chan = newChannel forkOS (ui_handler msg_chan evt_chan) -- kick off a ui handler thread ... rest of the app, which will write fltk actions with (send_action msg_chan action) ... send_action msg_chan action = do write msg_chan action Fl::kick_fltk_out_of_wait(); ui_handler msg_chan evt_chan = forever do Fl::wait(); actions = readEverythingFrom msg_chan do received actions, which will call fltk functions ui_events = Fl::take_all_events_since_last_call(); write evt_chan ui_evts -- ship events off to the rest of the app to deal with If I could send my own custom ui events, I could have kick_fltk_out_of_wait() send a "msg arrived" event, and the ui_handler would be: evt = Fl::wait(); if evt == msg_arrived then read from msg_chan, do action else write evt_chan evt > > Also, since I am only ever calling FLTK from one thread, I don't think > > I need all the locking and unlocking. Is there a simpler way to > > interrupt wait()? I gather I could wait on an fd, but that seems > > harder than just calling Fl::awake(). If I could deliver a custom ui > > event that said "message arrived", I could know that wait() returns on > > every arriving event, and dispense with the per-window queues. > > Actually, waiting on an fd is very easy and reliable - except maybe it > doesn't always work so well on win32 systems, unfortunatley, due to > win32's odd ways... Yeah, win32 compatibility is not a big concern though I imagine I could just use a socket instead of a pipe, but Fl::awake() seems to serve the same purpose in a cross platform way. It solves the kick_fltk_out_of_wait() problem, but not the take_all_events_since_last_call() one. Unfortunately the actual notification of when an event arrives seems buried in fl_handle (in Fl_x.cxx at least), which directly delivers it to a window, with no hooks for me to get at it, at least without hacking the platform code. In that case, I'd rather do the collect events in the window trick, which, while more awkward, requires no patches to fltk. _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

