From 05db7b9f7c2d51a8f52a3cf0ba7584a78cdacb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 7 Mar 2014 14:41:05 +0100 Subject: [PATCH] Use xml interfaces to interact with KWin's DBus interfaces It's a little bit more type safe. REVIEW: 116649 --- kcmkwin/kwincompositing/CMakeLists.txt | 16 ++++++++++++++++ kcmkwin/kwincompositing/compositing.cpp | 8 +++++--- kcmkwin/kwincompositing/model.cpp | 9 ++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/kcmkwin/kwincompositing/CMakeLists.txt b/kcmkwin/kwincompositing/CMakeLists.txt index d2e24af250..38da852cd6 100644 --- a/kcmkwin/kwincompositing/CMakeLists.txt +++ b/kcmkwin/kwincompositing/CMakeLists.txt @@ -53,6 +53,13 @@ find_package(KF5 CONFIG REQUIRED COMPONENTS CoreAddons Config I18n Service XmlGu find_package(KF5Declarative REQUIRED NO_MODULE) +# Required for KWin's DBus interfaces +find_package(KDE4Workspace REQUIRED NO_MODULE) +set_package_properties(KDE4Workspace PROPERTIES + TYPE REQUIRED + PURPOSE "Required for DBus interfaces to KWin" + ) + ######################################################################### add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) @@ -74,6 +81,10 @@ set(kwincomposing_SRC compositing.cpp effectconfig.cpp) +qt5_add_dbus_interface( kwincomposing_SRC + ${KDE4WORKSPACE_DBUS_INTERFACES_DIR}/org.kde.kwin.Compositing.xml kwin_compositing_interface) +qt5_add_dbus_interface( kwincomposing_SRC + ${KDE4WORKSPACE_DBUS_INTERFACES_DIR}/org.kde.kwin.Effects.xml kwin_effects_interface) add_library(kwincompositing MODULE ${kwincomposing_SRC}) @@ -99,6 +110,11 @@ set(modelTest_SRC test/effectmodeltest.cpp test/modeltest.cpp) +qt5_add_dbus_interface( modelTest_SRC + ${KDE4WORKSPACE_DBUS_INTERFACES_DIR}/org.kde.kwin.Compositing.xml kwin_compositing_interface) +qt5_add_dbus_interface( modelTest_SRC + ${KDE4WORKSPACE_DBUS_INTERFACES_DIR}/org.kde.kwin.Effects.xml kwin_effects_interface) + add_executable(effectModelTest ${modelTest_SRC}) target_link_libraries(effectModelTest diff --git a/kcmkwin/kwincompositing/compositing.cpp b/kcmkwin/kwincompositing/compositing.cpp index 545107b5ec..30c00fda56 100644 --- a/kcmkwin/kwincompositing/compositing.cpp +++ b/kcmkwin/kwincompositing/compositing.cpp @@ -20,6 +20,7 @@ **************************************************************************/ #include "compositing.h" +#include #include #include @@ -130,15 +131,16 @@ bool Compositing::OpenGLIsUnsafe() const bool Compositing::OpenGLIsBroken() { - QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Compositor")); + OrgKdeKwinCompositingInterface interface(QStringLiteral("org.kde.KWin"), + QStringLiteral("/Compositor"), + QDBusConnection::sessionBus()); KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing"); QString oldBackend = kwinConfig.readEntry("Backend", "OpenGL"); kwinConfig.writeEntry("Backend", "OpenGL"); kwinConfig.sync(); - QDBusReply OpenGLIsBrokenReply = interface.call("OpenGLIsBroken"); - if (OpenGLIsBrokenReply.value()) { + if (interface.openGLIsBroken()) { kwinConfig.writeEntry("Backend", oldBackend); kwinConfig.sync(); return true; diff --git a/kcmkwin/kwincompositing/model.cpp b/kcmkwin/kwincompositing/model.cpp index dc691292d6..bc5b3e0f30 100644 --- a/kcmkwin/kwincompositing/model.cpp +++ b/kcmkwin/kwincompositing/model.cpp @@ -21,6 +21,7 @@ #include "model.h" #include "effectconfig.h" #include "compositing.h" +#include #include #include @@ -235,13 +236,15 @@ int EffectModel::findRowByServiceName(const QString &serviceName) void EffectModel::syncEffectsToKWin() { - QDBusInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Effects")); + OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), + QStringLiteral("/Effects"), + QDBusConnection::sessionBus()); for (int it = 0; it < m_effectsList.size(); it++) { if (m_effectsList.at(it).effectStatus != m_effectsChanged.at(it).effectStatus) { if (m_effectsList.at(it).effectStatus) { - interface.asyncCall("loadEffect", m_effectsList.at(it).serviceName); + interface.loadEffect(m_effectsList.at(it).serviceName); } else { - interface.asyncCall("unloadEffect", m_effectsList.at(it).serviceName); + interface.unloadEffect(m_effectsList.at(it).serviceName); } } }