f95d0ee817e07ee26a025496e48a585516a33462
1 /************************************************************
2 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
27 #ifdef HAVE_DIX_CONFIG_H
28 #include <dix-config.h>
33 #include <X11/Xproto.h>
34 #include <X11/keysym.h>
36 #include "scrnintstr.h"
37 #include "windowstr.h"
39 #include <X11/extensions/XI.h>
41 /*#define FALLING_TONE 1*/
42 /*#define RISING_TONE 1*/
43 #define FALLING_TONE 10
44 #define RISING_TONE 10
46 #define SHORT_DELAY 60
48 #define VERY_LONG_TONE 100
50 #define CLICK_DURATION 1
52 #define DEEP_PITCH 250
54 #define MID_PITCH 1000
55 #define HIGH_PITCH 2000
56 #define CLICK_PITCH 1500
58 static unsigned long atomGeneration
= 0;
59 static Atom featureOn
;
60 static Atom featureOff
;
61 static Atom featureChange
;
64 static Atom ledChange
;
66 static Atom slowPress
;
67 static Atom slowReject
;
68 static Atom slowAccept
;
69 static Atom slowRelease
;
70 static Atom stickyLatch
;
71 static Atom stickyLock
;
72 static Atom stickyUnlock
;
73 static Atom bounceReject
;
74 static char doesPitch
= 1;
76 #define FEATURE_ON "AX_FeatureOn"
77 #define FEATURE_OFF "AX_FeatureOff"
78 #define FEATURE_CHANGE "AX_FeatureChange"
79 #define LED_ON "AX_IndicatorOn"
80 #define LED_OFF "AX_IndicatorOff"
81 #define LED_CHANGE "AX_IndicatorChange"
82 #define SLOW_WARN "AX_SlowKeysWarning"
83 #define SLOW_PRESS "AX_SlowKeyPress"
84 #define SLOW_REJECT "AX_SlowKeyReject"
85 #define SLOW_ACCEPT "AX_SlowKeyAccept"
86 #define SLOW_RELEASE "AX_SlowKeyRelease"
87 #define STICKY_LATCH "AX_StickyLatch"
88 #define STICKY_LOCK "AX_StickyLock"
89 #define STICKY_UNLOCK "AX_StickyUnlock"
90 #define BOUNCE_REJECT "AX_BounceKeyReject"
92 #define MAKE_ATOM(a) MakeAtom(a,sizeof(a)-1,TRUE)
95 _XkbDDXBeepInitAtoms(void)
97 featureOn
= MAKE_ATOM(FEATURE_ON
);
98 featureOff
= MAKE_ATOM(FEATURE_OFF
);
99 featureChange
= MAKE_ATOM(FEATURE_CHANGE
);
100 ledOn
= MAKE_ATOM(LED_ON
);
101 ledOff
= MAKE_ATOM(LED_OFF
);
102 ledChange
= MAKE_ATOM(LED_CHANGE
);
103 slowWarn
= MAKE_ATOM(SLOW_WARN
);
104 slowPress
= MAKE_ATOM(SLOW_PRESS
);
105 slowReject
= MAKE_ATOM(SLOW_REJECT
);
106 slowAccept
= MAKE_ATOM(SLOW_ACCEPT
);
107 slowRelease
= MAKE_ATOM(SLOW_RELEASE
);
108 stickyLatch
= MAKE_ATOM(STICKY_LATCH
);
109 stickyLock
= MAKE_ATOM(STICKY_LOCK
);
110 stickyUnlock
= MAKE_ATOM(STICKY_UNLOCK
);
111 bounceReject
= MAKE_ATOM(BOUNCE_REJECT
);
116 _XkbDDXBeepExpire(OsTimerPtr timer
, CARD32 now
, pointer arg
)
118 DeviceIntPtr dev
= (DeviceIntPtr
) arg
;
121 XkbSrvInfoPtr xkbInfo
;
124 int oldPitch
, oldDuration
;
127 if ((dev
== NULL
) || (dev
->key
== NULL
) || (dev
->key
->xkbInfo
== NULL
) ||
128 (dev
->kbdfeed
== NULL
))
130 if (atomGeneration
!= serverGeneration
) {
131 _XkbDDXBeepInitAtoms();
132 atomGeneration
= serverGeneration
;
137 xkbInfo
= dev
->key
->xkbInfo
;
139 pitch
= oldPitch
= ctrl
->bell_pitch
;
140 duration
= oldDuration
= ctrl
->bell_duration
;
142 switch (xkbInfo
->beepType
) {
144 ErrorF("[xkb] Unknown beep type %d\n", xkbInfo
->beepType
);
149 /* When an LED is turned on, we want a high-pitched beep.
150 * When the LED it turned off, we want a low-pitched beep.
151 * If we cannot do pitch, we want a single beep for on and two
157 duration
= SHORT_TONE
;
163 duration
= SHORT_TONE
;
165 if (!doesPitch
&& xkbInfo
->beepCount
< 1)
169 /* When a Feature is turned on, we want an up-siren.
170 * When a Feature is turned off, we want a down-siren.
171 * If we cannot do pitch, we want a single beep for on and two
174 case _BEEP_FEATURE_ON
:
177 if (xkbInfo
->beepCount
< 1) {
179 duration
= VERY_LONG_TONE
;
185 duration
= SHORT_TONE
;
189 case _BEEP_FEATURE_OFF
:
192 if (xkbInfo
->beepCount
< 1) {
195 duration
= VERY_LONG_TONE
;
197 duration
= SHORT_TONE
;
202 duration
= SHORT_TONE
;
206 /* Two high beeps indicate an LED or Feature changed
207 * state, but that another LED or Feature is also on.
208 * [[[WDW - This is not in AccessDOS ]]]
210 case _BEEP_LED_CHANGE
:
213 case _BEEP_FEATURE_CHANGE
:
215 name
= featureChange
;
216 duration
= SHORT_TONE
;
218 if (xkbInfo
->beepCount
< 1) {
223 /* Three high-pitched beeps are the warning that SlowKeys
224 * is going to be turned on or off.
226 case _BEEP_SLOW_WARN
:
229 duration
= SHORT_TONE
;
231 if (xkbInfo
->beepCount
< 2)
235 /* Click on SlowKeys press and accept.
236 * Deep pitch when a SlowKey or BounceKey is rejected.
237 * [[[WDW - Rejects are not in AccessDOS ]]]
238 * If we cannot do pitch, we want single beeps.
240 case _BEEP_SLOW_PRESS
:
243 case _BEEP_SLOW_ACCEPT
:
246 case _BEEP_SLOW_RELEASE
:
249 duration
= CLICK_DURATION
;
252 case _BEEP_BOUNCE_REJECT
:
255 case _BEEP_SLOW_REJECT
:
258 duration
= SHORT_TONE
;
262 /* Low followed by high pitch when a StickyKey is latched.
263 * High pitch when a StickyKey is locked.
264 * Low pitch when unlocked.
265 * If we cannot do pitch, two beeps for latch, nothing for
266 * lock, and two for unlock.
268 case _BEEP_STICKY_LATCH
:
271 duration
= SHORT_TONE
;
272 if (xkbInfo
->beepCount
< 1) {
279 case _BEEP_STICKY_LOCK
:
283 duration
= SHORT_TONE
;
287 case _BEEP_STICKY_UNLOCK
:
290 duration
= SHORT_TONE
;
292 if (!doesPitch
&& xkbInfo
->beepCount
< 1)
296 if (timer
== NULL
&& duration
> 0) {
297 CARD32 starttime
= GetTimeInMillis();
300 ctrl
->bell_duration
= duration
;
301 ctrl
->bell_pitch
= pitch
;
302 if (xkbInfo
->beepCount
== 0) {
303 XkbHandleBell(0, 0, dev
, ctrl
->bell
, (pointer
) ctrl
,
304 KbdFeedbackClass
, name
, None
, NULL
);
306 else if (xkbInfo
->desc
->ctrls
->enabled_ctrls
& XkbAudibleBellMask
) {
307 (*dev
->kbdfeed
->BellProc
) (ctrl
->bell
, dev
, (pointer
) ctrl
,
310 ctrl
->bell_duration
= oldDuration
;
311 ctrl
->bell_pitch
= oldPitch
;
312 xkbInfo
->beepCount
++;
314 /* Some DDX schedule the beep and return immediately, others don't
315 return until the beep is completed. We measure the time and if
316 it's less than the beep duration, make sure not to schedule the
317 next beep until after the current one finishes. */
319 elapsedtime
= GetTimeInMillis();
320 if (elapsedtime
> starttime
) { /* watch out for millisecond counter
322 elapsedtime
-= starttime
;
327 if (elapsedtime
< duration
) {
328 next
+= duration
- elapsedtime
;
336 XkbDDXAccessXBeep(DeviceIntPtr dev
, unsigned what
, unsigned which
)
338 XkbSrvInfoRec
*xkbInfo
= dev
->key
->xkbInfo
;
341 xkbInfo
->beepType
= what
;
342 xkbInfo
->beepCount
= 0;
343 next
= _XkbDDXBeepExpire(NULL
, 0, (pointer
) dev
);
345 xkbInfo
->beepTimer
= TimerSet(xkbInfo
->beepTimer
,
347 _XkbDDXBeepExpire
, (pointer
) dev
);