home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume41 / morse / part02 / beepX11.c < prev    next >
C/C++ Source or Header  |  1993-12-19  |  1KB  |  81 lines

  1. /* beepX11.c -- seligman 5/92 */
  2.  
  3. /*
  4. -- Implementation of beep.h for X11.
  5. --
  6. -- Compile with the library "-lX11".
  7. */
  8.  
  9. #include "beep.h"
  10. #include <X11/Xlib.h>
  11.  
  12.  
  13. static Display *dpy = 0;
  14. static XKeyboardControl initialState;
  15.  
  16. #define BellFlags (KBBellPercent | KBBellPitch | KBBellDuration)
  17.  
  18.  
  19. int BeepInit()
  20. {
  21.     XKeyboardState state;
  22.  
  23.     if (! (dpy = XOpenDisplay(0))) {
  24.     perror("Couldn't open display");
  25.     return 1;
  26.     }
  27.  
  28.     /* Save initial state so it can be restored later. */
  29.     XGetKeyboardControl(dpy, &state);
  30.     initialState.bell_duration = state.bell_duration;
  31.     initialState.bell_percent  = state.bell_percent;
  32.     initialState.bell_pitch    = state.bell_pitch;
  33.  
  34.     return 0;
  35. }
  36.  
  37.  
  38. int Beep(time, volume, pitch)
  39.     int time, volume, pitch;
  40. {
  41.     XKeyboardControl values;
  42.  
  43.     AlarmWait();
  44.  
  45.     if (volume != 0  &&  pitch != 0) {
  46.     values.bell_duration = time;
  47.     values.bell_percent  = 100;
  48.     values.bell_pitch    = pitch;
  49.  
  50.     XChangeKeyboardControl(dpy, BellFlags, &values);
  51.     XBell(dpy, volume - 100);
  52.     XFlush(dpy);
  53.     }
  54.  
  55.     AlarmSet(time);
  56.     return 0;
  57. }
  58.  
  59.  
  60. int BeepWait()
  61. {
  62.     AlarmWait();
  63.     return 0;
  64. }
  65.  
  66.  
  67. int BeepCleanup()
  68. {
  69.     if (dpy != 0) {
  70.     XChangeKeyboardControl(dpy, BellFlags, &initialState);
  71.     XFlush(dpy);
  72.     }
  73.     return 0;
  74. }
  75.  
  76.  
  77. int BeepResume()
  78. {
  79.     return 0;
  80. }
  81.