--- sourceforge.net/trunk/rdesktop/xclip.c 2006/03/28 13:24:48 1213 +++ sourceforge.net/trunk/rdesktop/xclip.c 2006/05/15 11:38:49 1234 @@ -157,6 +157,7 @@ { uint8 *result; uint16 *inptr, *outptr; + Bool swap_endianess; /* Worst case: Every char is LF */ result = xmalloc((*size * 2) + 2); @@ -167,7 +168,7 @@ outptr = (uint16 *) result; /* Check for a reversed BOM */ - Bool swap_endianess = (*inptr == 0xfffe); + swap_endianess = (*inptr == 0xfffe); while ((uint8 *) inptr < data + *size) { @@ -292,6 +293,16 @@ if (target == format_string_atom || target == format_unicode_atom || target == format_utf8_string_atom) { + size_t unicode_buffer_size; + char *unicode_buffer; + iconv_t cd; + size_t unicode_buffer_size_remaining; + char *unicode_buffer_remaining; + char *data_remaining; + size_t data_size_remaining; + uint32 translated_data_size; + uint8 *translated_data; + if (rdp_clipboard_request_format != RDP_CF_TEXT) return False; @@ -300,10 +311,6 @@ to it, so using CF_TEXT is not safe (and is unnecessary, since all WinNT versions are Unicode-minded). */ - size_t unicode_buffer_size; - char *unicode_buffer; - iconv_t cd; - if (target == format_string_atom) { char *locale_charset = nl_langinfo(CODESET); @@ -342,18 +349,17 @@ } unicode_buffer = xmalloc(unicode_buffer_size); - size_t unicode_buffer_size_remaining = unicode_buffer_size; - char *unicode_buffer_remaining = unicode_buffer; - char *data_remaining = (char *) source; - size_t data_size_remaining = source_size; + unicode_buffer_size_remaining = unicode_buffer_size; + unicode_buffer_remaining = unicode_buffer; + data_remaining = (char *) source; + data_size_remaining = source_size; iconv(cd, (ICONV_CONST char **) &data_remaining, &data_size_remaining, &unicode_buffer_remaining, &unicode_buffer_size_remaining); iconv_close(cd); /* translate linebreaks */ - uint32 translated_data_size = unicode_buffer_size - unicode_buffer_size_remaining; - uint8 *translated_data = - utf16_lf2crlf((uint8 *) unicode_buffer, &translated_data_size); + translated_data_size = unicode_buffer_size - unicode_buffer_size_remaining; + translated_data = utf16_lf2crlf((uint8 *) unicode_buffer, &translated_data_size); if (translated_data != NULL) { DEBUG_CLIPBOARD(("Sending Unicode string of %d bytes\n", @@ -512,19 +518,19 @@ { res = XGetWindowProperty(g_display, g_wnd, rdesktop_primary_timestamp_target_atom, 0, - XMaxRequestSize(g_display), False, XA_INTEGER, + XMaxRequestSize(g_display), False, AnyPropertyType, &type, &format, &nitems, &bytes_left, &data); } else { res = XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_timestamp_target_atom, 0, - XMaxRequestSize(g_display), False, XA_INTEGER, + XMaxRequestSize(g_display), False, AnyPropertyType, &type, &format, &nitems, &bytes_left, &data); } - if ((res != Success) || (nitems != 1)) + if ((res != Success) || (nitems != 1) || (format != 32)) { DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n")); goto fail; @@ -1112,8 +1118,7 @@ { g_rdpclip = True; - if (str_startswith(optarg, "auto") || str_startswith(optarg, "on") - || str_startswith(optarg, "PRIMARYCLIPBOARD")) + if (str_startswith(optarg, "PRIMARYCLIPBOARD")) auto_mode = True; else if (str_startswith(optarg, "CLIPBOARD")) auto_mode = False; @@ -1173,3 +1178,13 @@ targets[num_targets++] = format_string_atom; targets[num_targets++] = XA_STRING; } + +void +xclip_deinit(void) +{ + if (XGetSelectionOwner(g_display, primary_atom) == g_wnd) + XSetSelectionOwner(g_display, primary_atom, None, acquire_time); + if (XGetSelectionOwner(g_display, clipboard_atom) == g_wnd) + XSetSelectionOwner(g_display, clipboard_atom, None, acquire_time); + xclip_notify_change(); +}