2011-09-23 07:37:17 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-09-23 07:37:17 +04:00
|
|
|
* X11 Clipboard Redirection
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xatom.h>
|
2012-08-15 01:20:53 +04:00
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-03-29 05:13:56 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
#include <freerdp/utils/event.h>
|
2012-10-09 04:33:58 +04:00
|
|
|
#include <freerdp/client/cliprdr.h>
|
2013-05-13 05:23:12 +04:00
|
|
|
#include <freerdp/channels/channels.h>
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
#include "xf_cliprdr.h"
|
|
|
|
|
2013-04-02 23:13:10 +04:00
|
|
|
#ifdef WITH_DEBUG_X11
|
|
|
|
#define DEBUG_X11(fmt, ...) DEBUG_CLASS(X11, fmt, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DEBUG_X11(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_DEBUG_X11_CLIPRDR
|
|
|
|
#define DEBUG_X11_CLIPRDR(fmt, ...) DEBUG_CLASS(X11_CLIPRDR, fmt, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DEBUG_X11_CLIPRDR(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
typedef struct clipboard_format_mapping clipboardFormatMapping;
|
2013-02-21 11:56:57 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
struct clipboard_format_mapping
|
|
|
|
{
|
|
|
|
Atom target_format;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 format_id;
|
2011-09-23 07:37:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct clipboard_context clipboardContext;
|
2013-02-21 11:56:57 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
struct clipboard_context
|
|
|
|
{
|
2011-11-01 03:15:27 +04:00
|
|
|
rdpChannels* channels;
|
2011-09-23 07:37:17 +04:00
|
|
|
Window root_window;
|
|
|
|
Atom clipboard_atom;
|
|
|
|
Atom property_atom;
|
|
|
|
Atom identity_atom;
|
|
|
|
|
|
|
|
clipboardFormatMapping format_mappings[20];
|
|
|
|
int num_format_mappings;
|
|
|
|
|
|
|
|
/* server->client data */
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32* formats;
|
2011-09-23 07:37:17 +04:00
|
|
|
int num_formats;
|
|
|
|
Atom targets[20];
|
|
|
|
int num_targets;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* data;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_format;
|
|
|
|
UINT32 data_alt_format;
|
2011-09-23 07:37:17 +04:00
|
|
|
int data_length;
|
|
|
|
XEvent* respond;
|
|
|
|
|
|
|
|
/* client->server data */
|
|
|
|
Window owner;
|
|
|
|
int request_index;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL sync;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
/* INCR mechanism */
|
|
|
|
Atom incr_atom;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL incr_starts;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* incr_data;
|
2011-09-23 07:37:17 +04:00
|
|
|
int incr_data_length;
|
|
|
|
};
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_cliprdr_init(xfContext* xfc, rdpChannels* channels)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
int n;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 id;
|
2011-09-23 07:37:17 +04:00
|
|
|
clipboardContext* cb;
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
cb = (clipboardContext*) malloc(sizeof(clipboardContext));
|
|
|
|
ZeroMemory(cb, sizeof(clipboardContext));
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->clipboard_context = cb;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-05-13 05:23:12 +04:00
|
|
|
cb->channels = channels;
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->request_index = -1;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->root_window = DefaultRootWindow(xfc->display);
|
|
|
|
cb->clipboard_atom = XInternAtom(xfc->display, "CLIPBOARD", FALSE);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (cb->clipboard_atom == None)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("unable to get CLIPBOARD atom");
|
|
|
|
}
|
|
|
|
|
2011-11-01 03:15:27 +04:00
|
|
|
id = 1;
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->property_atom = XInternAtom(xfc->display, "_FREERDP_CLIPRDR", FALSE);
|
|
|
|
cb->identity_atom = XInternAtom(xfc->display, "_FREERDP_CLIPRDR_ID", FALSE);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XChangeProperty(xfc->display, xfc->drawable, cb->identity_atom,
|
2012-10-09 11:01:37 +04:00
|
|
|
XA_INTEGER, 32, PropModeReplace, (BYTE*) &id, 1);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XSelectInput(xfc->display, cb->root_window, PropertyChangeMask);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
n = 0;
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->format_mappings[n].target_format = XInternAtom(xfc->display, "_FREERDP_RAW", FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->format_mappings[n].format_id = CB_FORMAT_RAW;
|
|
|
|
|
|
|
|
n++;
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->format_mappings[n].target_format = XInternAtom(xfc->display, "UTF8_STRING", FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->format_mappings[n].format_id = CB_FORMAT_UNICODETEXT;
|
|
|
|
|
|
|
|
n++;
|
|
|
|
cb->format_mappings[n].target_format = XA_STRING;
|
|
|
|
cb->format_mappings[n].format_id = CB_FORMAT_TEXT;
|
|
|
|
|
|
|
|
n++;
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->format_mappings[n].target_format = XInternAtom(xfc->display, "image/png", FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->format_mappings[n].format_id = CB_FORMAT_PNG;
|
|
|
|
|
|
|
|
n++;
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->format_mappings[n].target_format = XInternAtom(xfc->display, "image/jpeg", FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->format_mappings[n].format_id = CB_FORMAT_JPEG;
|
|
|
|
|
|
|
|
n++;
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->format_mappings[n].target_format = XInternAtom(xfc->display, "image/gif", FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->format_mappings[n].format_id = CB_FORMAT_GIF;
|
|
|
|
|
|
|
|
n++;
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->format_mappings[n].target_format = XInternAtom(xfc->display, "image/bmp", FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->format_mappings[n].format_id = CB_FORMAT_DIB;
|
|
|
|
|
|
|
|
n++;
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->format_mappings[n].target_format = XInternAtom(xfc->display, "text/html", FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->format_mappings[n].format_id = CB_FORMAT_HTML;
|
|
|
|
|
|
|
|
cb->num_format_mappings = n + 1;
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->targets[0] = XInternAtom(xfc->display, "TIMESTAMP", FALSE);
|
|
|
|
cb->targets[1] = XInternAtom(xfc->display, "TARGETS", FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->num_targets = 2;
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->incr_atom = XInternAtom(xfc->display, "INCR", FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_cliprdr_uninit(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
if (cb)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(cb->formats);
|
|
|
|
free(cb->data);
|
|
|
|
free(cb->respond);
|
|
|
|
free(cb->incr_data);
|
|
|
|
free(cb);
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->clipboard_context = NULL;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static BYTE* lf2crlf(BYTE* data, int* size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE c;
|
|
|
|
BYTE* outbuf;
|
|
|
|
BYTE* out;
|
|
|
|
BYTE* in_end;
|
|
|
|
BYTE* in;
|
2011-09-23 07:37:17 +04:00
|
|
|
int out_size;
|
|
|
|
|
|
|
|
out_size = (*size) * 2 + 1;
|
2012-11-20 08:49:08 +04:00
|
|
|
outbuf = (BYTE*) malloc(out_size);
|
|
|
|
ZeroMemory(outbuf, out_size);
|
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
out = outbuf;
|
|
|
|
in = data;
|
|
|
|
in_end = data + (*size);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
while (in < in_end)
|
|
|
|
{
|
|
|
|
c = *in++;
|
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
*out++ = '\r';
|
|
|
|
*out++ = '\n';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*out++ = c;
|
|
|
|
}
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
*out++ = 0;
|
|
|
|
*size = out - outbuf;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
return outbuf;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static void crlf2lf(BYTE* data, int* size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE c;
|
|
|
|
BYTE* out;
|
|
|
|
BYTE* in;
|
|
|
|
BYTE* in_end;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
out = data;
|
|
|
|
in = data;
|
|
|
|
in_end = data + (*size);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
while (in < in_end)
|
|
|
|
{
|
|
|
|
c = *in++;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (c != '\r')
|
|
|
|
*out++ = c;
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
*size = out - data;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static void be2le(BYTE* data, int size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE c;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
while (size >= 2)
|
|
|
|
{
|
|
|
|
c = data[0];
|
|
|
|
data[0] = data[1];
|
|
|
|
data[1] = c;
|
|
|
|
|
|
|
|
data += 2;
|
|
|
|
size -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static BOOL xf_cliprdr_is_self_owned(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
Atom type;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 id = 0;
|
|
|
|
UINT32* pid = NULL;
|
2011-09-23 07:37:17 +04:00
|
|
|
int format, result = 0;
|
2011-11-18 04:51:30 +04:00
|
|
|
unsigned long length, bytes_left;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
cb->owner = XGetSelectionOwner(xfc->display, cb->clipboard_atom);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (cb->owner != None)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
result = XGetWindowProperty(xfc->display, cb->owner,
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->identity_atom, 0, 4, 0, XA_INTEGER,
|
2012-10-09 11:01:37 +04:00
|
|
|
&type, &format, &length, &bytes_left, (BYTE**) &pid);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (pid)
|
|
|
|
{
|
|
|
|
id = *pid;
|
|
|
|
XFree(pid);
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if ((cb->owner == None) || (cb->owner == xfc->drawable))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (result != Success)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return (id ? TRUE : FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static int xf_cliprdr_select_format_by_id(clipboardContext* cb, UINT32 format_id)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < cb->num_format_mappings; i++)
|
|
|
|
{
|
|
|
|
if (cb->format_mappings[i].format_id == format_id)
|
|
|
|
return i;
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xf_cliprdr_select_format_by_atom(clipboardContext* cb, Atom target)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (cb->formats == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < cb->num_format_mappings; i++)
|
|
|
|
{
|
|
|
|
if (cb->format_mappings[i].target_format != target)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (cb->format_mappings[i].format_id == CB_FORMAT_RAW)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
for (j = 0; j < cb->num_formats; j++)
|
|
|
|
{
|
|
|
|
if (cb->format_mappings[i].format_id == cb->formats[j])
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_send_raw_format_list(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
Atom type;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* format_data;
|
2011-09-23 07:37:17 +04:00
|
|
|
int format, result;
|
2011-11-18 04:51:30 +04:00
|
|
|
unsigned long length, bytes_left;
|
2011-09-23 07:37:17 +04:00
|
|
|
RDP_CB_FORMAT_LIST_EVENT* event;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
result = XGetWindowProperty(xfc->display, cb->root_window,
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->property_atom, 0, 3600, 0, XA_STRING,
|
2012-10-09 11:01:37 +04:00
|
|
|
&type, &format, &length, &bytes_left, (BYTE**) &format_data);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (result != Success)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("XGetWindowProperty failed");
|
|
|
|
return;
|
|
|
|
}
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("format=%d len=%d bytes_left=%d", format, (int) length, (int) bytes_left);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class,
|
|
|
|
CliprdrChannel_FormatList, NULL, NULL);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
event->raw_format_data = (BYTE*) malloc(length);
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(event->raw_format_data, format_data, length);
|
2011-11-18 04:51:30 +04:00
|
|
|
event->raw_format_data_size = length;
|
2011-09-23 07:37:17 +04:00
|
|
|
XFree(format_data);
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
freerdp_channels_send_event(cb->channels, (wMessage*) event);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_send_null_format_list(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
RDP_CB_FORMAT_LIST_EVENT* event;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class,
|
|
|
|
CliprdrChannel_FormatList, NULL, NULL);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
event->num_formats = 0;
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
freerdp_channels_send_event(cb->channels, (wMessage*) event);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_send_supported_format_list(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
RDP_CB_FORMAT_LIST_EVENT* event;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class,
|
|
|
|
CliprdrChannel_FormatList, NULL, NULL);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
event->formats = (UINT32*) malloc(sizeof(UINT32) * cb->num_format_mappings);
|
2011-09-23 07:37:17 +04:00
|
|
|
event->num_formats = cb->num_format_mappings;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
for (i = 0; i < cb->num_format_mappings; i++)
|
|
|
|
event->formats[i] = cb->format_mappings[i].format_id;
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
freerdp_channels_send_event(cb->channels, (wMessage*) event);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_send_format_list(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xf_cliprdr_is_self_owned(xfc))
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_raw_format_list(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else if (cb->owner == None)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_null_format_list(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
2013-06-13 02:57:25 +04:00
|
|
|
else if (cb->owner != xfc->drawable)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
/* Request the owner for TARGETS, and wait for SelectionNotify event */
|
2013-06-13 02:57:25 +04:00
|
|
|
XConvertSelection(xfc->display, cb->clipboard_atom,
|
|
|
|
cb->targets[1], cb->property_atom, xfc->drawable, CurrentTime);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_send_data_request(xfContext* xfc, UINT32 format)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
RDP_CB_DATA_REQUEST_EVENT* event;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(CliprdrChannel_Class,
|
|
|
|
CliprdrChannel_DataRequest, NULL, NULL);
|
2011-11-18 04:51:30 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
event->format = format;
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
freerdp_channels_send_event(cb->channels, (wMessage*) event);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_send_data_response(xfContext* xfc, BYTE* data, int size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
RDP_CB_DATA_RESPONSE_EVENT* event;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(CliprdrChannel_Class,
|
|
|
|
CliprdrChannel_DataResponse, NULL, NULL);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
event->data = data;
|
|
|
|
event->size = size;
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
freerdp_channels_send_event(cb->channels, (wMessage*) event);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_send_null_data_response(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_data_response(xfc, NULL, 0);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_process_cb_monitor_ready_event(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_format_list(xfc);
|
2012-10-09 10:31:28 +04:00
|
|
|
cb->sync = TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_process_cb_data_request_event(xfContext* xfc, RDP_CB_DATA_REQUEST_EVENT* event)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
int i;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("format %d", event->format);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xf_cliprdr_is_self_owned(xfc))
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
/* CB_FORMAT_RAW */
|
|
|
|
i = 0;
|
2013-06-13 02:57:25 +04:00
|
|
|
XChangeProperty(xfc->display, xfc->drawable, cb->property_atom,
|
2012-10-09 11:01:37 +04:00
|
|
|
XA_INTEGER, 32, PropModeReplace, (BYTE*) &event->format, 1);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i = xf_cliprdr_select_format_by_id(cb, event->format);
|
|
|
|
}
|
2011-11-18 04:51:30 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (i < 0)
|
|
|
|
{
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("unsupported format requested");
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_null_data_response(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cb->request_index = i;
|
|
|
|
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("target=%d", (int) cb->format_mappings[i].target_format);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XConvertSelection(xfc->display, cb->clipboard_atom,
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->format_mappings[i].target_format, cb->property_atom,
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->drawable, CurrentTime);
|
|
|
|
XFlush(xfc->display);
|
2011-09-23 07:37:17 +04:00
|
|
|
/* After this point, we expect a SelectionNotify event from the clipboard owner. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_get_requested_targets(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
int num;
|
|
|
|
int i, j;
|
|
|
|
Atom atom;
|
|
|
|
int format;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* data = NULL;
|
2011-11-18 04:51:30 +04:00
|
|
|
unsigned long length, bytes_left;
|
2011-09-23 07:37:17 +04:00
|
|
|
RDP_CB_FORMAT_LIST_EVENT* event;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XGetWindowProperty(xfc->display, xfc->drawable, cb->property_atom,
|
2013-03-29 02:29:57 +04:00
|
|
|
0, 200, 0, XA_ATOM, &atom, &format, &length, &bytes_left, &data);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("type=%d format=%d length=%d bytes_left=%d",
|
2011-11-18 04:51:30 +04:00
|
|
|
(int) atom, format, (int) length, (int) bytes_left);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2011-11-18 04:51:30 +04:00
|
|
|
if (length > 0)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-03-29 02:29:57 +04:00
|
|
|
event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class,
|
|
|
|
CliprdrChannel_FormatList, NULL, NULL);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
event->formats = (UINT32*) malloc(sizeof(UINT32) * cb->num_format_mappings);
|
2011-09-23 07:37:17 +04:00
|
|
|
num = 0;
|
2013-03-29 02:29:57 +04:00
|
|
|
|
2011-11-18 04:51:30 +04:00
|
|
|
for (i = 0; i < length; i++)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2011-11-18 04:51:30 +04:00
|
|
|
atom = ((Atom*) data)[i];
|
|
|
|
DEBUG_X11("atom %d", (int) atom);
|
2013-04-02 23:13:10 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
for (j = 0; j < cb->num_format_mappings; j++)
|
|
|
|
{
|
|
|
|
if (cb->format_mappings[j].target_format == atom)
|
|
|
|
{
|
|
|
|
DEBUG_X11("found format %d for atom %d",
|
|
|
|
cb->format_mappings[j].format_id, (int)atom);
|
|
|
|
event->formats[num++] = cb->format_mappings[j].format_id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-29 02:29:57 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
event->num_formats = num;
|
|
|
|
XFree(data);
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
freerdp_channels_send_event(cb->channels, (wMessage*) event);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
XFree(data);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_null_format_list(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static BYTE* xf_cliprdr_process_requested_raw(BYTE* data, int* size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* outbuf;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
outbuf = (BYTE*) malloc(*size);
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(outbuf, data, *size);
|
2011-09-23 07:37:17 +04:00
|
|
|
return outbuf;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static BYTE* xf_cliprdr_process_requested_unicodetext(BYTE* data, int* size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-09-24 03:49:13 +04:00
|
|
|
char* inbuf;
|
2013-01-11 00:30:32 +04:00
|
|
|
WCHAR* outbuf = NULL;
|
2012-09-24 03:49:13 +04:00
|
|
|
int out_size;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2012-09-24 03:49:13 +04:00
|
|
|
inbuf = (char*) lf2crlf(data, size);
|
2012-12-17 19:20:25 +04:00
|
|
|
out_size = ConvertToUnicode(CP_UTF8, 0, inbuf, -1, &outbuf, 0);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(inbuf);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2012-09-24 03:49:13 +04:00
|
|
|
*size = (int) ((out_size + 1) * 2);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
return (BYTE*) outbuf;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static BYTE* xf_cliprdr_process_requested_text(BYTE* data, int* size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* outbuf;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
outbuf = lf2crlf(data, size);
|
|
|
|
|
|
|
|
return outbuf;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static BYTE* xf_cliprdr_process_requested_dib(BYTE* data, int* size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* outbuf;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
/* length should be at least BMP header (14) + sizeof(BITMAPINFOHEADER) */
|
2013-03-29 02:29:57 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (*size < 54)
|
|
|
|
{
|
2013-03-29 02:29:57 +04:00
|
|
|
DEBUG_X11_CLIPRDR("bmp length %d too short", *size);
|
2011-09-23 07:37:17 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
*size -= 14;
|
2012-11-20 08:49:08 +04:00
|
|
|
outbuf = (BYTE*) malloc(*size);
|
|
|
|
ZeroMemory(outbuf, *size);
|
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
CopyMemory(outbuf, data + 14, *size);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
return outbuf;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static BYTE* xf_cliprdr_process_requested_html(BYTE* data, int* size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-09-24 04:11:50 +04:00
|
|
|
char* inbuf;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* in;
|
|
|
|
BYTE* outbuf;
|
2011-09-23 07:37:17 +04:00
|
|
|
char num[11];
|
|
|
|
|
|
|
|
inbuf = NULL;
|
2012-09-24 02:41:07 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (*size > 2)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
if ((BYTE) data[0] == 0xFE && (BYTE) data[1] == 0xFF)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
be2le(data, *size);
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
if ((BYTE) data[0] == 0xFF && (BYTE) data[1] == 0xFE)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-12-17 08:34:07 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) (data + 2),
|
|
|
|
(*size - 2) / 2, &inbuf, 0, NULL, NULL);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-24 02:41:07 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (inbuf == NULL)
|
|
|
|
{
|
2012-11-20 08:49:08 +04:00
|
|
|
inbuf = malloc(*size + 1);
|
|
|
|
ZeroMemory(inbuf, *size + 1);
|
|
|
|
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(inbuf, data, *size);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
outbuf = (BYTE*) malloc(*size + 200);
|
|
|
|
ZeroMemory(outbuf, *size + 200);
|
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
strcpy((char*) outbuf,
|
|
|
|
"Version:0.9\r\n"
|
|
|
|
"StartHTML:0000000000\r\n"
|
|
|
|
"EndHTML:0000000000\r\n"
|
|
|
|
"StartFragment:0000000000\r\n"
|
|
|
|
"EndFragment:0000000000\r\n");
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
in = (BYTE*) strstr((char*) inbuf, "<body");
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (in == NULL)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
in = (BYTE*) strstr((char*) inbuf, "<BODY");
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
/* StartHTML */
|
|
|
|
snprintf(num, sizeof(num), "%010lu", (unsigned long) strlen((char*) outbuf));
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(outbuf + 23, num, 10);
|
2011-09-23 07:37:17 +04:00
|
|
|
if (in == NULL)
|
|
|
|
{
|
|
|
|
strcat((char*) outbuf, "<HTML><BODY>");
|
|
|
|
}
|
|
|
|
strcat((char*) outbuf, "<!--StartFragment-->");
|
|
|
|
/* StartFragment */
|
|
|
|
snprintf(num, sizeof(num), "%010lu", (unsigned long) strlen((char*) outbuf));
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(outbuf + 69, num, 10);
|
2011-09-23 07:37:17 +04:00
|
|
|
strcat((char*) outbuf, (char*) inbuf);
|
|
|
|
/* EndFragment */
|
|
|
|
snprintf(num, sizeof(num), "%010lu", (unsigned long) strlen((char*) outbuf));
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(outbuf + 93, num, 10);
|
2011-09-23 07:37:17 +04:00
|
|
|
strcat((char*) outbuf, "<!--EndFragment-->");
|
|
|
|
if (in == NULL)
|
|
|
|
{
|
|
|
|
strcat((char*) outbuf, "</BODY></HTML>");
|
|
|
|
}
|
|
|
|
/* EndHTML */
|
|
|
|
snprintf(num, sizeof(num), "%010lu", (unsigned long) strlen((char*) outbuf));
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(outbuf + 43, num, 10);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
*size = strlen((char*) outbuf) + 1;
|
2012-10-09 07:21:26 +04:00
|
|
|
free(inbuf);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
return outbuf;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_process_requested_data(xfContext* xfc, BOOL has_data, BYTE* data, int size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* outbuf;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
if (cb->incr_starts && has_data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!has_data || data == NULL)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_null_data_response(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cb->format_mappings[cb->request_index].format_id)
|
|
|
|
{
|
|
|
|
case CB_FORMAT_RAW:
|
|
|
|
case CB_FORMAT_PNG:
|
|
|
|
case CB_FORMAT_JPEG:
|
|
|
|
case CB_FORMAT_GIF:
|
|
|
|
outbuf = xf_cliprdr_process_requested_raw(data, &size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_UNICODETEXT:
|
|
|
|
outbuf = xf_cliprdr_process_requested_unicodetext(data, &size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_TEXT:
|
|
|
|
outbuf = xf_cliprdr_process_requested_text(data, &size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_DIB:
|
|
|
|
outbuf = xf_cliprdr_process_requested_dib(data, &size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_HTML:
|
|
|
|
outbuf = xf_cliprdr_process_requested_html(data, &size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
outbuf = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outbuf)
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_data_response(xfc, outbuf, size);
|
2011-09-23 07:37:17 +04:00
|
|
|
else
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_null_data_response(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
/* Resend the format list, otherwise the server won't request again for the next paste */
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_format_list(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static BOOL xf_cliprdr_get_requested_data(xfContext* xfc, Atom target)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
Atom type;
|
|
|
|
int format;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* data = NULL;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL has_data = FALSE;
|
2011-11-18 04:51:30 +04:00
|
|
|
unsigned long length, bytes_left, dummy;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-02-12 05:38:19 +04:00
|
|
|
if ((cb->request_index < 0) || (cb->format_mappings[cb->request_index].target_format != target))
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("invalid target");
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_null_data_response(xfc);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XGetWindowProperty(xfc->display, xfc->drawable,
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->property_atom, 0, 0, 0, target,
|
2011-11-18 04:51:30 +04:00
|
|
|
&type, &format, &length, &bytes_left, &data);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("type=%d format=%d bytes=%d request_index=%d",
|
2011-11-01 03:15:27 +04:00
|
|
|
(int) type, format, (int) bytes_left, cb->request_index);
|
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
XFree(data);
|
|
|
|
data = NULL;
|
|
|
|
}
|
|
|
|
if (bytes_left <= 0 && !cb->incr_starts)
|
|
|
|
{
|
|
|
|
DEBUG_X11("no data");
|
|
|
|
}
|
|
|
|
else if (type == cb->incr_atom)
|
|
|
|
{
|
|
|
|
DEBUG_X11("INCR started");
|
2012-10-09 10:31:28 +04:00
|
|
|
cb->incr_starts = TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
if (cb->incr_data)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(cb->incr_data);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->incr_data = NULL;
|
|
|
|
}
|
|
|
|
cb->incr_data_length = 0;
|
|
|
|
/* Data will be followed in PropertyNotify event */
|
2012-10-09 10:31:28 +04:00
|
|
|
has_data = TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bytes_left <= 0)
|
|
|
|
{
|
|
|
|
/* INCR finish */
|
|
|
|
data = cb->incr_data;
|
|
|
|
cb->incr_data = NULL;
|
|
|
|
bytes_left = cb->incr_data_length;
|
|
|
|
cb->incr_data_length = 0;
|
|
|
|
cb->incr_starts = 0;
|
|
|
|
DEBUG_X11("INCR finished");
|
2012-10-09 10:31:28 +04:00
|
|
|
has_data = TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
2013-06-13 02:57:25 +04:00
|
|
|
else if (XGetWindowProperty(xfc->display, xfc->drawable,
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->property_atom, 0, bytes_left, 0, target,
|
2011-11-18 04:51:30 +04:00
|
|
|
&type, &format, &length, &dummy, &data) == Success)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
if (cb->incr_starts)
|
|
|
|
{
|
2011-11-18 04:51:30 +04:00
|
|
|
bytes_left = length * format / 8;
|
2011-09-23 07:37:17 +04:00
|
|
|
DEBUG_X11("%d bytes", (int)bytes_left);
|
2012-10-09 11:01:37 +04:00
|
|
|
cb->incr_data = (BYTE*) realloc(cb->incr_data, cb->incr_data_length + bytes_left);
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(cb->incr_data + cb->incr_data_length, data, bytes_left);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->incr_data_length += bytes_left;
|
|
|
|
XFree(data);
|
|
|
|
data = NULL;
|
|
|
|
}
|
2012-10-09 10:31:28 +04:00
|
|
|
has_data = TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("XGetWindowProperty failed");
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
2013-06-13 02:57:25 +04:00
|
|
|
XDeleteProperty(xfc->display, xfc->drawable, cb->property_atom);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_process_requested_data(xfc, has_data, data, (int) bytes_left);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
if (data)
|
|
|
|
XFree(data);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xf_cliprdr_append_target(clipboardContext* cb, Atom target)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-11-22 05:50:28 +04:00
|
|
|
if (cb->num_targets >= ARRAYSIZE(cb->targets))
|
2011-09-23 07:37:17 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < cb->num_targets; i++)
|
|
|
|
{
|
|
|
|
if (cb->targets[i] == target)
|
|
|
|
return;
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->targets[cb->num_targets++] = target;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_provide_targets(xfContext* xfc, XEvent* respond)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
if (respond->xselection.property != None)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XChangeProperty(xfc->display,
|
2011-09-23 07:37:17 +04:00
|
|
|
respond->xselection.requestor,
|
|
|
|
respond->xselection.property,
|
|
|
|
XA_ATOM, 32, PropModeReplace,
|
2012-10-09 11:01:37 +04:00
|
|
|
(BYTE*) cb->targets, cb->num_targets);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_provide_data(xfContext* xfc, XEvent* respond)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
if (respond->xselection.property != None)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XChangeProperty(xfc->display,
|
2011-09-23 07:37:17 +04:00
|
|
|
respond->xselection.requestor,
|
|
|
|
respond->xselection.property,
|
|
|
|
respond->xselection.target, 8, PropModeReplace,
|
2012-10-09 11:01:37 +04:00
|
|
|
(BYTE*) cb->data, cb->data_length);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_process_cb_format_list_event(xfContext* xfc, RDP_CB_FORMAT_LIST_EVENT* event)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
int i, j;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
if (cb->data)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(cb->data);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->data = NULL;
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (cb->formats)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(cb->formats);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
cb->formats = event->formats;
|
|
|
|
cb->num_formats = event->num_formats;
|
|
|
|
event->formats = NULL;
|
|
|
|
event->num_formats = 0;
|
|
|
|
|
|
|
|
cb->num_targets = 2;
|
2013-03-29 07:09:28 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
for (i = 0; i < cb->num_formats; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < cb->num_format_mappings; j++)
|
|
|
|
{
|
|
|
|
if (cb->formats[i] == cb->format_mappings[j].format_id)
|
|
|
|
{
|
|
|
|
DEBUG_X11("announce format#%d : %d", i, cb->formats[i]);
|
|
|
|
xf_cliprdr_append_target(cb, cb->format_mappings[j].target_format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XSetSelectionOwner(xfc->display, cb->clipboard_atom, xfc->drawable, CurrentTime);
|
2013-03-29 07:09:28 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (event->raw_format_data)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XChangeProperty(xfc->display, cb->root_window, cb->property_atom,
|
2011-09-23 07:37:17 +04:00
|
|
|
XA_STRING, 8, PropModeReplace,
|
|
|
|
event->raw_format_data, event->raw_format_data_size);
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XFlush(xfc->display);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static void xf_cliprdr_process_text(clipboardContext* cb, BYTE* data, int size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
cb->data = (BYTE*) malloc(size);
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(cb->data, data, size);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->data_length = size;
|
|
|
|
crlf2lf(cb->data, &cb->data_length);
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static void xf_cliprdr_process_unicodetext(clipboardContext* cb, BYTE* data, int size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-01-04 20:43:08 +04:00
|
|
|
cb->data_length = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) data, size / 2, (CHAR**) &(cb->data), 0, NULL, NULL);
|
2011-09-23 07:37:17 +04:00
|
|
|
crlf2lf(cb->data, &cb->data_length);
|
|
|
|
}
|
|
|
|
|
2014-05-29 12:12:02 +04:00
|
|
|
static BOOL xf_cliprdr_process_dib(clipboardContext* cb, BYTE* data, int size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 bpp;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 offset;
|
|
|
|
UINT32 ncolors;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
/* size should be at least sizeof(BITMAPINFOHEADER) */
|
2013-03-29 02:29:57 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (size < 40)
|
|
|
|
{
|
2013-03-29 02:29:57 +04:00
|
|
|
DEBUG_X11_CLIPRDR("dib size %d too short", size);
|
2014-05-29 12:12:02 +04:00
|
|
|
return FALSE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(data, size);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 14);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, bpp);
|
2014-05-29 12:12:02 +04:00
|
|
|
if ((bpp < 1) || (bpp > 32))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: invalid bpp value %d", __FUNCTION__, bpp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, ncolors);
|
2011-09-23 07:37:17 +04:00
|
|
|
offset = 14 + 40 + (bpp <= 8 ? (ncolors == 0 ? (1 << bpp) : ncolors) * 4 : 0);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, FALSE);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("offset=%d bpp=%d ncolors=%d", offset, bpp, ncolors);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(NULL, 14 + size);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, 'B');
|
|
|
|
Stream_Write_UINT8(s, 'M');
|
|
|
|
Stream_Write_UINT32(s, 14 + size);
|
|
|
|
Stream_Write_UINT32(s, 0);
|
|
|
|
Stream_Write_UINT32(s, offset);
|
|
|
|
Stream_Write(s, data, size);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
cb->data = Stream_Buffer(s);
|
2013-04-30 06:35:15 +04:00
|
|
|
cb->data_length = Stream_GetPosition(s);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, FALSE);
|
2014-05-29 12:12:02 +04:00
|
|
|
return TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static void xf_cliprdr_process_html(clipboardContext* cb, BYTE* data, int size)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
char* start_str;
|
|
|
|
char* end_str;
|
|
|
|
int start;
|
|
|
|
int end;
|
|
|
|
|
|
|
|
start_str = strstr((char*) data, "StartHTML:");
|
|
|
|
end_str = strstr((char*) data, "EndHTML:");
|
|
|
|
if (start_str == NULL || end_str == NULL)
|
|
|
|
{
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("invalid HTML clipboard format");
|
2011-09-23 07:37:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
start = atoi(start_str + 10);
|
|
|
|
end = atoi(end_str + 8);
|
|
|
|
if (start > size || end > size || start >= end)
|
|
|
|
{
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("invalid HTML offset");
|
2011-09-23 07:37:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
cb->data = (BYTE*) malloc(size - start + 1);
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(cb->data, data + start, end - start);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->data_length = end - start;
|
|
|
|
crlf2lf(cb->data, &cb->data_length);
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
static void xf_cliprdr_process_cb_data_response_event(xfContext* xfc, RDP_CB_DATA_RESPONSE_EVENT* event)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
DEBUG_X11_CLIPRDR("size=%d", event->size);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
if (!cb->respond)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("unexpected data");
|
2011-09-23 07:37:17 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->size == 0)
|
|
|
|
{
|
|
|
|
cb->respond->xselection.property = None;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (cb->data)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(cb->data);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->data = NULL;
|
|
|
|
}
|
2013-03-29 02:29:57 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
switch (cb->data_format)
|
|
|
|
{
|
|
|
|
case CB_FORMAT_RAW:
|
|
|
|
case CB_FORMAT_PNG:
|
|
|
|
case CB_FORMAT_JPEG:
|
|
|
|
case CB_FORMAT_GIF:
|
|
|
|
cb->data = event->data;
|
|
|
|
cb->data_length = event->size;
|
|
|
|
event->data = NULL;
|
|
|
|
event->size = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_TEXT:
|
|
|
|
xf_cliprdr_process_text(cb, event->data, event->size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_UNICODETEXT:
|
|
|
|
xf_cliprdr_process_unicodetext(cb, event->data, event->size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_DIB:
|
|
|
|
xf_cliprdr_process_dib(cb, event->data, event->size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CB_FORMAT_HTML:
|
|
|
|
xf_cliprdr_process_html(cb, event->data, event->size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
cb->respond->xselection.property = None;
|
|
|
|
break;
|
|
|
|
}
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_provide_data(xfc, cb->respond);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XSendEvent(xfc->display, cb->respond->xselection.requestor, 0, 0, cb->respond);
|
|
|
|
XFlush(xfc->display);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(cb->respond);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->respond = NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_process_cliprdr_event(xfContext* xfc, wMessage* event)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-03-29 02:29:57 +04:00
|
|
|
switch (GetMessageType(event->id))
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-03-29 02:29:57 +04:00
|
|
|
case CliprdrChannel_MonitorReady:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_process_cb_monitor_ready_event(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
break;
|
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
case CliprdrChannel_FormatList:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_process_cb_format_list_event(xfc, (RDP_CB_FORMAT_LIST_EVENT*) event);
|
2011-09-23 07:37:17 +04:00
|
|
|
break;
|
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
case CliprdrChannel_DataRequest:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_process_cb_data_request_event(xfc, (RDP_CB_DATA_REQUEST_EVENT*) event);
|
2011-09-23 07:37:17 +04:00
|
|
|
break;
|
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
case CliprdrChannel_DataResponse:
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_process_cb_data_response_event(xfc, (RDP_CB_DATA_RESPONSE_EVENT*) event);
|
2011-09-23 07:37:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-03-29 02:29:57 +04:00
|
|
|
DEBUG_X11_CLIPRDR("unknown event type %d", GetMessageType(event->id));
|
2011-09-23 07:37:17 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
BOOL xf_cliprdr_process_selection_notify(xfContext* xfc, XEvent* xevent)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
if (xevent->xselection.target == cb->targets[1])
|
|
|
|
{
|
|
|
|
if (xevent->xselection.property == None)
|
|
|
|
{
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("owner not support TARGETS. sending all format.");
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_supported_format_list(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_get_requested_targets(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
return xf_cliprdr_get_requested_data(xfc, xevent->xselection.target);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
BOOL xf_cliprdr_process_selection_request(xfContext* xfc, XEvent* xevent)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int fmt;
|
|
|
|
Atom type;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 format;
|
2011-09-23 07:37:17 +04:00
|
|
|
XEvent* respond;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 alt_format;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* data = NULL;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL delay_respond;
|
2011-11-18 04:51:30 +04:00
|
|
|
unsigned long length, bytes_left;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("target=%d", (int) xevent->xselectionrequest.target);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xevent->xselectionrequest.owner != xfc->drawable)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2011-11-23 21:36:36 +04:00
|
|
|
DEBUG_X11_CLIPRDR("not owner");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
delay_respond = FALSE;
|
2012-11-20 08:49:08 +04:00
|
|
|
|
|
|
|
respond = (XEvent*) malloc(sizeof(XEvent));
|
|
|
|
ZeroMemory(respond, sizeof(XEvent));
|
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
respond->xselection.property = None;
|
|
|
|
respond->xselection.type = SelectionNotify;
|
|
|
|
respond->xselection.display = xevent->xselectionrequest.display;
|
|
|
|
respond->xselection.requestor = xevent->xselectionrequest.requestor;
|
|
|
|
respond->xselection.selection = xevent->xselectionrequest.selection;
|
|
|
|
respond->xselection.target = xevent->xselectionrequest.target;
|
|
|
|
respond->xselection.time = xevent->xselectionrequest.time;
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (xevent->xselectionrequest.target == cb->targets[0]) /* TIMESTAMP */
|
|
|
|
{
|
|
|
|
/* TODO */
|
2011-11-23 21:36:36 +04:00
|
|
|
DEBUG_X11_CLIPRDR("target: TIMESTAMP (unimplemented)");
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else if (xevent->xselectionrequest.target == cb->targets[1]) /* TARGETS */
|
|
|
|
{
|
|
|
|
/* Someone else requests our available formats */
|
2011-11-23 21:36:36 +04:00
|
|
|
DEBUG_X11_CLIPRDR("target: TARGETS");
|
2011-09-23 07:37:17 +04:00
|
|
|
respond->xselection.property = xevent->xselectionrequest.property;
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_provide_targets(xfc, respond);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-23 21:36:36 +04:00
|
|
|
DEBUG_X11_CLIPRDR("target: other");
|
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
i = xf_cliprdr_select_format_by_atom(cb, xevent->xselectionrequest.target);
|
2011-11-23 21:36:36 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (i >= 0 && xevent->xselectionrequest.requestor != xfc->drawable)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
format = cb->format_mappings[i].format_id;
|
|
|
|
alt_format = format;
|
2013-02-12 05:38:19 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (format == CB_FORMAT_RAW)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
if (XGetWindowProperty(xfc->display, xevent->xselectionrequest.requestor,
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->property_atom, 0, 4, 0, XA_INTEGER,
|
2011-11-18 04:51:30 +04:00
|
|
|
&type, &fmt, &length, &bytes_left, &data) != Success)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2011-11-23 21:36:36 +04:00
|
|
|
DEBUG_X11_CLIPRDR("XGetWindowProperty failed");
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
if (data)
|
|
|
|
{
|
2013-03-29 05:13:56 +04:00
|
|
|
CopyMemory(&alt_format, data, 4);
|
2011-09-23 07:37:17 +04:00
|
|
|
XFree(data);
|
|
|
|
}
|
|
|
|
}
|
2013-02-12 05:38:19 +04:00
|
|
|
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("provide format 0x%04x alt_format 0x%04x", format, alt_format);
|
2013-02-12 05:38:19 +04:00
|
|
|
|
2011-11-18 04:51:30 +04:00
|
|
|
if ((cb->data != 0) && (format == cb->data_format) && (alt_format == cb->data_alt_format))
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
/* Cached clipboard data available. Send it now */
|
|
|
|
respond->xselection.property = xevent->xselectionrequest.property;
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_provide_data(xfc, respond);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else if (cb->respond)
|
|
|
|
{
|
2011-11-23 21:36:36 +04:00
|
|
|
DEBUG_X11_CLIPRDR("duplicated request");
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Send clipboard data request to the server.
|
|
|
|
* Response will be postponed after receiving the data
|
|
|
|
*/
|
|
|
|
if (cb->data)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(cb->data);
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->data = NULL;
|
|
|
|
}
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
respond->xselection.property = xevent->xselectionrequest.property;
|
|
|
|
cb->respond = respond;
|
|
|
|
cb->data_format = format;
|
|
|
|
cb->data_alt_format = alt_format;
|
2012-10-09 10:31:28 +04:00
|
|
|
delay_respond = TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_data_request(xfc, alt_format);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
if (delay_respond == FALSE)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
XSendEvent(xfc->display, xevent->xselectionrequest.requestor, 0, 0, respond);
|
|
|
|
XFlush(xfc->display);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(respond);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
BOOL xf_cliprdr_process_selection_clear(xfContext* xfc, XEvent* xevent)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
if (xf_cliprdr_is_self_owned(xfc))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
XDeleteProperty(xfc->display, cb->root_window, cb->property_atom);
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
BOOL xf_cliprdr_process_property_notify(xfContext* xfc, XEvent* xevent)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
2013-02-12 05:38:19 +04:00
|
|
|
if (!cb)
|
|
|
|
return TRUE;
|
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (xevent->xproperty.atom != cb->property_atom)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE; /* Not cliprdr-related */
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
if (xevent->xproperty.window == cb->root_window)
|
|
|
|
{
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("root window PropertyNotify");
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_format_list(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
2013-06-13 02:57:25 +04:00
|
|
|
else if (xevent->xproperty.window == xfc->drawable &&
|
2011-09-23 07:37:17 +04:00
|
|
|
xevent->xproperty.state == PropertyNewValue &&
|
2011-11-01 03:15:27 +04:00
|
|
|
cb->incr_starts && cb->request_index >= 0)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
2011-11-23 19:58:13 +04:00
|
|
|
DEBUG_X11_CLIPRDR("cliprdr window PropertyNotify");
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_get_requested_data(xfc,
|
2011-09-23 07:37:17 +04:00
|
|
|
cb->format_mappings[cb->request_index].target_format);
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
|
2013-06-13 02:57:25 +04:00
|
|
|
void xf_cliprdr_check_owner(xfContext* xfc)
|
2011-09-23 07:37:17 +04:00
|
|
|
{
|
|
|
|
Window owner;
|
2013-06-13 02:57:25 +04:00
|
|
|
clipboardContext* cb = (clipboardContext*) xfc->clipboard_context;
|
2011-09-23 07:37:17 +04:00
|
|
|
|
|
|
|
if (cb->sync)
|
|
|
|
{
|
2013-06-13 02:57:25 +04:00
|
|
|
owner = XGetSelectionOwner(xfc->display, cb->clipboard_atom);
|
2011-11-01 03:15:27 +04:00
|
|
|
|
2011-09-23 07:37:17 +04:00
|
|
|
if (cb->owner != owner)
|
|
|
|
{
|
|
|
|
cb->owner = owner;
|
2013-06-13 02:57:25 +04:00
|
|
|
xf_cliprdr_send_format_list(xfc);
|
2011-09-23 07:37:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|