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