From 46cad20ea861567d325a8f8fee74cd6e42278f61 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Fri, 3 Mar 2023 11:19:06 +0000 Subject: [PATCH] wayland: Cancel selections if set without focus Otherwise we confused clients in the following situation: Client A sets selection, but due to timing has lost focus User copies something in client B Client later tries to paste in client A. Client A still thinks it owns the selection so does nothing. CCBUG: 459389 --- src/wayland/seat_interface.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index 390d22abe4..07693f205c 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -293,20 +293,28 @@ void SeatInterfacePrivate::endDrag() void SeatInterfacePrivate::updateSelection(DataDeviceInterface *dataDevice) { + DataSourceInterface *selection = dataDevice->selection(); // if the update is from the focussed window we should inform the active client if (!(globalKeyboard.focus.surface && (*globalKeyboard.focus.surface->client() == dataDevice->client()))) { + if (selection) { + selection->cancel(); + } return; } - q->setSelection(dataDevice->selection()); + q->setSelection(selection); } void SeatInterfacePrivate::updatePrimarySelection(PrimarySelectionDeviceV1Interface *primarySelectionDevice) { + PrimarySelectionSourceV1Interface *selection = primarySelectionDevice->selection(); // if the update is from the focussed window we should inform the active client if (!(globalKeyboard.focus.surface && (*globalKeyboard.focus.surface->client() == primarySelectionDevice->client()))) { + if (selection) { + selection->cancel(); + } return; } - q->setPrimarySelection(primarySelectionDevice->selection()); + q->setPrimarySelection(selection); } void SeatInterfacePrivate::sendCapabilities()