Home | History | Annotate | Line # | Download | only in src
      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 (at) omron.co.jp
     25   *				kuwa%omron.co.jp (at) uunet.uu.net
     26   */
     27 
     28 /*
     29 
     30 Copyright 1991, 1998  The Open Group
     31 
     32 Permission to use, copy, modify, distribute, and sell this software and its
     33 documentation for any purpose is hereby granted without fee, provided that
     34 the above copyright notice appear in all copies and that both that
     35 copyright notice and this permission notice appear in supporting
     36 documentation.
     37 
     38 The above copyright notice and this permission notice shall be included
     39 in all copies or substantial portions of the Software.
     40 
     41 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     42 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     43 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     44 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
     45 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     46 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     47 OTHER DEALINGS IN THE SOFTWARE.
     48 
     49 Except as contained in this notice, the name of The Open Group shall
     50 not be used in advertising or otherwise to promote the sale, use or
     51 other dealings in this Software without prior written authorization
     52 from The Open Group.
     53 
     54 */
     55 
     56 #ifdef HAVE_CONFIG_H
     57 #include <config.h>
     58 #else
     59 #define XLOCALE 1
     60 #endif
     61 #include "Xlibint.h"
     62 #if XLOCALE
     63 #include "Xlcint.h"
     64 #endif
     65 
     66 extern long const _Xevent_to_mask[];
     67 
     68 /*
     69  * Look up if there is a specified filter for the event.
     70  */
     71 Bool
     72 XFilterEvent(
     73     XEvent *ev,
     74     Window window)
     75 {
     76 #if XLOCALE
     77     XFilterEventList	p;
     78     Window		win;
     79     long		mask;
     80     Bool		ret;
     81 
     82     if (window)
     83 	win = window;
     84     else
     85 	win = ev->xany.window;
     86     if (ev->type >= LASTEvent)
     87 	mask = 0;
     88     else
     89 	mask = _Xevent_to_mask[ev->type];
     90 
     91     LockDisplay(ev->xany.display);
     92     for (p = ev->xany.display->im_filters; p != NULL; p = p->next) {
     93 	if (win == p->window) {
     94 	    if ((mask & p->event_mask) ||
     95 		(ev->type >= p->start_type && ev->type <= p->end_type)) {
     96 		UnlockDisplay(ev->xany.display);
     97 		ret = (*(p->filter))(ev->xany.display, p->window, ev,
     98 				      p->client_data);
     99 		return(ret);
    100 	    }
    101 	}
    102     }
    103     for (p = ev->xany.display->im_filters; p != NULL; p = p->next) {
    104 	/* Java sometimes calls XFilterEvent() with window=0 and ev come from
    105 	 * XNextEvent() when users type some keys quickly and switch multiple
    106 	 * input focuses in a Java window with the keys.
    107 	 * But XKeyEvent filters need to receive the event with window=0 for
    108 	 * _XimPendingFilter() and _XimUnfabricateSerial() to clear the
    109 	 * fowarded XKeyEvent with XIM_FORWARD_EVENT.
    110 	 *
    111 	 * The case of p->window == 0 is checkekd after all cases of p->window
    112 	 * != 0 are checked because all input contexts share
    113 	 * Display->im_filters but each input context has
    114 	 * Xic->private.proto.registed_filter_event for the filters
    115 	 * and same p->filter could be registerd to Display->im_filters twice
    116 	 * with different p->window.
    117 	 */
    118 	if (p->window == 0 && window == 0) {
    119 	    if ((mask & p->event_mask) ||
    120 		(ev->type >= p->start_type && ev->type <= p->end_type)) {
    121 		UnlockDisplay(ev->xany.display);
    122 		ret = (*(p->filter))(ev->xany.display, p->window, ev,
    123 				      p->client_data);
    124 		return(ret);
    125 	    }
    126 	}
    127     }
    128     UnlockDisplay(ev->xany.display);
    129 #endif
    130     return(False);
    131 }
    132