Skip to content

Instantly share code, notes, and snippets.

@hexchain
Last active January 25, 2023 14:20
Show Gist options
  • Save hexchain/06e71deb8b29f661fee646fe0096a499 to your computer and use it in GitHub Desktop.
Save hexchain/06e71deb8b29f661fee646fe0096a499 to your computer and use it in GitHub Desktop.
diff --git a/src/systemclipboard/waylandclipboard.cpp b/src/systemclipboard/waylandclipboard.cpp
index 98d18fb..fea5082 100644
--- a/src/systemclipboard/waylandclipboard.cpp
+++ b/src/systemclipboard/waylandclipboard.cpp
@@ -542,11 +542,13 @@ public:
private:
void keyboard_enter([[maybe_unused]] uint32_t serial, [[maybe_unused]] wl_surface *surface, [[maybe_unused]] wl_array *keys) override
{
+ qInfo() << "kb enter";
m_seat.m_focus = true;
Q_EMIT m_seat.keyboardEntered();
}
void keyboard_leave([[maybe_unused]] uint32_t serial, [[maybe_unused]] wl_surface *surface) override
{
+ qInfo() << "kb leave";
m_seat.m_focus = false;
}
KeyboardFocusWatcher &m_seat;
@@ -612,10 +614,12 @@ void WaylandClipboard::setMimeData(QMimeData *mime, QClipboard::Mode mode)
// If the application is focused, use the normal mechanism so a future paste will not deadlock itself
// On enter Qt delays processing of the enter event but when a window is hidden the leave event arrives after hiding the window
if (const auto fw = QGuiApplication::focusWindow(); (fw && fw->isVisible()) || (!fw && m_keyboardFocusWatcher->hasFocus())) {
+ qInfo() << "using normal mechanism" << "fw:" << fw << ", fw->isVisible:" << (fw != nullptr && fw->isVisible()) << ", keyboard has focus:" << m_keyboardFocusWatcher->hasFocus();
QGuiApplication::clipboard()->setMimeData(mime, mode);
return;
}
// If not, set the clipboard once the app receives focus to avoid the deadlock
+ qInfo() << "not using normal mechanism";
connect(m_keyboardFocusWatcher.get(), &KeyboardFocusWatcher::keyboardEntered, this, &WaylandClipboard::gainedFocus, Qt::UniqueConnection);
auto source = std::make_unique<DataControlSource>(m_manager->create_data_source(), mime);
if (mode == QClipboard::Clipboard) {
@@ -627,6 +631,7 @@ void WaylandClipboard::setMimeData(QMimeData *mime, QClipboard::Mode mode)
void WaylandClipboard::gainedFocus()
{
+ qInfo() << "gained focus";
disconnect(m_keyboardFocusWatcher.get(), &KeyboardFocusWatcher::keyboardEntered, this, nullptr);
// QClipboard takes ownership of the QMimeData so we need to transfer and unset our selections
if (auto &selection = m_device->m_selection) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment