Skip to content

Add serial to data control to avoid race condition with clipboard managers

Simon Ser requested to merge github/fork/davidedmundson/wlr_data_serial into master

Created by: davidedmundson

A typically clipboard manager works as follows:

  • On a new clipboard, we copy any text
  • If the clipboard becomes empty (typically because a client died), we paste our previously copied text

Our race happens as follows:

first copy:

  • client creates a wl_data_offer
  • compositors sees it forwards it clipboard manager which copies the text...

second copy:

  • client deletes its old wl_data_offer before creating a new one

  • compositor forwards this update to clipboard manager

  • clipboard manager knows the clipboard is empty and starts its operation to prevent an empty clipboard

  • client creates a new wl_data_offer and calls set_selection

  • clipboard manager creates a new wlr_data_offer (with the old clipboard text) and calls set_selection

The compositor can get these last two in any order, and we end up replacing our new clipboard content with out-of-date previous clipboard contents.

This patch adds a serial number that can be used when a set_selection is used in repsponse to a selection event.

Merge request reports