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

  1. /* $XConsortium: XKBGetByName.c /main/4 1996/01/01 11:26:52 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. #define    NEED_MAP_READERS
  31. #include "Xlib_private.h"
  32. #include <X11/extensions/XKBproto.h>
  33. #include "XKBlibint.h"
  34.  
  35. /***====================================================================***/
  36. #if 0
  37. XkbDescPtr
  38. #if NeedFunctionPrototypes
  39. XkbGetKeyboardByName(    Display *        dpy,
  40.             unsigned        deviceSpec,
  41.             XkbComponentNamesPtr    names,
  42.             unsigned        want,
  43.             unsigned        need,
  44.             Bool            load)
  45. #else
  46. XkbGetKeyboardByName(dpy,deviceSpec,names,want,need,load)
  47.     Display *            dpy;
  48.     unsigned            deviceSpec;
  49.     XkbComponentNamesPtr    names;
  50.     unsigned            want;
  51.     unsigned            need;
  52.     Bool            load;
  53. #endif
  54. {
  55.     DBUG_ENTER("XkbGetKeyboardByName")
  56.     register xkbGetKbdByNameReq    *    req;
  57.     xkbGetKbdByNameReply         rep;
  58.     int                    len,extraLen;
  59.     char *                str;
  60.     XkbDescPtr                xkb;
  61.     int                    mapLen,codesLen,typesLen,compatLen;
  62.     int                    symsLen,geomLen;
  63.     XkbInfoPtr                 xkbi;
  64.  
  65.     if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) ||
  66.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) )
  67.     DBUG_RETURN(NULL);
  68.  
  69.     xkbi= dpy->xkb_info;
  70.     xkb = (XkbDescRec *)_XkbCalloc(1,sizeof(XkbDescRec));
  71.     if (!xkb)
  72.     DBUG_RETURN(NULL);
  73.     xkb->device_spec = deviceSpec;
  74.     xkb->map = (XkbClientMapRec *)_XkbCalloc(1,sizeof(XkbClientMapRec));
  75.     xkb->dpy = dpy;
  76.  
  77.     LockDisplay(dpy);
  78.     GetReq(kbGetKbdByName, req);
  79.     req->reqType = xkbi->codes->major_opcode;
  80.     req->xkbReqType = X_kbGetKbdByName;
  81.     req->deviceSpec = xkb->device_spec;
  82.     req->want= want;
  83.     req->need= need;
  84.     req->load= load;
  85.  
  86.     mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0;
  87.     if (names) {
  88.     if (names->keymap)
  89.         mapLen= (int)strlen(names->keymap);
  90.     if (names->keycodes)
  91.         codesLen= (int)strlen(names->keycodes);
  92.     if (names->types)
  93.         typesLen= (int)strlen(names->types);
  94.     if (names->compat)
  95.         compatLen= (int)strlen(names->compat);
  96.     if (names->symbols)
  97.         symsLen= (int)strlen(names->symbols);
  98.     if (names->geometry)
  99.         geomLen= (int)strlen(names->geometry);
  100.     if (mapLen>255)        mapLen= 255;
  101.     if (codesLen>255)    codesLen= 255;
  102.     if (typesLen>255)    typesLen= 255;
  103.     if (compatLen>255)    compatLen= 255;
  104.     if (symsLen>255)    symsLen= 255;
  105.     if (geomLen>255)    geomLen= 255;
  106.     }
  107.     else mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0;
  108.  
  109.     len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6;
  110.     len= XkbPaddedSize(len);
  111.     req->length+= len/4;
  112.     BufAlloc(char *,str,len);
  113.     *str++= mapLen;
  114.     if (mapLen>0) {
  115.      memcpy(str,names->keymap,mapLen);
  116.      str+= mapLen;
  117.     }
  118.     *str++= codesLen;
  119.     if (codesLen>0) {
  120.      memcpy(str,names->keycodes,codesLen);
  121.      str+= codesLen;
  122.     }
  123.     *str++= typesLen;
  124.     if (typesLen>0) {
  125.      memcpy(str,names->types,typesLen);
  126.      str+= typesLen;
  127.     }
  128.     *str++= compatLen;
  129.     if (compatLen>0) {
  130.      memcpy(str,names->compat,compatLen);
  131.      str+= compatLen;
  132.     }
  133.     *str++= symsLen;
  134.     if (symsLen>0) {
  135.      memcpy(str,names->symbols,symsLen);
  136.      str+= symsLen;
  137.     }
  138.     *str++= geomLen;
  139.     if (geomLen>0) {
  140.      memcpy(str,names->geometry,geomLen);
  141.      str+= geomLen;
  142.     }
  143.     if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.reported))
  144.     goto BAILOUT;
  145.     extraLen= (int)rep.length*4;
  146.  
  147.     xkb->device_spec= rep.deviceID;
  148.     xkb->min_key_code = rep.minKeyCode;
  149.     xkb->max_key_code = rep.maxKeyCode;
  150.     if (rep.reported&(XkbGBN_SymbolsMask|XkbGBN_TypesMask)) {
  151.     xkbGetMapReply     mrep;
  152.     Status        status;
  153.     int        nread= 0;
  154.  
  155.     _XRead(dpy, (char *)&mrep, SIZEOF(xkbGetMapReply));
  156.     extraLen-= SIZEOF(xkbGetMapReply);
  157.     status= _XkbReadGetMapReply(dpy,&mrep,xkb,&nread);
  158.     extraLen-= nread;
  159.     if (status!=Success)
  160.         goto BAILOUT;
  161.     }
  162.     if (rep.reported&XkbGBN_CompatMapMask) {
  163.     xkbGetCompatMapReply     crep;
  164.     Status            status;
  165.     int            nread= 0;
  166.  
  167.     _XRead(dpy, (char *)&crep, SIZEOF(xkbGetCompatMapReply));
  168.     extraLen-= SIZEOF(xkbGetCompatMapReply);
  169.     status= _XkbReadGetCompatMapReply(dpy,&crep,xkb,&nread);
  170.     extraLen-= nread;
  171.     if (status!=Success)
  172.         goto BAILOUT;
  173.     }
  174.     if (rep.reported&XkbGBN_IndicatorMapMask) {
  175.     xkbGetIndicatorMapReply irep;
  176.     Status            status;
  177.     int            nread= 0;
  178.  
  179.     _XRead(dpy, (char *)&irep, SIZEOF(xkbGetIndicatorMapReply));
  180.     extraLen-= SIZEOF(xkbGetIndicatorMapReply);
  181.     status= _XkbReadGetIndicatorMapReply(dpy,&irep,xkb,&nread);
  182.     extraLen-= nread;
  183.     if (status!=Success)
  184.         goto BAILOUT;
  185.     }
  186.     if (rep.reported&(XkbGBN_KeyNamesMask|XkbGBN_OtherNamesMask)) {
  187.     xkbGetNamesReply    nrep;
  188.     Status            status;
  189.     int            nread= 0;
  190.  
  191.     _XRead(dpy, (char *)&nrep, SIZEOF(xkbGetNamesReply));
  192.     extraLen-= SIZEOF(xkbGetNamesReply);
  193.     status= _XkbReadGetNamesReply(dpy,&nrep,xkb,&nread);
  194.     extraLen-= nread;
  195.     if (status!=Success)
  196.         goto BAILOUT;
  197.     }
  198.     if (rep.reported&XkbGBN_GeometryMask) {
  199.     xkbGetGeometryReply    grep;
  200.     Status            status;
  201.     int            nread= 0;
  202.  
  203.     _XRead(dpy, (char *)&grep, SIZEOF(xkbGetGeometryReply));
  204.     extraLen-= SIZEOF(xkbGetGeometryReply);
  205.     status= _XkbReadGetGeometryReply(dpy,&grep,xkb,&nread);
  206.     extraLen-= nread;
  207.     if (status!=Success)
  208.         goto BAILOUT;
  209.     }
  210.     UnlockDisplay(dpy);
  211.     SyncHandle();
  212.     DBUG_RETURN(xkb);
  213. BAILOUT:
  214.     if (xkb!=NULL)
  215.     XkbFreeKeyboard(xkb,XkbAllComponentsMask,xTrue);
  216.     UnlockDisplay(dpy);
  217.     SyncHandle();
  218.     DBUG_RETURN(NULL);
  219. }
  220. #endif
  221.  
  222. XkbDescPtr
  223. #if NeedFunctionPrototypes
  224. XkbGetKeyboard(Display *dpy,unsigned which,unsigned deviceSpec)
  225. #else
  226. XkbGetKeyboard(dpy,which,deviceSpec)
  227.     Display *        dpy;
  228.     unsigned        which;
  229.     unsigned        deviceSpec;
  230. #endif
  231. {
  232.     DBUG_ENTER("XkbGetKeyboard")
  233.     XkbDescPtr result = XkbGetKeyboardByName(dpy,deviceSpec,NULL,which,which,False);
  234.     DBUG_RETURN(result);
  235. }
  236.