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
This commit is contained in:
David Edmundson 2023-03-03 11:19:06 +00:00 committed by Vlad Zahorodnii
parent a9dc50e22d
commit 46cad20ea8

View file

@ -293,20 +293,28 @@ void SeatInterfacePrivate::endDrag()
void SeatInterfacePrivate::updateSelection(DataDeviceInterface *dataDevice) void SeatInterfacePrivate::updateSelection(DataDeviceInterface *dataDevice)
{ {
DataSourceInterface *selection = dataDevice->selection();
// if the update is from the focussed window we should inform the active client // 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 (!(globalKeyboard.focus.surface && (*globalKeyboard.focus.surface->client() == dataDevice->client()))) {
if (selection) {
selection->cancel();
}
return; return;
} }
q->setSelection(dataDevice->selection()); q->setSelection(selection);
} }
void SeatInterfacePrivate::updatePrimarySelection(PrimarySelectionDeviceV1Interface *primarySelectionDevice) void SeatInterfacePrivate::updatePrimarySelection(PrimarySelectionDeviceV1Interface *primarySelectionDevice)
{ {
PrimarySelectionSourceV1Interface *selection = primarySelectionDevice->selection();
// if the update is from the focussed window we should inform the active client // 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 (!(globalKeyboard.focus.surface && (*globalKeyboard.focus.surface->client() == primarySelectionDevice->client()))) {
if (selection) {
selection->cancel();
}
return; return;
} }
q->setPrimarySelection(primarySelectionDevice->selection()); q->setPrimarySelection(selection);
} }
void SeatInterfacePrivate::sendCapabilities() void SeatInterfacePrivate::sendCapabilities()