[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [qtcurve] qt5/style: workaround QStyle::~QStyle not called by at least klipper
From:       Yichao Yu <yyc1992 () gmail ! com>
Date:       2016-03-19 18:34:10
Message-ID: E1ahLhS-0005S1-Ib () scm ! kde ! org
[Download RAW message or body]

Git commit ef70ffffb0bdfe8f011e0f86bd475c54c55426f5 by Yichao Yu.
Committed on 19/03/2016 at 18:34.
Pushed by yuyichao into branch 'master'.

workaround QStyle::~QStyle not called by at least klipper

M  +18   -18   qt5/style/qtcurve.cpp
M  +2    -1    qt5/style/qtcurve.h
M  +46   -0    qt5/style/qtcurve_plugin.cpp
M  +4    -0    qt5/style/qtcurve_plugin.h

http://commits.kde.org/qtcurve/ef70ffffb0bdfe8f011e0f86bd475c54c55426f5

diff --git a/qt5/style/qtcurve.cpp b/qt5/style/qtcurve.cpp
index ca24837..43d70d4 100644
--- a/qt5/style/qtcurve.cpp
+++ b/qt5/style/qtcurve.cpp
@@ -21,6 +21,7 @@
  *****************************************************************************/
 
 #include "qtcurve_p.h"
+#include "qtcurve_plugin.h"
 #include <qtcurve-utils/qtprops.h>
 
 #include <QDBusConnection>
@@ -346,7 +347,7 @@ Style::Style() :
     m_windowManager(new WindowManager(this)),
     m_blurHelper(new BlurHelper(this)),
     m_shortcutHandler(new ShortcutHandler(this)),
-    m_dbusConnected(false)
+    m_dbusConnected(nullptr)
 {
     const char *env = getenv(QTCURVE_PREVIEW_CONFIG);
     if (env && strcmp(env, QTCURVE_PREVIEW_CONFIG) == 0) {
@@ -658,7 +659,10 @@ void Style::connectDBus()
 {
     if (m_dbusConnected)
         return;
-    m_dbusConnected = true;
+    m_dbusConnected = registerCleanup([] (void *data) {
+            reinterpret_cast<Style*>(data)->disconnectDBus();
+        }, this);
+    return;
     auto bus = QDBusConnection::sessionBus();
     bus.connect(QString(), "/KGlobalSettings", "org.kde.KGlobalSettings",
                 "notifyChange", this, SLOT(kdeGlobalSettingsChange(int, int)));
@@ -685,28 +689,24 @@ void Style::disconnectDBus()
 {
     if (!m_dbusConnected)
         return;
-    m_dbusConnected = false;
+    void *cb = m_dbusConnected;
+    m_dbusConnected = nullptr;
+    unregisterCleanup(cb);
+    return;
     auto bus = QDBusConnection::sessionBus();
     bus.disconnect(QString(), "/KGlobalSettings", "org.kde.KGlobalSettings",
                    "notifyChange",
                    this, SLOT(kdeGlobalSettingsChange(int, int)));
     bus.disconnect("org.kde.kwin", "/KWin", "org.kde.KWin", "compositingToggled",
                    this, SLOT(compositingToggled()));
-
-    if (!qApp || qApp->arguments()[0] != "kwin") {
-        bus.disconnect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
-                    "borderSizesChanged", this, SLOT(borderSizesChanged()));
-        if (opts.menubarHiding & HIDE_KWIN)
-            bus.disconnect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
-                           "toggleMenuBar",
-                           this, SLOT(toggleMenuBar(unsigned int)));
-
-        if (opts.statusbarHiding & HIDE_KWIN) {
-            bus.disconnect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
-                           "toggleStatusBar",
-                           this, SLOT(toggleStatusBar(unsigned int)));
-        }
-    }
+    bus.disconnect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
+                   "borderSizesChanged", this, SLOT(borderSizesChanged()));
+    bus.disconnect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
+                   "toggleMenuBar",
+                   this, SLOT(toggleMenuBar(unsigned int)));
+    bus.disconnect("org.kde.kwin", "/QtCurve", "org.kde.QtCurve",
+                   "toggleStatusBar",
+                   this, SLOT(toggleStatusBar(unsigned int)));
 }
 
 Style::~Style()
