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);
|
0
|
69 #endif
|
|
70
|
|
71 #ifdef DEBUG_WIDGET
|
|
72
|
|
73 static int geom_masks[] = {
|
|
74 CWX, CWY, CWWidth, CWHeight, CWBorderWidth, CWSibling, CWStackMode,
|
|
75 XtCWQueryOnly };
|
|
76 static char *geom_mask_strings[] = {
|
|
77 "CWX", "CWY", "CWWidth", "CWHeight", "CWBorderWidth",
|
|
78 "CWSibling", "CWStackMode", "XtCWQueryOnly" };
|
|
79 static int stack_modes[] = {
|
|
80 Below, TopIf, BottomIf, Opposite, XtSMDontChange };
|
|
81 static char *stack_mode_strings[] = {
|
|
82 "Below", "TopIf", "BottomIf", "Opposite", "XtSMDontChange" };
|
|
83
|
|
84 static void
|
|
85 print_geometry_structure(XtWidgetGeometry *xwg)
|
|
86 {
|
|
87 int num = sizeof(geom_masks)/sizeof(int);
|
|
88 int i;
|
2108
|
89
|
0
|
90 printf (" masks:");
|
|
91 for (i=0; i<num; i++)
|
|
92 if (xwg->request_mode & geom_masks[i])
|
|
93 printf (" %s", geom_mask_strings[i]);
|
|
94 printf ("\n");
|
|
95 printf (" x:%d y:%d\n", xwg->x, xwg->y);
|
|
96 printf (" width:%d height:%d border_width:%d\n", xwg->width,
|
|
97 xwg->height, xwg->border_width);
|
|
98 printf (" sibling: %x\n", xwg->sibling);
|
|
99 printf (" stack_mode: ");
|
|
100 for (i=0, num=sizeof(stack_modes)/sizeof(int); i<num; i++)
|
|
101 if (xwg->stack_mode == stack_modes[i]) {
|
|
102 printf ("%s", stack_mode_strings[i]);
|
|
103 break;
|
|
104 }
|
|
105 printf ("\n");
|
|
106 }
|
|
107
|
|
108 static void
|
|
109 print_geometry_result (XtGeometryResult res)
|
|
110 {
|
|
111 printf ("result: %s\n",
|
|
112 res == XtGeometryYes ? "XtGeometryYes" :
|
|
113 res == XtGeometryNo ? "XtGeometryNo" :
|
|
114 res == XtGeometryAlmost ? "XtGeometryAlmost" :
|
|
115 res == XtGeometryDone ? "XtGeometryDone" :
|
|
116 "unknown");
|
|
117 }
|
|
118
|
|
119 #endif
|
|
120
|
|
121 #ifndef emacs
|
|
122
|
|
123 static void
|
|
124 fatal (char *msg)
|
|
125 {
|
|
126 fprintf (stderr, "%s", msg);
|
|
127 exit (1);
|
|
128 }
|
|
129
|
|
130 #endif
|
|
131
|
|
132 /* put a geometry specification in the specified property on the window
|
|
133 of the specified widget, and send a notification message to tell the
|
|
134 client-side widget about this. */
|
|
135
|
|
136 void
|
|
137 extw_send_geometry_value(Display *display, Window win, Atom property,
|
|
138 en_extw_notify type, XtWidgetGeometry *xwg,
|
|
139 long data0)
|
|
140 {
|
|
141 if (xwg != NULL)
|
|
142 XChangeProperty(display, win, property,
|
|
143 a_EXTW_WIDGET_GEOMETRY, 32, PropModeReplace,
|
|
144 (unsigned char *) xwg, sizeof(*xwg)/sizeof(int));
|
|
145 extw_send_notify_3(display, win, type, data0, 0, 0);
|
|
146 }
|
|
147
|
|
148 /* get the geometry specification stored in the specified property of the
|
|
149 specified widget's window. */
|
|
150
|
|
151 void
|
|
152 extw_get_geometry_value(Display *display, Window win, Atom property,
|
|
153 XtWidgetGeometry *xwg)
|
|
154 {
|
|
155 Atom dummy;
|
|
156 int format;
|
|
157 unsigned long nitems, bytes_after;
|
|
158 unsigned char *prop;
|
2108
|
159
|
0
|
160 if (XGetWindowProperty(display, win, property, 0,
|
|
161 sizeof(*xwg)/4, False, a_EXTW_WIDGET_GEOMETRY,
|
|
162 &dummy, &format, &nitems, &bytes_after,
|
|
163 &prop) != Success)
|
|
164 goto error;
|
|
165 if (format != 8*sizeof(int) || bytes_after) {
|
|
166 XFree((char *) prop);
|
|
167 goto error;
|
|
168 }
|
|
169 *xwg = * (XtWidgetGeometry *) prop;
|
|
170 return;
|
|
171
|
|
172 error:
|
|
173 fatal("Unable to retrieve property for widget-geometry");
|
|
174 #if 0
|
|
175 XtAppErrorMsg(XtWidgetToApplicationContext((Widget)w),
|
|
176 "invalidProperty","get_geometry_value",XtCXtToolkitError,
|
|
177 "Unable to retrieve property for widget-geometry",
|
|
178 (String *)NULL, (Cardinal *)NULL);
|
|
179 #endif
|
|
180 }
|
|
181
|
|
182 typedef struct {
|
|
183 Widget w;
|
|
184 unsigned long request_num;
|
|
185 en_extw_notify type;
|
|
186 } QueryStruct;
|
|
187
|
|
188 /* check if an event is of the sort we're looking for */
|
|
189
|
|
190 static Bool
|
|
191 isMine(Display *dpy, XEvent *event, char *arg)
|
|
192 {
|
|
193 QueryStruct *q = (QueryStruct *) arg;
|
|
194 Widget w = q->w;
|
2108
|
195
|
0
|
196 if ( (dpy != XtDisplay(w)) || (event->xany.window != XtWindow(w)) ) {
|
|
197 return FALSE;
|
|
198 }
|
|
199 if (event->xany.serial >= q->request_num) {
|
|
200 if (event->type == ClientMessage &&
|
|
201 event->xclient.message_type == a_EXTW_NOTIFY &&
|
|
202 event->xclient.data.l[0] == 1 - extw_which_side &&
|
1094
|
203 (en_extw_notify) event->xclient.data.l[1] == q->type)
|
0
|
204 return TRUE;
|
|
205 }
|
|
206 return FALSE;
|
|
207 }
|
|
208
|
|
209 /* wait for a ClientMessage of the specified type from the other widget, or
|
|
210 time-out. isMine() determines whether an event matches. Culled from
|
|
211 Shell.c. */
|
|
212
|
|
213 Bool
|
2108
|
214 extw_wait_for_response (Widget w, XEvent *event, unsigned long request_num,
|
|
215 en_extw_notify type, unsigned long timeout)
|
0
|
216 {
|
2108
|
217 XtAppContext app = XtWidgetToApplicationContext(w);
|
|
218 QueryStruct q;
|
|
219
|
|
220 XFlush(XtDisplay(w));
|
|
221 q.w = w;
|
|
222 q.request_num = request_num;
|
|
223 q.type = type;
|
0
|
224
|
2108
|
225 for(;;)
|
|
226 {
|
|
227 /*
|
|
228 * look for match event
|
|
229 */
|
|
230 if (XCheckIfEvent (XtDisplay(w), event, isMine, (char*)&q))
|
|
231 return TRUE;
|
|
232 if (_XT_WAIT_FOR_SOMETHING (TRUE, TRUE, FALSE, TRUE, &timeout, app)
|
|
233 != -1)
|
|
234 continue;
|
|
235 if (timeout == 0)
|
|
236 return FALSE;
|
|
237 }
|
0
|
238 }
|