static BOOL xf_cliprdr_is_self_owned(xfClipboard* clipboard)
{
xfContext* xfc = clipboard->xfc;
-
- return XGetSelectionOwner(xfc->display, clipboard->clipboard_atom) == xfc->drawable;
+ return XGetSelectionOwner(xfc->display,
+ clipboard->clipboard_atom) == xfc->drawable;
}
-static void xf_cliprdr_set_raw_transfer_enabled(xfClipboard* clipboard, BOOL enabled)
+static void xf_cliprdr_set_raw_transfer_enabled(xfClipboard* clipboard,
+ BOOL enabled)
{
UINT32 data = enabled;
xfContext* xfc = clipboard->xfc;
-
XChangeProperty(xfc->display, xfc->drawable, clipboard->raw_transfer_atom,
- XA_INTEGER, 32, PropModeReplace, (BYTE*) &data, 1);
+ XA_INTEGER, 32, PropModeReplace, (BYTE*) &data, 1);
}
static BOOL xf_cliprdr_is_raw_transfer_available(xfClipboard* clipboard)
UINT32 is_enabled = 0;
Window owner = None;
xfContext* xfc = clipboard->xfc;
-
owner = XGetSelectionOwner(xfc->display, clipboard->clipboard_atom);
if (owner != None)
{
result = XGetWindowProperty(xfc->display, owner,
- clipboard->raw_transfer_atom, 0, 4, 0, XA_INTEGER,
- &type, &format, &length, &bytes_left, (BYTE**) &data);
+ clipboard->raw_transfer_atom, 0, 4, 0, XA_INTEGER,
+ &type, &format, &length, &bytes_left, (BYTE**) &data);
}
if (data)
return is_enabled ? TRUE : FALSE;
}
-static BOOL xf_cliprdr_formats_equal(const CLIPRDR_FORMAT* server, const xfCliprdrFormat* client)
+static BOOL xf_cliprdr_formats_equal(const CLIPRDR_FORMAT* server,
+ const xfCliprdrFormat* client)
{
if (server->formatName && client->formatName)
{
/* The server may be using short format names while we store them in full form. */
- return (0 == strncmp(server->formatName, client->formatName, strlen(server->formatName)));
+ return (0 == strncmp(server->formatName, client->formatName,
+ strlen(server->formatName)));
}
if (!server->formatName && !client->formatName)
return FALSE;
}
-static xfCliprdrFormat* xf_cliprdr_get_client_format_by_id(xfClipboard* clipboard, UINT32 formatId)
+static xfCliprdrFormat* xf_cliprdr_get_client_format_by_id(
+ xfClipboard* clipboard, UINT32 formatId)
{
int index;
xfCliprdrFormat* format;
return NULL;
}
-static xfCliprdrFormat* xf_cliprdr_get_client_format_by_atom(xfClipboard* clipboard, Atom atom)
+static xfCliprdrFormat* xf_cliprdr_get_client_format_by_atom(
+ xfClipboard* clipboard, Atom atom)
{
int i;
xfCliprdrFormat* format;
return NULL;
}
-static CLIPRDR_FORMAT* xf_cliprdr_get_server_format_by_atom(xfClipboard* clipboard, Atom atom)
+static CLIPRDR_FORMAT* xf_cliprdr_get_server_format_by_atom(
+ xfClipboard* clipboard, Atom atom)
{
int i, j;
xfCliprdrFormat* client_format;
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT xf_cliprdr_send_data_request(xfClipboard* clipboard, UINT32 formatId)
+static UINT xf_cliprdr_send_data_request(xfClipboard* clipboard,
+ UINT32 formatId)
{
CLIPRDR_FORMAT_DATA_REQUEST request;
-
ZeroMemory(&request, sizeof(CLIPRDR_FORMAT_DATA_REQUEST));
-
request.requestedFormatId = formatId;
-
- return clipboard->context->ClientFormatDataRequest(clipboard->context, &request);
+ return clipboard->context->ClientFormatDataRequest(clipboard->context,
+ &request);
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT xf_cliprdr_send_data_response(xfClipboard* clipboard, BYTE* data, int size)
+static UINT xf_cliprdr_send_data_response(xfClipboard* clipboard, BYTE* data,
+ int size)
{
CLIPRDR_FORMAT_DATA_RESPONSE response;
-
ZeroMemory(&response, sizeof(CLIPRDR_FORMAT_DATA_RESPONSE));
-
response.msgFlags = (data) ? CB_RESPONSE_OK : CB_RESPONSE_FAIL;
response.dataLen = size;
response.requestedFormatData = data;
-
- return clipboard->context->ClientFormatDataResponse(clipboard->context, &response);
+ return clipboard->context->ClientFormatDataResponse(clipboard->context,
+ &response);
}
static wStream* xf_cliprdr_serialize_server_format_list(xfClipboard* clipboard)
}
/* If present, the last format is always synthetic CF_RAW. Do not include it. */
- formatCount = (clipboard->numServerFormats > 0) ? clipboard->numServerFormats - 1 : 0;
-
+ formatCount = (clipboard->numServerFormats > 0) ? clipboard->numServerFormats -
+ 1 : 0;
Stream_Write_UINT32(s, formatCount);
for (i = 0; i < formatCount; i++)
}
Stream_SealLength(s);
-
return s;
-
error:
Stream_Free(s, TRUE);
return NULL;
}
-static CLIPRDR_FORMAT* xf_cliprdr_parse_server_format_list(BYTE* data, size_t length, UINT32* numFormats)
+static CLIPRDR_FORMAT* xf_cliprdr_parse_server_format_list(BYTE* data,
+ size_t length, UINT32* numFormats)
{
UINT32 i;
wStream* s = NULL;
}
Stream_Read_UINT32(s, formats[i].formatId);
-
formatName = (const char*) Stream_Pointer(s);
formatNameLength = strnlen(formatName, Stream_GetRemainingLength(s));
if (formatNameLength == Stream_GetRemainingLength(s))
{
- WLog_ERR(TAG, "missing terminating null byte, %zu bytes left to read", formatNameLength);
+ WLog_ERR(TAG, "missing terminating null byte, %zu bytes left to read",
+ formatNameLength);
goto error;
}
}
Stream_Free(s, FALSE);
-
return formats;
-
error:
Stream_Free(s, FALSE);
free(formats);
free(formats);
}
-static CLIPRDR_FORMAT* xf_cliprdr_get_raw_server_formats(xfClipboard* clipboard, UINT32* numFormats)
+static CLIPRDR_FORMAT* xf_cliprdr_get_raw_server_formats(xfClipboard* clipboard,
+ UINT32* numFormats)
{
Atom type = None;
int format = 0;
BYTE* data = NULL;
CLIPRDR_FORMAT* formats = NULL;
xfContext* xfc = clipboard->xfc;
-
*numFormats = 0;
+ XGetWindowProperty(xfc->display, clipboard->owner,
+ clipboard->raw_format_list_atom,
+ 0, 4096, False, clipboard->raw_format_list_atom, &type, &format,
+ &length, &remaining, &data);
- XGetWindowProperty(xfc->display, clipboard->owner, clipboard->raw_format_list_atom,
- 0, 4096, False, clipboard->raw_format_list_atom, &type, &format,
- &length, &remaining, &data);
-
- if (data && length > 0 && format == 8 && type == clipboard->raw_format_list_atom)
+ if (data && length > 0 && format == 8
+ && type == clipboard->raw_format_list_atom)
{
formats = xf_cliprdr_parse_server_format_list(data, length, numFormats);
}
else
{
- WLog_ERR(TAG, "failed to retrieve raw format list: data=%p, length=%lu, format=%d, type=%d (expected=%d)",
- data, length, format, type, clipboard->raw_format_list_atom);
+ WLog_ERR(TAG,
+ "failed to retrieve raw format list: data=%p, length=%lu, format=%d, type=%d (expected=%d)",
+ data, length, format, type, clipboard->raw_format_list_atom);
}
if (data)
return formats;
}
-static CLIPRDR_FORMAT* xf_cliprdr_get_formats_from_targets(xfClipboard* clipboard, UINT32* numFormats)
+static CLIPRDR_FORMAT* xf_cliprdr_get_formats_from_targets(
+ xfClipboard* clipboard, UINT32* numFormats)
{
int i;
Atom atom;
xfCliprdrFormat* format = NULL;
CLIPRDR_FORMAT* formats = NULL;
xfContext* xfc = clipboard->xfc;
-
*numFormats = 0;
-
XGetWindowProperty(xfc->display, xfc->drawable, clipboard->property_atom,
- 0, 200, 0, XA_ATOM, &atom, &format_property, &length, &bytes_left, &data);
+ 0, 200, 0, XA_ATOM, &atom, &format_property, &length, &bytes_left, &data);
if (length > 0)
{
WLog_ERR(TAG, "XGetWindowProperty set length = %d but data is NULL", length);
goto out;
}
+
if (!(formats = (CLIPRDR_FORMAT*) calloc(length, sizeof(CLIPRDR_FORMAT))))
{
WLog_ERR(TAG, "failed to allocate %d CLIPRDR_FORMAT structs", length);
for (i = 0; i < length; i++)
{
atom = ((Atom*) data)[i];
-
format = xf_cliprdr_get_client_format_by_atom(clipboard, atom);
if (format)
}
out:
+
if (data)
XFree(data);
return formats;
}
-static CLIPRDR_FORMAT* xf_cliprdr_get_client_formats(xfClipboard* clipboard, UINT32* numFormats)
+static CLIPRDR_FORMAT* xf_cliprdr_get_client_formats(xfClipboard* clipboard,
+ UINT32* numFormats)
{
CLIPRDR_FORMAT* formats = NULL;
-
*numFormats = 0;
if (xf_cliprdr_is_raw_transfer_available(clipboard))
if (*numFormats == 0)
{
xf_cliprdr_free_formats(formats, *numFormats);
-
formats = xf_cliprdr_get_formats_from_targets(clipboard, numFormats);
}
{
wStream* formats = NULL;
xfContext* xfc = clipboard->xfc;
-
formats = xf_cliprdr_serialize_server_format_list(clipboard);
if (formats)
{
XChangeProperty(xfc->display, xfc->drawable, clipboard->raw_format_list_atom,
- clipboard->raw_format_list_atom, 8, PropModeReplace,
- Stream_Buffer(formats), Stream_Length(formats));
+ clipboard->raw_format_list_atom, 8, PropModeReplace,
+ Stream_Buffer(formats), Stream_Length(formats));
}
else
{
UINT32 numFormats = 0;
CLIPRDR_FORMAT* formats = NULL;
CLIPRDR_FORMAT_LIST formatList;
-
formats = xf_cliprdr_get_client_formats(clipboard, &numFormats);
-
ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST));
-
formatList.msgFlags = CB_RESPONSE_OK;
formatList.numFormats = numFormats;
formatList.formats = formats;
-
clipboard->context->ClientFormatList(clipboard->context, &formatList);
-
xf_cliprdr_free_formats(formats, numFormats);
}
-static void xf_cliprdr_process_requested_data(xfClipboard* clipboard, BOOL hasData, BYTE* data, int size)
+static void xf_cliprdr_process_requested_data(xfClipboard* clipboard,
+ BOOL hasData, BYTE* data, int size)
{
BOOL bSuccess;
UINT32 SrcSize;
UINT32 DstSize;
UINT32 srcFormatId;
UINT32 dstFormatId;
- BYTE* pSrcData = NULL;
BYTE* pDstData = NULL;
xfCliprdrFormat* format;
if (clipboard->incr_starts && hasData)
return;
- format = xf_cliprdr_get_client_format_by_id(clipboard, clipboard->requestedFormatId);
+ format = xf_cliprdr_get_client_format_by_id(clipboard,
+ clipboard->requestedFormatId);
if (!hasData || !data || !format)
{
}
srcFormatId = 0;
- dstFormatId = 0;
switch (format->formatId)
{
}
SrcSize = (UINT32) size;
- pSrcData = (BYTE*) malloc(SrcSize);
-
- if (!pSrcData)
- return;
-
- CopyMemory(pSrcData, data, SrcSize);
-
- bSuccess = ClipboardSetData(clipboard->system, srcFormatId, (void*) pSrcData, SrcSize);
-
- if (!bSuccess)
- free(pSrcData);
+ bSuccess = ClipboardSetData(clipboard->system, srcFormatId, data, SrcSize);
if (format->formatName)
- {
dstFormatId = ClipboardGetFormatId(clipboard->system, format->formatName);
- }
else
- {
dstFormatId = format->formatId;
- }
if (bSuccess)
{
unsigned long bytes_left;
xfCliprdrFormat* format;
xfContext* xfc = clipboard->xfc;
-
- format = xf_cliprdr_get_client_format_by_id(clipboard, clipboard->requestedFormatId);
+ format = xf_cliprdr_get_client_format_by_id(clipboard,
+ clipboard->requestedFormatId);
if (!format || (format->atom != target))
{
}
XGetWindowProperty(xfc->display, xfc->drawable,
- clipboard->property_atom, 0, 0, 0, target,
- &type, &format_property, &length, &bytes_left, &data);
+ clipboard->property_atom, 0, 0, 0, target,
+ &type, &format_property, &length, &bytes_left, &data);
if (data)
{
if (bytes_left <= 0 && !clipboard->incr_starts)
{
-
}
else if (type == clipboard->incr_atom)
{
has_data = TRUE;
}
else if (XGetWindowProperty(xfc->display, xfc->drawable,
- clipboard->property_atom, 0, bytes_left, 0, target,
- &type, &format_property, &length, &dummy, &data) == Success)
+ clipboard->property_atom, 0, bytes_left, 0, target,
+ &type, &format_property, &length, &dummy, &data) == Success)
{
if (clipboard->incr_starts)
{
- BYTE *new_data;
-
+ BYTE* new_data;
bytes_left = length * format_property / 8;
- new_data = (BYTE*) realloc(clipboard->incr_data, clipboard->incr_data_length + bytes_left);
+ new_data = (BYTE*) realloc(clipboard->incr_data,
+ clipboard->incr_data_length + bytes_left);
+
if (!new_data)
return FALSE;
+
clipboard->incr_data = new_data;
- CopyMemory(clipboard->incr_data + clipboard->incr_data_length, data, bytes_left);
+ CopyMemory(clipboard->incr_data + clipboard->incr_data_length, data,
+ bytes_left);
clipboard->incr_data_length += bytes_left;
XFree(data);
data = NULL;
}
+
has_data = TRUE;
}
else
{
-
}
}
XDeleteProperty(xfc->display, xfc->drawable, clipboard->property_atom);
-
xf_cliprdr_process_requested_data(clipboard, has_data, data, (int) bytes_left);
if (data)
if (respond->xselection.property != None)
{
XChangeProperty(xfc->display, respond->xselection.requestor,
- respond->xselection.property, XA_ATOM, 32, PropModeReplace,
- (BYTE*) clipboard->targets, clipboard->numTargets);
+ respond->xselection.property, XA_ATOM, 32, PropModeReplace,
+ (BYTE*) clipboard->targets, clipboard->numTargets);
}
}
-static void xf_cliprdr_provide_data(xfClipboard* clipboard, XEvent* respond, BYTE* data, UINT32 size)
+static void xf_cliprdr_provide_data(xfClipboard* clipboard, XEvent* respond,
+ BYTE* data, UINT32 size)
{
xfContext* xfc = clipboard->xfc;
if (respond->xselection.property != None)
{
XChangeProperty(xfc->display, respond->xselection.requestor,
- respond->xselection.property, respond->xselection.target,
- 8, PropModeReplace, data, size);
+ respond->xselection.property, respond->xselection.target,
+ 8, PropModeReplace, data, size);
}
}
-static BOOL xf_cliprdr_process_selection_notify(xfClipboard* clipboard, XEvent* xevent)
+static BOOL xf_cliprdr_process_selection_notify(xfClipboard* clipboard,
+ XEvent* xevent)
{
if (xevent->xselection.target == clipboard->targets[1])
{
}
}
-static BOOL xf_cliprdr_process_selection_request(xfClipboard* clipboard, XEvent* xevent)
+static BOOL xf_cliprdr_process_selection_request(xfClipboard* clipboard,
+ XEvent* xevent)
{
int fmt;
Atom type;
{
/* TODO */
}
- else if (xevent->xselectionrequest.target == clipboard->targets[1]) /* TARGETS */
+ else if (xevent->xselectionrequest.target ==
+ clipboard->targets[1]) /* TARGETS */
{
/* Someone else requests our available formats */
respond->xselection.property = xevent->xselectionrequest.property;
}
else
{
- format = xf_cliprdr_get_server_format_by_atom(clipboard, xevent->xselectionrequest.target);
+ format = xf_cliprdr_get_server_format_by_atom(clipboard,
+ xevent->xselectionrequest.target);
if (format && (xevent->xselectionrequest.requestor != xfc->drawable))
{
if (formatId == CF_RAW)
{
if (XGetWindowProperty(xfc->display, xevent->xselectionrequest.requestor,
- clipboard->property_atom, 0, 4, 0, XA_INTEGER,
- &type, &fmt, &length, &bytes_left, &data) != Success)
+ clipboard->property_atom, 0, 4, 0, XA_INTEGER,
+ &type, &fmt, &length, &bytes_left, &data) != Success)
{
-
}
if (data)
}
}
- if ((clipboard->data != 0) && (formatId == clipboard->data_format_id) && (formatName == clipboard->data_format_name))
+ if ((clipboard->data != 0) && (formatId == clipboard->data_format_id)
+ && (formatName == clipboard->data_format_name))
{
/* Cached clipboard data available. Send it now */
respond->xselection.property = xevent->xselectionrequest.property;
- xf_cliprdr_provide_data(clipboard, respond, clipboard->data, clipboard->data_length);
+ xf_cliprdr_provide_data(clipboard, respond, clipboard->data,
+ clipboard->data_length);
}
else if (clipboard->respond)
{
clipboard->data_format_name = formatName;
clipboard->data_raw_format = rawTransfer;
delayRespond = TRUE;
-
xf_cliprdr_send_data_request(clipboard, formatId);
}
}
return TRUE;
}
-static BOOL xf_cliprdr_process_selection_clear(xfClipboard* clipboard, XEvent* xevent)
+static BOOL xf_cliprdr_process_selection_clear(xfClipboard* clipboard,
+ XEvent* xevent)
{
xfContext* xfc = clipboard->xfc;
return FALSE;
XDeleteProperty(xfc->display, clipboard->root_window, clipboard->property_atom);
-
return TRUE;
}
-static BOOL xf_cliprdr_process_property_notify(xfClipboard* clipboard, XEvent* xevent)
+static BOOL xf_cliprdr_process_property_notify(xfClipboard* clipboard,
+ XEvent* xevent)
{
xfCliprdrFormat* format;
xfContext* xfc = clipboard->xfc;
xf_cliprdr_send_client_format_list(clipboard);
}
else if ((xevent->xproperty.window == xfc->drawable) &&
- (xevent->xproperty.state == PropertyNewValue) && clipboard->incr_starts)
+ (xevent->xproperty.state == PropertyNewValue) && clipboard->incr_starts)
{
- format = xf_cliprdr_get_client_format_by_id(clipboard, clipboard->requestedFormatId);
+ format = xf_cliprdr_get_client_format_by_id(clipboard,
+ clipboard->requestedFormatId);
if (format)
xf_cliprdr_get_requested_data(clipboard, format->atom);
return;
#ifdef WITH_XFIXES
- if (clipboard->xfixes_supported && event->type == XFixesSelectionNotify + clipboard->xfixes_event_base)
+
+ if (clipboard->xfixes_supported
+ && event->type == XFixesSelectionNotify + clipboard->xfixes_event_base)
{
XFixesSelectionNotifyEvent* se = (XFixesSelectionNotifyEvent*) event;
return;
}
+
#endif
switch (event->type)
{
xf_cliprdr_check_owner(clipboard);
}
+
break;
}
}
{
CLIPRDR_CAPABILITIES capabilities;
CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
-
capabilities.cCapabilitiesSets = 1;
- capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*) &(generalCapabilitySet);
-
+ capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*) &
+ (generalCapabilitySet);
generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
generalCapabilitySet.capabilitySetLength = 12;
-
generalCapabilitySet.version = CB_CAPS_VERSION_2;
generalCapabilitySet.generalFlags = CB_USE_LONG_FORMAT_NAMES;
-
- return clipboard->context->ClientCapabilities(clipboard->context, &capabilities);
+ return clipboard->context->ClientCapabilities(clipboard->context,
+ &capabilities);
}
/**
CLIPRDR_FORMAT_LIST formatList;
xfContext* xfc = clipboard->xfc;
UINT ret;
-
ZeroMemory(&formatList, sizeof(CLIPRDR_FORMAT_LIST));
-
numFormats = clipboard->numClientFormats;
+
if (numFormats)
{
if (!(formats = (CLIPRDR_FORMAT*) calloc(numFormats, sizeof(CLIPRDR_FORMAT))))
formatList.msgFlags = CB_RESPONSE_OK;
formatList.numFormats = numFormats;
formatList.formats = formats;
-
ret = clipboard->context->ClientFormatList(clipboard->context, &formatList);
-
free(formats);
if (clipboard->owner && clipboard->owner != xfc->drawable)
{
/* Request the owner for TARGETS, and wait for SelectionNotify event */
XConvertSelection(xfc->display, clipboard->clipboard_atom,
- clipboard->targets[1], clipboard->property_atom, xfc->drawable, CurrentTime);
+ clipboard->targets[1], clipboard->property_atom, xfc->drawable, CurrentTime);
}
return ret;
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT xf_cliprdr_send_client_format_list_response(xfClipboard* clipboard, BOOL status)
+UINT xf_cliprdr_send_client_format_list_response(xfClipboard* clipboard,
+ BOOL status)
{
CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse;
-
formatListResponse.msgType = CB_FORMAT_LIST_RESPONSE;
formatListResponse.msgFlags = status ? CB_RESPONSE_OK : CB_RESPONSE_FAIL;
formatListResponse.dataLen = 0;
-
- return clipboard->context->ClientFormatListResponse(clipboard->context, &formatListResponse);
+ return clipboard->context->ClientFormatListResponse(clipboard->context,
+ &formatListResponse);
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT xf_cliprdr_monitor_ready(CliprdrClientContext* context, CLIPRDR_MONITOR_READY* monitorReady)
+static UINT xf_cliprdr_monitor_ready(CliprdrClientContext* context,
+ CLIPRDR_MONITOR_READY* monitorReady)
{
xfClipboard* clipboard = (xfClipboard*) context->custom;
UINT ret;
if ((ret = xf_cliprdr_send_client_capabilities(clipboard)) != CHANNEL_RC_OK)
return ret;
+
if ((ret = xf_cliprdr_send_client_format_list(clipboard)) != CHANNEL_RC_OK)
return ret;
clipboard->sync = TRUE;
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT xf_cliprdr_server_capabilities(CliprdrClientContext* context, CLIPRDR_CAPABILITIES* capabilities)
+static UINT xf_cliprdr_server_capabilities(CliprdrClientContext* context,
+ CLIPRDR_CAPABILITIES* capabilities)
{
//xfClipboard* clipboard = (xfClipboard*) context->custom;
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT xf_cliprdr_server_format_list(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST* formatList)
+static UINT xf_cliprdr_server_format_list(CliprdrClientContext* context,
+ CLIPRDR_FORMAT_LIST* formatList)
{
int i, j;
CLIPRDR_FORMAT* format;
free(clipboard->serverFormats);
clipboard->serverFormats = NULL;
-
clipboard->numServerFormats = 0;
}
clipboard->numServerFormats = formatList->numFormats + 1; /* +1 for CF_RAW */
- if (!(clipboard->serverFormats = (CLIPRDR_FORMAT*) calloc(clipboard->numServerFormats, sizeof(CLIPRDR_FORMAT)))) {
- WLog_ERR(TAG, "failed to allocate %d CLIPRDR_FORMAT structs", clipboard->numServerFormats);
+ if (!(clipboard->serverFormats = (CLIPRDR_FORMAT*) calloc(
+ clipboard->numServerFormats, sizeof(CLIPRDR_FORMAT))))
+ {
+ WLog_ERR(TAG, "failed to allocate %d CLIPRDR_FORMAT structs",
+ clipboard->numServerFormats);
return CHANNEL_RC_NO_MEMORY;
}
{
format = &formatList->formats[i];
clipboard->serverFormats[i].formatId = format->formatId;
+
if (format->formatName)
{
clipboard->serverFormats[i].formatName = _strdup(format->formatName);
+
if (!clipboard->serverFormats[i].formatName)
{
for (--i; i >= 0; --i)
format = &clipboard->serverFormats[formatList->numFormats];
format->formatId = CF_RAW;
format->formatName = NULL;
-
xf_cliprdr_provide_server_format_list(clipboard);
-
clipboard->numTargets = 2;
for (i = 0; i < formatList->numFormats; i++)
}
ret = xf_cliprdr_send_client_format_list_response(clipboard, TRUE);
-
- XSetSelectionOwner(xfc->display, clipboard->clipboard_atom, xfc->drawable, CurrentTime);
-
+ XSetSelectionOwner(xfc->display, clipboard->clipboard_atom, xfc->drawable,
+ CurrentTime);
XFlush(xfc->display);
-
return ret;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT xf_cliprdr_server_format_list_response(CliprdrClientContext* context, CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
+static UINT xf_cliprdr_server_format_list_response(CliprdrClientContext*
+ context, CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
{
//xfClipboard* clipboard = (xfClipboard*) context->custom;
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT xf_cliprdr_server_format_data_request(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
+static UINT xf_cliprdr_server_format_data_request(CliprdrClientContext* context,
+ CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
{
BOOL rawTransfer;
xfCliprdrFormat* format = NULL;
UINT32 formatId = formatDataRequest->requestedFormatId;
xfClipboard* clipboard = (xfClipboard*) context->custom;
xfContext* xfc = clipboard->xfc;
-
rawTransfer = xf_cliprdr_is_raw_transfer_available(clipboard);
if (rawTransfer)
{
format = xf_cliprdr_get_client_format_by_id(clipboard, CF_RAW);
-
XChangeProperty(xfc->display, xfc->drawable, clipboard->property_atom,
- XA_INTEGER, 32, PropModeReplace, (BYTE*) &formatId, 1);
+ XA_INTEGER, 32, PropModeReplace, (BYTE*) &formatId, 1);
}
else
format = xf_cliprdr_get_client_format_by_id(clipboard, formatId);
return xf_cliprdr_send_data_response(clipboard, NULL, 0);
clipboard->requestedFormatId = rawTransfer ? CF_RAW : formatId;
-
XConvertSelection(xfc->display, clipboard->clipboard_atom,
- format->atom, clipboard->property_atom, xfc->drawable, CurrentTime);
-
+ format->atom, clipboard->property_atom, xfc->drawable, CurrentTime);
XFlush(xfc->display);
-
/* After this point, we expect a SelectionNotify event from the clipboard owner. */
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT xf_cliprdr_server_format_data_response(CliprdrClientContext* context, CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
+static UINT xf_cliprdr_server_format_data_response(CliprdrClientContext*
+ context, CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
{
BOOL bSuccess;
- BYTE* pSrcData;
BYTE* pDstData;
UINT32 DstSize;
UINT32 SrcSize;
pDstData = NULL;
DstSize = 0;
-
srcFormatId = 0;
dstFormatId = 0;
{
switch (clipboard->data_format_id)
{
- case CF_TEXT:
- srcFormatId = CF_TEXT;
- dstFormatId = ClipboardGetFormatId(clipboard->system, "UTF8_STRING");
- nullTerminated = TRUE;
- break;
-
- case CF_OEMTEXT:
- srcFormatId = CF_OEMTEXT;
- dstFormatId = ClipboardGetFormatId(clipboard->system, "UTF8_STRING");
- nullTerminated = TRUE;
- break;
-
- case CF_UNICODETEXT:
- srcFormatId = CF_UNICODETEXT;
- dstFormatId = ClipboardGetFormatId(clipboard->system, "UTF8_STRING");
- nullTerminated = TRUE;
- break;
-
- case CF_DIB:
- srcFormatId = CF_DIB;
- dstFormatId = ClipboardGetFormatId(clipboard->system, "image/bmp");
- break;
+ case CF_TEXT:
+ srcFormatId = CF_TEXT;
+ dstFormatId = ClipboardGetFormatId(clipboard->system, "UTF8_STRING");
+ nullTerminated = TRUE;
+ break;
+
+ case CF_OEMTEXT:
+ srcFormatId = CF_OEMTEXT;
+ dstFormatId = ClipboardGetFormatId(clipboard->system, "UTF8_STRING");
+ nullTerminated = TRUE;
+ break;
+
+ case CF_UNICODETEXT:
+ srcFormatId = CF_UNICODETEXT;
+ dstFormatId = ClipboardGetFormatId(clipboard->system, "UTF8_STRING");
+ nullTerminated = TRUE;
+ break;
+
+ case CF_DIB:
+ srcFormatId = CF_DIB;
+ dstFormatId = ClipboardGetFormatId(clipboard->system, "image/bmp");
+ break;
}
}
SrcSize = (UINT32) size;
- pSrcData = (BYTE*) malloc(SrcSize);
-
- if (!pSrcData)
- return CHANNEL_RC_NO_MEMORY;
-
- CopyMemory(pSrcData, data, SrcSize);
-
- bSuccess = ClipboardSetData(clipboard->system, srcFormatId, (void*) pSrcData, SrcSize);
-
- if (!bSuccess)
- free (pSrcData);
+ bSuccess = ClipboardSetData(clipboard->system, srcFormatId, data, SrcSize);
if (bSuccess)
{
clipboard->data = pDstData;
clipboard->data_length = DstSize;
-
xf_cliprdr_provide_data(clipboard, clipboard->respond, pDstData, DstSize);
-
- XSendEvent(xfc->display, clipboard->respond->xselection.requestor, 0, 0, clipboard->respond);
+ XSendEvent(xfc->display, clipboard->respond->xselection.requestor, 0, 0,
+ clipboard->respond);
XFlush(xfc->display);
-
free(clipboard->respond);
clipboard->respond = NULL;
-
return CHANNEL_RC_OK;
}
}
xfc->clipboard = clipboard;
-
clipboard->xfc = xfc;
-
channels = ((rdpContext*) xfc)->channels;
clipboard->channels = channels;
-
clipboard->system = ClipboardCreate();
-
clipboard->requestedFormatId = -1;
-
clipboard->root_window = DefaultRootWindow(xfc->display);
clipboard->clipboard_atom = XInternAtom(xfc->display, "CLIPBOARD", FALSE);
}
clipboard->property_atom = XInternAtom(xfc->display, "_FREERDP_CLIPRDR", FALSE);
-
- clipboard->raw_transfer_atom = XInternAtom(xfc->display, "_FREERDP_CLIPRDR_RAW", FALSE);
- clipboard->raw_format_list_atom = XInternAtom(xfc->display, "_FREERDP_CLIPRDR_FORMATS", FALSE);
-
+ clipboard->raw_transfer_atom = XInternAtom(xfc->display, "_FREERDP_CLIPRDR_RAW",
+ FALSE);
+ clipboard->raw_format_list_atom = XInternAtom(xfc->display,
+ "_FREERDP_CLIPRDR_FORMATS", FALSE);
xf_cliprdr_set_raw_transfer_enabled(clipboard, TRUE);
-
XSelectInput(xfc->display, clipboard->root_window, PropertyChangeMask);
-
#ifdef WITH_XFIXES
- if (XFixesQueryExtension(xfc->display, &clipboard->xfixes_event_base, &clipboard->xfixes_error_base))
+
+ if (XFixesQueryExtension(xfc->display, &clipboard->xfixes_event_base,
+ &clipboard->xfixes_error_base))
{
int xfmajor, xfminor;
if (XFixesQueryVersion(xfc->display, &xfmajor, &xfminor))
{
XFixesSelectSelectionInput(xfc->display, clipboard->root_window,
- clipboard->clipboard_atom, XFixesSetSelectionOwnerNotifyMask);
+ clipboard->clipboard_atom, XFixesSetSelectionOwnerNotifyMask);
clipboard->xfixes_supported = TRUE;
}
else
{
WLog_ERR(TAG, "Error loading X Fixes extension");
}
+
#else
- WLog_ERR(TAG, "Warning: Using clipboard redirection without XFIXES extension is strongly discouraged!");
+ WLog_ERR(TAG,
+ "Warning: Using clipboard redirection without XFIXES extension is strongly discouraged!");
#endif
-
n = 0;
-
- clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "_FREERDP_RAW", False);
+ clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "_FREERDP_RAW",
+ False);
clipboard->clientFormats[n].formatId = CF_RAW;
n++;
-
- clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "UTF8_STRING", False);
+ clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "UTF8_STRING",
+ False);
clipboard->clientFormats[n].formatId = CF_UNICODETEXT;
n++;
-
clipboard->clientFormats[n].atom = XA_STRING;
clipboard->clientFormats[n].formatId = CF_TEXT;
n++;
-
- clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "image/png", False);
+ clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "image/png",
+ False);
clipboard->clientFormats[n].formatId = CB_FORMAT_PNG;
n++;
-
- clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "image/jpeg", False);
+ clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "image/jpeg",
+ False);
clipboard->clientFormats[n].formatId = CB_FORMAT_JPEG;
n++;
-
- clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "image/gif", False);
+ clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "image/gif",
+ False);
clipboard->clientFormats[n].formatId = CB_FORMAT_GIF;
n++;
-
- clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "image/bmp", False);
+ clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "image/bmp",
+ False);
clipboard->clientFormats[n].formatId = CF_DIB;
n++;
-
- clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "text/html", False);
+ clipboard->clientFormats[n].atom = XInternAtom(xfc->display, "text/html",
+ False);
clipboard->clientFormats[n].formatId = CB_FORMAT_HTML;
clipboard->clientFormats[n].formatName = _strdup("HTML Format");
+
if (!clipboard->clientFormats[n].formatName)
{
ClipboardDestroy(clipboard->system);
free(clipboard);
return NULL;
}
- n++;
+ n++;
clipboard->numClientFormats = n;
-
clipboard->targets[0] = XInternAtom(xfc->display, "TIMESTAMP", FALSE);
clipboard->targets[1] = XInternAtom(xfc->display, "TARGETS", FALSE);
clipboard->numTargets = 2;
-
clipboard->incr_atom = XInternAtom(xfc->display, "INCR", FALSE);
-
return clipboard;
}
}
ClipboardDestroy(clipboard->system);
-
free(clipboard->data);
free(clipboard->respond);
free(clipboard->incr_data);
xfc->cliprdr = cliprdr;
xfc->clipboard->context = cliprdr;
cliprdr->custom = (void*) xfc->clipboard;
-
cliprdr->MonitorReady = xf_cliprdr_monitor_ready;
cliprdr->ServerCapabilities = xf_cliprdr_server_capabilities;
cliprdr->ServerFormatList = xf_cliprdr_server_format_list;