void VkHypViewer::eventHandler(XEvent *event) {
  // may need to drain away events which occurred while HypView was busy
  int tossEvents = hv->getTossEvents();
  if (tossEvents) {
#ifdef HYPVK
    XtAppContext app = theApplication->appContext();
#else
    XtAppContext app = XtWidgetToApplicationContext (glxarea);
#endif
    XEvent e;
    while (XtAppPending(app)) {
      XtAppNextEvent(app, &e);     // just throw it away
      XtDispatchEvent(&e);
    }
    hv->setTossEvents(0);
    // if one of these ignored events was the rightmouse then 
    // Motif has already handed us input focus. must give it back! 
    XUngrabPointer(XtDisplay(glxarea), CurrentTime);
  }

  switch (event->type) {
  case ButtonPress:
  case ButtonRelease:
    hv->mouse(event->xbutton.button-1, 
	      event->xmotion.state&(Button1Mask|Button2Mask|Button3Mask),
	      event->xmotion.x, event->xmotion.y, 
	      event->xmotion.state&(ShiftMask), 
	      event->xmotion.state&(ControlMask)
	      );
    break;
  case MotionNotify:
    if (event->xmotion.state&(Button1Mask|Button2Mask|Button3Mask)) {
      hv->motion(event->xmotion.x, event->xmotion.y,
		 event->xmotion.state&(ShiftMask), 
		 event->xmotion.state&(ControlMask)
		 );
    } else {
      hv->passive(event->xmotion.x, event->xmotion.y,
		  event->xmotion.state&(ShiftMask), 
		  event->xmotion.state&(ControlMask)
		  );
    }
    break;
  case ConfigureNotify:
    hv->reshape(event->xconfigure.width, event->xconfigure.height);
    break;
  case Expose:
    hv->idle(1);
    hv->drawFrame();
    break;
  }
  // make the idle work right
  if (XtPending()) {
    hv->idle(0);
  }
}
Example #2
0
int
X11_Input(REQUEST *request, RESPONSE *response)
{
    XEvent ev;
    int nfds;
    fd_set rfds;

    switch (request->option) {

    case char_option:
        nfds = ConnectionNumber(display) > fileno(request->fp) ?
            ConnectionNumber(display) :
        fileno(request->fp);

        for (;;) {

            /* first read off the queue before doing the select */
            while (XtPending()) {
                XtNextEvent(&ev);
                XtDispatchEvent(&ev);
            }

            /* block on ConnectionNumber and request->fp */
            /* PN: added fd_set * casting */
            FD_ZERO(&rfds);
            FD_SET(fileno(request->fp), &rfds);
            FD_SET(ConnectionNumber(display), &rfds);
            select (nfds + 1,
                    &rfds,
                    NULL,
                    NULL,
                    NULL);

            /* handle X events first */
            if (FD_ISSET (ConnectionNumber(display), &rfds))
                /* handle ALL X events */
                while (XtPending()) {
                    XtNextEvent(&ev);
                    XtDispatchEvent(&ev);
                }

            if (FD_ISSET (fileno(request->fp), &rfds))
                goto out;

        }
        break;

    case click_option:
        /* let's fake this */
        response->reply.graph = lasthardcopy;
        break;

    case button_option:
        /* sit and handle events until get a button selection */
        internalerror("button_option not implemented");
        response->option = error_option;
        return 1;
        break;

    case checkup_option:
        /* first read off the queue before doing the select */
        while (XtPending()) {
            XtNextEvent(&ev);
            XtDispatchEvent(&ev);
        }
        break;

    default:
        internalerror("unrecognized input type");
        response->option = error_option;
        return 1;
        break;
    }

out:
    if (response)
        response->option = request->option;
    return 0;
}