34 |
extern char g_title[]; |
extern char g_title[]; |
35 |
extern int g_server_bpp; |
extern int g_server_bpp; |
36 |
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; |
|
37 |
|
|
38 |
Display *g_display; |
Display *g_display; |
39 |
Time g_last_gesturetime; |
Time g_last_gesturetime; |
40 |
static int g_x_socket; |
static int g_x_socket; |
41 |
static Screen *g_screen; |
static Screen *g_screen; |
42 |
Window g_wnd; |
Window g_wnd; |
43 |
|
BOOL g_enable_compose = False; |
44 |
static GC g_gc; |
static GC g_gc; |
45 |
static Visual *g_visual; |
static Visual *g_visual; |
46 |
static int g_depth; |
static int g_depth; |
49 |
static XIC g_IC; |
static XIC g_IC; |
50 |
static XModifierKeymap *g_mod_map; |
static XModifierKeymap *g_mod_map; |
51 |
static Cursor g_current_cursor; |
static Cursor g_current_cursor; |
52 |
|
static HCURSOR g_null_cursor; |
53 |
static Atom g_protocol_atom, g_kill_atom; |
static Atom g_protocol_atom, g_kill_atom; |
54 |
|
static BOOL g_focused; |
55 |
|
static BOOL g_mouse_in_wnd; |
56 |
|
|
57 |
/* endianness */ |
/* endianness */ |
58 |
static BOOL g_host_be; |
static BOOL g_host_be; |
67 |
static int g_move_x_offset = 0; |
static int g_move_x_offset = 0; |
68 |
static int g_move_y_offset = 0; |
static int g_move_y_offset = 0; |
69 |
|
|
70 |
|
#ifdef WITH_RDPSND |
71 |
|
extern int g_dsp_fd; |
72 |
|
extern BOOL g_dsp_busy; |
73 |
|
extern BOOL g_rdpsnd; |
74 |
|
#endif |
75 |
|
|
76 |
/* MWM decorations */ |
/* MWM decorations */ |
77 |
#define MWM_HINTS_DECORATIONS (1L << 1) |
#define MWM_HINTS_DECORATIONS (1L << 1) |
78 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5 |
208 |
static uint32 |
static uint32 |
209 |
make_colour24(PixelColour pc) |
make_colour24(PixelColour pc) |
210 |
{ |
{ |
211 |
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
if (g_xserver_be) |
212 |
|
{ |
213 |
|
return pc.red | (pc.green << 8) | (pc.blue << 16); |
214 |
|
} |
215 |
|
else |
216 |
|
{ |
217 |
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
218 |
|
} |
219 |
} |
} |
220 |
|
|
221 |
static uint32 |
static uint32 |
222 |
make_colour32(PixelColour pc) |
make_colour32(PixelColour pc) |
223 |
{ |
{ |
224 |
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
if (g_xserver_be) |
225 |
|
{ |
226 |
|
return pc.red | (pc.green << 8) | (pc.blue << 16); |
227 |
|
} |
228 |
|
else |
229 |
|
{ |
230 |
|
return (pc.red << 16) | (pc.green << 8) | pc.blue; |
231 |
|
} |
232 |
} |
} |
233 |
|
|
234 |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } |
282 |
} |
} |
283 |
break; |
break; |
284 |
} |
} |
|
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); |
|
|
break; |
|
|
} |
|
|
|
|
285 |
return colour; |
return colour; |
286 |
} |
} |
287 |
|
|
324 |
/* todo the remaining translate function might need some big endian check ?? */ |
/* todo the remaining translate function might need some big endian check ?? */ |
325 |
|
|
326 |
static void |
static void |
327 |
translate15to16(uint16 * data, uint16 * out, uint16 * end) |
translate15to16(uint16 * data, uint8 * out, uint8 * end) |
328 |
{ |
{ |
329 |
|
uint16 pixel; |
330 |
|
uint16 value; |
331 |
|
|
332 |
while (out < end) |
while (out < end) |
333 |
*(out++) = (uint16) make_colour16(split_colour15(*(data++))); |
{ |
334 |
|
pixel = *(data++); |
335 |
|
|
336 |
|
if (g_host_be) |
337 |
|
{ |
338 |
|
BSWAP16(pixel)} |
339 |
|
|
340 |
|
value = make_colour16(split_colour15(pixel)); |
341 |
|
|
342 |
|
if (g_xserver_be) |
343 |
|
{ |
344 |
|
*(out++) = value >> 8; |
345 |
|
*(out++) = value; |
346 |
|
} |
347 |
|
else |
348 |
|
{ |
349 |
|
*(out++) = value; |
350 |
|
*(out++) = value >> 8; |
351 |
|
} |
352 |
|
} |
353 |
} |
} |
354 |
|
|
355 |
static void |
static void |
356 |
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
translate15to24(uint16 * data, uint8 * out, uint8 * end) |
357 |
{ |
{ |
358 |
uint32 value; |
uint32 value; |
359 |
|
uint16 pixel; |
360 |
|
|
361 |
while (out < end) |
while (out < end) |
362 |
{ |
{ |
363 |
value = make_colour24(split_colour15(*(data++))); |
pixel = *(data++); |
364 |
*(out++) = value; |
|
365 |
*(out++) = value >> 8; |
if (g_host_be) |
366 |
*(out++) = value >> 16; |
{ |
367 |
|
BSWAP16(pixel)} |
368 |
|
|
369 |
|
value = make_colour24(split_colour15(pixel)); |
370 |
|
if (g_xserver_be) |
371 |
|
{ |
372 |
|
*(out++) = value >> 16; |
373 |
|
*(out++) = value >> 8; |
374 |
|
*(out++) = value; |
375 |
|
} |
376 |
|
else |
377 |
|
{ |
378 |
|
*(out++) = value; |
379 |
|
*(out++) = value >> 8; |
380 |
|
*(out++) = value >> 16; |
381 |
|
} |
382 |
} |
} |
383 |
} |
} |
384 |
|
|
385 |
static void |
static void |
386 |
translate15to32(uint16 * data, uint32 * out, uint32 * end) |
translate15to32(uint16 * data, uint8 * out, uint8 * end) |
387 |
{ |
{ |
388 |
|
uint16 pixel; |
389 |
|
uint32 value; |
390 |
|
|
391 |
while (out < end) |
while (out < end) |
392 |
*(out++) = make_colour32(split_colour15(*(data++))); |
{ |
393 |
|
pixel = *(data++); |
394 |
|
|
395 |
|
if (g_host_be) |
396 |
|
{ |
397 |
|
BSWAP16(pixel); |
398 |
|
} |
399 |
|
|
400 |
|
value = make_colour32(split_colour15(pixel)); |
401 |
|
|
402 |
|
if (g_xserver_be) |
403 |
|
{ |
404 |
|
*(out++) = value >> 24; |
405 |
|
*(out++) = value >> 16; |
406 |
|
*(out++) = value >> 8; |
407 |
|
*(out++) = value; |
408 |
|
} |
409 |
|
else |
410 |
|
{ |
411 |
|
*(out++) = value; |
412 |
|
*(out++) = value >> 8; |
413 |
|
*(out++) = value >> 16; |
414 |
|
*(out++) = value >> 24; |
415 |
|
} |
416 |
|
} |
417 |
} |
} |
418 |
|
|
419 |
static void |
static void |
420 |
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
translate16to16(uint16 * data, uint16 * out, uint16 * end) |
421 |
{ |
{ |
422 |
while (out < end) |
uint16 value; |
423 |
*(out++) = (uint16) (*(data++)); |
|
424 |
|
if (g_xserver_be) |
425 |
|
{ |
426 |
|
while (out < end) |
427 |
|
{ |
428 |
|
value = *data; |
429 |
|
BSWAP16(value); |
430 |
|
*out = value; |
431 |
|
data++; |
432 |
|
out++; |
433 |
|
} |
434 |
|
|
435 |
|
} |
436 |
|
else |
437 |
|
{ |
438 |
|
while (out < end) |
439 |
|
{ |
440 |
|
*out = *data; |
441 |
|
out++; |
442 |
|
data++; |
443 |
|
} |
444 |
|
} |
445 |
} |
} |
446 |
|
|
447 |
|
|
449 |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
translate16to24(uint16 * data, uint8 * out, uint8 * end) |
450 |
{ |
{ |
451 |
uint32 value; |
uint32 value; |
452 |
|
uint16 pixel; |
453 |
|
|
454 |
while (out < end) |
while (out < end) |
455 |
{ |
{ |
456 |
value = make_colour24(split_colour16(*(data++))); |
pixel = *(data++); |
457 |
*(out++) = value; |
|
458 |
*(out++) = value >> 8; |
if (g_host_be) |
459 |
*(out++) = value >> 16; |
{ |
460 |
|
BSWAP16(pixel)} |
461 |
|
|
462 |
|
value = make_colour24(split_colour16(pixel)); |
463 |
|
|
464 |
|
if (g_xserver_be) |
465 |
|
{ |
466 |
|
*(out++) = value >> 16; |
467 |
|
*(out++) = value >> 8; |
468 |
|
*(out++) = value; |
469 |
|
} |
470 |
|
else |
471 |
|
{ |
472 |
|
*(out++) = value; |
473 |
|
*(out++) = value >> 8; |
474 |
|
*(out++) = value >> 16; |
475 |
|
} |
476 |
} |
} |
477 |
} |
} |
478 |
|
|
479 |
static void |
static void |
480 |
translate16to32(uint16 * data, uint32 * out, uint32 * end) |
translate16to32(uint16 * data, uint8 * out, uint8 * end) |
481 |
{ |
{ |
482 |
|
uint16 pixel; |
483 |
|
uint32 value; |
484 |
|
|
485 |
while (out < end) |
while (out < end) |
486 |
*(out++) = make_colour32(split_colour16(*(data++))); |
{ |
487 |
|
pixel = *(data++); |
488 |
|
|
489 |
|
if (g_host_be) |
490 |
|
{ |
491 |
|
BSWAP16(pixel)} |
492 |
|
|
493 |
|
value = make_colour32(split_colour16(pixel)); |
494 |
|
|
495 |
|
if (g_xserver_be) |
496 |
|
{ |
497 |
|
*(out++) = value >> 24; |
498 |
|
*(out++) = value >> 16; |
499 |
|
*(out++) = value >> 8; |
500 |
|
*(out++) = value; |
501 |
|
} |
502 |
|
else |
503 |
|
{ |
504 |
|
*(out++) = value; |
505 |
|
*(out++) = value >> 8; |
506 |
|
*(out++) = value >> 16; |
507 |
|
*(out++) = value >> 24; |
508 |
|
} |
509 |
|
} |
510 |
} |
} |
511 |
|
|
512 |
static void |
static void |
513 |
translate24to16(uint8 * data, uint16 * out, uint16 * end) |
translate24to16(uint8 * data, uint8 * out, uint8 * end) |
514 |
{ |
{ |
515 |
uint32 pixel = 0; |
uint32 pixel = 0; |
516 |
|
uint16 value; |
517 |
while (out < end) |
while (out < end) |
518 |
{ |
{ |
519 |
pixel = *(data++) << 16; |
pixel = *(data++) << 16; |
520 |
pixel |= *(data++) << 8; |
pixel |= *(data++) << 8; |
521 |
pixel |= *(data++); |
pixel |= *(data++); |
522 |
*(out++) = (uint16) make_colour16(split_colour24(pixel)); |
|
523 |
|
value = (uint16) make_colour16(split_colour24(pixel)); |
524 |
|
|
525 |
|
if (g_xserver_be) |
526 |
|
{ |
527 |
|
*(out++) = value >> 8; |
528 |
|
*(out++) = value; |
529 |
|
} |
530 |
|
else |
531 |
|
{ |
532 |
|
*(out++) = value; |
533 |
|
*(out++) = value >> 8; |
534 |
|
} |
535 |
} |
} |
536 |
} |
} |
537 |
|
|
545 |
} |
} |
546 |
|
|
547 |
static void |
static void |
548 |
translate24to32(uint8 * data, uint32 * out, uint32 * end) |
translate24to32(uint8 * data, uint8 * out, uint8 * end) |
549 |
{ |
{ |
|
uint32 pixel = 0; |
|
550 |
while (out < end) |
while (out < end) |
551 |
{ |
{ |
552 |
pixel = *(data++); |
if (g_xserver_be) |
553 |
pixel |= *(data++) << 8; |
{ |
554 |
pixel |= *(data++) << 16; |
*(out++) = 0x00; |
555 |
*(out++) = pixel; |
*(out++) = *(data++); |
556 |
|
*(out++) = *(data++); |
557 |
|
*(out++) = *(data++); |
558 |
|
} |
559 |
|
else |
560 |
|
{ |
561 |
|
*(out++) = *(data++); |
562 |
|
*(out++) = *(data++); |
563 |
|
*(out++) = *(data++); |
564 |
|
*(out++) = 0x00; |
565 |
|
} |
566 |
} |
} |
567 |
} |
} |
568 |
|
|
579 |
switch (g_bpp) |
switch (g_bpp) |
580 |
{ |
{ |
581 |
case 32: |
case 32: |
582 |
translate24to32(data, (uint32 *) out, (uint32 *) end); |
translate24to32(data, out, end); |
583 |
break; |
break; |
584 |
case 24: |
case 24: |
585 |
translate24to24(data, out, end); |
translate24to24(data, out, end); |
586 |
break; |
break; |
587 |
case 16: |
case 16: |
588 |
translate24to16(data, (uint16 *) out, (uint16 *) end); |
translate24to16(data, out, end); |
589 |
break; |
break; |
590 |
} |
} |
591 |
break; |
break; |
593 |
switch (g_bpp) |
switch (g_bpp) |
594 |
{ |
{ |
595 |
case 32: |
case 32: |
596 |
translate16to32((uint16 *) data, (uint32 *) out, |
translate16to32((uint16 *) data, out, end); |
|
(uint32 *) end); |
|
597 |
break; |
break; |
598 |
case 24: |
case 24: |
599 |
translate16to24((uint16 *) data, out, end); |
translate16to24((uint16 *) data, out, end); |
608 |
switch (g_bpp) |
switch (g_bpp) |
609 |
{ |
{ |
610 |
case 32: |
case 32: |
611 |
translate15to32((uint16 *) data, (uint32 *) out, |
translate15to32((uint16 *) data, out, end); |
|
(uint32 *) end); |
|
612 |
break; |
break; |
613 |
case 24: |
case 24: |
614 |
translate15to24((uint16 *) data, out, end); |
translate15to24((uint16 *) data, out, end); |
615 |
break; |
break; |
616 |
case 16: |
case 16: |
617 |
translate15to16((uint16 *) data, (uint16 *) out, |
translate15to16((uint16 *) data, out, end); |
|
(uint16 *) end); |
|
618 |
break; |
break; |
619 |
} |
} |
620 |
break; |
break; |
721 |
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
g_host_be = !(BOOL) (*(uint8 *) (&test)); |
722 |
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); |
723 |
|
|
724 |
if ((g_width == 0) || (g_height == 0)) |
/* |
725 |
|
* Determine desktop size |
726 |
|
*/ |
727 |
|
if (g_width < 0) |
728 |
|
{ |
729 |
|
/* Percent of screen */ |
730 |
|
g_height = HeightOfScreen(g_screen) * (-g_width) / 100; |
731 |
|
g_width = WidthOfScreen(g_screen) * (-g_width) / 100; |
732 |
|
} |
733 |
|
else if (g_width == 0) |
734 |
{ |
{ |
735 |
/* Fetch geometry from _NET_WORKAREA */ |
/* Fetch geometry from _NET_WORKAREA */ |
736 |
uint32 x, y, cx, cy; |
uint32 x, y, cx, cy; |
747 |
g_height = 600; |
g_height = 600; |
748 |
} |
} |
749 |
} |
} |
750 |
|
else if (g_fullscreen) |
|
if (g_fullscreen) |
|
751 |
{ |
{ |
752 |
g_width = WidthOfScreen(g_screen); |
g_width = WidthOfScreen(g_screen); |
753 |
g_height = HeightOfScreen(g_screen); |
g_height = HeightOfScreen(g_screen); |
769 |
|
|
770 |
g_mod_map = XGetModifierMapping(g_display); |
g_mod_map = XGetModifierMapping(g_display); |
771 |
|
|
772 |
|
xkeymap_init(); |
773 |
|
|
774 |
if (g_enable_compose) |
if (g_enable_compose) |
775 |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
g_IM = XOpenIM(g_display, NULL, NULL, NULL); |
776 |
|
|
|
xkeymap_init(); |
|
777 |
xclip_init(); |
xclip_init(); |
778 |
|
|
779 |
/* todo take this out when high colour is done */ |
/* todo take this out when high colour is done */ |
798 |
g_display = NULL; |
g_display = NULL; |
799 |
} |
} |
800 |
|
|
801 |
|
#define NULL_POINTER_MASK "\x80" |
802 |
|
#define NULL_POINTER_DATA "\x0\x0\x0" |
803 |
|
|
804 |
BOOL |
BOOL |
805 |
ui_create_window(void) |
ui_create_window(void) |
806 |
{ |
{ |
885 |
g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True); |
g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True); |
886 |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); |
887 |
|
|
888 |
|
/* create invisible 1x1 cursor to be used as null cursor */ |
889 |
|
g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA); |
890 |
|
|
891 |
return True; |
return True; |
892 |
} |
} |
893 |
|
|
894 |
void |
void |
895 |
ui_destroy_window(void) |
ui_destroy_window(void) |
896 |
{ |
{ |
897 |
|
ui_destroy_cursor(g_null_cursor); |
898 |
|
|
899 |
if (g_IC != NULL) |
if (g_IC != NULL) |
900 |
XDestroyIC(g_IC); |
XDestroyIC(g_IC); |
901 |
|
|
1001 |
if (tr.scancode == 0) |
if (tr.scancode == 0) |
1002 |
break; |
break; |
1003 |
|
|
1004 |
save_remote_modifiers(); |
save_remote_modifiers(tr.scancode); |
1005 |
ensure_remote_modifiers(ev_time, tr); |
ensure_remote_modifiers(ev_time, tr); |
1006 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); |
1007 |
restore_remote_modifiers(); |
restore_remote_modifiers(ev_time, tr.scancode); |
1008 |
|
|
1009 |
break; |
break; |
1010 |
|
|
1197 |
ui_select(int rdp_socket) |
ui_select(int rdp_socket) |
1198 |
{ |
{ |
1199 |
int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1; |
int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1; |
1200 |
fd_set rfds; |
fd_set rfds, wfds; |
|
|
|
|
FD_ZERO(&rfds); |
|
1201 |
|
|
1202 |
while (True) |
while (True) |
1203 |
{ |
{ |
1207 |
return 0; |
return 0; |
1208 |
|
|
1209 |
FD_ZERO(&rfds); |
FD_ZERO(&rfds); |
1210 |
|
FD_ZERO(&wfds); |
1211 |
FD_SET(rdp_socket, &rfds); |
FD_SET(rdp_socket, &rfds); |
1212 |
FD_SET(g_x_socket, &rfds); |
FD_SET(g_x_socket, &rfds); |
1213 |
|
|
1214 |
switch (select(n, &rfds, NULL, NULL, NULL)) |
#ifdef WITH_RDPSND |
1215 |
|
/* FIXME: there should be an API for registering fds */ |
1216 |
|
if (g_dsp_busy) |
1217 |
|
{ |
1218 |
|
FD_SET(g_dsp_fd, &wfds); |
1219 |
|
n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; |
1220 |
|
} |
1221 |
|
#endif |
1222 |
|
|
1223 |
|
switch (select(n, &rfds, &wfds, NULL, NULL)) |
1224 |
{ |
{ |
1225 |
case -1: |
case -1: |
1226 |
error("select: %s\n", strerror(errno)); |
error("select: %s\n", strerror(errno)); |
1231 |
|
|
1232 |
if (FD_ISSET(rdp_socket, &rfds)) |
if (FD_ISSET(rdp_socket, &rfds)) |
1233 |
return 1; |
return 1; |
1234 |
|
|
1235 |
|
#ifdef WITH_RDPSND |
1236 |
|
if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds)) |
1237 |
|
wave_out_play(); |
1238 |
|
#endif |
1239 |
} |
} |
1240 |
} |
} |
1241 |
|
|
1411 |
XFreeCursor(g_display, (Cursor) cursor); |
XFreeCursor(g_display, (Cursor) cursor); |
1412 |
} |
} |
1413 |
|
|
1414 |
|
void |
1415 |
|
ui_set_null_cursor(void) |
1416 |
|
{ |
1417 |
|
ui_set_cursor(g_null_cursor); |
1418 |
|
} |
1419 |
|
|
1420 |
#define MAKE_XCOLOR(xc,c) \ |
#define MAKE_XCOLOR(xc,c) \ |
1421 |
(xc)->red = ((c)->red << 8) | (c)->red; \ |
(xc)->red = ((c)->red << 8) | (c)->red; \ |
1422 |
(xc)->green = ((c)->green << 8) | (c)->green; \ |
(xc)->green = ((c)->green << 8) | (c)->green; \ |
1617 |
case 2: /* Hatch */ |
case 2: /* Hatch */ |
1618 |
fill = (Pixmap) ui_create_glyph(8, 8, |
fill = (Pixmap) ui_create_glyph(8, 8, |
1619 |
hatch_patterns + brush->pattern[0] * 8); |
hatch_patterns + brush->pattern[0] * 8); |
1620 |
SET_FOREGROUND(bgcolour); |
SET_FOREGROUND(fgcolour); |
1621 |
SET_BACKGROUND(fgcolour); |
SET_BACKGROUND(bgcolour); |
1622 |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
XSetFillStyle(g_display, g_gc, FillOpaqueStippled); |
1623 |
XSetStipple(g_display, g_gc, fill); |
XSetStipple(g_display, g_gc, fill); |
1624 |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |
XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin); |