diff --git a/qt5/style/qtcurve.h b/qt5/style/qtcurve.h
index 69cf3d7..6836b9d 100644
--- a/qt5/style/qtcurve.h
+++ b/qt5/style/qtcurve.h
@@ -509,6 +509,7 @@ private:
                                       const QStyleOption *option,
                                       QPainter *painter,
                                       const QWidget *widget) const;
+    static void dbusCleanupCallback(void*);
 
 private:
     mutable Options opts;
@@ -559,7 +560,7 @@ private:
     WindowManager *m_windowManager;
     BlurHelper *m_blurHelper;
     ShortcutHandler *m_shortcutHandler;
-    bool m_dbusConnected;
+    void *m_dbusConnected;
 };
 }
 
diff --git a/qt5/style/qtcurve_plugin.cpp b/qt5/style/qtcurve_plugin.cpp
index 500a3ff..b8c76ce 100644
--- a/qt5/style/qtcurve_plugin.cpp
+++ b/qt5/style/qtcurve_plugin.cpp
@@ -27,6 +27,7 @@
 #include <qtcurve-utils/qtprops.h>
 #include <qtcurve-utils/x11shadow.h>
 #include <qtcurve-utils/x11blur.h>
+#include <qtcurve-utils/log.h>
 
 #include <QApplication>
 
@@ -43,6 +44,49 @@
 
 namespace QtCurve {
 
+// Using a `std::set` somehow result in a segfault in glibc (maybe realated to
+// this function being called in the exit handler?) so use a home made solution
+// instead...
+struct CleanupCallback {
+    void (*func)(void*);
+    void *data;
+    CleanupCallback *next;
+    CleanupCallback **prev;
+};
+
+static CleanupCallback *cleanup_callbacks = nullptr;
+
+void*
+registerCleanup(void (*func)(void*), void *data)
+{
+    auto cb = new CleanupCallback{func, data, cleanup_callbacks,
+                                  &cleanup_callbacks};
+    if (cleanup_callbacks)
+        cleanup_callbacks->prev = &cb->next;
+    cleanup_callbacks = cb;
+    return cb;
+}
+
+void
+unregisterCleanup(void *_cb)
+{
+    auto cb = (CleanupCallback*)_cb;
+    if (cb->next)
+        cb->next->prev = cb->prev;
+    *cb->prev = cb->next;
+    delete cb;
+}
+
+static void
+runAllCleanups()
+{
+    while (cleanup_callbacks) {
+        auto func = cleanup_callbacks->func;
+        auto data = cleanup_callbacks->data;
+        func(data);
+    }
+}
+
 __attribute__((hot)) static void
 polishQuickControl(QObject *obj)
 {
@@ -120,6 +164,7 @@ StylePlugin::create(const QString &key)
 
 StylePlugin::~StylePlugin()
 {
+    runAllCleanups();
     QInternal::unregisterCallback(QInternal::EventNotifyCallback,
                                   qtcEventCallback);
 }
@@ -140,4 +185,5 @@ StylePlugin::init()
 #endif
         });
 }
+
 }
diff --git a/qt5/style/qtcurve_plugin.h b/qt5/style/qtcurve_plugin.h
index 95bbfed..fc81107 100644
--- a/qt5/style/qtcurve_plugin.h
+++ b/qt5/style/qtcurve_plugin.h
@@ -36,6 +36,10 @@ private:
     void init();
     std::once_flag m_ref_flag;
 };
+
+void *registerCleanup(void (*func)(void*), void *data);
+void unregisterCleanup(void *handle);
+
 }
 
 #endif
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic