aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xwin/winclipboardxevents.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/hw/xwin/winclipboardxevents.c')
-rw-r--r--xorg-server/hw/xwin/winclipboardxevents.c102
1 files changed, 71 insertions, 31 deletions
diff --git a/xorg-server/hw/xwin/winclipboardxevents.c b/xorg-server/hw/xwin/winclipboardxevents.c
index 59b1f0715..2be03b707 100644
--- a/xorg-server/hw/xwin/winclipboardxevents.c
+++ b/xorg-server/hw/xwin/winclipboardxevents.c
@@ -35,12 +35,14 @@
#endif
#include "winclipboard.h"
#include "misc.h"
-
+#include "winmsg.h"
+#include <unistd.h>
/*
* References to external symbols
*/
extern Bool g_fUnicodeSupport;
+extern Bool g_fClipboardPrimary;
/*
* Process any pending X events
@@ -48,7 +50,7 @@ extern Bool g_fUnicodeSupport;
int
winClipboardFlushXEvents(HWND hwnd,
- int iWindow, Display * pDisplay, Bool fUseUnicode)
+ int iWindow, Display * pDisplay, Bool fUseUnicode, Bool ClipboardOpened)
{
static Atom atomLocalProperty;
static Atom atomCompoundText;
@@ -91,6 +93,8 @@ winClipboardFlushXEvents(HWND hwnd,
/* Get the next event - will not block because one is ready */
XNextEvent(pDisplay, &event);
+ winDebug ("Received event type %d\n",event.type);
+
/* Branch on the event type */
switch (event.type) {
/*
@@ -98,6 +102,7 @@ winClipboardFlushXEvents(HWND hwnd,
*/
case SelectionRequest:
+#ifdef _DEBUG
{
char *pszAtomName = NULL;
@@ -109,7 +114,10 @@ winClipboardFlushXEvents(HWND hwnd,
winDebug("SelectionRequest - Target atom name %s\n", pszAtomName);
XFree(pszAtomName);
pszAtomName = NULL;
+ winDebug ("SelectionRequest - owner %d\n", event.xselectionrequest.owner);
+ winDebug ("SelectionRequest - requestor %d\n", event.xselectionrequest.requestor);
}
+#endif
/* Abort if invalid target type */
if (event.xselectionrequest.target != XA_STRING
@@ -198,24 +206,23 @@ winClipboardFlushXEvents(HWND hwnd,
goto winClipboardFlushXEvents_SelectionRequest_Done;
}
- /* Close clipboard if we have it open already */
- if (GetOpenClipboardWindow() == hwnd) {
- CloseClipboard();
- }
-
/* Access the clipboard */
- if (!OpenClipboard(hwnd)) {
- ErrorF("winClipboardFlushXEvents - SelectionRequest - "
- "OpenClipboard () failed: %08lx\n", GetLastError());
-
- /* Abort */
- fAbort = TRUE;
- goto winClipboardFlushXEvents_SelectionRequest_Done;
- }
-
- /* Indicate that clipboard was opened */
- fCloseClipboard = TRUE;
-
+ if (!ClipboardOpened)
+ {
+ if (!OpenClipboard (hwnd))
+ {
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
+ "OpenClipboard () failed: %08lx\n",
+ GetLastError ());
+
+ /* Abort */
+ fAbort = TRUE;
+ goto winClipboardFlushXEvents_SelectionRequest_Done;
+ }
+
+ /* Indicate that clipboard was opened */
+ fCloseClipboard = TRUE;
+ }
/* Setup the string style */
if (event.xselectionrequest.target == XA_STRING)
xiccesStyle = XStringStyle;
@@ -242,7 +249,16 @@ winClipboardFlushXEvents(HWND hwnd,
hGlobal = GetClipboardData(CF_TEXT);
}
if (!hGlobal) {
- ErrorF("winClipboardFlushXEvents - SelectionRequest - "
+ if (GetLastError()==ERROR_CLIPBOARD_NOT_OPEN && ClipboardOpened)
+ {
+ ErrorF("We should not have received a SelectionRequest????\n"
+ "The owner is the clipboard, but in reality it was"
+ "an X window\n");
+ /* Set the owner to None */
+ if (g_fClipboardPrimary) XSetSelectionOwner (pDisplay, XA_PRIMARY, None, CurrentTime);
+ XSetSelectionOwner (pDisplay, XInternAtom (pDisplay, "CLIPBOARD", False), None, CurrentTime);
+ }
+ ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
"GetClipboardData () failed: %08lx\n", GetLastError());
/* Abort */
@@ -330,9 +346,11 @@ winClipboardFlushXEvents(HWND hwnd,
/* Release the clipboard data */
GlobalUnlock(hGlobal);
pszGlobalData = NULL;
- fCloseClipboard = FALSE;
- CloseClipboard();
-
+ if (fCloseClipboard)
+ {
+ fCloseClipboard = FALSE;
+ CloseClipboard ();
+ }
/* Clean up */
XFree(xtpText.value);
xtpText.value = NULL;
@@ -411,9 +429,8 @@ winClipboardFlushXEvents(HWND hwnd,
/*
* SelectionNotify
*/
-
case SelectionNotify:
-
+#ifdef _DEBUG
winDebug("winClipboardFlushXEvents - SelectionNotify\n");
{
char *pszAtomName;
@@ -424,8 +441,11 @@ winClipboardFlushXEvents(HWND hwnd,
winDebug
("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n",
pszAtomName);
+ winDebug ("SelectionNotify - requestor %d\n", event.xselectionrequest.requestor);
XFree(pszAtomName);
}
+#endif
+
/*
* Request conversion of UTF8 and CompoundText targets.
@@ -508,6 +528,7 @@ winClipboardFlushXEvents(HWND hwnd,
break;
}
+#ifdef WINDBG
{
char *pszAtomName = NULL;
@@ -518,6 +539,7 @@ winClipboardFlushXEvents(HWND hwnd,
XFree(pszAtomName);
pszAtomName = NULL;
}
+#endif
if (fUseUnicode) {
#ifdef X_HAVE_UTF8_STRING
@@ -539,7 +561,7 @@ winClipboardFlushXEvents(HWND hwnd,
for (i = 0; i < iCount; i++) {
iReturnDataLen += strlen(ppszTextList[i]);
}
- pszReturnData = malloc(iReturnDataLen + 1);
+ pszReturnData = (char *) malloc(iReturnDataLen + 1);
pszReturnData[0] = '\0';
for (i = 0; i < iCount; i++) {
strcat(pszReturnData, ppszTextList[i]);
@@ -548,7 +570,7 @@ winClipboardFlushXEvents(HWND hwnd,
else {
ErrorF("winClipboardFlushXEvents - SelectionNotify - "
"X*TextPropertyToTextList list_return is NULL.\n");
- pszReturnData = malloc(1);
+ pszReturnData = (char *) malloc(1);
pszReturnData[0] = '\0';
}
}
@@ -569,7 +591,7 @@ winClipboardFlushXEvents(HWND hwnd,
ErrorF("%d\n", iReturn);
break;
}
- pszReturnData = malloc(1);
+ pszReturnData = (char *) malloc(1);
pszReturnData[0] = '\0';
}
@@ -582,7 +604,7 @@ winClipboardFlushXEvents(HWND hwnd,
xtpText.nitems = 0;
/* Convert the X clipboard string to DOS format */
- winClipboardUNIXtoDOS(&pszReturnData, strlen(pszReturnData));
+ winClipboardUNIXtoDOS((unsigned char **)&pszReturnData, strlen(pszReturnData));
if (fUseUnicode) {
/* Find out how much space needed to convert MBCS to Unicode */
@@ -693,14 +715,32 @@ winClipboardFlushXEvents(HWND hwnd,
SetClipboardData(CF_TEXT, NULL);
return WIN_XEVENTS_NOTIFY;
- case SelectionClear:
+ /*
+ * SelectionClear
+ */
+ case SelectionClear:
+#ifdef _DEBUG
winDebug("SelectionClear - doing nothing\n");
+ {
+ char *pszAtomName;
+
+ pszAtomName = XGetAtomName (pDisplay,
+ event.xselection.selection);
+
+ winDebug ("SelectionClear - ATOM: %s\n",
+ pszAtomName);
+ winDebug ("SelectionClear - owner %d\n", event.xselectionrequest.owner);
+
+ XFree (pszAtomName);
+ }
+#endif
break;
case PropertyNotify:
break;
-
+
case MappingNotify:
+ XRefreshKeyboardMapping((XMappingEvent *)&event);
break;
default: