home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / XKBExtDev.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  28KB  |  975 lines

  1. /* $XConsortium: XKBExtDev.c /main/3 1996/08/31 12:44:26 kaleb $ */
  2. /************************************************************
  3. Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.
  4.  
  5. Permission to use, copy, modify, and distribute this
  6. software and its documentation for any purpose and without
  7. fee is hereby granted, provided that the above copyright
  8. notice appear in all copies and that both that copyright
  9. notice and this permission notice appear in supporting
  10. documentation, and that the name of Silicon Graphics not be 
  11. used in advertising or publicity pertaining to distribution 
  12. of the software without specific prior written permission.
  13. Silicon Graphics makes no representation about the suitability 
  14. of this software for any purpose. It is provided "as is"
  15. without any express or implied warranty.
  16.  
  17. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
  18. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
  19. AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  20. GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  21. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
  22. DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
  23. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  24. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  25.  
  26. ********************************************************/
  27.  
  28. #include <stdio.h>
  29. #define NEED_REPLIES
  30. #define NEED_EVENTS
  31. #define    NEED_MAP_READERS
  32. #include "Xlib_private.h"
  33. #include <X11/extensions/XKBproto.h>
  34. #include "XKBlibint.h"
  35. #include <X11/extensions/XI.h>
  36.  
  37. /***====================================================================***/
  38.  
  39. extern    void
  40. #if NeedFunctionPrototypes
  41. XkbNoteDeviceChanges(    XkbDeviceChangesPtr        old,
  42.             XkbExtensionDeviceNotifyEvent *    new,
  43.             unsigned int            wanted)
  44. #else
  45. XkbNoteDeviceChanges(old,new,wanted)
  46.     XkbDeviceChangesPtr            old;
  47.     XkbExtensionDeviceNotifyEvent *    new;
  48.     unsigned int            wanted;
  49. #endif
  50. {
  51.     DBUG_ENTER("XkbNoteDeviceChanges")
  52.     if ((!old)||(!new)||(!wanted)||((new->reason&wanted)==0))
  53.     DBUG_VOID_RETURN;
  54.     if ((wanted&new->reason)&XkbXI_ButtonActionsMask) {
  55.     if (old->changed&XkbXI_ButtonActionsMask) {
  56.         int first,last,newLast;
  57.         if (new->first_btn<old->first_btn)
  58.          first= new->first_btn;
  59.         else first= old->first_btn;
  60.         last= old->first_btn+old->num_btns-1;
  61.         newLast= new->first_btn+new->num_btns-1;
  62.         if (newLast>last)
  63.         last= newLast;
  64.         old->first_btn= first;
  65.         old->num_btns= (last-first)+1;
  66.     }
  67.     else {
  68.         old->changed|= XkbXI_ButtonActionsMask;
  69.         old->first_btn= new->first_btn;
  70.         old->num_btns= new->num_btns;
  71.     }
  72.     }
  73.     if ((wanted&new->reason)&XkbXI_IndicatorsMask) {
  74.     XkbDeviceLedChangesPtr this;
  75.     if (old->changed&XkbXI_IndicatorsMask) {
  76.         XkbDeviceLedChangesPtr found;
  77.         found= NULL;
  78.         for (this= &old->leds;this&&(!found);this=this->next) {
  79.         if ((this->led_class==new->led_class)&&
  80.                         (this->led_id==new->led_id)) {
  81.             found= this;
  82.         }
  83.         }
  84.         if (!found) {
  85.         found= _XkbTypedCalloc(1,XkbDeviceLedChangesRec);
  86.         if (!found)
  87.             return;
  88.         found->next= old->leds.next;
  89.         found->led_class= new->led_class;
  90.         found->led_id= new->led_id;
  91.         old->leds.next= found;
  92.         }
  93.         if ((wanted&new->reason)&XkbXI_IndicatorNamesMask)
  94.         found->defined= new->leds_defined;
  95.     }
  96.     else {
  97.         old->changed|= ((wanted&new->reason)&XkbXI_IndicatorsMask);
  98.         old->leds.led_class= new->led_class;
  99.         old->leds.led_id= new->led_id;
  100.         old->leds.defined= new->leds_defined;
  101.         if (old->leds.next) {
  102.         XkbDeviceLedChangesPtr next;
  103.         for (this=old->leds.next;this;this=next) {
  104.             next= this->next;
  105.             _XkbFree(this);
  106.         }
  107.         old->leds.next= NULL;
  108.         }
  109.     }
  110.     }
  111.     DBUG_VOID_RETURN;
  112. }
  113.  
  114. /***====================================================================***/
  115.  
  116. static Status
  117. #if NeedFunctionPrototypes
  118. _XkbReadDeviceLedInfo(    XkbReadBufferPtr    buf,
  119.             unsigned         present,
  120.             XkbDeviceInfoPtr     devi)
  121. #else
  122. _XkbReadDeviceLedInfo(buf,present,devi)
  123.     XkbReadBufferPtr    buf;
  124.     unsigned        present;
  125.     XkbDeviceInfoPtr    devi;
  126. #endif
  127. {
  128.     DBUG_ENTER("_XkbReadDeviceLedInfo")
  129.     register unsigned    i,bit;
  130.     XkbDeviceLedInfoPtr    devli;
  131.     xkbDeviceLedsWireDesc *    wireli;
  132.  
  133.     wireli= _XkbGetTypedRdBufPtr(buf,1,xkbDeviceLedsWireDesc);
  134.     if (!wireli)
  135.     DBUG_RETURN(BadLength);
  136.     devli= XkbAddDeviceLedInfo(devi,wireli->ledClass,wireli->ledID);
  137.     if (!devli)
  138.     DBUG_RETURN(BadAlloc);
  139.     devli->phys_indicators=     wireli->physIndicators;
  140.  
  141.     if (present&XkbXI_IndicatorStateMask)
  142.     devli->state= wireli->state;
  143.  
  144.     if (present&XkbXI_IndicatorNamesMask) {
  145.     devli->names_present=     wireli->namesPresent;
  146.     if (devli->names_present) {
  147.         for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
  148.         if (wireli->namesPresent&bit) {
  149.             if (!_XkbCopyFromReadBuffer(buf,(char *)&devli->names[i],4))
  150.             DBUG_RETURN(BadLength);
  151.         }
  152.         }
  153.     }
  154.     }
  155.  
  156.     if (present&XkbXI_IndicatorMapsMask) {
  157.     devli->maps_present=     wireli->mapsPresent;
  158.     if (devli->maps_present) {
  159.         XkbIndicatorMapPtr         im;
  160.         xkbIndicatorMapWireDesc *    wireim;
  161.         for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
  162.         if (wireli->mapsPresent&bit) {
  163.             wireim= _XkbGetTypedRdBufPtr(buf,1,xkbIndicatorMapWireDesc);
  164.             if (!wireim)
  165.             DBUG_RETURN(BadAlloc);
  166.             im= &devli->maps[i];
  167.             im->flags=         wireim->flags;
  168.             im->which_groups=     wireim->whichGroups;
  169.             im->groups=     wireim->groups;
  170.             im->which_mods=     wireim->whichMods;
  171.             im->mods.mask=     wireim->mods;
  172.             im->mods.real_mods= wireim->realMods;
  173.             im->mods.vmods=     wireim->virtualMods;
  174.             im->ctrls=         wireim->ctrls;
  175.         }
  176.         }
  177.     }
  178.     }
  179.     DBUG_RETURN(Success);
  180. }
  181.  
  182. static Status
  183. #if NeedFunctionPrototypes
  184. _XkbReadGetDeviceInfoReply(    Display *        dpy,
  185.                 xkbGetDeviceInfoReply *    rep,
  186.                 XkbDeviceInfoPtr    devi)
  187. #else
  188. _XkbReadGetDeviceInfoReply(dpy,rep,devi)
  189.     Display *            dpy;
  190.     xkbGetDeviceInfoReply *    rep;
  191.     XkbDeviceInfoPtr        devi;
  192. #endif
  193. {
  194.     DBUG_ENTER("_XkbReadGetDeviceInfoReply")
  195.     XkbReadBufferRec    buf;
  196.     XkbAction *        act;
  197.     int            tmp;
  198.  
  199.     if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4)) 
  200.     DBUG_RETURN(BadAlloc);
  201.  
  202.     if ((rep->totalBtns>0)&&(rep->totalBtns!=devi->num_btns)) {
  203.     tmp= XkbResizeDeviceButtonActions(devi,rep->totalBtns);
  204.     if (tmp!=Success)
  205.         DBUG_RETURN(tmp);
  206.     }
  207.     if (rep->nBtnsWanted>0) {
  208.     act= &devi->btn_acts[rep->firstBtnWanted];
  209.     bzero((char *)act,(rep->nBtnsWanted*sizeof(XkbAction)));
  210.     }
  211.     if (devi->name!=NULL)
  212.     _XkbFree(devi->name);
  213.     if (!_XkbGetReadBufferCountedString(&buf,&devi->name))
  214.     goto BAILOUT;
  215.     if (rep->nBtnsRtrn>0) {
  216.     int size;
  217.     act= &devi->btn_acts[rep->firstBtnRtrn];
  218.     size= rep->nBtnsRtrn*SIZEOF(xkbActionWireDesc);
  219.     if (!_XkbCopyFromReadBuffer(&buf,(char *)act,size))
  220.         goto BAILOUT;
  221.     }
  222.     if (rep->nDeviceLedFBs>0) {
  223.     register int         i;
  224.     for (i=0;i<rep->nDeviceLedFBs;i++) {
  225.         if ((tmp= _XkbReadDeviceLedInfo(&buf,rep->present,devi))!=Success)
  226.         DBUG_RETURN(tmp);
  227.     }
  228.     }
  229.     tmp= _XkbFreeReadBuffer(&buf);
  230.     if (tmp) 
  231.     fprintf(stderr,"GetDeviceInfo! Bad length (%d extra bytes)\n",tmp);
  232.     if (tmp || buf.error)
  233.     DBUG_RETURN(BadLength);
  234.     DBUG_RETURN(Success);
  235. BAILOUT:
  236.     _XkbFreeReadBuffer(&buf);
  237.     DBUG_RETURN(BadLength);
  238. }
  239.  
  240. #if 0
  241. XkbDeviceInfoPtr
  242. #if NeedFunctionPrototypes
  243. XkbGetDeviceInfo(    Display *    dpy,
  244.             unsigned     which,
  245.             unsigned     deviceSpec,
  246.             unsigned     class,
  247.             unsigned     id)
  248. #else
  249. XkbGetDeviceInfo(dpy,which,deviceSpec,class,id)
  250.     Display *    dpy;
  251.     unsigned    which;
  252.     unsigned    deviceSpec;
  253.     unsigned    class;
  254.     unsigned    id;
  255. #endif
  256. {
  257.     DBUG_ENTER("XkbGetDeviceInfo")
  258.     register xkbGetDeviceInfoReq *    req;
  259.     xkbGetDeviceInfoReply         rep;
  260.     Status                status;
  261.     XkbDeviceInfoPtr            devi;
  262.  
  263.     if ((dpy->flags & XlibDisplayNoXkb) ||
  264.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  265.     DBUG_RETURN(NULL);
  266.     LockDisplay(dpy);
  267.     GetReq(kbGetDeviceInfo, req);
  268.     req->reqType = dpy->xkb_info->codes->major_opcode;
  269.     req->xkbReqType = X_kbGetDeviceInfo;
  270.     req->deviceSpec = deviceSpec;
  271.     req->wanted= which;
  272.     req->allBtns= ((which&XkbXI_ButtonActionsMask)!=0);
  273.     req->firstBtn= req->nBtns= 0;
  274.     req->ledClass= class;
  275.     req->ledID= id;
  276.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  277.     UnlockDisplay(dpy);
  278.     SyncHandle();
  279.     DBUG_RETURN(NULL);
  280.     }
  281.     devi= XkbAllocDeviceInfo(rep.deviceID,rep.totalBtns,rep.nDeviceLedFBs);
  282.     if (devi) {
  283.     devi->supported= rep.supported;
  284.     devi->unsupported= rep.unsupported;
  285.     devi->type= rep.devType;
  286.     devi->has_own_state= rep.hasOwnState;
  287.     devi->dflt_kbd_fb = rep.dfltKbdFB;
  288.     devi->dflt_led_fb = rep.dfltLedFB;
  289.     status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
  290.     if (status!=Success) {
  291.         XkbFreeDeviceInfo(devi,XkbXI_AllDeviceFeaturesMask,True);
  292.         devi= NULL;
  293.     }
  294.     }
  295.     UnlockDisplay(dpy);
  296.     SyncHandle();
  297.     DBUG_RETURN(devi);
  298. }
  299.  
  300. Status
  301. #if NeedFunctionPrototypes
  302. XkbGetDeviceInfoChanges(    Display *        dpy,
  303.                 XkbDeviceInfoPtr     devi,
  304.                 XkbDeviceChangesPtr    changes)
  305. #else
  306. XkbGetDeviceInfoChanges(dpy,devi,changes)
  307.     Display *        dpy;
  308.     XkbDeviceInfoPtr    devi;
  309.     XkbDeviceChangesPtr    changes;
  310. #endif
  311. {
  312.     DBUG_ENTER("XkbGetDeviceInfoChanges")
  313.     register xkbGetDeviceInfoReq *    req;
  314.     xkbGetDeviceInfoReply         rep;
  315.     Status                status;
  316.  
  317.     if ((dpy->flags & XlibDisplayNoXkb) ||
  318.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  319.     DBUG_RETURN(BadMatch);
  320.     if ((changes->changed&XkbXI_AllDeviceFeaturesMask)==0)
  321.     DBUG_RETURN(Success);
  322.     changes->changed&= ~XkbXI_AllDeviceFeaturesMask;
  323.     status= Success;
  324.     LockDisplay(dpy);
  325.     while ((changes->changed)&&(status==Success)) {
  326.     GetReq(kbGetDeviceInfo, req);
  327.     req->reqType = dpy->xkb_info->codes->major_opcode;
  328.     req->xkbReqType = X_kbGetDeviceInfo;
  329.     req->deviceSpec = devi->device_spec;
  330.     req->wanted= changes->changed;
  331.     req->allBtns= False;
  332.     if (changes->changed&XkbXI_ButtonActionsMask) {
  333.          req->firstBtn= changes->first_btn;
  334.          req->nBtns=     changes->num_btns;
  335.          changes->changed&= ~XkbXI_ButtonActionsMask;
  336.     }
  337.     else req->firstBtn= req->nBtns= 0;
  338.     if (changes->changed&XkbXI_IndicatorsMask) {
  339.         req->ledClass= changes->leds.led_class;
  340.         req->ledID= changes->leds.led_id;
  341.         if (changes->leds.next==NULL)
  342.         changes->changed&= ~XkbXI_IndicatorsMask;
  343.         else {
  344.         XkbDeviceLedChangesPtr next;
  345.         next= changes->leds.next;
  346.         changes->leds= *next;
  347.         _XkbFree(next);
  348.         }
  349.     }
  350.     else {
  351.         req->ledClass= XkbDfltXIClass;
  352.         req->ledID= XkbDfltXIId;
  353.     }
  354.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  355.         status= BadLength;
  356.         break;
  357.     }
  358.     devi->supported|= rep.supported;
  359.     devi->unsupported|= rep.unsupported;
  360.     devi->type= rep.devType;
  361.     status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
  362.     }
  363.     UnlockDisplay(dpy);
  364.     SyncHandle();
  365.     DBUG_RETURN(status);
  366. }
  367.  
  368. Status
  369. #if NeedFunctionPrototypes
  370. XkbGetDeviceButtonActions(    Display *        dpy,
  371.                 XkbDeviceInfoPtr    devi,
  372.                 Bool            all,
  373.                 unsigned int        first,
  374.                 unsigned int        num)
  375. #else
  376. XkbGetDeviceButtonActions(dpy,devi,all,first,num)
  377.     Display *        dpy;
  378.     XkbDeviceInfoPtr    devi;
  379.     Bool        all;
  380.     unsigned int    first;
  381.     unsigned int    num;
  382. #endif
  383. {
  384.     DBUG_ENTER("XkbGetDeviceButtonActions")
  385.     register xkbGetDeviceInfoReq *    req;
  386.     xkbGetDeviceInfoReply         rep;
  387.     Status                status;
  388.  
  389.     if ((dpy->flags & XlibDisplayNoXkb) || 
  390.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  391.     DBUG_RETURN(BadMatch);
  392.     if (!devi)
  393.     DBUG_RETURN(BadValue);
  394.     LockDisplay(dpy);
  395.     GetReq(kbGetDeviceInfo, req);
  396.     req->reqType = dpy->xkb_info->codes->major_opcode;
  397.     req->xkbReqType = X_kbGetDeviceInfo;
  398.     req->deviceSpec = devi->device_spec;
  399.     req->wanted= XkbXI_ButtonActionsMask;
  400.     req->allBtns= all;
  401.     req->firstBtn= first;
  402.     req->nBtns= num;
  403.     req->ledClass= XkbDfltXIClass;
  404.     req->ledID= XkbDfltXIId;
  405.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  406.     UnlockDisplay(dpy);
  407.     SyncHandle();
  408.     DBUG_RETURN(BadLength);
  409.     }
  410.     devi->type= rep.devType;
  411.     devi->supported= rep.supported;
  412.     devi->unsupported= rep.unsupported;
  413.     status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
  414.     UnlockDisplay(dpy);
  415.     SyncHandle();
  416.     DBUG_RETURN(status);
  417. }
  418.  
  419. Status
  420. #if NeedFunctionPrototypes
  421. XkbGetDeviceLedInfo(    Display *        dpy,
  422.             XkbDeviceInfoPtr    devi,
  423.             unsigned int        ledClass,
  424.             unsigned int        ledId,
  425.             unsigned int        which)
  426. #else
  427. XkbGetDeviceLedInfo(dpy,devi,ledClass,ledId,which)
  428.     Display *        dpy;
  429.     XkbDeviceInfoPtr    devi;
  430.     unsigned int    ledClass;
  431.     unsigned int    ledId;
  432.     unsigned int    which;
  433. #endif
  434. {
  435.     DBUG_ENTER("XkbGetDeviceLedInfo")
  436.     register xkbGetDeviceInfoReq *    req;
  437.     xkbGetDeviceInfoReply         rep;
  438.     Status                status;
  439.  
  440.     if ((dpy->flags & XlibDisplayNoXkb) || 
  441.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  442.     DBUG_RETURN(BadMatch);
  443.     if (((which&XkbXI_IndicatorsMask)==0)||(which&(~XkbXI_IndicatorsMask)))
  444.     DBUG_RETURN(BadMatch);
  445.     if (!devi)
  446.     DBUG_RETURN(BadValue);
  447.     LockDisplay(dpy);
  448.     GetReq(kbGetDeviceInfo, req);
  449.     req->reqType = dpy->xkb_info->codes->major_opcode;
  450.     req->xkbReqType = X_kbGetDeviceInfo;
  451.     req->deviceSpec = devi->device_spec;
  452.     req->wanted= which;
  453.     req->allBtns= False;
  454.     req->firstBtn= req->nBtns= 0;
  455.     req->ledClass= ledClass;
  456.     req->ledID= ledId;
  457.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  458.     UnlockDisplay(dpy);
  459.     SyncHandle();
  460.     DBUG_RETURN(BadLength);
  461.     } 
  462.     devi->type= rep.devType;
  463.     devi->supported= rep.supported;
  464.     devi->unsupported= rep.unsupported;
  465.     status= _XkbReadGetDeviceInfoReply(dpy,&rep,devi);
  466.     UnlockDisplay(dpy);
  467.     SyncHandle();
  468.     DBUG_RETURN(status);
  469. }
  470. #endif
  471. /***====================================================================***/
  472.  
  473. typedef struct _LedInfoStuff {
  474.     Bool            used;
  475.     XkbDeviceLedInfoPtr    devli;
  476. } LedInfoStuff;
  477.  
  478. typedef struct _SetLedStuff {
  479.     unsigned        wanted;
  480.     int            num_info;
  481.     int            dflt_class;
  482.     LedInfoStuff *        dflt_kbd_fb;
  483.     LedInfoStuff *        dflt_led_fb;
  484.     LedInfoStuff *        info;
  485. } SetLedStuff;
  486.  
  487. static void
  488. #if NeedFunctionPrototypes
  489. _InitLedStuff(SetLedStuff *stuff,unsigned wanted,XkbDeviceInfoPtr devi)
  490. #else
  491. _InitLedStuff(stuff,wanted,devi)
  492.     SetLedStuff     *    stuff;
  493.     unsigned        wanted;
  494.     XkbDeviceInfoPtr    devi;
  495. #endif
  496. {
  497.     DBUG_ENTER("_InitLedStuff")
  498.     int                i;
  499.     register XkbDeviceLedInfoPtr    devli;
  500.  
  501.     bzero(stuff,sizeof(SetLedStuff));
  502.     stuff->wanted= wanted;
  503.     stuff->dflt_class=    XkbXINone;
  504.     if ((devi->num_leds<1)||((wanted&XkbXI_IndicatorsMask)==0))
  505.     DBUG_VOID_RETURN;
  506.     stuff->info= _XkbTypedCalloc(devi->num_leds,LedInfoStuff);
  507.     if (!stuff->info)
  508.     DBUG_VOID_RETURN;
  509.     stuff->num_info= devi->num_leds;
  510.     for (devli=&devi->leds[0],i=0;i<devi->num_leds;i++,devli++) {
  511.     stuff->info[i].devli= devli;
  512.     if (devli->led_class==KbdFeedbackClass) {
  513.         stuff->dflt_class= KbdFeedbackClass;
  514.         if (stuff->dflt_kbd_fb==NULL)
  515.         stuff->dflt_kbd_fb= &stuff->info[i];
  516.     }
  517.     else if (devli->led_class==LedFeedbackClass) {
  518.         if (stuff->dflt_class==XkbXINone)
  519.         stuff->dflt_class= LedFeedbackClass;
  520.         if (stuff->dflt_led_fb==NULL)
  521.         stuff->dflt_led_fb= &stuff->info[i];
  522.     }
  523.     }
  524.     DBUG_VOID_RETURN;
  525. }
  526.  
  527. static void
  528. #if NeedFunctionPrototypes
  529. _FreeLedStuff(SetLedStuff *stuff)
  530. #else
  531. _FreeLedStuff(stuff)
  532.     SetLedStuff    *stuff;
  533. #endif
  534. {
  535.     DBUG_ENTER("_FreeLedStuff")
  536.     if ((stuff->num_info>0)&&(stuff->info!=NULL))
  537.     _XkbFree(stuff->info);
  538.     bzero(stuff,sizeof(SetLedStuff));
  539.     DBUG_VOID_RETURN;
  540. }
  541.  
  542. static int
  543. #if NeedFunctionPrototypes
  544. _XkbSizeLedInfo(unsigned changed,XkbDeviceLedInfoPtr devli)
  545. #else
  546. _XkbSizeLedInfo(changed,devli)
  547.     unsigned        changed;
  548.     XkbDeviceLedInfoPtr    devli;
  549. #endif
  550. {
  551.     DBUG_ENTER("_XkbSizeLedInfo")
  552.     register int i,size;
  553.     register unsigned bit,namesNeeded,mapsNeeded;
  554.  
  555.     size= SIZEOF(xkbDeviceLedsWireDesc);
  556.     namesNeeded= mapsNeeded= 0;
  557.     if (changed&XkbXI_IndicatorNamesMask)
  558.     namesNeeded= devli->names_present;
  559.     if (changed&XkbXI_IndicatorMapsMask)
  560.     mapsNeeded= devli->maps_present;
  561.     if ((namesNeeded)||(mapsNeeded)) {
  562.     for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
  563.         if (namesNeeded&bit)
  564.         size+= 4; /* atoms are 4 bytes on the wire */
  565.         if (mapsNeeded&bit)
  566.         size+= SIZEOF(xkbIndicatorMapWireDesc);
  567.     }
  568.     }
  569.     DBUG_RETURN(size);
  570. }
  571.  
  572. static Bool
  573. #if NeedFunctionPrototypes
  574. _SizeMatches(    SetLedStuff *        stuff,
  575.         XkbDeviceLedChangesPtr     changes,
  576.         int *            sz_rtrn,
  577.         int *            nleds_rtrn)
  578. #else
  579. _SizeMatches(stuff,changes,sz_rtrn,nleds_rtrn)
  580.     SetLedStuff *        stuff;
  581.     XkbDeviceLedChangesPtr    changes;
  582.     int *            sz_rtrn;
  583.     int *            nleds_rtrn;
  584. #endif
  585. {
  586.     DBUG_ENTER("_SizeMatches")
  587.     int        i,nMatch,class,id;
  588.     LedInfoStuff *    linfo;
  589.     Bool        match;
  590.  
  591.     nMatch= 0;
  592.     class= changes->led_class;
  593.     id= changes->led_id;
  594.     if (class==XkbDfltXIClass)
  595.     class= stuff->dflt_class;
  596.     for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) {
  597.     XkbDeviceLedInfoPtr    devli;
  598.     LedInfoStuff *        dflt;
  599.  
  600.     devli= linfo->devli;
  601.     match= ((class==devli->led_class)||(class==XkbAllXIClasses));
  602.     if (devli->led_class==KbdFeedbackClass)    dflt= stuff->dflt_kbd_fb;
  603.     else                    dflt= stuff->dflt_led_fb;
  604.     match= match && (id==devli->led_id) || (id==XkbAllXIIds) ||
  605.                     ((id==XkbDfltXIId)&&(linfo==dflt));
  606.     if (match) {
  607.         if (!linfo->used) {
  608.         *sz_rtrn+= _XkbSizeLedInfo(stuff->wanted,devli);
  609.         *nleds_rtrn+= 1;
  610.         linfo->used= True;
  611.         if ((class!=XkbAllXIClasses)&&(id!=XkbAllXIIds))
  612.             DBUG_RETURN(True);
  613.         }
  614.         nMatch++;
  615.         linfo->used= True;
  616.     }
  617.     }
  618.     DBUG_RETURN(nMatch>0);
  619. }
  620.  
  621. /***====================================================================***/
  622.  
  623.  
  624. static Status
  625. #if NeedFunctionPrototypes
  626. _XkbSetDeviceInfoSize(    XkbDeviceInfoPtr    devi,
  627.             XkbDeviceChangesPtr    changes,
  628.             SetLedStuff *        stuff,
  629.             int *            sz_rtrn,
  630.             int *            num_leds_rtrn)
  631. #else
  632. _XkbSetDeviceInfoSize(devi,changes,stuff,sz_rtrn,num_leds_rtrn)
  633.     XkbDeviceInfoPtr    devi;
  634.     XkbDeviceChangesPtr    changes;
  635.     SetLedStuff *    stuff;
  636.     int *        sz_rtrn;
  637.     int *        num_leds_rtrn;
  638. #endif
  639. {
  640.     DBUG_ENTER("_XkbSetDeviceInfoSize")
  641.     *sz_rtrn= 0;
  642.     if ((changes->changed&XkbXI_ButtonActionsMask)&&(changes->num_btns>0)) {
  643.     if (!XkbXI_LegalDevBtn(devi,(changes->first_btn+changes->num_btns-1)))
  644.         DBUG_RETURN(BadMatch);
  645.     *sz_rtrn+= changes->num_btns*SIZEOF(xkbActionWireDesc);
  646.     }
  647.     else {
  648.     changes->changed&= ~XkbXI_ButtonActionsMask;
  649.     changes->first_btn= changes->num_btns= 0;
  650.     }
  651.     if ((changes->changed&XkbXI_IndicatorsMask)&&
  652.                 XkbLegalXILedClass(changes->leds.led_class)) {
  653.     XkbDeviceLedChangesPtr    leds;
  654.  
  655.     for (leds=&changes->leds;leds!=NULL;leds= leds->next) {
  656.         if (!_SizeMatches(stuff,leds,sz_rtrn,num_leds_rtrn))
  657.         DBUG_RETURN(BadMatch);
  658.     }
  659.     }
  660.     else {
  661.     changes->changed&= ~XkbXI_IndicatorsMask;
  662.     *num_leds_rtrn= 0;
  663.     }
  664.     DBUG_RETURN(Success);
  665. }
  666.  
  667. static char *
  668. #if NeedFunctionPrototypes
  669. _XkbWriteLedInfo(char *wire,unsigned changed,XkbDeviceLedInfoPtr devli)
  670. #else
  671. _XkbWriteLedInfo(wire,changed,devli)
  672.     char *            wire;
  673.     unsigned            changed;
  674.     XkbDeviceLedInfoPtr        devli;
  675. #endif
  676. {
  677.     DBUG_ENTER("_XkbWriteLedInfo")
  678.     register int         i;
  679.     register unsigned     bit,namesNeeded,mapsNeeded;
  680.     xkbDeviceLedsWireDesc *    lwire;
  681.  
  682.     namesNeeded= mapsNeeded= 0;
  683.     if (changed&XkbXI_IndicatorNamesMask)
  684.     namesNeeded= devli->names_present;
  685.     if (changed&XkbXI_IndicatorMapsMask)
  686.     mapsNeeded= devli->maps_present;
  687.  
  688.     lwire= (xkbDeviceLedsWireDesc *)wire;
  689.     lwire->ledClass= devli->led_class;
  690.     lwire->ledID= devli->led_id;
  691.     lwire->namesPresent= namesNeeded;
  692.     lwire->mapsPresent=  mapsNeeded;
  693.     lwire->physIndicators= devli->phys_indicators;
  694.     lwire->state= devli->state;
  695.     wire= (char *)&lwire[1];
  696.     if (namesNeeded) {
  697.     CARD32 *awire;
  698.     awire= (CARD32 *)wire;
  699.     for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
  700.         if (namesNeeded&bit) {
  701.         *awire= (CARD32)devli->names[i];
  702.         awire++;
  703.         }
  704.     }
  705.     wire= (char *)awire;
  706.     }
  707.     if (mapsNeeded) {
  708.     xkbIndicatorMapWireDesc *mwire;
  709.  
  710.     mwire= (xkbIndicatorMapWireDesc *)wire;
  711.     for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) {
  712.         if (mapsNeeded&bit) {
  713.         XkbIndicatorMapPtr    map;
  714.         map=             &devli->maps[i];
  715.         mwire->flags=         map->flags;
  716.         mwire->whichGroups=    map->which_groups;
  717.         mwire->groups=        map->groups;
  718.         mwire->whichMods=    map->which_mods;
  719.         mwire->mods=        map->mods.mask;
  720.         mwire->realMods=    map->mods.real_mods;
  721.         mwire->virtualMods=    map->mods.vmods;
  722.         mwire->ctrls=        map->ctrls;
  723.         mwire++;
  724.         }
  725.     }
  726.     wire= (char *)mwire;
  727.     }
  728.     DBUG_RETURN(wire);
  729. }
  730.  
  731.  
  732. static int
  733. #if NeedFunctionPrototypes
  734. _XkbWriteSetDeviceInfo(    char *            wire,
  735.             XkbDeviceChangesPtr    changes,
  736.             SetLedStuff *        stuff,
  737.             XkbDeviceInfoPtr    devi)
  738. #else
  739. _XkbWriteSetDeviceInfo(wire,changes,stuff,devi)
  740.     char *            wire;
  741.     XkbDeviceChangesPtr        changes;
  742.     SetLedStuff *        stuff;
  743.     XkbDeviceInfoPtr        devi;
  744. #endif
  745. {
  746.     DBUG_ENTER("_XkbWriteSetDeviceInfo")
  747.     char *start;
  748.  
  749.     start= wire;
  750.     if (changes->changed&XkbXI_ButtonActionsMask) {
  751.     int            size;
  752.     size= changes->num_btns*SIZEOF(xkbActionWireDesc);
  753.     memcpy(wire,(char *)&devi->btn_acts[changes->first_btn],size);
  754.     wire+= size;
  755.     }
  756.     if (changes->changed&XkbXI_IndicatorsMask) {
  757.     register int i;
  758.     register LedInfoStuff *linfo;
  759.  
  760.     for (i=0,linfo=&stuff->info[0];i<stuff->num_info;i++,linfo++) {
  761.         if (linfo->used) {
  762.         register char *new_wire;
  763.         new_wire= _XkbWriteLedInfo(wire,stuff->wanted,linfo->devli);
  764.         if (!new_wire)
  765.             return wire-start;
  766.         wire= new_wire;
  767.         }
  768.     }
  769.     }
  770.     DBUG_RETURN(wire-start);
  771. }
  772.  
  773. #if 0
  774. Bool
  775. #if NeedFunctionPrototypes
  776. XkbSetDeviceInfo(    Display *        dpy,
  777.             unsigned         which,
  778.             XkbDeviceInfoPtr    devi)
  779. #else
  780. XkbSetDeviceInfo(dpy,which,devi)
  781.     Display *        dpy;
  782.     unsigned         which;
  783.     XkbDeviceInfoPtr    devi;
  784. #endif
  785. {
  786.     DBUG_ENTER("XkbSetDeviceInfo")
  787.     register xkbSetDeviceInfoReq *req;
  788.     Status                 ok;
  789.     int                size,nLeds;
  790.     XkbInfoPtr             xkbi;
  791.     XkbDeviceChangesRec        changes;
  792.     SetLedStuff            lstuff;
  793.  
  794.     if ((dpy->flags & XlibDisplayNoXkb) ||
  795.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  796.     DBUG_RETURN(False);
  797.     if ((!devi) || (which&(~XkbXI_AllDeviceFeaturesMask)) ||
  798.     ((which&XkbXI_ButtonActionsMask)&&(!XkbXI_DevHasBtnActs(devi)))||
  799.     ((which&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi))))
  800.     DBUG_RETURN(False);
  801.  
  802.     bzero((char *)&changes,sizeof(XkbDeviceChangesRec));
  803.     changes.changed= which;
  804.     changes.first_btn=        0;
  805.     changes.num_btns=        devi->num_btns;
  806.     changes.leds.led_class=    XkbAllXIClasses;
  807.     changes.leds.led_id=    XkbAllXIIds;
  808.     changes.leds.defined=    0;
  809.     size= nLeds=         0;
  810.     _InitLedStuff(&lstuff,changes.changed,devi);
  811.     if (_XkbSetDeviceInfoSize(devi,&changes,&lstuff,&size,&nLeds)!=Success)
  812.     DBUG_RETURN(False);
  813.     LockDisplay(dpy);
  814.     xkbi = dpy->xkb_info;
  815.     GetReq(kbSetDeviceInfo, req);
  816.     req->length+=    size/4;
  817.     req->reqType=     xkbi->codes->major_opcode;
  818.     req->xkbReqType=     X_kbSetDeviceInfo;
  819.     req->deviceSpec=     devi->device_spec;
  820.     req->firstBtn=    changes.first_btn;
  821.     req->nBtns=        changes.num_btns;
  822.     req->change=    changes.changed;
  823.     req->nDeviceLedFBs=    nLeds;
  824.     if (size>0) {
  825.     char *     wire;
  826.     BufAlloc(char *,wire,size);
  827.     ok= (wire!=NULL)&&
  828.         (_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size);
  829.     }
  830.     UnlockDisplay(dpy);
  831.     SyncHandle();
  832.     _FreeLedStuff(&lstuff);
  833.     /* 12/11/95 (ef) -- XXX!! should clear changes here */
  834.     DBUG_RETURN(ok);
  835. }
  836.  
  837. Bool
  838. #if NeedFunctionPrototypes
  839. XkbChangeDeviceInfo(    Display *        dpy,
  840.             XkbDeviceInfoPtr    devi,
  841.             XkbDeviceChangesPtr    changes)
  842. #else
  843. XkbChangeDeviceInfo(dpy,devi,changes)
  844.     Display *        dpy;
  845.     XkbDeviceInfoPtr    devi;
  846.     XkbDeviceChangesPtr    changes;
  847. #endif
  848. {
  849.     DBUG_ENTER("XkbChangeDeviceInfo")
  850.     register xkbSetDeviceInfoReq *req;
  851.     Status                 ok;
  852.     int                size,nLeds;
  853.     XkbInfoPtr             xkbi;
  854.     SetLedStuff            lstuff;
  855.  
  856.     if ((dpy->flags & XlibDisplayNoXkb) ||
  857.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  858.     DBUG_RETURN(False);
  859.     if ((!devi) || (changes->changed&(~XkbXI_AllDeviceFeaturesMask)) ||
  860.     ((changes->changed&XkbXI_ButtonActionsMask)&&
  861.                     (!XkbXI_DevHasBtnActs(devi)))||
  862.     ((changes->changed&XkbXI_IndicatorsMask)&&(!XkbXI_DevHasLeds(devi))))
  863.     DBUG_RETURN(False);
  864.  
  865.     size= nLeds= 0;
  866.     _InitLedStuff(&lstuff,changes->changed,devi);
  867.     if (_XkbSetDeviceInfoSize(devi,changes,&lstuff,&size,&nLeds)!=Success)
  868.     DBUG_RETURN(False);
  869.     LockDisplay(dpy);
  870.     xkbi = dpy->xkb_info;
  871.     GetReq(kbSetDeviceInfo, req);
  872.     req->length+=    size/4;
  873.     req->reqType=     xkbi->codes->major_opcode;
  874.     req->xkbReqType=     X_kbSetDeviceInfo;
  875.     req->deviceSpec=     devi->device_spec;
  876.     req->firstBtn=    changes->first_btn;
  877.     req->nBtns=        changes->num_btns;
  878.     req->change=    changes->changed;
  879.     req->nDeviceLedFBs=    nLeds;
  880.     if (size>0) {
  881.     char *     wire;
  882.     BufAlloc(char *,wire,size);
  883.     ok= (wire!=NULL)&&
  884.         (_XkbWriteSetDeviceInfo(wire,changes,&lstuff,devi)==size);
  885.     }
  886.     UnlockDisplay(dpy);
  887.     SyncHandle();
  888.     _FreeLedStuff(&lstuff);
  889.     /* 12/11/95 (ef) -- XXX!! should clear changes here */
  890.     DBUG_RETURN(ok);
  891. }
  892. #endif
  893.  
  894. Bool 
  895. #if NeedFunctionPrototypes
  896. XkbSetDeviceLedInfo(    Display *        dpy,
  897.             XkbDeviceInfoPtr    devi,
  898.             unsigned         ledClass,
  899.             unsigned        ledID,
  900.             unsigned        which)
  901. #else
  902. XkbSetDeviceLedInfo(dpy,devi,ledClass,ledID,which)
  903.     Display *        dpy;
  904.     XkbDeviceInfoPtr    devi;
  905.     unsigned         ledClass;
  906.     unsigned        ledID;
  907.     unsigned        which;
  908. #endif
  909. {
  910.     return False;
  911. }
  912.  
  913. #if 0
  914. Bool 
  915. #if NeedFunctionPrototypes
  916. XkbSetDeviceButtonActions(    Display *        dpy,
  917.                 XkbDeviceInfoPtr     devi,
  918.                 unsigned int        first,
  919.                 unsigned int        nBtns)
  920. #else
  921. XkbSetDeviceButtonActions(dpy,devi,first,nBtns)
  922.     Display *        dpy;
  923.     XkbDeviceInfoPtr    devi;
  924.     unsigned int        first;
  925.     unsigned int        nBtns;
  926. #endif
  927. {
  928.     DBUG_ENTER("XkbSetDeviceButtonActions")
  929.     register xkbSetDeviceInfoReq *req;
  930.     Status                 ok;
  931.     int                size,nLeds;
  932.     XkbInfoPtr             xkbi;
  933.     XkbDeviceChangesRec        changes;
  934.     SetLedStuff            lstuff;
  935.  
  936.     if ((dpy->flags & XlibDisplayNoXkb) ||
  937.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  938.     DBUG_RETURN(False);
  939.     if ((!devi)||(!XkbXI_DevHasBtnActs(devi))||(first+nBtns>devi->num_btns))
  940.     DBUG_RETURN(False);
  941.     if (nBtns==0)
  942.     DBUG_RETURN(True);
  943.  
  944.     bzero((char *)&changes,sizeof(XkbDeviceChangesRec));
  945.     changes.changed=         XkbXI_ButtonActionsMask;
  946.     changes.first_btn=        first;
  947.     changes.num_btns=        nBtns;
  948.     changes.leds.led_class=    XkbXINone;
  949.     changes.leds.led_id=    XkbXINone;
  950.     changes.leds.defined=    0;
  951.     size= nLeds=         0;
  952.     if (_XkbSetDeviceInfoSize(devi,&changes,NULL,&size,&nLeds)!=Success)
  953.     DBUG_RETURN(False);
  954.     LockDisplay(dpy);
  955.     xkbi = dpy->xkb_info;
  956.     GetReq(kbSetDeviceInfo, req);
  957.     req->length+=    size/4;
  958.     req->reqType=     xkbi->codes->major_opcode;
  959.     req->xkbReqType=     X_kbSetDeviceInfo;
  960.     req->deviceSpec=     devi->device_spec;
  961.     req->firstBtn=    changes.first_btn;
  962.     req->nBtns=        changes.num_btns;
  963.     req->change=    changes.changed;
  964.     req->nDeviceLedFBs=    nLeds;
  965.     if (size>0) {
  966.     char *     wire;
  967.     BufAlloc(char *,wire,size);
  968.     ok= (wire!=NULL)&&
  969.         (_XkbWriteSetDeviceInfo(wire,&changes,&lstuff,devi)==size);
  970.     }
  971.     UnlockDisplay(dpy);
  972.     SyncHandle();
  973.     DBUG_RETURN(ok);
  974. }
  975. #endif