--- sourceforge.net/trunk/rdesktop/xwin.c 2003/09/15 08:03:30 470 +++ sourceforge.net/trunk/rdesktop/xwin.c 2003/10/22 10:55:11 508 @@ -34,15 +34,13 @@ extern char g_title[]; extern int g_server_bpp; extern int g_win_button_size; -BOOL g_enable_compose = False; -BOOL g_focused; -BOOL g_mouse_in_wnd; Display *g_display; Time g_last_gesturetime; static int g_x_socket; static Screen *g_screen; Window g_wnd; +BOOL g_enable_compose = False; static GC g_gc; static Visual *g_visual; static int g_depth; @@ -51,7 +49,10 @@ 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; /* endianness */ static BOOL g_host_be; @@ -66,6 +67,12 @@ static int g_move_x_offset = 0; static int g_move_y_offset = 0; +#ifdef WITH_RDPSND +extern int g_dsp_fd; +extern BOOL g_dsp_busy; +extern BOOL g_rdpsnd; +#endif + /* MWM decorations */ #define MWM_HINTS_DECORATIONS (1L << 1) #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 @@ -201,13 +208,27 @@ static uint32 make_colour24(PixelColour pc) { - return (pc.red << 16) | (pc.green << 8) | pc.blue; + if (g_xserver_be) + { + return pc.red | (pc.green << 8) | (pc.blue << 16); + } + else + { + return (pc.red << 16) | (pc.green << 8) | pc.blue; + } } static uint32 make_colour32(PixelColour pc) { - return (pc.red << 16) | (pc.green << 8) | pc.blue; + if (g_xserver_be) + { + return pc.red | (pc.green << 8) | (pc.blue << 16); + } + else + { + return (pc.red << 16) | (pc.green << 8) | pc.blue; + } } #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } @@ -261,24 +282,6 @@ } break; } - switch (g_bpp) - { - case 16: - if (g_host_be != g_xserver_be) - BSWAP16(colour); - break; - - case 24: - if (g_xserver_be) - BSWAP24(colour); - break; - - case 32: - if (g_host_be != g_xserver_be) - BSWAP32(colour); - break; - } - return colour; } @@ -321,38 +324,124 @@ /* todo the remaining translate function might need some big endian check ?? */ static void -translate15to16(uint16 * data, uint16 * out, uint16 * end) +translate15to16(uint16 * data, uint8 * out, uint8 * end) { + uint16 pixel; + uint16 value; + while (out < end) - *(out++) = (uint16) make_colour16(split_colour15(*(data++))); + { + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel)} + + value = make_colour16(split_colour15(pixel)); + + if (g_xserver_be) + { + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + } + } } static void translate15to24(uint16 * data, uint8 * out, uint8 * end) { uint32 value; + uint16 pixel; while (out < end) { - value = make_colour24(split_colour15(*(data++))); - *(out++) = value; - *(out++) = value >> 8; - *(out++) = value >> 16; + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel)} + + value = make_colour24(split_colour15(pixel)); + if (g_xserver_be) + { + *(out++) = value >> 16; + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + } } } static void -translate15to32(uint16 * data, uint32 * out, uint32 * end) +translate15to32(uint16 * data, uint8 * out, uint8 * end) { + uint16 pixel; + uint32 value; + while (out < end) - *(out++) = make_colour32(split_colour15(*(data++))); + { + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel); + } + + value = make_colour32(split_colour15(pixel)); + + 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; + } + } } static void translate16to16(uint16 * data, uint16 * out, uint16 * end) { - while (out < end) - *(out++) = (uint16) (*(data++)); + uint16 value; + + if (g_xserver_be) + { + while (out < end) + { + value = *data; + BSWAP16(value); + *out = value; + data++; + out++; + } + + } + else + { + while (out < end) + { + *out = *data; + out++; + data++; + } + } } @@ -360,33 +449,89 @@ translate16to24(uint16 * data, uint8 * out, uint8 * end) { uint32 value; + uint16 pixel; while (out < end) { - value = make_colour24(split_colour16(*(data++))); - *(out++) = value; - *(out++) = value >> 8; - *(out++) = value >> 16; + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel)} + + value = make_colour24(split_colour16(pixel)); + + if (g_xserver_be) + { + *(out++) = value >> 16; + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + } } } static void -translate16to32(uint16 * data, uint32 * out, uint32 * end) +translate16to32(uint16 * data, uint8 * out, uint8 * end) { + uint16 pixel; + uint32 value; + while (out < end) - *(out++) = make_colour32(split_colour16(*(data++))); + { + pixel = *(data++); + + if (g_host_be) + { + BSWAP16(pixel)} + + value = make_colour32(split_colour16(pixel)); + + 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; + } + } } static void -translate24to16(uint8 * data, uint16 * out, uint16 * end) +translate24to16(uint8 * data, uint8 * out, uint8 * end) { uint32 pixel = 0; + uint16 value; while (out < end) { pixel = *(data++) << 16; pixel |= *(data++) << 8; pixel |= *(data++); - *(out++) = (uint16) make_colour16(split_colour24(pixel)); + + value = (uint16) make_colour16(split_colour24(pixel)); + + if (g_xserver_be) + { + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + } } } @@ -400,15 +545,24 @@ } static void -translate24to32(uint8 * data, uint32 * out, uint32 * end) +translate24to32(uint8 * data, uint8 * out, uint8 * end) { - uint32 pixel = 0; while (out < end) { - pixel = *(data++); - pixel |= *(data++) << 8; - pixel |= *(data++) << 16; - *(out++) = pixel; + if (g_xserver_be) + { + *(out++) = 0x00; + *(out++) = *(data++); + *(out++) = *(data++); + *(out++) = *(data++); + } + else + { + *(out++) = *(data++); + *(out++) = *(data++); + *(out++) = *(data++); + *(out++) = 0x00; + } } } @@ -425,13 +579,13 @@ switch (g_bpp) { case 32: - translate24to32(data, (uint32 *) out, (uint32 *) end); + translate24to32(data, out, end); break; case 24: translate24to24(data, out, end); break; case 16: - translate24to16(data, (uint16 *) out, (uint16 *) end); + translate24to16(data, out, end); break; } break; @@ -439,8 +593,7 @@ switch (g_bpp) { case 32: - translate16to32((uint16 *) data, (uint32 *) out, - (uint32 *) end); + translate16to32((uint16 *) data, out, end); break; case 24: translate16to24((uint16 *) data, out, end); @@ -455,15 +608,13 @@ switch (g_bpp) { case 32: - translate15to32((uint16 *) data, (uint32 *) out, - (uint32 *) end); + translate15to32((uint16 *) data, out, end); break; case 24: translate15to24((uint16 *) data, out, end); break; case 16: - translate15to16((uint16 *) data, (uint16 *) out, - (uint16 *) end); + translate15to16((uint16 *) data, out, end); break; } break; @@ -570,7 +721,16 @@ g_host_be = !(BOOL) (*(uint8 *) (&test)); g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); - if ((g_width == 0) || (g_height == 0)) + /* + * Determine desktop size + */ + if (g_width < 0) + { + /* Percent of screen */ + g_height = HeightOfScreen(g_screen) * (-g_width) / 100; + g_width = WidthOfScreen(g_screen) * (-g_width) / 100; + } + else if (g_width == 0) { /* Fetch geometry from _NET_WORKAREA */ uint32 x, y, cx, cy; @@ -587,8 +747,7 @@ g_height = 600; } } - - if (g_fullscreen) + else if (g_fullscreen) { g_width = WidthOfScreen(g_screen); g_height = HeightOfScreen(g_screen); @@ -610,10 +769,11 @@ g_mod_map = XGetModifierMapping(g_display); + xkeymap_init(); + if (g_enable_compose) g_IM = XOpenIM(g_display, NULL, NULL, NULL); - xkeymap_init(); xclip_init(); /* todo take this out when high colour is done */ @@ -638,6 +798,9 @@ g_display = NULL; } +#define NULL_POINTER_MASK "\x80" +#define NULL_POINTER_DATA "\x0\x0\x0" + BOOL ui_create_window(void) { @@ -722,12 +885,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); @@ -1029,9 +1197,7 @@ ui_select(int rdp_socket) { int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1; - fd_set rfds; - - FD_ZERO(&rfds); + fd_set rfds, wfds; while (True) { @@ -1041,10 +1207,20 @@ return 0; FD_ZERO(&rfds); + FD_ZERO(&wfds); FD_SET(rdp_socket, &rfds); FD_SET(g_x_socket, &rfds); - switch (select(n, &rfds, NULL, NULL, NULL)) +#ifdef WITH_RDPSND + /* FIXME: there should be an API for registering fds */ + if (g_dsp_busy) + { + FD_SET(g_dsp_fd, &wfds); + n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n; + } +#endif + + switch (select(n, &rfds, &wfds, NULL, NULL)) { case -1: error("select: %s\n", strerror(errno)); @@ -1055,6 +1231,11 @@ if (FD_ISSET(rdp_socket, &rfds)) return 1; + +#ifdef WITH_RDPSND + if (g_dsp_busy && FD_ISSET(g_dsp_fd, &wfds)) + wave_out_play(); +#endif } } @@ -1230,6 +1411,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; \ @@ -1430,8 +1617,8 @@ case 2: /* Hatch */ fill = (Pixmap) ui_create_glyph(8, 8, hatch_patterns + brush->pattern[0] * 8); - SET_FOREGROUND(bgcolour); - SET_BACKGROUND(fgcolour); + SET_FOREGROUND(fgcolour); + SET_BACKGROUND(bgcolour); XSetFillStyle(g_display, g_gc, FillOpaqueStippled); XSetStipple(g_display, g_gc, fill); XSetTSOrigin(g_display, g_gc, brush->xorigin, brush->yorigin);