diff options
Diffstat (limited to 'xorg-server/hw/xwin/winclipboardwndproc.c')
-rw-r--r-- | xorg-server/hw/xwin/winclipboardwndproc.c | 78 |
1 files changed, 18 insertions, 60 deletions
diff --git a/xorg-server/hw/xwin/winclipboardwndproc.c b/xorg-server/hw/xwin/winclipboardwndproc.c index 802a74035..0518e25dd 100644 --- a/xorg-server/hw/xwin/winclipboardwndproc.c +++ b/xorg-server/hw/xwin/winclipboardwndproc.c @@ -1,5 +1,6 @@ /* *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. + *Copyright (C) Colin Harrison 2005-2008 * *Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -20,12 +21,13 @@ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - *Except as contained in this notice, the name of Harold L Hunt II - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from Harold L Hunt II. + *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). * * Authors: Harold L Hunt II + * Colin Harrison */ #ifdef HAVE_XWIN_CONFIG_H @@ -63,7 +65,7 @@ extern HWND g_hwndClipboard; * Local function prototypes */ -static Bool +static int winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay, Bool fUseUnicode, int iTimeoutSec); @@ -143,12 +145,6 @@ winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay, * Process a given Windows message */ -/* BPS - Define our own message, which we'll post to ourselves to facilitate - * resetting the delayed rendering mechanism after each paste from X app to - * Windows app. TODO - Perhaps move to win.h with the other WM_USER messages. - */ -#define WM_USER_PASTE_COMPLETE (WM_USER + 1003) - LRESULT CALLBACK winClipboardWindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) @@ -260,12 +256,15 @@ winClipboardWindowProc (HWND hwnd, UINT message, case WM_DRAWCLIPBOARD: { static Bool s_fProcessingDrawClipboard = FALSE; + static Atom atomClipboard; Display *pDisplay = g_pClipboardDisplay; Window iWindow = g_iClipboardWindow; int iReturn; winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n"); + if (atomClipboard == None) atomClipboard = XInternAtom (pDisplay, "CLIPBOARD", False); + /* * We've occasionally seen a loop in the clipboard chain. * Try and fix it on the first hint of recursion. @@ -353,17 +352,13 @@ winClipboardWindowProc (HWND hwnd, UINT message, /* Release CLIPBOARD selection if owned */ iReturn = XGetSelectionOwner (pDisplay, - XInternAtom (pDisplay, - "CLIPBOARD", - False)); + atomClipboard); if (iReturn == g_iClipboardWindow) { winDebug ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " "CLIPBOARD selection is owned by us.\n"); XSetSelectionOwner (pDisplay, - XInternAtom (pDisplay, - "CLIPBOARD", - False), + atomClipboard, None, CurrentTime); } @@ -383,7 +378,8 @@ winClipboardWindowProc (HWND hwnd, UINT message, XA_PRIMARY, iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) + if (iReturn == BadAtom || iReturn == BadWindow || + XGetSelectionOwner (pDisplay, XA_PRIMARY) != iWindow) { winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - " "Could not reassert ownership of PRIMARY\n"); @@ -396,12 +392,12 @@ winClipboardWindowProc (HWND hwnd, UINT message, /* Reassert ownership of the CLIPBOARD */ iReturn = XSetSelectionOwner (pDisplay, - XInternAtom (pDisplay, - "CLIPBOARD", - False), + atomClipboard, iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) + + if (iReturn == BadAtom || iReturn == BadWindow || + XGetSelectionOwner (pDisplay, atomClipboard) != iWindow) { winErrorFVerb (1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - " "Could not reassert ownership of CLIPBOARD\n"); @@ -533,13 +529,6 @@ winClipboardWindowProc (HWND hwnd, UINT message, SetClipboardData (CF_TEXT, NULL); } - /* BPS - Post ourselves a user message whose handler will reset the - * delayed rendering mechanism after the paste is complete. This is - * necessary because calling SetClipboardData() with a NULL argument - * here will cause the data we just put on the clipboard to be lost! - */ - PostMessage(g_hwndClipboard, WM_USER_PASTE_COMPLETE, 0, 0); - /* Special handling for WM_RENDERALLFORMATS */ if (message == WM_RENDERALLFORMATS) { @@ -557,37 +546,6 @@ winClipboardWindowProc (HWND hwnd, UINT message, winDebug ("winClipboardWindowProc - WM_RENDER*FORMAT - Returning.\n"); return 0; } - /* BPS - This WM_USER message is posted by us. It gives us the opportunity - * to reset the delayed rendering mechanism after each and every paste - * from an X app to a Windows app. Without such a mechanism, subsequent - * changes of selection in the X app owning the selection are not - * reflected in pastes into Windows apps, since Windows won't send us the - * WM_RENDERFORMAT message unless someone has set changed data (or NULL) - * on the clipboard. */ - case WM_USER_PASTE_COMPLETE: - { - if (hwnd != GetClipboardOwner ()) - /* In case we've lost the selection since posting the message */ - return 0; - winDebug ("winClipboardWindowProc - WM_USER_PASTE_COMPLETE\n"); - - /* Set up for another delayed rendering callback */ - OpenClipboard (g_hwndClipboard); - - /* Take ownership of the Windows clipboard */ - EmptyClipboard (); - - /* Advertise Unicode if we support it */ - if (g_fUnicodeSupport) - SetClipboardData (CF_UNICODETEXT, NULL); - - /* Always advertise regular text */ - SetClipboardData (CF_TEXT, NULL); - - /* Release the clipboard */ - CloseClipboard (); - } - return 0; } /* Let Windows perform default processing for unhandled messages */ |