mittmann@ral.rpi.edu (Michael Mittmann) (11/15/90)
I am attempting to write an X-windows application where one process sits in a loop reading the event queue for a particular window, and another process does whatever it has to do, including writing to that window. I tried to do this using is fork(), but the program doesn't run properly. A rough outline of the program is as follows: main() { /* initialization, create window, GC initialization and creation, input event selection */ /* window mapping */ XMapRaised (mydisplay, mywindow); pid = fork(); if (pid != 0){ /*event reading loop */ while (ThePopeIsCatholic) { XWindowEvent (mydisplay,mywindow,ExposureMask, &myevent); switch(myevent.type) { case Expose: printf("Expose stuff \n"); if(myevent.xexpose.count == 0) XDrawImageString(mydisplay, mywindow, mygc, 9,9,"f",1); break; case MappingNotify: XRefreshKeyboardMapping (&myevent); break; } } } else{ /* do all sorts of things, but including trying to write to the */ /* window with commands like */ XDrawImageString(mydisplay,mywindow,mygc,x_loc,y_loc,str,strlen(str)); } } The problems I'm having are: 1) The frame of the window and the rest of the window appear to be disconnected (I can change the size of the frame without affecting the window). 2) Sometimes I get errors from the XDrawImageString() command. 3) There are more but I suspect that they are all related. I suspect that what is happening is that when the process forks, each process has it's own event queue (instead of a pointer to an underlying structure), and the events are being written to one or the other depending on which is running at the time of the event. Someone must have tried this before. Is it hopeless? Should I use pipes (or X-properties) to send messages to a single process which controls the window? Should I just give up, and write the event checking into the main loop of the other program? aTdHvAaNnKcSe -mike (mittmann@ral.rpi.edu)
klee@wsl.dec.com (Ken Lee) (11/15/90)
In article <{-*^W|-@rpi.edu>, mittmann@ral.rpi.edu (Michael Mittmann) writes: |> Someone must have tried this before. Is it hopeless? Should I use |> pipes (or X-properties) to send messages to a single process which |> controls the window? Should I just give up, and write the event |> checking into the main loop of the other program? Two processes can share a window, but should not try to use the same server connection. Try opening a second connection from the child process. You can use any X resource (except GCs) on any connection to the same X server. -- Ken Lee DEC Western Software Laboratory, Palo Alto, Calif. Internet: klee@wsl.dec.com uucp: uunet!decwrl!klee
etaylor@wilkins.iaims.bcm.tmc.edu (Eric Taylor) (11/15/90)
I ran into this a long time ago and seem to remember that one of the forking processes must close their connection to the X server. If they want to do X calls they have to open another connection. -- Eric Taylor Baylor College of Medicine etaylor@wilkins.bmc.tmc.edu (713) 798-3776