Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/post/src/tk/window.c
3203 views
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include "tk.h"
5
#include "private.h"
6
7
/******************************************************************************/
8
9
Display *xDisplay = 0;
10
int xScreen = 0;
11
Window wRoot = 0;
12
Atom deleteWindowAtom;
13
WINDOW_REC w = {
14
0, 0, 300, 300, TK_RGB|TK_SINGLE|TK_DIRECT
15
};
16
float colorMaps[] = {
17
0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000,
18
0.000000, 1.000000, 0.333333, 0.776471, 0.443137, 0.556863,
19
0.443137, 0.556863, 0.219608, 0.666667, 0.666667, 0.333333,
20
0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
21
0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
22
0.666667, 0.333333, 0.039216, 0.078431, 0.117647, 0.156863,
23
0.200000, 0.239216, 0.278431, 0.317647, 0.356863, 0.400000,
24
0.439216, 0.478431, 0.517647, 0.556863, 0.600000, 0.639216,
25
0.678431, 0.717647, 0.756863, 0.800000, 0.839216, 0.878431,
26
0.917647, 0.956863, 0.000000, 0.000000, 0.000000, 0.000000,
27
0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059,
28
0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
29
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
30
0.498039, 0.498039, 0.749020, 0.749020, 0.749020, 0.749020,
31
0.749020, 0.749020, 0.749020, 0.749020, 1.000000, 1.000000,
32
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
33
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
34
0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059,
35
0.247059, 0.247059, 0.247059, 0.247059, 0.498039, 0.498039,
36
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
37
0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
38
0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000,
39
1.000000, 1.000000, 1.000000, 1.000000, 0.000000, 0.000000,
40
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
41
0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
42
0.247059, 0.247059, 0.498039, 0.498039, 0.498039, 0.498039,
43
0.498039, 0.498039, 0.498039, 0.498039, 0.749020, 0.749020,
44
0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
45
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
46
1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000,
47
0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059,
48
0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
49
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
50
0.498039, 0.498039, 0.749020, 0.749020, 0.749020, 0.749020,
51
0.749020, 0.749020, 0.749020, 0.749020, 1.000000, 1.000000,
52
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
53
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
54
0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059,
55
0.247059, 0.247059, 0.247059, 0.247059, 0.498039, 0.498039,
56
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
57
0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
58
0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000,
59
1.000000, 1.000000, 1.000000, 1.000000, 0.000000, 0.000000,
60
1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000,
61
0.333333, 0.443137, 0.776471, 0.556863, 0.443137, 0.219608,
62
0.556863, 0.666667, 0.666667, 0.333333, 0.666667, 0.333333,
63
0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
64
0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
65
0.039216, 0.078431, 0.117647, 0.156863, 0.200000, 0.239216,
66
0.278431, 0.317647, 0.356863, 0.400000, 0.439216, 0.478431,
67
0.517647, 0.556863, 0.600000, 0.639216, 0.678431, 0.717647,
68
0.756863, 0.800000, 0.839216, 0.878431, 0.917647, 0.956863,
69
0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
70
0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
71
0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
72
0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
73
0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
74
0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
75
0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
76
0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
77
0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
78
0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
79
0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
80
0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
81
0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
82
0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
83
0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
84
0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
85
0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
86
0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
87
0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
88
0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
89
0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
90
0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
91
0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
92
0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
93
0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
94
0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
95
0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
96
0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
97
0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
98
0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451,
99
0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176,
100
0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000,
101
0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726,
102
0.854902, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000,
103
1.000000, 1.000000, 1.000000, 1.000000, 0.333333, 0.443137,
104
0.443137, 0.219608, 0.776471, 0.556863, 0.556863, 0.666667,
105
0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
106
0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333,
107
0.666667, 0.333333, 0.666667, 0.333333, 0.039216, 0.078431,
108
0.117647, 0.156863, 0.200000, 0.239216, 0.278431, 0.317647,
109
0.356863, 0.400000, 0.439216, 0.478431, 0.517647, 0.556863,
110
0.600000, 0.639216, 0.678431, 0.717647, 0.756863, 0.800000,
111
0.839216, 0.878431, 0.917647, 0.956863, 0.000000, 0.000000,
112
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
113
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
114
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
115
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
116
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
117
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,
118
0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059,
119
0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
120
0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
121
0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
122
0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
123
0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
124
0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059,
125
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
126
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
127
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
128
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
129
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
130
0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039,
131
0.498039, 0.498039, 0.498039, 0.498039, 0.749020, 0.749020,
132
0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
133
0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
134
0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
135
0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
136
0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
137
0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020,
138
0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000,
139
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
140
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
141
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
142
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
143
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
144
1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
145
};
146
float tkRGBMap[8][3] = {
147
{
148
0, 0, 0
149
},
150
{
151
1, 0, 0
152
},
153
{
154
0, 1, 0
155
},
156
{
157
1, 1, 0
158
},
159
{
160
0, 0, 1
161
},
162
{
163
1, 0, 1
164
},
165
{
166
0, 1, 1
167
},
168
{
169
1, 1, 1
170
}
171
};
172
173
/******************************************************************************/
174
175
void tkCloseWindow(void)
176
{
177
178
if (xDisplay) {
179
cursorNum = 0;
180
181
ExposeFunc = 0;
182
ReshapeFunc = 0;
183
IdleFunc = 0;
184
DisplayFunc = 0;
185
KeyDownFunc = 0;
186
MouseDownFunc = 0;
187
MouseUpFunc = 0;
188
MouseMoveFunc = 0;
189
190
glFlush();
191
glFinish();
192
if (TK_HAS_OVERLAY(w.type)) {
193
XDestroyWindow(xDisplay, w.wOverlay);
194
glXDestroyContext(xDisplay, w.cOverlay);
195
XFreeColormap(xDisplay, w.cMapOverlay);
196
XFree((char *)w.vInfoOverlay);
197
}
198
XDestroyWindow(xDisplay, w.wMain);
199
glXDestroyContext(xDisplay, w.cMain);
200
if (w.cMapAllocated)
201
XFreeColormap(xDisplay, w.cMapMain);
202
XFree((char *)w.vInfoMain);
203
XCloseDisplay(xDisplay);
204
xDisplay = 0;
205
}
206
}
207
208
/******************************************************************************/
209
210
void tkInitDisplayMode(GLenum type)
211
{
212
213
w.type = type;
214
}
215
216
/******************************************************************************/
217
218
void tkInitPosition(int x, int y, int width, int height)
219
{
220
221
w.x = x;
222
w.y = y;
223
w.w = width;
224
w.h = height;
225
}
226
227
/******************************************************************************/
228
229
static int ErrorHandler(Display *xDisplay, XErrorEvent *event)
230
{
231
char buf[80];
232
233
printf("\nReceived X error!\n");
234
printf("\tError code : %d\n", event->error_code);
235
printf("\tRequest code : %d\n", event->request_code);
236
printf("\tMinor code : %d\n\n", event->minor_code);
237
XGetErrorText(xDisplay, event->error_code, buf, 80);
238
printf("\tError text : '%s'\n\n", buf);
239
return 0;
240
}
241
242
static XVisualInfo *FindMainVisual(GLenum type)
243
{
244
int list[32], i;
245
246
i = 0;
247
248
list[i++] = GLX_LEVEL;
249
list[i++] = 0;
250
251
if (TK_IS_DOUBLE(type)) {
252
list[i++] = GLX_DOUBLEBUFFER;
253
}
254
255
if (TK_IS_RGB(type)) {
256
list[i++] = GLX_RGBA;
257
list[i++] = GLX_RED_SIZE;
258
list[i++] = 1;
259
list[i++] = GLX_GREEN_SIZE;
260
list[i++] = 1;
261
list[i++] = GLX_BLUE_SIZE;
262
list[i++] = 1;
263
if (TK_HAS_ALPHA(type)) {
264
list[i++] = GLX_ALPHA_SIZE;
265
list[i++] = 1;
266
}
267
if (TK_HAS_ACCUM(type)) {
268
list[i++] = GLX_ACCUM_RED_SIZE;
269
list[i++] = 1;
270
list[i++] = GLX_ACCUM_GREEN_SIZE;
271
list[i++] = 1;
272
list[i++] = GLX_ACCUM_BLUE_SIZE;
273
list[i++] = 1;
274
if (TK_HAS_ALPHA(type)) {
275
list[i++] = GLX_ACCUM_ALPHA_SIZE;
276
list[i++] = 1;
277
}
278
}
279
} else if (TK_IS_INDEX(type)) {
280
list[i++] = GLX_BUFFER_SIZE;
281
list[i++] = 1;
282
}
283
284
if (TK_HAS_DEPTH(type)) {
285
list[i++] = GLX_DEPTH_SIZE;
286
list[i++] = 1;
287
}
288
289
if (TK_HAS_STENCIL(type)) {
290
list[i++] = GLX_STENCIL_SIZE;
291
list[i++] = 1;
292
}
293
294
list[i] = (int)None;
295
296
return glXChooseVisual(xDisplay, xScreen, list);
297
}
298
299
static XVisualInfo *FindOverlayVisual(void)
300
{
301
int list[3];
302
303
list[0] = GLX_LEVEL;
304
list[1] = 1;
305
list[2] = (int)None;
306
307
return glXChooseVisual(xDisplay, xScreen, list);
308
}
309
310
static GLenum GetMainWindowType(XVisualInfo *vi)
311
{
312
GLenum mask;
313
int x, y, z;
314
315
mask = 0;
316
317
glXGetConfig(xDisplay, vi, GLX_DOUBLEBUFFER, &x);
318
if (x) {
319
mask |= TK_DOUBLE;
320
} else {
321
mask |= TK_SINGLE;
322
}
323
324
glXGetConfig(xDisplay, vi, GLX_RGBA, &x);
325
if (x) {
326
mask |= TK_RGB;
327
glXGetConfig(xDisplay, vi, GLX_ALPHA_SIZE, &x);
328
if (x > 0) {
329
mask |= TK_ALPHA;
330
}
331
glXGetConfig(xDisplay, vi, GLX_ACCUM_RED_SIZE, &x);
332
glXGetConfig(xDisplay, vi, GLX_ACCUM_GREEN_SIZE, &y);
333
glXGetConfig(xDisplay, vi, GLX_ACCUM_BLUE_SIZE, &z);
334
if (x > 0 && y > 0 && z > 0) {
335
mask |= TK_ACCUM;
336
}
337
} else {
338
mask |= TK_INDEX;
339
}
340
341
glXGetConfig(xDisplay, vi, GLX_DEPTH_SIZE, &x);
342
if (x > 0) {
343
mask |= TK_DEPTH;
344
}
345
346
glXGetConfig(xDisplay, vi, GLX_STENCIL_SIZE, &x);
347
if (x > 0) {
348
mask |= TK_STENCIL;
349
}
350
351
if (glXIsDirect(xDisplay, w.cMain)) {
352
mask |= TK_DIRECT;
353
} else {
354
mask |= TK_INDIRECT;
355
}
356
357
return mask;
358
}
359
360
static int WaitForMainWindow(Display *d, XEvent *e, char *arg)
361
{
362
363
if (e->type == MapNotify && e->xmap.window == w.wMain) {
364
return GL_TRUE;
365
} else {
366
return GL_FALSE;
367
}
368
}
369
370
static int WaitForOverlayWindow(Display *d, XEvent *e, char *arg)
371
{
372
373
if (e->type == MapNotify && e->xmap.window == w.wOverlay) {
374
return GL_TRUE;
375
} else {
376
return GL_FALSE;
377
}
378
}
379
380
GLenum tkInitWindow(char *title)
381
{
382
XSetWindowAttributes wa;
383
XTextProperty tp;
384
XSizeHints sh;
385
XEvent e;
386
int erb, evb;
387
GLenum overlayFlag;
388
389
if (!xDisplay) {
390
xDisplay = XOpenDisplay(0);
391
if (!xDisplay) {
392
fprintf(stderr, "Can't connect to xDisplay!\n");
393
return GL_FALSE;
394
}
395
if (!glXQueryExtension(xDisplay, &erb, &evb)) {
396
fprintf(stderr, "No glx extension!\n");
397
return GL_FALSE;
398
}
399
xScreen = DefaultScreen(xDisplay);
400
wRoot = RootWindow(xDisplay, xScreen);
401
XSetErrorHandler(ErrorHandler);
402
}
403
404
if (TK_HAS_OVERLAY(w.type)) {
405
overlayFlag = GL_TRUE;
406
} else {
407
overlayFlag = GL_FALSE;
408
}
409
w.type &= ~TK_OVERLAY;
410
411
w.vInfoMain = FindMainVisual(w.type);
412
if (!w.vInfoMain) {
413
if (TK_IS_RGB(w.type)) {
414
fprintf(stderr, "Couldn't find visual for RGB mode!\n");
415
}
416
else {
417
fprintf(stderr, "Couldn't find visual for Color Index mode!\n");
418
}
419
xDisplay = 0; /* to prevent crash in tkCloseWindow */
420
return GL_FALSE;
421
}
422
423
w.cMain = glXCreateContext(xDisplay, w.vInfoMain, NULL,
424
(TK_IS_DIRECT(w.type))?GL_TRUE:GL_FALSE);
425
if (!w.cMain) {
426
fprintf(stderr, "Can't create a context!\n");
427
return GL_FALSE;
428
}
429
430
w.type = GetMainWindowType(w.vInfoMain);
431
432
w.cMapAllocated = 1;
433
if (TK_IS_INDEX(w.type)) {
434
/* Color Indexed windows needs a writable colormap */
435
if (w.vInfoMain->class != StaticColor &&
436
w.vInfoMain->class != StaticGray) {
437
w.cMapMain = XCreateColormap(xDisplay, wRoot, w.vInfoMain->visual,
438
AllocAll);
439
} else {
440
w.cMapMain = XCreateColormap(xDisplay, wRoot, w.vInfoMain->visual,
441
AllocNone);
442
}
443
} else {
444
/* RGB colormap is AllocNone, share the root colormap if possible */
445
Screen *scr = DefaultScreenOfDisplay(xDisplay);
446
int scrnum = DefaultScreen(xDisplay);
447
if (MaxCmapsOfScreen(scr)==1
448
&& w.vInfoMain->visual==DefaultVisual(xDisplay,scrnum)) {
449
/* the window and root are of the same visual type */
450
char *private = getenv("MESA_PRIVATE_CMAP");
451
if (private) {
452
/* user doesn't want to share colormaps */
453
w.cMapMain = XCreateColormap(xDisplay, wRoot,
454
w.vInfoMain->visual, AllocNone);
455
}
456
else {
457
/* share the root colormap */
458
w.cMapMain = DefaultColormap(xDisplay,scrnum);
459
}
460
}
461
else {
462
/* window and root are different visual types, allocate new cmap */
463
/**** [email protected]: Added initialization for HP color recovery *******/
464
Atom hp_cr_maps = XInternAtom(xDisplay, "_HP_RGB_SMOOTH_MAP_LIST", True);
465
w.cMapMain = 0;
466
if (hp_cr_maps) {
467
XStandardColormap* colmaps = 0;
468
int nrColmaps = 0;
469
int i;
470
XGetRGBColormaps( xDisplay, RootWindow(xDisplay, scrnum)
471
, &colmaps, &nrColmaps, hp_cr_maps);
472
for (i=0; i<nrColmaps; i++) {
473
if (colmaps[i].visualid == w.vInfoMain->visual->visualid) {
474
w.cMapMain = colmaps[i].colormap;
475
w.cMapAllocated = 0;
476
break;
477
}
478
}
479
} /*** end HP color recovery ***/
480
if (!w.cMapMain) {
481
if (w.vInfoMain->class==DirectColor) {
482
w.cMapMain = XCreateColormap(xDisplay, wRoot,
483
w.vInfoMain->visual, AllocAll);
484
}
485
else {
486
w.cMapMain = XCreateColormap(xDisplay, wRoot,
487
w.vInfoMain->visual, AllocNone);
488
}
489
}
490
}
491
}
492
if (TK_IS_INDEX(w.type) || w.vInfoMain->class==DirectColor) {
493
tkSetRGBMap(256, colorMaps);
494
}
495
wa.colormap = w.cMapMain;
496
wa.background_pixmap = None;
497
wa.border_pixel = 0;
498
wa.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask |
499
ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
500
w.wMain = XCreateWindow(xDisplay, wRoot, w.x, w.y, w.w, w.h, 0,
501
w.vInfoMain->depth, InputOutput,
502
w.vInfoMain->visual,
503
CWBackPixmap|CWBorderPixel|CWEventMask|CWColormap,
504
&wa);
505
506
/*OLD: XInstallColormap( xDisplay, w.cMapMain );*/
507
XSetWMColormapWindows( xDisplay, w.wMain, &w.wMain, 1 );
508
509
XStringListToTextProperty(&title, 1, &tp);
510
sh.flags = USPosition | USSize;
511
XSetWMProperties(xDisplay, w.wMain, &tp, &tp, 0, 0, &sh, 0, 0);
512
deleteWindowAtom = XInternAtom(xDisplay, "WM_DELETE_WINDOW", False);
513
XSetWMProtocols(xDisplay, w.wMain, &deleteWindowAtom, 1);
514
XMapWindow(xDisplay, w.wMain);
515
drawAllowFlag = GL_FALSE;
516
XIfEvent(xDisplay, &e, WaitForMainWindow, 0);
517
518
if (overlayFlag == GL_TRUE) {
519
w.vInfoOverlay = FindOverlayVisual();
520
if (w.vInfoOverlay) {
521
w.cOverlay = glXCreateContext(xDisplay, w.vInfoOverlay, None,
522
GL_TRUE);
523
w.cMapOverlay = XCreateColormap(xDisplay, wRoot,
524
w.vInfoOverlay->visual, AllocNone);
525
tkSetOverlayMap(256, colorMaps);
526
wa.colormap = w.cMapOverlay;
527
wa.background_pixmap = None;
528
wa.border_pixel = 0;
529
w.wOverlay = XCreateWindow(xDisplay, w.wMain, 0, 0, w.w, w.h, 0,
530
w.vInfoOverlay->depth, InputOutput,
531
w.vInfoOverlay->visual,
532
CWBackPixmap|CWBorderPixel|CWColormap,
533
&wa);
534
XMapWindow(xDisplay, w.wOverlay);
535
XSetWMColormapWindows(xDisplay, w.wMain, &w.wOverlay, 1);
536
w.type |= TK_OVERLAY;
537
} else {
538
fprintf(stderr, "Can't create a overlay plane!\n");
539
}
540
}
541
542
if (!glXMakeCurrent(xDisplay, w.wMain, w.cMain)) {
543
fprintf(stderr, "Can't make window current drawable!\n");
544
return GL_FALSE;
545
}
546
XFlush(xDisplay);
547
548
return GL_TRUE;
549
}
550
551
/******************************************************************************/
552
553
void tkQuit(void)
554
{
555
556
tkCloseWindow();
557
exit(0);
558
}
559
560
/******************************************************************************/
561
562
void tkSwapBuffers(void)
563
{
564
565
if (xDisplay) {
566
glXSwapBuffers(xDisplay, w.wMain);
567
}
568
}
569
570
/******************************************************************************/
571
572