Advanced Search
Mail us
Home    Manuel    Links    Faq    Submit a tcl/tk Reference    Contact Us

    Some examples tcl/tk codes     Man of Bwidget     Man of blt     mkwidget screenshots     TkOgl     Video Demo real.

  mix interactions between Xt and Tk/Tcl?
  YIP Chi Lap [Beta]  
	I have come up with a CPU hogging polling loop that
works (till now) for my application which not much
direct interaction between a Tk window and an Xt window is made.
(e.g., it won`t draw something on a Tk window by a Xt-dispatched routine)

  XEvent xevent;
  for (;;)
    if (XtAppPending(appcontext))

[ From David C Mudie  ]
	We use the main event loop below.  The basic idea
is to watch for events arriving from either the Xt server
connection or the Tk server connection and then call
the library dispatchers.

	The code fragment below will need to be cleaned up for
your usage; there are some missing include statements
and global declarations buried elsewhere in the file.

/* Allow Tcl/Tk and Xt to work at the same time. */
void tkGo(void)
  extern Widget topLevel;
  int width = ulimit(4, -1);
  fd_set readfds;
  struct timeval timeout;
  int nfds;
  int tkfd = ConnectionNumber(Tk_Display(mainWindow));
  int xtfd = ConnectionNumber(XtDisplay(topLevel));

  Tcl_VarEval(interp, "update", NULL);
  while (1) {

    /* Select on X server connections to wait for event. */
    /* Timeout every half second to allow processing of non-X events */

    FD_SET(tkfd, &readfds);
    FD_SET(xtfd, &readfds);
    timeout.tv_sec = 0;
    timeout.tv_usec = 500000;

    nfds = select(width, &readfds, NULL, NULL, &timeout);
    if (nfds < 0 && errno != EINTR) {
    } else if (nfds == 0) {
      /* printf("timeout
"); */

    while (XtPending()) {

    while (Tk_DoOneEvent(1)) {
      /* do nothing */
    if (mainWindow == NULL) {
//      Tcl_DeleteInterp(interp);
//      Tcl_DStringFree(&command);
      Tcl_Eval(interp, "exit");

[ From Davide Frisoni  ]
	One may use Xt properties to communicate between different