Skip to content

Fix wine copy & paste

Sebastian Keller requested to merge skeller/mutter:fix-wine-copy-paste into master

This is an attempt at fixing copy & paste in wine applications using X11. Wine uses a new window as selection owner for every selection and destroys the old one right before creating the new one. Destroying the selection owner causes the mutter clipboard manager to kick in which then becomes the new clipboard selection owner. This happens after the new wine selection, effectively overriding it. It is not possible to use SelectionClientClose instead, because clients like Chromium might destroy the selection window properly as part of their shutdown.

To solve this issue introduce a way to prevent updating the clipboard when setting a selection owner, then use this to only clear the selection but not the clipboard content on SelectionWindowDestroy and start a timeout to restore the clipboard if no other owner shows up in the meantime.

I have tested this code with a couple applications and toolkits. First whether multiple copies work and then whether the copied text was retained in the clipboard after closing the application:

Still/now working as expected with this MR:

  • Chromium
  • LibreOffice
  • Wine (Notepad)
  • gtk2 (hexchat)
  • gtk3 (gedit)
  • gtk4 (gtk4-widget-factory)
  • Qt3 (qt3-config)
  • Qt4 (KeePassX; Clearing the clipboard also still works)
  • Qt5 (kate)
  • xterm (with "Select to Clipboard" enabled)
  • swt (Eclipse)
  • javafx (JabRef)
  • swing (NetBeans)
  • motif (ddd)
  • efl (terminology)

Somewhat broken (but also broken in master and unrelated to this MR):

  • Firefox
    • Often does not retain clipboard after shutdown. This is because it it sets the selection owner to None, exactly like KeePassX does to clear the clipboard. Sometimes there is a SelectionClientCloseNotify instead of a SetSelectionOwnerNotify, those are the cases when the clipboard is retained (as expected from the mutter clipboard code). I think this would need to be fixed in Firefox, otherwise it is not possible to fix both KeePassX and Firefox.
  • tcl/tk (gitk)
    • The clipboard will retain the first copied string after closing the app. It does not trigger any kind of events when the copied text changes, therefore the text in the mutter clipboard never gets updated. I guess the only solution for this would be polling the clipboard selection, which given how little tcl/tk is used nowadays seems like a tradeoff we don't want to make.

Fixes #1338 (closed)

Edited by Robert Mader

Merge request reports