Modified form of Jim Lucas's PC speaker patch. I don't like
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 24 May 2003 12:31:32 +0000 (12:31 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sat, 24 May 2003 12:31:32 +0000 (12:31 +0000)
discriminating on the Windows version in order to decide whether to
call MessageBeep(-1) or Beep() - I'd prefer to directly test the
specific OS property in any given case - but it looks as if this is
the best available option.

git-svn-id: svn://svn.tartarus.org/sgt/putty@3208 cda61777-01e9-0310-a592-d414129be87e

putty.h
wincfg.c
window.c

diff --git a/putty.h b/putty.h
index 6d5a0a2..46d6dc6 100644 (file)
--- a/putty.h
+++ b/putty.h
@@ -243,7 +243,7 @@ enum {
 
 enum {
     /* Bell settings (cfg.beep) */
-    BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE
+    BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE, BELL_PCSPEAKER
 };
 
 enum {
index 7e3d5c0..c094eb7 100644 (file)
--- a/wincfg.c
+++ b/wincfg.c
@@ -103,10 +103,10 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
                  dlg_stdcheckbox_handler, I(offsetof(Config,ctrlaltkeys)));
 
     /*
-     * Windows allows an arbitrary .WAV to be played as a bell. For
-     * this we must search the existing controlset for the
-     * radio-button set controlling the `beep' option, and add an
-     * extra button to it.
+     * Windows allows an arbitrary .WAV to be played as a bell, and
+     * also the use of the PC speaker. For this we must search the
+     * existing controlset for the radio-button set controlling the
+     * `beep' option, and add extra buttons to it.
      * 
      * Note that although this _looks_ like a hideous hack, it's
      * actually all above board. The well-defined interface to the
@@ -127,18 +127,22 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
            if (c->generic.type == CTRL_RADIO &&
                c->generic.context.i == offsetof(Config, beep)) {
                assert(c->generic.handler == dlg_stdradiobutton_handler);
-               c->radio.nbuttons++;
+               c->radio.nbuttons += 2;
                c->radio.buttons =
                    sresize(c->radio.buttons, c->radio.nbuttons, char *);
                c->radio.buttons[c->radio.nbuttons-1] =
                    dupstr("Play a custom sound file");
+               c->radio.buttons[c->radio.nbuttons-2] =
+                   dupstr("Beep using the PC speaker");
                c->radio.buttondata =
                    sresize(c->radio.buttondata, c->radio.nbuttons, intorptr);
                c->radio.buttondata[c->radio.nbuttons-1] = I(BELL_WAVEFILE);
+               c->radio.buttondata[c->radio.nbuttons-2] = I(BELL_PCSPEAKER);
                if (c->radio.shortcuts) {
                    c->radio.shortcuts =
                        sresize(c->radio.shortcuts, c->radio.nbuttons, char);
                    c->radio.shortcuts[c->radio.nbuttons-1] = NO_SHORTCUT;
+                   c->radio.shortcuts[c->radio.nbuttons-2] = NO_SHORTCUT;
                }
                break;
            }
index c9d8df5..e11b2b9 100644 (file)
--- a/window.c
+++ b/window.c
@@ -4406,6 +4406,23 @@ void beep(void *frontend, int mode)
                       MB_OK | MB_ICONEXCLAMATION);
            cfg.beep = BELL_DEFAULT;
        }
+    } else if (mode == BELL_PCSPEAKER) {
+       static long lastbeep = 0;
+       long beepdiff;
+
+       beepdiff = GetTickCount() - lastbeep;
+       if (beepdiff >= 0 && beepdiff < 50)
+           return;
+
+       /*
+        * We must beep in different ways depending on whether this
+        * is a 95-series or NT-series OS.
+        */
+       if(osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT)
+           Beep(800, 100);
+       else
+           MessageBeep(-1);
+       lastbeep = GetTickCount();
     }
     /* Otherwise, either visual bell or disabled; do nothing here */
     if (!term->has_focus) {