beeping objects

jerobins@unity.ncsu.edu
Mon, 8 May 1995 07:53:27 -0400 (EDT)

Juergen Schoenwaelder wrote:
>
> James> 2. Beep. A few beeps when a node goes down or hits a
> James> threshold would be wonderful to get folks attention. (I know
> James> tk4.0 has a beep command...but we can't wait that long :-)
>
> Beeping is very simple, even in Tk3.6:
>
> proc beep {} {
> catch {
> set f [open /dev/tty w]
> puts $f "\a"
> close $f
> }
> }

Doesn't work well when xterm is set for flashing bell... :-)

>
> The problem is that we need a way to control which events should
> create a beep.
>

In our set-up, anything that flashes should be beeping. Here is the
patch for all who are interested. Of course it will be obsolete when the
new event object is complete.

(included tkined-1.2.2-bell.patch)

--cut-it---------8<-----------------8<----------------------------
--- tkined.h.orig Wed Mar 22 12:43:50 1995
+++ tkined.h Fri May 5 14:31:09 1995
@@ -155,6 +155,7 @@
int loaded:1; /* Not zero if object was read from a file */
double scale; /* The scaling factor for a strip- or barchart */
int flash; /* The number of seconds the objects flashes */
+ int bell; /* @JER number of times to ring bell in alarm state */
int allocValues; /* Number of allocated doubles to hold values */
int numValues; /* The number of values stored in valuePtr */
double *valuePtr; /* Dynamically allocated memory for XY values */
--- flash.c.orig Sun Aug 28 14:23:20 1994
+++ flash.c Mon May 8 07:46:02 1995
@@ -34,6 +34,15 @@

static fli *flashlist = NULL;

+/* @JER added for XBeep so we can get the Display handle */
+extern Tk_Window w;
+
+/*
+ * @JER number of times to ring the bell when an object
+ * state changes toflashing
+ */
+#define ALARMBEEP 10
+
/*
* This callback flashes every object in the flashlist and calls
* it again if there are any jobs left.
@@ -78,6 +87,14 @@

object->flash -= 1;

+ /* @JER ring the bell for an alarm */
+ if ( object->bell > 0 ) {
+ XBell (Tk_Display(w), 0);
+ XForceScreenSaver (Tk_Display(w), ScreenSaverReset);
+ /* @JER decrement the bell counter */
+ object->bell--;
+ }
+
if (object->flash == 0) {
notrace (m_color, interp, object, 1, &object->color);
free (p->id);
@@ -141,4 +158,8 @@
p->next = NULL;

}
+
+ /* @JER set the number of bell rings */
+ object->bell = ALARMBEEP;
+
}
----cut-it-------8<-----------------8<----------------------------

Enjoy,
James

-- 
James E. Robinson, III    |    http://www.cc.ncsu.edu/james 
   jer@ncsu.edu           |  Research, Development and Data Comm.
Systems Programmer        |   North Carolina State University
---
 "The first step to wisdom is silence; the second is listening."