Imported Upstream version 1.15.1
[deb_xorg-server.git] / Xi / getprop.c
CommitLineData
a09e091a
JB
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 * Function to return the dont-propagate-list for an extension device.
50 *
51 */
52
53#ifdef HAVE_DIX_CONFIG_H
54#include <dix-config.h>
55#endif
56
57#include "inputstr.h" /* DeviceIntPtr */
58#include "windowstr.h" /* window structs */
59#include <X11/extensions/XI.h>
60#include <X11/extensions/XIproto.h>
61#include "exglobals.h"
62#include "swaprep.h"
63
64#include "getprop.h"
65
66extern XExtEventInfo EventInfo[];
67extern int ExtEventIndex;
68
69/***********************************************************************
70 *
71 * Handle a request from a client with a different byte order.
72 *
73 */
74
75int
76SProcXGetDeviceDontPropagateList(ClientPtr client)
77{
78 REQUEST(xGetDeviceDontPropagateListReq);
79 swaps(&stuff->length);
80 REQUEST_SIZE_MATCH(xGetDeviceDontPropagateListReq);
81 swapl(&stuff->window);
82 return (ProcXGetDeviceDontPropagateList(client));
83}
84
85/***********************************************************************
86 *
87 * This procedure lists the input devices available to the server.
88 *
89 */
90
91int
92ProcXGetDeviceDontPropagateList(ClientPtr client)
93{
94 CARD16 count = 0;
95 int i, rc;
96 XEventClass *buf = NULL, *tbuf;
97 WindowPtr pWin;
98 xGetDeviceDontPropagateListReply rep;
99 OtherInputMasks *others;
100
101 REQUEST(xGetDeviceDontPropagateListReq);
102 REQUEST_SIZE_MATCH(xGetDeviceDontPropagateListReq);
103
104 rep = (xGetDeviceDontPropagateListReply) {
105 .repType = X_Reply,
106 .RepType = X_GetDeviceDontPropagateList,
107 .sequenceNumber = client->sequence,
108 .length = 0,
109 .count = 0
110 };
111
112 rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
113 if (rc != Success)
114 return rc;
115
116 if ((others = wOtherInputMasks(pWin)) != 0) {
117 for (i = 0; i < EMASKSIZE; i++)
118 ClassFromMask(NULL, others->dontPropagateMask[i], i, &count, COUNT);
119 if (count) {
120 rep.count = count;
121 buf = (XEventClass *) malloc(rep.count * sizeof(XEventClass));
122 rep.length = bytes_to_int32(rep.count * sizeof(XEventClass));
123
124 tbuf = buf;
125 for (i = 0; i < EMASKSIZE; i++)
126 tbuf = ClassFromMask(tbuf, others->dontPropagateMask[i], i,
127 NULL, CREATE);
128 }
129 }
130
131 WriteReplyToClient(client, sizeof(xGetDeviceDontPropagateListReply), &rep);
132
133 if (count) {
134 client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
135 WriteSwappedDataToClient(client, count * sizeof(XEventClass), buf);
136 free(buf);
137 }
138 return Success;
139}
140
141/***********************************************************************
142 *
143 * This procedure gets a list of event classes from a mask word.
144 * A single mask may translate to more than one event class.
145 *
146 */
147
148XEventClass
149 * ClassFromMask(XEventClass * buf, Mask mask, int maskndx, CARD16 *count,
150 int mode)
151{
152 int i, j;
153 int id = maskndx;
154 Mask tmask = 0x80000000;
155
156 for (i = 0; i < 32; i++, tmask >>= 1)
157 if (tmask & mask) {
158 for (j = 0; j < ExtEventIndex; j++)
159 if (EventInfo[j].mask == tmask) {
160 if (mode == COUNT)
161 (*count)++;
162 else
163 *buf++ = (id << 8) | EventInfo[j].type;
164 }
165 }
166 return buf;
167}
168
169/***********************************************************************
170 *
171 * This procedure writes the reply for the XGetDeviceDontPropagateList function,
172 * if the client and server have a different byte ordering.
173 *
174 */
175
176void
177SRepXGetDeviceDontPropagateList(ClientPtr client, int size,
178 xGetDeviceDontPropagateListReply * rep)
179{
180 swaps(&rep->sequenceNumber);
181 swapl(&rep->length);
182 swaps(&rep->count);
183 WriteToClient(client, size, rep);
184}