xref: /OK3568_Linux_fs/external/xserver/Xi/getprop.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /************************************************************
2 
3 Copyright 1989, 1998  The Open Group
4 
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24 
25 Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
26 
27 			All Rights Reserved
28 
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Hewlett-Packard not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
36 
37 HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43 SOFTWARE.
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 
66 extern XExtEventInfo EventInfo[];
67 extern int ExtEventIndex;
68 
69 /***********************************************************************
70  *
71  * Handle a request from a client with a different byte order.
72  *
73  */
74 
75 int _X_COLD
SProcXGetDeviceDontPropagateList(ClientPtr client)76 SProcXGetDeviceDontPropagateList(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 
91 int
ProcXGetDeviceDontPropagateList(ClientPtr client)92 ProcXGetDeviceDontPropagateList(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 = xallocarray(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 
148 XEventClass
ClassFromMask(XEventClass * buf,Mask mask,int maskndx,CARD16 * count,int mode)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 
176 void _X_COLD
SRepXGetDeviceDontPropagateList(ClientPtr client,int size,xGetDeviceDontPropagateListReply * rep)177 SRepXGetDeviceDontPropagateList(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 }
185