From 8425cd06fd83abb945917f8ba555f24f6fea6ab0 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Thu, 13 Aug 2020 10:48:16 +0100 Subject: [PATCH] Add serial to data control to avoid race condition with clipboard managers 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 repsonse to a selection event. --- unstable/wlr-data-control-unstable-v1.xml | 50 ++++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/unstable/wlr-data-control-unstable-v1.xml b/unstable/wlr-data-control-unstable-v1.xml index 75e8671..a2bfad4 100644 --- a/unstable/wlr-data-control-unstable-v1.xml +++ b/unstable/wlr-data-control-unstable-v1.xml @@ -41,7 +41,7 @@ interface version number is reset. - + This interface is a manager that allows creating per-seat data device controls. @@ -71,7 +71,7 @@ - + This interface allows a client to manage a seat's selection. @@ -141,7 +141,7 @@ - + The primary_selection event is sent out to notify the client of a new wlr_data_control_offer for the primary selection for this device. The @@ -183,9 +183,33 @@ + + + + + + This should be sent by compositors before a selection event with an + increasing serial number. + + This can be used by the client in partnership to set_selection_response + to indicate pairing of a selection event to a reply. + + + + + + + This should be sent by compositors before a primary_selection event + with an increasing serial number. + + This can be used by the client in partnership to set_selection_response + to indicate pairing of a selection event to a reply. + + + - + The wlr_data_control_source object is the source side of a wlr_data_control_offer. It is created by the source client in a data @@ -233,9 +257,25 @@ The client should clean up and destroy this data source. + + + + + + Clients can optionally specify a serial for this source indicating that + it is in response to a previous data device event. For example a + clipboard manager updating the text after a a set_selection event with + an empty selection. + Compositors may disregard this set_selection event if it is deemed + outdated. + + + + - + A wlr_data_control_offer represents a piece of data offered for transfer by another client (the source client). The offer describes the different