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

  1. /* $XConsortium: XKBNames.c /main/8 1996/01/14 16:43:43 kaleb $ */
  2. /************************************************************
  3. Copyright (c) 1993 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. #define NEED_REPLIES
  29. #define NEED_EVENTS
  30. #include "Xlib_private.h"
  31. #include <X11/extensions/XKBproto.h>
  32. #include "XKBlibint.h"
  33.  
  34. static Status
  35. #if NeedFunctionPrototypes
  36. _XkbReadAtoms(    XkbReadBufferPtr    buf,
  37.         Atom *            atoms,
  38.         int            maxAtoms,
  39.         CARD32             present)
  40. #else
  41. _XkbReadAtoms(buf,atoms,maxAtoms,present)
  42.     XkbReadBufferPtr     buf;
  43.     Atom        *atoms;
  44.     int             maxAtoms;
  45.     CARD32         present;
  46. #endif
  47. {
  48.     DBUG_ENTER("_XkbReadAtoms")
  49.     register int i,bit;
  50.  
  51.     for (i=0,bit=1;(i<maxAtoms)&&(present);i++,bit<<=1) {
  52.     if (present&bit) {
  53.         if (!_XkbReadBufferCopy32(buf,(long *)&atoms[i],1))
  54.         DBUG_RETURN(BadLength);
  55.         present&= ~bit;
  56.     }
  57.     }
  58.     DBUG_RETURN(Success);
  59. }
  60.  
  61. Status
  62. #if NeedFunctionPrototypes
  63. _XkbReadGetNamesReply(    Display *        dpy,
  64.             xkbGetNamesReply *    rep,
  65.             XkbDescPtr         xkb,
  66.             int *            nread_rtrn)
  67. #else
  68. _XkbReadGetNamesReply(dpy,rep,xkb,nread_rtrn)
  69.     Display *        dpy;
  70.     xkbGetNamesReply *    rep;
  71.     XkbDescPtr         xkb;
  72.     int *        nread_rtrn;
  73. #endif
  74. {
  75.     DBUG_ENTER("_XkbReadGetNamesReply")
  76.     int                 i,len;
  77.     XkbReadBufferRec         buf;
  78.     register XkbNamesPtr     names;
  79.  
  80.     if ( xkb->device_spec == XkbUseCoreKbd )
  81.     xkb->device_spec = rep->deviceID;
  82.  
  83.     if ((xkb->names==NULL)&&
  84.     (XkbAllocNames(xkb,rep->which,
  85.                 rep->nRadioGroups,rep->nKeyAliases)!=Success)) {
  86.     DBUG_RETURN(BadAlloc);
  87.     }
  88.     names= xkb->names;
  89.     if (rep->length==0)
  90.     DBUG_RETURN(Success);
  91.  
  92.     if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
  93.     DBUG_RETURN(BadAlloc);
  94.     if (nread_rtrn)
  95.     *nread_rtrn= (int)rep->length*4;
  96.  
  97.     if ((rep->which&XkbKeycodesNameMask)&&
  98.     (!_XkbReadBufferCopy32(&buf,(long *)&names->keycodes,1)))
  99.         goto BAILOUT;
  100.     if ((rep->which&XkbGeometryNameMask)&&
  101.     (!_XkbReadBufferCopy32(&buf,(long *)&names->geometry,1)))
  102.         goto BAILOUT;
  103.     if ((rep->which&XkbSymbolsNameMask)&&
  104.     (!_XkbReadBufferCopy32(&buf,(long *)&names->symbols,1)))
  105.         goto BAILOUT;
  106.     if ((rep->which&XkbPhysSymbolsNameMask)&&
  107.     (!_XkbReadBufferCopy32(&buf,(long *)&names->phys_symbols,1)))
  108.         goto BAILOUT;
  109.     if ((rep->which&XkbTypesNameMask)&&
  110.     (!_XkbReadBufferCopy32(&buf,(long *)&names->types,1)))
  111.         goto BAILOUT;
  112.     if ((rep->which&XkbCompatNameMask)&&
  113.     (!_XkbReadBufferCopy32(&buf,(long *)&names->compat,1)))
  114.         goto BAILOUT;
  115.  
  116.     if ( rep->which & XkbKeyTypeNamesMask ) {
  117.     XkbClientMapPtr    map= xkb->map;
  118.     XkbKeyTypePtr    type;
  119.  
  120.     len= rep->nTypes*4;
  121.     if (map!=NULL) {
  122.         type= map->types;
  123.         for (i=0;(i<map->num_types)&&(i<rep->nTypes);i++,type++) {
  124.         if (!_XkbReadBufferCopy32(&buf,(long *)&type->name,1))
  125.             goto BAILOUT;
  126.         len-= 4;
  127.         }
  128.     }
  129.     if ((len>0)&&(!_XkbSkipReadBufferData(&buf,len)))
  130.         goto BAILOUT;
  131.     }
  132.     if ( rep->which&XkbKTLevelNamesMask ) {
  133.     CARD8 *nLevels;
  134.     XkbClientMapPtr    map= xkb->map;
  135.     XkbKeyTypePtr    type;
  136.  
  137.     nLevels=(CARD8*)_XkbGetReadBufferPtr(&buf,XkbPaddedSize(rep->nTypes));
  138.     if (nLevels==NULL)
  139.         goto BAILOUT;
  140.     if (map!=NULL) {
  141.         type= map->types;
  142.         for (i=0;i<(int)rep->nTypes;i++,type++) {
  143.         if (i>=map->num_types) {
  144.             if (!_XkbSkipReadBufferData(&buf,nLevels[i]*4))
  145.             goto BAILOUT;
  146.             continue;
  147.         }
  148.         if ((nLevels[i]>0)&&(nLevels[i]!=type->num_levels)) {
  149.             goto BAILOUT;
  150.         }
  151.         if (type->level_names!=NULL)
  152.             Xfree(type->level_names);
  153.         if (nLevels[i]==0) {
  154.             type->level_names= NULL;
  155.             continue;
  156.         }
  157.         type->level_names= _XkbTypedCalloc(nLevels[i],Atom);
  158.         if (type->level_names!=NULL) {
  159.             if (!_XkbReadBufferCopy32(&buf,(long *)type->level_names,
  160.                                 nLevels[i]))
  161.             goto BAILOUT;
  162.         }
  163.         else {
  164.             _XkbSkipReadBufferData(&buf,nLevels[i]*4);
  165.         }
  166.         }
  167.     }
  168.     else {
  169.         for (i=0;i<(int)rep->nTypes;i++) {
  170.         _XkbSkipReadBufferData(&buf,nLevels[i]*4);
  171.         }
  172.     }
  173.     }
  174.     if (rep->which & XkbIndicatorNamesMask) {
  175.     if (_XkbReadAtoms(&buf,names->indicators,XkbNumIndicators,
  176.                         rep->indicators)!=Success)
  177.         goto BAILOUT;
  178.     }
  179.     if ( rep->which&XkbVirtualModNamesMask ) {
  180.     if (_XkbReadAtoms(&buf,names->vmods,XkbNumVirtualMods,
  181.                     (CARD32)rep->virtualMods)!=Success)
  182.         goto BAILOUT;
  183.     }
  184.     if ( rep->which&XkbGroupNamesMask ) {
  185.     if (_XkbReadAtoms(&buf,names->groups,XkbNumKbdGroups,
  186.                     (CARD32)rep->groupNames)!=Success)
  187.         goto BAILOUT;
  188.     }
  189.     if ( rep->which&XkbKeyNamesMask ) {
  190.     if (names->keys==NULL) {
  191.         int nKeys;
  192.         if (xkb->max_key_code==0) {
  193.         xkb->min_key_code= rep->minKeyCode;
  194.         xkb->max_key_code= rep->maxKeyCode;
  195.         }
  196.         nKeys= xkb->max_key_code+1;
  197.         names->keys= _XkbTypedCalloc(nKeys,XkbKeyNameRec);
  198.     }
  199.     if (names->keys!=NULL) {
  200.         if (!_XkbCopyFromReadBuffer(&buf,
  201.                     (char *)&names->keys[rep->firstKey],
  202.                     rep->nKeys*XkbKeyNameLength))
  203.         goto BAILOUT;
  204.     }
  205.     else _XkbSkipReadBufferData(&buf,rep->nKeys*XkbKeyNameLength);
  206.     }
  207.     if ( rep->which&XkbKeyAliasesMask && (rep->nKeyAliases>0) ) {
  208.     if (XkbAllocNames(xkb,XkbKeyAliasesMask,0,rep->nKeyAliases)!=Success)
  209.         goto BAILOUT;
  210.     if (!_XkbCopyFromReadBuffer(&buf,(char *)names->key_aliases,
  211.                 rep->nKeyAliases*XkbKeyNameLength*2))
  212.         goto BAILOUT;
  213.     }
  214.     if ( rep->which&XkbRGNamesMask ) {
  215.     if (rep->nRadioGroups>0) {
  216.         Atom *rgNames;
  217.  
  218.         if (names->radio_groups==NULL)
  219.         names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups,Atom);
  220.         else if (names->num_rg<rep->nRadioGroups) {
  221.         names->radio_groups = _XkbTypedRealloc(names->radio_groups,
  222.                             rep->nRadioGroups,
  223.                             Atom);
  224.         }
  225.         rgNames= names->radio_groups;
  226.         if (!rgNames) {
  227.         goto BAILOUT;
  228.         }
  229.         if (!_XkbReadBufferCopy32(&buf,(long *)rgNames,rep->nRadioGroups))
  230.         goto BAILOUT;
  231.         names->num_rg= rep->nRadioGroups;
  232.     }
  233.     else if (names->num_rg>0) {
  234.         names->num_rg= 0;
  235.         Xfree(names->radio_groups);
  236.     }
  237.     }
  238.     len= _XkbFreeReadBuffer(&buf);
  239.     if (len!=0) {     DBUG_RETURN(BadLength);
  240.     } else        DBUG_RETURN(Success);
  241. BAILOUT:
  242.     _XkbFreeReadBuffer(&buf);
  243.     DBUG_RETURN(BadLength);
  244. }
  245.  
  246. #if 0
  247. Status
  248. #if NeedFunctionPrototypes
  249. XkbGetNames(Display *dpy,unsigned which,XkbDescPtr xkb)
  250. #else
  251. XkbGetNames(dpy,which,xkb)
  252.     Display *    dpy;
  253.     unsigned    which;
  254.     XkbDescPtr    xkb;
  255. #endif
  256. {
  257.     DBUG_ENTER("XkbGetNames")
  258.     register xkbGetNamesReq *req;
  259.     xkbGetNamesReply         rep;
  260.     Status             status;
  261.     XkbInfoPtr xkbi;
  262.  
  263.     if ((dpy->flags & XlibDisplayNoXkb) ||
  264.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  265.     DBUG_RETURN(BadAccess);
  266.     LockDisplay(dpy);
  267.     xkbi = dpy->xkb_info;
  268.     if (!xkb->names) {
  269.     xkb->names = _XkbTypedCalloc(1,XkbNamesRec);
  270.     if (!xkb->names) {
  271.         UnlockDisplay(dpy);
  272.         SyncHandle();
  273.         DBUG_RETURN(BadAlloc);
  274.     }
  275.     }
  276.     GetReq(kbGetNames, req);
  277.     req->reqType = xkbi->codes->major_opcode;
  278.     req->xkbReqType = X_kbGetNames;
  279.     req->deviceSpec = xkb->device_spec;
  280.     req->which = which;
  281.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  282.     UnlockDisplay(dpy);
  283.     SyncHandle();
  284.     DBUG_RETURN(BadImplementation);
  285.     }
  286.  
  287.     status = _XkbReadGetNamesReply(dpy,&rep,xkb,NULL);
  288.     UnlockDisplay(dpy);
  289.     SyncHandle();
  290.     DBUG_RETURN(status);
  291. }
  292. #endif
  293.  
  294. /***====================================================================***/
  295.  
  296. static int
  297. #if NeedFunctionPrototypes
  298. _XkbCountBits(int nBitsMax,unsigned long mask)
  299. #else
  300. _XkbCountBits(nBitsMax,mask)
  301.     int            nBitsMax;
  302.     unsigned long    mask;
  303. #endif
  304. {
  305.     DBUG_ENTER("_XkbCountBits")
  306.     register unsigned int i,bit,nBits;
  307.  
  308.     for (i=nBits=0,bit=1;i<nBitsMax;i++,bit<<=1) {
  309.     if (mask&bit)
  310.         nBits++;
  311.     }
  312.     DBUG_RETURN(nBits);
  313. }
  314.  
  315. static CARD32
  316. #if NeedFunctionPrototypes
  317. _XkbCountAtoms(Atom *atoms,int maxAtoms,int *count)
  318. #else
  319. _XkbCountAtoms(atoms,maxAtoms,count)
  320.     Atom *atoms;
  321.     int   maxAtoms;
  322.     int  *count;
  323. #endif
  324. {
  325.     DBUG_ENTER("_XkbCountAtoms")
  326.     register unsigned int i,bit,nAtoms;
  327.     register CARD32 atomsPresent;
  328.  
  329.     for (i=nAtoms=atomsPresent=0,bit=1;i<maxAtoms;i++,bit<<=1) {
  330.         if (atoms[i]!=None) {
  331.             atomsPresent|= bit;
  332.             nAtoms++;
  333.         }
  334.     }
  335.     if (count)
  336.         *count= nAtoms;
  337.     DBUG_RETURN(atomsPresent);
  338. }
  339.  
  340. #if 0
  341. static void
  342. #if NeedFunctionPrototypes
  343. _XkbCopyAtoms(Display *dpy,Atom *atoms,CARD32 mask,int maxAtoms)
  344. #else
  345. _XkbCopyAtoms(dpy,atoms,mask,maxAtoms)
  346.     Display *    dpy;
  347.     Atom *    atoms;
  348.     CARD32    mask;
  349.     int       maxAtoms;
  350. #endif
  351. {
  352.     DBUG_ENTER("_XkbCopyAtoms")
  353.     register unsigned int i,bit;
  354.  
  355.     for (i=0,bit=1;i<maxAtoms;i++,bit<<=1) {
  356.         if (mask&bit)
  357.         Data32(dpy,&atoms[i],4);
  358.     }
  359.     DBUG_VOID_RETURN;
  360. }
  361.  
  362. Bool
  363. #if NeedFunctionPrototypes
  364. XkbSetNames(    Display *    dpy,
  365.         unsigned int     which,
  366.         unsigned int     firstType,
  367.         unsigned int     nTypes,
  368.         XkbDescPtr     xkb)
  369. #else
  370. XkbSetNames(dpy,which,firstType,nTypes,xkb)
  371.     Display *        dpy;
  372.     unsigned int     which;
  373.     unsigned int     firstType;
  374.     unsigned int     nTypes;
  375.     XkbDescPtr        xkb;
  376. #endif
  377. {
  378.     DBUG_ENTER("XkbSetNames")
  379.     register xkbSetNamesReq *req;
  380.     int  nLvlNames;
  381.     XkbInfoPtr xkbi;
  382.     XkbNamesPtr names;
  383.     unsigned firstLvlType,nLvlTypes;
  384.     int    nVMods,nLEDs,nRG,nKA,nGroups;
  385.     int nKeys,firstKey,nAtoms;
  386.     CARD32 leds,vmods,groups;
  387.  
  388.     if ((dpy->flags & XlibDisplayNoXkb) ||
  389.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  390.     DBUG_RETURN(False);
  391.     if ((!xkb)||(!xkb->names))
  392.     DBUG_RETURN(False);
  393.     firstLvlType= firstType;
  394.     nLvlTypes= nTypes;
  395.     if (nTypes<1)
  396.     which&= ~(XkbKTLevelNamesMask|XkbKeyTypeNamesMask);
  397.     else if (firstType<=XkbLastRequiredType) {
  398.     int    adjust;
  399.     adjust= XkbLastRequiredType-firstType+1;
  400.     firstType+= adjust;
  401.     nTypes-= adjust;
  402.     if (nTypes<1)
  403.         which&= ~XkbKeyTypeNamesMask;
  404.     }
  405.     names= xkb->names;
  406.     if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) {
  407.     register int    i;
  408.     XkbKeyTypePtr    type;
  409.     if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)||
  410.                 (firstType+nTypes>xkb->map->num_types)||
  411.                 (firstLvlType+nLvlTypes>xkb->map->num_types))
  412.         DBUG_RETURN(False);
  413.     if (which&XkbKTLevelNamesMask) {
  414.         type= &xkb->map->types[firstLvlType];
  415.         for (i=nLvlNames=0;i<nLvlTypes;i++,type++) {
  416.         if (type->level_names!=NULL)
  417.             nLvlNames+= type->num_levels;
  418.         }
  419.     }
  420.     }
  421.  
  422.     nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0;
  423.     LockDisplay(dpy);
  424.     xkbi = dpy->xkb_info;
  425.     GetReq(kbSetNames, req);
  426.     req->reqType = xkbi->codes->major_opcode;
  427.     req->xkbReqType = X_kbSetNames;
  428.     req->deviceSpec = xkb->device_spec;
  429.     req->firstType = firstType;
  430.     req->nTypes = nTypes;
  431.     req->firstKey = xkb->min_key_code;
  432.     req->nKeys = xkb->max_key_code-xkb->min_key_code+1;
  433.  
  434.     if (which&XkbKeycodesNameMask)
  435.     nAtoms++;
  436.     if (which&XkbGeometryNameMask)
  437.     nAtoms++;
  438.     if (which&XkbSymbolsNameMask)
  439.     nAtoms++;
  440.     if (which&XkbPhysSymbolsNameMask)
  441.     nAtoms++;
  442.     if (which&XkbTypesNameMask)
  443.     nAtoms++;
  444.     if (which&XkbCompatNameMask)
  445.     nAtoms++;
  446.     if (which&XkbKeyTypeNamesMask)
  447.     nAtoms+= nTypes;
  448.     if (which&XkbKTLevelNamesMask) {
  449.     req->firstKTLevel= firstLvlType;
  450.     req->nKTLevels= nLvlTypes;
  451.     req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */
  452.     nAtoms+= nLvlNames;
  453.     }
  454.     else req->firstKTLevel= req->nKTLevels= 0;
  455.  
  456.     if (which&XkbIndicatorNamesMask) {
  457.     req->indicators= leds=
  458.         _XkbCountAtoms(names->indicators,XkbNumIndicators,&nLEDs);
  459.     if (nLEDs>0)
  460.          nAtoms+= nLEDs;
  461.     else which&= ~XkbIndicatorNamesMask;
  462.     }
  463.     else req->indicators= leds= 0;
  464.  
  465.     if (which&XkbVirtualModNamesMask) {
  466.     vmods= req->virtualMods= (CARD16) 
  467.         _XkbCountAtoms(names->vmods,XkbNumVirtualMods,&nVMods);
  468.     if (nVMods>0)
  469.          nAtoms+= nVMods;
  470.     else which&= ~XkbVirtualModNamesMask;
  471.     }
  472.     else vmods= req->virtualMods= 0;
  473.  
  474.     if (which&XkbGroupNamesMask) {
  475.     groups= req->groupNames= (CARD8)
  476.         _XkbCountAtoms(names->groups,XkbNumKbdGroups,&nGroups);
  477.     if (nGroups>0)
  478.          nAtoms+= nGroups;
  479.     else which&= ~XkbGroupNamesMask;
  480.     }
  481.     else groups= req->groupNames= 0;
  482.  
  483.     if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
  484.     firstKey= req->firstKey;
  485.     nKeys= req->nKeys;
  486.     nAtoms+= nKeys;    /* technically not atoms, but 4 bytes wide */
  487.     }
  488.     else which&= ~XkbKeyNamesMask;
  489.  
  490.     if (which&XkbKeyAliasesMask) {
  491.     nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0);
  492.     if (nKA>0) {
  493.         req->nKeyAliases= nKA;
  494.         nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */
  495.     }
  496.     else {
  497.         which&= ~XkbKeyAliasesMask;
  498.         req->nKeyAliases = 0;
  499.     }
  500.     }
  501.     else req->nKeyAliases= 0;
  502.  
  503.     if (which&XkbRGNamesMask) {
  504.     nRG= names->num_rg;
  505.     if (nRG>0)
  506.          nAtoms+= nRG;
  507.     else which&= ~XkbRGNamesMask;
  508.     }
  509.  
  510.     req->which= which;
  511.     req->nRadioGroups= nRG;
  512.     req->length+= (nAtoms*4)/4;
  513.  
  514.     if (which&XkbKeycodesNameMask)
  515.     Data32(dpy,(long *)&names->keycodes,4);
  516.     if (which&XkbGeometryNameMask)
  517.     Data32(dpy,(long *)&names->geometry,4);
  518.     if (which&XkbSymbolsNameMask)
  519.     Data32(dpy,(long *)&names->symbols,4);
  520.     if (which&XkbPhysSymbolsNameMask)
  521.     Data32(dpy,(long *)&names->phys_symbols,4);
  522.     if (which&XkbTypesNameMask)
  523.     Data32(dpy,(long *)&names->types,4);
  524.     if (which&XkbCompatNameMask)
  525.     Data32(dpy,(long *)&names->compat,4);
  526.     if (which&XkbKeyTypeNamesMask) {
  527.     register int         i;
  528.     register XkbKeyTypePtr    type;
  529.     type= &xkb->map->types[firstType];
  530.     for (i=0;i<nTypes;i++,type++) {
  531.         Data32(dpy,(long *)&type->name,4);
  532.     }
  533.     }
  534.     if (which&XkbKTLevelNamesMask) {
  535.     XkbKeyTypePtr type;
  536.     int i;
  537.     char *tmp;
  538.  
  539.     BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes));
  540.     type = &xkb->map->types[firstLvlType];
  541.     for (i=0;i<nLvlTypes;i++,type++) {
  542.         *tmp++ = type->num_levels;
  543.     }
  544.     type = &xkb->map->types[firstLvlType];
  545.     for (i=0;i<nLvlTypes;i++,type++) {
  546.         if (type->level_names!=NULL)
  547.         Data32(dpy,(long *)type->level_names,type->num_levels*4);
  548.     }
  549.     }
  550.     if (which&XkbIndicatorNamesMask)
  551.     _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators);
  552.     if (which&XkbVirtualModNamesMask)
  553.     _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods);
  554.     if (which&XkbGroupNamesMask)
  555.     _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups);
  556.     if (which&XkbKeyNamesMask) {
  557. #ifdef WORD64
  558.     char *tmp;
  559.     register int i;
  560.     BufAlloc(char *,tmp,nKeys*XkbKeyNameLength);
  561.     for (i=0;i<nKeys;i++,tmp+= XkbKeyNameLength) {
  562.         tmp[0]= names->keys[firstKey+i].name[0];
  563.         tmp[1]= names->keys[firstKey+i].name[1];
  564.         tmp[2]= names->keys[firstKey+i].name[2];
  565.         tmp[3]= names->keys[firstKey+i].name[3];
  566.     }
  567. #else
  568.     Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength);
  569. #endif
  570.     }
  571.     if (which&XkbKeyAliasesMask) {
  572. #ifdef WORD64
  573.     char *tmp;
  574.     register int i;
  575.     BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2);
  576.     for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength) {
  577.         tmp[0]= names->key_aliases[i].real[0];
  578.         tmp[1]= names->key_aliases[i].real[1];
  579.         tmp[2]= names->key_aliases[i].real[2];
  580.         tmp[3]= names->key_aliases[i].real[3];
  581.         tmp[4]= names->key_aliases[i].alias[0];
  582.         tmp[5]= names->key_aliases[i].alias[1];
  583.         tmp[6]= names->key_aliases[i].alias[2];
  584.         tmp[7]= names->key_aliases[i].alias[3];
  585.     }
  586. #else
  587.     Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2);
  588. #endif
  589.     }
  590.     if (which&XkbRGNamesMask) {
  591.     Data32(dpy,(long *)names->radio_groups,nRG*4);
  592.     }
  593.     UnlockDisplay(dpy);
  594.     SyncHandle();
  595.     DBUG_RETURN(True);
  596. }
  597.  
  598. Bool
  599. #if NeedFunctionPrototypes
  600. XkbChangeNames(Display *dpy,XkbDescPtr xkb,XkbNameChangesPtr changes)
  601. #else
  602. XkbChangeNames(dpy,xkb,changes)
  603.     Display *        dpy;
  604.     XkbDescPtr        xkb;
  605.     XkbNameChangesPtr    changes;
  606. #endif
  607. {
  608.     DBUG_ENTER("XkbChangeNames")
  609.     register xkbSetNamesReq *req;
  610.     int  nLvlNames;
  611.     XkbInfoPtr xkbi;
  612.     XkbNamesPtr names;
  613.     unsigned which,firstType,nTypes;
  614.     unsigned firstLvlType,nLvlTypes;
  615.     int    nVMods,nLEDs,nRG,nKA,nGroups;
  616.     int nKeys,firstKey,nAtoms;
  617.     CARD32 leds,vmods,groups;
  618.  
  619.     if ((dpy->flags & XlibDisplayNoXkb) ||
  620.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  621.     DBUG_RETURN(False);
  622.     if ((!xkb)||(!xkb->names)||(!changes))
  623.     DBUG_RETURN(False);
  624.     which= changes->changed;
  625.     firstType= changes->first_type;
  626.     nTypes= changes->num_types;
  627.     firstLvlType= changes->first_lvl;;
  628.     nLvlTypes= changes->num_lvls;
  629.     if (which&XkbKeyTypeNamesMask) {
  630.     if (nTypes<1)    
  631.         which&= ~XkbKeyTypeNamesMask;
  632.     else if (firstType<=XkbLastRequiredType) {
  633.         int    adjust;
  634.         adjust= XkbLastRequiredType-firstType+1;
  635.         firstType+= adjust;
  636.         nTypes-= adjust;
  637.         if (nTypes<1)
  638.         which&= ~XkbKeyTypeNamesMask;
  639.     }
  640.     }
  641.     else firstType= nTypes= 0;
  642.  
  643.     if (which&XkbKTLevelNamesMask) {
  644.     if (nLvlTypes<1)
  645.         which&= ~XkbKTLevelNamesMask;
  646.     }
  647.     else firstLvlType= nLvlTypes= 0;
  648.  
  649.     names= xkb->names;
  650.     if (which&(XkbKTLevelNamesMask|XkbKeyTypeNamesMask)) {
  651.     register int    i;
  652.     XkbKeyTypePtr    type;
  653.     if((xkb->map==NULL)||(xkb->map->types==NULL)||(nTypes==0)||
  654.                 (firstType+nTypes>xkb->map->num_types)||
  655.                 (firstLvlType+nLvlTypes>xkb->map->num_types))
  656.         DBUG_RETURN(False);
  657.     if (which&XkbKTLevelNamesMask) {
  658.         type= &xkb->map->types[firstLvlType];
  659.         for (i=nLvlNames=0;i<nLvlTypes;i++,type++) {
  660.         if (type->level_names!=NULL)
  661.             nLvlNames+= type->num_levels;
  662.         }
  663.     }
  664.     }
  665.  
  666.     if (changes->num_keys<1)
  667.     which&= ~XkbKeyNamesMask;
  668.     if ((which&XkbKeyNamesMask)==0)
  669.     changes->first_key= changes->num_keys= 0;
  670.     else if ((changes->first_key<xkb->min_key_code)||
  671.          (changes->first_key+changes->num_keys>xkb->max_key_code)) {
  672.     DBUG_RETURN(False);
  673.     }
  674.  
  675.     if ((which&XkbVirtualModNamesMask)==0)
  676.     changes->changed_vmods= 0;
  677.     else if (changes->changed_vmods==0)
  678.     which&= ~XkbVirtualModNamesMask;
  679.  
  680.     if ((which&XkbIndicatorNamesMask)==0)
  681.     changes->changed_indicators= 0;
  682.     else if (changes->changed_indicators==0)
  683.     which&= ~XkbIndicatorNamesMask;
  684.  
  685.     if ((which&XkbGroupNamesMask)==0)
  686.     changes->changed_groups= 0;
  687.     else if (changes->changed_groups==0)
  688.     which&= ~XkbGroupNamesMask;
  689.  
  690.     nVMods= nLEDs= nRG= nKA= nAtoms= nGroups= 0;
  691.     LockDisplay(dpy);
  692.     xkbi = dpy->xkb_info;
  693.     GetReq(kbSetNames, req);
  694.     req->reqType = xkbi->codes->major_opcode;
  695.     req->xkbReqType = X_kbSetNames;
  696.     req->deviceSpec = xkb->device_spec;
  697.     req->firstType = firstType;
  698.     req->nTypes = nTypes;
  699.     req->firstKey = changes->first_key;
  700.     req->nKeys = changes->num_keys;
  701.  
  702.     if (which&XkbKeycodesNameMask)
  703.     nAtoms++;
  704.     if (which&XkbGeometryNameMask)
  705.     nAtoms++;
  706.     if (which&XkbSymbolsNameMask)
  707.     nAtoms++;
  708.     if (which&XkbPhysSymbolsNameMask)
  709.     nAtoms++;
  710.     if (which&XkbTypesNameMask)
  711.     nAtoms++;
  712.     if (which&XkbCompatNameMask)
  713.     nAtoms++;
  714.     if (which&XkbKeyTypeNamesMask)
  715.     nAtoms+= nTypes;
  716.     if (which&XkbKTLevelNamesMask) {
  717.     req->firstKTLevel= firstLvlType;
  718.     req->nKTLevels= nLvlTypes;
  719.     req->length+= XkbPaddedSize(nLvlTypes)/4; /* room for group widths */
  720.     nAtoms+= nLvlNames;
  721.     }
  722.     else req->firstKTLevel= req->nKTLevels= 0;
  723.  
  724.     if (which&XkbIndicatorNamesMask) {
  725.     leds= req->indicators= (CARD32)changes->changed_indicators;
  726.     nLEDs= _XkbCountBits(XkbNumIndicators,changes->changed_indicators);
  727.     if (nLEDs>0)
  728.          nAtoms+= nLEDs;
  729.     else which&= ~XkbIndicatorNamesMask;
  730.     }
  731.     else req->indicators= 0;
  732.  
  733.     if (which&XkbVirtualModNamesMask) {
  734.     vmods= req->virtualMods= changes->changed_vmods;
  735.     nVMods= _XkbCountBits(XkbNumVirtualMods,
  736.                     (unsigned long)changes->changed_vmods);
  737.     if (nVMods>0)
  738.          nAtoms+= nVMods;
  739.     else which&= ~XkbVirtualModNamesMask;
  740.     }
  741.     else req->virtualMods= 0;
  742.  
  743.     if (which&XkbGroupNamesMask) {
  744.     groups= req->groupNames= changes->changed_groups;
  745.     nGroups= _XkbCountBits(XkbNumKbdGroups,
  746.                     (unsigned long)changes->changed_groups);
  747.     if (nGroups>0)
  748.          nAtoms+= nGroups;
  749.     else which&= ~XkbGroupNamesMask;
  750.     }
  751.     else req->groupNames= 0;
  752.  
  753.     if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
  754.     firstKey= req->firstKey;
  755.     nKeys= req->nKeys;
  756.     nAtoms+= nKeys;    /* technically not atoms, but 4 bytes wide */
  757.     }
  758.     else which&= ~XkbKeyNamesMask;
  759.  
  760.     if (which&XkbKeyAliasesMask) {
  761.     nKA= ((names->key_aliases!=NULL)?names->num_key_aliases:0);
  762.     if (nKA>0)
  763.         nAtoms+= nKA*2; /* not atoms, but 8 bytes on the wire */
  764.     else which&= ~XkbKeyAliasesMask;
  765.     }
  766.  
  767.     if (which&XkbRGNamesMask) {
  768.     nRG= names->num_rg;
  769.     if (nRG>0)
  770.          nAtoms+= nRG;
  771.     else which&= ~XkbRGNamesMask;
  772.     }
  773.  
  774.     req->which= which;
  775.     req->nRadioGroups= nRG;
  776.     req->length+= (nAtoms*4)/4;
  777.  
  778.     if (which&XkbKeycodesNameMask)
  779.     Data32(dpy,(long *)&names->keycodes,4);
  780.     if (which&XkbGeometryNameMask)
  781.     Data32(dpy,(long *)&names->geometry,4);
  782.     if (which&XkbSymbolsNameMask)
  783.     Data32(dpy,(long *)&names->symbols,4);
  784.     if (which&XkbPhysSymbolsNameMask)
  785.     Data32(dpy,(long *)&names->phys_symbols,4);
  786.     if (which&XkbTypesNameMask)
  787.     Data32(dpy,(long *)&names->types,4);
  788.     if (which&XkbCompatNameMask)
  789.     Data32(dpy,(long *)&names->compat,4);
  790.     if (which&XkbKeyTypeNamesMask) {
  791.     register int         i;
  792.     register XkbKeyTypePtr    type;
  793.     type= &xkb->map->types[firstType];
  794.     for (i=0;i<nTypes;i++,type++) {
  795.         Data32(dpy,(long *)&type->name,4);
  796.     }
  797.     }
  798.     if (which&XkbKTLevelNamesMask) {
  799.     XkbKeyTypePtr type;
  800.     int i;
  801.     char *tmp;
  802.  
  803.     BufAlloc(char *,tmp,XkbPaddedSize(nLvlTypes));
  804.     type = &xkb->map->types[firstLvlType];
  805.     for (i=0;i<nLvlTypes;i++,type++) {
  806.         *tmp++ = type->num_levels;
  807.     }
  808.     type = &xkb->map->types[firstLvlType];
  809.     for (i=0;i<nLvlTypes;i++,type++) {
  810.         if (type->level_names!=NULL)
  811.         Data32(dpy,(long *)type->level_names,type->num_levels*4);
  812.     }
  813.     }
  814.     if (which&XkbIndicatorNamesMask)
  815.     _XkbCopyAtoms(dpy,names->indicators,leds,XkbNumIndicators);
  816.     if (which&XkbVirtualModNamesMask)
  817.     _XkbCopyAtoms(dpy,names->vmods,vmods,XkbNumVirtualMods);
  818.     if (which&XkbGroupNamesMask)
  819.     _XkbCopyAtoms(dpy,names->groups,groups,XkbNumKbdGroups);
  820.     if (which&XkbKeyNamesMask) {
  821. #ifdef WORD64
  822.     char *tmp;
  823.     register int i;
  824.     BufAlloc(char *,tmp,nKeys*4);
  825.     for (i=0;i<nKeys;i++,tmp+= 4) {
  826.         tmp[0]= names->keys[firstKey+i].name[0];
  827.         tmp[1]= names->keys[firstKey+i].name[1];
  828.         tmp[2]= names->keys[firstKey+i].name[2];
  829.         tmp[3]= names->keys[firstKey+i].name[3];
  830.     }
  831. #else
  832.     Data(dpy,(char *)&names->keys[firstKey],nKeys*XkbKeyNameLength);
  833. #endif
  834.     }
  835.     if (which&XkbKeyAliasesMask) {
  836. #ifdef WORD64
  837.     char *tmp;
  838.     register int i;
  839.     BufAlloc(char *,tmp,nKA*XkbKeyNameLength*2);
  840.     for (i=0;i<nKeys;i++,tmp+= 2*XkbKeyNameLength) {
  841.         tmp[0]= names->key_aliases[i].real[0];
  842.         tmp[1]= names->key_aliases[i].real[1];
  843.         tmp[2]= names->key_aliases[i].real[2];
  844.         tmp[3]= names->key_aliases[i].real[3];
  845.         tmp[4]= names->key_aliases[i].alias[0];
  846.         tmp[5]= names->key_aliases[i].alias[1];
  847.         tmp[6]= names->key_aliases[i].alias[2];
  848.         tmp[7]= names->key_aliases[i].alias[3];
  849.     }
  850. #else
  851.     Data(dpy,(char *)names->key_aliases,nKA*XkbKeyNameLength*2);
  852. #endif
  853.     }
  854.     if (which&XkbRGNamesMask) {
  855.     Data32(dpy,(long *)names->radio_groups,nRG*4);
  856.     }
  857.     UnlockDisplay(dpy);
  858.     SyncHandle();
  859.     DBUG_RETURN(True);
  860. }
  861. #endif
  862.  
  863. void
  864. #if NeedFunctionPrototypes
  865. XkbNoteNameChanges(    XkbNameChangesPtr    old,
  866.             XkbNamesNotifyEvent *    new,
  867.             unsigned int         wanted)
  868. #else
  869. XkbNoteNameChanges(old,new,wanted)
  870.     XkbNameChangesPtr        old;
  871.     XkbNamesNotifyEvent    *    new;
  872.     unsigned int         wanted;
  873. #endif
  874. {
  875.     DBUG_ENTER("XkbNoteNameChanges")
  876.     int    first,last,old_last,new_last;
  877.  
  878.     wanted&= new->changed;
  879.     if ((old==NULL)||(new==NULL)||(wanted==0))
  880.     DBUG_VOID_RETURN;
  881.     if (wanted&XkbKeyTypeNamesMask) {
  882.     if (old->changed&XkbKeyTypeNamesMask) {
  883.         new_last= (new->first_type+new->num_types-1);
  884.         old_last= (old->first_type+old->num_types-1);
  885.  
  886.         if (new->first_type<old->first_type)
  887.          first= new->first_type;
  888.         else first= old->first_type;
  889.  
  890.         if (old_last>new_last)
  891.          last= old_last;
  892.         else last= new_last;
  893.  
  894.         old->first_type= first;
  895.         old->num_types= (last-first)+1;
  896.     }
  897.     else {
  898.         old->first_type= new->first_type;
  899.         old->num_types= new->num_types;
  900.     }
  901.     }
  902.     if (wanted&XkbKTLevelNamesMask) {
  903.     if (old->changed&XkbKTLevelNamesMask) {
  904.         new_last= (new->first_lvl+new->num_lvls-1);
  905.         old_last= (old->first_lvl+old->num_lvls-1);
  906.  
  907.         if (new->first_lvl<old->first_lvl)
  908.          first= new->first_lvl;
  909.         else first= old->first_lvl;
  910.  
  911.         if (old_last>new_last)
  912.          last= old_last;
  913.         else last= new_last;
  914.  
  915.         old->first_lvl= first;
  916.         old->num_lvls= (last-first)+1;
  917.     }
  918.     else {
  919.         old->first_lvl= new->first_lvl;
  920.         old->num_lvls= new->num_lvls;
  921.     }
  922.     }
  923.     if (wanted&XkbIndicatorNamesMask) {
  924.     if (old->changed&XkbIndicatorNamesMask)
  925.          old->changed_indicators|= new->changed_indicators;
  926.     else old->changed_indicators=  new->changed_indicators;
  927.     }
  928.     if (wanted&XkbKeyNamesMask) {
  929.     if (old->changed&XkbKeyNamesMask) {
  930.         new_last= (new->first_key+new->num_keys-1);
  931.         old_last= (old->first_key+old->num_keys-1);
  932.  
  933.         first= old->first_key;
  934.  
  935.         if (new->first_key<old->first_key)
  936.         first= new->first_key;
  937.         if (old_last>new_last)
  938.         new_last= old_last;
  939.  
  940.         old->first_key= first;
  941.         old->num_keys= (new_last-first)+1;
  942.     }
  943.     else {
  944.         old->first_key= new->first_key;
  945.         old->num_keys= new->num_keys;
  946.     }
  947.     }
  948.     if (wanted&XkbVirtualModNamesMask) {
  949.     if (old->changed&XkbVirtualModNamesMask)
  950.          old->changed_vmods|= new->changed_vmods;
  951.     else old->changed_vmods=  new->changed_vmods;
  952.     }
  953.     if (wanted&XkbGroupNamesMask) {
  954.     if (old->changed&XkbGroupNamesMask)
  955.          old->changed_groups|= new->changed_groups;
  956.     else old->changed_groups=  new->changed_groups;
  957.     }
  958.     if (wanted&XkbRGNamesMask) 
  959.     old->num_rg= new->num_radio_groups;
  960.     if (wanted&XkbKeyAliasesMask) 
  961.     old->num_aliases= new->num_aliases;
  962.     old->changed|= wanted;
  963.     DBUG_VOID_RETURN;
  964. }
  965.