[comp.windows.x] Audible Bell

HODGES@SRI-STRIPE.ARPA (Richard Hodges) (03/18/87)

Why doesn't the Audible bell work in X.V10R4 on Sun 3/50, running
Sun OS 3.0 or 3.2?
-------

brisco@caip.RUTGERS.EDU (Thomas Paul Brisco) (03/19/87)

	
From: HODGES@SRI-STRIPE.ARPA (Richard Hodges)
>Why doesn't the Audible bell work in X.V10R4 on Sun 3/50, running
>Sun OS 3.0 or 3.2?

	It works out that you need a /dev/bell (believe it or not).
character device, major number the same as your tty's, minor number
one more than your highest tty minor number.

					tp.
-- 
                  ----------------------------------------------------------
                  -                  ARPA: Brisco@rutgers                  -
                  -  UUCP: (ihnp4!ut-sally, allegra!packard) !caip!brisco  -
                  ----------------------------------------------------------

tsf@theory.cs.cmu.edu (Timothy Freeman) (03/19/87)

In article <12287439268.16.HODGES@SRI-STRIPE.ARPA> HODGES@SRI-STRIPE.ARPA (Richard Hodges) writes:
>Why doesn't the Audible bell work in X.V10R4 on Sun 3/50, running
>Sun OS 3.0 or 3.2?

Here's what the comments from libsun/util.c say.  I did it on my Sun 3/160
and it worked.  I think that some operation similar to this was
mandated by the installation guide, but I can't get my hands on that
right now.

When I did this, after I created the bell I had to give a chmod
command when I was root to make the bell device writable by all.

 * Need to make the /dev/bell device with
 * the same major device number as tty[ab] but with a new minor number.
 *
 *  # /etc/mknod /dev/bell c 12 2
 *
 *  crw-rw-rw-  1 root      12,   0 Jan  6 18:18 /dev/ttya
 *  crw-rw-rw-  1 root      12,   1 Feb 26  1985 /dev/ttyb
 *  crw-rw-rw-  1 root      12,   2 Jan 14 08:45 /dev/bell
 *
 */

mlandau@Diamond.BBN.COM (Matt Landau) (03/19/87)

In comp.windows.x HODGES@SRI-STRIPE.ARPA (Richard Hodges) writes:
>Why doesn't the Audible bell work in X.V10R4 on Sun 3/50, running
>Sun OS 3.0 or 3.2?

You first have to create /dev/bell, which is the device XFeep() wants
to talk to.  I did it by issuing the following commands as root:

	/etc/mknod /dev/bell c 12 2
	chmod 666 /dev/bell
-- 
 Matt Landau      	 		BBN Laboratories, Inc.
    mlandau@diamond.bbn.com		10 Moulton Street, Cambridge MA 02238
 ...seismo!diamond.bbn.com!mlandau      (617) 497-2429

guy%gorodish@Sun.COM (Guy Harris) (03/19/87)

>You first have to create /dev/bell, which is the device XFeep() wants
>to talk to.

Or, alternatively, apply the following script to the X.V10R4
"libsun/util.c", which causes it to use the "ioctl"s that are
documented in the manual page KB(4S), at least in 3.2:

*** util.c	Mon Mar 16 08:40:44 1987
--- /tmp/util.c	Thu Mar 19 11:52:26 1987
***************
*** 59,118 ****
  
  #include "Xsun.h"
  #include <sys/time.h>
  
  extern int vsdev;
  
