Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!ATHENA.MIT.EDU!kit From: kit@ATHENA.MIT.EDU (Chris D. Peterson) Newsgroups: comp.windows.x Subject: Re: Widgets and Xlib Message-ID: <8901262004.AA03005@DORA.MIT.EDU> Date: 26 Jan 89 20:04:33 GMT References: <33500005@iuvax> Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 75 > From: beckman@iuvax.cs.indiana.edu > I am using the HP Widget set. How do I use the Xlib graphic primitives > within a widget to draw lines, boxes, etc. I haven't had any success. > I have tried lots of different things, the most recent being this: > > Display *dpy; > Drawable win; > GC gc; > > dpy = XtDisplay(widget) > win = XtWindow(widget); > gc = XtGetGC(widget); > > XDrawLine(dpy,win,gc,0,0,100,100); This is relatively common problem that many people run into when beginning to program in X because X is an asynchronous environment. This is necessary to achieve network transparency and not be horribly slow. Here are some concepts that you need to be aware of when programming in X. 1) X is a client server model, all application programs are clients that because X has a standard protocol are able to talk to any X server. 2) Because X is an asynchronous environment you are never sure when your X functions will actually be processed by the X server. 3) X does not remember what is drawn into the window, and it is the client's responsibility to repair any damage done to his window. 4) Since window managers can intercept mapping events you are never sure when you client's windows will actually get mapped, unless you are looking for the correct events. Thus the program above may end up drawing the line before the window is visible on the screen. All good X clients are responsible for repainting their contents when these contents become damaged. The server will notify the client that some part of his window is damaged and that it needs to be repainted by issuing an Expose event on that window for each rectangular region that has been damaged. Clever clients will only repaint the particular region of the screen that has been damaged. Clients that are not quite this clever can repaint the entire window when an expose event is received for a particular window. It is important to check the exposure count field (count == 0) to make sure that you do not repaint the window more often than necessary. If you are using the X toolkit the easiest way to receive expose events is either: 1) Add an entry in the translation table and register an action that should be performed on that entry. 2) Us XtAddEventHandler to register a function that should be called when an exposure event is received. References: Xlib Manual Chapter 8 : Events and Event Handling. Xtk Manual Chapter 7 : Event Management. Chapter 10 : Translation Management. Appendix B : Translation Table Syntax. Chris D. Peterson MIT X Consortium / Project Athena Net: kit@athena.mit.edu Phone: (617) 253 - 1326 USMail: MIT - Room E40-321 77 Massachusetts Ave. Cambridge, MA 02139