--- sourceforge.net/trunk/rdesktop/xwin.c 2002/11/26 10:09:14 279 +++ sourceforge.net/trunk/rdesktop/xwin.c 2003/02/05 14:16:33 311 @@ -31,6 +31,7 @@ extern BOOL grab_keyboard; extern BOOL hide_decorations; extern char title[]; +extern int server_bpp; BOOL enable_compose = False; BOOL focused; BOOL mouse_in_wnd; @@ -62,11 +63,11 @@ #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 typedef struct { - unsigned long flags; - unsigned long functions; - unsigned long decorations; - long inputMode; - unsigned long status; + uint32 flags; + uint32 functions; + uint32 decorations; + sint32 inputMode; + uint32 status; } PropMotifWmHints; @@ -78,12 +79,17 @@ XFillRectangle(display, backstore, gc, x, y, cx, cy); \ } +#define FILL_RECTANGLE_BACKSTORE(x,y,cx,cy)\ +{ \ + XFillRectangle(display, ownbackstore ? backstore : wnd, gc, x, y, cx, cy); \ +} + /* colour maps */ BOOL owncolmap = False; static Colormap xcolmap; static uint32 *colmap; -#define TRANSLATE(col) ( owncolmap ? col : translate_colour(colmap[col]) ) +#define TRANSLATE(col) ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) ) #define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); #define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); @@ -123,7 +129,7 @@ hintsatom = XInternAtom(display, "_MOTIF_WM_HINTS", False); if (!hintsatom) { - error("Failed to get atom _MOTIF_WM_HINTS\n"); + warning("Failed to get atom _MOTIF_WM_HINTS: probably your window manager does not support MWM hints\n"); return; } @@ -131,23 +137,112 @@ (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); } +uint32 +colour16to24(uint32 colour) +{ + int r; + int g; + int b; + r = (colour & 0xf800) >> 11; + r = (r * 0xff) / 0x1f; + g = (colour & 0x07e0) >> 5; + g = (g * 0xff) / 0x3f; + b = (colour & 0x001f); + b = (b * 0xff) / 0x1f; + return (r << 16) | (g << 8) | b; +} + +uint32 +colour16to32(uint32 colour) +{ + return colour16to24(colour); +} + +uint32 +colour24to32(uint32 colour) +{ + return colour; +} + +#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } +#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } +#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ + x = (x << 16) | (x >> 16); } + +static uint32 +translate_colour(uint32 colour) +{ + switch (server_bpp) + { + case 16: + switch (bpp) + { + case 16: + break; + case 24: + colour = colour16to24(colour); + break; + case 32: + colour = colour16to32(colour); + break; + } + break; + case 24: + switch (bpp) + { + case 24: + break; + case 32: + colour = colour24to32(colour); + break; + } + break; + } + switch (bpp) + { + case 16: + if (host_be != xserver_be) + BSWAP16(colour); + break; + + case 24: + if (xserver_be) + BSWAP24(colour); + break; + + case 32: + if (host_be != xserver_be) + BSWAP32(colour); + break; + } + + return colour; +} + static void -translate8(uint8 * data, uint8 * out, uint8 * end) +translate8to8(uint8 * data, uint8 * out, uint8 * end) { while (out < end) *(out++) = (uint8) colmap[*(data++)]; } static void -translate16(uint8 * data, uint16 * out, uint16 * end) +translate8to16(uint8 * data, uint16 * out, uint16 * end) { while (out < end) *(out++) = (uint16) colmap[*(data++)]; } +static void +translate16to16(uint16 * data, uint16 * out, uint16 * end) +{ + while (out < end) + *(out++) = (uint16) translate_colour(*(data++)); +} + /* little endian - conversion happens when colourmap is built */ static void -translate24(uint8 * data, uint8 * out, uint8 * end) +translate8to24(uint8 * data, uint8 * out, uint8 * end) { uint32 value; @@ -161,12 +256,33 @@ } static void -translate32(uint8 * data, uint32 * out, uint32 * end) +translate16to24(uint16 * data, uint8 * out, uint8 * end) +{ + uint32 value; + + while (out < end) + { + value = translate_colour(*(data++)); + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + } +} + +static void +translate8to32(uint8 * data, uint32 * out, uint32 * end) { while (out < end) *(out++) = colmap[*(data++)]; } +static void +translate16to32(uint16 * data, uint32 * out, uint32 * end) +{ + while (out < end) + *(out++) = translate_colour(*(data++)); +} + static uint8 * translate_image(int width, int height, uint8 * data) { @@ -174,57 +290,39 @@ uint8 *out = xmalloc(size); uint8 *end = out + size; + if (server_bpp == 16) + { + if (bpp == 16) + translate16to16((uint16 *) data, (uint16 *) out, (uint16 *) end); + else if (bpp == 24) + translate16to24((uint16 *) data, out, end); /* todo, check this one */ + else if (bpp == 32) + translate16to32((uint16 *) data, (uint32 *) out, (uint32 *) end); + return out; + } + /* todo needs server_bpp == 24 */ switch (bpp) { case 8: - translate8(data, out, end); + translate8to8(data, out, end); break; case 16: - translate16(data, (uint16 *) out, (uint16 *) end); + translate8to16(data, (uint16 *) out, (uint16 *) end); break; case 24: - translate24(data, out, end); + translate8to24(data, out, end); break; case 32: - translate32(data, (uint32 *) out, (uint32 *) end); + translate8to32(data, (uint32 *) out, (uint32 *) end); break; } return out; } -#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } -#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } -#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ - x = (x << 16) | (x >> 16); } - -static uint32 -translate_colour(uint32 colour) -{ - switch (bpp) - { - case 16: - if (host_be != xserver_be) - BSWAP16(colour); - break; - - case 24: - if (xserver_be) - BSWAP24(colour); - break; - - case 32: - if (host_be != xserver_be) - BSWAP32(colour); - break; - } - - return colour; -} - BOOL get_key_state(unsigned int state, uint32 keysym) { @@ -295,10 +393,7 @@ { xcolmap = DefaultColormapOfScreen(screen); if (depth <= 8) - { - printf("You're using a screen depth of 8-bits or lower\n"); - printf("If you get scewed colours, try the -C switch\n"); - } + warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); } gc = XCreateGC(display, RootWindowOfScreen(screen), 0, NULL); @@ -313,13 +408,16 @@ if ((width == 0) || (height == 0)) { /* Fetch geometry from _NET_WORKAREA */ - uint32 xpos, ypos; + uint32 x, y, cx, cy; - if (get_current_workarea(&xpos, &ypos, &width, &height) < 0) + if (get_current_workarea(&x, &y, &cx, &cy) == 0) + { + width = cx; + height = cy; + } + else { - error("Failed to get workarea.\n"); - error("Perhaps your window manager does not support EWMH?\n"); - error("Defaulting to geometry 800x600\n"); + warning("Failed to get workarea: probably your window manager does not support extended hints\n"); width = 800; height = 600; } @@ -602,6 +700,9 @@ break; case MotionNotify: + if (fullscreen && !focused) + XSetInputFocus(display, wnd, RevertToPointerRoot, + CurrentTime); rdp_send_input(time(NULL), RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, xevent.xmotion.x, xevent.xmotion.y); break; @@ -725,7 +826,7 @@ tdata = (owncolmap ? data : translate_image(width, height, data)); bitmap = XCreatePixmap(display, wnd, width, height, depth); image = XCreateImage(display, visual, depth, ZPixmap, 0, - (char *) tdata, width, height, 8, 0); + (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); @@ -740,10 +841,9 @@ { XImage *image; uint8 *tdata; - tdata = (owncolmap ? data : translate_image(width, height, data)); image = XCreateImage(display, visual, depth, ZPixmap, 0, - (char *) tdata, width, height, 8, 0); + (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); if (ownbackstore) { @@ -1184,10 +1284,7 @@ XSetStipple(display, gc, (Pixmap) glyph); XSetTSOrigin(display, gc, x, y); - if (ownbackstore) - XFillRectangle(display, backstore, gc, x, y, cx, cy); - else - XFillRectangle(display, wnd, gc, x, y, cx, cy); + FILL_RECTANGLE_BACKSTORE(x, y, cx, cy); XSetFillStyle(display, gc, FillSolid); } @@ -1216,8 +1313,8 @@ }\ if (glyph != NULL)\ {\ - ui_draw_glyph (mixmode, x + (short) glyph->offset,\ - y + (short) glyph->baseline,\ + ui_draw_glyph (mixmode, x + glyph->offset,\ + y + glyph->baseline,\ glyph->width, glyph->height,\ glyph->pixmap, 0, 0, bgcolour, fgcolour);\ if (flags & TEXT2_IMPLICIT_X)\ @@ -1239,11 +1336,11 @@ if (boxcx > 1) { - FILL_RECTANGLE(boxx, boxy, boxcx, boxcy); + FILL_RECTANGLE_BACKSTORE(boxx, boxy, boxcx, boxcy); } else if (mixmode == MIX_OPAQUE) { - FILL_RECTANGLE(clipx, clipy, clipcx, clipcy); + FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); } /* Paint text, character by character */ @@ -1277,17 +1374,17 @@ else x += text[i + 2]; } - 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; for (j = 0; j < entry->size; j++) DO_GLYPH(((uint8 *) (entry->data)), j); } + 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; break; default: