[comp.windows.x] demo for "fix2 patch to window.c destroys backing_store"

hiebeler@TURING.CS.RPI.EDU (Dave Hiebeler) (04/20/89)

  Here is a small program to demonstrate the problem with
backing_store.  I pretty much cut away everything except
the bare minimum, although there are still probably a few
things in there that don't need to be.
  I hope this problem is reproducable.  If it only happens on the
server here at RPI, well, the sysadmin probably won't be terribly
happy about that.
  If someone runs this on a Sun 3/50 running SunOS 3.5 and X11R3,
I'd like to know if it works (and also whether or not the 2 lines
    if (!pWin->firstChild)
	return;
are in .../server/dix/window.c at the beginning of UnmapSubwindows().


/*
 * demo.c
 *
 * On a Sun 3/50 running SunOS 3.5, this works on an X11R3 server
 * that has not had the "fix2" patch to window.c installed, but
 * does not work on a server which has had "fix2" installed.
 *  The symptoms are that when you scroll part of the image away,
 * then scroll it back, the image is erased (until you click on
 * the redraw button).
 *
 *  Click on the redraw button to generate the original image.
 *
 *   compile with:
 *     cc -g demo.c -o demo -lXaw -lXmu -lXt -lX11
 *
 */

#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Box.h>
#include <X11/Command.h>
#include <X11/Scroll.h>
#include <X11/Viewport.h>

#include <stdio.h>
#include <sys/types.h>


#define XSIZE 1152
#define YSIZE 900

#define NODE_SIZE 48


Window draw_window;
GC graphics_context, inverse_graphics_context, line_gc;
XFontStruct *myfont;
Font myFont;
XColor black, white;
Display *display;
Widget
    control_rootwidget,		/* top level control-panel widget */
      control_box,		/* main box with important buttons */
        quit_widget,
        redraw_widget,
    draw_rootwidget,		/*  top level drawing-area widget */
      draw_viewport,
        draw_box;			/* box to draw stuff in */



void quit_proc(), network_proc(), init_control_box(), init_draw_box(),
    redraw_proc(), draw_line();


void
quit(s)
char *s;
{
    fprintf(stderr,"%s\n",s);
    exit(1);
}


main(argc, argv)
int argc;
char **argv;
{
    Arg args[10],		/* generic argument list */
        get_args[10];	       	/* used to get argument lists */
    XGCValues xgcvals;	/* GC values */
    Colormap cmap;
    XSetWindowAttributes attributes[1];
    
    /* Start up top level stuff */
    control_rootwidget = XtInitialize(argv[0],"demo",NULL,0,&argc,argv);
    display = XtDisplay(control_rootwidget);
    /* Get the font for drawing */
    myFont = XLoadFont(display,"9x15");
    draw_rootwidget = XtCreateApplicationShell("Xmessenger.draw",
						  topLevelShellWidgetClass,
						  NULL,0);
    /* Set up default colors */
    cmap = DefaultColormap(display,DefaultScreen(display));
    XParseColor(display,cmap,"White",&white);
    XParseColor(display,cmap,"Black",&black);
    XAllocColor(display,cmap,&white);
    XAllocColor(display,cmap,&black);
    xgcvals.foreground = black.pixel;
    xgcvals.background = white.pixel;
    graphics_context = XtGetGC(control_rootwidget,GCForeground|GCBackground,
			       &xgcvals);
    xgcvals.foreground = white.pixel;
    xgcvals.background = black.pixel;
    inverse_graphics_context = XtGetGC(control_rootwidget,
				       GCForeground|GCBackground,
				       &xgcvals);
    xgcvals.foreground = black.pixel;
    xgcvals.background = white.pixel;
    line_gc = XtGetGC(control_rootwidget,GCForeground|GCBackground,
		      &xgcvals);
    init_control_box();
    init_draw_box();
    /* Ok, let's realize the main toplevel stuff and start looping */
    XtRealizeWidget(control_rootwidget);
    XtRealizeWidget(draw_rootwidget);
    /* Set backing_store on the draw_box */
    attributes[0].backing_store = Always;
    XChangeWindowAttributes(display,XtWindow(draw_box),
			    CWBackingStore,attributes);
    draw_window = XtWindow(draw_box);

    XtMainLoop();
}



void
init_control_box()
{
    Arg args[10], get_args[10];

/* Start creating the stuff in the main control-box */
    XtSetArg(args[0],XtNwidth,(XtArgVal)110);
    XtSetArg(args[1],XtNheight,(XtArgVal)40);
    control_box = XtCreateManagedWidget("control_box",compositeWidgetClass,
				     control_rootwidget,args,2);
    XtSetArg(args[0],XtNx,(XtArgVal)5);
    XtSetArg(args[1],XtNy,(XtArgVal)5);
    XtSetArg(args[2],XtNforeground,(XtArgVal)0);
    XtSetArg(args[3],XtNbackground,(XtArgVal)1);
    quit_widget = XtCreateManagedWidget("quit",commandWidgetClass,
					control_box,args,4);
    XtAddCallback(quit_widget,XtNcallback,quit_proc,NULL);
    XtSetArg(get_args[0],XtNwidth,0);
    XtGetValues(quit_widget,get_args,1);
    XtSetArg(args[0],XtNx,(XtArgVal)get_args[0].value+10);
    XtSetArg(args[1],XtNy,(XtArgVal)5);
    redraw_widget = XtCreateManagedWidget("redraw",commandWidgetClass,
					   control_box,args,2);
    XtAddCallback(redraw_widget,XtNcallback,redraw_proc,NULL);
}


void
init_draw_box()
{
    Arg args[10], get_args[10];

    /* Now for the drawing viewport */
    XtSetArg(args[0],XtNheight,(XtArgVal)500);
    XtSetArg(args[1],XtNwidth,(XtArgVal)500);
    XtSetArg(args[2],XtNallowHoriz,(XtArgVal)True);
    XtSetArg(args[3],XtNallowVert,(XtArgVal)True);
    draw_viewport = XtCreateManagedWidget("draw_viewport",
					  viewportWidgetClass,
					  draw_rootwidget, args, 4);
    /* Then, the drawing box */
    XtSetArg(args[0],XtNwidth,(XtArgVal)XSIZE);
    XtSetArg(args[1],XtNheight,(XtArgVal)YSIZE);
    draw_box = XtCreateManagedWidget("draw_box",boxWidgetClass,
				     draw_viewport,args,3);
}




void
redraw_proc()
{
    int y;

    for (y=0; y<880; y += 20)
	draw_line(10,y,1000,y);
}


void
draw_line(x0,y0,x1,y1)
int x0,y0,x1,y1;
{
    XDrawLine(XtDisplay(draw_rootwidget),draw_window,
	      graphics_context,x0,y0,x1,y1);
}


void
quit_proc(w,a,b)
Widget w;
caddr_t a,b;
{
    exit(0);
}