xxDark commented on PR #8277:
URL: https://github.com/apache/netbeans/pull/8277#issuecomment-2679959287

   I think I've figured out what happens:
   ```C
   BOOL __stdcall OpenClipboard(HWND hWndNewOwner)
   {
     DWORD emptyClipboard;
     DWORD result = NtUserOpenClipboard(hWndNewOwner, &emptyClipboard);
     if ( emptyClipboard )
       ClientEmptyClipboard();
     return result;
   }
   ```
   Call to `OpenClipboard` fails in the JDK, because both toolkit & EDT are 
trying to access it.
   `emptyClipboard` never gets set to `true` (?), so `ClientEmptyClipboard` is 
never called. I think that `ClientEmptyClipboard` is a user-mode version of 
`EmptyClipboard` which calls `NtUserEmptyClipboard`. In MS documentation, there 
is a reference to 
[WM_DESTROYCLIPBOARD](https://learn.microsoft.com/en-us/windows/desktop/dataxchg/wm-destroyclipboard)
 (keep 
[this](https://github.com/openjdk/jdk/blob/990d40e98da2ceb3261096eaa55550565af58fc1/src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp#L1039)
 code in mind).
   `ClientEmptyClipboard` looks like this (and not called):
   ```C
   void ClientEmptyClipboard(void)
   {
     struct _HANDLENODE *v0; // rbx
     struct _HANDLENODE *v1; // rdi
   
     RtlEnterCriticalSection(&gcsClipboard);
     v0 = (struct _HANDLENODE *)gphn;
     if ( gphn )
     {
       do
       {
         v1 = *(struct _HANDLENODE **)v0;
         if ( *((_QWORD *)v0 + 3) )
           DeleteClientClipboardHandle(v0);
         RtlFreeHeap(pUserHeap, 0, v0);
         v0 = v1;
       }
       while ( v1 );
     }
     gphn = 0LL;
     if ( pfnWowEmptyClipBoard )
       pfnWowEmptyClipBoard(); // Supposed to send WM_DESTROYCLIPBOARD here, 
but because OpenClipboard did not succeed, the message is silently discarded (?)
     RtlLeaveCriticalSection(&gcsClipboard);
   }
   ```
   So TL;DR `LostOwnership` never gets a chance to be called because 
`WM_DESTROYCLIPBOARD` does not get delivered. If we follow what function native 
code does: [supposed to clear current cached 
contents](https://github.com/openjdk/jdk/blob/990d40e98da2ceb3261096eaa55550565af58fc1/src/java.desktop/share/classes/sun/awt/datatransfer/SunClipboard.java#L299),
 but never gets a chance to do so.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to