summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2023-08-16 10:27:41 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2023-08-16 10:27:41 +0200
commit4aae2d1224bdda67870cee96333336e4a6985f49 (patch)
tree7f169ce761a90ef2c9b8e2d5c76e5d9f89bd4ad7
parent34db9e8bf7198575e6adeed6a972a9695a1dd320 (diff)
Allow build of sudoku app with macOS + XQuartz
-rw-r--r--test/sudoku.cxx36
1 files changed, 19 insertions, 17 deletions
diff --git a/test/sudoku.cxx b/test/sudoku.cxx
index 97766ac2f..feb41fab7 100644
--- a/test/sudoku.cxx
+++ b/test/sudoku.cxx
@@ -42,14 +42,17 @@
#ifndef _WIN32
# include <unistd.h>
#endif // !_WIN32
+#if defined __APPLE__ && !defined(FLTK_USE_X11)
+# define USE_MACOS 1
+#endif
#ifdef HAVE_ALSA_ASOUNDLIB_H
# define ALSA_PCM_NEW_HW_PARAMS_API
# include <alsa/asoundlib.h>
#endif // HAVE_ALSA_ASOUNDLIB_H
-#ifdef __APPLE__
+#ifdef USE_MACOS
# include <CoreAudio/AudioHardware.h>
-#endif // __APPLE__
+#endif // USE_MACOS
#ifdef _WIN32
# include <mmsystem.h>
#endif // _WIN32
@@ -62,11 +65,11 @@
#define GROUP_SIZE 160
#define CELL_SIZE 50
#define CELL_OFFSET 5
-#ifdef __APPLE__
+#ifdef USE_MACOS
# define MENU_OFFSET 0
#else
# define MENU_OFFSET 25
-#endif // __APPLE__
+#endif // USE_MACOS
// Sound class for Sudoku...
//
@@ -85,11 +88,8 @@
// the CoreAudio implementation you see here!
class SudokuSound {
// Private, OS-specific data...
-#ifdef __APPLE__
+#ifdef USE_MACOS
AudioDeviceID device;
-#ifndef MAC_OS_X_VERSION_10_5
-#define MAC_OS_X_VERSION_10_5 1050
-#endif
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
AudioDeviceIOProcID audio_proc_id;
# endif
@@ -115,7 +115,7 @@ class SudokuSound {
# ifdef HAVE_ALSA_ASOUNDLIB_H
snd_pcm_t *handle;
# endif // HAVE_ALSA_ASOUNDLIB_H
-#endif // __APPLE__
+#endif // USE_MACOS
// Common data...
static int frequencies[9];
@@ -216,7 +216,7 @@ int SudokuSound::sample_size = 0;
SudokuSound::SudokuSound() {
sample_size = 0;
-#ifdef __APPLE__
+#ifdef USE_MACOS
remaining = 0;
UInt32 size = sizeof(device);
@@ -312,7 +312,7 @@ SudokuSound::SudokuSound() {
}
}
# endif // HAVE_ALSA_ASOUNDLIB_H
-#endif // __APPLE__
+#endif // USE_MACOS
if (sample_size) {
// Make each of the notes using a combination of sine and sawtooth waves
@@ -344,7 +344,7 @@ SudokuSound::SudokuSound() {
// Cleanup the SudokuSound class
SudokuSound::~SudokuSound() {
-#ifdef __APPLE__
+#ifdef USE_MACOS
if (sample_size) {
# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
AudioDeviceStop(device, audio_proc_id);
@@ -373,7 +373,7 @@ SudokuSound::~SudokuSound() {
snd_pcm_close(handle);
}
# endif // HAVE_ALSA_ASOUNDLIB_H
-#endif // __APPLE__
+#endif // USE_MACOS
if (sample_size) {
for (int i = 0; i < 9; i ++) {
@@ -383,7 +383,7 @@ SudokuSound::~SudokuSound() {
}
-#ifdef __APPLE__
+#ifdef USE_MACOS
// Callback function for writing audio data...
OSStatus
SudokuSound::audio_cb(AudioDeviceID device,
@@ -413,7 +413,7 @@ SudokuSound::audio_cb(AudioDeviceID device,
return noErr;
}
-#endif // __APPLE__
+#endif // USE_MACOS
#define NOTE_DURATION 50
@@ -421,7 +421,7 @@ SudokuSound::audio_cb(AudioDeviceID device,
void SudokuSound::play(char note) {
Fl::check();
-#ifdef __APPLE__
+#ifdef USE_MACOS
// Point to the next note...
data = sample_data[note - 'A'];
remaining = sample_size * 2;
@@ -477,7 +477,7 @@ void SudokuSound::play(char note) {
XChangeKeyboardControl(fl_display,
KBBellPercent | KBBellPitch | KBBellDuration,
&control);
-#endif // __APPLE__
+#endif // USE_MACOS
}
@@ -643,7 +643,9 @@ Sudoku::Sudoku()
{ "&Solve Game", FL_COMMAND | 's', solve_cb, 0, FL_MENU_DIVIDER },
{ "&Update Helpers", 0, update_helpers_cb, 0, 0 },
{ "&Mute Sound", FL_COMMAND | 'm', mute_cb, 0, FL_MENU_TOGGLE | FL_MENU_DIVIDER },
+#ifndef USE_MACOS
{ "&Quit", FL_COMMAND | 'q', close_cb, 0, 0 },
+#endif
{ 0 },
{ "&Difficulty", 0, 0, 0, FL_SUBMENU },
{ "&Easy", 0, diff_cb, (void *)"0", FL_MENU_RADIO },