--- sourceforge.net/trunk/rdesktop/xwin.c 2003/10/31 04:29:57 536 +++ sourceforge.net/trunk/rdesktop/xwin.c 2004/01/19 23:45:26 566 @@ -20,6 +20,7 @@ #include #include +#include #include #include #include "rdesktop.h" @@ -42,6 +43,7 @@ Window g_wnd; BOOL g_enable_compose = False; static GC g_gc; +static BOOL g_gc_initialized = False; static Visual *g_visual; static int g_depth; static int g_bpp; @@ -63,6 +65,7 @@ /* software backing store */ static BOOL g_ownbackstore; static Pixmap g_backstore; +static BOOL g_backstore_initialized = False; /* Moving in single app mode */ static BOOL g_moving_wnd; @@ -310,8 +313,6 @@ } } -/* todo the remaining translate function might need some big endian check ?? */ - static void translate15to16(uint16 * data, uint8 * out, uint8 * end) { @@ -542,7 +543,7 @@ pixel |= *(data++); value = make_colour(split_colour24(pixel)); - + if (g_xserver_be) { *(out++) = value >> 16; @@ -700,7 +701,10 @@ XVisualInfo vi; XPixmapFormatValues *pfm; uint16 test; - int i, screen_num; + int i, screen_num, nvisuals; + XVisualInfo *vmatches = NULL; + XVisualInfo template; + Bool TrueColorVisual = False; g_display = XOpenDisplay(NULL); if (g_display == NULL) @@ -714,10 +718,32 @@ g_screen = ScreenOfDisplay(g_display, screen_num); g_depth = DefaultDepthOfScreen(g_screen); - if (g_server_bpp == 8) + /* Search for best TrueColor depth */ + template.class = TrueColor; + vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals); + + nvisuals--; + while (nvisuals >= 0) + { + if ((vmatches + nvisuals)->depth > g_depth) + { + g_depth = (vmatches + nvisuals)->depth; + } + nvisuals--; + TrueColorVisual = True; + } + + if ((g_server_bpp == 8) && ((! TrueColorVisual) || (g_depth <= 8))) { - /* we use a colourmap, so any visual should do */ + /* we use a colourmap, so the default visual should do */ g_visual = DefaultVisualOfScreen(g_screen); + g_depth = DefaultDepthOfScreen(g_screen); + + /* Do not allocate colours on a TrueColor visual */ + if (g_visual->class == TrueColor) + { + g_owncolmap = False; + } } else { @@ -759,13 +785,11 @@ if (!g_owncolmap) { - g_xcolmap = DefaultColormapOfScreen(g_screen); + g_xcolmap = XCreateColormap(g_display,RootWindowOfScreen(g_screen),g_visual,AllocNone); if (g_depth <= 8) warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n"); } - g_gc = XCreateGC(g_display, RootWindowOfScreen(g_screen), 0, NULL); - if (DoesBackingStore(g_screen) != Always) g_ownbackstore = True; @@ -776,7 +800,12 @@ /* * Determine desktop size */ - if (g_width < 0) + if (g_fullscreen) + { + g_width = WidthOfScreen(g_screen); + g_height = HeightOfScreen(g_screen); + } + else if (g_width < 0) { /* Percent of screen */ g_height = HeightOfScreen(g_screen) * (-g_width) / 100; @@ -799,26 +828,10 @@ g_height = 600; } } - else if (g_fullscreen) - { - g_width = WidthOfScreen(g_screen); - g_height = HeightOfScreen(g_screen); - } /* make sure width is a multiple of 4 */ g_width = (g_width + 3) & ~3; - if (g_ownbackstore) - { - g_backstore = - XCreatePixmap(g_display, RootWindowOfScreen(g_screen), g_width, g_height, - g_depth); - - /* clear to prevent rubbish being exposed at startup */ - XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen)); - XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height); - } - g_mod_map = XGetModifierMapping(g_display); xkeymap_init(); @@ -865,12 +878,33 @@ wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; attribs.background_pixel = BlackPixelOfScreen(g_screen); + attribs.border_pixel = WhitePixelOfScreen(g_screen); attribs.backing_store = g_ownbackstore ? NotUseful : Always; attribs.override_redirect = g_fullscreen; + attribs.colormap = g_xcolmap; g_wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), 0, 0, wndwidth, wndheight, - 0, CopyFromParent, InputOutput, CopyFromParent, - CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs); + 0, g_depth, InputOutput, g_visual, + CWBackPixel | CWBackingStore | CWOverrideRedirect | + CWColormap | CWBorderPixel, &attribs); + + if ( ! g_gc_initialized ) + { + g_gc = XCreateGC(g_display, g_wnd, 0, NULL); + g_gc_initialized = True; + } + + if ((g_ownbackstore) && (! g_backstore_initialized)) + { + g_backstore = + XCreatePixmap(g_display, g_wnd, g_width, g_height, + g_depth); + + /* clear to prevent rubbish being exposed at startup */ + XSetForeground(g_display, g_gc, BlackPixelOfScreen(g_screen)); + XFillRectangle(g_display, g_backstore, g_gc, 0, 0, g_width, g_height); + g_backstore_initialized = True; + } XStoreName(g_display, g_wnd, g_title); @@ -944,8 +978,6 @@ void ui_destroy_window(void) { - ui_destroy_cursor(g_null_cursor); - if (g_IC != NULL) XDestroyIC(g_IC); @@ -989,9 +1021,6 @@ key_translation tr; char str[256]; Status status; - unsigned int state; - Window wdummy; - int dummy; while (XPending(g_display) > 0) { @@ -1164,9 +1193,7 @@ if (xevent.xfocus.mode == NotifyGrab) break; g_focused = True; - XQueryPointer(g_display, g_wnd, &wdummy, &wdummy, &dummy, &dummy, - &dummy, &dummy, &state); - reset_modifier_keys(state); + reset_modifier_keys(); if (g_grab_keyboard && g_mouse_in_wnd) XGrabKeyboard(g_display, g_wnd, True, GrabModeAsync, GrabModeAsync, CurrentTime); @@ -1831,33 +1858,34 @@ {\ glyph = cache_get_font (font, ttext[idx]);\ if (!(flags & TEXT2_IMPLICIT_X))\ + {\ + xyoffset = ttext[++idx];\ + if ((xyoffset & 0x80))\ {\ - xyoffset = ttext[++idx];\ - if ((xyoffset & 0x80))\ - {\ - if (flags & TEXT2_VERTICAL) \ - y += ttext[idx+1] | (ttext[idx+2] << 8);\ - else\ - x += ttext[idx+1] | (ttext[idx+2] << 8);\ - idx += 2;\ - }\ + if (flags & TEXT2_VERTICAL)\ + y += ttext[idx+1] | (ttext[idx+2] << 8);\ else\ - {\ - if (flags & TEXT2_VERTICAL) \ - y += xyoffset;\ - else\ - x += xyoffset;\ - }\ + x += ttext[idx+1] | (ttext[idx+2] << 8);\ + idx += 2;\ }\ - if (glyph != NULL)\ + else\ {\ - 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)\ - x += glyph->width;\ + if (flags & TEXT2_VERTICAL)\ + y += xyoffset;\ + else\ + x += xyoffset;\ }\ + }\ + if (glyph != NULL)\ + {\ + x1 = x + glyph->offset;\ + y1 = y + glyph->baseline;\ + XSetStipple(g_display, g_gc, (Pixmap) glyph->pixmap);\ + XSetTSOrigin(g_display, g_gc, x1, y1);\ + FILL_RECTANGLE_BACKSTORE(x1, y1, glyph->width, glyph->height);\ + if (flags & TEXT2_IMPLICIT_X)\ + x += glyph->width;\ + }\ } void @@ -1867,7 +1895,7 @@ int fgcolour, uint8 * text, uint8 length) { FONTGLYPH *glyph; - int i, j, xyoffset; + int i, j, xyoffset, x1, y1; DATABLOB *entry; SET_FOREGROUND(bgcolour); @@ -1881,6 +1909,10 @@ FILL_RECTANGLE_BACKSTORE(clipx, clipy, clipcx, clipcy); } + SET_FOREGROUND(fgcolour); + SET_BACKGROUND(bgcolour); + XSetFillStyle(g_display, g_gc, FillStippled); + /* Paint text, character by character */ for (i = 0; i < length;) { @@ -1931,6 +1963,9 @@ break; } } + + XSetFillStyle(g_display, g_gc, FillSolid); + if (g_ownbackstore) { if (boxcx > 1)