Path: utzoo!attcan!uunet!jarthur!usc!snorkelwacker!bloom-beacon!HARVARD.HARVARD.EDU!jimf%saber From: jimf%saber@HARVARD.HARVARD.EDU Newsgroups: comp.windows.x Subject: Re: Help on Invisible windows Message-ID: <9003211620.AA16247@armory> Date: 21 Mar 90 16:20:27 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 70 | How do I create the "invisible (shadow/outline) windows" that |"twm" uses when a user moves his window (so that the user knows where |the destination is going to be)? The simplest way is something like: -- cut here -- get_window_location(disp, width, height, rx, ry) int *rx, *ry; /* return location */ int width, height; /* width and height to outline */ { int x, y; Display *disp; Window root; long junk; XGCValues gcv; GC gc; union { XEvent generic; XAnyEvent any; XButtonEvent button; XMotionEvent pointer; } xevent; scrn= DefaultScreen(disp); root= RootWindow(disp, scrn); XQueryPointer(disp, root, &junk, &junk, &x, &y, &junk, &junk, &junk); gcv.function= GXxor; gcv.foreground= 1; gcv.subwindow_mode= IncludeInferiors; gc= XCreateGC(disp, root, GCFunction | GCForeground | GCSubwindowMode, &gcv); /* get mean */ XGrabPointer(disp, root, False, ButtonPressMask | PointerMotionMask, GrabModeSync, GrabModeSync, None, None, CurrentTime); /* zorch the root window */ XDrawRectangle(disp, root, gc, x, y, width, height); for (;;) { XNextEvent(disp, &xevent); switch(xevent.any.type) { case ButtonPress: goto done; /* nasty */ case MotionNotify: XDrawRectangle(disp, root, gc, x, y, width, height); x= xevent.pointer.x; y= xevent.pointer.y; XDrawRectangle(disp, root, gc, x, y, width, height); } } done: /* unzorch the root window */ XDrawRectangle(disp, root, gc, x, y, width, height); XUngrabPointer(disp, CurrentTime); /* sigh of relief */ XFreeGC(disp, gc); *rx= x; *ry= y; } -- cut here -- That's quick and dirty but it works pretty well. You can get a lot more sophisticated (especially if you're using color) and you should probably consider error checking the XGrabPointer call. Happy hacking, jim frost saber software jimf@saber.com