Mercurial > hg > xemacs-beta
comparison src/extw-Xt.c @ 4331:4fbcce3f6097
Don't use undocumented Xt functions in external widget.
2007-12-18 Kenny Chien <Kenny.Chien@morganstanley.com>
* extw-Xt.c (extw_wait_for_response): Don't use undocumented
internal Xt functions, avoiding inconsistent behavior between
different Solaris versions.
author | Mike Sperber <sperber@deinprogramm.de> |
---|---|
date | Wed, 19 Dec 2007 10:21:38 +0100 |
parents | 2e4be8dd02fc |
children | 2aa9cd456ae7 |
comparison
equal
deleted
inserted
replaced
4330:8a38eea09ab5 | 4331:4fbcce3f6097 |
---|---|
35 | 35 |
36 #include <X11/Intrinsic.h> | 36 #include <X11/Intrinsic.h> |
37 #include <X11/IntrinsicP.h> | 37 #include <X11/IntrinsicP.h> |
38 #include <stdlib.h> | 38 #include <stdlib.h> |
39 #include <stdio.h> | 39 #include <stdio.h> |
40 #include "compiler.h" | |
40 #include "extw-Xt.h" | 41 #include "extw-Xt.h" |
41 | |
42 /* Yeah, that's portable! | |
43 | |
44 Why the hell didn't the Xt people just export this function | |
45 for real? */ | |
46 | |
47 #if (XT_REVISION > 5) | |
48 EXTERN_C int | |
49 _XtWaitForSomething (XtAppContext app, _XtBoolean ignoreEvents, | |
50 _XtBoolean ignoreTimers, _XtBoolean ignoreInputs, | |
51 _XtBoolean ignoreSignals, _XtBoolean block, | |
52 #ifdef XTHREADS | |
53 _XtBoolean drop_lock, | |
54 #endif | |
55 unsigned long *howlong); | |
56 | |
57 # ifndef XTHREADS | |
58 # define _XT_WAIT_FOR_SOMETHING(timers,inputs,events,block,howlong,appCtx) \ | |
59 _XtWaitForSomething (appCtx,events,timers,inputs,0,block,howlong) | |
60 # else | |
61 # define _XT_WAIT_FOR_SOMETHING(timers,inputs,events,block,howlong,appCtx) \ | |
62 _XtWaitForSomething (appCtx,events,timers,inputs,0,block,1,howlong) | |
63 # endif | |
64 #else | |
65 EXTERN_C int | |
66 _XtwaitForSomething (Boolean ignoreTimers, Boolean ignoreInputs, | |
67 Boolean ignoreEvents, Boolean block, | |
68 unsigned long *howlong, XtAppContext app); | |
69 # define _XT_WAIT_FOR_SOMETHING(timers,inputs,events,block,howlong,appCtx) \ | |
70 _XtwaitForSomething (timers,inputs,events,block,howlong,appCtx) | |
71 #endif | |
72 | 42 |
73 #ifdef DEBUG_WIDGET | 43 #ifdef DEBUG_WIDGET |
74 | 44 |
75 static int geom_masks[] = { | 45 static int geom_masks[] = { |
76 CWX, CWY, CWWidth, CWHeight, CWBorderWidth, CWSibling, CWStackMode, | 46 CWX, CWY, CWWidth, CWHeight, CWBorderWidth, CWSibling, CWStackMode, |
179 "Unable to retrieve property for widget-geometry", | 149 "Unable to retrieve property for widget-geometry", |
180 (String *)NULL, (Cardinal *)NULL); | 150 (String *)NULL, (Cardinal *)NULL); |
181 #endif | 151 #endif |
182 } | 152 } |
183 | 153 |
184 typedef struct { | 154 typedef struct |
185 Widget w; | 155 { |
186 unsigned long request_num; | 156 Widget w; |
187 en_extw_notify type; | 157 unsigned long request_num; |
158 en_extw_notify type; | |
188 } QueryStruct; | 159 } QueryStruct; |
189 | 160 |
190 /* check if an event is of the sort we're looking for */ | 161 /* check if an event is of the sort we're looking for */ |
191 | 162 |
192 static Bool | 163 static Bool |
193 isMine(Display *dpy, XEvent *event, char *arg) | 164 isMine(XEvent *event, QueryStruct *q) |
194 { | 165 { |
195 QueryStruct *q = (QueryStruct *) arg; | 166 Widget w = q->w; |
196 Widget w = q->w; | 167 |
197 | 168 if ( (event->xany.display != XtDisplay(w)) || (event->xany.window != XtWindow(w)) ) |
198 if ( (dpy != XtDisplay(w)) || (event->xany.window != XtWindow(w)) ) { | 169 { |
199 return FALSE; | 170 return FALSE; |
171 } | |
172 if (event->xany.serial >= q->request_num) | |
173 { | |
174 if (event->type == ClientMessage && | |
175 event->xclient.message_type == a_EXTW_NOTIFY && | |
176 event->xclient.data.l[0] == 1 - extw_which_side && | |
177 event->xclient.data.l[1] == (int) q->type) | |
178 { | |
179 return TRUE; | |
200 } | 180 } |
201 if (event->xany.serial >= q->request_num) { | 181 } |
202 if (event->type == ClientMessage && | 182 return FALSE; |
203 event->xclient.message_type == a_EXTW_NOTIFY && | 183 } |
204 event->xclient.data.l[0] == 1 - extw_which_side && | 184 |
205 (en_extw_notify) event->xclient.data.l[1] == q->type) | 185 void responseTimeOut(XtPointer clientData, XtIntervalId * UNUSED (id)) |
206 return TRUE; | 186 { |
207 } | 187 Bool *expired=(Bool *)clientData; |
208 return FALSE; | 188 *expired=TRUE; |
209 } | 189 } |
210 | 190 |
211 /* wait for a ClientMessage of the specified type from the other widget, or | 191 /* wait for a ClientMessage of the specified type from the other widget, or |
212 time-out. isMine() determines whether an event matches. Culled from | 192 time-out. isMine() determines whether an event matches. |
213 Shell.c. */ | 193 Took out the call to _XtWaitForSomething and replaced it with public |
194 Xt api's. | |
195 */ | |
214 | 196 |
215 Bool | 197 Bool |
216 extw_wait_for_response (Widget w, XEvent *event, unsigned long request_num, | 198 extw_wait_for_response (Widget w, XEvent *event, unsigned long request_num, |
217 en_extw_notify type, unsigned long timeout) | 199 en_extw_notify type, unsigned long timeout) |
218 { | 200 { |
219 XtAppContext app = XtWidgetToApplicationContext(w); | 201 XtAppContext app = XtWidgetToApplicationContext(w); |
202 XtInputMask inputMask; | |
220 QueryStruct q; | 203 QueryStruct q; |
221 | 204 Bool expired; |
222 XFlush(XtDisplay(w)); | 205 XtIntervalId id; |
206 | |
223 q.w = w; | 207 q.w = w; |
224 q.request_num = request_num; | 208 q.request_num = request_num; |
225 q.type = type; | 209 q.type = type; |
226 | 210 expired=FALSE; |
227 for(;;) | 211 |
212 id=XtAppAddTimeOut(app, timeout, responseTimeOut,&expired); | |
213 while (!expired) | |
228 { | 214 { |
229 /* | 215 inputMask=XtAppPending(app); |
230 * look for match event | 216 if (inputMask & XtIMXEvent) |
231 */ | 217 { |
232 if (XCheckIfEvent (XtDisplay(w), event, isMine, (char*)&q)) | 218 XtAppNextEvent(app, event); |
233 return TRUE; | 219 if (isMine(event,&q)) |
234 if (_XT_WAIT_FOR_SOMETHING (TRUE, TRUE, FALSE, TRUE, &timeout, app) | 220 { |
235 != -1) | 221 if (!expired) XtRemoveTimeOut(id); |
236 continue; | 222 return True; |
237 if (timeout == 0) | 223 } |
238 return FALSE; | 224 else |
239 } | 225 { |
240 } | 226 /* Do Nothing and go back to waiting */ |
227 } | |
228 } | |
229 if (inputMask & XtIMTimer) | |
230 { | |
231 /* Process the expired timer */ | |
232 XtAppProcessEvent(app,XtIMTimer); | |
233 } | |
234 } | |
235 /* Must have expired */ | |
236 return False; | |
237 } |