|
|
|
@ -43,6 +43,12 @@
|
|
|
|
|
|
|
|
|
|
static Atom xaPRIMARY, xaCLIPBOARD;
|
|
|
|
|
static Atom xaTARGETS, xaTIMESTAMP, xaSTRING, xaTEXT, xaUTF8_STRING;
|
|
|
|
|
static Atom *xaBinclips;
|
|
|
|
|
static unsigned xaHtmlIndex, xaPngIndex;
|
|
|
|
|
static Bool htmlPngPresent;
|
|
|
|
|
|
|
|
|
|
static unsigned *mimeIndexesFromClient;
|
|
|
|
|
static unsigned numMimesFromClient;
|
|
|
|
|
|
|
|
|
|
static WindowPtr pWindow;
|
|
|
|
|
static Window wid;
|
|
|
|
@ -90,6 +96,29 @@ void vncSelectionInit(void)
|
|
|
|
|
xaTEXT = MakeAtom("TEXT", 4, TRUE);
|
|
|
|
|
xaUTF8_STRING = MakeAtom("UTF8_STRING", 11, TRUE);
|
|
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
|
mimeIndexesFromClient = calloc(dlp_num_mimetypes(), sizeof(unsigned));
|
|
|
|
|
numMimesFromClient = 0;
|
|
|
|
|
xaBinclips = calloc(dlp_num_mimetypes(), sizeof(Atom));
|
|
|
|
|
htmlPngPresent = FALSE;
|
|
|
|
|
Bool htmlfound = FALSE, pngfound = FALSE;
|
|
|
|
|
for (i = 0; i < dlp_num_mimetypes(); i++) {
|
|
|
|
|
const char *cur = dlp_get_mimetype(i);
|
|
|
|
|
xaBinclips[i] = MakeAtom(cur, strlen(cur), TRUE);
|
|
|
|
|
|
|
|
|
|
if (!strcmp(cur, "text/html")) {
|
|
|
|
|
xaHtmlIndex = i;
|
|
|
|
|
htmlfound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
if (!strcmp(cur, "image/png")) {
|
|
|
|
|
xaPngIndex = i;
|
|
|
|
|
pngfound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (htmlfound && pngfound)
|
|
|
|
|
htmlPngPresent = TRUE;
|
|
|
|
|
|
|
|
|
|
/* There are no hooks for when these are internal windows, so
|
|
|
|
|
* override the relevant handlers. */
|
|
|
|
|
origProcConvertSelection = ProcVector[X_ConvertSelection];
|
|
|
|
@ -161,6 +190,66 @@ void vncHandleClipboardAnnounce(int available)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vncHandleClipboardAnnounceBinary(const unsigned num, const char mimes[][32])
|
|
|
|
|
{
|
|
|
|
|
if (num) {
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
LOG_DEBUG("Remote binary clipboard announced, grabbing local ownership");
|
|
|
|
|
|
|
|
|
|
if (vncGetSetPrimary()) {
|
|
|
|
|
rc = vncOwnSelection(xaPRIMARY);
|
|
|
|
|
if (rc != Success)
|
|
|
|
|
LOG_ERROR("Could not set PRIMARY selection");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = vncOwnSelection(xaCLIPBOARD);
|
|
|
|
|
if (rc != Success)
|
|
|
|
|
LOG_ERROR("Could not set CLIPBOARD selection");
|
|
|
|
|
|
|
|
|
|
unsigned i, valid = 0;
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
|
unsigned j;
|
|
|
|
|
for (j = 0; j < dlp_num_mimetypes(); j++) {
|
|
|
|
|
if (!strcmp(dlp_get_mimetype(j), mimes[i])) {
|
|
|
|
|
mimeIndexesFromClient[valid] = j;
|
|
|
|
|
valid++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
numMimesFromClient = valid;
|
|
|
|
|
LOG_DEBUG("Client sent %u mimes, %u were valid", num, valid);
|
|
|
|
|
} else {
|
|
|
|
|
struct VncDataTarget* next;
|
|
|
|
|
numMimesFromClient = 0;
|
|
|
|
|
|
|
|
|
|
if (pWindow == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LOG_DEBUG("Remote binary clipboard lost, removing local ownership");
|
|
|
|
|
|
|
|
|
|
DeleteWindowFromAnySelections(pWindow);
|
|
|
|
|
|
|
|
|
|
/* Abort any pending transfer */
|
|
|
|
|
while (vncDataTargetHead != NULL) {
|
|
|
|
|
xEvent event;
|
|
|
|
|
|
|
|
|
|
event.u.u.type = SelectionNotify;
|
|
|
|
|
event.u.selectionNotify.time = vncDataTargetHead->time;
|
|
|
|
|
event.u.selectionNotify.requestor = vncDataTargetHead->requestor;
|
|
|
|
|
event.u.selectionNotify.selection = vncDataTargetHead->selection;
|
|
|
|
|
event.u.selectionNotify.target = vncDataTargetHead->target;
|
|
|
|
|
event.u.selectionNotify.property = None;
|
|
|
|
|
WriteEventsToClient(vncDataTargetHead->client, 1, &event);
|
|
|
|
|
|
|
|
|
|
next = vncDataTargetHead->next;
|
|
|
|
|
free(vncDataTargetHead);
|
|
|
|
|
vncDataTargetHead = next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vncHandleClipboardData(const char* data, int len)
|
|
|
|
|
{
|
|
|
|
|
struct VncDataTarget* next;
|
|
|
|
@ -277,6 +366,19 @@ static int vncOwnSelection(Atom selection)
|
|
|
|
|
return Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Bool clientHasBinaryAtom(const Atom target, unsigned *which)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
|
|
|
|
for (i = 0; i < numMimesFromClient; i++) {
|
|
|
|
|
if (xaBinclips[mimeIndexesFromClient[i]] == target) {
|
|
|
|
|
*which = mimeIndexesFromClient[i];
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int vncConvertSelection(ClientPtr client, Atom selection,
|
|
|
|
|
Atom target, Atom property,
|
|
|
|
|
Window requestor, CARD32 time,
|
|
|
|
@ -315,14 +417,23 @@ static int vncConvertSelection(ClientPtr client, Atom selection,
|
|
|
|
|
realProperty = target;
|
|
|
|
|
|
|
|
|
|
/* FIXME: MULTIPLE target */
|
|
|
|
|
unsigned binatomidx;
|
|
|
|
|
|
|
|
|
|
if (target == xaTARGETS) {
|
|
|
|
|
Atom targets[] = { xaTARGETS, xaTIMESTAMP,
|
|
|
|
|
xaSTRING, xaTEXT, xaUTF8_STRING };
|
|
|
|
|
Atom targets[5 + numMimesFromClient];
|
|
|
|
|
targets[0] = xaTARGETS;
|
|
|
|
|
targets[1] = xaTIMESTAMP;
|
|
|
|
|
targets[2] = xaSTRING;
|
|
|
|
|
targets[3] = xaTEXT;
|
|
|
|
|
targets[4] = xaUTF8_STRING;
|
|
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
|
for (i = 0; i < numMimesFromClient; i++)
|
|
|
|
|
targets[5 + i] = xaBinclips[mimeIndexesFromClient[i]];
|
|
|
|
|
|
|
|
|
|
rc = dixChangeWindowProperty(serverClient, pWin, realProperty,
|
|
|
|
|
XA_ATOM, 32, PropModeReplace,
|
|
|
|
|
sizeof(targets)/sizeof(targets[0]),
|
|
|
|
|
5 + numMimesFromClient,
|
|
|
|
|
targets, TRUE);
|
|
|
|
|
if (rc != Success)
|
|
|
|
|
return rc;
|
|
|
|
@ -333,6 +444,15 @@ static int vncConvertSelection(ClientPtr client, Atom selection,
|
|
|
|
|
TRUE);
|
|
|
|
|
if (rc != Success)
|
|
|
|
|
return rc;
|
|
|
|
|
} else if (clientHasBinaryAtom(target, &binatomidx)) {
|
|
|
|
|
const unsigned char *data;
|
|
|
|
|
unsigned len;
|
|
|
|
|
vncGetBinaryClipboardData(dlp_get_mimetype(binatomidx), &data, &len);
|
|
|
|
|
rc = dixChangeWindowProperty(serverClient, pWin, realProperty,
|
|
|
|
|
xaBinclips[binatomidx], 8, PropModeReplace,
|
|
|
|
|
len, (unsigned char *) data, TRUE);
|
|
|
|
|
if (rc != Success)
|
|
|
|
|
return rc;
|
|
|
|
|
} else {
|
|
|
|
|
if (data == NULL) {
|
|
|
|
|
struct VncDataTarget* vdt;
|
|
|
|
@ -379,7 +499,7 @@ static int vncConvertSelection(ClientPtr client, Atom selection,
|
|
|
|
|
} else if (target == xaUTF8_STRING) {
|
|
|
|
|
rc = dixChangeWindowProperty(serverClient, pWin, realProperty,
|
|
|
|
|
xaUTF8_STRING, 8, PropModeReplace,
|
|
|
|
|
len, data, TRUE);
|
|
|
|
|
len, (char *) data, TRUE);
|
|
|
|
|
if (rc != Success)
|
|
|
|
|
return rc;
|
|
|
|
|
} else {
|
|
|
|
@ -483,6 +603,21 @@ static Bool vncHasAtom(Atom atom, const Atom list[], size_t size)
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Bool vncHasBinaryClipboardAtom(const Atom list[], size_t size)
|
|
|
|
|
{
|
|
|
|
|
size_t i, b;
|
|
|
|
|
const unsigned num = dlp_num_mimetypes();
|
|
|
|
|
|
|
|
|
|
for (i = 0;i < size;i++) {
|
|
|
|
|
for (b = 0; b < num; b++) {
|
|
|
|
|
if (list[i] == xaBinclips[b])
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vncHandleSelection(Atom selection, Atom target,
|
|
|
|
|
Atom property, Atom requestor,
|
|
|
|
|
TimeStamp time)
|
|
|
|
@ -510,7 +645,8 @@ static void vncHandleSelection(Atom selection, Atom target,
|
|
|
|
|
|
|
|
|
|
if (probing) {
|
|
|
|
|
if (vncHasAtom(xaSTRING, (const Atom*)prop->data, prop->size) ||
|
|
|
|
|
vncHasAtom(xaUTF8_STRING, (const Atom*)prop->data, prop->size)) {
|
|
|
|
|
vncHasAtom(xaUTF8_STRING, (const Atom*)prop->data, prop->size) ||
|
|
|
|
|
vncHasBinaryClipboardAtom((const Atom*)prop->data, prop->size)) {
|
|
|
|
|
LOG_DEBUG("Compatible format found, notifying clients");
|
|
|
|
|
activeSelection = selection;
|
|
|
|
|
vncAnnounceClipboard(TRUE);
|
|
|
|
@ -520,6 +656,28 @@ static void vncHandleSelection(Atom selection, Atom target,
|
|
|
|
|
vncSelectionRequest(selection, xaUTF8_STRING);
|
|
|
|
|
else if (vncHasAtom(xaSTRING, (const Atom*)prop->data, prop->size))
|
|
|
|
|
vncSelectionRequest(selection, xaSTRING);
|
|
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
Bool skiphtml = FALSE;
|
|
|
|
|
Bool cleared = FALSE;
|
|
|
|
|
if (htmlPngPresent &&
|
|
|
|
|
vncHasAtom(xaBinclips[xaHtmlIndex], (const Atom*)prop->data, prop->size) &&
|
|
|
|
|
vncHasAtom(xaBinclips[xaPngIndex], (const Atom*)prop->data, prop->size))
|
|
|
|
|
skiphtml = TRUE;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < dlp_num_mimetypes(); i++) {
|
|
|
|
|
if (skiphtml && i == xaHtmlIndex)
|
|
|
|
|
continue;
|
|
|
|
|
if (vncHasAtom(xaBinclips[i], (const Atom*)prop->data, prop->size)) {
|
|
|
|
|
if (!cleared) {
|
|
|
|
|
vncClearBinaryClipboardData();
|
|
|
|
|
cleared = TRUE;
|
|
|
|
|
}
|
|
|
|
|
vncSelectionRequest(selection, xaBinclips[i]);
|
|
|
|
|
//break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (target == xaSTRING) {
|
|
|
|
|
char* filtered;
|
|
|
|
@ -563,6 +721,25 @@ static void vncHandleSelection(Atom selection, Atom target,
|
|
|
|
|
vncSendClipboardData(filtered);
|
|
|
|
|
|
|
|
|
|
vncStrFree(filtered);
|
|
|
|
|
} else {
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
if (prop->format != 8)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < dlp_num_mimetypes(); i++) {
|
|
|
|
|
if (target == xaBinclips[i]) {
|
|
|
|
|
if (prop->type != xaBinclips[i])
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LOG_DEBUG("Sending binary clipboard to clients (%d bytes)",
|
|
|
|
|
prop->size);
|
|
|
|
|
|
|
|
|
|
vncSendBinaryClipboardData(dlp_get_mimetype(i), prop->data, prop->size);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|