home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / ibm / AIX / aixEvents.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  37.4 KB  |  1,387 lines

  1. /*
  2.  * $XConsortium: aixEvents.c,v 1.3 91/07/16 12:59:36 jap Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989,1990,1991
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * License to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND 
  18.  * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
  19.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23.  * SOFTWARE.
  24.  *
  25. */
  26.  
  27. #include <sys/hft.h>
  28.  
  29. #define NEED_EVENTS
  30. #define NEED_REPLIES
  31. #include "X.h"
  32. #include "Xproto.h"
  33. #include "miscstruct.h"
  34. #include "scrnintstr.h"
  35. #include "cursorstr.h"
  36. #include "aixInput.h"
  37. #include "input.h"
  38. #include "inputstr.h"
  39.  
  40. #include "compiler.h"
  41.  
  42. #include "ibmIO.h"
  43. #include "ibmMouse.h"
  44. #include "ibmKeybd.h"
  45. #include "ibmScreen.h"
  46. #include "ibmTrace.h"
  47.  
  48. #include "OSio.h"
  49. #include "hftQueue.h"
  50.  
  51. #ifdef AIXEXTENSIONS
  52.  
  53. #include "AIX.h"
  54. #include "AIXproto.h"
  55. #include "AIXext.h"
  56.  
  57. #ifdef CFBSERVER
  58. extern DevicePtr rtDial ;
  59. extern DevicePtr rtLpfk ;
  60. #endif
  61.  
  62. #ifndef CFBSERVER /* come frome aixExtHook */
  63. AIXInfoRec      aixInfo  = {0,                          /* kbdid */
  64.                         0,                          /* display vrmid */
  65.                         0,                          /* display model */
  66.                         0,                          /* autoloadmode */
  67.                        -1,                          /* fd  */
  68.                         0,                          /* kbd iodn */
  69.                         0,                          /* loc iodn */
  70. #ifdef AIXTABLET
  71.                         0,                          /* mouse iodn */
  72.                         0,                          /* tablet iodn */
  73. #endif AIXTABLET
  74.                         0,                          /* dial iodn */
  75.                         0,                          /* lpfk iodn */
  76.                         0,                          /* loctype */
  77.                        };
  78. #endif
  79.  
  80. #ifdef AIXTABLET
  81. extern DevicePtr rtTablet ;
  82. #endif AIXTABLET
  83.  
  84. #endif
  85.  
  86. #ifdef  XTESTEXT1
  87. /*
  88.  * device ID defines
  89.  */
  90. #define XE_MOUSE 1 /* mouse */
  91. #define XE_DKB 2 /* main keyboard */
  92.  
  93. extern KeyCode xtest_command_key;
  94.  
  95. #define  XTestSERVER_SIDE
  96. #include "xtestext1.h"
  97. extern Bool     XTestStealKeyData();
  98. /*
  99.  * defined in xtestext1di.c
  100.  */
  101. extern int      on_steal_input;         /* steal input mode is on.      */
  102. extern int      exclusive_steal;
  103.  
  104. /*
  105.  * defined in xtestext1di.c
  106.  */
  107. extern short    xtest_mousex;
  108. /*
  109.  * defined in xtestext1di.c
  110.  */
  111. extern short    xtest_mousey;
  112.  
  113. #endif  /* XTESTEXT1 */
  114.  
  115. extern  int      screenIsSaved;
  116. extern  int      kbdType ;
  117.  
  118. static  hftEvent delayedEvent;
  119. static  int      delayed_left;
  120. static  int      delayed_right;
  121. static  int      delayed_middle;
  122. static  unsigned char lastButtons = 0x00 ;
  123. static  short    lastModKeys;
  124. static  int      pendingX;
  125. static  int      pendingY;
  126.  
  127. static int  kanjiCapsLockOn = 0;
  128.  
  129. #define GET_OS_TIME() (GetTimeInMillis())
  130.  
  131. extern void aixFlushMouse();
  132. extern int aixPtrEvent() ;
  133. extern int aixKbdEvent() ;
  134. extern int aixTabletEvent();
  135. extern int aixDialEvent();
  136. extern int aixLpfkEvent();
  137. extern void     ibmReactivateScreens(), ibmDeactivateScreens();
  138.  
  139. void
  140. AIXInitEventHandlers()
  141. {
  142.     TRACE(("InitEventHandlers()\n"));
  143.  
  144. #ifdef XTESTEXT1
  145.     xtest_command_key = 0x78;   /* F1 key */
  146. #endif /* XTESTEXT1 */
  147.  
  148.     if (hftInstallHandler(HFT_LOCATOR,aixPtrEvent)==HFT_ERROR) {
  149.     ErrorF("Couldn't install mouse handler\n");
  150.     }
  151.     if (hftInstallHandler(HFT_KEYBOARD,aixKbdEvent)==HFT_ERROR) {
  152.     ErrorF("Couldn't install keyboard handler\n");
  153.     }
  154.     hftInstallHandler(HFT_EVENT_ARRIVED,HFT_IGNORE);
  155.     if (hftInstallHandler(HFT_GRANTED,ibmReactivateScreens)==HFT_ERROR) {
  156.     ErrorF("Couldn't install grant routine\n");
  157.     }
  158.     if (hftInstallHandler(HFT_RETRACTED,ibmDeactivateScreens)==HFT_ERROR) {
  159.     ErrorF("Couldn't install retract handler\n");
  160.     }
  161. #ifdef AIXEXTENSIONS
  162.     if (hftInstallHandler(HFT_TABLET,aixTabletEvent)==HFT_ERROR) {
  163.     ErrorF("Couldn't install tablet handler\n");
  164.     }
  165.     if (hftInstallHandler(HFT_DIAL,aixDialEvent)==HFT_ERROR) {
  166.     ErrorF("Couldn't install dial handler\n");
  167.     }
  168.     if (hftInstallHandler(HFT_LPFK,aixLpfkEvent)==HFT_ERROR) {
  169.     ErrorF("Couldn't install lpfk handler\n");
  170.     }
  171. #endif
  172. }
  173.  
  174. void
  175. ProcessInputEvents()
  176. {
  177.  
  178. #ifdef IBM_SPECIAL_MALLOC
  179. extern int ibmShouldDumpArena;
  180.  
  181.     if (ibmShouldDumpArena) {
  182.     ibmDumpArena();
  183.     }
  184. #endif /* IBM_SPECIAL_MALLOC */
  185.  
  186.     TRACE(("ProcessInputEvents (pending=%d)\n",hftPending));
  187.  
  188.     if ( screenIsSaved == SCREEN_SAVER_ON ) {
  189.     SaveScreens( SCREEN_SAVER_OFF, ScreenSaverReset );
  190.     }
  191.     hftDispatchEvents();
  192.     if (pendingX||pendingY)
  193.     aixFlushMouse();
  194. }
  195.  
  196. static void
  197. aixFlushMouse()
  198. {
  199. register        int     x,y;
  200. register        ibmPerScreenInfo        *screenInfo;
  201.             int     oldScr, newScr, v;
  202.             int     setCursor;
  203.             xEvent  e;
  204.  
  205.     TRACE(("aixFlushMouse\n"));
  206.  
  207.     if ((pendingX)||(pendingY)) {
  208.     ibmAccelerate(pendingX,pendingY);
  209.     x= AIXCurrentX+pendingX;
  210.     y= AIXCurrentY-pendingY;
  211.  
  212.     pendingX= 0;
  213.     pendingY= 0;
  214.  
  215.     oldScr = ibmCurrentScreen;
  216.     newScr = ibmCurrentScreen;
  217.     screenInfo = ibmScreens[ oldScr ];
  218.     setCursor = FALSE;
  219.  
  220.     while( y<0 || x<0 || y>screenInfo->ibm_ScreenBounds.y2 || x>screenInfo->ibm_ScreenBounds.x2 ) {
  221.         if( y < 0 ){
  222.             if( (v=aixWrapUp(newScr)) < 0 ){
  223.                     /* if no wrap this direction */
  224.                 y= 0;
  225.                 setCursor= TRUE;
  226.             }
  227.             else{
  228.                 newScr = v;
  229.                 screenInfo = ibmScreens[newScr];
  230.                 y+= screenInfo->ibm_ScreenBounds.y2;
  231.                 setCursor= TRUE;
  232.             }
  233.         }
  234.         else if( y>screenInfo->ibm_ScreenBounds.y2 ) {
  235.             if( (v=aixWrapDown(newScr)) < 0 ){
  236.                     /* if no wrap this direction */
  237.                 y= screenInfo->ibm_ScreenBounds.y2;
  238.                 setCursor= TRUE;
  239.             }
  240.             else{
  241.                 newScr = v;
  242.                 screenInfo = ibmScreens[newScr];
  243.                 y-= screenInfo->ibm_ScreenBounds.y2;
  244.                 setCursor= TRUE;
  245.             }
  246.         }
  247.  
  248.         if( x < 0 ){
  249.             if( (v=aixWrapLeft(newScr)) < 0 ){
  250.                     /* if no wrap this direction */
  251.                 x= 0;
  252.                 setCursor= TRUE;
  253.             }
  254.             else{
  255.                 newScr = v;
  256.                 screenInfo = ibmScreens[newScr];
  257.                 x+= screenInfo->ibm_ScreenBounds.x2;
  258.                 setCursor= TRUE;
  259.             }
  260.         }
  261.         else if( x>screenInfo->ibm_ScreenBounds.x2 ) {
  262.             if( (v=aixWrapRight(newScr)) < 0 ){
  263.                     /* if no wrap this direction */
  264.                 x= screenInfo->ibm_ScreenBounds.x2;
  265.                 setCursor= TRUE;
  266.             }
  267.             else{
  268.                 newScr = v;
  269.                 screenInfo = ibmScreens[newScr];
  270.                 x-= screenInfo->ibm_ScreenBounds.x2;
  271.                 setCursor= TRUE;
  272.             }
  273.         }
  274.     }
  275.  
  276.     if (setCursor)
  277.         setCursorPosition(x,y);
  278.  
  279.     if (oldScr != newScr ) {
  280.     TRACE(("switching screens in ProcessInputEvents\n"));
  281.     NewCurrentScreen( screenInfo->ibm_Screen, x, y ) ;
  282.     }
  283.  
  284. #ifdef XTESTEXT1
  285.     if (on_steal_input)
  286.     {
  287.             /*
  288.              * only call if the mouse position has actually moved
  289.              */
  290.             if ((x != xtest_mousex) || (y != xtest_mousey))
  291.             {
  292.                     XTestStealMotionData((x - xtest_mousex),
  293.                                          (y - xtest_mousey),
  294.                                          XE_MOUSE,
  295.                                          xtest_mousex,
  296.                                          xtest_mousey);
  297.             }
  298.     }
  299. #endif /* XTESTEXT1 */
  300.  
  301. #ifdef SOFTWARE_CURSOR
  302.     miPointerMoveCursor(screenInfo->ibm_Screen, x, y, TRUE) ;
  303. #else
  304.     (* screenInfo->ibm_CursorShow )( x, y ) ;
  305. #endif
  306.  
  307.     e.u.u.type=                     MotionNotify;
  308.     e.u.keyButtonPointer.rootX=     AIXCurrentX= x;
  309.     e.u.keyButtonPointer.rootY=     AIXCurrentY= y;
  310.     e.u.keyButtonPointer.time=      lastEventTime = GET_OS_TIME();
  311.     pendingX= pendingY= 0;
  312.     (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  313.     }
  314. }
  315.  
  316. /***====================================================================***/
  317.  
  318.     /*
  319.      * All of this keyboard stuff needs to
  320.      * be reorganized anyway (into osKeymap.h and a single keyboard.c)
  321.      */
  322.  
  323.  
  324. #define LSHIFT  (HFUXLSH)
  325. #define RSHIFT  (HFUXRSH)
  326. #define RALT    (HFUXRALT)
  327. #define LALT    (HFUXLALT)
  328.  
  329. #define CTRL    0
  330.  
  331. #define MODKEYMASK      (LSHIFT|RSHIFT|RALT|LALT|CTRL)
  332. #define setModKeyState(ms,pe)   \
  333.             ((ms)=((((pe)->keStatus[0]<<8)|(pe)->keStatus[1])&MODKEYMASK))
  334.  
  335. #ifdef XTESTEXT1
  336. #define FAKEEVENT(ev,key,up)    {\
  337.     (ev)->u.u.detail= (key);\
  338.     (ev)->u.u.type= ((up)?KeyRelease:KeyPress);\
  339.     if (!on_steal_input || \
  340.         XTestStealKeyData((ev)->u.u.detail, (ev)->u.u.type, XE_DKB, \
  341.                           AIXCurrentX, AIXCurrentY)) \
  342.     (*ibmKeybd->processInputProc)((ev),ibmKeybd,1);\
  343.     }
  344. #elif defined(SOFTWARE_CURSOR)
  345. #define FAKEEVENT(ev,key,up)    {\
  346.     (ev)->u.u.detail= (key);\
  347.     (ev)->u.u.type= ((up)?KeyRelease:KeyPress);\
  348.     miPointerPosition(ibmScreens[ibmCurrentScreen]->ibm_Screen,\
  349.                       &((ev)->u.keyButtonPointer.rootX),       \
  350.                       &((ev)->u.keyButtonPointer.rootY)         \
  351.                       ) ;                                       \
  352.     (*ibmKeybd->processInputProc)((ev),ibmKeybd,1);\
  353.     }
  354. #else /* HARDWARE_CURSOR */
  355. #define FAKEEVENT(ev,key,up)    {\
  356.     (ev)->u.u.detail= (key);\
  357.     (ev)->u.u.type= ((up)?KeyRelease:KeyPress);\
  358.     (*ibmKeybd->processInputProc)((ev),ibmKeybd,1);\
  359.     }
  360. #endif /* XTESTEXT1 */
  361.  
  362. void
  363. aixFakeModKeyEvent(changedModKeys)
  364. unsigned short  changedModKeys;
  365. {
  366. xEvent          e;
  367.  
  368.     TRACE(("aixFakeModKeyEvent(%d)\n"));
  369.  
  370.     e.u.keyButtonPointer.rootX= AIXCurrentX;
  371.     e.u.keyButtonPointer.rootY= AIXCurrentY;
  372.     e.u.keyButtonPointer.time=  lastEventTime= GET_OS_TIME();
  373.  
  374.     if (changedModKeys&LSHIFT) {
  375.     FAKEEVENT(&e,Aix_Shift_L,(lastModKeys&LSHIFT));
  376.     }
  377.     if (changedModKeys&RSHIFT) {
  378.     FAKEEVENT(&e,Aix_Shift_R,(lastModKeys&RSHIFT));
  379.     }
  380.     if (changedModKeys&LALT) {
  381.     FAKEEVENT(&e,Aix_Alt_L,(lastModKeys&LALT));
  382.     }
  383.     if (changedModKeys&RALT) {
  384.     FAKEEVENT(&e,Aix_Alt_R,(lastModKeys&RALT));
  385.     }
  386.  
  387.     return;
  388.  
  389. }
  390.  
  391. /***====================================================================***/
  392.  
  393. static int
  394. aixKbdEvent(pEv)
  395. hftEvent        *pEv;
  396. {
  397. hftKeyEv        *pKey= &pEv->hftEv.hftKey;
  398. unsigned short  theseModKeys;
  399. DeviceIntPtr    KeyboardPtr;
  400. xEvent          e;
  401. int             key;
  402.  
  403.     TRACE(("aixKbdEvent (%d)\n",pKey->kePos));
  404.  
  405.     key = pKey->kePos + AIX_MIN_KEY ;
  406.  
  407.     if ((pendingX)||(pendingY))
  408.     aixFlushMouse();
  409.  
  410.     setModKeyState(theseModKeys,pKey);
  411.     if (theseModKeys!=lastModKeys) {
  412.     aixFakeModKeyEvent(theseModKeys^lastModKeys);
  413.     }
  414.  
  415.     lastModKeys= theseModKeys;
  416.  
  417.     switch (key) {
  418.     case Aix_Alt_L:
  419.             {
  420.             if (kbdType == HF106KBD)        /* special case */
  421.                     break ;
  422.             else
  423.                     return(1);
  424.             }
  425.     case Aix_Shift_L:
  426.     case Aix_Shift_R:
  427.     case Aix_Alt_R:
  428.                     return(1);
  429.     case Aix_Backspace:
  430.             if ((!ibmDontZap)&&(pKey->keStatus[0]&HFUXCTRL)&&
  431.                                     (pKey->keStatus[0]&HFUXALT)) {
  432.                 GiveUp();
  433.             }
  434.             break;
  435.     default:
  436.             break;
  437.     }
  438.  
  439.     if ((!ibmKeyRepeat)&&pKey->keStatus[1]&HFUXRPT)
  440.     return(1);
  441.  
  442.     e.u.keyButtonPointer.rootX= AIXCurrentX;
  443.     e.u.keyButtonPointer.rootY= AIXCurrentY;
  444.     e.u.keyButtonPointer.time=  lastEventTime= GET_OS_TIME();
  445.     e.u.u.detail= key ;
  446.     if (pKey->keStatus[1]&HFUXRPT)      {
  447.     e.u.u.type= KeyRelease;
  448. #ifdef XTESTEXT1
  449.     if (!on_steal_input ||
  450.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_DKB,
  451.                           AIXCurrentX, AIXCurrentY))
  452. #endif /* XTESTEXT1 */
  453. #ifdef SOFTWARE_CURSOR
  454.     miPointerPosition(ibmScreens[ibmCurrentScreen]->ibm_Screen,
  455.                       &e.u.keyButtonPointer.rootX,
  456.                       &e.u.keyButtonPointer.rootY
  457.                       ) ;
  458. #endif
  459.     (*ibmKeybd->processInputProc)(&e,ibmKeybd,1);
  460.     e.u.u.type= KeyPress;
  461.     }
  462.     else if (pKey->keStatus[0]&HFUXMAKE)        e.u.u.type= KeyPress;
  463.     else                                        e.u.u.type= KeyRelease;
  464.  
  465.     if (kbdType == HF106KBD) {
  466.     /*
  467.             On 106 keyboard the Caps Lock key is in the same
  468.             place as the Left Alt key and is only active when
  469.             the Right Alt key is down.  To toggle Caps Lock type
  470.             the sequence Right_Alt down, Left_Alt down, then let
  471.             the keys up in any order.  The Left_Alt acts like a
  472.             normal key when Right_Alt is up.
  473.     */
  474.  
  475.     KeyboardPtr = (DeviceIntPtr)ibmKeybd;
  476.  
  477.     if( (key == Aix_Alt_L) && (e.u.u.type == KeyPress) )
  478.     {
  479.     /* if left alt key was just pressed */
  480.     /* if right alt key is down */
  481.     if( theseModKeys & RALT ){
  482.             if( kanjiCapsLockOn ){
  483.                     /* turn OFF caps lock */
  484. #ifdef CFBSERVER
  485. /* where is is defined ??? */
  486.                 kanjiClearCapsLock();
  487.                 kanjiCapsLockOn = 0;
  488. #endif
  489.                 SetCapsLockLED(0);
  490.             }
  491.             else{
  492.                     /* turn ON caps lock */
  493. #ifdef CFBSERVER
  494.                 kanjiSetCapsLock();
  495.                 kanjiCapsLockOn = 1;
  496. #endif
  497.                 SetCapsLockLED(1);
  498.             }
  499.     }
  500.     }
  501.  
  502.     /*
  503.      *  toggle num lock key:
  504.      *  ignore releases, toggle on & off on presses
  505.      */
  506.  
  507.     if( (KeyboardPtr)->key->modifierMap[key] & NumLockMask )
  508.     {
  509.        if( e.u.u.type == KeyRelease )
  510.             return (1);
  511.        if( KeyboardPtr->key->down[key >> 3] & (1 << (key & 7)) )
  512.        {
  513.         e.u.u.type = KeyRelease;
  514.         SetNumLockLED(0);
  515.        } else
  516.         SetNumLockLED(1);
  517.     }
  518.  
  519.     } /* end if (kbdType == HF106KBD) */
  520.  
  521.     if (kbdType == HF101KBD || kbdType == HF102KBD) {
  522.  
  523.     /*
  524.      *  toggle lock shift keys:
  525.      *  ignore releases, toggle on & off on presses
  526.      */
  527.  
  528.     KeyboardPtr = (DeviceIntPtr)ibmKeybd;
  529.  
  530.     if( KeyboardPtr->key->modifierMap[key] & LockMask )
  531.     {
  532.     if( e.u.u.type == KeyRelease )
  533.          return (1);
  534.     if( KeyboardPtr->key->down[key >> 3] & (1 << (key & 7)) )
  535.     {
  536.          e.u.u.type = KeyRelease;
  537.          SetCapsLockLED(0);
  538.     } else
  539.          SetCapsLockLED(1);
  540.     }
  541.  
  542.     /*
  543.      *  toggle num lock key:
  544.      *  ignore releases, toggle on & off on presses
  545.      */
  546.  
  547.     if( KeyboardPtr->key->modifierMap[key] & NumLockMask )
  548.     {
  549.        if( e.u.u.type == KeyRelease )
  550.             return (1);
  551.        if( KeyboardPtr->key->down[key >> 3] & (1 << (key & 7)) )
  552.        {
  553.         e.u.u.type = KeyRelease;
  554.         SetNumLockLED(0);
  555.        } else
  556.         SetNumLockLED(1);
  557.     }
  558.  
  559.     }
  560.  
  561. #ifdef XTESTEXT1
  562.     if (!on_steal_input ||
  563.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_DKB,
  564.                           AIXCurrentX, AIXCurrentY))
  565. #endif /* XTESTEXT1 */
  566.  
  567. #ifdef SOFTWARE_CURSOR
  568.     miPointerPosition(ibmScreens[ibmCurrentScreen]->ibm_Screen,
  569.                       &(e.u.keyButtonPointer.rootX),
  570.                       &(e.u.keyButtonPointer.rootY)
  571.                       ) ;
  572. #endif
  573.     (*ibmKeybd->processInputProc)(&e,ibmKeybd,1);
  574.  
  575.     return(1);
  576. }
  577.  
  578. /***====================================================================***/
  579.  
  580. #define NONE    0x00
  581. #define LEFT    Button1
  582. #define MIDDLE  Button2
  583. #define RIGHT   Button3
  584.  
  585. #define UP      ButtonRelease
  586. #define DOWN    ButtonPress
  587.  
  588. static int aix3ButtonPtrEvent();
  589.  
  590.  
  591. static void
  592. locatorTimeout()
  593. {
  594. aixPtrEvent(&delayedEvent);
  595. return;
  596. }
  597.  
  598.  
  599. static int
  600. aixPtrEvent(pIn)
  601. hftEvent        *pIn;
  602. {
  603. extern  int     AIXMouseChordDelay;
  604. hftLocEv        *pEv= &pIn->hftEv.hftLoc;
  605. unsigned char   buttons= pEv->leButtons&(HFT_BUTTONS|HFT_MBUTTON);
  606. xEvent          e;
  607.  
  608.  
  609.     TRACE(("aixPtrEvent (%d,%d)\n",pEv->leDeltaX,pEv->leDeltaY));
  610.     pendingX+= pEv->leDeltaX;
  611.     pendingY+= pEv->leDeltaY;
  612.  
  613.     if (pendingX||pendingY)
  614.     aixFlushMouse();
  615.     e.u.keyButtonPointer.rootX=     AIXCurrentX;
  616.     e.u.keyButtonPointer.rootY=     AIXCurrentY;
  617.     e.u.keyButtonPointer.time=      GET_OS_TIME();
  618.  
  619.     if (buttons&HFT_MBUTTON) {
  620.     /* We don't care about all the 2 button stuff anymore because
  621.        we know there is a three button mouse.  Therefore, LEFT&RIGHT
  622.        buttons down don't mean middle button( like they had to for a two
  623.        button mouse), they mean left and right button down consecutively.*/
  624.     if (delayed_right || (buttons&HFT_RBUTTON) ) {
  625.         hftAddTimeout(NULL,0);
  626.         e.u.u.detail= RIGHT;
  627.         e.u.u.type=   DOWN;
  628. #ifdef  XTESTEXT1
  629.     if (!on_steal_input ||
  630.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  631.                           AIXCurrentX, AIXCurrentY))
  632. #endif /* XTESTEXT1 */
  633.         (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  634.     }
  635.     if (delayed_left || (buttons&HFT_LBUTTON) ) {
  636.         hftAddTimeout(NULL,0);
  637.         e.u.u.detail= LEFT;
  638.         e.u.u.type=   DOWN;
  639. #ifdef  XTESTEXT1
  640.     if (!on_steal_input ||
  641.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  642.                           AIXCurrentX, AIXCurrentY))
  643. #endif /* XTESTEXT1 */
  644.         (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  645.     }
  646.     /* if we had previously generated a middle event from a LEFT&RIGHT
  647.        and we are waiting for it to go away */
  648.     if (delayed_middle) {
  649.         hftAddTimeout(NULL,0);
  650.         e.u.u.detail= MIDDLE;
  651.         e.u.u.type=   UP;
  652. #ifdef  XTESTEXT1
  653.     if (!on_steal_input ||
  654.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  655.                           AIXCurrentX, AIXCurrentY))
  656. #endif /* XTESTEXT1 */
  657.         (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  658.     }
  659.     e.u.u.detail= MIDDLE;
  660.     e.u.u.type=   DOWN;
  661. #ifdef  XTESTEXT1
  662.     if (!on_steal_input ||
  663.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  664.                           AIXCurrentX, AIXCurrentY))
  665. #endif /* XTESTEXT1 */
  666.     (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  667.     lastButtons = buttons;
  668.     if (hftInstallHandler(HFT_LOCATOR,aix3ButtonPtrEvent)==HFT_ERROR)
  669.         ErrorF("Couldn't install three button mouse handler\n");
  670.     return(1);
  671.     }
  672.  
  673.  
  674.     switch(lastButtons)
  675.     {
  676.     case NONE  :
  677.          switch(buttons)
  678.          {
  679.              case NONE  :
  680.                   break;
  681.              case HFT_LBUTTON  :
  682.                   delayed_left = TRUE;
  683.                   break;
  684.              case HFT_RBUTTON  :
  685.                   delayed_right = TRUE;
  686.                   break;
  687.              case HFT_BUTTONS  :
  688.                   e.u.u.detail= MIDDLE;
  689.                   e.u.u.type=   DOWN;
  690. #ifdef  XTESTEXT1
  691.     if (!on_steal_input ||
  692.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  693.                           AIXCurrentX, AIXCurrentY))
  694. #endif /* XTESTEXT1 */
  695.                   (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  696.                   break;
  697.           }
  698.          break;
  699.     case HFT_LBUTTON  :
  700.          switch(buttons)
  701.          {
  702.              case NONE  :
  703.                   if (delayed_left) {
  704.                       hftAddTimeout(NULL,0);
  705.                       e.u.u.detail= LEFT;
  706.                       e.u.u.type=   DOWN;
  707. #ifdef  XTESTEXT1
  708.     if (!on_steal_input ||
  709.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  710.                           AIXCurrentX, AIXCurrentY))
  711. #endif /* XTESTEXT1 */
  712.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  713.                       delayed_left = FALSE;
  714.                   }
  715.                   if (delayed_middle) {
  716.                       e.u.u.detail= MIDDLE;
  717.                       e.u.u.type=   UP;
  718. #ifdef  XTESTEXT1
  719.     if (!on_steal_input ||
  720.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  721.                           AIXCurrentX, AIXCurrentY))
  722. #endif /* XTESTEXT1 */
  723.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  724.                       delayed_middle = FALSE;
  725.                   } else {
  726.                       e.u.u.detail= LEFT;
  727.                       e.u.u.type=   UP;
  728. #ifdef  XTESTEXT1
  729.     if (!on_steal_input ||
  730.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  731.                           AIXCurrentX, AIXCurrentY))
  732. #endif /* XTESTEXT1 */
  733.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  734.                   }
  735.                   break;
  736.              case HFT_LBUTTON  :
  737.                   if (delayed_left) {
  738.                       hftAddTimeout(NULL,0);
  739.                       e.u.u.detail= LEFT;
  740.                       e.u.u.type=   DOWN;
  741. #ifdef  XTESTEXT1
  742.     if (!on_steal_input ||
  743.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  744.                           AIXCurrentX, AIXCurrentY))
  745. #endif /* XTESTEXT1 */
  746.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  747.                       delayed_left = FALSE;
  748.                   }
  749.                   break;
  750.              case HFT_RBUTTON  :
  751.                   if (delayed_left) {
  752.                       hftAddTimeout(NULL,0);
  753.                       e.u.u.detail= LEFT;
  754.                       e.u.u.type=   DOWN;
  755. #ifdef  XTESTEXT1
  756.     if (!on_steal_input ||
  757.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  758.                           AIXCurrentX, AIXCurrentY))
  759. #endif /* XTESTEXT1 */
  760.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  761.                       delayed_left = FALSE;
  762.                   }
  763.                       e.u.u.detail= LEFT;
  764.                       e.u.u.type=   UP;
  765. #ifdef  XTESTEXT1
  766.     if (!on_steal_input ||
  767.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  768.                           AIXCurrentX, AIXCurrentY))
  769. #endif /* XTESTEXT1 */
  770.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  771.                   delayed_right = TRUE;
  772.                   break;
  773.              case HFT_BUTTONS  :
  774.                   if (delayed_left) {
  775.                       hftAddTimeout(NULL,0);
  776.                       e.u.u.detail= MIDDLE;
  777.                       e.u.u.type=   DOWN;
  778. #ifdef  XTESTEXT1
  779.     if (!on_steal_input ||
  780.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  781.                           AIXCurrentX, AIXCurrentY))
  782. #endif /* XTESTEXT1 */
  783.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  784.                       delayed_left = FALSE;
  785.                   } else if (!delayed_middle) {
  786.                       e.u.u.detail= LEFT;
  787.                       e.u.u.type=   UP;
  788. #ifdef  XTESTEXT1
  789.     if (!on_steal_input ||
  790.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  791.                           AIXCurrentX, AIXCurrentY))
  792. #endif /* XTESTEXT1 */
  793.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  794.                       e.u.u.detail= MIDDLE;
  795.                       e.u.u.type=   DOWN;
  796. #ifdef  XTESTEXT1
  797.     if (!on_steal_input ||
  798.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  799.                           AIXCurrentX, AIXCurrentY))
  800. #endif /* XTESTEXT1 */
  801.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  802.                   }
  803.                   break;
  804.           }
  805.          break;
  806.     case HFT_RBUTTON  :
  807.          switch(buttons)
  808.          {
  809.              case NONE  :
  810.                   if (delayed_right) {
  811.                       hftAddTimeout(NULL,0);
  812.                       e.u.u.detail= RIGHT;
  813.                       e.u.u.type=   DOWN;
  814. #ifdef  XTESTEXT1
  815.     if (!on_steal_input ||
  816.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  817.                           AIXCurrentX, AIXCurrentY))
  818. #endif /* XTESTEXT1 */
  819.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  820.                       delayed_right = FALSE;
  821.                   }
  822.                   if (delayed_middle) {
  823.                       e.u.u.detail= MIDDLE;
  824.                       e.u.u.type=   UP;
  825. #ifdef  XTESTEXT1
  826.     if (!on_steal_input ||
  827.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  828.                           AIXCurrentX, AIXCurrentY))
  829. #endif /* XTESTEXT1 */
  830.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  831.                       delayed_middle = FALSE;
  832.                   } else {
  833.                       e.u.u.detail= RIGHT;
  834.                       e.u.u.type=   UP;
  835. #ifdef  XTESTEXT1
  836.     if (!on_steal_input ||
  837.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  838.                           AIXCurrentX, AIXCurrentY))
  839. #endif /* XTESTEXT1 */
  840.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  841.                   }
  842.                   break;
  843.              case HFT_LBUTTON  :
  844.                   if (delayed_right) {
  845.                       hftAddTimeout(NULL,0);
  846.                       e.u.u.detail= RIGHT;
  847.                       e.u.u.type=   DOWN;
  848. #ifdef  XTESTEXT1
  849.     if (!on_steal_input ||
  850.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  851.                           AIXCurrentX, AIXCurrentY))
  852. #endif /* XTESTEXT1 */
  853.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  854.                       delayed_right = FALSE;
  855.                   }
  856.                   e.u.u.detail= RIGHT;
  857.                   e.u.u.type=   UP;
  858. #ifdef  XTESTEXT1
  859.     if (!on_steal_input ||
  860.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  861.                           AIXCurrentX, AIXCurrentY))
  862. #endif /* XTESTEXT1 */
  863.                   (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  864.                   delayed_left = TRUE;
  865.                   break;
  866.              case HFT_RBUTTON  :
  867.                   if (delayed_right) {
  868.                       hftAddTimeout(NULL,0);
  869.                       e.u.u.detail= RIGHT;
  870.                       e.u.u.type=   DOWN;
  871. #ifdef  XTESTEXT1
  872.     if (!on_steal_input ||
  873.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  874.                           AIXCurrentX, AIXCurrentY))
  875. #endif /* XTESTEXT1 */
  876.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  877.                       delayed_right = FALSE;
  878.                   }
  879.                   break;
  880.              case HFT_BUTTONS  :
  881.                   if (delayed_right) {
  882.                       hftAddTimeout(NULL,0);
  883.                       e.u.u.detail= MIDDLE;
  884.                       e.u.u.type=   DOWN;
  885. #ifdef  XTESTEXT1
  886.     if (!on_steal_input ||
  887.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  888.                           AIXCurrentX, AIXCurrentY))
  889. #endif /* XTESTEXT1 */
  890.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  891.                       delayed_right = FALSE;
  892.                   } else if (!delayed_middle) {
  893.                       e.u.u.detail= RIGHT;
  894.                       e.u.u.type=   UP;
  895. #ifdef  XTESTEXT1
  896.     if (!on_steal_input ||
  897.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  898.                           AIXCurrentX, AIXCurrentY))
  899. #endif /* XTESTEXT1 */
  900.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  901.                       e.u.u.detail= MIDDLE;
  902.                       e.u.u.type=   DOWN;
  903. #ifdef  XTESTEXT1
  904.     if (!on_steal_input ||
  905.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  906.                           AIXCurrentX, AIXCurrentY))
  907. #endif /* XTESTEXT1 */
  908.                       (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  909.                   }
  910.                   break;
  911.           }
  912.          break;
  913.     case HFT_BUTTONS  :
  914.          switch(buttons)
  915.          {
  916.              case NONE  :
  917.                   e.u.u.detail= MIDDLE;
  918.                   e.u.u.type=   UP;
  919. #ifdef  XTESTEXT1
  920.     if (!on_steal_input ||
  921.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  922.                           AIXCurrentX, AIXCurrentY))
  923. #endif /* XTESTEXT1 */
  924.                   (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  925.                   break;
  926.              case HFT_LBUTTON  :
  927.              case HFT_RBUTTON  :
  928.                   delayed_middle = TRUE;
  929.                   break;
  930.              case HFT_BUTTONS  :
  931.                   break;
  932.           }
  933.           break;
  934.     }
  935.  
  936.     lastButtons = buttons;
  937.  
  938.     if (delayed_left || delayed_right) {
  939.     delayedEvent = *pIn;
  940.     delayedEvent.hftEv.hftLoc.leDeltaX = 0;
  941.     delayedEvent.hftEv.hftLoc.leDeltaY = 0;
  942.     hftAddTimeout(locatorTimeout,AIXMouseChordDelay);
  943.     }
  944.     return(1);
  945. }
  946.  
  947.  
  948.  
  949. /***====================================================================***/
  950.  
  951. static int
  952. aix3ButtonPtrEvent(pIn)
  953. hftEvent        *pIn;
  954. {
  955. extern  int     AIXMouseChordDelay;
  956. hftLocEv        *pEv= &pIn->hftEv.hftLoc;
  957. unsigned char   buttons= pEv->leButtons&(HFT_BUTTONS|HFT_MBUTTON);
  958. unsigned char   changed;
  959. xEvent          e;
  960.  
  961.     TRACE(("aix3ButtonPtrEvent (%d,%d)\n",pEv->leDeltaX,pEv->leDeltaY));
  962.     pendingX+= pEv->leDeltaX;
  963.     pendingY+= pEv->leDeltaY;
  964.  
  965.     if (pendingX||pendingY)
  966.     aixFlushMouse();
  967.  
  968.     e.u.keyButtonPointer.rootX=     AIXCurrentX;
  969.     e.u.keyButtonPointer.rootY=     AIXCurrentY;
  970.     e.u.keyButtonPointer.time=      GET_OS_TIME();
  971.  
  972.     changed = buttons ^ lastButtons;
  973.  
  974.     if (changed & HFT_BUTTON1) {
  975.     if (buttons & HFT_BUTTON1)      e.u.u.type = DOWN;
  976.         else                        e.u.u.type = UP;
  977.     e.u.u.detail= LEFT;
  978. #ifdef  XTESTEXT1
  979.     if (!on_steal_input ||
  980.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  981.                           AIXCurrentX, AIXCurrentY))
  982. #endif /* XTESTEXT1 */
  983.     (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  984.     }
  985.     if (changed & HFT_BUTTON3) {
  986.     if (buttons & HFT_BUTTON3)      e.u.u.type = DOWN;
  987.         else                        e.u.u.type = UP;
  988.     e.u.u.detail= RIGHT;
  989. #ifdef  XTESTEXT1
  990.     if (!on_steal_input ||
  991.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  992.                           AIXCurrentX, AIXCurrentY))
  993. #endif /* XTESTEXT1 */
  994.     (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  995.     }
  996.     if (changed & HFT_BUTTON2) {
  997.     if (buttons & HFT_BUTTON2)      e.u.u.type = DOWN;
  998.         else                        e.u.u.type = UP;
  999.     e.u.u.detail= MIDDLE;
  1000. #ifdef  XTESTEXT1
  1001.     if (!on_steal_input ||
  1002.         XTestStealKeyData(e.u.u.detail, e.u.u.type, XE_MOUSE,
  1003.                           AIXCurrentX, AIXCurrentY))
  1004. #endif /* XTESTEXT1 */
  1005.     (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  1006.     }
  1007.  
  1008.     lastButtons = buttons;
  1009.     return(1);
  1010. }
  1011.  
  1012.  
  1013. /*
  1014.  * Additional test extension functions.
  1015.  */
  1016. #ifdef XTESTEXT1
  1017. void
  1018. XTestGenerateEvent(dev_type, keycode, keystate, mousex, mousey)
  1019.     int     dev_type;
  1020.     int     keycode;
  1021.     int     keystate;
  1022.     int     mousex;
  1023.     int     mousey;
  1024. {
  1025.     xEvent  e;
  1026.     TRACE(("XTestGenerateEvent#1\n"));
  1027.  
  1028.     if (pendingX||pendingY)
  1029.         aixFlushMouse();
  1030.     /*
  1031.      * the server expects to have the x and y position of the locator
  1032.      * when the action happened placed in other_p[XPOINTER]
  1033.      */
  1034.     if (dev_type == XE_MOUSE)
  1035.     {
  1036.             if (keystate == XTestKEY_UP)
  1037.                     keystate = ButtonRelease;
  1038.             else
  1039.                     keystate = ButtonPress;
  1040.             e.u.keyButtonPointer.rootX= AIXCurrentX = mousex;
  1041.             e.u.keyButtonPointer.rootY= AIXCurrentY = mousey;
  1042.             e.u.keyButtonPointer.time= lastEventTime = GET_OS_TIME();
  1043.             e.u.u.detail=                   keycode;
  1044.             e.u.u.type=                     keystate;
  1045.             (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  1046.     }
  1047.     else  /* keyboard events */
  1048.     {
  1049.             if (keystate == XTestKEY_UP)
  1050.                     keystate = KeyRelease;
  1051.             else
  1052.                     keystate = KeyPress;
  1053.             e.u.keyButtonPointer.rootX= AIXCurrentX = mousex;
  1054.             e.u.keyButtonPointer.rootY= AIXCurrentY = mousey;
  1055.             e.u.keyButtonPointer.time= lastEventTime = GET_OS_TIME();
  1056.             e.u.u.detail=                   keycode;
  1057.             e.u.u.type=                     keystate;
  1058.             (*ibmKeybd->processInputProc)(&e,ibmKeybd,1);
  1059.     }
  1060.  
  1061. #ifdef notdef
  1062.     /*
  1063.        ##### Here is the original HP code, the generated event is put in
  1064.        ##### event queue.  Similar implementation might be needed
  1065.        ##### in our AIX hft layer, but until we see XTM code, we'll
  1066.        ##### have better idea.   -glee
  1067.      */
  1068.     /*
  1069.      * set the last event time so that the screen saver code will
  1070.      * think that a key has been pressed
  1071.      */
  1072.     lastEventTime = GetTimeInMillis();
  1073.  
  1074.     put_keyevent(keycode,
  1075.                  keystate,
  1076.                  0,
  1077.                  dev_type,
  1078.                  tmp_ptr,
  1079.                  &hil_info);
  1080.  
  1081.     ProcessInputEvents();
  1082. #endif
  1083.  
  1084. }
  1085.  
  1086.  
  1087. void
  1088. XTestGetPointerPos(fmousex, fmousey)
  1089.     short *fmousex, *fmousey;
  1090. {
  1091.     *fmousex = AIXCurrentX;
  1092.     *fmousey = AIXCurrentY;
  1093. }
  1094.  
  1095. /******************************************************************************
  1096.  *
  1097.  *      Tell the server to move the mouse.
  1098.  *
  1099.  */
  1100. void
  1101. XTestJumpPointer(jx, jy, dev_type)
  1102. /*
  1103.  * the x and y position to move the mouse to
  1104.  */
  1105. int     jx;
  1106. int     jy;
  1107. /*
  1108.  * which device is supposed to move (ignored)
  1109.  */
  1110. int     dev_type;
  1111. {
  1112.     xEvent e;
  1113.     TRACE(("XTestJumpPointer#1\n"));
  1114.  
  1115.     ProcessInputEvents();
  1116.     /*
  1117.      * set the last event time so that the screen saver code will
  1118.      * think that the mouse has been moved
  1119.      */
  1120.     e.u.keyButtonPointer.time = lastEventTime = GET_OS_TIME();
  1121.     /*
  1122.      * tell the server where the mouse is being moved to
  1123.      */
  1124.     e.u.keyButtonPointer.rootX = AIXCurrentX = jx;
  1125.     e.u.keyButtonPointer.rootY = AIXCurrentY = jy;
  1126.     e.u.u.type = MotionNotify;
  1127.  
  1128.     (*ibmPtr->processInputProc)(&e,ibmPtr,1);
  1129.     (*(ibmCursorShow(ibmCurrentScreen)))(jx, jy);
  1130. }
  1131. #endif /* XTESTEXT1 */
  1132.  
  1133. #ifdef AIXEXTENSIONS
  1134.  
  1135. static int aixTabletSaveX = 1 ;
  1136. static int aixTabletSaveY = 1;
  1137. int aixTabletScaleX ;
  1138. int aixTabletScaleY ;
  1139.  
  1140. static void
  1141. aixFlushTablet(deltax,deltay)
  1142. int deltax,deltay;
  1143. {
  1144. register        int     x,y;
  1145. register        ibmPerScreenInfo        *screenInfo;
  1146.             int     setCursor;
  1147.             xEvent  e;
  1148.  
  1149.     TRACE(("aixFlushTablet(%d, %d)\n", deltax, deltay));
  1150.  
  1151.     screenInfo = ibmScreens[ ibmCurrentScreen ];
  1152.     setCursor = TRUE ;
  1153.  
  1154. #ifdef AIXV3
  1155.     /* save current values */
  1156.     aixTabletSaveX = deltax;
  1157.     aixTabletSaveY = deltay;
  1158.  
  1159.     /* deltax and deltay are really absolute tablet coordinates */
  1160.     x = deltax * screenInfo->ibm_ScreenBounds.x2 / aixTabletScaleX;
  1161.     y = deltay * screenInfo->ibm_ScreenBounds.y2 / aixTabletScaleY;
  1162. #else
  1163.     x = AIXCurrentX ;
  1164.     y = screenInfo->ibm_ScreenBounds.y2 - AIXCurrentY ;
  1165.  
  1166.     /*
  1167.      * Analize horizontal movement for releative coordinates
  1168.      */
  1169.  
  1170.     if ( deltax <= aixTabletSaveX )
  1171.     x =  deltax * x / aixTabletSaveX ;
  1172.     else if ((screenInfo->ibm_ScreenBounds.x2 * aixTabletScaleX) != aixTabletSaveX)
  1173.     x += (deltax - aixTabletSaveX) * (screenInfo->ibm_ScreenBounds.x2 - x) /
  1174.          (screenInfo->ibm_ScreenBounds.x2 * aixTabletScaleX - aixTabletSaveX);
  1175.  
  1176.     if ( !deltax )
  1177.     aixTabletSaveX = 1 ;
  1178.     else
  1179.     aixTabletSaveX = deltax;
  1180.  
  1181.     /*
  1182.      * Analize vertical movement for releative coordinates
  1183.      */
  1184.  
  1185.     if ( deltay <= aixTabletSaveY )
  1186.        y = deltay * y / aixTabletSaveY ;
  1187.     else if ((screenInfo->ibm_ScreenBounds.y2 * aixTabletScaleY) != aixTabletSaveY)
  1188.        y += (deltay - aixTabletSaveY) * (screenInfo->ibm_ScreenBounds.y2 - y) /
  1189.         (screenInfo->ibm_ScreenBounds.y2 * aixTabletScaleY - aixTabletSaveY);
  1190.  
  1191.     if ( !deltay)
  1192.     aixTabletSaveY = 1 ;
  1193.     else
  1194.     aixTabletSaveY = deltay ;
  1195. #endif
  1196.  
  1197.     y = screenInfo->ibm_ScreenBounds.y2 - y ;
  1198.  
  1199.     if ( y > screenInfo->ibm_ScreenBounds.y2)
  1200.     y = screenInfo->ibm_ScreenBounds.y2;
  1201.  
  1202.     if ( x > screenInfo->ibm_ScreenBounds.x2)
  1203.     x = screenInfo->ibm_ScreenBounds.x2;
  1204.  
  1205.     if ( y <= 0)
  1206.     y = 0;
  1207.  
  1208.     if ( x <= 0)
  1209.     x = 0;
  1210.  
  1211.     if (setCursor) {
  1212.     /* OS-DEPENDENT MACRO GOES HERE!!
  1213.      * MACRO DEFINED IN FILE ibmos.h
  1214.      * TELL OS THAT CURSOR HAS MOVED
  1215.      * TO A NEW POSITION
  1216.      */
  1217.     setCursorPosition(x,y);
  1218.     }
  1219.  
  1220.     (* screenInfo->ibm_CursorShow )( x, y ) ;
  1221.  
  1222.     AIXCurrentX= x ;
  1223.     AIXCurrentY= y ;
  1224.     pendingX= pendingY= 0;
  1225.  
  1226. }
  1227.  
  1228. /***====================================================================***/
  1229.  
  1230. static int
  1231. aixTabletEvent(pIn)
  1232. hftEvent        *pIn;
  1233. {
  1234. hftLocEv        *pEv= &pIn->hftEv.hftLoc;
  1235. unsigned char   tmpbuttons,buttons ;
  1236. xEvent          e;
  1237.  
  1238. #ifdef AIXTABLET
  1239.  
  1240. xExtEvent       xe;
  1241.  
  1242.     TRACE(("aixTabletEvent()\n"));
  1243.     TRACE(("aixTabletEvent: Event type = %d\n", pIn->hftEvType));
  1244.     TRACE(("aixTabletEvent: Buttons    = %d\n", pEv->leButtons));
  1245.     TRACE(("aixTabletEvent: DeltaX     = %d\n", pEv->leDeltaX));
  1246.     TRACE(("aixTabletEvent: DeltaY     = %d\n", pEv->leDeltaY));
  1247.  
  1248.     xe.u.Tablet.rootX = AIXCurrentX;
  1249.     xe.u.Tablet.rootY = AIXCurrentY;
  1250.     xe.u.Tablet.deviceid = DEVTABLET;
  1251.     xe.u.Tablet.axes_count = 2;             /* always 2 for tablet */
  1252.     xe.u.Tablet.first_axes = 0;             /* 0 - x  1 - y */
  1253.     xe.u.Tablet.axes_data[0] = pEv->leDeltaX;
  1254.     xe.u.Tablet.axes_data[1] = pEv->leDeltaY;
  1255.     lastEventTime = xe.u.Tablet.time = GET_OS_TIME();
  1256.  
  1257.     xe.u.u.type = DeviceMotion;
  1258.     xe.u.u.detail = pEv->leButtons & HFT_TABLET_BUTTONS;
  1259.  
  1260.     if (rtTablet->on)
  1261.         (*(rtTablet->processInputProc))((xEvent *)&xe, rtTablet,1);
  1262.  
  1263. #else AIXTABLET
  1264.  
  1265. #ifdef AIXV3
  1266.     /* check if cursor has moved or different button is pressed */
  1267.     if ((aixTabletSaveX == pEv->leDeltaX) &&
  1268.         (aixTabletSaveY == pEv->leDeltaY) &&
  1269.         ((pEv->leButtons & HFT_TABLET_BUTTONS) == lastButtons))
  1270.             return (1) ;
  1271.  
  1272.     buttons = pEv->leButtons & HFT_TABLET_BUTTONS ;
  1273. #else
  1274.  
  1275.     /* bug compatible */
  1276.  
  1277.     if (pEv->leButtons == 3 )
  1278.             return ;
  1279.  
  1280.     buttons = pEv->leButtons >> 3 ;
  1281.  
  1282.     switch (buttons)
  1283.     {
  1284.     case  1 :
  1285.             buttons = 0x80 ;
  1286.             break ;
  1287.     case  2 :
  1288.             buttons = 0x40 ;
  1289.             break ;
  1290.     case  3 :
  1291.             buttons = 0x20 ;
  1292.             break ;
  1293.     case  4 :
  1294.             buttons = 0x10 ;
  1295.             break ;
  1296.     }
  1297. #endif
  1298.  
  1299.     if (lastButtons != (buttons & HFT_TABLET_BUTTONS)) {
  1300.         if (lastButtons) {
  1301.             e.u.u.type = ButtonRelease;
  1302.             buttons = 0x00 ;
  1303.             tmpbuttons = lastButtons;
  1304.         } else {
  1305.             e.u.u.type = ButtonPress;
  1306.             tmpbuttons = buttons;
  1307.         }
  1308.  
  1309.         lastButtons = buttons & HFT_TABLET_BUTTONS ;
  1310.  
  1311.         switch (tmpbuttons) {
  1312.             case  HFT_BUTTON1 : e.u.u.detail = Button1;  break;
  1313.             case  HFT_BUTTON2 : e.u.u.detail = Button2;  break;
  1314.             case  HFT_BUTTON3 : e.u.u.detail = Button3;  break;
  1315.             case  HFT_BUTTON4 : e.u.u.detail = Button4;  break;
  1316.         }
  1317.     }
  1318.     else
  1319.     {
  1320.         e.u.u.detail= 0 ;
  1321.         e.u.u.type=  MotionNotify;
  1322.     }
  1323.  
  1324.     aixFlushTablet(pEv->leDeltaX,pEv->leDeltaY);
  1325.  
  1326.     e.u.keyButtonPointer.rootX=     AIXCurrentX;
  1327.     e.u.keyButtonPointer.rootY=     AIXCurrentY;
  1328.     e.u.keyButtonPointer.time=      GET_OS_TIME();
  1329.  
  1330.     (*(ibmPtr->processInputProc))(&e,ibmPtr,1);
  1331. #endif AIXTABLET
  1332.  
  1333.     return (1) ;
  1334. }
  1335.  
  1336. #endif AIXEXTENSIONS
  1337.  
  1338.  
  1339. #ifdef AIXEXTENSIONS
  1340. static int
  1341. aixDialEvent (pIn)
  1342. hftEvent        *pIn;
  1343. {
  1344.     xExtEvent   xe;
  1345.     hftDialEv   *pEv = &pIn->hftEv.hftDial;
  1346.  
  1347.     xe.u.DialLpfk.rootX =  AIXCurrentX;
  1348.     xe.u.DialLpfk.rootY =  AIXCurrentY;
  1349.     lastEventTime = xe.u.DialLpfk.time = GET_OS_TIME();
  1350.  
  1351.     xe.u.u.type = DialRotate;
  1352.     xe.u.u.detail = (char) pEv->deDialNo;
  1353.     xe.u.DialLpfk.value = (char) pEv->deDelta;
  1354.  
  1355. #ifdef CFBSERVER
  1356.     if (rtDial->on)
  1357.     (*(rtDial->processInputProc))((xEvent *)&xe, rtDial,1);
  1358. #endif
  1359.  
  1360.     return (1);
  1361. }
  1362.  
  1363.  
  1364. static int
  1365. aixLpfkEvent (pIn)
  1366. hftEvent        *pIn;
  1367. {
  1368.     xExtEvent   xe;
  1369.     hftLPFKEv   *pEv = &pIn->hftEv.hftLpfk;
  1370.  
  1371.     xe.u.DialLpfk.rootX =  AIXCurrentX;
  1372.     xe.u.DialLpfk.rootY =  AIXCurrentY;
  1373.     lastEventTime = xe.u.DialLpfk.time = GET_OS_TIME();
  1374.  
  1375.     xe.u.u.type = LPFKeyPress ;
  1376.     xe.u.u.detail = pEv->lpfkeKeyNo ;
  1377.  
  1378. #ifdef CFBSERVER
  1379.     if (rtLpfk->on)
  1380.     (*(rtLpfk->processInputProc))((xEvent *)&xe, rtLpfk,1);
  1381. #endif
  1382.  
  1383.     return (1);
  1384. }
  1385. #endif
  1386.  
  1387.