- /*
-  * Ring the bell on a sun 120, volume between 0 (quiet) and 7 (loud).  
-  * Need to make the /dev/bell device with
-  * the same major device number as tty[ab] but with a new minor number.
-  *
-  *  # /etc/mknod /dev/bell c 12 2
-  *
-  *  crw-rw-rw-  1 root      12,   0 Jan  6 18:18 /dev/ttya
-  *  crw-rw-rw-  1 root      12,   1 Feb 26  1985 /dev/ttyb
-  *  crw-rw-rw-  1 root      12,   2 Jan 14 08:45 /dev/bell
-  *
-  */
- 
- 
- #define RING_ON         0x02    /* Control-B */
- #define RING_OFF        0x03    /* Control-C */
  #define RING_WAIT       25000 /* microseconds, for volume 1 */
  #ifndef NULL
  #define NULL            0
  #endif
  
  SoundBell (volume)
      int volume;
  {
-     static int bell = -1;
-     int status;
-     char outbuf[1];
      struct timeval ring_time;
  
      if (volume == 0) {
  	return(0);
      }
!     if (bell < 0) {
! 	bell = open("/dev/bell",2);
! 	if (bell < 0) {
  	    return(1);
  	}
      }
      ring_time.tv_sec = 0;
      ring_time.tv_usec = RING_WAIT * volume;
!     outbuf[0] = RING_ON;
!     status = write(bell,outbuf,1);
!     if (status < 0) {
  	return(1);
      }
  
      select(0, NULL, NULL, NULL, &ring_time);
  
!     outbuf[0] = RING_OFF;
!     status = write(bell,outbuf,1);
!     if (status < 0) {
  	return(1);
      }
      return (0);
--- 59,102 ----
  
  #include "Xsun.h"
  #include <sys/time.h>
+ #include <sys/ioctl.h>
+ #include <sundev/kbd.h>
+ #include <sundev/kbio.h>
  
  extern int vsdev;
  
  #define RING_WAIT       25000 /* microseconds, for volume 1 */
  #ifndef NULL
  #define NULL            0
  #endif
  
+ static int kbdfd = -1;
+ 
  SoundBell (volume)
      int volume;
  {
      struct timeval ring_time;
+     static int bell = KBD_CMD_BELL;
+     static int nobell = KBD_CMD_NOBELL;
  
      if (volume == 0) {
  	return(0);
      }
!     if (kbdfd < 0) {
! 	kbdfd = open("/dev/kbd",2);
! 	if (kbdfd < 0) {
  	    return(1);
  	}
      }
      ring_time.tv_sec = 0;
      ring_time.tv_usec = RING_WAIT * volume;
!     if (ioctl(kbdfd, KIOCCMD, &bell) < 0) {
  	return(1);
      }
  
      select(0, NULL, NULL, NULL, &ring_time);
  
!     if (ioctl(kbdfd, KIOCCMD, &nobell) < 0) {
  	return(1);
      }
      return (0);
***************
*** 123,129 ****
  SetKeyClick (volume)
  	int volume;
  {
! 	return (0);
  }
  
  /* Set autorepeat */
--- 107,125 ----
  SetKeyClick (volume)
  	int volume;
  {
!     int cmd;
! 
!     if (kbdfd < 0) {
! 	kbdfd = open("/dev/kbd",2);
! 	if (kbdfd < 0) {
! 	    return(1);
! 	}
!     }
!     cmd = (volume == 0) ? KBD_CMD_NOCLICK : KBD_CMD_CLICK;
!     if (ioctl(kbdfd, KIOCCMD, &cmd) < 0) {
! 	return(1);
!     }
!     return (0);
  }
  
  /* Set autorepeat */

This also gives you the ability to change the key click.  CAVEAT: I haven't
tried this to see what it does on a Sun-2 keyboard.  I also don't
guarantee that it won't get confused.  SunView doesn't change the key
click; I have no idea if this is because they haven't bothered or
because the keyboard can get confused.  There are some comments in
the keyboard driver code that imply the latter is a possibility....

FURTHER CAVEAT: I haven't dropped this into X to try it out.  I just
tested the "ioctl"s under SunView in stand-alone programs (although
the bell "ioctl"s are what SunView uses to ring the audible bell).
If it doesn't compile, the changes should be obvious.  Also note that
all the other caveats we stuck into "util.c" apply here as well:

 * The Sun X drivers are a product of Sun Microsystems, Inc. and are provided
 * for unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify these drivers without charge, but are not authorized
 * to license or distribute them to anyone else except as part of a product or
 * program developed by the user.
 * 
 * THE SUN X DRIVERS ARE PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND
 * INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE
 * PRACTICE.
 *
 * The Sun X Drivers are provided with no support and without any obligation
 * on the part of Sun Microsystems, Inc. to assist in their use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THE SUN X
 * DRIVERS OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.

The changes to other versions of "util.c" should be similar (the
version from the 4.3BSD tape doesn't have SoundBell, so you just drop
the new one in).

guy%gorodish@Sun.COM (Guy Harris) (03/19/87)

>	It works out that you need a /dev/bell (believe it or not).
>character device, major number the same as your tty's, minor number
>one more than your highest tty minor number.

BTW, for those of you whose curiosity is insatiable, this "/dev/bell"
is just a special file that refers to one of the machine's serial
ports - in this case, the serial port to which the keyboard is
connected.  The keyboard is connected to the "zs2" serial port, and
the mouse is connected to the "zs3" serial port.  The "/dev/ttya" and
"/dev/ttyb" ports are the "zs0" and "zs1" serial ports, respectively.

HODGES@SRI-STRIPE.ARPA (Richard Hodges) (03/20/87)

Thanks to the MANY people who responded to my query about the audible bell.
Shouldn't creation of /dev/bell be taken care of by make install? Or at 
least mentioned in install.doc?
-------