XGtSelect.c revision c43cc173
1/* $Xorg: XGtSelect.c,v 1.4 2001/02/09 02:03:51 xorgcvs Exp $ */
2
3/************************************************************
4
5Copyright 1989, 1998  The Open Group
6
7Permission to use, copy, modify, distribute, and sell this software and its
8documentation for any purpose is hereby granted without fee, provided that
9the above copyright notice appear in all copies and that both that
10copyright notice and this permission notice appear in supporting
11documentation.
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of The Open Group shall not be
24used in advertising or otherwise to promote the sale, use or other dealings
25in this Software without prior written authorization from The Open Group.
26
27Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
28
29			All Rights Reserved
30
31Permission to use, copy, modify, and distribute this software and its
32documentation for any purpose and without fee is hereby granted,
33provided that the above copyright notice appear in all copies and that
34both that copyright notice and this permission notice appear in
35supporting documentation, and that the name of Hewlett-Packard not be
36used in advertising or publicity pertaining to distribution of the
37software without specific, written prior permission.
38
39HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45SOFTWARE.
46
47********************************************************/
48/* $XFree86: xc/lib/Xi/XGtSelect.c,v 3.3 2001/12/14 19:55:19 dawes Exp $ */
49
50/***********************************************************************
51 *
52 * XGetSelectedExtensionEvents - return a list of currently selected events.
53 *
54 */
55
56#include <X11/extensions/XI.h>
57#include <X11/extensions/XIproto.h>
58#include <X11/Xlibint.h>
59#include <X11/extensions/XInput.h>
60#include <X11/extensions/extutil.h>
61#include "XIint.h"
62
63int
64XGetSelectedExtensionEvents(dpy, w, this_client_count, this_client_list,
65			    all_clients_count, all_clients_list)
66    register Display *dpy;
67    Window w;
68    int *this_client_count;
69    XEventClass **this_client_list;
70    int *all_clients_count;
71    XEventClass **all_clients_list;
72{
73    int tlen, alen;
74    register xGetSelectedExtensionEventsReq *req;
75    xGetSelectedExtensionEventsReply rep;
76    XExtDisplayInfo *info = XInput_find_display(dpy);
77
78    LockDisplay(dpy);
79    if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1)
80	return (NoSuchExtension);
81    GetReq(GetSelectedExtensionEvents, req);
82
83    req->reqType = info->codes->major_opcode;
84    req->ReqType = X_GetSelectedExtensionEvents;
85    req->window = w;
86
87    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
88	UnlockDisplay(dpy);
89	SyncHandle();
90	return Success;
91    }
92
93    *this_client_count = rep.this_client_count;
94    *all_clients_count = rep.all_clients_count;
95
96    if (rep.length) {
97	int i;
98	CARD32 ec;
99
100	tlen = (*this_client_count) * sizeof(CARD32);
101	alen = (rep.length << 2) - tlen;
102
103	if (tlen) {
104	    *this_client_list =
105		(XEventClass *) Xmalloc(*this_client_count *
106					sizeof(XEventClass));
107	    if (!*this_client_list) {
108		_XEatData(dpy, (unsigned long)tlen + alen);
109                UnlockDisplay(dpy);
110                SyncHandle();
111		return (Success);
112	    }
113	    for (i = 0; i < *this_client_count; i++) {
114		_XRead(dpy, (char *)(&ec), sizeof(CARD32));
115		(*this_client_list)[i] = (XEventClass) ec;
116	    }
117	} else
118	    *this_client_list = (XEventClass *) NULL;
119	if (alen) {
120	    *all_clients_list =
121		(XEventClass *) Xmalloc(*all_clients_count *
122					sizeof(XEventClass));
123	    if (!*all_clients_list) {
124		Xfree((char *)*this_client_list);
125		*this_client_list = NULL;
126		_XEatData(dpy, (unsigned long)alen);
127                UnlockDisplay(dpy);
128                SyncHandle();
129		return (Success);
130	    }
131	    for (i = 0; i < *all_clients_count; i++) {
132		_XRead(dpy, (char *)(&ec), sizeof(CARD32));
133		(*all_clients_list)[i] = (XEventClass) ec;
134	    }
135	} else
136	    *all_clients_list = (XEventClass *) NULL;
137
138    }
139
140    UnlockDisplay(dpy);
141    SyncHandle();
142    return (Success);
143}
144