2003-11-14 17:48:57 +01:00
|
|
|
/*
|
2004-06-21 15:19:32 +02:00
|
|
|
*Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
|
2009-02-03 16:48:04 +01:00
|
|
|
*Copyright (C) Colin Harrison 2005-2008
|
2003-11-14 17:48:57 +01:00
|
|
|
*
|
|
|
|
*Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
*"Software"), to deal in the Software without restriction, including
|
|
|
|
*without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
*distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
*permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
*the following conditions:
|
|
|
|
*
|
|
|
|
*The above copyright notice and this permission notice shall be
|
|
|
|
*included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
*EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
*MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
2004-06-21 15:19:32 +02:00
|
|
|
*NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
|
2003-11-14 17:48:57 +01:00
|
|
|
*ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
|
|
*CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
*WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
2009-02-03 16:48:04 +01:00
|
|
|
*Except as contained in this notice, the name of the copyright holder(s)
|
|
|
|
*and author(s) shall not be used in advertising or otherwise to promote
|
|
|
|
*the sale, use or other dealings in this Software without prior written
|
|
|
|
*authorization from the copyright holder(s) and author(s).
|
2003-11-14 17:48:57 +01:00
|
|
|
*
|
|
|
|
* Authors: Harold L Hunt II
|
2009-02-03 16:48:04 +01:00
|
|
|
* Colin Harrison
|
2003-11-14 17:48:57 +01:00
|
|
|
*/
|
|
|
|
|
2005-07-05 00:10:43 +02:00
|
|
|
#ifdef HAVE_XWIN_CONFIG_H
|
|
|
|
#include <xwin-config.h>
|
|
|
|
#endif
|
2012-02-13 20:58:37 +01:00
|
|
|
|
2013-09-24 14:30:32 +02:00
|
|
|
#include <limits.h>
|
2014-09-27 12:50:11 +02:00
|
|
|
#include <wchar.h>
|
2018-06-30 17:00:16 +02:00
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xfixes.h>
|
2012-02-13 20:58:37 +01:00
|
|
|
|
2013-09-24 16:09:22 +02:00
|
|
|
#include "winclipboard.h"
|
|
|
|
#include "internal.h"
|
|
|
|
|
2012-02-13 20:58:37 +01:00
|
|
|
/*
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CLIP_NUM_SELECTIONS 2
|
2018-06-30 17:00:16 +02:00
|
|
|
#define CLIP_OWN_NONE -1
|
2012-02-13 20:58:37 +01:00
|
|
|
#define CLIP_OWN_PRIMARY 0
|
|
|
|
#define CLIP_OWN_CLIPBOARD 1
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
#define CP_ISO_8559_1 28591
|
|
|
|
|
2012-02-13 20:58:37 +01:00
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern int xfixes_event_base;
|
2013-09-24 16:09:22 +02:00
|
|
|
Bool fPrimarySelection = TRUE;
|
2012-02-13 20:58:37 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables
|
|
|
|
*/
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
static xcb_window_t s_iOwners[CLIP_NUM_SELECTIONS] = { XCB_NONE, XCB_NONE };
|
2012-02-13 20:58:37 +01:00
|
|
|
static const char *szSelectionNames[CLIP_NUM_SELECTIONS] =
|
|
|
|
{ "PRIMARY", "CLIPBOARD" };
|
|
|
|
|
|
|
|
static unsigned int lastOwnedSelectionIndex = CLIP_OWN_NONE;
|
|
|
|
|
|
|
|
static void
|
2018-06-30 17:00:16 +02:00
|
|
|
MonitorSelection(xcb_xfixes_selection_notify_event_t * e, unsigned int i)
|
2012-02-13 20:58:37 +01:00
|
|
|
{
|
|
|
|
/* Look for owned -> not owned transition */
|
2018-06-30 17:00:16 +02:00
|
|
|
if ((XCB_NONE == e->owner) && (XCB_NONE != s_iOwners[i])) {
|
2012-02-13 20:58:37 +01:00
|
|
|
unsigned int other_index;
|
|
|
|
|
|
|
|
winDebug("MonitorSelection - %s - Going from owned to not owned.\n",
|
|
|
|
szSelectionNames[i]);
|
|
|
|
|
|
|
|
/* If this selection is not owned, the other monitored selection must be the most
|
|
|
|
recently owned, if it is owned at all */
|
|
|
|
if (i == CLIP_OWN_PRIMARY)
|
|
|
|
other_index = CLIP_OWN_CLIPBOARD;
|
|
|
|
if (i == CLIP_OWN_CLIPBOARD)
|
|
|
|
other_index = CLIP_OWN_PRIMARY;
|
2018-06-30 17:00:16 +02:00
|
|
|
if (XCB_NONE != s_iOwners[other_index])
|
2012-02-13 20:58:37 +01:00
|
|
|
lastOwnedSelectionIndex = other_index;
|
|
|
|
else
|
|
|
|
lastOwnedSelectionIndex = CLIP_OWN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save last owned selection */
|
2018-06-30 17:00:16 +02:00
|
|
|
if (XCB_NONE != e->owner) {
|
2012-02-13 20:58:37 +01:00
|
|
|
lastOwnedSelectionIndex = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save new selection owner or None */
|
|
|
|
s_iOwners[i] = e->owner;
|
2018-06-30 17:00:16 +02:00
|
|
|
winDebug("MonitorSelection - %s - Now owned by XID %x\n",
|
2012-02-13 20:58:37 +01:00
|
|
|
szSelectionNames[i], e->owner);
|
|
|
|
}
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_atom_t
|
2013-06-17 20:58:20 +02:00
|
|
|
winClipboardGetLastOwnedSelectionAtom(ClipboardAtoms *atoms)
|
2012-02-13 20:58:37 +01:00
|
|
|
{
|
|
|
|
if (lastOwnedSelectionIndex == CLIP_OWN_NONE)
|
2018-06-30 17:00:16 +02:00
|
|
|
return XCB_NONE;
|
2012-02-13 20:58:37 +01:00
|
|
|
|
|
|
|
if (lastOwnedSelectionIndex == CLIP_OWN_PRIMARY)
|
2018-06-30 17:00:16 +02:00
|
|
|
return XCB_ATOM_PRIMARY;
|
2012-02-13 20:58:37 +01:00
|
|
|
|
|
|
|
if (lastOwnedSelectionIndex == CLIP_OWN_CLIPBOARD)
|
2013-06-17 20:58:20 +02:00
|
|
|
return atoms->atomClipboard;
|
2012-02-13 20:58:37 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
return XCB_NONE;
|
2012-02-13 20:58:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
winClipboardInitMonitoredSelections(void)
|
|
|
|
{
|
|
|
|
/* Initialize static variables */
|
2014-10-01 13:14:43 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < CLIP_NUM_SELECTIONS; ++i)
|
2018-06-30 17:00:16 +02:00
|
|
|
s_iOwners[i] = XCB_NONE;
|
2012-02-13 20:58:37 +01:00
|
|
|
|
|
|
|
lastOwnedSelectionIndex = CLIP_OWN_NONE;
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
static char *get_atom_name(xcb_connection_t *conn, xcb_atom_t atom)
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
{
|
2018-06-30 17:00:16 +02:00
|
|
|
char *ret;
|
|
|
|
xcb_get_atom_name_cookie_t cookie = xcb_get_atom_name(conn, atom);
|
|
|
|
xcb_get_atom_name_reply_t *reply = xcb_get_atom_name_reply(conn, cookie, NULL);
|
|
|
|
if (!reply)
|
|
|
|
return NULL;
|
|
|
|
ret = malloc(xcb_get_atom_name_name_length(reply) + 1);
|
|
|
|
if (ret) {
|
|
|
|
memcpy(ret, xcb_get_atom_name_name(reply), xcb_get_atom_name_name_length(reply));
|
|
|
|
ret[xcb_get_atom_name_name_length(reply)] = '\0';
|
|
|
|
}
|
|
|
|
free(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
static int
|
|
|
|
winClipboardSelectionNotifyTargets(HWND hwnd, xcb_window_t iWindow, xcb_connection_t *conn, ClipboardConversionData *data, ClipboardAtoms *atoms)
|
|
|
|
{
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
/* Retrieve the selection data and delete the property */
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_get_property_cookie_t cookie = xcb_get_property(conn,
|
|
|
|
TRUE,
|
|
|
|
iWindow,
|
|
|
|
atoms->atomLocalProperty,
|
|
|
|
XCB_GET_PROPERTY_TYPE_ANY,
|
|
|
|
0,
|
|
|
|
INT_MAX);
|
|
|
|
xcb_get_property_reply_t *reply = xcb_get_property_reply(conn, cookie, NULL);
|
|
|
|
if (!reply) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionNotify - "
|
|
|
|
"XGetWindowProperty () failed\n");
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
} else {
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_atom_t *prop = xcb_get_property_value(reply);
|
|
|
|
int nitems = xcb_get_property_value_length(reply)/sizeof(xcb_atom_t);
|
|
|
|
int i;
|
|
|
|
data->targetList = malloc((nitems+1)*sizeof(xcb_atom_t));
|
|
|
|
|
|
|
|
for (i = 0; i < nitems; i++)
|
|
|
|
{
|
|
|
|
xcb_atom_t atom = prop[i];
|
|
|
|
char *pszAtomName = get_atom_name(conn, atom);
|
|
|
|
data->targetList[i] = atom;
|
|
|
|
winDebug("winClipboardFlushXEvents - SelectionNotify - target[%d] %d = %s\n", i, atom, pszAtomName);
|
|
|
|
free(pszAtomName);
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data->targetList[nitems] = 0;
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
free(reply);
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return WIN_XEVENTS_NOTIFY_TARGETS;
|
|
|
|
}
|
|
|
|
|
2015-11-18 22:27:23 +01:00
|
|
|
static int
|
2018-06-30 17:00:16 +02:00
|
|
|
winClipboardSelectionNotifyData(HWND hwnd, xcb_window_t iWindow, xcb_connection_t *conn, ClipboardConversionData *data, ClipboardAtoms *atoms)
|
2015-11-18 22:27:23 +01:00
|
|
|
{
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_atom_t encoding;
|
2015-11-18 22:27:23 +01:00
|
|
|
int format;
|
|
|
|
unsigned long int nitems;
|
|
|
|
unsigned long int after;
|
|
|
|
unsigned char *value;
|
2018-06-30 17:00:16 +02:00
|
|
|
|
|
|
|
unsigned char *xtpText_value;
|
|
|
|
xcb_atom_t xtpText_encoding;
|
|
|
|
int xtpText_nitems;
|
|
|
|
|
2015-11-18 22:27:23 +01:00
|
|
|
Bool fSetClipboardData = TRUE;
|
|
|
|
char *pszReturnData = NULL;
|
2018-06-30 17:00:16 +02:00
|
|
|
UINT codepage;
|
2015-11-18 22:27:23 +01:00
|
|
|
wchar_t *pwszUnicodeStr = NULL;
|
|
|
|
HGLOBAL hGlobal = NULL;
|
|
|
|
char *pszGlobalData = NULL;
|
|
|
|
|
|
|
|
/* Retrieve the selection data and delete the property */
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_get_property_cookie_t cookie = xcb_get_property(conn,
|
|
|
|
TRUE,
|
|
|
|
iWindow,
|
|
|
|
atoms->atomLocalProperty,
|
|
|
|
XCB_GET_PROPERTY_TYPE_ANY,
|
|
|
|
0,
|
|
|
|
INT_MAX);
|
|
|
|
xcb_get_property_reply_t *reply = xcb_get_property_reply(conn, cookie, NULL);
|
|
|
|
if (!reply) {
|
2015-11-18 22:27:23 +01:00
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionNotify - "
|
2018-06-30 17:00:16 +02:00
|
|
|
"XGetWindowProperty () failed\n");
|
2015-11-18 22:27:23 +01:00
|
|
|
goto winClipboardFlushXEvents_SelectionNotify_Done;
|
2018-06-30 17:00:16 +02:00
|
|
|
} else {
|
|
|
|
nitems = xcb_get_property_value_length(reply);
|
|
|
|
value = xcb_get_property_value(reply);
|
|
|
|
after = reply->bytes_after;
|
|
|
|
encoding = reply->type;
|
|
|
|
format = reply->format;
|
|
|
|
// We assume format == 8 (i.e. data is a sequence of bytes). It's not
|
|
|
|
// clear how anything else should be handled.
|
|
|
|
if (format != 8)
|
|
|
|
ErrorF("SelectionNotify: format is %d, proceeding as if it was 8\n", format);
|
2015-11-18 22:27:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-06-30 17:00:16 +02:00
|
|
|
char *pszAtomName;
|
2015-11-18 22:27:23 +01:00
|
|
|
winDebug("SelectionNotify - returned data %lu left %lu\n", nitems, after);
|
2018-06-30 17:00:16 +02:00
|
|
|
pszAtomName = get_atom_name(conn, encoding);
|
2015-11-18 22:27:23 +01:00
|
|
|
winDebug("Notify atom name %s\n", pszAtomName);
|
2018-06-30 17:00:16 +02:00
|
|
|
free(pszAtomName);
|
2015-11-18 22:27:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* INCR reply indicates the start of a incremental transfer */
|
|
|
|
if (encoding == atoms->atomIncr) {
|
|
|
|
winDebug("winClipboardSelectionNotifyData: starting INCR, anticipated size %d\n", *(int *)value);
|
|
|
|
data->incrsize = 0;
|
|
|
|
data->incr = malloc(*(int *)value);
|
|
|
|
// XXX: if malloc failed, we have an error
|
|
|
|
return WIN_XEVENTS_SUCCESS;
|
|
|
|
}
|
|
|
|
else if (data->incr) {
|
|
|
|
/* If an INCR transfer is in progress ... */
|
|
|
|
if (nitems == 0) {
|
|
|
|
winDebug("winClipboardSelectionNotifyData: ending INCR, actual size %ld\n", data->incrsize);
|
|
|
|
/* a zero-length property indicates the end of the data */
|
2018-06-30 17:00:16 +02:00
|
|
|
xtpText_value = data->incr;
|
|
|
|
xtpText_encoding = encoding;
|
|
|
|
// XXX: The type of the converted selection is the type of the first
|
|
|
|
// partial property. The remaining partial properties must have the
|
|
|
|
// same type.
|
|
|
|
xtpText_nitems = data->incrsize;
|
2015-11-18 22:27:23 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Otherwise, continue appending the INCR data */
|
|
|
|
winDebug("winClipboardSelectionNotifyData: INCR, %ld bytes\n", nitems);
|
|
|
|
data->incr = realloc(data->incr, data->incrsize + nitems);
|
|
|
|
memcpy(data->incr + data->incrsize, value, nitems);
|
|
|
|
data->incrsize = data->incrsize + nitems;
|
|
|
|
return WIN_XEVENTS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Otherwise, the data is just contained in the property */
|
|
|
|
winDebug("winClipboardSelectionNotifyData: non-INCR, %ld bytes\n", nitems);
|
2018-06-30 17:00:16 +02:00
|
|
|
xtpText_value = value;
|
|
|
|
xtpText_encoding = encoding;
|
|
|
|
xtpText_nitems = nitems;
|
2015-11-18 22:27:23 +01:00
|
|
|
}
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
if (xtpText_encoding == atoms->atomUTF8String) {
|
|
|
|
pszReturnData = malloc(xtpText_nitems + 1);
|
|
|
|
memcpy(pszReturnData, xtpText_value, xtpText_nitems);
|
|
|
|
pszReturnData[xtpText_nitems] = 0;
|
|
|
|
codepage = CP_UTF8; // code page identifier for utf8
|
|
|
|
} else if (xtpText_encoding == XCB_ATOM_STRING) {
|
|
|
|
// STRING encoding is Latin1 (ISO8859-1) plus tab and newline
|
|
|
|
pszReturnData = malloc(xtpText_nitems + 1);
|
|
|
|
memcpy(pszReturnData, xtpText_value, xtpText_nitems);
|
|
|
|
pszReturnData[xtpText_nitems] = 0;
|
|
|
|
codepage = CP_ISO_8559_1; // code page identifier for iso-8559-1
|
|
|
|
} else if (xtpText_encoding == atoms->atomCompoundText) {
|
|
|
|
// COMPOUND_TEXT is complex, based on ISO 2022
|
|
|
|
ErrorF("SelectionNotify: data in COMPOUND_TEXT encoding which is not implemented, discarding\n");
|
|
|
|
pszReturnData = malloc(1);
|
|
|
|
pszReturnData[0] = '\0';
|
|
|
|
} else { // shouldn't happen as we accept no other encodings
|
2015-11-18 22:27:23 +01:00
|
|
|
pszReturnData = malloc(1);
|
|
|
|
pszReturnData[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
/* Free the data returned from xcb_get_property */
|
|
|
|
free(reply);
|
2015-11-18 22:27:23 +01:00
|
|
|
|
|
|
|
/* Free any INCR data */
|
|
|
|
if (data->incr) {
|
|
|
|
free(data->incr);
|
|
|
|
data->incr = NULL;
|
|
|
|
data->incrsize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert the X clipboard string to DOS format */
|
|
|
|
winClipboardUNIXtoDOS(&pszReturnData, strlen(pszReturnData));
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
/* Find out how much space needed when converted to UTF-16 */
|
|
|
|
int iUnicodeLen = MultiByteToWideChar(codepage, 0,
|
2018-07-01 13:11:19 +02:00
|
|
|
pszReturnData, -1, NULL, 0);
|
2015-11-18 22:27:23 +01:00
|
|
|
|
2018-07-01 13:11:19 +02:00
|
|
|
/* NOTE: iUnicodeLen includes space for null terminator */
|
|
|
|
pwszUnicodeStr = malloc(sizeof(wchar_t) * iUnicodeLen);
|
|
|
|
if (!pwszUnicodeStr) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionNotify "
|
|
|
|
"malloc failed for pwszUnicodeStr, aborting.\n");
|
2015-11-18 22:27:23 +01:00
|
|
|
|
2018-07-01 13:11:19 +02:00
|
|
|
/* Abort */
|
|
|
|
goto winClipboardFlushXEvents_SelectionNotify_Done;
|
|
|
|
}
|
2015-11-18 22:27:23 +01:00
|
|
|
|
2018-07-01 13:11:19 +02:00
|
|
|
/* Do the actual conversion */
|
2018-06-30 17:00:16 +02:00
|
|
|
MultiByteToWideChar(codepage, 0,
|
|
|
|
pszReturnData, -1, pwszUnicodeStr, iUnicodeLen);
|
2015-11-18 22:27:23 +01:00
|
|
|
|
2018-07-01 13:11:19 +02:00
|
|
|
/* Allocate global memory for the X clipboard data */
|
|
|
|
hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * iUnicodeLen);
|
2015-11-18 22:27:23 +01:00
|
|
|
|
|
|
|
free(pszReturnData);
|
|
|
|
|
|
|
|
/* Check that global memory was allocated */
|
|
|
|
if (!hGlobal) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionNotify "
|
|
|
|
"GlobalAlloc failed, aborting: %08x\n", (unsigned int)GetLastError());
|
|
|
|
|
|
|
|
/* Abort */
|
|
|
|
goto winClipboardFlushXEvents_SelectionNotify_Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Obtain a pointer to the global memory */
|
|
|
|
pszGlobalData = GlobalLock(hGlobal);
|
|
|
|
if (pszGlobalData == NULL) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - Could not lock global "
|
|
|
|
"memory for clipboard transfer\n");
|
|
|
|
|
|
|
|
/* Abort */
|
|
|
|
goto winClipboardFlushXEvents_SelectionNotify_Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the returned string into the global memory */
|
2018-07-01 13:11:19 +02:00
|
|
|
wcscpy((wchar_t *)pszGlobalData, pwszUnicodeStr);
|
|
|
|
free(pwszUnicodeStr);
|
|
|
|
pwszUnicodeStr = NULL;
|
2015-11-18 22:27:23 +01:00
|
|
|
|
|
|
|
/* Release the pointer to the global memory */
|
|
|
|
GlobalUnlock(hGlobal);
|
|
|
|
pszGlobalData = NULL;
|
|
|
|
|
|
|
|
/* Push the selection data to the Windows clipboard */
|
2018-07-01 13:11:19 +02:00
|
|
|
SetClipboardData(CF_UNICODETEXT, hGlobal);
|
2015-11-18 22:27:23 +01:00
|
|
|
|
|
|
|
/* Flag that SetClipboardData has been called */
|
|
|
|
fSetClipboardData = FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: Do not try to free pszGlobalData, it is owned by
|
|
|
|
* Windows after the call to SetClipboardData ().
|
|
|
|
*/
|
|
|
|
|
|
|
|
winClipboardFlushXEvents_SelectionNotify_Done:
|
|
|
|
/* Free allocated resources */
|
|
|
|
free(pwszUnicodeStr);
|
|
|
|
if (hGlobal && pszGlobalData)
|
|
|
|
GlobalUnlock(hGlobal);
|
|
|
|
if (fSetClipboardData) {
|
|
|
|
SetClipboardData(CF_UNICODETEXT, NULL);
|
|
|
|
SetClipboardData(CF_TEXT, NULL);
|
|
|
|
}
|
|
|
|
return WIN_XEVENTS_NOTIFY_DATA;
|
|
|
|
}
|
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
/*
|
|
|
|
* Process any pending X events
|
|
|
|
*/
|
|
|
|
|
2004-06-21 15:19:32 +02:00
|
|
|
int
|
2012-03-21 20:55:09 +01:00
|
|
|
winClipboardFlushXEvents(HWND hwnd,
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_window_t iWindow, xcb_connection_t *conn,
|
|
|
|
ClipboardConversionData *data, ClipboardAtoms *atoms)
|
2003-11-14 17:48:57 +01:00
|
|
|
{
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_atom_t atomClipboard = atoms->atomClipboard;
|
|
|
|
xcb_atom_t atomUTF8String = atoms->atomUTF8String;
|
|
|
|
xcb_atom_t atomCompoundText = atoms->atomCompoundText;
|
|
|
|
xcb_atom_t atomTargets = atoms->atomTargets;
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Process all pending events */
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_generic_event_t *event;
|
|
|
|
while ((event = xcb_poll_for_event(conn))) {
|
|
|
|
const char *pszGlobalData = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
HGLOBAL hGlobal = NULL;
|
|
|
|
char *pszConvertData = NULL;
|
|
|
|
Bool fAbort = FALSE;
|
|
|
|
Bool fCloseClipboard = FALSE;
|
|
|
|
|
|
|
|
/* Branch on the event type */
|
2018-06-30 17:00:16 +02:00
|
|
|
switch (event->response_type & ~0x80) {
|
|
|
|
case XCB_SELECTION_REQUEST:
|
|
|
|
{
|
|
|
|
char *xtpText_value = NULL;
|
|
|
|
int xtpText_nitems;
|
|
|
|
UINT codepage;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_selection_request_event_t *selection_request = (xcb_selection_request_event_t *)event;
|
2012-03-21 20:55:09 +01:00
|
|
|
{
|
|
|
|
char *pszAtomName = NULL;
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
winDebug("SelectionRequest - target %d\n", selection_request->target);
|
2009-11-01 19:18:51 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
pszAtomName = get_atom_name(conn, selection_request->target);
|
2012-03-21 20:55:09 +01:00
|
|
|
winDebug("SelectionRequest - Target atom name %s\n", pszAtomName);
|
2018-06-30 17:00:16 +02:00
|
|
|
free(pszAtomName);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Abort if invalid target type */
|
2018-06-30 17:00:16 +02:00
|
|
|
if (selection_request->target != XCB_ATOM_STRING
|
|
|
|
&& selection_request->target != atomUTF8String
|
|
|
|
&& selection_request->target != atomCompoundText
|
|
|
|
&& selection_request->target != atomTargets) {
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Abort */
|
|
|
|
fAbort = TRUE;
|
|
|
|
goto winClipboardFlushXEvents_SelectionRequest_Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle targets type of request */
|
2018-06-30 17:00:16 +02:00
|
|
|
if (selection_request->target == atomTargets) {
|
|
|
|
xcb_atom_t atomTargetArr[] =
|
|
|
|
{
|
|
|
|
atomTargets,
|
|
|
|
atomUTF8String,
|
|
|
|
XCB_ATOM_STRING,
|
|
|
|
// atomCompoundText, not implemented (yet?)
|
|
|
|
};
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
/* Try to change the property */
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_void_cookie_t cookie = xcb_change_property_checked(conn,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
selection_request->requestor,
|
|
|
|
selection_request->property,
|
|
|
|
XCB_ATOM_ATOM,
|
2012-03-21 20:55:09 +01:00
|
|
|
32,
|
2018-06-30 17:00:16 +02:00
|
|
|
ARRAY_SIZE(atomTargetArr),
|
|
|
|
(unsigned char *) atomTargetArr);
|
|
|
|
xcb_generic_error_t *error;
|
|
|
|
if ((error = xcb_request_check(conn, cookie))) {
|
2012-03-21 20:55:09 +01:00
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionRequest - "
|
2018-06-30 17:00:16 +02:00
|
|
|
"xcb_change_property failed");
|
|
|
|
free(error);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup selection notify xevent */
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_selection_notify_event_t eventSelection;
|
|
|
|
eventSelection.response_type = XCB_SELECTION_NOTIFY;
|
|
|
|
eventSelection.requestor = selection_request->requestor;
|
|
|
|
eventSelection.selection = selection_request->selection;
|
|
|
|
eventSelection.target = selection_request->target;
|
|
|
|
eventSelection.property = selection_request->property;
|
|
|
|
eventSelection.time = selection_request->time;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify the requesting window that
|
|
|
|
* the operation has completed
|
|
|
|
*/
|
2018-06-30 17:00:16 +02:00
|
|
|
cookie = xcb_send_event_checked(conn, FALSE,
|
|
|
|
eventSelection.requestor,
|
|
|
|
0, (char *) &eventSelection);
|
|
|
|
if ((error = xcb_request_check(conn, cookie))) {
|
2012-03-21 20:55:09 +01:00
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionRequest - "
|
2018-06-30 17:00:16 +02:00
|
|
|
"xcb_send_event() failed\n");
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-24 16:32:26 +01:00
|
|
|
/* Close clipboard if we have it open already */
|
|
|
|
if (GetOpenClipboardWindow() == hwnd) {
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Access the clipboard */
|
|
|
|
if (!OpenClipboard(hwnd)) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionRequest - "
|
2015-02-06 20:46:45 +01:00
|
|
|
"OpenClipboard () failed: %08x\n", (unsigned int)GetLastError());
|
2012-02-24 16:32:26 +01:00
|
|
|
|
|
|
|
/* Abort */
|
|
|
|
fAbort = TRUE;
|
|
|
|
goto winClipboardFlushXEvents_SelectionRequest_Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Indicate that clipboard was opened */
|
|
|
|
fCloseClipboard = TRUE;
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Check that clipboard format is available */
|
2018-07-01 13:11:19 +02:00
|
|
|
if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) {
|
2012-03-21 20:55:09 +01:00
|
|
|
static int count; /* Hack to stop acroread spamming the log */
|
|
|
|
static HWND lasthwnd; /* I've not seen any other client get here repeatedly? */
|
|
|
|
|
|
|
|
if (hwnd != lasthwnd)
|
|
|
|
count = 0;
|
|
|
|
count++;
|
|
|
|
if (count < 6)
|
|
|
|
ErrorF("winClipboardFlushXEvents - CF_UNICODETEXT is not "
|
|
|
|
"available from Win32 clipboard. Aborting %d.\n",
|
|
|
|
count);
|
|
|
|
lasthwnd = hwnd;
|
|
|
|
|
|
|
|
/* Abort */
|
|
|
|
fAbort = TRUE;
|
|
|
|
goto winClipboardFlushXEvents_SelectionRequest_Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a pointer to the clipboard text, in desired format */
|
2018-07-01 13:11:19 +02:00
|
|
|
/* Retrieve clipboard data */
|
|
|
|
hGlobal = GetClipboardData(CF_UNICODETEXT);
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (!hGlobal) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionRequest - "
|
2015-02-06 20:46:45 +01:00
|
|
|
"GetClipboardData () failed: %08x\n", (unsigned int)GetLastError());
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
/* Abort */
|
|
|
|
fAbort = TRUE;
|
|
|
|
goto winClipboardFlushXEvents_SelectionRequest_Done;
|
|
|
|
}
|
|
|
|
pszGlobalData = (char *) GlobalLock(hGlobal);
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
/* Convert to target string style */
|
|
|
|
if (selection_request->target == XCB_ATOM_STRING) {
|
|
|
|
codepage = CP_ISO_8559_1; // code page identifier for iso-8559-1
|
|
|
|
} else if (selection_request->target == atomUTF8String) {
|
|
|
|
codepage = CP_UTF8; // code page identifier for utf8
|
|
|
|
} else if (selection_request->target == atomCompoundText) {
|
|
|
|
// COMPOUND_TEXT is complex, not (yet) implemented
|
|
|
|
pszGlobalData = "COMPOUND_TEXT not implemented";
|
|
|
|
codepage = CP_UTF8; // code page identifier for utf8
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert the UTF16 string to required encoding */
|
|
|
|
int iConvertDataLen = WideCharToMultiByte(codepage, 0,
|
|
|
|
(LPCWSTR) pszGlobalData, -1,
|
|
|
|
NULL, 0, NULL, NULL);
|
2018-07-01 13:11:19 +02:00
|
|
|
/* NOTE: iConvertDataLen includes space for null terminator */
|
|
|
|
pszConvertData = malloc(iConvertDataLen);
|
2018-06-30 17:00:16 +02:00
|
|
|
WideCharToMultiByte(codepage, 0,
|
|
|
|
(LPCWSTR) pszGlobalData, -1,
|
|
|
|
pszConvertData, iConvertDataLen, NULL, NULL);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
/* Convert DOS string to UNIX string */
|
|
|
|
winClipboardDOStoUNIX(pszConvertData, strlen(pszConvertData));
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
xtpText_value = strdup(pszConvertData);
|
|
|
|
xtpText_nitems = strlen(pszConvertData);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
/* data will fit into a single X request? (INCR not yet supported) */
|
2015-11-19 19:06:28 +01:00
|
|
|
{
|
2018-06-30 17:00:16 +02:00
|
|
|
uint32_t maxreqsize = xcb_get_maximum_request_length(conn);
|
2015-11-19 19:06:28 +01:00
|
|
|
|
|
|
|
/* covert to bytes and allow for allow for X_ChangeProperty request */
|
|
|
|
maxreqsize = maxreqsize*4 - 24;
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
if (xtpText_nitems > maxreqsize) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - clipboard data size %d greater than maximum %u\n", xtpText_nitems, maxreqsize);
|
2015-11-19 19:06:28 +01:00
|
|
|
|
|
|
|
/* Abort */
|
|
|
|
fAbort = TRUE;
|
|
|
|
goto winClipboardFlushXEvents_SelectionRequest_Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Copy the clipboard text to the requesting window */
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_void_cookie_t cookie = xcb_change_property_checked(conn,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
selection_request->requestor,
|
|
|
|
selection_request->property,
|
|
|
|
selection_request->target,
|
2012-03-21 20:55:09 +01:00
|
|
|
8,
|
2018-06-30 17:00:16 +02:00
|
|
|
xtpText_nitems, xtpText_value);
|
|
|
|
xcb_generic_error_t *error;
|
|
|
|
if ((error = xcb_request_check(conn, cookie))) {
|
2012-03-21 20:55:09 +01:00
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionRequest - "
|
2018-06-30 17:00:16 +02:00
|
|
|
"xcb_change_property failed\n");
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
/* Abort */
|
|
|
|
fAbort = TRUE;
|
|
|
|
goto winClipboardFlushXEvents_SelectionRequest_Done;
|
|
|
|
}
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
/* Free the converted string */
|
|
|
|
free(pszConvertData);
|
|
|
|
pszConvertData = NULL;
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
/* Release the clipboard data */
|
|
|
|
GlobalUnlock(hGlobal);
|
|
|
|
pszGlobalData = NULL;
|
|
|
|
fCloseClipboard = FALSE;
|
|
|
|
CloseClipboard();
|
|
|
|
|
|
|
|
/* Clean up */
|
2018-06-30 17:00:16 +02:00
|
|
|
free(xtpText_value);
|
|
|
|
xtpText_value = NULL;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
/* Setup selection notify event */
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_selection_notify_event_t eventSelection;
|
|
|
|
eventSelection.response_type = XCB_SELECTION_NOTIFY;
|
|
|
|
eventSelection.requestor = selection_request->requestor;
|
|
|
|
eventSelection.selection = selection_request->selection;
|
|
|
|
eventSelection.target = selection_request->target;
|
|
|
|
eventSelection.property = selection_request->property;
|
|
|
|
eventSelection.time = selection_request->time;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
/* Notify the requesting window that the operation has completed */
|
2018-06-30 17:00:16 +02:00
|
|
|
cookie = xcb_send_event_checked(conn, FALSE,
|
|
|
|
eventSelection.requestor,
|
|
|
|
0, (char *) &eventSelection);
|
|
|
|
if ((error = xcb_request_check(conn, cookie))) {
|
2012-03-21 20:55:09 +01:00
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionRequest - "
|
2018-06-30 17:00:16 +02:00
|
|
|
"xcb_send_event() failed\n");
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
/* Abort */
|
|
|
|
fAbort = TRUE;
|
|
|
|
goto winClipboardFlushXEvents_SelectionRequest_Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
winClipboardFlushXEvents_SelectionRequest_Done:
|
|
|
|
/* Free allocated resources */
|
2018-06-30 17:00:16 +02:00
|
|
|
if (xtpText_value) {
|
|
|
|
free(xtpText_value);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
2018-06-30 17:00:16 +02:00
|
|
|
if (pszConvertData)
|
|
|
|
free(pszConvertData);
|
2012-03-21 20:55:09 +01:00
|
|
|
if (hGlobal && pszGlobalData)
|
|
|
|
GlobalUnlock(hGlobal);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a SelectionNotify event to the requesting
|
|
|
|
* client when we abort.
|
|
|
|
*/
|
|
|
|
if (fAbort) {
|
|
|
|
/* Setup selection notify event */
|
2018-06-30 17:00:16 +02:00
|
|
|
eventSelection.response_type = XCB_SELECTION_NOTIFY;
|
|
|
|
eventSelection.requestor = selection_request->requestor;
|
|
|
|
eventSelection.selection = selection_request->selection;
|
|
|
|
eventSelection.target = selection_request->target;
|
|
|
|
eventSelection.property = XCB_NONE;
|
|
|
|
eventSelection.time = selection_request->time;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
/* Notify the requesting window that the operation is complete */
|
2018-06-30 17:00:16 +02:00
|
|
|
cookie = xcb_send_event_checked(conn, FALSE,
|
|
|
|
eventSelection.requestor,
|
|
|
|
0, (char *) &eventSelection);
|
|
|
|
if ((error = xcb_request_check(conn, cookie))) {
|
2012-03-21 20:55:09 +01:00
|
|
|
/*
|
|
|
|
* Should not be a problem if XSendEvent fails because
|
|
|
|
* the client may simply have exited.
|
|
|
|
*/
|
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionRequest - "
|
2018-06-30 17:00:16 +02:00
|
|
|
"xcb_send_event() failed for abort event.\n");
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close clipboard if it was opened */
|
|
|
|
if (fCloseClipboard) {
|
|
|
|
fCloseClipboard = FALSE;
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
break;
|
2018-06-30 17:00:16 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
case XCB_SELECTION_NOTIFY:
|
|
|
|
{
|
|
|
|
xcb_selection_notify_event_t *selection_notify = (xcb_selection_notify_event_t *)event;
|
2012-03-21 20:55:09 +01:00
|
|
|
winDebug("winClipboardFlushXEvents - SelectionNotify\n");
|
|
|
|
{
|
|
|
|
char *pszAtomName;
|
2018-06-30 17:00:16 +02:00
|
|
|
pszAtomName = get_atom_name(conn, selection_notify->selection);
|
|
|
|
winDebug("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n", pszAtomName);
|
|
|
|
free(pszAtomName);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-06-30 17:00:16 +02:00
|
|
|
SelectionNotify with property of XCB_NONE indicates either:
|
2012-03-21 20:55:09 +01:00
|
|
|
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
(i) Generated by the X server if no owner for the specified selection exists
|
|
|
|
(perhaps it's disappeared on us mid-transaction), or
|
|
|
|
(ii) Sent by the selection owner when the requested selection conversion could
|
|
|
|
not be performed or server errors prevented the conversion data being returned
|
|
|
|
*/
|
2018-06-30 17:00:16 +02:00
|
|
|
if (selection_notify->property == XCB_NONE) {
|
2012-03-21 20:55:09 +01:00
|
|
|
ErrorF("winClipboardFlushXEvents - SelectionNotify - "
|
2018-06-30 17:00:16 +02:00
|
|
|
"Conversion to format %d refused.\n",
|
|
|
|
selection_notify->target);
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
return WIN_XEVENTS_FAILED;
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
if (selection_notify->target == atomTargets) {
|
|
|
|
return winClipboardSelectionNotifyTargets(hwnd, iWindow, conn, data, atoms);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
return winClipboardSelectionNotifyData(hwnd, iWindow, conn, data, atoms);
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
case XCB_SELECTION_CLEAR:
|
2012-03-21 20:55:09 +01:00
|
|
|
winDebug("SelectionClear - doing nothing\n");
|
|
|
|
break;
|
2009-11-01 19:18:51 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
case XCB_PROPERTY_NOTIFY:
|
|
|
|
{
|
|
|
|
xcb_property_notify_event_t *property_notify = (xcb_property_notify_event_t *)event;
|
|
|
|
|
2015-11-18 22:27:23 +01:00
|
|
|
/* If INCR is in progress, collect the data */
|
|
|
|
if (data->incr &&
|
2018-06-30 17:00:16 +02:00
|
|
|
(property_notify->atom == atoms->atomLocalProperty) &&
|
|
|
|
(property_notify->state == XCB_PROPERTY_NEW_VALUE))
|
|
|
|
return winClipboardSelectionNotifyData(hwnd, iWindow, conn, data, atoms);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2015-11-18 22:27:23 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
case XCB_MAPPING_NOTIFY:
|
2012-03-21 20:55:09 +01:00
|
|
|
break;
|
2009-11-01 19:18:51 +01:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
case 0:
|
|
|
|
/* This is just laziness rather than making sure we used _checked everywhere */
|
|
|
|
{
|
|
|
|
xcb_generic_error_t *err = (xcb_generic_error_t *)event;
|
|
|
|
ErrorF("winClipboardFlushXEvents - Error code: %i, ID: 0x%08x, "
|
|
|
|
"Major opcode: %i, Minor opcode: %i\n",
|
|
|
|
err->error_code, err->resource_id,
|
|
|
|
err->major_code, err->minor_code);
|
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
break;
|
2010-04-02 00:10:58 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
default:
|
2018-06-30 17:00:16 +02:00
|
|
|
if ((event->response_type & ~0x80) == XCB_XFIXES_SELECTION_EVENT_SET_SELECTION_OWNER + xfixes_event_base) {
|
|
|
|
xcb_xfixes_selection_notify_event_t *e = (xcb_xfixes_selection_notify_event_t *)event;
|
2012-02-13 20:58:37 +01:00
|
|
|
winDebug("winClipboardFlushXEvents - XFixesSetSelectionOwnerNotify\n");
|
|
|
|
|
|
|
|
/* Save selection owners for monitored selections, ignore other selections */
|
2018-06-30 17:00:16 +02:00
|
|
|
if ((e->selection == XCB_ATOM_PRIMARY) && fPrimarySelection) {
|
2012-02-13 20:58:37 +01:00
|
|
|
MonitorSelection(e, CLIP_OWN_PRIMARY);
|
|
|
|
}
|
|
|
|
else if (e->selection == atomClipboard) {
|
|
|
|
MonitorSelection(e, CLIP_OWN_CLIPBOARD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Selection is being disowned */
|
2018-06-30 17:00:16 +02:00
|
|
|
if (e->owner == XCB_NONE) {
|
|
|
|
winDebug("winClipboardFlushXEvents - No window, returning.\n");
|
2012-02-13 20:58:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
XXX: there are all kinds of wacky edge cases we might need here:
|
|
|
|
- we own windows clipboard, but neither PRIMARY nor CLIPBOARD have an owner, so we should disown it?
|
|
|
|
- root window is taking ownership?
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* If we are the owner of the most recently owned selection, don't go all recursive :) */
|
|
|
|
if ((lastOwnedSelectionIndex != CLIP_OWN_NONE) &&
|
|
|
|
(s_iOwners[lastOwnedSelectionIndex] == iWindow)) {
|
|
|
|
winDebug("winClipboardFlushXEvents - Ownership changed to us, aborting.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close clipboard if we have it open already (possible? correct??) */
|
|
|
|
if (GetOpenClipboardWindow() == hwnd) {
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Access the Windows clipboard */
|
|
|
|
if (!OpenClipboard(hwnd)) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - OpenClipboard () failed: %08x\n",
|
|
|
|
(int) GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Take ownership of the Windows clipboard */
|
|
|
|
if (!EmptyClipboard()) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - EmptyClipboard () failed: %08x\n",
|
|
|
|
(int) GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Advertise regular text and unicode */
|
|
|
|
SetClipboardData(CF_UNICODETEXT, NULL);
|
|
|
|
SetClipboardData(CF_TEXT, NULL);
|
|
|
|
|
|
|
|
/* Release the clipboard */
|
|
|
|
if (!CloseClipboard()) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - CloseClipboard () failed: %08x\n",
|
|
|
|
(int) GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-30 17:00:16 +02:00
|
|
|
/* XCB_XFIXES_SELECTION_EVENT_SELECTION_WINDOW_DESTROY */
|
|
|
|
/* XCB_XFIXES_SELECTION_EVENT_SELECTION_CLIENT_CLOSE */
|
2012-02-13 20:58:37 +01:00
|
|
|
else {
|
|
|
|
ErrorF("winClipboardFlushXEvents - unexpected event type %d\n",
|
2018-06-30 17:00:16 +02:00
|
|
|
event->response_type);
|
2012-02-13 20:58:37 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-06-30 17:00:16 +02:00
|
|
|
|
|
|
|
/* I/O errors etc. */
|
|
|
|
{
|
|
|
|
int e = xcb_connection_has_error(conn);
|
|
|
|
if (e) {
|
|
|
|
ErrorF("winClipboardFlushXEvents - Fatal error %d on xcb connection\n", e);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
return WIN_XEVENTS_SUCCESS;
|
2018-06-30 17:00:16 +02:00
|
|
|
|
2003-11-14 17:48:57 +01:00
|
|
|
}
|