Changeset View
Changeset View
Standalone View
Standalone View
dbusinterface.cpp
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 50 | { | |||
---|---|---|---|---|---|
59 | if (!dbus.registerService(m_serviceName)) { | 59 | if (!dbus.registerService(m_serviceName)) { | ||
60 | QDBusServiceWatcher *dog = new QDBusServiceWatcher(m_serviceName, dbus, QDBusServiceWatcher::WatchForUnregistration, this); | 60 | QDBusServiceWatcher *dog = new QDBusServiceWatcher(m_serviceName, dbus, QDBusServiceWatcher::WatchForUnregistration, this); | ||
61 | connect (dog, SIGNAL(serviceUnregistered(QString)), SLOT(becomeKWinService(QString))); | 61 | connect (dog, SIGNAL(serviceUnregistered(QString)), SLOT(becomeKWinService(QString))); | ||
62 | } else { | 62 | } else { | ||
63 | announceService(); | 63 | announceService(); | ||
64 | } | 64 | } | ||
65 | dbus.connect(QString(), QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig"), | 65 | dbus.connect(QString(), QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig"), | ||
66 | Workspace::self(), SLOT(slotReloadConfig())); | 66 | Workspace::self(), SLOT(slotReloadConfig())); | ||
67 | connect(kwinApp(), &Application::x11ConnectionChanged, this, &DBusInterface::announceService); | ||||
67 | } | 68 | } | ||
68 | 69 | | |||
69 | void DBusInterface::becomeKWinService(const QString &service) | 70 | void DBusInterface::becomeKWinService(const QString &service) | ||
70 | { | 71 | { | ||
71 | // TODO: this watchdog exists to make really safe that we at some point get the service | 72 | // TODO: this watchdog exists to make really safe that we at some point get the service | ||
72 | // but it's probably no longer needed since we explicitly unregister the service with the deconstructor | 73 | // but it's probably no longer needed since we explicitly unregister the service with the deconstructor | ||
73 | if (service == m_serviceName && QDBusConnection::sessionBus().registerService(m_serviceName) && sender()) { | 74 | if (service == m_serviceName && QDBusConnection::sessionBus().registerService(m_serviceName) && sender()) { | ||
74 | sender()->deleteLater(); // bye doggy :'( | 75 | sender()->deleteLater(); // bye doggy :'( | ||
75 | announceService(); | 76 | announceService(); | ||
76 | } | 77 | } | ||
77 | } | 78 | } | ||
78 | 79 | | |||
79 | DBusInterface::~DBusInterface() | 80 | DBusInterface::~DBusInterface() | ||
80 | { | 81 | { | ||
81 | QDBusConnection::sessionBus().unregisterService(m_serviceName); | 82 | QDBusConnection::sessionBus().unregisterService(m_serviceName); | ||
82 | // KApplication automatically also grabs org.kde.kwin, so it's often been used externally - ensure to free it as well | 83 | // KApplication automatically also grabs org.kde.kwin, so it's often been used externally - ensure to free it as well | ||
83 | QDBusConnection::sessionBus().unregisterService(QStringLiteral("org.kde.kwin")); | 84 | QDBusConnection::sessionBus().unregisterService(QStringLiteral("org.kde.kwin")); | ||
84 | xcb_delete_property(connection(), rootWindow(), atoms->kwin_dbus_service); | 85 | if (kwinApp()->x11Connection()) { | ||
86 | xcb_delete_property(kwinApp()->x11Connection(), kwinApp()->x11RootWindow(), atoms->kwin_dbus_service); | ||||
87 | } | ||||
85 | } | 88 | } | ||
86 | 89 | | |||
87 | void DBusInterface::announceService() | 90 | void DBusInterface::announceService() | ||
88 | { | 91 | { | ||
92 | if (!kwinApp()->x11Connection()) { | ||||
93 | return; | ||||
94 | } | ||||
89 | const QByteArray service = m_serviceName.toUtf8(); | 95 | const QByteArray service = m_serviceName.toUtf8(); | ||
90 | xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, rootWindow(), atoms->kwin_dbus_service, | 96 | xcb_change_property(kwinApp()->x11Connection(), XCB_PROP_MODE_REPLACE, kwinApp()->x11RootWindow(), atoms->kwin_dbus_service, | ||
91 | atoms->utf8_string, 8, service.size(), service.constData()); | 97 | atoms->utf8_string, 8, service.size(), service.constData()); | ||
92 | } | 98 | } | ||
93 | 99 | | |||
94 | // wrap void methods with no arguments to Workspace | 100 | // wrap void methods with no arguments to Workspace | ||
95 | #define WRAP(name) \ | 101 | #define WRAP(name) \ | ||
96 | void DBusInterface::name() \ | 102 | void DBusInterface::name() \ | ||
97 | {\ | 103 | {\ | ||
98 | Workspace::self()->name();\ | 104 | Workspace::self()->name();\ | ||
▲ Show 20 Lines • Show All 172 Lines • Show Last 20 Lines |