Commit feb67853 authored by David Edmundson's avatar David Edmundson Committed by Aleix Pol Gonzalez
Browse files

[klipper] Workaround race when klipper updates on wayland

We have a situation where some clients drop their old offer before
creating a new one. This means klipper tries to fill in the empty
clipboard at the same time the client posts its new real contents.

This adds in a flag (via a hidden mimetype) that klipper is trying to
replace a null clipboard. If this flag is set and our clipboard is not
null because the client has updated it in the meantime we ignore the
klipper update.

It's a workaround, rather than an ideal fix at a data level, but it
solves the problem in the interim.
parent e79000e5
......@@ -737,7 +737,7 @@ void Klipper::checkClipData( bool selectionMode )
if ( top ) {
// keep old clipboard after someone set it to null
qCDebug(KLIPPER_LOG) << "Resetting clipboard (Prevent empty clipboard)";
setClipboard( *top, selectionMode ? Selection : Clipboard );
setClipboard( *top, selectionMode ? Selection : Clipboard, ClipboardUpdateReason::PreventEmptyClipboard);
}
return;
} else if (clipEmpty) {
......@@ -791,7 +791,7 @@ void Klipper::checkClipData( bool selectionMode )
}
}
void Klipper::setClipboard( const HistoryItem& item, int mode )
void Klipper::setClipboard( const HistoryItem& item, int mode , ClipboardUpdateReason updateReason)
{
Ignore lock( m_locklevel );
......@@ -799,11 +799,19 @@ void Klipper::setClipboard( const HistoryItem& item, int mode )
if ( mode & Selection ) {
qCDebug(KLIPPER_LOG) << "Setting selection to <" << item.text() << ">";
m_clip->setMimeData( item.mimeData(), QClipboard::Selection );
QMimeData *mimeData = item.mimeData();
if (updateReason == ClipboardUpdateReason::PreventEmptyClipboard) {
mimeData->setData(QStringLiteral("application/x-kde-onlyReplaceEmpty"), "1");
}
m_clip->setMimeData( mimeData, QClipboard::Selection );
}
if ( mode & Clipboard ) {
qCDebug(KLIPPER_LOG) << "Setting clipboard to <" << item.text() << ">";
m_clip->setMimeData( item.mimeData(), QClipboard::Clipboard );
QMimeData *mimeData = item.mimeData();
if (updateReason == ClipboardUpdateReason::PreventEmptyClipboard) {
mimeData->setData(QStringLiteral("application/x-kde-onlyReplaceEmpty"), "1");
}
m_clip->setMimeData( mimeData, QClipboard::Clipboard );
}
}
......
......@@ -101,6 +101,10 @@ protected:
* a boolean true as a mode.
*/
enum SelectionMode { Clipboard = 2, Selection = 4 };
enum class ClipboardUpdateReason {
UpdateClipboard,
PreventEmptyClipboard
};
/**
* Loads history from disk.
......@@ -124,7 +128,7 @@ protected:
*/
QSharedPointer<HistoryItem> applyClipChanges( const QMimeData* data );
void setClipboard( const HistoryItem& item, int mode );
void setClipboard( const HistoryItem& item, int mode, ClipboardUpdateReason updateReason = ClipboardUpdateReason::UpdateClipboard);
bool ignoreClipboardChanges() const;
KSharedConfigPtr config() const { return m_config; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment