home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / aix / 9210 < prev    next >
Encoding:
Text File  |  1992-08-30  |  3.3 KB  |  116 lines

  1. Newsgroups: comp.unix.aix
  2. Path: sparky!uunet!brunix!doorknob!nfp
  3. From: nfp@cs.brown.edu (Noah Parker)
  4. Subject: Reading from dialbox with Xt
  5. Message-ID: <NFP.92Aug30181133@gano.cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Department of Computer Science, Brown University
  8. Distribution: comp
  9. Date: Sun, 30 Aug 1992 23:11:33 GMT
  10. Lines: 104
  11.  
  12.     I'm trying to query a set of dials (a dialbox) attached
  13. to the HFT (console) of an IBM RS/6000 while running X.  I
  14. want to do this asychronously, using event handlers.
  15.  
  16.     It works fine when I create a window, select input the
  17. dials device, and then make multiple calls to XNextEvent.
  18. However, if I try to use Xt, create a widget, select input
  19. from the dials device, and finally add an event handler for
  20. that device.  The event handler gets called, but with
  21. *keyboard* device events, not dials!  
  22.  
  23.     The 'DialRotateMask' and the 'KeyReleaseMask' are
  24. identical in the X header files.  They are both (1L << 1).
  25. Info Explorer explains that it is acceptable to overload
  26. these masks since the event handler can look at the .type
  27. field of the event structure to determine which device
  28. created the event.  The keyboard device event type is '3',
  29. while the dial rotate event type is '64'.  The only value we
  30. get in our dial rotate callback is 3, the keyboard,
  31. triggered by keyboard key release events.  (See code
  32. following message.)
  33.  
  34.    Has anyone ever read dialbox input using event handlers
  35. in X/Xt?  Does anyone have any ideas why Xt would ignore
  36. dial rotate events?
  37.  
  38. Any help/insight would be greatly appreciated.
  39.  
  40. Noah Parker   <nfp@cs.brown.edu>
  41.  
  42. -----------------------  specifics:  -----------------------
  43.  
  44. This is what works:   (abbreviated)
  45. --------
  46.  
  47.    XRotateEvent *rotev;
  48.    XEvent rep;
  49.  
  50.    /* set up display, make a window, etc... */
  51.    disp = XOpenDisplay(NULL);
  52.    rootwin   = RootWindow(disp,0);
  53.    madewin = XCreateSimpleWindow(disp,rootwin, ...)
  54.    XMapWindow(disp,madewin);
  55.  
  56.    /* select dials, which dials, etc. */
  57.  
  58.    XEnableInputDevice(disp,DEVDIAL);
  59.  
  60.    XSelectDeviceInput(disp,DEVDIAL,madewin,DialRotateMask);
  61.  
  62.    XSelectDial(disp, madewin, AllDialsMask);
  63.  
  64.    XSelectInput(disp,madewin,KeyPressMask | ButtonPressMask |
  65.       DialRotateMask  );
  66.  
  67.    /* read events, display any dial rotations */
  68.    while(1) {
  69.       XNextEvent(disp,&rep);
  70.       switch( rep.type ) {
  71.          case DialRotate:
  72.             /* great, we got a dial event, display values */
  73.             rotev = (XRotateEvent *) &rep;
  74.             fprintf(stderr,"dial rotate:  #%d, val = %d\n",
  75.                rotev->dialnum,
  76.                rotev->dialval);
  77.          default:
  78.             fprintf(stderr,"event type: %d\n",rep.type);
  79.       } /* end switch */
  80.    }
  81.  
  82. --------
  83.  
  84. ... now, what I want to do is read this asychronously,
  85. using event handlers:
  86.  
  87. --------
  88.  
  89.    /* 
  90.     *  (widget is the window I made in this test program, 
  91.     *   analogous to the window in previous example) 
  92.     */
  93.     XtAddEventHandler(widget, DialRotateMask, (Boolean) FALSE,
  94.                      (XtEventHandler) DEV_dial_rotate, (caddr_t) NULL);
  95.  
  96.     ...
  97.  
  98. /* the event handler: */
  99.  
  100. void
  101. DEV_dial_rotate(
  102.    Widget,
  103.    caddr_t            client_data,
  104.    XDialRotatedEvent *xevent
  105.    )
  106. {
  107.    DEVdials *dev;
  108.  
  109.    /* the only thing we ever get here is keyboard key release events */
  110.    fprintf(stderr,"Dial callback got event type: %d\n",xevent->type);
  111.  
  112. }
  113.  
  114. --------
  115.  
  116.