A better Beep

David Lee Lambert lamber45 at cse.msu.edu
Mon May 16 15:04:28 CDT 2005


Changelog:
  Support beeping with the PC speaker when running from the Linux console

-- 
David Lee Lambert (also as4109 at wayne.edu)    cell ph# 586-873-8813
PGP key at http://www.cse.msu.edu/~lamber45/newmail.htm#GPGKey
-------------- next part --------------
--- dlls/kernel/console.c.v1_39	Fri May 13 15:38:16 2005
+++ dlls/kernel/console.c	Fri May 13 21:02:19 2005
@@ -193,9 +193,19 @@
  */
 BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
 {
-    static const char beep = '\a';
-    /* dwFreq and dwDur are ignored by Win95 */
-    if (isatty(2)) write( 2, &beep, 1 );
+   if (strcmp(getenv("TERM"),"linux")==0 && isatty(2)) {
+      /* the Linux console supports setting frequency and duration */
+      char szBeep[50];
+      snprintf(szBeep,50,"\x1B[10;%d]\x1B[11;%d]\a",(int)dwFreq,(int)dwDur);
+      write( 2, szBeep, strlen(szBeep) );
+      usleep(dwDur*1000);
+   } else if (isatty(2)) {
+      /* dwFreq and dwDur are ignored by Win95 */
+      static const char beep = '\a';
+      write( 2, &beep, 1 );
+   } else {
+      /* TODO: we could play a .wav file instead... */
+   }
     return TRUE;
 }
 


More information about the wine-patches mailing list