XChgFCtl.c revision c43cc173
1c43cc173Smrg/* $Xorg: XChgFCtl.c,v 1.4 2001/02/09 02:03:50 xorgcvs Exp $ */
2c43cc173Smrg
3c43cc173Smrg/************************************************************
4c43cc173Smrg
5c43cc173SmrgCopyright 1989, 1998  The Open Group
6c43cc173Smrg
7c43cc173SmrgPermission to use, copy, modify, distribute, and sell this software and its
8c43cc173Smrgdocumentation for any purpose is hereby granted without fee, provided that
9c43cc173Smrgthe above copyright notice appear in all copies and that both that
10c43cc173Smrgcopyright notice and this permission notice appear in supporting
11c43cc173Smrgdocumentation.
12c43cc173Smrg
13c43cc173SmrgThe above copyright notice and this permission notice shall be included in
14c43cc173Smrgall copies or substantial portions of the Software.
15c43cc173Smrg
16c43cc173SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17c43cc173SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18c43cc173SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19c43cc173SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20c43cc173SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21c43cc173SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22c43cc173Smrg
23c43cc173SmrgExcept as contained in this notice, the name of The Open Group shall not be
24c43cc173Smrgused in advertising or otherwise to promote the sale, use or other dealings
25c43cc173Smrgin this Software without prior written authorization from The Open Group.
26c43cc173Smrg
27c43cc173SmrgCopyright 1989 by Hewlett-Packard Company, Palo Alto, California.
28c43cc173Smrg
29c43cc173Smrg			All Rights Reserved
30c43cc173Smrg
31c43cc173SmrgPermission to use, copy, modify, and distribute this software and its
32c43cc173Smrgdocumentation for any purpose and without fee is hereby granted,
33c43cc173Smrgprovided that the above copyright notice appear in all copies and that
34c43cc173Smrgboth that copyright notice and this permission notice appear in
35c43cc173Smrgsupporting documentation, and that the name of Hewlett-Packard not be
36c43cc173Smrgused in advertising or publicity pertaining to distribution of the
37c43cc173Smrgsoftware without specific, written prior permission.
38c43cc173Smrg
39c43cc173SmrgHEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40c43cc173SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41c43cc173SmrgHEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42c43cc173SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43c43cc173SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44c43cc173SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45c43cc173SmrgSOFTWARE.
46c43cc173Smrg
47c43cc173Smrg********************************************************/
48c43cc173Smrg/* $XFree86: xc/lib/Xi/XChgFCtl.c,v 3.3 2001/12/14 19:55:03 dawes Exp $ */
49c43cc173Smrg
50c43cc173Smrg/***********************************************************************
51c43cc173Smrg *
52c43cc173Smrg * XChangeFeedbackControl - Change the control attributes of feedbacks on
53c43cc173Smrg * an extension device.
54c43cc173Smrg *
55c43cc173Smrg */
56c43cc173Smrg
57c43cc173Smrg#include <X11/extensions/XI.h>
58c43cc173Smrg#include <X11/extensions/XIproto.h>
59c43cc173Smrg#include <X11/Xlibint.h>
60c43cc173Smrg#include <X11/extensions/XInput.h>
61c43cc173Smrg#include <X11/extensions/extutil.h>
62c43cc173Smrg#include "XIint.h"
63c43cc173Smrg
64c43cc173Smrgint
65c43cc173SmrgXChangeFeedbackControl(dpy, dev, mask, f)
66c43cc173Smrg    register Display *dpy;
67c43cc173Smrg    XDevice *dev;
68c43cc173Smrg    unsigned long mask;
69c43cc173Smrg    XFeedbackControl *f;
70c43cc173Smrg{
71c43cc173Smrg    int length;
72c43cc173Smrg    xChangeFeedbackControlReq *req;
73c43cc173Smrg    XExtDisplayInfo *info = XInput_find_display(dpy);
74c43cc173Smrg
75c43cc173Smrg    LockDisplay(dpy);
76c43cc173Smrg    if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1)
77c43cc173Smrg	return (NoSuchExtension);
78c43cc173Smrg
79c43cc173Smrg    GetReq(ChangeFeedbackControl, req);
80c43cc173Smrg    req->reqType = info->codes->major_opcode;
81c43cc173Smrg    req->ReqType = X_ChangeFeedbackControl;
82c43cc173Smrg    req->deviceid = dev->device_id;
83c43cc173Smrg    req->mask = mask;
84c43cc173Smrg    req->feedbackid = f->class;
85c43cc173Smrg
86c43cc173Smrg    if (f->class == KbdFeedbackClass) {
87c43cc173Smrg	XKbdFeedbackControl *K;
88c43cc173Smrg	xKbdFeedbackCtl k;
89c43cc173Smrg
90c43cc173Smrg	K = (XKbdFeedbackControl *) f;
91c43cc173Smrg	k.class = KbdFeedbackClass;
92c43cc173Smrg	k.length = sizeof(xKbdFeedbackCtl);
93c43cc173Smrg	k.id = K->id;
94c43cc173Smrg	k.click = K->click;
95c43cc173Smrg	k.percent = K->percent;
96c43cc173Smrg	k.pitch = K->pitch;
97c43cc173Smrg	k.duration = K->duration;
98c43cc173Smrg	k.led_mask = K->led_mask;
99c43cc173Smrg	k.led_values = K->led_value;
100c43cc173Smrg	k.key = K->key;
101c43cc173Smrg	k.auto_repeat_mode = K->auto_repeat_mode;
102c43cc173Smrg	length = ((unsigned)(k.length + 3) >> 2);
103c43cc173Smrg	req->length += length;
104c43cc173Smrg	length <<= 2;
105c43cc173Smrg	Data(dpy, (char *)&k, length);
106c43cc173Smrg    } else if (f->class == PtrFeedbackClass) {
107c43cc173Smrg	XPtrFeedbackControl *P;
108c43cc173Smrg	xPtrFeedbackCtl p;
109c43cc173Smrg
110c43cc173Smrg	P = (XPtrFeedbackControl *) f;
111c43cc173Smrg	p.class = PtrFeedbackClass;
112c43cc173Smrg	p.length = sizeof(xPtrFeedbackCtl);
113c43cc173Smrg	p.id = P->id;
114c43cc173Smrg	p.num = P->accelNum;
115c43cc173Smrg	p.denom = P->accelDenom;
116c43cc173Smrg	p.thresh = P->threshold;
117c43cc173Smrg	length = ((unsigned)(p.length + 3) >> 2);
118c43cc173Smrg	req->length += length;
119c43cc173Smrg	length <<= 2;
120c43cc173Smrg	Data(dpy, (char *)&p, length);
121c43cc173Smrg    } else if (f->class == IntegerFeedbackClass) {
122c43cc173Smrg	XIntegerFeedbackControl *I;
123c43cc173Smrg	xIntegerFeedbackCtl i;
124c43cc173Smrg
125c43cc173Smrg	I = (XIntegerFeedbackControl *) f;
126c43cc173Smrg	i.class = IntegerFeedbackClass;
127c43cc173Smrg	i.length = sizeof(xIntegerFeedbackCtl);
128c43cc173Smrg	i.id = I->id;
129c43cc173Smrg	i.int_to_display = I->int_to_display;
130c43cc173Smrg	length = ((unsigned)(i.length + 3) >> 2);
131c43cc173Smrg	req->length += length;
132c43cc173Smrg	length <<= 2;
133c43cc173Smrg	Data(dpy, (char *)&i, length);
134c43cc173Smrg    } else if (f->class == StringFeedbackClass) {
135c43cc173Smrg	XStringFeedbackControl *S;
136c43cc173Smrg	xStringFeedbackCtl s;
137c43cc173Smrg
138c43cc173Smrg	S = (XStringFeedbackControl *) f;
139c43cc173Smrg	s.class = StringFeedbackClass;
140c43cc173Smrg	s.length = sizeof(xStringFeedbackCtl) +
141c43cc173Smrg	    (S->num_keysyms * sizeof(KeySym));
142c43cc173Smrg	s.id = S->id;
143c43cc173Smrg	s.num_keysyms = S->num_keysyms;
144c43cc173Smrg	req->length += ((unsigned)(s.length + 3) >> 2);
145c43cc173Smrg	length = sizeof(xStringFeedbackCtl);
146c43cc173Smrg	Data(dpy, (char *)&s, length);
147c43cc173Smrg	length = (s.num_keysyms * sizeof(KeySym));
148c43cc173Smrg	Data(dpy, (char *)S->syms_to_display, length);
149c43cc173Smrg    } else if (f->class == BellFeedbackClass) {
150c43cc173Smrg	XBellFeedbackControl *B;
151c43cc173Smrg	xBellFeedbackCtl b;
152c43cc173Smrg
153c43cc173Smrg	B = (XBellFeedbackControl *) f;
154c43cc173Smrg	b.class = BellFeedbackClass;
155c43cc173Smrg	b.length = sizeof(xBellFeedbackCtl);
156c43cc173Smrg	b.id = B->id;
157c43cc173Smrg	b.percent = B->percent;
158c43cc173Smrg	b.pitch = B->pitch;
159c43cc173Smrg	b.duration = B->duration;
160c43cc173Smrg	length = ((unsigned)(b.length + 3) >> 2);
161c43cc173Smrg	req->length += length;
162c43cc173Smrg	length <<= 2;
163c43cc173Smrg	Data(dpy, (char *)&b, length);
164c43cc173Smrg    } else if (f->class == LedFeedbackClass) {
165c43cc173Smrg	XLedFeedbackControl *L;
166c43cc173Smrg	xLedFeedbackCtl l;
167c43cc173Smrg
168c43cc173Smrg	L = (XLedFeedbackControl *) f;
169c43cc173Smrg	l.class = LedFeedbackClass;
170c43cc173Smrg	l.length = sizeof(xLedFeedbackCtl);
171c43cc173Smrg	l.id = L->id;
172c43cc173Smrg	l.led_mask = L->led_mask;
173c43cc173Smrg	l.led_values = L->led_values;
174c43cc173Smrg	length = ((unsigned)(l.length + 3) >> 2);
175c43cc173Smrg	req->length += length;
176c43cc173Smrg	length <<= 2;
177c43cc173Smrg	Data(dpy, (char *)&l, length);
178c43cc173Smrg    } else {
179c43cc173Smrg	xFeedbackCtl u;
180c43cc173Smrg
181c43cc173Smrg	u.class = f->class;
182c43cc173Smrg	u.length = f->length - sizeof(int);
183c43cc173Smrg	u.id = f->id;
184c43cc173Smrg	length = ((unsigned)(u.length + 3) >> 2);
185c43cc173Smrg	req->length += length;
186c43cc173Smrg	length <<= 2;
187c43cc173Smrg	Data(dpy, (char *)&u, length);
188c43cc173Smrg    }
189c43cc173Smrg
190c43cc173Smrg    UnlockDisplay(dpy);
191c43cc173Smrg    SyncHandle();
192c43cc173Smrg    return (Success);
193c43cc173Smrg}
194