RegstFlt.c revision 1ab64890
1/* $Xorg: RegstFlt.c,v 1.5 2001/02/09 02:03:35 xorgcvs Exp $ */
2
3 /*
4  * Copyright 1990, 1991 by OMRON Corporation
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name OMRON not be used in
11  * advertising or publicity pertaining to distribution of the software without
12  * specific, written prior permission.  OMRON makes no representations
13  * about the suitability of this software for any purpose.  It is provided
14  * "as is" without express or implied warranty.
15  *
16  * OMRON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18  * EVENT SHALL OMRON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21  * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22  * PERFORMANCE OF THIS SOFTWARE.
23  *
24  *	Author:	Seiji Kuwari	OMRON Corporation
25  *				kuwa@omron.co.jp
26  *				kuwa%omron.co.jp@uunet.uu.net
27  */
28/*
29
30Copyright 1990, 1991, 1998  The Open Group
31
32Permission to use, copy, modify, distribute, and sell this software and its
33documentation for any purpose is hereby granted without fee, provided that
34the above copyright notice appear in all copies and that both that
35copyright notice and this permission notice appear in supporting
36documentation.
37
38The above copyright notice and this permission notice shall be included
39in all copies or substantial portions of the Software.
40
41THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
42OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
45OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
46ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
47OTHER DEALINGS IN THE SOFTWARE.
48
49Except as contained in this notice, the name of The Open Group shall
50not be used in advertising or otherwise to promote the sale, use or
51other dealings in this Software without prior written authorization
52from The Open Group.
53
54*/
55/* $XFree86: xc/lib/X11/RegstFlt.c,v 1.5 2003/04/13 19:22:17 dawes Exp $ */
56
57#ifdef HAVE_CONFIG_H
58#include <config.h>
59#endif
60#include "Xlibint.h"
61#include "Xlcint.h"
62
63static void
64_XFreeIMFilters(
65    Display *display)
66{
67    register XFilterEventList fl;
68
69    while ((fl = display->im_filters)) {
70        display->im_filters = fl->next;
71        Xfree((char *)fl);
72    }
73}
74
75/*
76 * Register a filter with the filter machinery by event mask.
77 */
78void
79_XRegisterFilterByMask(
80    Display *display,
81    Window window,
82    unsigned long event_mask,
83    Bool (*filter)(
84		   Display*, Window, XEvent*, XPointer
85		   ),
86    XPointer client_data)
87{
88    XFilterEventRec		*rec;
89
90    rec = (XFilterEventList)Xmalloc(sizeof(XFilterEventRec));
91    if (!rec)
92	return;
93    rec->window = window;
94    rec->event_mask = event_mask;
95    rec->start_type = 0;
96    rec->end_type = 0;
97    rec->filter = filter;
98    rec->client_data = client_data;
99    LockDisplay(display);
100    rec->next = display->im_filters;
101    display->im_filters = rec;
102    display->free_funcs->im_filters = _XFreeIMFilters;
103    UnlockDisplay(display);
104}
105
106/*
107 * Register a filter with the filter machinery by type code.
108 */
109void
110_XRegisterFilterByType(
111    Display *display,
112    Window window,
113    int start_type,
114    int end_type,
115    Bool (*filter)(
116		   Display*, Window, XEvent*, XPointer
117		   ),
118    XPointer client_data)
119{
120    XFilterEventRec		*rec;
121
122    rec = (XFilterEventList)Xmalloc(sizeof(XFilterEventRec));
123    if (!rec)
124	return;
125    rec->window = window;
126    rec->event_mask = 0;
127    rec->start_type = start_type;
128    rec->end_type = end_type;
129    rec->filter = filter;
130    rec->client_data = client_data;
131    LockDisplay(display);
132    rec->next = display->im_filters;
133    display->im_filters = rec;
134    display->free_funcs->im_filters = _XFreeIMFilters;
135    UnlockDisplay(display);
136}
137
138void
139_XUnregisterFilter(
140    Display *display,
141    Window window,
142    Bool (*filter)(
143		   Display*, Window, XEvent*, XPointer
144		   ),
145    XPointer client_data)
146{
147    register XFilterEventList	*prev, fl;
148
149    for (prev = &display->im_filters; (fl = *prev); ) {
150	if (fl->window == window &&
151	    fl->filter == filter && fl->client_data == client_data) {
152	    *prev = fl->next;
153	    Xfree((char *)fl);
154	} else
155	    prev = &fl->next;
156    }
157}
158