fix dbus service registration/invocation

REVIEW: 108016
This commit is contained in:
Thomas Lübking 2012-12-30 00:15:30 +01:00
parent 8b35d3e34e
commit fa29b4141b
3 changed files with 28 additions and 7 deletions

View file

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// own
#include "dbusinterface.h"
// kwin
// TODO: remove together with deprecated methods
#include "client.h"
@ -28,6 +29,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kwinadaptor.h"
#include "workspace.h"
// Qt
#include <QDBusServiceWatcher>
namespace KWin
{
@ -38,7 +42,10 @@ DBusInterface::DBusInterface(QObject *parent)
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerObject("/KWin", this);
dbus.registerService("org.kde.KWin");
if (!dbus.registerService("org.kde.KWin")) {
QDBusServiceWatcher *dog = new QDBusServiceWatcher("org.kde.KWin", dbus, QDBusServiceWatcher::WatchForUnregistration, this);
connect (dog, SIGNAL(serviceUnregistered(const QString&)), SLOT(becomeKWinService(const QString&)));
}
connect(Compositor::self(), SIGNAL(compositingToggled(bool)), SIGNAL(compositingToggled(bool)));
dbus.connect(QString(), "/KWin", "org.kde.KWin", "reloadConfig",
Workspace::self(), SLOT(slotReloadConfig()));
@ -46,8 +53,20 @@ DBusInterface::DBusInterface(QObject *parent)
Compositor::self(), SLOT(slotReinitialize()));
}
void DBusInterface::becomeKWinService(const QString &service)
{
// TODO: this watchdog exists to make really safe that we at some point get the service
// but it's probably no longer needed since we explicitly unregister the service with the deconstructor
if (service == "org.kde.KWin" && QDBusConnection::sessionBus().registerService("org.kde.KWin") && sender()) {
sender()->deleteLater(); // bye doggy :'(
}
}
DBusInterface::~DBusInterface()
{
QDBusConnection::sessionBus().unregisterService("org.kde.KWin"); // this is the long standing legal service
// KApplication automatically also grabs org.kde.kwin, so it's often been used externally - ensure to free it as well
QDBusConnection::sessionBus().unregisterService("org.kde.kwin");
}
void DBusInterface::circulateDesktopApplications()

View file

@ -147,6 +147,8 @@ Q_SIGNALS: // SIGNALS
* @deprecated
**/
void compositingToggled(bool active);
private Q_SLOTS:
void becomeKWinService(const QString &service);
};
} // namespace

View file

@ -196,7 +196,7 @@ void KWinCompositingConfig::showConfirmDialog(bool reinitCompositing)
bool revert = false;
// Feel free to extend this to support several kwin instances (multihead) if you
// think it makes sense.
OrgKdeKWinInterface kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
OrgKdeKWinInterface kwin("org.kde.KWin", "/KWin", QDBusConnection::sessionBus());
if (reinitCompositing ? !kwin.compositingActive().value() : !kwin.waitForCompositingSetup().value()) {
KMessageBox::sorry(this, i18n(
"Failed to activate desktop effects using the given "
@ -399,7 +399,7 @@ void KWinCompositingConfig::updateStatusUI(bool compositingIsPossible)
ui.rearmGlSupport->hide();
}
else {
OrgKdeKWinInterface kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
OrgKdeKWinInterface kwin("org.kde.KWin", "/KWin", QDBusConnection::sessionBus());
ui.compositingOptionsContainer->hide();
QString text = i18n("Desktop effects are not available on this system due to the following technical issues:");
text += "<hr>";
@ -416,7 +416,7 @@ void KWinCompositingConfig::load()
{
initEffectSelector();
mKWinConfig->reparseConfiguration();
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kwin", "/KWin", "org.kde.KWin", "compositingPossible");
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.KWin", "/KWin", "org.kde.KWin", "compositingPossible");
QDBusConnection::sessionBus().callWithCallback(msg, this, SLOT(updateStatusUI(bool)));
// Copy Plugins group to temp config file
@ -527,7 +527,7 @@ bool KWinCompositingConfig::saveAdvancedTab()
void KWinCompositingConfig::save()
{
OrgKdeKWinInterface kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
OrgKdeKWinInterface kwin("org.kde.KWin", "/KWin", QDBusConnection::sessionBus());
if (ui.compositingType->currentIndex() == OPENGL_INDEX &&
kwin.openGLIsBroken() && !ui.rearmGlSupport->isVisible())
{
@ -595,7 +595,7 @@ void KWinCompositingConfig::checkLoadedEffects()
{
// check for effects not supported by Backend or hardware
// such effects are enabled but not returned by DBus method loadedEffects
OrgKdeKWinInterface kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
OrgKdeKWinInterface kwin("org.kde.KWin", "/KWin", QDBusConnection::sessionBus());
KConfigGroup effectConfig = KConfigGroup(mKWinConfig, "Compositing");
bool enabledAfter = effectConfig.readEntry("Enabled", true);
@ -626,7 +626,7 @@ void KWinCompositingConfig::checkLoadedEffects()
void KWinCompositingConfig::showDetailedEffectLoadingInformation()
{
QStringList disabledEffects = m_showDetailedErrors->data().toStringList();
OrgKdeKWinInterface kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
OrgKdeKWinInterface kwin("org.kde.KWin", "/KWin", QDBusConnection::sessionBus());
QDBusPendingReply< QString > pendingCompositingType = kwin.compositingType();
QString compositingType = pendingCompositingType.isError() ? "none" : pendingCompositingType.value();
KServiceTypeTrader* trader = KServiceTypeTrader::self();