--- sourceforge.net/trunk/rdesktop/xwin.c 2003/09/02 09:40:07 461 +++ sourceforge.net/trunk/rdesktop/xwin.c 2003/10/11 19:12:10 483 @@ -34,15 +34,13 @@ extern char g_title[]; extern int g_server_bpp; extern int g_win_button_size; -BOOL g_enable_compose = False; -BOOL g_focused; -BOOL g_mouse_in_wnd; Display *g_display; Time g_last_gesturetime; static int g_x_socket; static Screen *g_screen; Window g_wnd; +BOOL g_enable_compose = False; static GC g_gc; static Visual *g_visual; static int g_depth; @@ -52,6 +50,8 @@ static XModifierKeymap *g_mod_map; static Cursor g_current_cursor; static Atom g_protocol_atom, g_kill_atom; +static BOOL g_focused; +static BOOL g_mouse_in_wnd; /* endianness */ static BOOL g_host_be; @@ -66,6 +66,11 @@ static int g_move_x_offset = 0; static int g_move_y_offset = 0; +#ifdef WITH_RDPSND +extern int g_dsp_fd; +extern BOOL g_dsp_busy; +#endif + /* MWM decorations */ #define MWM_HINTS_DECORATIONS (1L << 1) #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 @@ -201,13 +206,27 @@ static uint32 make_colour24(PixelColour pc) { - return (pc.red << 16) | (pc.green << 8) | pc.blue; + 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) { - return (pc.red << 16) | (pc.green << 8) | pc.blue; + if (g_xserver_be) + { + return pc.red | (pc.green << 8) | (pc.blue << 16); + } + else + { + return (pc.red << 16) | (pc.green << 8) | pc.blue; + } } #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } @@ -261,24 +280,6 @@ } 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); - break; - } - return colour; } @@ -321,38 +322,126 @@ /* todo the remaining translate function might need some big endian check ?? */ static void -translate15to16(uint16 * data, uint16 * out, uint16 * end) +translate15to16(uint16 * data, uint8 * out, uint8 * end) { + uint16 pixel; + uint16 value; + while (out < end) - *(out++) = (uint16) make_colour16(split_colour15(*(data++))); + { + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel) + } + + value = make_colour16(split_colour15(pixel)); + + if (g_xserver_be) + { + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + } + } } static void translate15to24(uint16 * data, uint8 * out, uint8 * end) { uint32 value; + uint16 pixel; while (out < end) { - value = make_colour24(split_colour15(*(data++))); - *(out++) = value; - *(out++) = value >> 8; - *(out++) = value >> 16; + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel) + } + + value = make_colour24(split_colour15(pixel)); + if (g_xserver_be) + { + *(out++) = value >> 16; + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + } } } static void -translate15to32(uint16 * data, uint32 * out, uint32 * end) +translate15to32(uint16 * data, uint8 * out, uint8 * end) { + uint16 pixel; + uint32 value; + while (out < end) - *(out++) = make_colour32(split_colour15(*(data++))); + { + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel); + } + + value = make_colour32(split_colour15(pixel)); + + if (g_xserver_be) + { + *(out++) = value >> 24; + *(out++) = value >> 16; + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + *(out++) = value >> 24; + } + } } static void translate16to16(uint16 * data, uint16 * out, uint16 * end) { - while (out < end) - *(out++) = (uint16) (*(data++)); + uint16 value; + + if (g_xserver_be) + { + while (out < end) + { + value = *data; + BSWAP16(value); + *out = value; + data++; + out++; + } + + } + else + { + while (out < end) + { + *out = *data; + out++; + data++; + } + } } @@ -360,33 +449,91 @@ translate16to24(uint16 * data, uint8 * out, uint8 * end) { uint32 value; + uint16 pixel; while (out < end) { - value = make_colour24(split_colour16(*(data++))); - *(out++) = value; - *(out++) = value >> 8; - *(out++) = value >> 16; + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel) + } + + value = make_colour24(split_colour16(pixel)); + + if (g_xserver_be) + { + *(out++) = value >> 16; + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + } } } static void -translate16to32(uint16 * data, uint32 * out, uint32 * end) +translate16to32(uint16 * data, uint8 * out, uint8 * end) { + uint16 pixel; + uint32 value; + while (out < end) - *(out++) = make_colour32(split_colour16(*(data++))); + { + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel) + } + + value = make_colour32(split_colour16(pixel)); + + if (g_xserver_be) + { + *(out++) = value >> 24; + *(out++) = value >> 16; + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + *(out++) = value >> 24; + } + } } static void -translate24to16(uint8 * data, uint16 * out, uint16 * end) +translate24to16(uint8 * data, uint8 * out, uint8 * end) { uint32 pixel = 0; + uint16 value; while (out < end) { pixel = *(data++) << 16; pixel |= *(data++) << 8; pixel |= *(data++); - *(out++) = (uint16) make_colour16(split_colour24(pixel)); + + value = (uint16) make_colour16(split_colour24(pixel)); + + if (g_xserver_be) + { + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + } } } @@ -400,15 +547,24 @@ } static void -translate24to32(uint8 * data, uint32 * out, uint32 * end) +translate24to32(uint8 * data, uint8 * out, uint8 * end) { - uint32 pixel = 0; while (out < end) { - pixel = *(data++); - pixel |= *(data++) << 8; - pixel |= *(data++) << 16; - *(out++) = pixel; + if (g_xserver_be) + { + *(out++) = 0x00; + *(out++) = *(data++); + *(out++) = *(data++); + *(out++) = *(data++); + } + else + { + *(out++) = *(data++); + *(out++) = *(data++); + *(out++) = *(data++); + *(out++) = 0x00; + } } } @@ -425,13 +581,13 @@ switch (g_bpp) { case 32: - translate24to32(data, (uint32 *) out, (uint32 *) end); + translate24to32(data, out, end); break; case 24: translate24to24(data, out, end); break; case 16: - translate24to16(data, (uint16 *) out, (uint16 *) end); + translate24to16(data, out, end); break; } break; @@ -439,8 +595,7 @@ switch (g_bpp) { case 32: - translate16to32((uint16 *) data, (uint32 *) out, - (uint32 *) end); + translate16to32((uint16 *) data, out, end); break; case 24: translate16to24((uint16 *) data, out, end); @@ -455,15 +610,13 @@ switch (g_bpp) { case 32: - translate15to32((uint16 *) data, (uint32 *) out, - (uint32 *) end); + translate15to32((uint16 *) data, out, end); break; case 24: translate15to24((uint16 *) data, out, end); break; case 16: - translate15to16((uint16 *) data, (uint16 *) out, - (uint16 *) end); + translate15to16((uint16 *) data, out, end); break; } break; @@ -833,10 +986,10 @@ if (tr.scancode == 0) break; - save_remote_modifiers(); + save_remote_modifiers(tr.scancode); ensure_remote_modifiers(ev_time, tr); rdp_send_scancode(ev_time, RDP_KEYPRESS, tr.scancode); - restore_remote_modifiers(ev_time); + restore_remote_modifiers(ev_time, tr.scancode); break; @@ -1029,9 +1182,7 @@ ui_select(int rdp_socket) { int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1; - fd_set rfds; - - FD_ZERO(&rfds); + fd_set rfds, wfds; while (True) { @@ -1041,10 +1192,20 @@ return 0; FD_ZERO(&rfds); + FD_ZERO(&wfds); FD_SET(rdp_socket, &rfds); FD_SET(g_x_socket, &rfds); - switch (select(n, &rfds, NULL, NULL, NULL)) +#ifdef WITH_RDPSND + /* FIXME: there should be an API for registering fds */ + if (g_dsp_busy) + { + FD_SET(g_dsp_fd, &wfds); + n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; + } +#endif + + switch (select(n, &rfds, &wfds, NULL, NULL)) { case -1: error("select: %s\n", strerror(errno)); @@ -1055,6 +1216,11 @@ if (FD_ISSET(rdp_socket, &rfds)) return 1; + +#ifdef WITH_RDPSND + if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds)) + wave_out_play(); +#endif } }