Symptom: After coming back from remote desktop session first copy
         operation might crash XWin when using -clipboard (maybe 
         requiring -multiwindow too).

Cause:   XWin becomes its own next window in the clipboard chain
         after trying to ensure that it is still in the clipboard
         chain.

Fix:     Don't allow s_hwndNextViewer to get set to hwnd.

Also:    Added new -clipboarddebug flag which turns on more
         debugging messages from the clipboard manager.

ChangeLog:

2004-05-03 Dan Wilks <[EMAIL PROTECTED]>

* iniOutput.c (winUseMsg): Add documentation for new -clipboarddebug flag.
* winclipboardwndproc.c: Add reference to new clipboard debug variable.
(winClipboardWindowProc): Change debugging messages from #if 0 to use
new debug flag.  Don't try to set the "next window" in the clipboard 
chain to ourself.
* winglobals.c: Add new g_fClipboardDebug for clipboard debugging.
* winprocarg.c (ddxProcessArgument): Process -clipboarddebug and turn
on g_fClipboardDebug.

Diffs:
 
Index: InitOutput.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xwin/InitOutput.c,v
retrieving revision 1.1.4.1.2.39
diff -u -p -r1.1.4.1.2.39 InitOutput.c
--- InitOutput.c        26 Apr 2004 12:50:59 -0000      1.1.4.1.2.39
+++ InitOutput.c        3 May 2004 22:51:50 -0000
@@ -385,6 +385,10 @@ winUseMsg (void)
          "\tRun the clipboard integration module.\n"
          "\tDo not use at the same time as 'xwinclip'.\n");
 
+  ErrorF ("-clipboarddebug\n"
+         "\tRun the clipboard integration module with debugging output.\n"
+         "\tDo not use at the same time as 'xwinclip'.\n");
+
   ErrorF ("-nounicodeclipboard\n"
          "\tDo not use Unicode clipboard even if NT-based platform.\n");
 #endif
Index: winclipboardwndproc.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xwin/winclipboardwndproc.c,v
retrieving revision 1.1.4.1.2.20
diff -u -p -r1.1.4.1.2.20 winclipboardwndproc.c
--- winclipboardwndproc.c       26 Apr 2004 19:53:49 -0000      1.1.4.1.2.20
+++ winclipboardwndproc.c       3 May 2004 22:51:50 -0000
@@ -44,6 +44,7 @@
  */
 
 extern Bool            g_fUnicodeSupport;
+extern Bool            g_fClipboardDebug;
 extern void            *g_pClipboardDisplay;
 extern Window          g_iClipboardWindow;
 extern Atom            g_atomLastOwnedSelection;
