[comp.windows.x] Athena form widget resize bug

pusateri@duke.cs.duke.edu (Thomas J. Pusateri) (09/08/90)

I'm having a problem getting an athena widget program to resize correctly.
The resize is triggered by an external program through a socket interface.
This sometimes happens very quickly even before the toplevel widget is
completely drawn.

I whipped up a shorter demo program to display the behavior. Basically
it doesn't work if you don't sleep for a while before sending a message
through the pipe to trigger the resize request.

I'm not sure if its a bug, but I sure do hate putting sleeps in my code
in order to make it work. Anybody have any ideas?

Thanks for any info.

Tom Pusateri

pusateri@nbsr.duke.edu
pusateri@macbeth.cs.duke.edu

----------------------- Cut Here -------- demo.c -----------------------
/*
	Compile with:
		cc -o demo demo.c -lXaw -lXmu -lXt -lXext -lX11
	Try running with:
		demo

		demo -geometry +100+100

	Resizing does not work with no delay before the resize request.
	If geometry is specified, the resize will work with a delay of
	1 second. But if the corner geometry position is specified by
	pointing and clicking, you have to sleep 2 seconds in order for
	it to work.

	Now compile with:
		cc -o demo2 -DSLEEP demo.c -lXaw -lXmu -lXt -lXext -lX11

	Making the parent sleep for 2 seconds before sending the
	resize message works fine with either invocation. This is the case
	we normally see with other applications since a resize request
	is not usually generated so quickly.

*/

#include <stdio.h>		/* C standard I/O library	   */
#include <sys/wait.h>
#include <X11/Intrinsic.h>	/* X toolkit initrinsics	   */
#include <X11/StringDefs.h>	/* X String definitions		   */
#include <X11/Shell.h>		/* Athena shell widget defs	   */
#include <X11/Xaw/Cardinals.h>	/* X type definitions		   */
#include <X11/Xaw/Form.h>	/* Athena form widget defs	   */
#include <X11/Xaw/Command.h>	/* Athena command widget defs	   */
#include <X11/Xaw/AsciiText.h>	/* More Athena text widget defs	   */

#ifndef lint
static char RCSid[]=
"$Id$";
#endif

String fallback_resources[] = { 
    "*Text*editType:		append",
    "*Text*autoFill:		on",
    "*Command*shapeStyle:	oval",
    "*allowShellResize:		True",
    NULL,
};
 
int pipefd[2];		/* holds file descriptors of pipe */
Widget text;

/**********************************************************************
 *
 *                 Resize Demonstration Program
 *
 *  Date:	9/7/90
 *  Author:	Thomas Pusateri  (pusateri@nbsr.duke.edu)
 * 
 ***********************************************************************/

main(argc,argv)
int argc;
char *argv[];
{
    void msg_callback(),	/* callback function when input received */
	 quit_callback();	/* exit callback function */

    XtAppContext context;
    Arg arg[10];		/* holds argument list when creating widgets */
    Widget toplevel,
	   form,
	   name,
	   quit;
    Cardinal n;			/* number of arguments passed to create */
    int count,			/* number of bytes written */
	pid;			/* process id of child */
    char buf[80],		/* buffer space to hold string written */
	 txt[100];

    if (pipe(pipefd) < 0) {
	perror("pipe");
	exit(1);
    }

    pid = fork();

    if (pid == 0) {	/* child process */

	toplevel = XtAppInitialize(&context, "Demo", NULL, ZERO, &argc, argv,
	    fallback_resources, NULL, ZERO);

	(void) XtAppAddInput(context, pipefd[0], XtInputReadMask, msg_callback,
			  (XtPointer) NULL);

			/* the form widget contains all of the other widgets */
	form = XtCreateManagedWidget("form",formWidgetClass,
		toplevel, (Arg *) NULL, 0);


	n = 0;		/* this widget provides a program title */
	XtSetArg(arg[n], XtNborderWidth, 0);			n++;
	XtSetArg(arg[n], XtNlabel, "Tom's Demo Program");	n++;
	name = XtCreateManagedWidget("name", labelWidgetClass, form, arg, n);


	(void) strcpy(txt, "Ok");
	n = 0;
	XtSetArg(arg[n], XtNvertDistance, 10);			n++;
	XtSetArg(arg[n], XtNfromVert, name);			n++;
	XtSetArg(arg[n], XtNheight, (Dimension) 150);		n++;
	XtSetArg(arg[n], XtNtype, XawAsciiString);		n++;
	XtSetArg(arg[n], XtNstring, txt);			n++;
	XtSetArg(arg[n], XtNresizable, True);			n++;
	XtSetArg(arg[n], XtNscrollHorizontal, XawtextScrollWhenNeeded);	n++;
	XtSetArg(arg[n], XtNscrollVertical, XawtextScrollAlways);	n++;
	text = XtCreateManagedWidget("text",asciiTextWidgetClass, form, arg, n);


	n = 0;		/* this widget is a quit button */
	XtSetArg(arg[n], XtNvertDistance, 15);			n++;
	XtSetArg(arg[n], XtNfromVert, text);			n++;
	XtSetArg(arg[n], XtNlabel, "Quit");				n++;
	quit = XtCreateManagedWidget("quit", commandWidgetClass, form,arg,n);
	XtAddCallback(quit, XtNcallback, quit_callback, (XtPointer) NULL);

	XtRealizeWidget(toplevel);

	XtAppMainLoop(context);		  /* let X windows process events */

    }
    else if (pid > 0) {		/* parent process */

	close(pipefd[0]);	/* parent only writes */

#ifdef SLEEP
	sleep(2);
#endif

	(void) strcpy(buf, "This is a test");
	count = write(pipefd[1], buf, strlen(buf));
	if (count < 0)
	    perror("write failed");

	pid = wait((int *) NULL);
	if (pid < 0)
	    perror("no child");

	close(pipefd[1]);
    }
    else {
	perror("fork");
	exit(1);
    }
}

void msg_callback(widget, clientData, callData)
Widget widget;                  /* unused */
caddr_t clientData;             /* unused */
caddr_t callData;               /* unused */
{
	int count;
	Arg arg[2];
	char newbuf[80];

	count = read(pipefd[0], newbuf, sizeof(newbuf));
	if (count < 0)
		perror("read");
	else {
		XtSetArg(arg[0], XtNwidth, 300);
		XtSetValues(text, arg, ONE);
	}
}

void quit_callback(widget, clientData, callData)
Widget widget;                  /* unused */
caddr_t clientData;             /* unused */
caddr_t callData;               /* unused */
{
	exit(0);
}

tpf@jdyx.UUCP (Tom Friedel) (09/09/90)

pusateri@duke.cs.duke.edu (Thomas J. Pusateri) writes:

>I'm having a problem getting an athena widget program to resize correctly.
>The resize is triggered by an external program through a socket interface.
>This sometimes happens very quickly even before the toplevel widget is
>completely drawn.

I presume this is an operating system problem.  When I run this on system V
i get 

Select error: not typewriter
repeated many times.

This is from _XtWaitForNextEvent in NextEvent.c in the Xt ib directory.

Looking at the code it was not clear what file desciptors are normally 
being passed to select() in this function that might cause this.  Can 
someone help me here?

tom friedel
-- 
Tom Friedel  JDyx Enterprises (404) 320-7624 tpf@jdyx.UUCP 
Unix BBS:  (404) 325-1719 <= 2400 ; (404) 321-5020 >= 2400
"Live simply, so that others may simply live."