Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!swrinde!emory!mephisto!mcnc!duke!pusateri From: pusateri@duke.cs.duke.edu (Thomas J. Pusateri) Newsgroups: comp.windows.x Subject: Athena form widget resize bug Keywords: athena resize Message-ID: <652744620@macbeth.cs.duke.edu> Date: 7 Sep 90 21:57:01 GMT Organization: Duke University Computer Science Dept.; Durham, N.C. Lines: 199 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 /* C standard I/O library */ #include #include /* X toolkit initrinsics */ #include /* X String definitions */ #include /* Athena shell widget defs */ #include /* X type definitions */ #include /* Athena form widget defs */ #include /* Athena command widget defs */ #include /* 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); }