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

  1. /* $XConsortium: XKBleds.c /main/6 1996/01/14 16:43:58 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. #if 0
  35. Status
  36. #if NeedFunctionPrototypes
  37. XkbGetIndicatorState(Display *dpy,unsigned deviceSpec,unsigned *pStateRtrn)
  38. #else
  39. XkbGetIndicatorState(dpy,deviceSpec,pStateRtrn)
  40.     Display *        dpy;
  41.     unsigned int    deviceSpec;
  42.     unsigned int *    pStateRtrn;
  43. #endif
  44. {
  45.     DBUG_ENTER("XkbGetIndicatorState")
  46.     register xkbGetIndicatorStateReq *req;
  47.     xkbGetIndicatorStateReply    rep;
  48.     XkbInfoPtr xkbi;
  49.     Bool ok;
  50.     
  51.     if ((dpy->flags & XlibDisplayNoXkb) ||
  52.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  53.     DBUG_RETURN(BadAccess);
  54.     LockDisplay(dpy);
  55.     xkbi = dpy->xkb_info;
  56.     GetReq(kbGetIndicatorState, req);
  57.     req->reqType = xkbi->codes->major_opcode;
  58.     req->xkbReqType = X_kbGetIndicatorState;
  59.     req->deviceSpec = deviceSpec;
  60.     ok=_XReply(dpy, (xReply *)&rep, 0, xFalse);
  61.     if (ok && (pStateRtrn!=NULL))
  62.     *pStateRtrn= rep.state;
  63.     UnlockDisplay(dpy);
  64.     SyncHandle();
  65.     DBUG_RETURN(ok?Success:BadImplementation);
  66. }
  67. #endif
  68.  
  69. Status    
  70. #if NeedFunctionPrototypes
  71. _XkbReadGetIndicatorMapReply(    Display *            dpy,
  72.                 xkbGetIndicatorMapReply *    rep,
  73.                 XkbDescPtr            xkb,
  74.                 int    *            nread_rtrn)
  75. #else
  76. _XkbReadGetIndicatorMapReply(dpy,rep,xkb,nread_rtrn)
  77.     Display *            dpy;
  78.     xkbGetIndicatorMapReply *    rep;
  79.     XkbDescPtr            xkb;
  80.     int    *            nread_rtrn;
  81. #endif
  82. {
  83.     DBUG_ENTER("_XkbReadGetIndicatorMapReply")
  84.     XkbIndicatorPtr        leds;
  85.     XkbReadBufferRec    buf;
  86.  
  87.     if ((!xkb->indicators)&&(XkbAllocIndicatorMaps(xkb)!=Success))
  88.     DBUG_RETURN(BadAlloc);
  89.     leds= xkb->indicators;
  90.  
  91.     leds->phys_indicators = rep->realIndicators;
  92.     if (rep->length>0) {
  93.     register int left;
  94.     if (!_XkbInitReadBuffer(dpy,&buf,(int)rep->length*4))
  95.         DBUG_RETURN(BadAlloc);
  96.     if (nread_rtrn)
  97.         *nread_rtrn= (int)rep->length*4;
  98.     if (rep->which) {
  99.         register int i,bit;
  100.         left= (int)rep->which;
  101.         for (i=0,bit=1;(i<XkbNumIndicators)&&(left);i++,bit<<=1) {
  102.         if (left&bit) {
  103.             xkbIndicatorMapWireDesc *wire;
  104.             wire= (xkbIndicatorMapWireDesc *)
  105.               _XkbGetReadBufferPtr(&buf,
  106.                     SIZEOF(xkbIndicatorMapWireDesc));
  107.             if (wire==NULL) {
  108.             _XkbFreeReadBuffer(&buf);
  109.             DBUG_RETURN(BadAlloc);
  110.             }
  111.             leds->maps[i].flags= wire->flags;
  112.             leds->maps[i].which_groups= wire->whichGroups;
  113.             leds->maps[i].groups= wire->groups;
  114.             leds->maps[i].which_mods= wire->whichMods;
  115.             leds->maps[i].mods.mask= wire->mods;
  116.             leds->maps[i].mods.real_mods= wire->realMods;
  117.             leds->maps[i].mods.vmods= wire->virtualMods;
  118.             leds->maps[i].ctrls= wire->ctrls;
  119.             left&= ~bit;
  120.         }
  121.         }
  122.     }
  123.     left= _XkbFreeReadBuffer(&buf);
  124.     }
  125.     DBUG_RETURN(Success);
  126. }
  127.  
  128. #if 0
  129. Bool
  130. #if NeedFunctionPrototypes
  131. XkbGetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
  132. #else
  133. XkbGetIndicatorMap(dpy,which,xkb)
  134.     Display *        dpy;
  135.     unsigned long     which;
  136.     XkbDescPtr        xkb;
  137. #endif
  138. {
  139.     DBUG_ENTER("XkbGetIndicatorMap")
  140.     register xkbGetIndicatorMapReq *    req;
  141.     xkbGetIndicatorMapReply         rep;
  142.     XkbInfoPtr                 xkbi;
  143.     Status                status;
  144.  
  145.     if ((dpy->flags & XlibDisplayNoXkb) ||
  146.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  147.     DBUG_RETURN(BadAccess);
  148.     if ((!which)||(!xkb))
  149.     DBUG_RETURN(BadValue);
  150.  
  151.     LockDisplay(dpy);
  152.     xkbi = dpy->xkb_info;
  153.     if (!xkb->indicators) {
  154.     xkb->indicators = _XkbTypedCalloc(1,XkbIndicatorRec);
  155.     if (!xkb->indicators) {
  156.         UnlockDisplay(dpy);
  157.         SyncHandle();
  158.         DBUG_RETURN(BadAlloc);
  159.     }
  160.     }
  161.     GetReq(kbGetIndicatorMap, req);
  162.     req->reqType = xkbi->codes->major_opcode;
  163.     req->xkbReqType = X_kbGetIndicatorMap;
  164.     req->deviceSpec = xkb->device_spec;
  165.     req->which = (CARD32)which;
  166.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  167.     UnlockDisplay(dpy);
  168.     SyncHandle();
  169.     DBUG_RETURN(BadValue);
  170.     }
  171.     status= _XkbReadGetIndicatorMapReply(dpy,&rep,xkb,NULL);
  172.     UnlockDisplay(dpy);
  173.     SyncHandle();
  174.     DBUG_RETURN(status);
  175. }
  176.  
  177. Bool
  178. #if NeedFunctionPrototypes
  179. XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb)
  180. #else
  181. XkbSetIndicatorMap(dpy,which,xkb)
  182.     Display *        dpy;
  183.     unsigned long     which;
  184.     XkbDescPtr        xkb;
  185. #endif
  186. {
  187.     DBUG_ENTER("XkbSetIndicatorMap")
  188.     register xkbSetIndicatorMapReq    *req;
  189.     register int i,bit;
  190.     int nMaps;
  191.     xkbIndicatorMapWireDesc *wire;
  192.     XkbInfoPtr xkbi;
  193.  
  194.     if ((dpy->flags & XlibDisplayNoXkb) ||
  195.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  196.     DBUG_RETURN(False);
  197.     if ((!xkb)||(!which)||(!xkb->indicators))
  198.     DBUG_RETURN(False);
  199.     LockDisplay(dpy);
  200.     xkbi = dpy->xkb_info;
  201.     GetReq(kbSetIndicatorMap, req);
  202.     req->reqType = xkbi->codes->major_opcode;
  203.     req->xkbReqType = X_kbSetIndicatorMap;
  204.     req->deviceSpec = xkb->device_spec;
  205.     req->which = (CARD32)which;
  206.     for (i=nMaps=0,bit=1;i<32;i++,bit<<=1) {
  207.     if (which&bit)
  208.         nMaps++;
  209.     }
  210.     req->length+= (nMaps*sizeof(XkbIndicatorMapRec))/4;
  211.     BufAlloc(xkbIndicatorMapWireDesc *,wire,
  212.                        (nMaps*SIZEOF(xkbIndicatorMapWireDesc)));
  213.     for (i=0,bit=1;i<32;i++,bit<<=1) {
  214.     if (which&bit) {
  215.         wire->flags= xkb->indicators->maps[i].flags;
  216.         wire->whichGroups= xkb->indicators->maps[i].which_groups;
  217.         wire->groups= xkb->indicators->maps[i].groups;
  218.         wire->whichMods= xkb->indicators->maps[i].which_mods;
  219.         wire->mods= xkb->indicators->maps[i].mods.real_mods;
  220.         wire->virtualMods= xkb->indicators->maps[i].mods.vmods;
  221.         wire->ctrls= xkb->indicators->maps[i].ctrls;
  222.         wire++;
  223.     }
  224.     }
  225.     UnlockDisplay(dpy);
  226.     SyncHandle();
  227.     DBUG_RETURN(True);
  228. }
  229.  
  230. Bool
  231. #if NeedFunctionPrototypes
  232. XkbGetNamedDeviceIndicator(    Display *        dpy,
  233.                 unsigned        device,
  234.                 unsigned        class,
  235.                 unsigned        id,
  236.                 Atom            name,
  237.                 int    *        pNdxRtrn,
  238.                     Bool *            pStateRtrn,
  239.                 XkbIndicatorMapPtr    pMapRtrn,
  240.                 Bool *            pRealRtrn)
  241. #else
  242. XkbGetNamedDeviceIndicator(dpy,device,class,id,name,pNdxRtrn,pStateRtrn,
  243.                             pMapRtrn,pRealRtrn)
  244.     Display *        dpy;
  245.     unsigned        device;
  246.     unsigned        class;
  247.     unsigned        id;
  248.     Atom        name;
  249.     int    *        pNdxRtrn;
  250.     Bool *        pStateRtrn;
  251.     XkbIndicatorMapPtr    pMapRtrn;
  252.     Bool *        pRealRtrn;
  253. #endif
  254. {
  255.     DBUG_ENTER("XkbGetNamedDeviceIndicator")
  256.     register xkbGetNamedIndicatorReq *req;
  257.     xkbGetNamedIndicatorReply    rep;
  258.     XkbInfoPtr xkbi;
  259.     
  260.     if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
  261.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
  262.     DBUG_RETURN(False);
  263.     LockDisplay(dpy);
  264.     xkbi = dpy->xkb_info;
  265.     GetReq(kbGetNamedIndicator, req);
  266.     req->reqType = xkbi->codes->major_opcode;
  267.     req->xkbReqType = X_kbGetNamedIndicator;
  268.     req->deviceSpec = device;
  269.     req->ledClass = class;
  270.     req->ledID = id;
  271.     req->indicator = (CARD32)name;
  272.     if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
  273.     UnlockDisplay(dpy);
  274.     SyncHandle();
  275.     DBUG_RETURN(False);
  276.     }
  277.     if ((!rep.found)||(!rep.supported))
  278.     DBUG_RETURN(False);
  279.     if (pNdxRtrn!=NULL)
  280.     *pNdxRtrn= rep.ndx;
  281.     if (pStateRtrn!=NULL)
  282.     *pStateRtrn= rep.on;
  283.     if (pMapRtrn!=NULL) {
  284.     pMapRtrn->flags= rep.flags;
  285.     pMapRtrn->which_groups= rep.whichGroups;
  286.     pMapRtrn->groups= rep.groups;
  287.     pMapRtrn->which_mods= rep.whichMods;
  288.     pMapRtrn->mods.mask= rep.mods;
  289.     pMapRtrn->mods.real_mods= rep.realMods;
  290.     pMapRtrn->mods.vmods= rep.virtualMods;
  291.     pMapRtrn->ctrls= rep.ctrls;
  292.     }
  293.     if (pRealRtrn!=NULL) 
  294.     *pRealRtrn= rep.realIndicator;
  295.     DBUG_RETURN(True);
  296. }
  297. #endif
  298.  
  299. Bool
  300. #if NeedFunctionPrototypes
  301. XkbGetNamedIndicator(    Display *        dpy,
  302.             Atom            name,
  303.             int    *        pNdxRtrn,
  304.                 Bool *            pStateRtrn,
  305.             XkbIndicatorMapPtr    pMapRtrn,
  306.             Bool *            pRealRtrn)
  307. #else
  308. XkbGetNamedIndicator(dpy,name,pNdxRtrn,pStateRtrn,pMapRtrn,pRealRtrn)
  309.     Display *        dpy;
  310.     Atom        name;
  311.     int    *        pNdxRtrn;
  312.     Bool *        pStateRtrn;
  313.     XkbIndicatorMapPtr    pMapRtrn;
  314.     Bool *        pRealRtrn;
  315. #endif
  316. {
  317.     DBUG_ENTER("XkbGetNamedIndicator")
  318.     Bool result = XkbGetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
  319.                       XkbDfltXIClass,XkbDfltXIId,
  320.                       name,pNdxRtrn,pStateRtrn,
  321.                       pMapRtrn,pRealRtrn);
  322.     DBUG_RETURN(result);
  323. }
  324.  
  325. #if 0
  326. Bool
  327. #if NeedFunctionPrototypes
  328. XkbSetNamedDeviceIndicator(    Display *        dpy,
  329.                 unsigned        device,
  330.                 unsigned        class,
  331.                 unsigned        id,
  332.                 Atom            name,
  333.                 Bool            changeState,
  334.                 Bool            state,
  335.                 Bool            createNewMap,
  336.                 XkbIndicatorMapPtr    pMap)
  337. #else
  338. XkbSetNamedDeviceIndicator(dpy,device,class,id,name,changeState,
  339.                             state,createNewMap,pMap)
  340.     Display *        dpy;
  341.     unsigned        device;
  342.     unsigned        class;
  343.     unsigned        id;
  344.     Atom        name;
  345.     Bool        changeState;
  346.     Bool        state;
  347.     Bool        createNewMap;
  348.     XkbIndicatorMapPtr    pMap;
  349. #endif
  350. {
  351.     DBUG_ENTER("XkbSetNamedDeviceIndicator")
  352.     register xkbSetNamedIndicatorReq    *req;
  353.     XkbInfoPtr xkbi;
  354.  
  355.     if ((dpy->flags & XlibDisplayNoXkb) || (name==None) ||
  356.     (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ||
  357.     (pMap==NULL))
  358.     DBUG_RETURN(False);
  359.     LockDisplay(dpy);
  360.     xkbi = dpy->xkb_info;
  361.     GetReq(kbSetNamedIndicator, req);
  362.     req->reqType = xkbi->codes->major_opcode;
  363.     req->xkbReqType = X_kbSetNamedIndicator;
  364.     req->deviceSpec = device;
  365.     req->ledClass = class;
  366.     req->ledID = id;
  367.     req->indicator= (CARD32)name;
  368.     req->setState= changeState;
  369.     if (req->setState)
  370.      req->on= state;
  371.     else req->on= False;
  372.     if (pMap!=NULL) {
  373.     req->setMap= True;
  374.     req->createMap= createNewMap;
  375.     req->flags= pMap->flags;
  376.     req->whichGroups= pMap->which_groups;
  377.     req->groups= pMap->groups;
  378.     req->whichMods= pMap->which_mods;
  379.     req->realMods= pMap->mods.real_mods;
  380.     req->virtualMods= pMap->mods.vmods;
  381.     req->ctrls= pMap->ctrls;
  382.     }
  383.     else {
  384.     req->setMap=         False;
  385.     req->createMap=     False;
  386.     req->flags=         0;
  387.     req->whichGroups=     0;
  388.     req->groups=         0;
  389.     req->whichMods=     0;
  390.     req->realMods=         0;
  391.     req->virtualMods=     0;
  392.     req->ctrls=        0;
  393.     }
  394.     UnlockDisplay(dpy);
  395.     SyncHandle();
  396.     DBUG_RETURN(True);
  397. }
  398. #endif
  399.  
  400. Bool
  401. #if NeedFunctionPrototypes
  402. XkbSetNamedIndicator(    Display *        dpy,
  403.             Atom            name,
  404.             Bool            changeState,
  405.             Bool            state,
  406.             Bool            createNewMap,
  407.             XkbIndicatorMapPtr    pMap)
  408. #else
  409. XkbSetNamedIndicator(dpy,name,changeState,state,createNewMap,pMap)
  410.     Display *        dpy;
  411.     Atom        name;
  412.     Bool        changeState;
  413.     Bool        state;
  414.     Bool        createNewMap;
  415.     XkbIndicatorMapPtr    pMap;
  416. #endif
  417. {
  418.     DBUG_ENTER("XkbSetNamedIndicator")
  419.     Bool result = XkbSetNamedDeviceIndicator(dpy,XkbUseCoreKbd,
  420.                       XkbDfltXIClass,XkbDfltXIId,
  421.                       name,changeState,state,
  422.                       createNewMap,pMap);
  423.     DBUG_RETURN(result);
  424. }
  425.