29 |
extern BOOL sendmotion; |
extern BOOL sendmotion; |
30 |
extern BOOL fullscreen; |
extern BOOL fullscreen; |
31 |
extern BOOL grab_keyboard; |
extern BOOL grab_keyboard; |
32 |
|
extern BOOL hide_decorations; |
33 |
extern char title[]; |
extern char title[]; |
34 |
|
extern int server_bpp; |
35 |
BOOL enable_compose = False; |
BOOL enable_compose = False; |
36 |
|
BOOL focused; |
37 |
|
BOOL mouse_in_wnd; |
38 |
|
|
39 |
Display *display; |
Display *display; |
40 |
static int x_socket; |
static int x_socket; |
48 |
static XIC IC; |
static XIC IC; |
49 |
static XModifierKeymap *mod_map; |
static XModifierKeymap *mod_map; |
50 |
static Cursor current_cursor; |
static Cursor current_cursor; |
51 |
|
static Atom protocol_atom, kill_atom; |
52 |
|
|
53 |
/* endianness */ |
/* endianness */ |
54 |
static BOOL host_be; |
static BOOL host_be; |
58 |
static BOOL ownbackstore; |
static BOOL ownbackstore; |
59 |
static Pixmap backstore; |
static Pixmap backstore; |
60 |
|
|
61 |
|
/* MWM decorations */ |
62 |
|
#define MWM_HINTS_DECORATIONS (1L << 1) |
63 |
|
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
64 |
|
typedef struct |
65 |
|
{ |
66 |
|
uint32 flags; |
67 |
|
uint32 functions; |
68 |
|
uint32 decorations; |
69 |
|
sint32 inputMode; |
70 |
|
uint32 status; |
71 |
|
} |
72 |
|
PropMotifWmHints; |
73 |
|
|
74 |
|
typedef struct |
75 |
|
{ |
76 |
|
uint32 red; |
77 |
|
uint32 green; |
78 |
|
uint32 blue; |
79 |
|
} |
80 |
|
PixelColour; |
81 |
|
|
82 |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
#define FILL_RECTANGLE(x,y,cx,cy)\ |
83 |
{ \ |
{ \ |
84 |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
XFillRectangle(display, wnd, gc, x, y, cx, cy); \ |
86 |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
XFillRectangle(display, backstore, gc, x, y, cx, cy); \ |
87 |
} |
} |
88 |
|
|
89 |
|
#define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\ |
90 |
|
{ \ |
91 |
|
XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \ |
92 |
|
} |
93 |
|
|
94 |
/* colour maps */ |
/* colour maps */ |
95 |
|
BOOL owncolmap = False; |
96 |
static Colormap xcolmap; |
static Colormap xcolmap; |
97 |
static uint32 *colmap; |
static uint32 *colmap; |
98 |
|
|
99 |
#define SET_FOREGROUND(col) XSetForeground(display, gc, translate_colour(colmap[col])); |
#define TRANSLATE(col) ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) ) |
100 |
#define SET_BACKGROUND(col) XSetBackground(display, gc, translate_colour(colmap[col])); |
#define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); |
101 |
|
#define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); |
102 |
|
|
103 |
static int rop2_map[] = { |
static int rop2_map[] = { |
104 |
GXclear, /* 0 */ |
GXclear, /* 0 */ |
122 |
#define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); } |
#define SET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, rop2_map[rop2]); } |
123 |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
#define RESET_FUNCTION(rop2) { if (rop2 != ROP2_COPY) XSetFunction(display, gc, GXcopy); } |
124 |
|
|
125 |
|
void |
126 |
|
mwm_hide_decorations(void) |
127 |
|
{ |
128 |
|
PropMotifWmHints motif_hints; |
129 |
|
Atom hintsatom; |
130 |
|
|
131 |
|
/* setup the property */ |
132 |
|
motif_hints.flags = MWM_HINTS_DECORATIONS; |
133 |
|
motif_hints.decorations = 0; |
134 |
|
|
135 |
|
/* get the atom for the property */ |
136 |
|
hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); |
137 |
|
if (!hintsatom) |
138 |
|
{ |
139 |
|
warning("Failed to get atom _MOTIF_WM_HINTS: probably your window manager does not support MWM hints\n"); |
140 |
|
return; |
141 |
|
} |
142 |
|
|
143 |
|
XChangeProperty(display, wnd, hintsatom, hintsatom, 32, PropModeReplace, |
144 |
|
(unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); |
145 |
|
} |
146 |
|
|
147 |
|
PixelColour |
148 |
|
split_colour15(uint32 colour) |
149 |
|
{ |
150 |
|
PixelColour rv; |
151 |
|
rv.red = (colour & 0x7c00) >> 10; |
152 |
|
rv.red = (rv.red * 0xff) / 0x1f; |
153 |
|
rv.green = (colour & 0x03e0) >> 5; |
154 |
|
rv.green = (rv.green * 0xff) / 0x1f; |
155 |
|
rv.blue = (colour & 0x1f); |
156 |
|
rv.blue = (rv.blue * 0xff) / 0x1f; |
157 |
|
return rv; |
158 |
|
} |
159 |
|
|
160 |
|
PixelColour |
161 |
|
split_colour16(uint32 colour) |
162 |
|
{ |
163 |
|
PixelColour rv; |
164 |
|
rv.red = (colour & 0xf800) >> 11; |
165 |
|
rv.red = (rv.red * 0xff) / 0x1f; |
166 |
|
rv.green = (colour & 0x07e0) >> 5; |
167 |
|
rv.green = (rv.green * 0xff) / 0x3f; |
168 |
|
rv.blue = (colour & 0x001f); |
169 |
|
rv.blue = (rv.blue * 0xff) / 0x1f; |
170 |
|
return rv; |
171 |
|
} |
172 |
|
|
173 |
|
PixelColour |
174 |
|
split_colour24(uint32 colour) |
175 |
|
{ |
176 |
|
PixelColour rv; |
177 |
|
rv.blue = (colour & 0xff0000) >> 16; |
178 |
|
rv.green = (colour & 0xff00) >> 8; |
179 |
|
rv.red = (colour & 0xff); |
180 |
|
return rv; |
181 |
|
} |
182 |
|
|
183 |
|
uint32 |
184 |
|
make_colour16(PixelColour pc) |
185 |
|
{ |
186 |
|
pc.red = (pc.red * 0x1f) / 0xff; |
187 |
|
pc.green = (pc.green * 0x3f) / 0xff; |
188 |
|
pc.blue = (pc.blue * 0x1f) / 0xff; |
189 |
|
return (pc.red << 11) | (pc.green << 5) | pc.blue; |
190 |
|
} |
191 |
|
|
192 |
|
uint32 |
193 |
|
make_colour24(PixelColour pc) |
194 |
|
{ |
195 |
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
196 |
|
} |
197 |
|
|
198 |
|
uint32 |
199 |
|
make_colour32(PixelColour pc) |
200 |
|
{ |
201 |
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
202 |
|
} |
203 |
|
|
204 |
|
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
205 |
|
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
206 |
|
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
207 |
|
x = (x << 16) | (x >> 16); } |
208 |
|
|
209 |
|
static uint32 |
210 |
|
translate_colour(uint32 colour) |
211 |
|
{ |
212 |
|
switch (server_bpp) |
213 |
|
{ |
214 |
|
case 15: |
215 |
|
switch (bpp) |
216 |
|
{ |
217 |
|
case 16: |
218 |
|
colour = make_colour16(split_colour15(colour)); |
219 |
|
break; |
220 |
|
case 24: |
221 |
|
colour = make_colour24(split_colour15(colour)); |
222 |
|
break; |
223 |
|
case 32: |
224 |
|
colour = make_colour32(split_colour15(colour)); |
225 |
|
break; |
226 |
|
} |
227 |
|
break; |
228 |
|
case 16: |
229 |
|
switch (bpp) |
230 |
|
{ |
231 |
|
case 16: |
232 |
|
break; |
233 |
|
case 24: |
234 |
|
colour = make_colour24(split_colour16(colour)); |
235 |
|
break; |
236 |
|
case 32: |
237 |
|
colour = make_colour32(split_colour16(colour)); |
238 |
|
break; |
239 |
|
} |
240 |
|
break; |
241 |
|
case 24: |
242 |
|
switch (bpp) |
243 |
|
{ |
244 |
|
case 16: |
245 |
|
colour = make_colour16(split_colour24(colour)); |
246 |
|
break; |
247 |
|
case 24: |
248 |
|
break; |
249 |
|
case 32: |
250 |
|
colour = make_colour32(split_colour24(colour)); |
251 |
|
break; |
252 |
|
} |
253 |
|
break; |
254 |
|
} |
255 |
|
switch (bpp) |
256 |
|
{ |
257 |
|
case 16: |
258 |
|
if (host_be != xserver_be) |
259 |
|
BSWAP16(colour); |
260 |
|
break; |
261 |
|
|
262 |
|
case 24: |
263 |
|
if (xserver_be) |
264 |
|
BSWAP24(colour); |
265 |
|
break; |
266 |
|
|
267 |
|
case 32: |
268 |
|
if (host_be != xserver_be) |
269 |
|
BSWAP32(colour); |
270 |
|
break; |
271 |
|
} |
272 |
|
|
273 |
|
return colour; |
274 |
|
} |
275 |
|
|
276 |
static void |
static void |
277 |
translate8(uint8 * data, uint8 * out, uint8 * end) |
translate8to8(uint8 * data, uint8 * out, uint8 * end) |
278 |
{ |
{ |
279 |
while (out < end) |
while (out < end) |
280 |
*(out++) = (uint8) colmap[*(data++)]; |
*(out++) = (uint8) colmap[*(data++)]; |
281 |
} |
} |
282 |
|
|
283 |
static void |
static void |
284 |
translate16(uint8 * data, uint16 * out, uint16 * end) |
translate8to16(uint8 * data, uint16 * out, uint16 * end) |
285 |
{ |
{ |
286 |
while (out < end) |
while (out < end) |
287 |
*(out++) = (uint16) colmap[*(data++)]; |
*(out++) = (uint16) colmap[*(data++)]; |
289 |
|
|
290 |
/* little endian - conversion happens when colourmap is built */ |
/* little endian - conversion happens when colourmap is built */ |
291 |
static void |
static void |
292 |
translate24(uint8 * data, uint8 * out, uint8 * end) |
translate8to24(uint8 * data, uint8 * out, uint8 * end) |
293 |
{ |
{ |
294 |
uint32 value; |
uint32 value; |
295 |
|
|
303 |
} |
} |
304 |
|
|
305 |
static void |
static void |
306 |
translate32(uint8 * data, uint32 * out, uint32 * end) |
translate8to32(uint8 * data, uint32 * out, uint32 * end) |
307 |
{ |
{ |
308 |
while (out < end) |
while (out < end) |
309 |
*(out++) = colmap[*(data++)]; |
*(out++) = colmap[*(data++)]; |
310 |
} |
} |
311 |
|
|
312 |
static uint8 * |
/* todo the remaining translate function might need some big endian check ?? */ |
313 |
translate_image(int width, int height, uint8 * data) |
|
314 |
|
static void |
315 |
|
translate15to16(uint16 * data, uint16 * out, uint16 * end) |
316 |
{ |
{ |
317 |
int size = width * height * bpp / 8; |
while (out < end) |
318 |
uint8 *out = xmalloc(size); |
*(out++) = (uint16) make_colour16(split_colour15(*(data++))); |
319 |
uint8 *end = out + size; |
} |
320 |
|
|
321 |
switch (bpp) |
static void |
322 |
|
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
323 |
|
{ |
324 |
|
uint32 value; |
325 |
|
|
326 |
|
while (out < end) |
327 |
{ |
{ |
328 |
case 8: |
value = make_colour24(split_colour15(*(data++))); |
329 |
translate8(data, out, end); |
*(out++) = value; |
330 |
break; |
*(out++) = value >> 8; |
331 |
|
*(out++) = value >> 16; |
332 |
|
} |
333 |
|
} |
334 |
|
|
335 |
case 16: |
static void |
336 |
translate16(data, (uint16 *) out, (uint16 *) end); |
translate15to32(uint16 * data, uint32 * out, uint32 * end) |
337 |
break; |
{ |
338 |
|
while (out < end) |
339 |
|
*(out++) = make_colour32(split_colour15(*(data++))); |
340 |
|
} |
341 |
|
|
342 |
case 24: |
static void |
343 |
translate24(data, out, end); |
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
344 |
break; |
{ |
345 |
|
while (out < end) |
346 |
|
*(out++) = (uint16) (*(data++)); |
347 |
|
} |
348 |
|
|
349 |
case 32: |
|
350 |
translate32(data, (uint32 *) out, (uint32 *) end); |
static void |
351 |
break; |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
352 |
|
{ |
353 |
|
uint32 value; |
354 |
|
|
355 |
|
while (out < end) |
356 |
|
{ |
357 |
|
value = make_colour24(split_colour16(*(data++))); |
358 |
|
*(out++) = value; |
359 |
|
*(out++) = value >> 8; |
360 |
|
*(out++) = value >> 16; |
361 |
} |
} |
362 |
|
} |
363 |
|
|
364 |
return out; |
static void |
365 |
|
translate16to32(uint16 * data, uint32 * out, uint32 * end) |
366 |
|
{ |
367 |
|
while (out < end) |
368 |
|
*(out++) = make_colour32(split_colour16(*(data++))); |
369 |
} |
} |
370 |
|
|
371 |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
static void |
372 |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
translate24to16(uint8 * data, uint16 * out, uint16 * end) |
373 |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
{ |
374 |
x = (x << 16) | (x >> 16); } |
uint32 pixel = 0; |
375 |
|
while (out < end) |
376 |
|
{ |
377 |
|
pixel = *(data++) << 16; |
378 |
|
pixel |= *(data++) << 8; |
379 |
|
pixel |= *(data++); |
380 |
|
*(out++) = (uint16) make_colour16(split_colour24(pixel)); |
381 |
|
} |
382 |
|
} |
383 |
|
|
384 |
static uint32 |
static void |
385 |
translate_colour(uint32 colour) |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
386 |
{ |
{ |
387 |
switch (bpp) |
while (out < end) |
388 |
{ |
{ |
389 |
case 16: |
*(out++) = (*(data++)); |
390 |
if (host_be != xserver_be) |
} |
391 |
BSWAP16(colour); |
} |
392 |
break; |
|
393 |
|
static void |
394 |
|
translate24to32(uint8 * data, uint32 * out, uint32 * end) |
395 |
|
{ |
396 |
|
uint32 pixel = 0; |
397 |
|
while (out < end) |
398 |
|
{ |
399 |
|
memcpy(&pixel, data, 3); |
400 |
|
data += 3; |
401 |
|
*(out++) = pixel; |
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
|
static uint8 * |
406 |
|
translate_image(int width, int height, uint8 * data) |
407 |
|
{ |
408 |
|
int size = width * height * bpp / 8; |
409 |
|
uint8 *out = xmalloc(size); |
410 |
|
uint8 *end = out + size; |
411 |
|
|
412 |
|
switch (server_bpp) |
413 |
|
{ |
414 |
case 24: |
case 24: |
415 |
if (xserver_be) |
switch (bpp) |
416 |
BSWAP24(colour); |
{ |
417 |
|
case 32: |
418 |
|
translate24to32(data, (uint32 *) out, (uint32 *) end); |
419 |
|
break; |
420 |
|
case 24: |
421 |
|
translate24to24(data, out, end); |
422 |
|
break; |
423 |
|
case 16: |
424 |
|
translate24to16(data, (uint16 *) out, (uint16 *) end); |
425 |
|
break; |
426 |
|
} |
427 |
break; |
break; |
428 |
|
case 16: |
429 |
case 32: |
switch (bpp) |
430 |
if (host_be != xserver_be) |
{ |
431 |
BSWAP32(colour); |
case 32: |
432 |
|
translate16to32((uint16 *) data, (uint32 *) out, |
433 |
|
(uint32 *) end); |
434 |
|
break; |
435 |
|
case 24: |
436 |
|
translate16to24((uint16 *) data, out, end); |
437 |
|
break; |
438 |
|
case 16: |
439 |
|
translate16to16((uint16 *) data, (uint16 *) out, |
440 |
|
(uint16 *) end); |
441 |
|
break; |
442 |
|
} |
443 |
|
break; |
444 |
|
case 15: |
445 |
|
switch (bpp) |
446 |
|
{ |
447 |
|
case 32: |
448 |
|
translate15to32((uint16 *) data, (uint32 *) out, |
449 |
|
(uint32 *) end); |
450 |
|
break; |
451 |
|
case 24: |
452 |
|
translate15to24((uint16 *) data, out, end); |
453 |
|
break; |
454 |
|
case 16: |
455 |
|
translate15to16((uint16 *) data, (uint16 *) out, |
456 |
|
(uint16 *) end); |
457 |
|
break; |
458 |
|
} |
459 |
|
break; |
460 |
|
case 8: |
461 |
|
switch (bpp) |
462 |
|
{ |
463 |
|
case 8: |
464 |
|
translate8to8(data, out, end); |
465 |
|
break; |
466 |
|
case 16: |
467 |
|
translate8to16(data, (uint16 *) out, (uint16 *) end); |
468 |
|
break; |
469 |
|
case 24: |
470 |
|
translate8to24(data, out, end); |
471 |
|
break; |
472 |
|
case 32: |
473 |
|
translate8to32(data, (uint32 *) out, (uint32 *) end); |
474 |
|
break; |
475 |
|
} |
476 |
break; |
break; |
477 |
} |
} |
478 |
|
return out; |
|
return colour; |
|
479 |
} |
} |
480 |
|
|
481 |
BOOL |
BOOL |
482 |
get_key_state(uint32 keysym, unsigned int state) |
get_key_state(unsigned int state, uint32 keysym) |
483 |
{ |
{ |
484 |
int modifierpos, key, keysymMask = 0; |
int modifierpos, key, keysymMask = 0; |
485 |
int offset; |
int offset; |
513 |
display = XOpenDisplay(NULL); |
display = XOpenDisplay(NULL); |
514 |
if (display == NULL) |
if (display == NULL) |
515 |
{ |
{ |
516 |
error("Failed to open display\n"); |
error("Failed to open display: %s\n", XDisplayName(NULL)); |
517 |
return False; |
return False; |
518 |
} |
} |
519 |
|
|
544 |
return False; |
return False; |
545 |
} |
} |
546 |
|
|
547 |
xcolmap = DefaultColormapOfScreen(screen); |
if (owncolmap != True) |
548 |
|
{ |
549 |
|
xcolmap = DefaultColormapOfScreen(screen); |
550 |
|
if (depth <= 8) |
551 |
|
warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); |
552 |
|
} |
553 |
|
|
554 |
gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); |
gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); |
555 |
|
|
556 |
if (DoesBackingStore(screen) != Always) |
if (DoesBackingStore(screen) != Always) |
560 |
host_be = !(BOOL) (*(uint8 *) (&test)); |
host_be = !(BOOL) (*(uint8 *) (&test)); |
561 |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
xserver_be = (ImageByteOrder(display) == MSBFirst); |
562 |
|
|
563 |
|
if ((width == 0) || (height == 0)) |
564 |
|
{ |
565 |
|
/* Fetch geometry from _NET_WORKAREA */ |
566 |
|
uint32 x, y, cx, cy; |
567 |
|
|
568 |
|
if (get_current_workarea(&x, &y, &cx, &cy) == 0) |
569 |
|
{ |
570 |
|
width = cx; |
571 |
|
height = cy; |
572 |
|
} |
573 |
|
else |
574 |
|
{ |
575 |
|
warning("Failed to get workarea: probably your window manager does not support extended hints\n"); |
576 |
|
width = 800; |
577 |
|
height = 600; |
578 |
|
} |
579 |
|
} |
580 |
|
|
581 |
if (fullscreen) |
if (fullscreen) |
582 |
{ |
{ |
583 |
width = WidthOfScreen(screen); |
width = WidthOfScreen(screen); |
603 |
IM = XOpenIM(display, NULL, NULL, NULL); |
IM = XOpenIM(display, NULL, NULL, NULL); |
604 |
|
|
605 |
xkeymap_init(); |
xkeymap_init(); |
606 |
|
|
607 |
|
/* todo take this out when high colour is done */ |
608 |
|
printf("server bpp %d client bpp %d depth %d\n", server_bpp, bpp, depth); |
609 |
|
|
610 |
return True; |
return True; |
611 |
} |
} |
612 |
|
|
649 |
|
|
650 |
XStoreName(display, wnd, title); |
XStoreName(display, wnd, title); |
651 |
|
|
652 |
|
if (hide_decorations) |
653 |
|
mwm_hide_decorations(); |
654 |
|
|
655 |
classhints = XAllocClassHint(); |
classhints = XAllocClassHint(); |
656 |
if (classhints != NULL) |
if (classhints != NULL) |
657 |
{ |
{ |
671 |
} |
} |
672 |
|
|
673 |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
674 |
StructureNotifyMask | FocusChangeMask; |
VisibilityChangeMask | FocusChangeMask; |
675 |
|
|
676 |
if (sendmotion) |
if (sendmotion) |
677 |
input_mask |= PointerMotionMask; |
input_mask |= PointerMotionMask; |
678 |
if (ownbackstore) |
if (ownbackstore) |
679 |
input_mask |= ExposureMask; |
input_mask |= ExposureMask; |
680 |
|
if (fullscreen || grab_keyboard) |
681 |
|
input_mask |= EnterWindowMask; |
682 |
|
if (grab_keyboard) |
683 |
|
input_mask |= LeaveWindowMask; |
684 |
|
|
685 |
if (IM != NULL) |
if (IM != NULL) |
686 |
{ |
{ |
695 |
XSelectInput(display, wnd, input_mask); |
XSelectInput(display, wnd, input_mask); |
696 |
XMapWindow(display, wnd); |
XMapWindow(display, wnd); |
697 |
|
|
698 |
/* wait for MapNotify */ |
/* wait for VisibilityNotify */ |
699 |
do |
do |
700 |
{ |
{ |
701 |
XMaskEvent(display, StructureNotifyMask, &xevent); |
XMaskEvent(display, VisibilityChangeMask, &xevent); |
702 |
} |
} |
703 |
while (xevent.type != MapNotify); |
while (xevent.type != VisibilityNotify); |
704 |
|
|
705 |
if (fullscreen) |
focused = False; |
706 |
XSetInputFocus(display, wnd, RevertToPointerRoot, CurrentTime); |
mouse_in_wnd = False; |
707 |
|
|
708 |
|
/* handle the WM_DELETE_WINDOW protocol */ |
709 |
|
protocol_atom = XInternAtom(display, "WM_PROTOCOLS", True); |
710 |
|
kill_atom = XInternAtom(display, "WM_DELETE_WINDOW", True); |
711 |
|
XSetWMProtocols(display, wnd, &kill_atom, 1); |
712 |
|
|
713 |
return True; |
return True; |
714 |
} |
} |
747 |
} |
} |
748 |
} |
} |
749 |
|
|
750 |
/* Process all events in Xlib queue */ |
/* Process all events in Xlib queue |
751 |
static void |
Returns 0 after user quit, 1 otherwise */ |
752 |
|
static int |
753 |
xwin_process_events(void) |
xwin_process_events(void) |
754 |
{ |
{ |
755 |
XEvent xevent; |
XEvent xevent; |
777 |
|
|
778 |
switch (xevent.type) |
switch (xevent.type) |
779 |
{ |
{ |
780 |
|
case ClientMessage: |
781 |
|
/* the window manager told us to quit */ |
782 |
|
if ((xevent.xclient.message_type == protocol_atom) |
783 |
|
&& (xevent.xclient.data.l[0] == kill_atom)) |
784 |
|
/* Quit */ |
785 |
|
return 0; |
786 |
|
break; |
787 |
|
|
788 |
case KeyPress: |
case KeyPress: |
789 |
if (IC != NULL) |
if (IC != NULL) |
790 |
/* Multi_key compatible version */ |
/* Multi_key compatible version */ |
807 |
str, sizeof(str), &keysym, NULL); |
str, sizeof(str), &keysym, NULL); |
808 |
} |
} |
809 |
|
|
810 |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym))); |
DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, |
811 |
|
get_ksname(keysym))); |
812 |
|
|
813 |
ev_time = time(NULL); |
ev_time = time(NULL); |
814 |
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) |
859 |
break; |
break; |
860 |
|
|
861 |
case MotionNotify: |
case MotionNotify: |
862 |
|
if (fullscreen && !focused) |
863 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
864 |
|
CurrentTime); |
865 |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
rdp_send_input(time(NULL), RDP_INPUT_MOUSE, |
866 |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); |
867 |
break; |
break; |
868 |
|
|
869 |
case FocusIn: |
case FocusIn: |
870 |
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, &dummy, &dummy, &state); |
if (xevent.xfocus.mode == NotifyGrab) |
871 |
|
break; |
872 |
|
focused = True; |
873 |
|
XQueryPointer(display, wnd, &wdummy, &wdummy, &dummy, &dummy, |
874 |
|
&dummy, &dummy, &state); |
875 |
reset_modifier_keys(state); |
reset_modifier_keys(state); |
876 |
if (grab_keyboard) |
if (grab_keyboard && mouse_in_wnd) |
877 |
XGrabKeyboard(display, wnd, True, |
XGrabKeyboard(display, wnd, True, |
878 |
GrabModeAsync, GrabModeAsync, CurrentTime); |
GrabModeAsync, GrabModeAsync, CurrentTime); |
879 |
break; |
break; |
880 |
|
|
881 |
case FocusOut: |
case FocusOut: |
882 |
|
if (xevent.xfocus.mode == NotifyUngrab) |
883 |
|
break; |
884 |
|
focused = False; |
885 |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
if (xevent.xfocus.mode == NotifyWhileGrabbed) |
886 |
XUngrabKeyboard(display, CurrentTime); |
XUngrabKeyboard(display, CurrentTime); |
887 |
break; |
break; |
888 |
|
|
889 |
|
case EnterNotify: |
890 |
|
/* we only register for this event when in fullscreen mode */ |
891 |
|
/* or grab_keyboard */ |
892 |
|
mouse_in_wnd = True; |
893 |
|
if (fullscreen) |
894 |
|
{ |
895 |
|
XSetInputFocus(display, wnd, RevertToPointerRoot, |
896 |
|
CurrentTime); |
897 |
|
break; |
898 |
|
} |
899 |
|
if (focused) |
900 |
|
XGrabKeyboard(display, wnd, True, |
901 |
|
GrabModeAsync, GrabModeAsync, CurrentTime); |
902 |
|
break; |
903 |
|
|
904 |
|
case LeaveNotify: |
905 |
|
/* we only register for this event when grab_keyboard */ |
906 |
|
mouse_in_wnd = False; |
907 |
|
XUngrabKeyboard(display, CurrentTime); |
908 |
|
break; |
909 |
|
|
910 |
case Expose: |
case Expose: |
911 |
XCopyArea(display, backstore, wnd, gc, |
XCopyArea(display, backstore, wnd, gc, |
912 |
xevent.xexpose.x, xevent.xexpose.y, |
xevent.xexpose.x, xevent.xexpose.y, |
931 |
|
|
932 |
} |
} |
933 |
} |
} |
934 |
|
/* Keep going */ |
935 |
|
return 1; |
936 |
} |
} |
937 |
|
|
938 |
void |
/* Returns 0 after user quit, 1 otherwise */ |
939 |
|
int |
940 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
941 |
{ |
{ |
942 |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
int n = (rdp_socket > x_socket) ? rdp_socket + 1 : x_socket + 1; |
947 |
while (True) |
while (True) |
948 |
{ |
{ |
949 |
/* Process any events already waiting */ |
/* Process any events already waiting */ |
950 |
xwin_process_events(); |
if (!xwin_process_events()) |
951 |
|
/* User quit */ |
952 |
|
return 0; |
953 |
|
|
954 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
955 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
965 |
} |
} |
966 |
|
|
967 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
968 |
return; |
return 1; |
969 |
} |
} |
970 |
} |
} |
971 |
|
|
982 |
Pixmap bitmap; |
Pixmap bitmap; |
983 |
uint8 *tdata; |
uint8 *tdata; |
984 |
|
|
985 |
tdata = translate_image(width, height, data); |
tdata = (owncolmap ? data : translate_image(width, height, data)); |
986 |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
bitmap = XCreatePixmap(display, wnd, width, height, depth); |
987 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
988 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
989 |
|
|
990 |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
991 |
|
|
992 |
XFree(image); |
XFree(image); |
993 |
xfree(tdata); |
if (!owncolmap) |
994 |
|
xfree(tdata); |
995 |
return (HBITMAP) bitmap; |
return (HBITMAP) bitmap; |
996 |
} |
} |
997 |
|
|
1000 |
{ |
{ |
1001 |
XImage *image; |
XImage *image; |
1002 |
uint8 *tdata; |
uint8 *tdata; |
1003 |
|
tdata = (owncolmap ? data : translate_image(width, height, data)); |
|
tdata = translate_image(width, height, data); |
|
1004 |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
image = XCreateImage(display, visual, depth, ZPixmap, 0, |
1005 |
(char *) tdata, width, height, 8, 0); |
(char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); |
1006 |
|
|
1007 |
if (ownbackstore) |
if (ownbackstore) |
1008 |
{ |
{ |
1015 |
} |
} |
1016 |
|
|
1017 |
XFree(image); |
XFree(image); |
1018 |
xfree(tdata); |
if (!owncolmap) |
1019 |
|
xfree(tdata); |
1020 |
} |
} |
1021 |
|
|
1022 |
void |
void |
1147 |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
(xc)->blue = ((c)->blue << 8) | (c)->blue; \ |
1148 |
(xc)->flags = DoRed | DoGreen | DoBlue; |
(xc)->flags = DoRed | DoGreen | DoBlue; |
1149 |
|
|
1150 |
|
|
1151 |
HCOLOURMAP |
HCOLOURMAP |
1152 |
ui_create_colourmap(COLOURMAP * colours) |
ui_create_colourmap(COLOURMAP * colours) |
1153 |
{ |
{ |
1154 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
1155 |
int i, ncolours = colours->ncolours; |
int i, ncolours = colours->ncolours; |
1156 |
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
if (!owncolmap) |
|
XColor xentry; |
|
|
XColor xc_cache[256]; |
|
|
uint32 colour; |
|
|
int colLookup = 256; |
|
|
for (i = 0; i < ncolours; i++) |
|
1157 |
{ |
{ |
1158 |
entry = &colours->colours[i]; |
uint32 *map = xmalloc(sizeof(*colmap) * ncolours); |
1159 |
MAKE_XCOLOR(&xentry, entry); |
XColor xentry; |
1160 |
|
XColor xc_cache[256]; |
1161 |
if (XAllocColor(display, xcolmap, &xentry) == 0) |
uint32 colour; |
1162 |
|
int colLookup = 256; |
1163 |
|
for (i = 0; i < ncolours; i++) |
1164 |
{ |
{ |
1165 |
/* Allocation failed, find closest match. */ |
entry = &colours->colours[i]; |
1166 |
int j = 256; |
MAKE_XCOLOR(&xentry, entry); |
|
int nMinDist = 3 * 256 * 256; |
|
|
long nDist = nMinDist; |
|
1167 |
|
|
1168 |
/* only get the colors once */ |
if (XAllocColor(display, xcolmap, &xentry) == 0) |
|
while (colLookup--) |
|
1169 |
{ |
{ |
1170 |
xc_cache[colLookup].pixel = colLookup; |
/* Allocation failed, find closest match. */ |
1171 |
xc_cache[colLookup].red = xc_cache[colLookup].green = |
int j = 256; |
1172 |
xc_cache[colLookup].blue = 0; |
int nMinDist = 3 * 256 * 256; |
1173 |
xc_cache[colLookup].flags = 0; |
long nDist = nMinDist; |
|
XQueryColor(display, |
|
|
DefaultColormap(display, DefaultScreen(display)), |
|
|
&xc_cache[colLookup]); |
|
|
} |
|
|
colLookup = 0; |
|
1174 |
|
|
1175 |
/* approximate the pixel */ |
/* only get the colors once */ |
1176 |
while (j--) |
while (colLookup--) |
|
{ |
|
|
if (xc_cache[j].flags) |
|
1177 |
{ |
{ |
1178 |
nDist = ((long) (xc_cache[j].red >> 8) - |
xc_cache[colLookup].pixel = colLookup; |
1179 |
(long) (xentry.red >> 8)) * |
xc_cache[colLookup].red = xc_cache[colLookup].green = |
1180 |
((long) (xc_cache[j].red >> 8) - |
xc_cache[colLookup].blue = 0; |
1181 |
(long) (xentry.red >> 8)) + |
xc_cache[colLookup].flags = 0; |
1182 |
((long) (xc_cache[j].green >> 8) - |
XQueryColor(display, |
1183 |
(long) (xentry.green >> 8)) * |
DefaultColormap(display, |
1184 |
((long) (xc_cache[j].green >> 8) - |
DefaultScreen(display)), |
1185 |
(long) (xentry.green >> 8)) + |
&xc_cache[colLookup]); |
|
((long) (xc_cache[j].blue >> 8) - |
|
|
(long) (xentry.blue >> 8)) * |
|
|
((long) (xc_cache[j].blue >> 8) - |
|
|
(long) (xentry.blue >> 8)); |
|
1186 |
} |
} |
1187 |
if (nDist < nMinDist) |
colLookup = 0; |
1188 |
|
|
1189 |
|
/* approximate the pixel */ |
1190 |
|
while (j--) |
1191 |
{ |
{ |
1192 |
nMinDist = nDist; |
if (xc_cache[j].flags) |
1193 |
xentry.pixel = j; |
{ |
1194 |
|
nDist = ((long) (xc_cache[j].red >> 8) - |
1195 |
|
(long) (xentry.red >> 8)) * |
1196 |
|
((long) (xc_cache[j].red >> 8) - |
1197 |
|
(long) (xentry.red >> 8)) + |
1198 |
|
((long) (xc_cache[j].green >> 8) - |
1199 |
|
(long) (xentry.green >> 8)) * |
1200 |
|
((long) (xc_cache[j].green >> 8) - |
1201 |
|
(long) (xentry.green >> 8)) + |
1202 |
|
((long) (xc_cache[j].blue >> 8) - |
1203 |
|
(long) (xentry.blue >> 8)) * |
1204 |
|
((long) (xc_cache[j].blue >> 8) - |
1205 |
|
(long) (xentry.blue >> 8)); |
1206 |
|
} |
1207 |
|
if (nDist < nMinDist) |
1208 |
|
{ |
1209 |
|
nMinDist = nDist; |
1210 |
|
xentry.pixel = j; |
1211 |
|
} |
1212 |
} |
} |
1213 |
} |
} |
1214 |
|
colour = xentry.pixel; |
1215 |
|
|
1216 |
|
/* update our cache */ |
1217 |
|
if (xentry.pixel < 256) |
1218 |
|
{ |
1219 |
|
xc_cache[xentry.pixel].red = xentry.red; |
1220 |
|
xc_cache[xentry.pixel].green = xentry.green; |
1221 |
|
xc_cache[xentry.pixel].blue = xentry.blue; |
1222 |
|
|
1223 |
|
} |
1224 |
|
|
1225 |
|
|
1226 |
|
/* byte swap here to make translate_image faster */ |
1227 |
|
map[i] = translate_colour(colour); |
1228 |
} |
} |
1229 |
colour = xentry.pixel; |
return map; |
1230 |
|
} |
1231 |
|
else |
1232 |
|
{ |
1233 |
|
XColor *xcolours, *xentry; |
1234 |
|
Colormap map; |
1235 |
|
|
1236 |
/* update our cache */ |
xcolours = xmalloc(sizeof(XColor) * ncolours); |
1237 |
if (xentry.pixel < 256) |
for (i = 0; i < ncolours; i++) |
1238 |
{ |
{ |
1239 |
xc_cache[xentry.pixel].red = xentry.red; |
entry = &colours->colours[i]; |
1240 |
xc_cache[xentry.pixel].green = xentry.green; |
xentry = &xcolours[i]; |
1241 |
xc_cache[xentry.pixel].blue = xentry.blue; |
xentry->pixel = i; |
1242 |
|
MAKE_XCOLOR(xentry, entry); |
1243 |
} |
} |
1244 |
|
|
1245 |
|
map = XCreateColormap(display, wnd, visual, AllocAll); |
1246 |
|
XStoreColors(display, map, xcolours, ncolours); |
1247 |
|
|
1248 |
/* byte swap here to make translate_image faster */ |
xfree(xcolours); |
1249 |
map[i] = translate_colour(colour); |
return (HCOLOURMAP) map; |
1250 |
} |
} |
|
|
|
|
return map; |
|
1251 |
} |
} |
1252 |
|
|
1253 |
void |
void |
1254 |
ui_destroy_colourmap(HCOLOURMAP map) |
ui_destroy_colourmap(HCOLOURMAP map) |
1255 |
{ |
{ |
1256 |
xfree(map); |
if (!owncolmap) |
1257 |
|
xfree(map); |
1258 |
|
else |
1259 |
|
XFreeColormap(display, (Colormap) map); |
1260 |
} |
} |
1261 |
|
|
1262 |
void |
void |
1263 |
ui_set_colourmap(HCOLOURMAP map) |
ui_set_colourmap(HCOLOURMAP map) |
1264 |
{ |
{ |
1265 |
colmap = map; |
if (!owncolmap) |
1266 |
|
colmap = map; |
1267 |
|
else |
1268 |
|
XSetWindowColormap(display, wnd, (Colormap) map); |
1269 |
} |
} |
1270 |
|
|
1271 |
void |
void |
1428 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE(x, y, cx, cy); |
1429 |
} |
} |
1430 |
|
|
1431 |
|
/* warning, this function only draws on wnd or backstore, not both */ |
1432 |
void |
void |
1433 |
ui_draw_glyph(int mixmode, |
ui_draw_glyph(int mixmode, |
1434 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
1443 |
XSetStipple(display, gc, (Pixmap) glyph); |
XSetStipple(display, gc, (Pixmap) glyph); |
1444 |
XSetTSOrigin(display, gc, x, y); |
XSetTSOrigin(display, gc, x, y); |
1445 |
|
|
1446 |
FILL_RECTANGLE(x, y, cx, cy); |
FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); |
1447 |
|
|
1448 |
XSetFillStyle(display, gc, FillSolid); |
XSetFillStyle(display, gc, FillSolid); |
1449 |
} |
} |
1472 |
}\ |
}\ |
1473 |
if (glyph != NULL)\ |
if (glyph != NULL)\ |
1474 |
{\ |
{\ |
1475 |
ui_draw_glyph (mixmode, x + (short) glyph->offset,\ |
ui_draw_glyph (mixmode, x + glyph->offset,\ |
1476 |
y + (short) glyph->baseline,\ |
y + glyph->baseline,\ |
1477 |
glyph->width, glyph->height,\ |
glyph->width, glyph->height,\ |
1478 |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
glyph->pixmap, 0, 0, bgcolour, fgcolour);\ |
1479 |
if (flags & TEXT2_IMPLICIT_X)\ |
if (flags & TEXT2_IMPLICIT_X)\ |
1495 |
|
|
1496 |
if (boxcx > 1) |
if (boxcx > 1) |
1497 |
{ |
{ |
1498 |
FILL_RECTANGLE(boxx, boxy, boxcx, boxcy); |
FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); |
1499 |
} |
} |
1500 |
else if (mixmode == MIX_OPAQUE) |
else if (mixmode == MIX_OPAQUE) |
1501 |
{ |
{ |
1502 |
FILL_RECTANGLE(clipx, clipy, clipcx, clipcy); |
FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); |
1503 |
} |
} |
1504 |
|
|
1505 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
1513 |
else |
else |
1514 |
{ |
{ |
1515 |
error("this shouldn't be happening\n"); |
error("this shouldn't be happening\n"); |
1516 |
break; |
exit(1); |
1517 |
} |
} |
1518 |
/* this will move pointer from start to first character after FF command */ |
/* this will move pointer from start to first character after FF command */ |
1519 |
length -= i + 3; |
length -= i + 3; |
1533 |
else |
else |
1534 |
x += text[i + 2]; |
x += text[i + 2]; |
1535 |
} |
} |
|
if (i + 2 < length) |
|
|
i += 3; |
|
|
else |
|
|
i += 2; |
|
|
length -= i; |
|
|
/* this will move pointer from start to first character after FE command */ |
|
|
text = &(text[i]); |
|
|
i = 0; |
|
1536 |
for (j = 0; j < entry->size; j++) |
for (j = 0; j < entry->size; j++) |
1537 |
DO_GLYPH(((uint8 *) (entry->data)), j); |
DO_GLYPH(((uint8 *) (entry->data)), j); |
1538 |
} |
} |
1539 |
|
if (i + 2 < length) |
1540 |
|
i += 3; |
1541 |
|
else |
1542 |
|
i += 2; |
1543 |
|
length -= i; |
1544 |
|
/* this will move pointer from start to first character after FE command */ |
1545 |
|
text = &(text[i]); |
1546 |
|
i = 0; |
1547 |
break; |
break; |
1548 |
|
|
1549 |
default: |
default: |
1552 |
break; |
break; |
1553 |
} |
} |
1554 |
} |
} |
1555 |
|
if (ownbackstore) |
1556 |
|
{ |
1557 |
|
if (boxcx > 1) |
1558 |
|
XCopyArea(display, backstore, wnd, gc, boxx, |
1559 |
|
boxy, boxcx, boxcy, boxx, boxy); |
1560 |
|
else |
1561 |
|
XCopyArea(display, backstore, wnd, gc, clipx, |
1562 |
|
clipy, clipcx, clipcy, clipx, clipy); |
1563 |
|
} |
1564 |
} |
} |
1565 |
|
|
1566 |
void |
void |