Repository navigation
Expand file tree
/
Copy pathnanox.c
More file actions
459 lines (393 loc
10BC8
) · 12.2 KB
/
Copy pathnanox.c
File metadata and controls
459 lines (393 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/*
* nanox.c
*
* Replacements for some comomon Xlib functions
* Licence: The wxWidgets licence
*/
#include "wx/setup.h"
#if wxUSE_NANOX
#include <ctype.h>
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include "wx/defs.h"
#include "wx/x11/nanox/X11/Xlib.h"
/* Expands to some compatibility functions (see XtoNX.h) */
STATIC_FUNCTIONS
static GR_PALETTE* s_globalColormap = 0;
Colormap DefaultC
10BC8
olormapOfScreen(Screen* screen)
{
if (!s_globalColormap)
{
s_globalColormap = (GR_PALETTE*) malloc(sizeof(GR_PALETTE));
GrGetSystemPalette(s_globalColormap);
}
return s_globalColormap;
}
int XSetGraphicsExposures( Display* display, GC gc, Bool graphics_exposures)
{
return Success ;
}
int XWarpPointer( Display* display, Window srcW, Window destW,
int srcX, int srcY,
unsigned int srcWidth,
unsigned int srcHeight,
int destX, int destY)
{
GrMoveCursor(destX, destY);
return Success;
}
int XSetInputFocus(Display* display, Window focus, int revert_to, Time time)
{
GrSetFocus(focus);
return Success;
}
int XGetInputFocus(Display* display, Window* focus_return, int* revert_to_return)
{
* focus_return = GrGetFocus();
* revert_to_return = 0;
return Success;
}
int XGrabPointer(Display* display, Window grab_window,
Bool owner_events, unsigned int event_mask,
int pointer_mode, int keyboard_mode,
Window confine_to, Cursor cursor, Time time)
{
/* According to comments in srvevent.c in Nano-X, the pointer
* is implicitly grabbed when a mouse button is down.
* We may be able to simulate this further in the event loop.
*/
return Success;
}
int XUngrabPointer(Display* display, Time time)
{
return Success;
}
int XCopyArea(Display* display, Drawable src, Drawable dest, GC gc,
int src_x, int src_y, unsigned int width, unsigned int height,
int dest_x, int dest_y)
{
GrCopyArea(dest, gc, dest_x, dest_y,
width, height, src,
src_x, src_y, 0);
return Success;
}
int XCopyPlane(Display* display, Drawable src, Drawable dest, GC gc,
int src_x, int src_y, unsigned int width, unsigned int height,
int dest_x, int dest_y, unsigned long plane)
{
GrCopyArea(dest, gc, dest_x, dest_y,
width, height, src,
src_x, src_y, 0);
return Success;
}
#if 0
typedef struct {
GR_WINDOW_ID wid; /* window id (or 0 if no such window) */
GR_WINDOW_ID parent; /* parent window id */
GR_WINDOW_ID child; /* first child window id (or 0) */
GR_WINDOW_ID sibling; /* next sibling window id (or 0) */
GR_BOOL inputonly; /* TRUE if window is input only */
GR_BOOL mapped; /* TRUE if window is mapped */
GR_COUNT unmapcount; /* reasons why window is unmapped */
GR_COORD x; /* absolute x position of window */
GR_COORD y; /* absolute y position of window */
GR_SIZE width; /* width of window */
GR_SIZE height; /* height of window */
GR_SIZE bordersize; /* size of border */
GR_COLOR bordercolor; /* color of border */
GR_COLOR background; /* background color */
GR_EVENT_MASK eventmask; /* current event mask for this client */
GR_WM_PROPS props; /* window properties */
GR_CURSOR_ID cursor; /* cursor id*/
unsigned long processid; /* process id of owner*/
} GR_WINDOW_INFO;
typedef struct {
int x, y; /* location of window */
int width, height; /* width and height of window */
int border_width; /* border width of window */
int depth; /* depth of window */
Visual *visual; /* the associated visual structure */
Window root; /* root of screen containing window */
int class; /* InputOutput, InputOnly*/
int bit_gravity; /* one of the bit gravity values */
int win_gravity; /* one of the window gravity values */
int backing_store; /* NotUseful, WhenMapped, Always */
unsigned long backing_planes;/* planes to be preserved if possible */
unsigned long backing_pixel;/* value to be used when restoring planes */
Bool save_under; /* boolean, should bits under be saved? */
Colormap colormap; /* color map to be associated with window */
Bool map_installed; /* boolean, is color map currently installed*/
int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
long all_event_masks; /* set of events all people have interest in*/
long your_event_mask; /* my event mask */
long do_not_propagate_mask;/* set of events that should not propagate */
Bool override_redirect; /* boolean value for override-redirect */
Screen *screen; /* back pointer to correct screen */
} XWindowAttributes;
#endif
Status XGetWindowAttributes(Display* display, Window w,
XWindowAttributes* window_attributes)
{
GR_WINDOW_INFO info;
Window parent = 0;
GrFlush();
GrGetWindowInfo(w, & info);
window_attributes->x = info.x;
window_attributes->y = info.y;
window_attributes->width = info.width;
window_attributes->height = info.height;
window_attributes->border_width = info.bordersize;
window_attributes->depth = 0;
window_attributes->visual = NULL;
window_attributes->root = 0;
window_attributes->_class = info.inputonly ? InputOnly : InputOutput ;
window_attributes->bit_gravity = 0;
window_attributes->win_gravity = 0;
window_attributes->backing_store = 0;
window_attributes->backing_planes = 0;
window_attributes->backing_pixel = 0;
window_attributes->save_under = FALSE;
window_attributes->colormap = DefaultColormapOfScreen(0);
window_attributes->map_installed = FALSE;
window_attributes->map_state = info.mapped ? IsViewable : IsUnmapped ;
window_attributes->all_event_masks = 0;
window_attributes->do_not_propagate_mask = 0;
window_attributes->override_redirect = FALSE;
window_attributes->screen = NULL;
/* We need to check if any parents are unmapped,
* or we will report a window as mapped when it is not.
*/
parent = info.parent;
while (parent)
{
GrGetWindowInfo(parent, & info);
if (info.mapped == 0)
window_attributes->map_state = IsUnmapped;
parent = info.parent;
}
return 1;
}
static XErrorHandler* g_ErrorHandler = NULL;
void DefaultNanoXErrorHandler(GR_EVENT_ERROR* ep)
{
if (g_ErrorHandler)
{
XErrorEvent errEvent;
errEvent.type = ep->type;
errEvent.display = NULL;
errEvent.resourceid = ep->id;
errEvent.serial = 0;
errEvent.error_code = ep->code;
errEvent.request_code = 0;
errEvent.minor_code = 0;
(*g_ErrorHandler)(NULL, & errEvent);
}
}
XErrorHandler XSetErrorHandler (XErrorHandler handler)
{
XErrorHandler oldHandler = g_ErrorHandler;
g_ErrorHandler = handler;
GrSetErrorHandler(DefaultNanoXErrorHandler);
return oldHandler;
}
static Screen s_screen;
Screen *XScreenOfDisplay(Display* display,
int screen_number)
{
/* TODO: fill in the members. See Xlib.h */
return & s_screen;
}
int DisplayWidth(Display* display, int screen)
{
return _display.display_width;
}
int DisplayHeight(Display* display, int screen)
{
return _display.display_height;
}
int DefaultDepth(Display* display, int screen)
{
return _display.display_bpp;
}
int XAllocColor(Display* display, Colormap cmap,
XColor* color)
{
GR_PIXELVAL pixel;
GrFindColor(GR_RGB(color->red, color->green, color->blue), & pixel);
color->pixel = pixel;
return 1;
}
typedef struct {
const char* name;
unsigned int red;
unsigned int green;
unsigned int blue;
} _wxColourEntry;
static _wxColourEntry _wxColourDatabase[] =
{
{ "WHITE", 255, 255, 255 },
{ "BLACK", 0, 0, 0 },
{ "RED", 255, 0, 0 },
{ "GREEN", 0, 255, 0 },
{ "BLUE", 0, 255, 255 },
{ "GREY", 128, 128, 128 },
{ "GRAY", 128, 128, 128 },
{ "LIGHT GREY", 192, 192, 192 },
{ "LIGHT GRAY", 192, 192, 192 },
{ "DARK GREY", 32, 32, 32 },
{ "DARK GRAY", 32, 32, 32 },
{ "CYAN", 0, 255, 255 },
{ "MAGENTA", 255, 255, 0 },
/* TODO: the rest */
{ NULL, 0, 0, 0 }
};
int XParseColor(Display* display, Colormap cmap,
const char* cname, XColor* color)
{
int i = 0;
for (;;)
{
if (!_wxColourDatabase[i].name)
break;
else
{
if (strcmp(cname, _wxColourDatabase[i].name) == 0)
{
color->red = _wxColourDatabase[i].red;
color->green = _wxColourDatabase[i].green;
color->blue = _wxColourDatabase[i].blue;
return 1;
}
i ++;
}
}
/* Not found: use black */
color->red = 0;
color->green = 0;
color->blue = 0;
return 0;
}
int XDrawLine(Display* display, Window win, GC gc,
int x1, int y1, int x2, int y2)
{
GR_POINT points[2];
points[0].x = x1;
points[0].y = y1;
points[1].x = x2;
points[1].y = y2;
GrDrawLines(win, gc, points, 2);
return 1;
}
int XTextExtents( XFontStruct* font, char* s, int len, int* direction,
int* ascent, int* descent2, XCharStruct* overall)
{
GR_SIZE retwidth, retheight, retbase;
GR_GC_ID gc = GrNewGC();
*ascent = font->info.baseline;
*direction = 1; /* ? */
*descent2 = 0; /* ? */
GrSetGCFont(gc, font->fid);
/* TODO need to set the relevant flags for the character set.
* A good trick might be to pass a wxString instead of char*
* to this function.
*/
GrGetGCTextSize(gc, s, len, GR_TFASCII, & retwidth,
& retheight, & retbase);
if (overall)
{
overall->width = retwidth;
overall->lbearing = 0;
overall->rbearing = 0;
overall->ascent = *ascent;
overall->descent = 0;
overall->attributes = 0;
}
GrDestroyGC(gc);
return 1;
}
XFontStruct* XLoadQueryFont(Display* display, const char* fontSpec)
{
/* TODO: map fontSpec to something sensible for Nano-X */
char *fontName = NULL;
XFontStruct* fontInfo = malloc(sizeof(XFontStruct));
fontInfo->fid = GrCreateFont(fontName, 0, 0);
GrGetFontInfo(fontInfo->fid, & fontInfo->info);
printf("Warning: should not call XLoadQueryFont since font spec is not used in Nano-X.\n");
return fontInfo;
}
int XFreeFont(Display* display, XFontStruct* fontStruct)
{
GrDestroyFont(fontStruct->fid);
free(fontStruct);
return 1;
}
int XQueryColor(Display* display, Colormap cmap, XColor* color)
{
/* cmap is a GR_PALETTE */
if (color->pixel < cmap->count)
{
color->red = cmap->palette[color->pixel].r;
color->green = cmap->palette[color->pixel].g;
color->blue = cmap->palette[color->pixel].b;
return 1;
}
else
return 0;
}
int XConfigureWindow(Display* display, Window w, int mask, XWindowChanges* changes)
{
if ((mask & CWX) && (mask & CWY))
GrMoveWindow(w, changes->x, changes->y);
if ((mask & CWWidth) && (mask & CWHeight))
GrResizeWindow(w, changes->width, changes->height);
if (mask & CWBorderWidth)
{
/* TODO */
}
if (mask & CWSibling)
{
/* TODO */
}
if (mask & CWStackMode)
{
/* TODO */
}
return 1;
}
int XTranslateCoordinates(Display* display, Window srcWindow, Window destWindow, int srcX, int srcY, int* destX, int* destY, Window* childReturn)
{
int offx = 0;
int offy = 0;
Window w = srcWindow;
while (w != GR_ROOT_WINDOW_ID)
{
GR_WINDOW_INFO info;
GrGetWindowInfo(w, & info);
w = info.parent;
offx += info.x ;
offy += info.y ;
}
w = destWindow;
while (w != GR_ROOT_WINDOW_ID)
{
GR_WINDOW_INFO info;
GrGetWindowInfo(w, & info);
w = info.parent;
offx -= info.x ;
offy -= info.y ;
}
*destX = srcX + offx;
*destY = srcY + offy;
if (childReturn)
*childReturn = 0;
return 1;
}
/* Should not really be necessary but in no-optimize mode
* gcc complains that wxNoop is not found if wxNoop is inline.
*/
void wxNoop()
{
}
#endif
/* wxUSE_NANOX */