20 |
|
|
21 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
22 |
#include <X11/Xutil.h> |
#include <X11/Xutil.h> |
23 |
|
#include <unistd.h> |
24 |
#include <time.h> |
#include <time.h> |
25 |
#include <errno.h> |
#include <errno.h> |
26 |
#include "rdesktop.h" |
#include "rdesktop.h" |
35 |
extern char g_title[]; |
extern char g_title[]; |
36 |
extern int g_server_bpp; |
extern int g_server_bpp; |
37 |
extern int g_win_button_size; |
extern int g_win_button_size; |
|
BOOL g_enable_compose = False; |
|
|
BOOL g_focused; |
|
|
BOOL g_mouse_in_wnd; |
|
38 |
|
|
39 |
Display *g_display; |
Display *g_display; |
40 |
Time g_last_gesturetime; |
Time g_last_gesturetime; |
41 |
static int g_x_socket; |
static int g_x_socket; |
42 |
static Screen *g_screen; |
static Screen *g_screen; |
43 |
Window g_wnd; |
Window g_wnd; |
44 |
|
BOOL g_enable_compose = False; |
45 |
static GC g_gc; |
static GC g_gc; |
46 |
static Visual *g_visual; |
static Visual *g_visual; |
47 |
static int g_depth; |
static int g_depth; |
50 |
static XIC g_IC; |
static XIC g_IC; |
51 |
static XModifierKeymap *g_mod_map; |
static XModifierKeymap *g_mod_map; |
52 |
static Cursor g_current_cursor; |
static Cursor g_current_cursor; |
53 |
|
static HCURSOR g_null_cursor; |
54 |
static Atom g_protocol_atom, g_kill_atom; |
static Atom g_protocol_atom, g_kill_atom; |
55 |
|
static BOOL g_focused; |
56 |
|
static BOOL g_mouse_in_wnd; |
57 |
|
|
58 |
/* endianness */ |
/* endianness */ |
59 |
static BOOL g_host_be; |
static BOOL g_host_be; |
60 |
static BOOL g_xserver_be; |
static BOOL g_xserver_be; |
61 |
|
static int g_red_shift_r, g_blue_shift_r, g_green_shift_r; |
62 |
|
static int g_red_shift_l, g_blue_shift_l, g_green_shift_l; |
63 |
|
|
64 |
/* software backing store */ |
/* software backing store */ |
65 |
static BOOL g_ownbackstore; |
static BOOL g_ownbackstore; |
73 |
#ifdef WITH_RDPSND |
#ifdef WITH_RDPSND |
74 |
extern int g_dsp_fd; |
extern int g_dsp_fd; |
75 |
extern BOOL g_dsp_busy; |
extern BOOL g_dsp_busy; |
76 |
|
extern BOOL g_rdpsnd; |
77 |
#endif |
#endif |
78 |
|
|
79 |
/* MWM decorations */ |
/* MWM decorations */ |
115 |
static Colormap g_xcolmap; |
static Colormap g_xcolmap; |
116 |
static uint32 *g_colmap = NULL; |
static uint32 *g_colmap = NULL; |
117 |
|
|
118 |
#define TRANSLATE(col) ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : translate_colour(g_colmap[col]) ) |
#define TRANSLATE(col) ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] ) |
119 |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
#define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); |
120 |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
#define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); |
121 |
|
|
200 |
} |
} |
201 |
|
|
202 |
static uint32 |
static uint32 |
203 |
make_colour16(PixelColour pc) |
make_colour(PixelColour pc) |
|
{ |
|
|
pc.red = (pc.red * 0x1f) / 0xff; |
|
|
pc.green = (pc.green * 0x3f) / 0xff; |
|
|
pc.blue = (pc.blue * 0x1f) / 0xff; |
|
|
return (pc.red << 11) | (pc.green << 5) | pc.blue; |
|
|
} |
|
|
|
|
|
static uint32 |
|
|
make_colour24(PixelColour pc) |
|
|
{ |
|
|
if (g_xserver_be) |
|
|
{ |
|
|
return pc.red | (pc.green << 8) | (pc.blue << 16); |
|
|
} |
|
|
else |
|
|
{ |
|
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
|
|
} |
|
|
} |
|
|
|
|
|
static uint32 |
|
|
make_colour32(PixelColour pc) |
|
204 |
{ |
{ |
205 |
if (g_xserver_be) |
return (((pc.red >> g_red_shift_r) << g_red_shift_l) |
206 |
{ |
| ((pc.green >> g_green_shift_r) << g_green_shift_l) |
207 |
return pc.red | (pc.green << 8) | (pc.blue << 16); |
| ((pc.blue >> g_blue_shift_r) << g_blue_shift_l)); |
|
} |
|
|
else |
|
|
{ |
|
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
|
|
} |
|
208 |
} |
} |
209 |
|
|
210 |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
211 |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } |
#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | (x & 0xff00)); } |
212 |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ |
213 |
x = (x << 16) | (x >> 16); } |
x = (x << 16) | (x >> 16); } |
214 |
|
|
215 |
static uint32 |
static uint32 |
216 |
translate_colour(uint32 colour) |
translate_colour(uint32 colour) |
217 |
{ |
{ |
218 |
|
PixelColour pc; |
219 |
switch (g_server_bpp) |
switch (g_server_bpp) |
220 |
{ |
{ |
221 |
case 15: |
case 15: |
222 |
switch (g_bpp) |
pc = split_colour15(colour); |
|
{ |
|
|
case 16: |
|
|
colour = make_colour16(split_colour15(colour)); |
|
|
break; |
|
|
case 24: |
|
|
colour = make_colour24(split_colour15(colour)); |
|
|
break; |
|
|
case 32: |
|
|
colour = make_colour32(split_colour15(colour)); |
|
|
break; |
|
|
} |
|
223 |
break; |
break; |
224 |
case 16: |
case 16: |
225 |
switch (g_bpp) |
pc = split_colour16(colour); |
|
{ |
|
|
case 16: |
|
|
break; |
|
|
case 24: |
|
|
colour = make_colour24(split_colour16(colour)); |
|
|
break; |
|
|
case 32: |
|
|
colour = make_colour32(split_colour16(colour)); |
|
|
break; |
|
|
} |
|
226 |
break; |
break; |
227 |
case 24: |
case 24: |
228 |
switch (g_bpp) |
pc = split_colour24(colour); |
|
{ |
|
|
case 16: |
|
|
colour = make_colour16(split_colour24(colour)); |
|
|
break; |
|
|
case 24: |
|
|
break; |
|
|
case 32: |
|
|
colour = make_colour32(split_colour24(colour)); |
|
|
break; |
|
|
} |
|
|
break; |
|
|
} |
|
|
switch (g_bpp) |
|
|
{ |
|
|
case 16: |
|
|
if (g_host_be != g_xserver_be) |
|
|
BSWAP16(colour); |
|
|
break; |
|
|
|
|
|
case 24: |
|
|
if (g_xserver_be) |
|
|
BSWAP24(colour); |
|
|
break; |
|
|
|
|
|
case 32: |
|
|
if (g_host_be != g_xserver_be) |
|
|
BSWAP32(colour); |
|
229 |
break; |
break; |
230 |
} |
} |
231 |
|
return make_colour(pc); |
|
return colour; |
|
232 |
} |
} |
233 |
|
|
234 |
static void |
static void |
239 |
} |
} |
240 |
|
|
241 |
static void |
static void |
242 |
translate8to16(uint8 * data, uint16 * out, uint16 * end) |
translate8to16(uint8 * data, uint8 * out, uint8 * end) |
243 |
{ |
{ |
244 |
|
uint16 value; |
245 |
|
|
246 |
while (out < end) |
while (out < end) |
247 |
*(out++) = (uint16) g_colmap[*(data++)]; |
{ |
248 |
|
value = (uint16) g_colmap[*(data++)]; |
249 |
|
|
250 |
|
if (g_xserver_be) |
251 |
|
{ |
252 |
|
*(out++) = value >> 8; |
253 |
|
*(out++) = value; |
254 |
|
} |
255 |
|
else |
256 |
|
{ |
257 |
|
*(out++) = value; |
258 |
|
*(out++) = value >> 8; |
259 |
|
} |
260 |
|
} |
261 |
} |
} |
262 |
|
|
263 |
/* little endian - conversion happens when colourmap is built */ |
/* little endian - conversion happens when colourmap is built */ |
269 |
while (out < end) |
while (out < end) |
270 |
{ |
{ |
271 |
value = g_colmap[*(data++)]; |
value = g_colmap[*(data++)]; |
272 |
*(out++) = value; |
|
273 |
*(out++) = value >> 8; |
if (g_xserver_be) |
274 |
*(out++) = value >> 16; |
{ |
275 |
|
*(out++) = value >> 16; |
276 |
|
*(out++) = value >> 8; |
277 |
|
*(out++) = value; |
278 |
|
} |
279 |
|
else |
280 |
|
{ |
281 |
|
*(out++) = value; |
282 |
|
*(out++) = value >> 8; |
283 |
|
*(out++) = value >> 16; |
284 |
|
} |
285 |
} |
} |
286 |
} |
} |
287 |
|
|
288 |
static void |
static void |
289 |
translate8to32(uint8 * data, uint32 * out, uint32 * end) |
translate8to32(uint8 * data, uint8 * out, uint8 * end) |
290 |
{ |
{ |
291 |
|
uint32 value; |
292 |
|
|
293 |
while (out < end) |
while (out < end) |
294 |
*(out++) = g_colmap[*(data++)]; |
{ |
295 |
|
value = g_colmap[*(data++)]; |
296 |
|
|
297 |
|
if (g_xserver_be) |
298 |
|
{ |
299 |
|
*(out++) = value >> 24; |
300 |
|
*(out++) = value >> 16; |
301 |
|
*(out++) = value >> 8; |
302 |
|
*(out++) = value; |
303 |
|
} |
304 |
|
else |
305 |
|
{ |
306 |
|
*(out++) = value; |
307 |
|
*(out++) = value >> 8; |
308 |
|
*(out++) = value >> 16; |
309 |
|
*(out++) = value >> 24; |
310 |
|
} |
311 |
|
} |
312 |
} |
} |
313 |
|
|
314 |
/* todo the remaining translate function might need some big endian check ?? */ |
/* todo the remaining translate function might need some big endian check ?? */ |
315 |
|
|
316 |
static void |
static void |
317 |
translate15to16(uint16 * data, uint16 * out, uint16 * end) |
translate15to16(uint16 * data, uint8 * out, uint8 * end) |
318 |
{ |
{ |
319 |
|
uint16 pixel; |
320 |
|
uint16 value; |
321 |
|
|
322 |
while (out < end) |
while (out < end) |
323 |
*(out++) = (uint16) make_colour16(split_colour15(*(data++))); |
{ |
324 |
|
pixel = *(data++); |
325 |
|
|
326 |
|
if (g_host_be) |
327 |
|
{ |
328 |
|
BSWAP16(pixel); |
329 |
|
} |
330 |
|
|
331 |
|
value = make_colour(split_colour15(pixel)); |
332 |
|
|
333 |
|
if (g_xserver_be) |
334 |
|
{ |
335 |
|
*(out++) = value >> 8; |
336 |
|
*(out++) = value; |
337 |
|
} |
338 |
|
else |
339 |
|
{ |
340 |
|
*(out++) = value; |
341 |
|
*(out++) = value >> 8; |
342 |
|
} |
343 |
|
} |
344 |
} |
} |
345 |
|
|
346 |
static void |
static void |
347 |
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
348 |
{ |
{ |
349 |
uint32 value; |
uint32 value; |
350 |
|
uint16 pixel; |
351 |
|
|
352 |
while (out < end) |
while (out < end) |
353 |
{ |
{ |
354 |
value = make_colour24(split_colour15(*(data++))); |
pixel = *(data++); |
355 |
*(out++) = value; |
|
356 |
*(out++) = value >> 8; |
if (g_host_be) |
357 |
*(out++) = value >> 16; |
{ |
358 |
|
BSWAP16(pixel); |
359 |
|
} |
360 |
|
|
361 |
|
value = make_colour(split_colour15(pixel)); |
362 |
|
if (g_xserver_be) |
363 |
|
{ |
364 |
|
*(out++) = value >> 16; |
365 |
|
*(out++) = value >> 8; |
366 |
|
*(out++) = value; |
367 |
|
} |
368 |
|
else |
369 |
|
{ |
370 |
|
*(out++) = value; |
371 |
|
*(out++) = value >> 8; |
372 |
|
*(out++) = value >> 16; |
373 |
|
} |
374 |
} |
} |
375 |
} |
} |
376 |
|
|
377 |
static void |
static void |
378 |
translate15to32(uint16 * data, uint32 * out, uint32 * end) |
translate15to32(uint16 * data, uint8 * out, uint8 * end) |
379 |
{ |
{ |
380 |
uint16 pixel; |
uint16 pixel; |
381 |
|
uint32 value; |
382 |
|
|
383 |
while (out < end) |
while (out < end) |
384 |
{ |
{ |
385 |
|
pixel = *(data++); |
386 |
|
|
387 |
if (g_host_be) |
if (g_host_be) |
388 |
{ |
{ |
389 |
pixel = *(data++); |
BSWAP16(pixel); |
390 |
pixel = (pixel & 0xff) << 8 | (pixel & 0xff00) >> 8; |
} |
391 |
*(out++) = make_colour32(split_colour15(pixel)); |
|
392 |
|
value = make_colour(split_colour15(pixel)); |
393 |
|
|
394 |
|
if (g_xserver_be) |
395 |
|
{ |
396 |
|
*(out++) = value >> 24; |
397 |
|
*(out++) = value >> 16; |
398 |
|
*(out++) = value >> 8; |
399 |
|
*(out++) = value; |
400 |
} |
} |
401 |
else |
else |
402 |
{ |
{ |
403 |
*(out++) = make_colour32(split_colour15(*(data++))); |
*(out++) = value; |
404 |
|
*(out++) = value >> 8; |
405 |
|
*(out++) = value >> 16; |
406 |
|
*(out++) = value >> 24; |
407 |
} |
} |
408 |
} |
} |
409 |
} |
} |
410 |
|
|
411 |
static void |
static void |
412 |
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
translate16to16(uint16 * data, uint8 * out, uint8 * end) |
413 |
{ |
{ |
414 |
|
uint16 pixel; |
415 |
|
uint16 value; |
416 |
|
|
417 |
while (out < end) |
while (out < end) |
418 |
*(out++) = (uint16) (*(data++)); |
{ |
419 |
} |
pixel = *(data++); |
420 |
|
|
421 |
|
if (g_host_be) |
422 |
|
{ |
423 |
|
BSWAP16(pixel); |
424 |
|
} |
425 |
|
|
426 |
|
value = make_colour(split_colour16(pixel)); |
427 |
|
|
428 |
|
if (g_xserver_be) |
429 |
|
{ |
430 |
|
*(out++) = value >> 8; |
431 |
|
*(out++) = value; |
432 |
|
} |
433 |
|
else |
434 |
|
{ |
435 |
|
*(out++) = value; |
436 |
|
*(out++) = value >> 8; |
437 |
|
} |
438 |
|
} |
439 |
|
} |
440 |
|
|
441 |
static void |
static void |
442 |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
443 |
{ |
{ |
444 |
uint32 value; |
uint32 value; |
445 |
|
uint16 pixel; |
446 |
|
|
447 |
while (out < end) |
while (out < end) |
448 |
{ |
{ |
449 |
value = make_colour24(split_colour16(*(data++))); |
pixel = *(data++); |
450 |
*(out++) = value; |
|
451 |
*(out++) = value >> 8; |
if (g_host_be) |
452 |
*(out++) = value >> 16; |
{ |
453 |
|
BSWAP16(pixel); |
454 |
|
} |
455 |
|
|
456 |
|
value = make_colour(split_colour16(pixel)); |
457 |
|
|
458 |
|
if (g_xserver_be) |
459 |
|
{ |
460 |
|
*(out++) = value >> 16; |
461 |
|
*(out++) = value >> 8; |
462 |
|
*(out++) = value; |
463 |
|
} |
464 |
|
else |
465 |
|
{ |
466 |
|
*(out++) = value; |
467 |
|
*(out++) = value >> 8; |
468 |
|
*(out++) = value >> 16; |
469 |
|
} |
470 |
} |
} |
471 |
} |
} |
472 |
|
|
473 |
static void |
static void |
474 |
translate16to32(uint16 * data, uint32 * out, uint32 * end) |
translate16to32(uint16 * data, uint8 * out, uint8 * end) |
475 |
{ |
{ |
476 |
uint16 pixel; |
uint16 pixel; |
477 |
|
uint32 value; |
478 |
|
|
479 |
while (out < end) |
while (out < end) |
480 |
{ |
{ |
481 |
|
pixel = *(data++); |
482 |
|
|
483 |
if (g_host_be) |
if (g_host_be) |
484 |
{ |
{ |
485 |
pixel = *(data++); |
BSWAP16(pixel); |
486 |
pixel = (pixel & 0xff) << 8 | (pixel & 0xff00) >> 8; |
} |
487 |
*(out++) = make_colour32(split_colour16(pixel)); |
|
488 |
|
value = make_colour(split_colour16(pixel)); |
489 |
|
|
490 |
|
if (g_xserver_be) |
491 |
|
{ |
492 |
|
*(out++) = value >> 24; |
493 |
|
*(out++) = value >> 16; |
494 |
|
*(out++) = value >> 8; |
495 |
|
*(out++) = value; |
496 |
} |
} |
497 |
else |
else |
498 |
{ |
{ |
499 |
*(out++) = make_colour32(split_colour16(*(data++))); |
*(out++) = value; |
500 |
|
*(out++) = value >> 8; |
501 |
|
*(out++) = value >> 16; |
502 |
|
*(out++) = value >> 24; |
503 |
} |
} |
504 |
} |
} |
505 |
} |
} |
506 |
|
|
507 |
static void |
static void |
508 |
translate24to16(uint8 * data, uint16 * out, uint16 * end) |
translate24to16(uint8 * data, uint8 * out, uint8 * end) |
509 |
{ |
{ |
510 |
uint32 pixel = 0; |
uint32 pixel = 0; |
511 |
|
uint16 value; |
512 |
while (out < end) |
while (out < end) |
513 |
{ |
{ |
514 |
pixel = *(data++) << 16; |
pixel = *(data++) << 16; |
515 |
pixel |= *(data++) << 8; |
pixel |= *(data++) << 8; |
516 |
pixel |= *(data++); |
pixel |= *(data++); |
517 |
*(out++) = (uint16) make_colour16(split_colour24(pixel)); |
|
518 |
|
value = (uint16) make_colour(split_colour24(pixel)); |
519 |
|
|
520 |
|
if (g_xserver_be) |
521 |
|
{ |
522 |
|
*(out++) = value >> 8; |
523 |
|
*(out++) = value; |
524 |
|
} |
525 |
|
else |
526 |
|
{ |
527 |
|
*(out++) = value; |
528 |
|
*(out++) = value >> 8; |
529 |
|
} |
530 |
} |
} |
531 |
} |
} |
532 |
|
|
533 |
static void |
static void |
534 |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
translate24to24(uint8 * data, uint8 * out, uint8 * end) |
535 |
{ |
{ |
536 |
|
uint32 pixel; |
537 |
|
uint32 value; |
538 |
|
|
539 |
while (out < end) |
while (out < end) |
540 |
{ |
{ |
541 |
*(out++) = (*(data++)); |
pixel = *(data++) << 16; |
542 |
|
pixel |= *(data++) << 8; |
543 |
|
pixel |= *(data++); |
544 |
|
|
545 |
|
value = make_colour(split_colour24(pixel)); |
546 |
|
|
547 |
|
if (g_xserver_be) |
548 |
|
{ |
549 |
|
*(out++) = value >> 16; |
550 |
|
*(out++) = value >> 8; |
551 |
|
*(out++) = value; |
552 |
|
} |
553 |
|
else |
554 |
|
{ |
555 |
|
*(out++) = value; |
556 |
|
*(out++) = value >> 8; |
557 |
|
*(out++) = value >> 16; |
558 |
|
} |
559 |
} |
} |
560 |
} |
} |
561 |
|
|
562 |
static void |
static void |
563 |
translate24to32(uint8 * data, uint32 * out, uint32 * end) |
translate24to32(uint8 * data, uint8 * out, uint8 * end) |
564 |
{ |
{ |
565 |
uint32 pixel = 0; |
uint32 pixel; |
566 |
|
uint32 value; |
567 |
|
|
568 |
while (out < end) |
while (out < end) |
569 |
{ |
{ |
570 |
if (g_host_be) |
pixel = *(data++) << 16; |
571 |
|
pixel |= *(data++) << 8; |
572 |
|
pixel |= *(data++); |
573 |
|
|
574 |
|
value = make_colour(split_colour24(pixel)); |
575 |
|
|
576 |
|
if (g_xserver_be) |
577 |
{ |
{ |
578 |
pixel = *(data++) << 16; |
*(out++) = value >> 24; |
579 |
pixel |= *(data++) << 8; |
*(out++) = value >> 16; |
580 |
pixel |= *(data++); |
*(out++) = value >> 8; |
581 |
|
*(out++) = value; |
582 |
} |
} |
583 |
else |
else |
584 |
{ |
{ |
585 |
pixel = *(data++); |
*(out++) = value; |
586 |
pixel |= *(data++) << 8; |
*(out++) = value >> 8; |
587 |
pixel |= *(data++) << 16; |
*(out++) = value >> 16; |
588 |
|
*(out++) = value >> 24; |
589 |
} |
} |
|
*(out++) = pixel; |
|
590 |
} |
} |
591 |
} |
} |
592 |
|
|
603 |
switch (g_bpp) |
switch (g_bpp) |
604 |
{ |
{ |
605 |
case 32: |
case 32: |
606 |
translate24to32(data, (uint32 *) out, (uint32 *) end); |
translate24to32(data, out, end); |
607 |
break; |
break; |
608 |
case 24: |
case 24: |
609 |
translate24to24(data, out, end); |
translate24to24(data, out, end); |
610 |
break; |
break; |
611 |
case 16: |
case 16: |
612 |
translate24to16(data, (uint16 *) out, (uint16 *) end); |
translate24to16(data, out, end); |
613 |
break; |
break; |
614 |
} |
} |
615 |
break; |
break; |
617 |
switch (g_bpp) |
switch (g_bpp) |
618 |
{ |
{ |
619 |
case 32: |
case 32: |
620 |
translate16to32((uint16 *) data, (uint32 *) out, |
translate16to32((uint16 *) data, out, end); |
|
(uint32 *) end); |
|
621 |
break; |
break; |
622 |
case 24: |
case 24: |
623 |
translate16to24((uint16 *) data, out, end); |
translate16to24((uint16 *) data, out, end); |
624 |
break; |
break; |
625 |
case 16: |
case 16: |
626 |
translate16to16((uint16 *) data, (uint16 *) out, |
translate16to16((uint16 *) data, out, end); |
|
(uint16 *) end); |
|
627 |
break; |
break; |
628 |
} |
} |
629 |
break; |
break; |
631 |
switch (g_bpp) |
switch (g_bpp) |
632 |
{ |
{ |
633 |
case 32: |
case 32: |
634 |
translate15to32((uint16 *) data, (uint32 *) out, |
translate15to32((uint16 *) data, out, end); |
|
(uint32 *) end); |
|
635 |
break; |
break; |
636 |
case 24: |
case 24: |
637 |
translate15to24((uint16 *) data, out, end); |
translate15to24((uint16 *) data, out, end); |
638 |
break; |
break; |
639 |
case 16: |
case 16: |
640 |
translate15to16((uint16 *) data, (uint16 *) out, |
translate15to16((uint16 *) data, out, end); |
|
(uint16 *) end); |
|
641 |
break; |
break; |
642 |
} |
} |
643 |
break; |
break; |
648 |
translate8to8(data, out, end); |
translate8to8(data, out, end); |
649 |
break; |
break; |
650 |
case 16: |
case 16: |
651 |
translate8to16(data, (uint16 *) out, (uint16 *) end); |
translate8to16(data, out, end); |
652 |
break; |
break; |
653 |
case 24: |
case 24: |
654 |
translate8to24(data, out, end); |
translate8to24(data, out, end); |
655 |
break; |
break; |
656 |
case 32: |
case 32: |
657 |
translate8to32(data, (uint32 *) out, (uint32 *) end); |
translate8to32(data, out, end); |
658 |
break; |
break; |
659 |
} |
} |
660 |
break; |
break; |
687 |
return (state & keysymMask) ? True : False; |
return (state & keysymMask) ? True : False; |
688 |
} |
} |
689 |
|
|
690 |
|
static void |
691 |
|
calculate_shifts(uint32 mask, int *shift_r, int *shift_l) |
692 |
|
{ |
693 |
|
*shift_l = ffs(mask) - 1; |
694 |
|
mask >>= *shift_l; |
695 |
|
*shift_r = 8 - ffs(mask & ~(mask >> 1)); |
696 |
|
} |
697 |
|
|
698 |
BOOL |
BOOL |
699 |
ui_init(void) |
ui_init(void) |
700 |
{ |
{ |
701 |
|
XVisualInfo vi; |
702 |
XPixmapFormatValues *pfm; |
XPixmapFormatValues *pfm; |
703 |
uint16 test; |
uint16 test; |
704 |
int i; |
int i, screen_num; |
705 |
|
|
706 |
g_display = XOpenDisplay(NULL); |
g_display = XOpenDisplay(NULL); |
707 |
if (g_display == NULL) |
if (g_display == NULL) |
710 |
return False; |
return False; |
711 |
} |
} |
712 |
|
|
713 |
|
screen_num = DefaultScreen(g_display); |
714 |
g_x_socket = ConnectionNumber(g_display); |
g_x_socket = ConnectionNumber(g_display); |
715 |
g_screen = DefaultScreenOfDisplay(g_display); |
g_screen = ScreenOfDisplay(g_display, screen_num); |
|
g_visual = DefaultVisualOfScreen(g_screen); |
|
716 |
g_depth = DefaultDepthOfScreen(g_screen); |
g_depth = DefaultDepthOfScreen(g_screen); |
717 |
|
|
718 |
|
if (g_server_bpp == 8) |
719 |
|
{ |
720 |
|
/* we use a colourmap, so any visual should do */ |
721 |
|
g_visual = DefaultVisualOfScreen(g_screen); |
722 |
|
} |
723 |
|
else |
724 |
|
{ |
725 |
|
/* need a truecolour visual */ |
726 |
|
if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi)) |
727 |
|
{ |
728 |
|
error("The display does not support true colour - high colour support unavailable.\n"); |
729 |
|
return False; |
730 |
|
} |
731 |
|
|
732 |
|
g_visual = vi.visual; |
733 |
|
g_owncolmap = False; |
734 |
|
calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l); |
735 |
|
calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l); |
736 |
|
calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l); |
737 |
|
} |
738 |
|
|
739 |
pfm = XListPixmapFormats(g_display, &i); |
pfm = XListPixmapFormats(g_display, &i); |
740 |
if (pfm != NULL) |
if (pfm != NULL) |
741 |
{ |
{ |
758 |
return False; |
return False; |
759 |
} |
} |
760 |
|
|
761 |
if (g_owncolmap != True) |
if (!g_owncolmap) |
762 |
{ |
{ |
763 |
g_xcolmap = DefaultColormapOfScreen(g_screen); |
g_xcolmap = DefaultColormapOfScreen(g_screen); |
764 |
if (g_depth <= 8) |
if (g_depth <= 8) |
774 |
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
775 |
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
776 |
|
|
777 |
if ((g_width == 0) || (g_height == 0)) |
/* |
778 |
|
* Determine desktop size |
779 |
|
*/ |
780 |
|
if (g_width < 0) |
781 |
|
{ |
782 |
|
/* Percent of screen */ |
783 |
|
g_height = HeightOfScreen(g_screen) * (-g_width) / 100; |
784 |
|
g_width = WidthOfScreen(g_screen) * (-g_width) / 100; |
785 |
|
} |
786 |
|
else if (g_width == 0) |
787 |
{ |
{ |
788 |
/* Fetch geometry from _NET_WORKAREA */ |
/* Fetch geometry from _NET_WORKAREA */ |
789 |
uint32 x, y, cx, cy; |
uint32 x, y, cx, cy; |
800 |
g_height = 600; |
g_height = 600; |
801 |
} |
} |
802 |
} |
} |
803 |
|
else if (g_fullscreen) |
|
if (g_fullscreen) |
|
804 |
{ |
{ |
805 |
g_width = WidthOfScreen(g_screen); |
g_width = WidthOfScreen(g_screen); |
806 |
g_height = HeightOfScreen(g_screen); |
g_height = HeightOfScreen(g_screen); |
822 |
|
|
823 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
824 |
|
|
825 |
|
xkeymap_init(); |
826 |
|
|
827 |
if (g_enable_compose) |
if (g_enable_compose) |
828 |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
829 |
|
|
|
xkeymap_init(); |
|
830 |
xclip_init(); |
xclip_init(); |
831 |
|
|
832 |
/* todo take this out when high colour is done */ |
DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth)); |
|
printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth); |
|
833 |
|
|
834 |
return True; |
return True; |
835 |
} |
} |
853 |
BOOL |
BOOL |
854 |
ui_create_window(void) |
ui_create_window(void) |
855 |
{ |
{ |
856 |
|
uint8 null_pointer_mask[1] = { 0x80 }; |
857 |
|
uint8 null_pointer_data[4] = { 0x00, 0x00, 0x00, 0x00 }; |
858 |
XSetWindowAttributes attribs; |
XSetWindowAttributes attribs; |
859 |
XClassHint *classhints; |
XClassHint *classhints; |
860 |
XSizeHints *sizehints; |
XSizeHints *sizehints; |
936 |
g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True); |
g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True); |
937 |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
938 |
|
|
939 |
|
/* create invisible 1x1 cursor to be used as null cursor */ |
940 |
|
g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data); |
941 |
|
|
942 |
return True; |
return True; |
943 |
} |
} |
944 |
|
|
945 |
void |
void |
946 |
ui_destroy_window(void) |
ui_destroy_window(void) |
947 |
{ |
{ |
948 |
|
ui_destroy_cursor(g_null_cursor); |
949 |
|
|
950 |
if (g_IC != NULL) |
if (g_IC != NULL) |
951 |
XDestroyIC(g_IC); |
XDestroyIC(g_IC); |
952 |
|
|
1268 |
{ |
{ |
1269 |
FD_SET(g_dsp_fd, &wfds); |
FD_SET(g_dsp_fd, &wfds); |
1270 |
n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; |
n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; |
1271 |
} |
} |
1272 |
#endif |
#endif |
1273 |
|
|
1274 |
switch (select(n, &rfds, &wfds, NULL, NULL)) |
switch (select(n, &rfds, &wfds, NULL, NULL)) |
1302 |
XImage *image; |
XImage *image; |
1303 |
Pixmap bitmap; |
Pixmap bitmap; |
1304 |
uint8 *tdata; |
uint8 *tdata; |
1305 |
|
int bitmap_pad; |
1306 |
|
|
1307 |
|
if (g_server_bpp == 8) |
1308 |
|
{ |
1309 |
|
bitmap_pad = 8; |
1310 |
|
} |
1311 |
|
else |
1312 |
|
{ |
1313 |
|
bitmap_pad = g_bpp; |
1314 |
|
|
1315 |
|
if (g_bpp == 24) |
1316 |
|
bitmap_pad = 32; |
1317 |
|
} |
1318 |
|
|
1319 |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
1320 |
bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth); |
bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth); |
1321 |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
1322 |
(char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); |
(char *) tdata, width, height, bitmap_pad, 0); |
1323 |
|
|
1324 |
XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height); |
XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height); |
1325 |
|
|
1334 |
{ |
{ |
1335 |
XImage *image; |
XImage *image; |
1336 |
uint8 *tdata; |
uint8 *tdata; |
1337 |
|
int bitmap_pad; |
1338 |
|
|
1339 |
|
if (g_server_bpp == 8) |
1340 |
|
{ |
1341 |
|
bitmap_pad = 8; |
1342 |
|
} |
1343 |
|
else |
1344 |
|
{ |
1345 |
|
bitmap_pad = g_bpp; |
1346 |
|
|
1347 |
|
if (g_bpp == 24) |
1348 |
|
bitmap_pad = 32; |
1349 |
|
} |
1350 |
|
|
1351 |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
tdata = (g_owncolmap ? data : translate_image(width, height, data)); |
1352 |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, |
1353 |
(char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); |
(char *) tdata, width, height, bitmap_pad, 0); |
1354 |
|
|
1355 |
if (g_ownbackstore) |
if (g_ownbackstore) |
1356 |
{ |
{ |
1489 |
XFreeCursor(g_display, (Cursor) cursor); |
XFreeCursor(g_display, (Cursor) cursor); |
1490 |
} |
} |
1491 |
|
|
1492 |
|
void |
1493 |
|
ui_set_null_cursor(void) |
1494 |
|
{ |
1495 |
|
ui_set_cursor(g_null_cursor); |
1496 |
|
} |
1497 |
|
|
1498 |
#define MAKE_XCOLOR(xc,c) \ |
#define MAKE_XCOLOR(xc,c) \ |
1499 |
(xc)->red = ((c)->red << 8) | (c)->red; \ |
(xc)->red = ((c)->red << 8) | (c)->red; \ |
1500 |
(xc)->green = ((c)->green << 8) | (c)->green; \ |
(xc)->green = ((c)->green << 8) | (c)->green; \ |
1576 |
|
|
1577 |
} |
} |
1578 |
|
|
1579 |
|
map[i] = colour; |
|
/* byte swap here to make translate_image faster */ |
|
|
map[i] = translate_colour(colour); |
|
1580 |
} |
} |
1581 |
return map; |
return map; |
1582 |
} |
} |
1693 |
case 2: /* Hatch */ |
case 2: /* Hatch */ |
1694 |
fill = (Pixmap) ui_create_glyph(8, 8, |
fill = (Pixmap) ui_create_glyph(8, 8, |
1695 |
hatch_patterns + brush->pattern[0] * 8); |
hatch_patterns + brush->pattern[0] * 8); |
1696 |
SET_FOREGROUND(bgcolour); |
SET_FOREGROUND(fgcolour); |
1697 |
SET_BACKGROUND(fgcolour); |
SET_BACKGROUND(bgcolour); |
1698 |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
1699 |
XSetStipple(g_display, g_gc, fill); |
XSetStipple(g_display, g_gc, fill); |
1700 |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |