There is a long standing issue plaguing me with Gtk4 on Windows10 : after some time (can be minutes or days), randomly, my app stops receiving clipboard content from other apps.
Typically:
copy from Notepad++ , when pasting in my app I don’t get the Notepad++ text but the previous clipboard content.
copy from my app, paste in my app → works
copy from Notepad++, paste in other apps → works
copy from my app, paste in Notepad++ → works
Looks like at this point Gdk isn’t able to retrieve content from Win32 APIs anymore…
Some context: I’m using python-gobject, and had this issue since I started the porting from gtk3 to gtk4 about 1 year ago (i.e. not a recent regression). Gtk3 isn’t affected.
Anyone has knowledge about how Gdk-Win32 processes the incoming clipboard content? Is there an event on clipboard changes, or just polling? Any hints where in the code I can put some breakpoints to see what’s going on?
when the clipboard worked fine, I saw the messages 775=WM_DESTROYCLIPBOARD then 776=WM_DRAWCLIPBOARD, plus some weird message 49918.
but after the issue, I could only see the messages 49918 events (so the clipboard_window seems alive). OpenClipboard and GetClipboardData don’t even get called anymore after this point.
I added more logs to see if I got WM_DESTROY or WM_CHANGECBCHAIN.
Let’s see how it goes.
Yes, it’s this clipboard_window variable.
The thread seems to run fine, events are dispatched to _clipboard_window_procedure().
Doesn’t seem so…
I don’t enter the if (message == thread_wakeup_message || message == WM_TIMER) block, the message 49918 just gets consumed in the default case by DefWindowProcW().
I see it typically when changing windows focus, I don’t think it’s related to clipboard processing.
Mmh ok, however 49918 is a registered window message, because it’s in the range 0xC000 - 0xFFFF. This was documented by Raymond Chen in Which message numbers belong to whom?. See also RegisterWindowMessageW function (winuser.h) - Win32 apps | Microsoft Learn. Of course it can be a different message than the one registered by GDK, after all messages can be sent from external sources, but seems quite unlikely. Could you print the value of thread_wakeup_message when the issue occurs? I suspect that the variable gets overwritten, somehow
Well, according to GetClipboardFormatName(), my message 49918 corresponds to WM_MSO_BROADCASTCHANGE. So just noise from Microsoft Office, nothing to worry about.
My thread_wakeup_message has a value = 49749, same as the one assigned at init, so not corrupted (I did put a watch on it with gdb, but did not trigger anyway).
They claim our “Clipboard Viewer Window” is obsolete and recommend using AddClipboardFormatListener() instead. Seems only available since Windows10, are older Windows version still supported by gtk? If not we could give it a try
Good question The doc says that when we use the “Clipboard Viewer Window” then we have to manage the clipboard chain (react on changes WM_CHANGECBCHAIN, remove ourselves from the chain on on WM_DESTROY).
I wonder what happens if another client doesn’t follow the rules, does it “breaks” that chain? Can it affect other apps? Sounds nuts, but, well, it’s Windows we’re talking about…