frameworkintegration/0001-Ensure-the-xcb-connection-gets-flushed-before-the-ev.patch

117 lines
3.7 KiB
Diff

From 6210b6bb8af128c8e93c77330af80185d8ac3bec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= <mgraesslin@kde.org>
Date: Wed, 21 May 2014 08:10:07 +0200
Subject: [PATCH 1/1] Ensure the xcb connection gets flushed before the event
dispatcher blocks
This is a workaround for Qt versions which do not yet have the change
https://codereview.qt-project.org/85654
It is important to have this workaround as applications can get stalled
when a framework uses xcb and doesn't flush the connection manually.
BUG: 334858
REVIEW: 118234
---
src/platformtheme/CMakeLists.txt | 19 +++++++++++++++
src/platformtheme/config-platformtheme.h.cmake | 1 +
src/platformtheme/main.cpp | 33 ++++++++++++++++++++++++++
3 files changed, 53 insertions(+)
create mode 100644 src/platformtheme/config-platformtheme.h.cmake
diff --git a/src/platformtheme/CMakeLists.txt b/src/platformtheme/CMakeLists.txt
index da77cf8..8a3b1b4 100644
--- a/src/platformtheme/CMakeLists.txt
+++ b/src/platformtheme/CMakeLists.txt
@@ -1,3 +1,18 @@
+if(NOT APPLE)
+ find_package(XCB COMPONENTS XCB)
+ set_package_properties(XCB PROPERTIES
+ TYPE RECOMMENDED
+ PURPOSE "Required for flushing the XCB connection on the X11 Platform"
+ )
+ set(HAVE_X11 ${XCB_XCB_FOUND})
+ if (XCB_XCB_FOUND)
+ find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED X11Extras)
+ endif()
+else()
+ set(HAVE_X11 FALSE)
+endif()
+
+configure_file(config-platformtheme.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-platformtheme.h )
set(platformtheme_SRCS
kdeplatformtheme.cpp
@@ -30,4 +45,8 @@ target_link_libraries(KDEPlatformTheme
KF5::Notifications
)
+if(HAVE_X11)
+ target_link_libraries(KDEPlatformTheme PRIVATE Qt5::X11Extras XCB::XCB)
+endif()
+
install(TARGETS KDEPlatformTheme DESTINATION ${QT_PLUGIN_INSTALL_DIR}/platformthemes)
diff --git a/src/platformtheme/config-platformtheme.h.cmake b/src/platformtheme/config-platformtheme.h.cmake
new file mode 100644
index 0000000..89858d1
--- /dev/null
+++ b/src/platformtheme/config-platformtheme.h.cmake
@@ -0,0 +1 @@
+#cmakedefine01 HAVE_X11
diff --git a/src/platformtheme/main.cpp b/src/platformtheme/main.cpp
index 21d9aa0..d2c2bb1 100644
--- a/src/platformtheme/main.cpp
+++ b/src/platformtheme/main.cpp
@@ -22,6 +22,14 @@
#include "kdeplatformtheme.h"
+#include <config-platformtheme.h>
+#if HAVE_X11
+#include <QCoreApplication>
+#include <QAbstractEventDispatcher>
+#include <QX11Info>
+#include <xcb/xcb.h>
+#endif
+
class KdePlatformThemePlugin : public QPlatformThemePlugin
{
Q_OBJECT
@@ -34,8 +42,33 @@ public:
{
Q_UNUSED(key)
Q_UNUSED(paramList)
+ // Must be done after we have an event-dispatcher. By posting a method invocation
+ // we are sure that by the time the method is called we have an event-dispatcher.
+ QMetaObject::invokeMethod(this, "setupXcbFlush", Qt::QueuedConnection);
return new KdePlatformTheme;
}
+
+public Q_SLOTS:
+ void setupXcbFlush();
};
+void KdePlatformThemePlugin::setupXcbFlush()
+{
+#if HAVE_X11
+ // this is a workaround for BUG 334858
+ // it ensures that the xcb connection gets flushed before the EventDispatcher
+ // is going to block. Qt does not guarantee this in all cases.
+ // For Qt this issue is addressed in https://codereview.qt-project.org/85654
+ // TODO: remove again once we depend on a Qt version with the patch.
+ if (!QX11Info::isPlatformX11()) {
+ return;
+ }
+ connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock,
+ []() {
+ xcb_flush(QX11Info::connection());
+ }
+ );
+#endif
+}
+
#include "main.moc"
--
1.9.3