1 /* Defines a function to find the Widget that XtDispatchEvent() would use.
2 Copyright (C) 1992 Lucid, Inc.
4 This file is part of the Lucid Widget Library.
6 The Lucid Widget Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 The Lucid Widget Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 * The function XtWidgetToDispatchTo(), given an XEvent, returns the
22 * widget that XtDispatchEvent() would send that event to if called now.
23 * This file copies much code from the X11r4 Xt source, and is thus a
24 * portability problem. It also requires data structures defined in
25 * IntrinsicI.h, which is a non-exported Xt header file, so you can't
26 * compile this file unless you have the Xt sources online.
29 #include <IntrinsicI.h> /* Don't change this: see comments in Imakefile. */
30 #include <X11/Xatom.h>
34 #include <X11/cursorfont.h>
35 #include <X11/Xutil.h>
37 #ifdef XlibSpecificationRelease
38 #if XlibSpecificationRelease >= 5
43 /* ## All of the code on this page was copied from the X11R5 lib/Xt/Event.c,
44 ## but is compatible with X11R4; the code in Event.c is different, but
45 ## functionally equivalent for our purposes.
54 #define NonMaskableMask ((EventMask)0x80000000L)
56 #define COMP_EXPOSE (widget->core.widget_class->core_class.compress_exposure)
57 #define COMP_EXPOSE_TYPE (COMP_EXPOSE & 0x0f)
58 #define GRAPHICS_EXPOSE ((XtExposeGraphicsExpose & COMP_EXPOSE) || \
59 (XtExposeGraphicsExposeMerged & COMP_EXPOSE))
60 #define NO_EXPOSE (XtExposeNoExpose & COMP_EXPOSE)
63 /* -- lots of stuff we don't need to copy, omitted -- */
66 static EventMask Const masks
[] = {
67 0, /* Error, should never see */
68 0, /* Reply, should never see */
69 KeyPressMask
, /* KeyPress */
70 KeyReleaseMask
, /* KeyRelease */
71 ButtonPressMask
, /* ButtonPress */
72 ButtonReleaseMask
, /* ButtonRelease */
73 PointerMotionMask
/* MotionNotify */
75 EnterWindowMask
, /* EnterNotify */
76 LeaveWindowMask
, /* LeaveNotify */
77 FocusChangeMask
, /* FocusIn */
78 FocusChangeMask
, /* FocusOut */
79 KeymapStateMask
, /* KeymapNotify */
80 ExposureMask
, /* Expose */
81 NonMaskableMask
, /* GraphicsExpose, in GC */
82 NonMaskableMask
, /* NoExpose, in GC */
83 VisibilityChangeMask
, /* VisibilityNotify */
84 SubstructureNotifyMask
, /* CreateNotify */
85 StructureNotifyMask
/* DestroyNotify */
86 | SubstructureNotifyMask
,
87 StructureNotifyMask
/* UnmapNotify */
88 | SubstructureNotifyMask
,
89 StructureNotifyMask
/* MapNotify */
90 | SubstructureNotifyMask
,
91 SubstructureRedirectMask
, /* MapRequest */
92 StructureNotifyMask
/* ReparentNotify */
93 | SubstructureNotifyMask
,
94 StructureNotifyMask
/* ConfigureNotify */
95 | SubstructureNotifyMask
,
96 SubstructureRedirectMask
, /* ConfigureRequest */
97 StructureNotifyMask
/* GravityNotify */
98 | SubstructureNotifyMask
,
99 ResizeRedirectMask
, /* ResizeRequest */
100 StructureNotifyMask
/* CirculateNotify */
101 | SubstructureNotifyMask
,
102 SubstructureRedirectMask
, /* CirculateRequest */
103 PropertyChangeMask
, /* PropertyNotify */
104 NonMaskableMask
, /* SelectionClear */
105 NonMaskableMask
, /* SelectionRequest */
106 NonMaskableMask
, /* SelectionNotify */
107 ColormapChangeMask
, /* ColormapNotify */
108 NonMaskableMask
, /* ClientMessage */
109 NonMaskableMask
/* MappingNotify */
114 static /* in R5, this is not static, so we don't need to define it at all */
115 EventMask
_XtConvertTypeToMask (eventType
)
118 eventType
&= 0x7f; /* Events sent with XSendEvent have high bit set. */
119 if (eventType
< XtNumber(masks
))
120 return masks
[eventType
];
125 #endif /* not HAVE_X11R5 */
127 /* -- _XtOnGrabList() omitted -- */
130 static Widget
LookupSpringLoaded(grabList
)
135 for (gl
= grabList
; gl
!= NULL
; gl
= gl
->next
) {
136 if (gl
->spring_loaded
)
137 if (XtIsSensitive(gl
->widget
))
141 if (gl
->exclusive
) break;
148 /* This function is new. */
150 static Boolean
WouldDispatchEvent(event
, widget
, mask
, pd
)
151 register XEvent
*event
;
157 Boolean would_dispatched
= False
;
159 if ((mask
== ExposureMask
) ||
160 ((event
->type
== NoExpose
) && NO_EXPOSE
) ||
161 ((event
->type
== GraphicsExpose
) && GRAPHICS_EXPOSE
) )
162 if (widget
->core
.widget_class
->core_class
.expose
!= NULL
)
166 if ((mask
== VisibilityChangeMask
) &&
167 XtClass(widget
)->core_class
.visible_interest
)
170 for (p
=widget
->core
.event_table
; p
!= NULL
; p
= p
->next
)
171 if ((mask
& p
->mask
) != 0
173 || (mask
== 0 && p
->non_filter
)
182 /* #### This function is mostly copied from DecideToDispatch().
185 typedef enum _GrabType
{pass
, ignore
, remap
} GrabType
;
188 XtWidgetToDispatchTo (XEvent
* event
)
190 register Widget widget
;
196 XtPerDisplayInput pdi
;
199 widget
= XtWindowToWidget (event
->xany
.display
, event
->xany
.window
);
200 pd
= _XtGetPerDisplay(event
->xany
.display
);
201 pdi
= _XtGetPerDisplayInput(event
->xany
.display
);
202 grabList
= *_XtGetGrabList(pdi
);
204 mask
= _XtConvertTypeToMask(event
->xany
.type
);
206 switch (event
->xany
.type
& 0x7f) {
208 case KeyRelease
: grabType
= remap
; break;
210 case ButtonRelease
: grabType
= remap
; break;
211 case MotionNotify
: grabType
= ignore
;
212 #define XKnownButtons (Button1MotionMask|Button2MotionMask|Button3MotionMask|\
213 Button4MotionMask|Button5MotionMask)
214 mask
|= (event
->xmotion
.state
& XKnownButtons
);
217 case EnterNotify
: grabType
= ignore
; break;
220 if (widget
== NULL
) {
221 if (grabType
!= remap
) return False
;
222 /* event occurred in a non-widget window, but we've promised also
223 to dispatch it to the nearest accessible spring_loaded widget */
224 else if ((widget
= LookupSpringLoaded(grabList
)) != NULL
)
234 if ((grabList
== NULL
|| _XtOnGrabList(widget
,grabList
))
235 && XtIsSensitive(widget
)) {
243 Widget was_dispatched_to
= NULL
;
244 extern Widget
_XtFindRemapWidget();
245 extern void _XtUngrabBadGrabs();
247 dspWidget
= _XtFindRemapWidget(event
, widget
, mask
, pdi
);
249 if ((grabList
== NULL
||
250 _XtOnGrabList(dspWidget
, grabList
)) &&
251 XtIsSensitive(dspWidget
)) {
252 if (WouldDispatchEvent (event
, dspWidget
, mask
, pd
))
253 was_dispatched_to
= dspWidget
;
256 /* Also dispatch to nearest accessible spring_loaded. */
257 /* Fetch this afterward to reflect modal list changes */
258 grabList
= *_XtGetGrabList(pdi
);
259 widget
= LookupSpringLoaded(grabList
);
260 if (widget
!= NULL
&& widget
!= dspWidget
) {
261 if (!was_dispatched_to
)
262 was_dispatched_to
= widget
;
265 return was_dispatched_to
;
268 /* should never reach here */