--- sourceforge.net/trunk/rdesktop/xwin.c 2003/10/19 11:59:41 504 +++ sourceforge.net/trunk/rdesktop/xwin.c 2003/10/29 06:29:05 524 @@ -49,6 +49,7 @@ static XIC g_IC; static XModifierKeymap *g_mod_map; static Cursor g_current_cursor; +static HCURSOR g_null_cursor; static Atom g_protocol_atom, g_kill_atom; static BOOL g_focused; static BOOL g_mouse_in_wnd; @@ -56,6 +57,7 @@ /* endianness */ static BOOL g_host_be; static BOOL g_xserver_be; +static BOOL g_xserver_bgr; /* software backing store */ static BOOL g_ownbackstore; @@ -201,33 +203,29 @@ 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; + if (g_xserver_bgr) + return (pc.blue << 11) | (pc.green << 5) | pc.red; + else + 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); - } + if (g_xserver_bgr) + return (pc.blue << 16) | (pc.green << 8) | pc.red; else - { return (pc.red << 16) | (pc.green << 8) | pc.blue; - } } static uint32 make_colour32(PixelColour pc) { - if (g_xserver_be) - { - return pc.red | (pc.green << 8) | (pc.blue << 16); - } + if (g_xserver_bgr) + return (pc.blue << 16) | (pc.green << 8) | pc.red; else - { return (pc.red << 16) | (pc.green << 8) | pc.blue; - } } #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } @@ -274,6 +272,7 @@ colour = make_colour16(split_colour24(colour)); break; case 24: + colour = make_colour24(split_colour24(colour)); break; case 32: colour = make_colour32(split_colour24(colour)); @@ -292,10 +291,25 @@ } static void -translate8to16(uint8 * data, uint16 * out, uint16 * end) +translate8to16(uint8 * data, uint8 * out, uint8 * end) { + uint16 value; + while (out < end) - *(out++) = (uint16) g_colmap[*(data++)]; + { + value = (uint16) g_colmap[*(data++)]; + + if (g_xserver_be) + { + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + } + } } /* little endian - conversion happens when colourmap is built */ @@ -307,17 +321,46 @@ while (out < end) { value = g_colmap[*(data++)]; - *(out++) = value; - *(out++) = value >> 8; - *(out++) = value >> 16; + + if (g_xserver_be) + { + *(out++) = value >> 16; + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + } } } static void -translate8to32(uint8 * data, uint32 * out, uint32 * end) +translate8to32(uint8 * data, uint8 * out, uint8 * end) { + uint32 value; + while (out < end) - *(out++) = g_colmap[*(data++)]; + { + value = g_colmap[*(data++)]; + + 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; + } + } } /* todo the remaining translate function might need some big endian check ?? */ @@ -334,7 +377,8 @@ if (g_host_be) { - BSWAP16(pixel)} + BSWAP16(pixel); + } value = make_colour16(split_colour15(pixel)); @@ -363,7 +407,8 @@ if (g_host_be) { - BSWAP16(pixel)} + BSWAP16(pixel); + } value = make_colour24(split_colour15(pixel)); if (g_xserver_be) @@ -456,7 +501,8 @@ if (g_host_be) { - BSWAP16(pixel)} + BSWAP16(pixel); + } value = make_colour24(split_colour16(pixel)); @@ -624,13 +670,13 @@ translate8to8(data, out, end); break; case 16: - translate8to16(data, (uint16 *) out, (uint16 *) end); + translate8to16(data, out, end); break; case 24: translate8to24(data, out, end); break; case 32: - translate8to32(data, (uint32 *) out, (uint32 *) end); + translate8to32(data, out, end); break; } break; @@ -704,7 +750,11 @@ return False; } - if (g_owncolmap != True) + /* private colour map code only works for 8 bpp */ + if (g_owncolmap && (g_bpp > 8)) + g_owncolmap = False; + + if (!g_owncolmap) { g_xcolmap = DefaultColormapOfScreen(g_screen); if (g_depth <= 8) @@ -719,6 +769,7 @@ test = 1; g_host_be = !(BOOL) (*(uint8 *) (&test)); g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); + g_xserver_bgr = (g_visual->blue_mask > g_visual->red_mask); /* * Determine desktop size @@ -775,8 +826,7 @@ xclip_init(); - /* todo take this out when high colour is done */ - printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth); + DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth)); return True; } @@ -797,6 +847,9 @@ g_display = NULL; } +#define NULL_POINTER_MASK "\x80" +#define NULL_POINTER_DATA "\x0\x0\x0" + BOOL ui_create_window(void) { @@ -881,12 +934,17 @@ g_kill_atom = XInternAtom(g_display, "WM_DELETE_WINDOW", True); XSetWMProtocols(g_display, g_wnd, &g_kill_atom, 1); + /* create invisible 1x1 cursor to be used as null cursor */ + g_null_cursor = ui_create_cursor(0, 0, 1, 1, NULL_POINTER_MASK, NULL_POINTER_DATA); + return True; } void ui_destroy_window(void) { + ui_destroy_cursor(g_null_cursor); + if (g_IC != NULL) XDestroyIC(g_IC); @@ -1242,11 +1300,24 @@ XImage *image; Pixmap bitmap; uint8 *tdata; + int bitmap_pad; + + if (g_server_bpp == 8) + { + bitmap_pad = 8; + } + else + { + bitmap_pad = g_bpp; + + if (g_bpp == 24) + bitmap_pad = 32; + } tdata = (g_owncolmap ? data : translate_image(width, height, data)); bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth); image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, - (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); + (char *) tdata, width, height, bitmap_pad, 0); XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height); @@ -1261,9 +1332,23 @@ { XImage *image; uint8 *tdata; + int bitmap_pad; + + if (g_server_bpp == 8) + { + bitmap_pad = 8; + } + else + { + bitmap_pad = g_bpp; + + if (g_bpp == 24) + bitmap_pad = 32; + } + tdata = (g_owncolmap ? data : translate_image(width, height, data)); image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, - (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); + (char *) tdata, width, height, bitmap_pad, 0); if (g_ownbackstore) { @@ -1402,6 +1487,12 @@ XFreeCursor(g_display, (Cursor) cursor); } +void +ui_set_null_cursor(void) +{ + ui_set_cursor(g_null_cursor); +} + #define MAKE_XCOLOR(xc,c) \ (xc)->red = ((c)->red << 8) | (c)->red; \ (xc)->green = ((c)->green << 8) | (c)->green; \