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 ce533c59f..910e437c2 100644
--- a/xorg-server/hw/xwin/winclipboardxevents.c
+++ b/xorg-server/hw/xwin/winclipboardxevents.c
@@ -35,14 +35,16 @@
#endif
#include "winclipboard.h"
#include "misc.h"
-
+#include "winmsg.h"
+#include <unistd.h>
/*
+extern Bool g_fClipboardPrimary;
* Process any pending X events
*/
int
winClipboardFlushXEvents(HWND hwnd,
- int iWindow, Display * pDisplay, Bool fUseUnicode)
+ int iWindow, Display * pDisplay, Bool fUseUnicode, Bool ClipboardOpened)
{
static Atom atomLocalProperty;
static Atom atomCompoundText;
@@ -85,6 +87,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) {
/*
@@ -92,6 +96,7 @@ winClipboardFlushXEvents(HWND hwnd,
*/
case SelectionRequest:
+#ifdef _DEBUG
{
char *pszAtomName = NULL;
@@ -103,7 +108,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
@@ -192,24 +200,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;
@@ -232,7 +239,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 */
@@ -320,9 +336,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;
@@ -401,9 +419,8 @@ winClipboardFlushXEvents(HWND hwnd,
/*
* SelectionNotify
*/
-
case SelectionNotify:
-
+#ifdef _DEBUG
winDebug("winClipboardFlushXEvents - SelectionNotify\n");
{
char *pszAtomName;
@@ -414,8 +431,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.
@@ -498,6 +518,7 @@ winClipboardFlushXEvents(HWND hwnd,
break;
}
+#ifdef WINDBG
{
char *pszAtomName = NULL;
@@ -508,6 +529,7 @@ winClipboardFlushXEvents(HWND hwnd,
XFree(pszAtomName);
pszAtomName = NULL;
}
+#endif
if (fUseUnicode) {
#ifdef X_HAVE_UTF8_STRING
@@ -529,7 +551,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]);
@@ -538,7 +560,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';
}
}
@@ -559,7 +581,7 @@ winClipboardFlushXEvents(HWND hwnd,
ErrorF("%d\n", iReturn);
break;
}
- pszReturnData = malloc(1);
+ pszReturnData = (char *) malloc(1);
pszReturnData[0] = '\0';
}
@@ -572,7 +594,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 */
@@ -683,14 +705,32 @@ winClipboardFlushXEvents(HWND hwnd,
}
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: