xwayland: Drop outdated guard against clipboard races

This guard was added as part of d335070b80.

The guard as-is does not work correctly. If a client quits at the wrong point
or simply never responds to the request for targets, we get into a stuck state
where we will never update the clipboard from Wayland to X again until the
selection owner changes.

The guard appears to be outdated: The rationale given in the original MR was
that it prevented a race where:
 1. The X11 clipboard changes
 2. We start fetching targets
 3. We notify Wayland clients that the clipboard changed is now empty
 4. Klipper replaces the clipboard
 5. Kwin then replaces the X11 clipboard
 6. X11 finishes fetching targets, but this is now discarded as there's a new
X11 clipboard

However we can not find a path for step 2 to happen in the current codebase.
Potentially due to one of many refactors over the past few years.
The wayland selection is only replaced when targets are fully loaded.

The only way it could happen is if an X11 client replaced the clipboard by
explicitly deleting the old selection first, but this also does not appear to
happen in any tested apps.

BUG: 490577
This commit is contained in:
David Edmundson 2024-08-10 21:53:04 +00:00
parent 516e60948a
commit 7e23386d46
4 changed files with 0 additions and 22 deletions

View file

@ -53,10 +53,6 @@ Clipboard::Clipboard(xcb_atom_t atom, QObject *parent)
void Clipboard::wlSelectionChanged(AbstractDataSource *dsi)
{
if (m_waitingForTargets) {
return;
}
if (!ownsSelection(dsi)) {
// Wayland native window provides new selection
if (!m_checkConnection) {
@ -76,10 +72,6 @@ bool Clipboard::ownsSelection(AbstractDataSource *dsi) const
void Clipboard::checkWlSource()
{
if (m_waitingForTargets) {
return;
}
auto dsi = waylandServer()->seat()->selection();
auto removeSource = [this] {
if (wlSource()) {
@ -128,7 +120,6 @@ void Clipboard::doHandleXfixesNotify(xcb_xfixes_selection_notify_event_t *event)
if (X11Source *source = x11Source()) {
source->getTargets();
m_waitingForTargets = true;
} else {
qCWarning(KWIN_XWL) << "Could not create a source from" << event << Qt::hex << (event ? event->owner : -1);
}
@ -141,7 +132,6 @@ void Clipboard::x11OfferLost()
void Clipboard::x11OffersChanged(const QStringList &added, const QStringList &removed)
{
m_waitingForTargets = false;
X11Source *source = x11Source();
if (!source) {
qCWarning(KWIN_XWL) << "offers changed when not having an X11Source!?";

View file

@ -54,7 +54,6 @@ private:
QMetaObject::Connection m_checkConnection;
Q_DISABLE_COPY(Clipboard)
bool m_waitingForTargets = false;
std::unique_ptr<XwlDataSource> m_selectionSource;
};

View file

@ -56,10 +56,6 @@ Primary::~Primary() = default;
void Primary::wlPrimarySelectionChanged(AbstractDataSource *dsi)
{
if (m_waitingForTargets) {
return;
}
if (!ownsSelection(dsi)) {
// Wayland native window provides new selection
if (!m_checkConnection) {
@ -79,10 +75,6 @@ bool Primary::ownsSelection(AbstractDataSource *dsi) const
void Primary::checkWlSource()
{
if (m_waitingForTargets) {
return;
}
auto dsi = waylandServer()->seat()->primarySelection();
auto removeSource = [this] {
if (wlSource()) {
@ -139,7 +131,6 @@ void Primary::doHandleXfixesNotify(xcb_xfixes_selection_notify_event_t *event)
if (X11Source *source = x11Source()) {
source->getTargets();
m_waitingForTargets = true;
} else {
qCWarning(KWIN_XWL) << "Could not create a source from" << event << Qt::hex << (event ? event->owner : -1);
}
@ -152,7 +143,6 @@ void Primary::x11OfferLost()
void Primary::x11OffersChanged(const QStringList &added, const QStringList &removed)
{
m_waitingForTargets = false;
X11Source *source = x11Source();
if (!source) {
qCWarning(KWIN_XWL) << "offers changed when not having an X11Source!?";

View file

@ -55,7 +55,6 @@ private:
QMetaObject::Connection m_checkConnection;
Q_DISABLE_COPY(Primary)
bool m_waitingForTargets = false;
std::unique_ptr<XwlDataSource> m_primarySelectionSource;
};