[comp.windows.x] Help on Invisible windows

chandran@SLCS.SLB.COM (Sharat Chandran) (03/21/90)

Here is a simple, hopefully crisp question, at the Xlib level:

     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)?

I tried the obvious by setting the "background_pixmap" attribute of
the window to none.  It almost works. 

The window is "transparent" and looks normal when it is first placed.
But when I move this window, it has the contents of whatever was
underneath it the first time it was placed.  What are the window
attributes I need to set?

[I turned of backing store and save under for both the window and the
server just to make sure.]

Another related  question:  Once I create such a transparent window,
subsequent graphics calls to a window underneath it (via XPutImage)
does not show up.  I suspect that they are getting clipped.  Shouldn't
they show through?

Many thanks.

	chandran@asc.slb.com

jimf%saber@HARVARD.HARVARD.EDU (03/22/90)

|     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

rmacfarq@cs.strath.ac.uk (Roderick F MacFarquhar IE87) (03/23/90)

In article <9003210343.AA15162.chandran@SLCS.SLB.COM> chandran@SLCS.SLB.COM (Sharat Chandran) writes:
>     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)?

I'd like to do something similar, though not for the same reason I suspect.

What I want is a transparent window the full size of the screen which
is always on the top of the window `stack' and which can intercept all
events from the user and filter out some for its own use and pass the
rest on.  It will _not_ respond to the user directly who won't know
its there and it will not prevent what's underneath it being updated
(exposure events etc.)

(BTW it's for a purely innocent purpose before anyone suspects
otherwise) 

Is there a way to do this (or something which would provide the same
intercept facilities) at the application level ?  (if not its back
into the server code ..splash.. . glug . glug . glug )

Thanks

  Roddy

_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
 Roderick MacFarquhar - Information Eng IV, Strathclyde University 
 Janet rmacfarq@cs.strath.ac.uk    Internet rmacfarq%cs.strath.ac.uk@nsf.ac.uk 
 Voice (but I'm rarely home - sob :'{ ) +44 (0)41 339 0263 
 'How many fibres are intertwined in a shreaded wheat biscuit ?' 
~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~"~