XChgFCtl.c 5.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/************************************************************

Copyright 1989, 1998  The Open Group

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.

Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.

			All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Hewlett-Packard not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

********************************************************/

/***********************************************************************
 *
 * XChangeFeedbackControl - Change the control attributes of feedbacks on
 * an extension device.
 *
 */

54 55 56 57
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

58 59 60 61 62 63
#include <X11/extensions/XI.h>
#include <X11/extensions/XIproto.h>
#include <X11/Xlibint.h>
#include <X11/extensions/XInput.h>
#include <X11/extensions/extutil.h>
#include "XIint.h"
64 65

int
66 67 68 69 70
XChangeFeedbackControl(
    register Display	*dpy,
    XDevice		*dev,
    unsigned long	 mask,
    XFeedbackControl	*f)
Daniel Stone's avatar
Daniel Stone committed
71
{
72
    int length;
Daniel Stone's avatar
Daniel Stone committed
73 74
    xChangeFeedbackControlReq *req;
    XExtDisplayInfo *info = XInput_find_display(dpy);
75

Daniel Stone's avatar
Daniel Stone committed
76
    LockDisplay(dpy);
77
    if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1)
78 79
	return (NoSuchExtension);

Daniel Stone's avatar
Daniel Stone committed
80
    GetReq(ChangeFeedbackControl, req);
81 82 83 84 85 86
    req->reqType = info->codes->major_opcode;
    req->ReqType = X_ChangeFeedbackControl;
    req->deviceid = dev->device_id;
    req->mask = mask;
    req->feedbackid = f->class;

Daniel Stone's avatar
Daniel Stone committed
87 88 89
    if (f->class == KbdFeedbackClass) {
	XKbdFeedbackControl *K;
	xKbdFeedbackCtl k;
90 91 92

	K = (XKbdFeedbackControl *) f;
	k.class = KbdFeedbackClass;
Daniel Stone's avatar
Daniel Stone committed
93
	k.length = sizeof(xKbdFeedbackCtl);
94 95 96 97 98 99 100 101 102 103 104 105
	k.id = K->id;
	k.click = K->click;
	k.percent = K->percent;
	k.pitch = K->pitch;
	k.duration = K->duration;
	k.led_mask = K->led_mask;
	k.led_values = K->led_value;
	k.key = K->key;
	k.auto_repeat_mode = K->auto_repeat_mode;
	length = ((unsigned)(k.length + 3) >> 2);
	req->length += length;
	length <<= 2;
Daniel Stone's avatar
Daniel Stone committed
106 107 108 109
	Data(dpy, (char *)&k, length);
    } else if (f->class == PtrFeedbackClass) {
	XPtrFeedbackControl *P;
	xPtrFeedbackCtl p;
110 111 112

	P = (XPtrFeedbackControl *) f;
	p.class = PtrFeedbackClass;
Daniel Stone's avatar
Daniel Stone committed
113
	p.length = sizeof(xPtrFeedbackCtl);
114 115 116 117 118 119 120
	p.id = P->id;
	p.num = P->accelNum;
	p.denom = P->accelDenom;
	p.thresh = P->threshold;
	length = ((unsigned)(p.length + 3) >> 2);
	req->length += length;
	length <<= 2;
Daniel Stone's avatar
Daniel Stone committed
121 122 123 124
	Data(dpy, (char *)&p, length);
    } else if (f->class == IntegerFeedbackClass) {
	XIntegerFeedbackControl *I;
	xIntegerFeedbackCtl i;
125 126 127

	I = (XIntegerFeedbackControl *) f;
	i.class = IntegerFeedbackClass;
Daniel Stone's avatar
Daniel Stone committed
128
	i.length = sizeof(xIntegerFeedbackCtl);
129 130 131 132 133
	i.id = I->id;
	i.int_to_display = I->int_to_display;
	length = ((unsigned)(i.length + 3) >> 2);
	req->length += length;
	length <<= 2;
Daniel Stone's avatar
Daniel Stone committed
134 135 136 137
	Data(dpy, (char *)&i, length);
    } else if (f->class == StringFeedbackClass) {
	XStringFeedbackControl *S;
	xStringFeedbackCtl s;
138 139 140

	S = (XStringFeedbackControl *) f;
	s.class = StringFeedbackClass;
Daniel Stone's avatar
Daniel Stone committed
141 142
	s.length = sizeof(xStringFeedbackCtl) +
	    (S->num_keysyms * sizeof(KeySym));
143 144 145
	s.id = S->id;
	s.num_keysyms = S->num_keysyms;
	req->length += ((unsigned)(s.length + 3) >> 2);
Daniel Stone's avatar
Daniel Stone committed
146 147 148 149 150 151 152
	length = sizeof(xStringFeedbackCtl);
	Data(dpy, (char *)&s, length);
	length = (s.num_keysyms * sizeof(KeySym));
	Data(dpy, (char *)S->syms_to_display, length);
    } else if (f->class == BellFeedbackClass) {
	XBellFeedbackControl *B;
	xBellFeedbackCtl b;
153 154 155

	B = (XBellFeedbackControl *) f;
	b.class = BellFeedbackClass;
Daniel Stone's avatar
Daniel Stone committed
156
	b.length = sizeof(xBellFeedbackCtl);
157 158 159 160 161 162 163
	b.id = B->id;
	b.percent = B->percent;
	b.pitch = B->pitch;
	b.duration = B->duration;
	length = ((unsigned)(b.length + 3) >> 2);
	req->length += length;
	length <<= 2;
Daniel Stone's avatar
Daniel Stone committed
164 165 166 167
	Data(dpy, (char *)&b, length);
    } else if (f->class == LedFeedbackClass) {
	XLedFeedbackControl *L;
	xLedFeedbackCtl l;
168 169 170

	L = (XLedFeedbackControl *) f;
	l.class = LedFeedbackClass;
Daniel Stone's avatar
Daniel Stone committed
171
	l.length = sizeof(xLedFeedbackCtl);
172 173 174 175 176 177
	l.id = L->id;
	l.led_mask = L->led_mask;
	l.led_values = L->led_values;
	length = ((unsigned)(l.length + 3) >> 2);
	req->length += length;
	length <<= 2;
Daniel Stone's avatar
Daniel Stone committed
178 179 180
	Data(dpy, (char *)&l, length);
    } else {
	xFeedbackCtl u;
181 182

	u.class = f->class;
Daniel Stone's avatar
Daniel Stone committed
183
	u.length = f->length - sizeof(int);
184 185 186 187
	u.id = f->id;
	length = ((unsigned)(u.length + 3) >> 2);
	req->length += length;
	length <<= 2;
Daniel Stone's avatar
Daniel Stone committed
188 189
	Data(dpy, (char *)&u, length);
    }
190 191 192 193

    UnlockDisplay(dpy);
    SyncHandle();
    return (Success);
Daniel Stone's avatar
Daniel Stone committed
194
}