Serious flaw in Cygwin X clipboard integration prevents paste from X to Windows apps

Stahlman Family brettstahlman@comcast.net
Wed Jan 25 13:08:00 GMT 2006


> Hi,
> 
> Stahlman Brett wrote:
> > I will try to look into
> > it as I get time over the next few days...
> 
> I can quickly build an experimental Xming.exe with any patch you have in
> mind.
> (Xming shares the same code base as Cygwin/X).
> If proven the patch could then be incorporated into Cygwin/X, at leisure,
> via an XOrg bugzilla.
> 
> 
> Colin Harrison

Colin,
 Here's an experimental patch. It appears to fix the issue I was
having with unix gvim running on Windows. Hopefully, it doesn't break
anything else. I was able to keep all of the changes in a single file:
winclipboardwndproc.c. Included is a unified context diff, performed
from the <...>hw/xwin directory. Let me know if you have any problems
with the format and would like me to send as attachment or in a
different format.

Also, let me know if you aren't sure how to reproduce the problem the
patch is supposed to fix. Basically, any X app that doesn't implement a
workaround (and some probably do) would exhibit the buggy clipboard
behavior with the unpatched X server... For details on the problem,
you can visit the thread

Patch for problems with X11 GUI / XTERM clipboard integration with
native Win applications - was "clipboard support"

on the vim@vim.org mailing list.

Thanks in advance,
 Brett Stahlman




*** winclipboardwndproc.c Wed Jan 25 06:42:50 2006
--- winclipboardwndproc_bps.c Wed Jan 25 06:50:21 2006
***************
*** 49,54 ****
--- 49,56 ----
  extern Window  g_iClipboardWindow;
  extern Atom  g_atomLastOwnedSelection;
  
+ /* BPS - g_hwndClipboard needed for X app->Windows paste fix */
+ extern HWND  g_hwndClipboard;
  
  /* 
   * Local function prototypes
***************
*** 134,139 ****
--- 136,147 ----
   * 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)
***************
*** 527,532 ****
--- 535,547 ----
       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)
     {
***************
*** 544,549 ****
--- 559,609 ----
   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 */
+  if (!OpenClipboard (g_hwndClipboard))
+    {
+      ErrorF ("winClipboardWindowProc - OpenClipboard () failed: %08x\n",
+       (int) GetLastError ());
+    }
+ 
+  /* Take ownership of the Windows clipboard */
+  if (!EmptyClipboard ())
+    {
+      ErrorF ("winClipboardWindowProc - EmptyClipboard () failed: %08x\n",
+       (int) GetLastError ());
+    }
+ 
+  /* Advertise Unicode if we support it */
+  if (g_fUnicodeSupport)
+    SetClipboardData (CF_UNICODETEXT, NULL);
+ 
+  /* Always advertise regular text */
+  SetClipboardData (CF_TEXT, NULL);
+ 
+  /* Release the clipboard */
+  if (!CloseClipboard ())
+    {
+      ErrorF ("winClipboardWindowProc - CloseClipboard () failed: "
+       "%08x\n",
+       (int) GetLastError ());
+    }
+ 
+       }
+       return 0;
      }
  
    /* Let Windows perform default processing for unhandled messages */



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/



More information about the Cygwin-xfree mailing list