@@ -145,9 +146,10 @@ winClipboardWindowProc (HWND hwnd, UINT 
     {
     case WM_DESTROY:
       {
-#if 0
-       ErrorF ("winClipboardWindowProc - WM_DESTROY\n");
-#endif
+       if (g_fClipboardDebug)
+         {
+           ErrorF ("winClipboardWindowProc - WM_DESTROY\n");
+         }
 
        /* Remove ourselves from the clipboard chain */
        ChangeClipboardChain (hwnd, s_hwndNextViewer);
@@ -161,18 +163,27 @@ winClipboardWindowProc (HWND hwnd, UINT 
 
     case WM_CREATE:
       {
-#if 0
-       ErrorF ("winClipboardWindowProc - WM_CREATE\n");
-#endif
+       if (g_fClipboardDebug) 
+         {
+           ErrorF ("winClipboardWindowProc - WM_CREATE\n");
+         }
        
        /* Add ourselves to the clipboard viewer chain */
        s_hwndNextViewer = SetClipboardViewer (hwnd);
+       if (s_hwndNextViewer == hwnd)
+         {
+           s_hwndNextViewer = NULL;
+         }
       }
       return 0;
 
 
     case WM_CHANGECBCHAIN:
       {
+       if (g_fClipboardDebug)
+         {
+           ErrorF ("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%x)
s_hwndNextViewer(%x)\n", wParam, s_hwndNextViewer);
+         }
        if ((HWND) wParam == s_hwndNextViewer)
          s_hwndNextViewer = (HWND) lParam;
        else if (s_hwndNextViewer)
@@ -197,10 +208,22 @@ winClipboardWindowProc (HWND hwnd, UINT 
         */
 
         s_fCBCInitialized = FALSE;
+       if (g_fClipboardDebug)
+         {
+           ErrorF ("winClipboardWindowProc - WM_WM_REINIT: Removing
ourselves\n");
+         }
         ChangeClipboardChain (hwnd, s_hwndNextViewer);
         s_hwndNextViewer = NULL;
         s_fCBCInitialized = FALSE;
+       if (g_fClipboardDebug)
+         {
+           ErrorF ("winClipboardWindowProc - WM_WM_REINIT: Readding
ourselves\n");
+         }
         s_hwndNextViewer = SetClipboardViewer (hwnd);
+       if (s_hwndNextViewer == hwnd)
+         {
+           s_hwndNextViewer = NULL;
+         }
       }
       return 0;
 
@@ -211,9 +234,20 @@ winClipboardWindowProc (HWND hwnd, UINT 
        Window  iWindow = g_iClipboardWindow;
        int     iReturn;
 
+       if (g_fClipboardDebug)
+         {
+           ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD\n");
+         }
+
        /* Pass the message on the next window in the clipboard viewer chain
*/
-       if (s_hwndNextViewer)
-         SendMessage (s_hwndNextViewer, message, 0, 0);
+       if (s_hwndNextViewer) 
+         {
+           if (g_fClipboardDebug)
+             {
+               ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD:
Forwarding message to %x\n", s_hwndNextViewer);
+             }
+           SendMessage (s_hwndNextViewer, message, 0, 0);
+         }
        
        /* Bail on first message */
        if (!s_fCBCInitialized)
@@ -233,10 +267,11 @@ winClipboardWindowProc (HWND hwnd, UINT 
        /* Bail when we still own the clipboard */
        if (hwnd == GetClipboardOwner ())
          {
-#if 0
-           ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                   "We own the clipboard, returning.\n");
-#endif
+           if (g_fClipboardDebug) 
+             {
+               ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                       "We own the clipboard, returning.\n");
+             }
            return 0;
          }
 
@@ -248,11 +283,12 @@ winClipboardWindowProc (HWND hwnd, UINT 
        if (!IsClipboardFormatAvailable (CF_TEXT)
            && !IsClipboardFormatAvailable (CF_UNICODETEXT))
          {
-#if 0
-           ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                   "Clipboard does not contain CF_TEXT nor "
-                   "CF_UNICODETEXT.\n");
-#endif
+           if (g_fClipboardDebug) 
+             {
+               ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                       "Clipboard does not contain CF_TEXT nor "
+                       "CF_UNICODETEXT.\n");
+             }
 
            /*
             * We need to make sure that the X Server has processed
@@ -264,10 +300,11 @@ winClipboardWindowProc (HWND hwnd, UINT 
            iReturn = XGetSelectionOwner (pDisplay, XA_PRIMARY);
            if (iReturn == g_iClipboardWindow)
              {
-#if 0
-               ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                       "PRIMARY selection is owned by us.\n");
-#endif
+               if (g_fClipboardDebug) 
+                 {
+                   ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                           "PRIMARY selection is owned by us.\n");
+                 }
                XSetSelectionOwner (pDisplay,
                                    XA_PRIMARY,
                                    None,
@@ -284,10 +321,11 @@ winClipboardWindowProc (HWND hwnd, UINT 
                                                       False));
            if (iReturn == g_iClipboardWindow)
              {
-#if 0
-               ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                       "CLIPBOARD selection is owned by us.\n");
-#endif
+               if (g_fClipboardDebug) 
+                 {
+                   ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                           "CLIPBOARD selection is owned by us.\n");
+                 }
                XSetSelectionOwner (pDisplay,
                                    XInternAtom (pDisplay,
                                                 "CLIPBOARD",
@@ -312,13 +350,11 @@ winClipboardWindowProc (HWND hwnd, UINT 
            ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                    "Could not reassert ownership of PRIMARY\n");
          }
-#if 0
-       else
+       else if (g_fClipboardDebug)
          {
            ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                    "Reasserted ownership of PRIMARY\n");
          }
-#endif
        
        /* Reassert ownership of the CLIPBOARD */         
        iReturn = XSetSelectionOwner (pDisplay,
@@ -332,13 +368,11 @@ winClipboardWindowProc (HWND hwnd, UINT 
            ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                    "Could not reassert ownership of CLIPBOARD\n");
          }
-#if 0
-       else
+       else if (g_fClipboardDebug) 
          {
            ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                    "Reasserted ownership of CLIPBOARD\n");
          }
-#endif
        
        /* Flush the pending SetSelectionOwner event now */
        XFlush (pDisplay);
@@ -368,9 +402,10 @@ winClipboardWindowProc (HWND hwnd, UINT 
        Window  iWindow = g_iClipboardWindow;
        Bool    fConvertToUnicode;
 
-#if 0
-       ErrorF ("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n");
-#endif
+       if (g_fClipboardDebug) 
+         {
+           ErrorF ("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n");
+         }
 
        /* Flag whether to convert to Unicode or not */
        if (message == WM_RENDERALLFORMATS)
@@ -472,9 +507,10 @@ winClipboardWindowProc (HWND hwnd, UINT 
              }
          }
 
-#if 0
-       ErrorF ("winClipboardWindowProc - WM_RENDER*FORMAT - Returning.\n");
-#endif
+       if (g_fClipboardDebug) 
+         {
+           ErrorF ("winClipboardWindowProc - WM_RENDER*FORMAT -
Returning.\n");
+         }
        return 0;
       }
     }
Index: winglobals.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xwin/Attic/winglobals.c,v
retrieving revision 1.1.2.20
diff -u -p -r1.1.2.20 winglobals.c
--- winglobals.c        22 Apr 2004 20:16:51 -0000      1.1.2.20
+++ winglobals.c        3 May 2004 22:51:50 -0000
@@ -95,6 +95,7 @@ winDispatchProcPtr    winProcSetSelectionOw
 
 Bool                   g_fUnicodeClipboard = TRUE;
 Bool                   g_fClipboard = FALSE;
+Bool                   g_fClipboardDebug = FALSE;
 Bool                   g_fClipboardLaunched = FALSE;
 Bool                   g_fClipboardStarted = FALSE;
 pthread_t              g_ptClipboardProc = 0;
Index: winprocarg.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xwin/Attic/winprocarg.c,v
retrieving revision 1.1.2.17
diff -u -p -r1.1.2.17 winprocarg.c
--- winprocarg.c        22 Apr 2004 20:16:51 -0000      1.1.2.17
+++ winprocarg.c        3 May 2004 22:51:50 -0000
@@ -42,6 +42,7 @@ extern Bool                   g_fInitializedDefaultScree
 #ifdef XWIN_CLIPBOARD
 extern Bool                    g_fUnicodeClipboard;
 extern Bool                    g_fClipboard;
+extern Bool                    g_fClipboardDebug;
 #endif
 extern int                     g_iLogVerbose;
 extern char *                  g_pszLogFile;
@@ -610,6 +611,18 @@ ddxProcessArgument (int argc, char *argv
       /* Indicate that we have processed this argument */
       return 1;
     }
+
+  /*
+   * Look for the '-clipboarddebug' argument
+   */
+  if (IS_OPTION ("-clipboarddebug"))
+    {
+      g_fClipboard = TRUE;
+      g_fClipboardDebug = TRUE;
+
+      /* Indicate that we have processed this argument */
+      return 1;
+    }
 #endif
 


Reply via email to