From: nfp@cs.brown.edu (Noah Parker)
Subject: Reading from dialbox with Xt
Organization: Department of Computer Science, Brown University
Distribution: comp
Date: Sun, 30 Aug 1992 23:11:33 GMT

    I'm trying to query a set of dials (a dialbox) attached
to the HFT (console) of an IBM RS/6000 while running X.  I
want to do this asychronously, using event handlers.

    It works fine when I create a window, select input the
dials device, and then make multiple calls to XNextEvent.
However, if I try to use Xt, create a widget, select input
from the dials device, and finally add an event handler for
that device.  The event handler gets called, but with
*keyboard* device events, not dials!  

    The 'DialRotateMask' and the 'KeyReleaseMask' are
identical in the X header files.  They are both (1L << 1).
Info Explorer explains that it is acceptable to overload
these masks since the event handler can look at the .type
field of the event structure to determine which device
created the event.  The keyboard device event type is '3',
while the dial rotate event type is '64'.  The only value we
get in our dial rotate callback is 3, the keyboard,
triggered by keyboard key release events.  (See code
following message.)

   Has anyone ever read dialbox input using event handlers
in X/Xt?  Does anyone have any ideas why Xt would ignore
dial rotate events?

Any help/insight would be greatly appreciated.

Noah Parker   <nfp@cs.brown.edu>

-----------------------  specifics:  -----------------------

This is what works:   (abbreviated)
--------

   XRotateEvent *rotev;
   XEvent rep;

   /* set up display, make a window, etc... */
   disp = XOpenDisplay(NULL);
   rootwin   = RootWindow(disp,0);
   madewin = XCreateSimpleWindow(disp,rootwin, ...)
   XMapWindow(disp,madewin);

   /* select dials, which dials, etc. */

   XEnableInputDevice(disp,DEVDIAL);

   XSelectDeviceInput(disp,DEVDIAL,madewin,DialRotateMask);

   XSelectDial(disp, madewin, AllDialsMask);

   XSelectInput(disp,madewin,KeyPressMask | ButtonPressMask |
      DialRotateMask  );

   /* read events, display any dial rotations */
   while(1) {
      XNextEvent(disp,&rep);
      switch( rep.type ) {
         case DialRotate:
            /* great, we got a dial event, display values */
            rotev = (XRotateEvent *) &rep;
            fprintf(stderr,"dial rotate:  #%d, val = %d\n",
               rotev->dialnum,
               rotev->dialval);
         default:
            fprintf(stderr,"event type: %d\n",rep.type);
      } /* end switch */
   }

--------

... now, what I want to do is read this asychronously,
using event handlers:

--------

   /* 
    *  (widget is the window I made in this test program, 
    *   analogous to the window in previous example) 
    */
    XtAddEventHandler(widget, DialRotateMask, (Boolean) FALSE,
                     (XtEventHandler) DEV_dial_rotate, (caddr_t) NULL);

    ...

/* the event handler: */

void
DEV_dial_rotate(
   Widget,
   caddr_t            client_data,
   XDialRotatedEvent *xevent
   )
{
   DEVdials *dev;

   /* the only thing we ever get here is keyboard key release events */
   fprintf(stderr,"Dial callback got event type: %d\n",xevent->type);

}

--------

Newsgroups: comp.unix.aix