xW: improve beeping

This adds yet another build dependency,
but it's better than the alternatives of handling it in code.
This commit is contained in:
Přemysl Eric Janouch 2023-07-27 16:05:32 +02:00
parent 3d345987c3
commit fcd1b8e011
Signed by: p
GPG Key ID: A0420B94F92B9493
4 changed files with 22 additions and 6 deletions

View File

@ -59,6 +59,13 @@ function (icon_for_win32 ico pngs pngs_raw)
COMMENT "Generating Windows program icon" VERBATIM)
endfunction ()
# Produce a beep sample
find_program (sox_EXECUTABLE sox ${find_program_REQUIRE})
add_custom_command (OUTPUT beep.wav
COMMAND ${sox_EXECUTABLE} -b 16 -Dr 44100 -n beep.wav
synth 0.1 0 25 triangle 800 vol 0.5 fade t 0 -0 0.005 pad 0 0.05
COMMENT "Generating a beep sample" VERBATIM)
# Rasterize SVG icons
set (icon_ico_list)
foreach (icon xW xW-highlighted)
@ -76,7 +83,8 @@ foreach (icon xW xW-highlighted)
list (APPEND icon_ico_list ${icon_ico})
endforeach ()
set_property (SOURCE xW.rc APPEND PROPERTY OBJECT_DEPENDS ${icon_ico_list})
set_property (SOURCE xW.rc
APPEND PROPERTY OBJECT_DEPENDS ${icon_ico_list} beep.wav)
# Build the main executable and link it
set (root "${PROJECT_SOURCE_DIR}/..")
@ -97,7 +105,7 @@ add_custom_target (xC-proto DEPENDS ${PROJECT_BINARY_DIR}/xC-proto.cpp)
add_executable (xW WIN32 xW.cpp xW.rc xW.manifest ${project_config}
${root}/liberty/tools/lxdrgen-cpp-win32.cpp)
target_link_libraries (xW comctl32 ws2_32)
target_link_libraries (xW comctl32 ws2_32 winmm)
add_dependencies (xW xC-proto)
# At least with MinGW, this is a fully independent portable executable

View File

@ -1,5 +1,6 @@
#define IDI_ICON 1
#define IDI_HIGHLIGHTED 2
#define IDR_BEEP 3
#define IDA_ACCELERATORS 10
// Named after input_add_functions() in xC.

View File

@ -165,6 +165,14 @@ window_get_text(HWND hWnd)
return buffer;
}
static void
beep()
{
if (!PlaySound(MAKEINTRESOURCE(IDR_BEEP),
GetModuleHandle(NULL), SND_ASYNC | SND_RESOURCE))
Beep(800, 100);
}
// --- Networking --------------------------------------------------------------
static bool
@ -785,8 +793,7 @@ relay_process_buffer_line(Buffer &b, Relay::EventData_BufferLine &m)
if (line->is_highlight || (!visible && !line->is_unimportant &&
b.kind == Relay::BufferKind::PRIVATE_MESSAGE)) {
// TODO(p): Avoid the PC speaker, which is also unreliable.
Beep(800, 100);
beep();
if (!visible) {
b.highlighted = true;
@ -1261,9 +1268,8 @@ input_complete(const InputStamp &state, const std::wstring &error,
SendMessage(g.hwndInput, EM_REPLACESEL, TRUE, (LPARAM) insert.c_str());
}
// TODO(p): Avoid the PC speaker, which is also unreliable.
if (response->completions.size() != 1)
Beep(800, 100);
beep();
// TODO(p): Show all completion options.
}

View File

@ -12,6 +12,7 @@ CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "xW.manifest"
IDI_ICON ICON "xW.ico"
IDI_HIGHLIGHTED ICON "xW-highlighted.ico"
IDR_BEEP WAVE "beep.wav"
IDA_ACCELERATORS ACCELERATORS
BEGIN