diff options
Diffstat (limited to 'xorg-server/hw/xwin/winclipboard/xevents.c')
-rwxr-xr-x[-rw-r--r--] | xorg-server/hw/xwin/winclipboard/xevents.c | 285 |
1 files changed, 85 insertions, 200 deletions
diff --git a/xorg-server/hw/xwin/winclipboard/xevents.c b/xorg-server/hw/xwin/winclipboard/xevents.c index d0077b846..cfbf0121e 100644..100755 --- a/xorg-server/hw/xwin/winclipboard/xevents.c +++ b/xorg-server/hw/xwin/winclipboard/xevents.c @@ -33,104 +33,13 @@ #ifdef HAVE_XWIN_CONFIG_H #include <xwin-config.h> #endif - -/* - * Including any server header might define the macro _XSERVER64 on 64 bit machines. - * That macro must _NOT_ be defined for Xlib client code, otherwise bad things happen. - * So let's undef that macro if necessary. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif - +#include "winclipboard.h" +#include "misc.h" +#include "winmsg.h" #include "internal.h" -#include <X11/Xutil.h> -#include <X11/Xatom.h> -#include <X11/extensions/Xfixes.h> - -/* - * Constants - */ - -#define CLIP_NUM_SELECTIONS 2 -#define CLIP_OWN_NONE -1 -#define CLIP_OWN_PRIMARY 0 -#define CLIP_OWN_CLIPBOARD 1 - -/* - * Global variables - */ +#include <unistd.h> -extern int xfixes_event_base; - -/* - * Local variables - */ - -static Window s_iOwners[CLIP_NUM_SELECTIONS] = { None, None }; -static const char *szSelectionNames[CLIP_NUM_SELECTIONS] = - { "PRIMARY", "CLIPBOARD" }; - -static unsigned int lastOwnedSelectionIndex = CLIP_OWN_NONE; - -static void -MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i) -{ - /* Look for owned -> not owned transition */ - if (None == e->owner && None != s_iOwners[i]) { - 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; - if (None != s_iOwners[other_index]) - lastOwnedSelectionIndex = other_index; - else - lastOwnedSelectionIndex = CLIP_OWN_NONE; - } - - /* Save last owned selection */ - if (None != e->owner) { - lastOwnedSelectionIndex = i; - } - - /* Save new selection owner or None */ - s_iOwners[i] = e->owner; - winDebug("MonitorSelection - %s - Now owned by XID %x\n", - szSelectionNames[i], e->owner); -} - -Atom -winClipboardGetLastOwnedSelectionAtom(ClipboardAtoms *atoms) -{ - if (lastOwnedSelectionIndex == CLIP_OWN_NONE) - return None; - - if (lastOwnedSelectionIndex == CLIP_OWN_PRIMARY) - return XA_PRIMARY; - - if (lastOwnedSelectionIndex == CLIP_OWN_CLIPBOARD) - return atoms->atomClipboard; - - return None; -} - - -void -winClipboardInitMonitoredSelections(void) -{ - /* Initialize static variables */ - for (int i = 0; i < CLIP_NUM_SELECTIONS; ++i) - s_iOwners[i] = None; - - lastOwnedSelectionIndex = CLIP_OWN_NONE; -} +extern Bool g_fClipboardPrimary; /* * Process any pending X events @@ -138,13 +47,21 @@ winClipboardInitMonitoredSelections(void) int winClipboardFlushXEvents(HWND hwnd, - Window iWindow, Display * pDisplay, Bool fUseUnicode, ClipboardAtoms *atoms) + int iWindow, Display * pDisplay, Bool fUseUnicode, Bool ClipboardOpened) { - Atom atomClipboard = atoms->atomClipboard; - Atom atomLocalProperty = atoms->atomLocalProperty; - Atom atomUTF8String = atoms->atomUTF8String; - Atom atomCompoundText = atoms->atomCompoundText; - Atom atomTargets = atoms->atomTargets; + static Atom atomLocalProperty; + static Atom atomCompoundText; + static Atom atomUTF8String; + static Atom atomTargets; + static int generation; + + if (generation != serverGeneration) { + generation = serverGeneration; + atomLocalProperty = XInternAtom(pDisplay, WIN_LOCAL_PROPERTY, False); + atomUTF8String = XInternAtom(pDisplay, "UTF8_STRING", False); + atomCompoundText = XInternAtom(pDisplay, "COMPOUND_TEXT", False); + atomTargets = XInternAtom(pDisplay, "TARGETS", False); + } /* Process all pending events */ while (XPending(pDisplay)) { @@ -165,6 +82,7 @@ winClipboardFlushXEvents(HWND hwnd, wchar_t *pwszUnicodeStr = NULL; int iUnicodeLen = 0; int iReturnDataLen = 0; + int i; Bool fAbort = FALSE; Bool fCloseClipboard = FALSE; Bool fSetClipboardData = TRUE; @@ -172,6 +90,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) { /* @@ -179,6 +99,7 @@ winClipboardFlushXEvents(HWND hwnd, */ case SelectionRequest: +#ifdef _DEBUG { char *pszAtomName = NULL; @@ -190,7 +111,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 @@ -252,24 +176,24 @@ winClipboardFlushXEvents(HWND hwnd, break; } - /* 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()); + /* Access the clipboard */ + 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; } - /* Indicate that clipboard was opened */ - fCloseClipboard = TRUE; - /* Check that clipboard format is available */ if (fUseUnicode && !IsClipboardFormatAvailable(CF_UNICODETEXT)) { static int count; /* Hack to stop acroread spamming the log */ @@ -319,7 +243,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 */ @@ -407,9 +340,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; @@ -488,9 +423,8 @@ winClipboardFlushXEvents(HWND hwnd, /* * SelectionNotify */ - case SelectionNotify: - +#ifdef _DEBUG winDebug("winClipboardFlushXEvents - SelectionNotify\n"); { char *pszAtomName; @@ -501,8 +435,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. @@ -585,6 +522,7 @@ winClipboardFlushXEvents(HWND hwnd, break; } +#ifdef WINDBG { char *pszAtomName = NULL; @@ -595,6 +533,7 @@ winClipboardFlushXEvents(HWND hwnd, XFree(pszAtomName); pszAtomName = NULL; } +#endif if (fUseUnicode) { #ifdef X_HAVE_UTF8_STRING @@ -612,13 +551,11 @@ winClipboardFlushXEvents(HWND hwnd, if (iReturn == Success || iReturn > 0) { /* Conversion succeeded or some unconvertible characters */ if (ppszTextList != NULL) { - int i; - iReturnDataLen = 0; 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]); @@ -627,7 +564,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'; } } @@ -648,7 +585,7 @@ winClipboardFlushXEvents(HWND hwnd, ErrorF("%d\n", iReturn); break; } - pszReturnData = malloc(1); + pszReturnData = (char *) malloc(1); pszReturnData[0] = '\0'; } @@ -661,7 +598,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 */ @@ -771,89 +708,37 @@ 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: - if (event.type == XFixesSetSelectionOwnerNotify + xfixes_event_base) { - XFixesSelectionNotifyEvent *e = - (XFixesSelectionNotifyEvent *) & event; - - winDebug("winClipboardFlushXEvents - XFixesSetSelectionOwnerNotify\n"); - - /* Save selection owners for monitored selections, ignore other selections */ - if (e->selection == XA_PRIMARY) { - MonitorSelection(e, CLIP_OWN_PRIMARY); - } - else if (e->selection == atomClipboard) { - MonitorSelection(e, CLIP_OWN_CLIPBOARD); - } - else - break; - - /* Selection is being disowned */ - if (e->owner == None) { - winDebug - ("winClipboardFlushXEvents - No window, returning.\n"); - 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; - } - } - /* XFixesSelectionWindowDestroyNotifyMask */ - /* XFixesSelectionClientCloseNotifyMask */ - else { - ErrorF("winClipboardFlushXEvents - unexpected event type %d\n", - event.type); - } + ErrorF("winClipboardFlushXEvents - unexpected event type %d\n", + event.type); break; } } |