0
|
1 /* Common code between client and shell widgets -- Xt only.
|
|
2 Copyright (C) 1993, 1994 Sun Microsystems, Inc.
|
|
3
|
|
4 This library is free software; you can redistribute it and/or
|
|
5 modify it under the terms of the GNU Library General Public
|
|
6 License as published by the Free Software Foundation; either
|
|
7 version 2 of the License, or (at your option) any later version.
|
|
8
|
|
9 This library is distributed in the hope that it will be useful,
|
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12 Library General Public License for more details.
|
|
13
|
|
14 You should have received a copy of the GNU Library General Public
|
|
15 License along with this library; if not, write to
|
|
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
17 Boston, MA 02111-1307, USA. */
|
|
18
|
|
19 /* Synched up with: Not in FSF. */
|
|
20
|
|
21 /* Written by Ben Wing, September 1993. */
|
|
22
|
|
23 #ifdef emacs
|
|
24
|
|
25 #include <config.h>
|
|
26
|
|
27 #ifndef EXTERNAL_WIDGET
|
|
28 ERROR! This ought not be getting compiled if EXTERNAL_WIDGET is undefined
|
|
29 #endif
|
|
30
|
2110
|
31 EXTERN_C void fatal (const char *fmt, ...);
|
0
|
32 #else /* not emacs */
|
|
33 static void fatal (char *msg);
|
|
34 #endif
|
|
35
|
|
36 #include <X11/Intrinsic.h>
|
|
37 #include <X11/IntrinsicP.h>
|
|
38 #include <stdlib.h>
|
|
39 #include <stdio.h>
|
|
40 #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)
|
2110
|
48 EXTERN_C int
|
|
49 _XtWaitForSomething (XtAppContext app, _XtBoolean ignoreEvents,
|
|
50 _XtBoolean ignoreTimers, _XtBoolean ignoreInputs,
|
|
51 _XtBoolean ignoreSignals, _XtBoolean block,
|
0
|
52 #ifdef XTHREADS
|
2110
|
53 _XtBoolean drop_lock,
|
0
|
54 #endif
|
2110
|
55 unsigned long *howlong);
|
0
|
56
|
|
57 # ifndef XTHREADS
|
2108
|
58 # define _XT_WAIT_FOR_SOMETHING(timers,inputs,events,block,howlong,appCtx) \
|
|
59 _XtWaitForSomething (appCtx,events,timers,inputs,0,block,howlong)
|
0
|
60 # else
|
2108
|
61 # define _XT_WAIT_FOR_SOMETHING(timers,inputs,events,block,howlong,appCtx) \
|
|
62 _XtWaitForSomething (appCtx,events,timers,inputs,0,block,1,howlong)
|
0
|
63 # endif
|
|
64 #else
|
2110
|
65 EXTERN_C int
|
|
66 _XtwaitForSomething (Boolean ignoreTimers, Boolean ignoreInputs,
|
|
67 Boolean ignoreEvents, Boolean block,
|
|
68 unsigned long *howlong, XtAppContext app);
|
2114
|
69 # define _XT_WAIT_FOR_SOMETHING(timers,inputs,events,block,howlong,appCtx) \
|
|
70 _XtwaitForSomething (timers,inputs,events,block,howlong,appCtx)
|
0
|
71 #endif
|
|
72
|
|
73 #ifdef DEBUG_WIDGET
|
|
74
|
|
75 static int geom_masks[] = {
|
|
76 CWX, CWY, CWWidth, CWHeight, CWBorderWidth, CWSibling, CWStackMode,
|
|
77 XtCWQueryOnly };
|
|
78 static char *geom_mask_strings[] = {
|
|
79 "CWX", "CWY", "CWWidth", "CWHeight", "CWBorderWidth",
|
|
80 "CWSibling", "CWStackMode", "XtCWQueryOnly" };
|
|
81 static int stack_modes[] = {
|
|
82 Below, TopIf, BottomIf, Opposite, XtSMDontChange };
|
|
83 static char *stack_mode_strings[] = {
|
|
84 "Below", "TopIf", "BottomIf", "Opposite", "XtSMDontChange" };
|
|
85
|
|
86 static void
|
|
87 print_geometry_structure(XtWidgetGeometry *xwg)
|
|
88 {
|
|
89 int num = sizeof(geom_masks)/sizeof(int);
|
|
90 int i;
|
2108
|
91
|
0
|
92 printf (" masks:");
|
|
93 for (i=0; i<num; i++)
|
|
94 if (xwg->request_mode & geom_masks[i])
|
|
95 printf (" %s", geom_mask_strings[i]);
|
|
96 printf ("\n");
|
|
97 printf (" x:%d y:%d\n", xwg->x, xwg->y);
|
|
98 printf (" width:%d height:%d border_width:%d\n", xwg->width,
|
|
99 xwg->height, xwg->border_width);
|
|
100 printf (" sibling: %x\n", xwg->sibling);
|
|
101 printf (" stack_mode: ");
|
|
102 for (i=0, num=sizeof(stack_modes)/sizeof(int); i<num; i++)
|
|
103 if (xwg->stack_mode == stack_modes[i]) {
|
|
104 printf ("%s", stack_mode_strings[i]);
|
|
105 break;
|
|
106 }
|
|
107 printf ("\n");
|
|
108 }
|
|
109
|
|
110 static void
|
|
111 print_geometry_result (XtGeometryResult res)
|
|
112 {
|
|
113 printf ("result: %s\n",
|
|
114 res == XtGeometryYes ? "XtGeometryYes" :
|
|
115 res == XtGeometryNo ? "XtGeometryNo" :
|
|
116 res == XtGeometryAlmost ? "XtGeometryAlmost" :
|
|
117 res == XtGeometryDone ? "XtGeometryDone" :
|
|
118 "unknown");
|
|
119 }
|
|
120
|
|
121 #endif
|
|
122
|
|
123 #ifndef emacs
|
|
124
|
|
125 static void
|
|
126 fatal (char *msg)
|
|
127 {
|
|
128 fprintf (stderr, "%s", msg);
|
|
129 exit (1);
|
|
130 }
|
|
131
|
|
132 #endif
|
|
133
|
|
134 /* put a geometry specification in the specified property on the window
|
|
135 of the specified widget, and send a notification message to tell the
|
|
136 client-side widget about this. */
|
|
137
|
|
138 void
|
|
139 extw_send_geometry_value(Display *display, Window win, Atom property,
|
|
140 en_extw_notify type, XtWidgetGeometry *xwg,
|
|
141 long data0)
|
|
142 {
|
|
143 if (xwg != NULL)
|
|
144 XChangeProperty(display, win, property,
|
|
145 a_EXTW_WIDGET_GEOMETRY, 32, PropModeReplace,
|
|
146 (unsigned char *) xwg, sizeof(*xwg)/sizeof(int));
|
|
147 extw_send_notify_3(display, win, type, data0, 0, 0);
|
|
148 }
|
|
149
|
|
150 /* get the geometry specification stored in the specified property of the
|
|
151 specified widget's window. */
|
|
152
|
|
153 void
|
|
154 extw_get_geometry_value(Display *display, Window win, Atom property,
|
|
155 XtWidgetGeometry *xwg)
|
|
156 {
|
|
157 Atom dummy;
|
|
158 int format;
|
|
159 unsigned long nitems, bytes_after;
|
|
160 unsigned char *prop;
|
2108
|
161
|
0
|
162 if (XGetWindowProperty(display, win, property, 0,
|
|
163 sizeof(*xwg)/4, False, a_EXTW_WIDGET_GEOMETRY,
|
|
164 &dummy, &format, &nitems, &bytes_after,
|
|
165 &prop) != Success)
|
|
166 goto error;
|
|
167 if (format != 8*sizeof(int) || bytes_after) {
|
|
168 XFree((char *) prop);
|
|
169 goto error;
|
|
170 }
|
|
171 *xwg = * (XtWidgetGeometry *) prop;
|
|
172 return;
|
|
173
|
|
174 error:
|
|
175 fatal("Unable to retrieve property for widget-geometry");
|
|
176 #if 0
|
|
177 XtAppErrorMsg(XtWidgetToApplicationContext((Widget)w),
|
|
178 "invalidProperty","get_geometry_value",XtCXtToolkitError,
|
|
179 "Unable to retrieve property for widget-geometry",
|
|
180 (String *)NULL, (Cardinal *)NULL);
|
|
181 #endif
|
|
182 }
|
|
183
|
|
184 typedef struct {
|
|
185 Widget w;
|
|
186 unsigned long request_num;
|
|
187 en_extw_notify type;
|
|
188 } QueryStruct;
|
|
189
|
|
190 /* check if an event is of the sort we're looking for */
|
|
191
|
|
192 static Bool
|
|
193 isMine(Display *dpy, XEvent *event, char *arg)
|
|
194 {
|
|
195 QueryStruct *q = (QueryStruct *) arg;
|
|
196 Widget w = q->w;
|
2108
|
197
|
0
|
198 if ( (dpy != XtDisplay(w)) || (event->xany.window != XtWindow(w)) ) {
|
|
199 return FALSE;
|
|
200 }
|
|
201 if (event->xany.serial >= q->request_num) {
|
|
202 if (event->type == ClientMessage &&
|
|
203 event->xclient.message_type == a_EXTW_NOTIFY &&
|
|
204 event->xclient.data.l[0] == 1 - extw_which_side &&
|
1094
|
205 (en_extw_notify) event->xclient.data.l[1] == q->type)
|
0
|
206 return TRUE;
|
|
207 }
|
|
208 return FALSE;
|
|
209 }
|
|
210
|
|
211 /* wait for a ClientMessage of the specified type from the other widget, or
|
|
212 time-out. isMine() determines whether an event matches. Culled from
|
|
213 Shell.c. */
|
|
214
|
|
215 Bool
|
2108
|
216 extw_wait_for_response (Widget w, XEvent *event, unsigned long request_num,
|
|
217 en_extw_notify type, unsigned long timeout)
|
0
|
218 {
|
2108
|
219 XtAppContext app = XtWidgetToApplicationContext(w);
|
|
220 QueryStruct q;
|
|
221
|
|
222 XFlush(XtDisplay(w));
|
|
223 q.w = w;
|
|
224 q.request_num = request_num;
|
|
225 q.type = type;
|
0
|
226
|
2108
|
227 for(;;)
|
|
228 {
|
|
229 /*
|
|
230 * look for match event
|
|
231 */
|
|
232 if (XCheckIfEvent (XtDisplay(w), event, isMine, (char*)&q))
|
|
233 return TRUE;
|
|
234 if (_XT_WAIT_FOR_SOMETHING (TRUE, TRUE, FALSE, TRUE, &timeout, app)
|
|
235 != -1)
|
|
236 continue;
|
|
237 if (timeout == 0)
|
|
238 return FALSE;
|
|
239 }
|
0
|
240 }
|