home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / server / xinput / xdevbell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-14  |  4.1 KB  |  149 lines

  1. #ifdef XINPUT
  2. /* $Header: xdevbell.c,v 1.2 91/05/14 12:22:22 rws Exp $ */
  3.  
  4. /************************************************************
  5. Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, California, and the 
  6. Massachusetts Institute of Technology, Cambridge, Massachusetts.
  7.  
  8.             All Rights Reserved
  9.  
  10. Permission to use, copy, modify, and distribute this software and its
  11. documentation for any purpose and without fee is hereby granted,
  12. provided that the above copyright notice appear in all copies and that
  13. both that copyright notice and this permission notice appear in
  14. supporting documentation, and that the names of Hewlett-Packard or MIT not be
  15. used in advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17.  
  18. HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  20. HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  21. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  23. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  24. SOFTWARE.
  25.  
  26. ********************************************************/
  27.  
  28. /***********************************************************************
  29.  *
  30.  * Extension function to change the keyboard device.
  31.  *
  32.  */
  33.  
  34. #define     NEED_EVENTS
  35. #define     NEED_REPLIES
  36. #include "X.h"                /* for inputstr.h    */
  37. #include "Xproto.h"            /* Request macro     */
  38. #include "inputstr.h"            /* DeviceIntPtr         */
  39. #include "XI.h"
  40. #include "XIproto.h"
  41.  
  42. extern    int         IReqCode;
  43. extern    int         BadDevice;
  44. extern    void        (* ReplySwapVector[256]) ();
  45. DeviceIntPtr        LookupDeviceIntRec();
  46.  
  47. /***********************************************************************
  48.  *
  49.  * This procedure is invoked to swap the request bytes if the server and
  50.  * client have a different byte order.
  51.  *
  52.  */
  53.  
  54. int
  55. SProcXDeviceBell(client)
  56.     register ClientPtr client;
  57.     {
  58.     register char n;
  59.  
  60.     REQUEST(xDeviceBellReq);
  61.     swaps(&stuff->length, n);
  62.     return(ProcXDeviceBell(client));
  63.     }
  64.  
  65. /***********************************************************************
  66.  *
  67.  * This procedure rings a bell on an extension device.
  68.  *
  69.  */
  70.  
  71. ProcXDeviceBell (client)
  72.     register ClientPtr client;
  73.     {
  74.     DeviceIntPtr dev;
  75.     KbdFeedbackPtr k;
  76.     BellFeedbackPtr b;
  77.     int base;
  78.     int newpercent;
  79.     CARD8 class;
  80.     pointer ctrl;
  81.     void (*proc)();
  82.  
  83.     REQUEST(xDeviceBellReq);
  84.     REQUEST_SIZE_MATCH(xDeviceBellReq);
  85.  
  86.     dev = LookupDeviceIntRec (stuff->deviceid);
  87.     if (dev == NULL)
  88.     {
  89.     client->errorValue = stuff->deviceid;
  90.     SendErrorToClient(client, IReqCode, X_DeviceBell, 0, BadDevice);
  91.     return Success;
  92.     }
  93.  
  94.     if (stuff->percent < -100 || stuff->percent > 100)
  95.     {
  96.     client->errorValue = stuff->percent;
  97.     SendErrorToClient(client, IReqCode, X_DeviceBell, 0, BadValue);
  98.     return Success;
  99.     }
  100.     if (stuff->feedbackclass == KbdFeedbackClass)
  101.     {
  102.     for (k=dev->kbdfeed; k; k=k->next)
  103.         if (k->ctrl.id == stuff->feedbackid)
  104.         break;
  105.     if (!k)
  106.         {
  107.         client->errorValue = stuff->feedbackid;
  108.         SendErrorToClient(client, IReqCode, X_DeviceBell, 0, BadValue);
  109.         return Success;
  110.         }
  111.     base = k->ctrl.bell;
  112.     proc = k->BellProc;
  113.     ctrl = (pointer) &(k->ctrl);
  114.     class = KbdFeedbackClass;
  115.     }
  116.     else if (stuff->feedbackclass == BellFeedbackClass)
  117.     {
  118.     for (b=dev->bell; b; b=b->next)
  119.         if (b->ctrl.id == stuff->feedbackid)
  120.         break;
  121.     if (!b)
  122.         {
  123.         client->errorValue = stuff->feedbackid;
  124.         SendErrorToClient(client, IReqCode, X_DeviceBell, 0, BadValue);
  125.         return Success;
  126.         }
  127.     base = b->ctrl.percent;
  128.     proc = b->BellProc;
  129.     ctrl = (pointer) &(b->ctrl);
  130.     class = BellFeedbackClass;
  131.     }
  132.     else
  133.     {
  134.     client->errorValue = stuff->feedbackclass;
  135.     SendErrorToClient(client, IReqCode, X_DeviceBell, 0, BadValue);
  136.     return Success;
  137.     }
  138.     newpercent = (base * stuff->percent) / 100;
  139.     if (stuff->percent < 0)
  140.         newpercent = base + newpercent;
  141.     else
  142.         newpercent = base - newpercent + stuff->percent;
  143.     (*proc)(newpercent, dev, ctrl, class);
  144.  
  145.     return Success;
  146.     }
  147.  
  148. #endif /* XINPUT */
  149.