Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!mittmann From: mittmann@ral.rpi.edu (Michael Mittmann) Newsgroups: comp.windows.x Subject: Forking a process and allowing both to use the window Summary: I think I'm creating duplicate event queues. Keywords: fork, event queue, Message-ID: <{-*^W|-@rpi.edu> Date: 14 Nov 90 17:27:50 GMT Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 66 Nntp-Posting-Host: ral.rpi.edu 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)