Clipboard replacements are not atomic on GTK (Issue #26265)

30 views
Skip to first unread message

davidedmundson

unread,
Mar 5, 2026, 9:02:37 AM (9 days ago) Mar 5
to wx-...@googlegroups.com, Subscribed
davidedmundson created an issue (wxWidgets/wxWidgets#26265)

Description

Incorrect copy/paste behaviour when a desktop has a clipboard manager running.

Bug description:

When replacing a clipboard (or selection in X11) terms it is expected to be an atomic operation. The wXWidget client owns the selection when it creates a new selection it should take ownership again.

What wxWidgets does instead is:

  • drop the selection (clipbrd.cpp:649 in wxClipboard::SetData)
  • wait for the selection to be dropped (wxClipboardSync)
  • drop the selection again (for some reason we call clear again in wxClipboard::addData)
  • and only then do we make a new selection

This is problematic because desktops often have a clipboard manager. A clipboard manager's main job is to allow clipboard contents to persist across closing an application. When a selection is lost it will jump in and replace the contents.

Because wxWidgets has an extra notification and worse - waits a while, this looks like an application going away and the clipboard manager will jump in replacing the old contents.

This is exacerbated on Wayland as now we have an extra async step and we're hitting this race very reliably.

Upstream bug report: https://bugs.kde.org/514317
We (KDE) can try to work around it with bad timers, but at the end of the day what WxWidgets is doing is not right.

tldr:

  • Please don't call Clear() when replacing the clipboard. You don't need to. I think just just need to delete/reset m_dataPrimary without having to tell the outside world.

Expected vs observed behaviour:

Observed behaviour
In kicad on Plasma wayland:

  • copy item1
  • copy item2
  • paste an item
  • nothing is pasted, or item1 is pasted

Platform and version information

  • wxWidgets version: master
  • wxWidgets port: gtk
  • OS GTK running in Xwayland on KDE Plasma Wayland


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26265@github.com>

VZ

unread,
Mar 5, 2026, 2:40:00 PM (9 days ago) Mar 5
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26265)

Thanks for reporting this!

This is some very old code (Clear() has been added back in 0d2a2b6 (New DnD and Clipboard code, 1999-01-19)...) and I have to admit I have no idea why was it done like this. In wx API SetData() is supposed to replace the existing data on clipboard while AddData() should make the new data available in addition to the existing data, but this code doesn't do it this anyhow.

If removing calls to Clear() is really enough, I'm all for doing it, but I can't easily test that this fixes the problem. Would there be some way to test it without installing KDE?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26265/4007296750@github.com>

davidedmundson

unread,
Mar 9, 2026, 11:47:32 AM (5 days ago) Mar 9
to wx-...@googlegroups.com, Subscribed
davidedmundson left a comment (wxWidgets/wxWidgets#26265)

Would there be some way to test it without installing KDE?

Technically you can run klipper (our clipboard manager) standalone, but given it's all racey timings it'll be hard.
I can provide a patch that I can confirm fixes the bug.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26265/4024754862@github.com>

VZ

unread,
Mar 13, 2026, 11:02:49 AM (yesterday) Mar 13
to wx-...@googlegroups.com, Subscribed

Closed #26265 as completed via f11053a.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/26265/issue_event/23549708202@github.com>

Reply all
Reply to author
Forward
0 new messages