1 /* -*-c-*- */
2 
3 #ifndef FVWMLIB_FEVENT_H
4 #define FVWMLIB_FEVENT_H
5 
6 /* ---------------------------- included header files ---------------------- */
7 #include "fvwm_x11.h"
8 
9 /* ---------------------------- global definitions ------------------------- */
10 
11 #define FEV_IS_EVENT_INVALID(e) \
12 	(fev_is_invalid_event_type_set && (e).type == fev_invalid_event_type)
13 
14 #define FEV_HAS_EVENT_WINDOW(type) \
15 	(( \
16 		 (type) != GraphicsExpose && \
17 		 (type) != NoExpose && \
18 		 (type) != SelectionNotify && \
19 		 (type) != SelectionRequest) ? 1 : 0)
20 
21 /* invalidate event by setting a bogus event type */
22 #define FEV_INVALIDATE_EVENT(e) \
23 	do { (e)->type = fev_invalid_event_type; } while (0)
24 
25 /* ---------------------------- global macros ------------------------------ */
26 
27 /* ---------------------------- type definitions --------------------------- */
28 
29 /* ---------------------------- forward declarations ----------------------- */
30 
31 /* ---------------------------- exported variables (globals) --------------- */
32 
33 /* Exported to be used in FEV_IS_EVENT_INVALID().  Do not use. */
34 extern char fev_is_invalid_event_type_set;
35 /* Exported to be used in FEV_IS_EVENT_INVALID().  Do not use. */
36 extern int fev_invalid_event_type;
37 
38 /* ---------------------------- interface functions (privileged access) ---- */
39 
40 #ifdef FEVENT_PRIVILEGED_ACCESS
41 void fev_copy_last_event(XEvent *dest);
42 XEvent *fev_get_last_event_address(void);
43 #endif
44 
45 /* ---------------------------- interface functions (normal_access) -------- */
46 
47 /* Sets the event type that is used by FWeedIfEvents() to mark an event as
48  * invalid.  Needs to be called before FWeedIfEvents() can be used. */
49 void fev_init_invalid_event_type(int invalid_event_type);
50 
51 /* get the latest event time */
52 Time fev_get_evtime(void);
53 
54 /* This function determines the location of the mouse pointer from the event
55  * if possible, if not it queries the X server. Returns False if it had to
56  * query the server and the call failed because the pointer was on a
57  * different screen. */
58 Bool fev_get_evpos_or_query(
59 	Display *dpy, Window w, const XEvent *e, int *ret_x, int *ret_y);
60 
61 /* Sets the x_root/y_root position in the given event if it's of the proper
62  * type.  Returns True if the position was set. */
63 Bool fev_set_evpos(XEvent *e, int x, int y);
64 
65 /* announce a faked event to the FEvent module */
66 void fev_fake_event(XEvent *ev);
67 
68 /* temporarily store the cached event in allocated memory */
69 void *fev_save_event(void);
70 
71 /* restore an event saved with fev_save_event and free the memory it uses */
72 void fev_restore_event(void *ev);
73 
74 /* fill the event structure *ev with a dummy event of no particular type */
75 void fev_make_null_event(XEvent *ev, Display *dpy);
76 
77 /* return a copy of the last XEVent in *ev */
78 void fev_get_last_event(XEvent *ev);
79 
80 /* Make sure the values in the event are in the defined range (e.g. x is and
81  * int, but the protocol uses only a 16 bit signed integer. */
82 void fev_sanitise_configure_request(XConfigureRequestEvent *cr);
83 void fev_sanitise_configure_notify(XConfigureEvent *cn);
84 void fev_sanitize_size_hints(XSizeHints *sh);
85 
86 /* ---------------------------- Functions not present in Xlib -------------- */
87 
88 /* Iterates over all events currentliy in the input queue and calls the
89  * weed_predicate procedure for them.  The predicate may return
90  *  0 = keep event and continue weeding
91  *  1 = invalidate event and continue weeding
92  *  2 = keep event and stop weeding
93  *  3 = invalidate event and stop weeding
94  * Events are marked as invalid by overwriting the event type with the invalid
95  * event type configured with fev_init_invalid_event_type().  Returns the
96  * number of invalidated events.
97  *
98  * The return codes 2 and 3 of the weed_predicate procedure can be used to
99  * stop weeding if another event gets "in the way".  For example, when merging
100  * Expose events, one might want to stop merging when a ConfigureRequest event
101  * is encountered in the queue as that event may change the visible are of the
102  * window.
103  *
104  * Weeded events can still be returned by functions that do not check the event
105  * type, e.g. FNextEvent(), FWindowEvent(), FMaskEvent(), FPeekEvent etc.  It
106  * is the responsibility of the caller to discard these events.
107  *
108  * If the weed_predicate is a NULL pointer, no call is made and the result for
109  * all events is assumed to be 1.
110  */
111 int FWeedIfEvents(
112 	Display *display,
113 	int (*weed_predicate) (
114 		Display *display, XEvent *current_event, XPointer arg),
115 	XPointer arg);
116 
117 /* Same as FWeedIfEvents but weeds only events for the given window.  The
118  * weed_predicate is only called for events with a matching window.  */
119 int FWeedIfWindowEvents(
120 	Display *display, Window window,
121 	int (*weed_predicate) (
122 		Display *display, XEvent *current_event, XPointer arg),
123 	XPointer arg);
124 
125 /* Same as FWeedIfEvents but weeds only events of the given type for the given
126  * window.  If last_event is not NULL, a copy of the last weeded event is
127  * returned through *last_event (valid if a value > 0 is treturned). */
128 int FCheckWeedTypedWindowEvents(
129 	Display *display, Window window, int event_type, XEvent *last_event);
130 
131 /* Like FCheckIfEvent but does not remove the event from the queue. */
132 int FCheckPeekIfEvent(
133         Display *display, XEvent *event_return,
134         Bool (*predicate) (Display *display, XEvent *event, XPointer arg),
135         XPointer arg);
136 
137 /* ---------------------------- X event replacements ----------------------- */
138 
139 /* Replacements for X functions */
140 XTimeCoord *FGetMotionEvents(
141 	Display *display, Window w, Time start, Time stop, int *nevents_return);
142 int FAllowEvents(
143 	Display *display, int event_mode, Time time);
144 Bool FCheckIfEvent(
145 	Display *display, XEvent *event_return,
146 	Bool (*predicate) (Display *display, XEvent *event, XPointer arg),
147 	XPointer arg);
148 Bool FCheckMaskEvent(
149 	Display *display, long event_mask, XEvent *event_return);
150 Bool FCheckTypedEvent(
151 	Display *display, int event_type, XEvent *event_return);
152 Bool FCheckTypedWindowEvent(
153 	Display *display, Window w, int event_type, XEvent *event_return);
154 Bool FCheckWindowEvent(
155 	Display *display, Window w, long event_mask, XEvent *event_return);
156 int FEventsQueued(
157 	Display *display, int mode);
158 int FIfEvent(
159 	Display *display, XEvent *event_return,
160 	Bool (*predicate) (Display *display, XEvent *event, XPointer arg),
161 	XPointer arg);
162 int FMaskEvent(
163 	Display *display, long event_mask, XEvent *event_return);
164 int FNextEvent(
165 	Display *display, XEvent *event_return);
166 int FPeekEvent(
167 	Display *display, XEvent *event_return);
168 int FPeekIfEvent(
169 	Display *display, XEvent *event_return,
170 	Bool (*predicate) (Display *display, XEvent *event, XPointer arg),
171 	XPointer arg);
172 int FPending(
173 	Display *display);
174 int FPutBackEvent(
175 	Display *display, XEvent *event);
176 int FQLength(
177 	Display *display);
178 Bool FQueryPointer(
179 	Display *display, Window w, Window *root_return, Window *child_return,
180 	int *root_x_return, int *root_y_return, int *win_x_return,
181 	int *win_y_return, unsigned int *mask_return);
182 int FSelectInput(
183 	Display *display, Window w, long event_mask);
184 Status FSendEvent(
185 	Display *display, Window w, Bool propagate, long event_mask,
186 	XEvent *event_send);
187 int FWarpPointer(
188 	Display *display, Window src_w, Window dest_w, int src_x, int src_y,
189 	unsigned int src_width, unsigned int src_height, int dest_x,
190 	int dest_y);
191 int FWarpPointerUpdateEvpos(
192 	XEvent *ev, Display *display, Window src_w, Window dest_w, int src_x,
193 	int src_y, unsigned int src_width, unsigned int src_height,
194 	int dest_x, int dest_y);
195 int FWindowEvent(
196 	Display *display, Window w, long event_mask, XEvent *event_return);
197 Status FGetWMNormalHints(
198 	Display *display, Window w, XSizeHints *hints_return,
199 	long *supplied_return);
200 
201 /* ---------------------------- disable X symbols -------------------------- */
202 
203 /* FEVENT_C must only be defined in FEvent.c! */
204 #ifndef FEVENT_C
205 #define XGetMotionEvents(a, b, c, d, e) use_FGetMotionEvents
206 #define XCheckIfEvent(a, b, c, d) use_FCheckIfEvent
207 #define XCheckMaskEvent(a, b, c) use_FCheckMaskEvent
208 #define XCheckTypedEvent(a, b, c) use_FCheckTypedEvent
209 #define XCheckTypedWindowEvent(a, b, c, d) use_FCheckTypedWindowEvent
210 #define XCheckWindowEvent(a, b, c, d) use_FCheckWindowEvent
211 #define XEventsQueued(a, b) use_FEventsQueued
212 #define XIfEvent(a, b, c, d) use_FIfEvent
213 #define XMaskEvent(a, b, c) use_FMaskEvent
214 #define XNextEvent(a, b) use_FNextEvent
215 #define XPeekEvent(a, b) use_FPeekEvent
216 #define XPeekIfEvent(a, b, c, d) use_FPeekIfEvent
217 #define XPending(a) use_FPending
218 #define XPutBackEvent(a, b) use_FPutBackEvent
219 #define XQueryPointer(a, b, c, d, e, f, g, h, i) use_FQueryPointer
220 #define XQLength(a) use_FQLength
221 #define XSendEvent(a, b, c, d, e) use_FSendEvent
222 #define XWarpPointer(a, b, c, d, e, f, g, h, i) use_FWarpPointer
223 #define XWindowEvent(a, b, c, d) use_FWindowEvent
224 #define XGetSizeHints(a, b, c, d) use_FGetWMNormalHints
225 #define XGetNormalHints(a, b, c) use_FGetWMNormalHints
226 #define XGetWMNormalHints(a, b, c, d) use_FGetWMNormalHints
227 #endif
228 
229 #endif /* FVWMLIB_FEVENT_H */
230