#line 14 "test.c-nw" #include #include #include #include #include #include #include #include static String fallback[] = { "*rowcol.location: 0 0 300 300", "*XfwfButton.location: 0 0 110 35", "*embedded.label: Embedded!", "*borderWidth: 0", "*add.label: Add", "*quit.label: Quit", NULL, }; static XrmOptionDescRec options[] = { {"-root", ".root", XrmoptionSepArg, NULL}, }; static XtAppContext app_context; static Widget button, rowcol, toplevel, add, quit; static char *progname; static void quit_cb(Widget w, XtPointer client_data, XtPointer call_data) { XEvent event; /* Dangerous? Is Xt sufficiently reentrant? Anyway, it's just a test */ XtVaSetValues(w, XtNlabel, "waiting...", NULL); while (waitpid(-1, NULL, WNOHANG) != -1) { XtAppNextEvent(app_context, &event); XtDispatchEvent(&event); } exit(0); } static void add_cb(Widget w, XtPointer client_data, XtPointer call_data) { Widget container; XEvent event; /* Create a container widget */ container = XtVaCreateManagedWidget ("container", containerWidgetClass, rowcol, NULL); /* Wait until it is realized */ while (! XtIsRealized(container)) { XtAppNextEvent(app_context, &event); XtDispatchEvent(&event); } /* Start a new process embedded in the conteiner */ if (fork() == 0) { char s[20]; sprintf(s, "%ld", XtWindow(container)); execlp(progname, "-test", "-root", s, NULL); exit(1); } } void main(int argc, char *argv[]) { Display *display; progname = argv[0]; if (argv[0][0] == '-') { /* Embedded */ toplevel = XtAppInitializeEmbed (&app_context, "Test", options, XtNumber(options), &argc, argv, fallback, NULL, 0); button = XtVaCreateManagedWidget ("embedded", xfwfButtonWidgetClass, toplevel, NULL); XtAddCallback(button, XtNactivate, quit_cb, NULL); } else { toplevel = XtAppInitialize (&app_context, "Test", NULL, 0, &argc, argv, fallback, NULL, 0); rowcol = XtVaCreateManagedWidget ("rowcol", xfwfRowColWidgetClass, toplevel, NULL); add = XtVaCreateManagedWidget ("add", xfwfButtonWidgetClass, rowcol, NULL); XtAddCallback(add, XtNactivate, add_cb, NULL); quit = XtVaCreateManagedWidget ("quit", xfwfButtonWidgetClass, rowcol, NULL); XtAddCallback(quit, XtNactivate, quit_cb, NULL); } XtRealizeWidget(toplevel); XtAppMainLoop(app_context); }