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