RegstFlt.c revision d4a3aaf4
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 display->im_filters = NULL; 72} 73 74/* 75 * Register a filter with the filter machinery by event mask. 76 */ 77void 78_XRegisterFilterByMask( 79 Display *display, 80 Window window, 81 unsigned long event_mask, 82 Bool (*filter)( 83 Display*, Window, XEvent*, XPointer 84 ), 85 XPointer client_data) 86{ 87 XFilterEventRec *rec; 88 89 rec = Xmalloc(sizeof(XFilterEventRec)); 90 if (!rec) 91 return; 92 rec->window = window; 93 rec->event_mask = event_mask; 94 rec->start_type = 0; 95 rec->end_type = 0; 96 rec->filter = filter; 97 rec->client_data = client_data; 98 LockDisplay(display); 99 rec->next = display->im_filters; 100 display->im_filters = rec; 101 display->free_funcs->im_filters = _XFreeIMFilters; 102 UnlockDisplay(display); 103} 104 105/* 106 * Register a filter with the filter machinery by type code. 107 */ 108void 109_XRegisterFilterByType( 110 Display *display, 111 Window window, 112 int start_type, 113 int end_type, 114 Bool (*filter)( 115 Display*, Window, XEvent*, XPointer 116 ), 117 XPointer client_data) 118{ 119 XFilterEventRec *rec; 120 121 rec = Xmalloc(sizeof(XFilterEventRec)); 122 if (!rec) 123 return; 124 rec->window = window; 125 rec->event_mask = 0; 126 rec->start_type = start_type; 127 rec->end_type = end_type; 128 rec->filter = filter; 129 rec->client_data = client_data; 130 LockDisplay(display); 131 rec->next = display->im_filters; 132 display->im_filters = rec; 133 display->free_funcs->im_filters = _XFreeIMFilters; 134 UnlockDisplay(display); 135} 136 137void 138_XUnregisterFilter( 139 Display *display, 140 Window window, 141 Bool (*filter)( 142 Display*, Window, XEvent*, XPointer 143 ), 144 XPointer client_data) 145{ 146 register XFilterEventList *prev, fl; 147 148 for (prev = &display->im_filters; (fl = *prev); ) { 149 if (fl->window == window && 150 fl->filter == filter && fl->client_data == client_data) { 151 *prev = fl->next; 152 Xfree(fl); 153 } else 154 prev = &fl->next; 155 } 156} 157