--- sourceforge.net/trunk/rdesktop/xwin.c 2005/03/10 22:48:15 844 +++ sourceforge.net/trunk/rdesktop/xwin.c 2006/01/24 12:40:24 1042 @@ -32,12 +32,15 @@ extern int g_height; extern int g_xpos; extern int g_ypos; +extern int g_pos; extern BOOL g_sendmotion; extern BOOL g_fullscreen; extern BOOL g_grab_keyboard; extern BOOL g_hide_decorations; extern char g_title[]; -extern int g_server_bpp; +/* Color depth of the RDP session. + As of RDP 5.1, it may be 8, 15, 16 or 24. */ +extern int g_server_depth; extern int g_win_button_size; Display *g_display; @@ -52,7 +55,13 @@ static GC g_create_bitmap_gc = NULL; static GC g_create_glyph_gc = NULL; static Visual *g_visual; +/* Color depth of the X11 visual of our window (e.g. 24 for True Color R8G8B visual). + This may be 32 for R8G8B8 visuals, and then the rest of the bits are undefined + as far as we're concerned. */ static int g_depth; +/* Bits-per-Pixel of the pixmaps we'll be using to draw on our window. + This may be larger than g_depth, in which case some of the bits would + be kept solely for alignment (e.g. 32bpp pixmaps on a 24bpp visual). */ static int g_bpp; static XIM g_IM; static XIC g_IC; @@ -62,7 +71,13 @@ static Atom g_protocol_atom, g_kill_atom; static BOOL g_focused; static BOOL g_mouse_in_wnd; -static BOOL g_arch_match = False; /* set to True if RGB XServer and little endian */ +/* Indicates the visual is has 15, 16 or 24 depth + and the same color channel masks as its RDP equivalent. */ +static BOOL g_compatible_depth; +/* Indicates whether RDP's bitmaps and our XImages have the same + binary format. If so, we can avoid an expensive translation. + If this is True, so is g_compatible_depth. */ +static BOOL g_no_translate_image = False; /* endianness */ static BOOL g_host_be; @@ -78,6 +93,7 @@ static BOOL g_moving_wnd; static int g_move_x_offset = 0; static int g_move_y_offset = 0; +static BOOL g_using_full_workarea = False; #ifdef WITH_RDPSND extern int g_dsp_fd; @@ -90,11 +106,11 @@ #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 typedef struct { - uint32 flags; - uint32 functions; - uint32 decorations; - sint32 inputMode; - uint32 status; + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long inputMode; + unsigned long status; } PropMotifWmHints; @@ -136,10 +152,9 @@ XDrawArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \ break; \ case 1: /* Filled */ \ - XFillArc(g_display, g_ownbackstore ? g_backstore : g_wnd, g_gc, x, y, \ - cx, cy, 0, 360*64); \ + XFillArc(g_display, g_wnd, g_gc, x, y, cx, cy, 0, 360*64); \ if (g_ownbackstore) \ - XCopyArea(g_display, g_backstore, g_wnd, g_gc, x, y, cx, cy, x, y); \ + XFillArc(g_display, g_backstore, g_gc, x, y, cx, cy, 0, 360*64); \ break; \ } \ } @@ -149,7 +164,7 @@ static Colormap g_xcolmap; static uint32 *g_colmap = NULL; -#define TRANSLATE(col) ( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] ) +#define TRANSLATE(col) ( g_server_depth != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] ) #define SET_FOREGROUND(col) XSetForeground(g_display, g_gc, TRANSLATE(col)); #define SET_BACKGROUND(col) XSetBackground(g_display, g_gc, TRANSLATE(col)); @@ -239,7 +254,7 @@ translate_colour(uint32 colour) { PixelColour pc; - switch (g_server_bpp) + switch (g_server_depth) { case 15: SPLITCOLOUR15(colour, pc); @@ -250,6 +265,12 @@ case 24: SPLITCOLOUR24(colour, pc); break; + default: + /* Avoid warning */ + pc.red = 0; + pc.green = 0; + pc.blue = 0; + break; } return MAKECOLOUR(pc); } @@ -301,7 +322,7 @@ { uint16 value; - if (g_arch_match) + if (g_compatible_depth) { /* *INDENT-OFF* */ REPEAT2 @@ -335,7 +356,7 @@ { uint32 value; - if (g_xserver_be) + if (g_compatible_depth) { while (out < end) { @@ -358,7 +379,7 @@ { uint32 value; - if (g_arch_match) + if (g_compatible_depth) { /* *INDENT-OFF* */ REPEAT4 @@ -430,7 +451,7 @@ uint16 pixel; PixelColour pc; - if (g_arch_match) + if (g_compatible_depth) { /* *INDENT-OFF* */ REPEAT3 @@ -480,7 +501,7 @@ uint32 value; PixelColour pc; - if (g_arch_match) + if (g_compatible_depth) { /* *INDENT-OFF* */ REPEAT4 @@ -588,7 +609,7 @@ uint16 pixel; PixelColour pc; - if (g_arch_match) + if (g_compatible_depth) { /* *INDENT-OFF* */ REPEAT3 @@ -658,7 +679,7 @@ uint32 value; PixelColour pc; - if (g_arch_match) + if (g_compatible_depth) { /* *INDENT-OFF* */ REPEAT4 @@ -787,7 +808,7 @@ uint32 value; PixelColour pc; - if (g_arch_match) + if (g_compatible_depth) { /* *INDENT-OFF* */ #ifdef NEED_ALIGN @@ -801,9 +822,10 @@ #else REPEAT4 ( - *((uint32 *) out) = *((uint32 *) data); - out += 4; - data += 3; + /* Only read 3 bytes. Reading 4 bytes means reading beyond buffer. */ + *((uint32 *) out) = *((uint16 *) data) + (*((uint8 *) data + 2) << 16); + out += 4; + data += 3; ) #endif /* *INDENT-ON* */ @@ -841,16 +863,19 @@ uint8 *out; uint8 *end; - /* if server and xserver bpp match, */ - /* and arch(endian) matches, no need to translate */ - /* just return data */ - if (g_arch_match) + /* + If RDP depth and X Visual depths match, + and arch(endian) matches, no need to translate: + just return data. + Note: select_visual should've already ensured g_no_translate + is only set for compatible depths, but the RDP depth might've + changed during connection negotiations. + */ + if (g_no_translate_image) { - if (g_depth == 15 && g_server_bpp == 15) - return data; - if (g_depth == 16 && g_server_bpp == 16) - return data; - if (g_depth == 24 && g_bpp == 24 && g_server_bpp == 24) + if ((g_depth == 15 && g_server_depth == 15) || + (g_depth == 16 && g_server_depth == 16) || + (g_depth == 24 && g_server_depth == 24)) return data; } @@ -858,7 +883,7 @@ out = (uint8 *) xmalloc(size); end = out + size; - switch (g_server_bpp) + switch (g_server_depth) { case 24: switch (g_bpp) @@ -956,126 +981,260 @@ *shift_r = 8 - ffs(mask & ~(mask >> 1)); } -BOOL -ui_init(void) +/* Given a mask of a colour channel (e.g. XVisualInfo.red_mask), + calculates the bits-per-pixel of this channel (a.k.a. colour weight). + */ +static unsigned +calculate_mask_weight(uint32 mask) +{ + unsigned weight = 0; + do + { + weight += (mask & 1); + } + while (mask >>= 1); + return weight; +} + +static BOOL +select_visual() { - XVisualInfo vi; XPixmapFormatValues *pfm; - uint16 test; - int i, screen_num, nvisuals; + int pixmap_formats_count, visuals_count; XVisualInfo *vmatches = NULL; XVisualInfo template; - Bool TrueColorVisual = False; + int i; + unsigned red_weight, blue_weight, green_weight; - g_display = XOpenDisplay(NULL); - if (g_display == NULL) + red_weight = blue_weight = green_weight = 0; + + pfm = XListPixmapFormats(g_display, &pixmap_formats_count); + if (pfm == NULL) { - error("Failed to open display: %s\n", XDisplayName(NULL)); + error("Unable to get list of pixmap formats from display.\n"); + XCloseDisplay(g_display); return False; } - screen_num = DefaultScreen(g_display); - g_x_socket = ConnectionNumber(g_display); - g_screen = ScreenOfDisplay(g_display, screen_num); - g_depth = DefaultDepthOfScreen(g_screen); - - /* Search for best TrueColor depth */ + /* Search for best TrueColor visual */ template.class = TrueColor; - vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals); + vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &visuals_count); + g_visual = NULL; + g_no_translate_image = False; + g_compatible_depth = False; + if (vmatches != NULL) + { + for (i = 0; i < visuals_count; ++i) + { + XVisualInfo *visual_info = &vmatches[i]; + + /* Try to find a no-translation visual that'll + allow us to use RDP bitmaps directly as ZPixmaps. */ + if (!g_xserver_be && (((visual_info->depth == 15) && + /* R5G5B5 */ + (visual_info->red_mask == 0x7c00) && + (visual_info->green_mask == 0x3e0) && + (visual_info->blue_mask == 0x1f)) || + ((visual_info->depth == 16) && + /* R5G6B5 */ + (visual_info->red_mask == 0xf800) && + (visual_info->green_mask == 0x7e0) && + (visual_info->blue_mask == 0x1f)) || + ((visual_info->depth == 24) && + /* R8G8B8 */ + (visual_info->red_mask == 0xff0000) && + (visual_info->green_mask == 0xff00) && + (visual_info->blue_mask == 0xff)))) + { + g_visual = visual_info->visual; + g_depth = visual_info->depth; + g_compatible_depth = True; + g_no_translate_image = (visual_info->depth == g_server_depth); + if (g_no_translate_image) + /* We found the best visual */ + break; + } + else + { + g_compatible_depth = False; + } + + if (visual_info->depth > 24) + { + /* Avoid 32-bit visuals and likes like the plague. + They're either untested or proven to work bad + (e.g. nvidia's Composite 32-bit visual). + Most implementation offer a 24-bit visual anyway. */ + continue; + } - nvisuals--; - while (nvisuals >= 0) - { - if ((vmatches + nvisuals)->depth > g_depth) - { - g_depth = (vmatches + nvisuals)->depth; + /* Only care for visuals, for whose BPPs (not depths!) + we have a translateXtoY function. */ + BOOL can_translate_to_bpp = False; + int j; + for (j = 0; j < pixmap_formats_count; ++j) + { + if (pfm[j].depth == visual_info->depth) + { + if ((pfm[j].bits_per_pixel == 16) || + (pfm[j].bits_per_pixel == 24) || + (pfm[j].bits_per_pixel == 32)) + { + can_translate_to_bpp = True; + } + break; + } + } + + /* Prefer formats which have the most colour depth. + We're being truly aristocratic here, minding each + weight on its own. */ + if (can_translate_to_bpp) + { + unsigned vis_red_weight = + calculate_mask_weight(visual_info->red_mask); + unsigned vis_green_weight = + calculate_mask_weight(visual_info->green_mask); + unsigned vis_blue_weight = + calculate_mask_weight(visual_info->blue_mask); + if ((vis_red_weight >= red_weight) + && (vis_green_weight >= green_weight) + && (vis_blue_weight >= blue_weight)) + { + red_weight = vis_red_weight; + green_weight = vis_green_weight; + blue_weight = vis_blue_weight; + g_visual = visual_info->visual; + g_depth = visual_info->depth; + } + } } - nvisuals--; - TrueColorVisual = True; + XFree(vmatches); } - test = 1; - g_host_be = !(BOOL) (*(uint8 *) (&test)); - g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); - - if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8))) + if (g_visual != NULL) { - /* 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; - } + g_owncolmap = False; + calculate_shifts(g_visual->red_mask, &g_red_shift_r, &g_red_shift_l); + calculate_shifts(g_visual->green_mask, &g_green_shift_r, &g_green_shift_l); + calculate_shifts(g_visual->blue_mask, &g_blue_shift_r, &g_blue_shift_l); } else { - /* need a truecolour visual */ - if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi)) - { - error("The display does not support true colour - high colour support unavailable.\n"); + template.class = PseudoColor; + template.depth = 8; + template.colormap_size = 256; + vmatches = + XGetVisualInfo(g_display, + VisualClassMask | VisualDepthMask | VisualColormapSizeMask, + &template, &visuals_count); + if (vmatches == NULL) + { + error("No usable TrueColor or PseudoColor visuals on this display.\n"); + XCloseDisplay(g_display); + XFree(pfm); return False; } - g_visual = vi.visual; - g_owncolmap = False; - calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l); - calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l); - calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l); + /* we use a colourmap, so the default visual should do */ + g_owncolmap = True; + g_visual = vmatches[0].visual; + g_depth = vmatches[0].depth; + } - /* if RGB video and everything is little endian */ - if ((vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) && - !g_xserver_be && !g_host_be) + g_bpp = 0; + for (i = 0; i < pixmap_formats_count; ++i) + { + XPixmapFormatValues *pf = &pfm[i]; + if (pf->depth == g_depth) { - if (g_depth <= 16 || (g_red_shift_l == 16 && g_green_shift_l == 8 && - g_blue_shift_l == 0)) + g_bpp = pf->bits_per_pixel; + + if (g_no_translate_image) { - g_arch_match = True; + switch (g_server_depth) + { + case 15: + case 16: + if (g_bpp != 16) + g_no_translate_image = False; + break; + case 24: + /* Yes, this will force image translation + on most modern servers which use 32 bits + for R8G8B8. */ + if (g_bpp != 24) + g_no_translate_image = False; + break; + default: + g_no_translate_image = False; + break; + } } - } - if (g_arch_match) - { - DEBUG(("Architectures match, enabling little endian optimisations.\n")); + /* Pixmap formats list is a depth-to-bpp mapping -- + there's just a single entry for every depth, + so we can safely break here */ + break; } } + XFree(pfm); + pfm = NULL; + return True; +} + +BOOL +ui_init(void) +{ + int screen_num; - pfm = XListPixmapFormats(g_display, &i); - if (pfm != NULL) + g_display = XOpenDisplay(NULL); + if (g_display == NULL) { - /* Use maximum bpp for this depth - this is generally - desirable, e.g. 24 bits->32 bits. */ - while (i--) - { - if ((pfm[i].depth == g_depth) && (pfm[i].bits_per_pixel > g_bpp)) - { - g_bpp = pfm[i].bits_per_pixel; - } - } - XFree(pfm); + error("Failed to open display: %s\n", XDisplayName(NULL)); + return False; } - if (g_bpp < 8) { - error("Less than 8 bpp not currently supported.\n"); - XCloseDisplay(g_display); + uint16 endianess_test = 1; + g_host_be = !(BOOL) (*(uint8 *) (&endianess_test)); + } + + g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); + screen_num = DefaultScreen(g_display); + g_x_socket = ConnectionNumber(g_display); + g_screen = ScreenOfDisplay(g_display, screen_num); + g_depth = DefaultDepthOfScreen(g_screen); + + if (!select_visual()) return False; + + if (g_no_translate_image) + { + DEBUG(("Performance optimization possible: avoiding image translation (colour depth conversion).\n")); + } + + if (g_server_depth > g_bpp) + { + warning("Remote desktop colour depth %d higher than display colour depth %d.\n", + g_server_depth, g_bpp); } + DEBUG(("RDP depth: %d, display depth: %d, display bpp: %d, X server BE: %d, host BE: %d\n", + g_server_depth, g_depth, g_bpp, g_xserver_be, g_host_be)); + if (!g_owncolmap) { 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"); + warning("Display colour depth is %d bit: you may want to use -C for a private colourmap.\n", g_depth); } if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) { - warning("External BackingStore not available, using internal\n"); + warning("External BackingStore not available. Using internal.\n"); g_ownbackstore = True; } @@ -1090,6 +1249,8 @@ else if (g_width < 0) { /* Percent of screen */ + if (-g_width >= 100) + g_using_full_workarea = True; g_height = HeightOfScreen(g_screen) * (-g_width) / 100; g_width = WidthOfScreen(g_screen) * (-g_width) / 100; } @@ -1097,6 +1258,7 @@ { /* Fetch geometry from _NET_WORKAREA */ uint32 x, y, cx, cy; + g_using_full_workarea = True; if (get_current_workarea(&x, &y, &cx, &cy) == 0) { @@ -1123,7 +1285,7 @@ xclip_init(); - DEBUG_RDP5(("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_depth, g_bpp, g_depth)); return True; } @@ -1163,6 +1325,12 @@ wndwidth = g_fullscreen ? WidthOfScreen(g_screen) : g_width; wndheight = g_fullscreen ? HeightOfScreen(g_screen) : g_height; + /* Handle -x-y portion of geometry string */ + if (g_xpos < 0 || (g_xpos == 0 && (g_pos & 2))) + g_xpos = WidthOfScreen(g_screen) + g_xpos - g_width; + if (g_ypos < 0 || (g_ypos == 0 && (g_pos & 4))) + g_ypos = HeightOfScreen(g_screen) + g_ypos - g_height; + attribs.background_pixel = BlackPixelOfScreen(g_screen); attribs.border_pixel = WhitePixelOfScreen(g_screen); attribs.backing_store = g_ownbackstore ? NotUseful : Always; @@ -1206,6 +1374,8 @@ if (sizehints) { sizehints->flags = PMinSize | PMaxSize; + if (g_pos) + sizehints->flags |= PPosition; sizehints->min_width = sizehints->max_width = g_width; sizehints->min_height = sizehints->max_height = g_height; XSetWMNormalHints(g_display, g_wnd, sizehints); @@ -1218,7 +1388,7 @@ } input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | - VisibilityChangeMask | FocusChangeMask; + VisibilityChangeMask | FocusChangeMask | StructureNotifyMask; if (g_sendmotion) input_mask |= PointerMotionMask; @@ -1332,20 +1502,91 @@ } } -/* Process all events in Xlib queue +static void +handle_button_event(XEvent xevent, BOOL down) +{ + uint16 button, flags = 0; + g_last_gesturetime = xevent.xbutton.time; + button = xkeymap_translate_button(xevent.xbutton.button); + if (button == 0) + return; + + if (down) + flags = MOUSE_FLAG_DOWN; + + /* Stop moving window when button is released, regardless of cursor position */ + if (g_moving_wnd && (xevent.type == ButtonRelease)) + g_moving_wnd = False; + + /* If win_button_size is nonzero, enable single app mode */ + if (xevent.xbutton.y < g_win_button_size) + { + /* Check from right to left: */ + if (xevent.xbutton.x >= g_width - g_win_button_size) + { + /* The close button, continue */ + ; + } + else if (xevent.xbutton.x >= g_width - g_win_button_size * 2) + { + /* The maximize/restore button. Do not send to + server. It might be a good idea to change the + cursor or give some other visible indication + that rdesktop inhibited this click */ + if (xevent.type == ButtonPress) + return; + } + else if (xevent.xbutton.x >= g_width - g_win_button_size * 3) + { + /* The minimize button. Iconify window. */ + if (xevent.type == ButtonRelease) + { + /* Release the mouse button outside the minimize button, to prevent the + actual minimazation to happen */ + rdp_send_input(time(NULL), RDP_INPUT_MOUSE, button, 1, 1); + XIconifyWindow(g_display, g_wnd, DefaultScreen(g_display)); + return; + } + } + else if (xevent.xbutton.x <= g_win_button_size) + { + /* The system menu. Ignore. */ + if (xevent.type == ButtonPress) + return; + } + else + { + /* The title bar. */ + if (xevent.type == ButtonPress) + { + if (!g_fullscreen && g_hide_decorations && !g_using_full_workarea) + { + g_moving_wnd = True; + g_move_x_offset = xevent.xbutton.x; + g_move_y_offset = xevent.xbutton.y; + } + return; + } + } + } + + rdp_send_input(time(NULL), RDP_INPUT_MOUSE, + flags | button, xevent.xbutton.x, xevent.xbutton.y); +} + +/* Process events in Xlib queue Returns 0 after user quit, 1 otherwise */ static int xwin_process_events(void) { XEvent xevent; KeySym keysym; - uint16 button, flags; uint32 ev_time; - key_translation tr; char str[256]; Status status; + int events = 0; - while (XPending(g_display) > 0) + while ((XPending(g_display) > 0) && events++ < 20) { XNextEvent(g_display, &xevent); @@ -1355,8 +1596,6 @@ continue; } - flags = 0; - switch (xevent.type) { case VisibilityNotify: @@ -1393,24 +1632,15 @@ str, sizeof(str), &keysym, NULL); } - DEBUG_KBD(("KeyPress for (keysym 0x%lx, %s)\n", keysym, + DEBUG_KBD(("KeyPress for keysym (0x%lx, %s)\n", keysym, get_ksname(keysym))); ev_time = time(NULL); if (handle_special_keys(keysym, xevent.xkey.state, ev_time, True)) break; - tr = xkeymap_translate_key(keysym, - xevent.xkey.keycode, xevent.xkey.state); - - if (tr.scancode == 0) - break; - - 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, tr.scancode); - + xkeymap_send_keys(keysym, xevent.xkey.keycode, xevent.xkey.state, + ev_time, True, 0); break; case KeyRelease: @@ -1418,85 +1648,23 @@ XLookupString((XKeyEvent *) & xevent, str, sizeof(str), &keysym, NULL); - DEBUG_KBD(("\nKeyRelease for (keysym 0x%lx, %s)\n", keysym, + DEBUG_KBD(("\nKeyRelease for keysym (0x%lx, %s)\n", keysym, get_ksname(keysym))); ev_time = time(NULL); if (handle_special_keys(keysym, xevent.xkey.state, ev_time, False)) break; - tr = xkeymap_translate_key(keysym, - xevent.xkey.keycode, xevent.xkey.state); - - if (tr.scancode == 0) - break; - - rdp_send_scancode(ev_time, RDP_KEYRELEASE, tr.scancode); + xkeymap_send_keys(keysym, xevent.xkey.keycode, xevent.xkey.state, + ev_time, False, 0); break; case ButtonPress: - flags = MOUSE_FLAG_DOWN; - /* fall through */ + handle_button_event(xevent, True); + break; case ButtonRelease: - g_last_gesturetime = xevent.xbutton.time; - button = xkeymap_translate_button(xevent.xbutton.button); - if (button == 0) - break; - - /* If win_button_size is nonzero, enable single app mode */ - if (xevent.xbutton.y < g_win_button_size) - { - /* Stop moving window when button is released, regardless of cursor position */ - if (g_moving_wnd && (xevent.type == ButtonRelease)) - g_moving_wnd = False; - - /* Check from right to left: */ - - if (xevent.xbutton.x >= g_width - g_win_button_size) - { - /* The close button, continue */ - ; - } - else if (xevent.xbutton.x >= - g_width - g_win_button_size * 2) - { - /* The maximize/restore button. Do not send to - server. It might be a good idea to change the - cursor or give some other visible indication - that rdesktop inhibited this click */ - break; - } - else if (xevent.xbutton.x >= - g_width - g_win_button_size * 3) - { - /* The minimize button. Iconify window. */ - XIconifyWindow(g_display, g_wnd, - DefaultScreen(g_display)); - break; - } - else if (xevent.xbutton.x <= g_win_button_size) - { - /* The system menu. Ignore. */ - break; - } - else - { - /* The title bar. */ - if ((xevent.type == ButtonPress) && !g_fullscreen - && g_hide_decorations) - { - g_moving_wnd = True; - g_move_x_offset = xevent.xbutton.x; - g_move_y_offset = xevent.xbutton.y; - } - break; - - } - } - - rdp_send_input(time(NULL), RDP_INPUT_MOUSE, - flags | button, xevent.xbutton.x, xevent.xbutton.y); + handle_button_event(xevent, False); break; case MotionNotify: @@ -1589,6 +1757,12 @@ case PropertyNotify: xclip_handle_PropertyNotify(&xevent.xproperty); break; + case MapNotify: + rdp_send_client_window_status(1); + break; + case UnmapNotify: + rdp_send_client_window_status(0); + break; } } /* Keep going */ @@ -1672,7 +1846,7 @@ uint8 *tdata; int bitmap_pad; - if (g_server_bpp == 8) + if (g_server_depth == 8) { bitmap_pad = 8; } @@ -1704,7 +1878,7 @@ uint8 *tdata; int bitmap_pad; - if (g_server_bpp == 8) + if (g_server_depth == 8) { bitmap_pad = 8; } @@ -2429,25 +2603,40 @@ switch (text[i]) { case 0xff: - if (i + 2 < length) - cache_put_text(text[i + 1], text, text[i + 2]); - else + /* At least two bytes needs to follow */ + if (i + 3 > length) { - error("this shouldn't be happening\n"); - exit(1); + warning("Skipping short 0xff command:"); + for (j = 0; j < length; j++) + fprintf(stderr, "%02x ", text[j]); + fprintf(stderr, "\n"); + i = length = 0; + break; } + cache_put_text(text[i + 1], text, text[i + 2]); + i += 3; + length -= i; /* this will move pointer from start to first character after FF command */ - length -= i + 3; - text = &(text[i + 3]); + text = &(text[i]); i = 0; break; case 0xfe: + /* At least one byte needs to follow */ + if (i + 2 > length) + { + warning("Skipping short 0xfe command:"); + for (j = 0; j < length; j++) + fprintf(stderr, "%02x ", text[j]); + fprintf(stderr, "\n"); + i = length = 0; + break; + } entry = cache_get_text(text[i + 1]); - if (entry != NULL) + if (entry->data != NULL) { - if ((((uint8 *) (entry->data))[1] == - 0) && (!(flags & TEXT2_IMPLICIT_X))) + if ((((uint8 *) (entry->data))[1] == 0) + && (!(flags & TEXT2_IMPLICIT_X)) && (i + 2 < length)) { if (flags & TEXT2_VERTICAL) y += text[i + 2];