-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbeeper.cc
53 lines (46 loc) · 1.21 KB
/
beeper.cc
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
#include <cstdlib>
#include <cstdio>
#include "settings.hh"
#include "beeper.hh"
#include <SDL.h>
#include <SDL_syswm.h>
#ifdef SDL_VIDEO_DRIVER_X11
# include <X11/Xlib.h>
#endif
#ifdef SDL_VIDEO_DRIVER_WINDOWS
# include <Utilapiset.h>
#endif
extern SDL_Window* window;
void BeepOn()
{
if(Headless) return;
SDL_SysWMinfo info = {};
SDL_VERSION(&info.version);
if(!SDL_GetWindowWMInfo(window,&info))
fprintf(stderr, "GetWindowWMInfo failed %s\n", SDL_GetError());
#ifdef SDL_VIDEO_DRIVER_X11
if(info.subsystem == SDL_SYSWM_X11)
{
if(auto display = info.info.x11.display)
{
XKeyboardControl ctrl = {};
ctrl.bell_percent = 100;
ctrl.bell_pitch = 440;
ctrl.bell_duration = 50;
XChangeKeyboardControl(display, KBBellPitch|KBBellPercent|KBBellDuration, &ctrl);
XBell(display, 100);
return;
}
}
#endif
#ifdef SDL_VIDEO_DRIVER_WINDOWS
if(info.subsystem == SDL_SYSWM_WINDOWS)
{
Beep(440, 50);
return;
}
#endif
// Unknown video driver.
// TODO: Create an audio interface.
// TODO: Synthesize beep.
}