XKBBell.c revision 1ab64890
1/* $Xorg: XKBBell.c,v 1.3 2000/08/17 19:45:00 cpqbld Exp $ */
2/************************************************************
3Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4
5Permission to use, copy, modify, and distribute this
6software and its documentation for any purpose and without
7fee is hereby granted, provided that the above copyright
8notice appear in all copies and that both that copyright
9notice and this permission notice appear in supporting
10documentation, and that the name of Silicon Graphics not be
11used in advertising or publicity pertaining to distribution
12of the software without specific prior written permission.
13Silicon Graphics makes no representation about the suitability
14of this software for any purpose. It is provided "as is"
15without any express or implied warranty.
16
17SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
18SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
20GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
21DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
23OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
24THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
26********************************************************/
27/* $XFree86$ */
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32#include <stdio.h>
33#define NEED_REPLIES
34#define NEED_EVENTS
35#include "Xlibint.h"
36#include <X11/extensions/XKBproto.h>
37#include "XKBlibint.h"
38
39
40Bool
41XkbDeviceBell(	Display *	dpy,
42		Window 		window,
43		int 		deviceID,
44		int 		bellClass,
45		int 		bellID,
46		int 		percent,
47		Atom 		name)
48{
49    register xkbBellReq *req;
50    XkbInfoPtr xkbi;
51
52    if ((dpy->flags & XlibDisplayNoXkb) ||
53	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
54	return False;
55    LockDisplay(dpy);
56    xkbi = dpy->xkb_info;
57    GetReq(kbBell,req);
58    req->reqType = xkbi->codes->major_opcode;
59    req->xkbReqType = X_kbBell;
60    req->deviceSpec = deviceID;
61    req->window = (CARD32)window;
62    req->bellClass = (CARD16)bellClass;
63    req->bellID = (CARD16)bellID;
64    req->percent = percent;
65    req->forceSound = False;
66    req->eventOnly = False;
67    req->pitch = 0;
68    req->duration = 0;
69    req->name = (CARD32)name;
70    req->pad1= 0; req->pad2= 0;
71    UnlockDisplay(dpy);
72    SyncHandle();
73    return True;
74}
75
76Bool
77XkbForceDeviceBell(	Display *	dpy,
78			int 		deviceID,
79			int 		bellClass,
80			int 		bellID,
81			int 		percent)
82{
83    register xkbBellReq *req;
84    XkbInfoPtr xkbi;
85
86    if ((dpy->flags & XlibDisplayNoXkb) ||
87	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
88	return False;
89    LockDisplay(dpy);
90    xkbi = dpy->xkb_info;
91    GetReq(kbBell,req);
92    req->reqType = xkbi->codes->major_opcode;
93    req->xkbReqType = X_kbBell;
94    req->deviceSpec = deviceID;
95    req->window = (CARD32)None;
96    req->bellClass = (CARD16)bellClass;
97    req->bellID = (CARD16)bellID;
98    req->percent = percent;
99    req->forceSound = True;
100    req->eventOnly = False;
101    req->pitch = 0;
102    req->duration = 0;
103    req->name = None;
104    req->pad1= 0; req->pad2= 0;
105    UnlockDisplay(dpy);
106    SyncHandle();
107    return True;
108}
109
110Bool
111XkbDeviceBellEvent(	Display *	dpy,
112			Window 		window,
113			int		deviceID,
114			int		bellClass,
115			int		bellID,
116			int		percent,
117			Atom 		name)
118{
119    register xkbBellReq *req;
120    XkbInfoPtr xkbi;
121
122    if ((dpy->flags & XlibDisplayNoXkb) ||
123	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
124	return False;
125    LockDisplay(dpy);
126    xkbi = dpy->xkb_info;
127    GetReq(kbBell,req);
128    req->reqType = xkbi->codes->major_opcode;
129    req->xkbReqType = X_kbBell;
130    req->deviceSpec = deviceID;
131    req->window = (CARD32)window;
132    req->bellClass = (CARD16)bellClass;
133    req->bellID = (CARD16)bellID;
134    req->percent = percent;
135    req->forceSound = False;
136    req->eventOnly = True;
137    req->pitch = 0;
138    req->duration = 0;
139    req->name = (CARD32)name;
140    req->pad1= 0; req->pad2= 0;
141    UnlockDisplay(dpy);
142    SyncHandle();
143    return True;
144}
145
146Bool
147XkbBell(Display *dpy,Window window,int percent,Atom name)
148{
149    if ((dpy->flags & XlibDisplayNoXkb) ||
150	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
151	XBell(dpy,percent);
152	return False;
153    }
154    return XkbDeviceBell(dpy,window,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId,
155								percent,name);
156}
157
158Bool
159XkbForceBell(Display *dpy,int percent)
160{
161    if ((dpy->flags & XlibDisplayNoXkb) ||
162	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
163	XBell(dpy,percent);
164	return False;
165    }
166    return XkbForceDeviceBell(dpy,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId,
167								percent);
168}
169
170Bool
171XkbBellEvent(Display *dpy,Window window,int percent,Atom name)
172{
173    if ((dpy->flags & XlibDisplayNoXkb) ||
174	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) {
175	return False;
176    }
177    /* class 0 = KbdFeedbackClass (X Input Extension) */
178    return XkbDeviceBellEvent(dpy,window,XkbUseCoreKbd,
179					XkbDfltXIClass,XkbDfltXIId,
180					percent,name);
181}
182
183