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