--- sourceforge.net/trunk/rdesktop/xwin.c 2004/01/19 21:58:58 565 +++ sourceforge.net/trunk/rdesktop/xwin.c 2004/02/16 20:28:09 609 @@ -21,8 +21,10 @@ #include #include #include +#include #include #include +#include #include "rdesktop.h" #include "xproto.h" @@ -42,7 +44,7 @@ static Screen *g_screen; Window g_wnd; BOOL g_enable_compose = False; -static GC g_gc; +static GC g_gc = NULL; static Visual *g_visual; static int g_depth; static int g_bpp; @@ -50,7 +52,7 @@ static XIC g_IC; static XModifierKeymap *g_mod_map; static Cursor g_current_cursor; -static HCURSOR g_null_cursor; +static HCURSOR g_null_cursor = NULL; static Atom g_protocol_atom, g_kill_atom; static BOOL g_focused; static BOOL g_mouse_in_wnd; @@ -62,9 +64,8 @@ static int g_red_shift_l, g_blue_shift_l, g_green_shift_l; /* software backing store */ -static BOOL g_ownbackstore; -static Pixmap g_backstore; -static BOOL g_backstore_initialized = False; +BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ +static Pixmap g_backstore = 0; /* Moving in single app mode */ static BOOL g_moving_wnd; @@ -732,7 +733,7 @@ TrueColorVisual = True; } - if ((g_server_bpp == 8) && ((! TrueColorVisual) || (g_depth <= 8))) + if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8))) { /* we use a colourmap, so the default visual should do */ g_visual = DefaultVisualOfScreen(g_screen); @@ -784,13 +785,18 @@ if (!g_owncolmap) { - g_xcolmap = XCreateColormap(g_display,RootWindowOfScreen(g_screen),g_visual,AllocNone); + 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"); } - if (DoesBackingStore(g_screen) != Always) + if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always)) + { + warning("External BackingStore not available, using internal\n"); g_ownbackstore = True; + } test = 1; g_host_be = !(BOOL) (*(uint8 *) (&test)); @@ -851,6 +857,9 @@ if (g_IM != NULL) XCloseIM(g_IM); + if (g_null_cursor != NULL) + ui_destroy_cursor(g_null_cursor); + XFreeModifiermap(g_mod_map); if (g_ownbackstore) @@ -887,18 +896,16 @@ CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap | CWBorderPixel, &attribs); - g_gc = XCreateGC(g_display, g_wnd, 0, NULL); + if (g_gc == NULL) + g_gc = XCreateGC(g_display, g_wnd, 0, NULL); - if ((g_ownbackstore) && (! g_backstore_initialized)) + if ((g_ownbackstore) && (g_backstore == 0)) { - g_backstore = - XCreatePixmap(g_display, g_wnd, g_width, g_height, - g_depth); + 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); @@ -965,7 +972,8 @@ 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); + if (g_null_cursor == NULL) + g_null_cursor = ui_create_cursor(0, 0, 1, 1, null_pointer_mask, null_pointer_data); return True; } @@ -1268,11 +1276,14 @@ int ui_select(int rdp_socket) { - int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1; + int n; fd_set rfds, wfds; + struct timeval tv; + BOOL s_timeout = False; while (True) { + n = (rdp_socket > g_x_socket) ? rdp_socket : g_x_socket; /* Process any events already waiting */ if (!xwin_process_events()) /* User quit */ @@ -1288,19 +1299,35 @@ if (g_dsp_busy) { FD_SET(g_dsp_fd, &wfds); - n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; + n = (g_dsp_fd > n) ? g_dsp_fd : n; } #endif + /* default timeout */ + tv.tv_sec = 60; + tv.tv_usec = 0; - switch (select(n, &rfds, &wfds, NULL, NULL)) + /* add redirection handles */ + rdpdr_add_fds(&n, &rfds, &wfds, &tv, &s_timeout); + + n++; + + switch (select(n, &rfds, &wfds, NULL, &tv)) { case -1: error("select: %s\n", strerror(errno)); case 0: + /* TODO: if tv.tv_sec just times out + * we will segfault. + * FIXME: + */ + //s_timeout = True; + //rdpdr_check_fds(&rfds, &wfds, (BOOL) True); continue; } + rdpdr_check_fds(&rfds, &wfds, (BOOL) False); + if (FD_ISSET(rdp_socket, &rfds)) return 1; @@ -1756,9 +1783,15 @@ /* src */ int srcx, int srcy) { SET_FUNCTION(opcode); - XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); if (g_ownbackstore) + { + XCopyArea(g_display, g_backstore, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); XCopyArea(g_display, g_backstore, g_backstore, g_gc, srcx, srcy, cx, cy, x, y); + } + else + { + XCopyArea(g_display, g_wnd, g_wnd, g_gc, srcx, srcy, cx, cy, x, y); + } RESET_FUNCTION(opcode); }