Changeset View
Changeset View
Standalone View
Standalone View
src/service/ksmserver/KSMServer.cpp
Show All 36 Lines | |||||
37 | #include <utils/d_ptr_implementation.h> | 37 | #include <utils/d_ptr_implementation.h> | ||
38 | 38 | | |||
39 | // Local | 39 | // Local | ||
40 | #include "DebugActivities.h" | 40 | #include "DebugActivities.h" | ||
41 | 41 | | |||
42 | #define KWIN_SERVICE QStringLiteral("org.kde.KWin") | 42 | #define KWIN_SERVICE QStringLiteral("org.kde.KWin") | ||
43 | 43 | | |||
44 | KSMServer::Private::Private(KSMServer *parent) | 44 | KSMServer::Private::Private(KSMServer *parent) | ||
45 | : serviceWatcher(new QDBusServiceWatcher(this)) | 45 | : kwin(new QDBusInterface(KWIN_SERVICE, QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QDBusConnection::sessionBus(), this)) | ||
broulik: This is also a perfect candidate for dbus xml? | |||||
davidedmundson: It absolutely is. But one change at a time. | |||||
46 | , kwin(nullptr) | | |||
47 | , processing(false) | 46 | , processing(false) | ||
48 | , q(parent) | 47 | , q(parent) | ||
49 | { | 48 | { | ||
50 | serviceWatcher->setConnection(KDBusConnectionPool::threadConnection()); | | |||
51 | serviceWatcher->addWatchedService(KWIN_SERVICE); | | |||
52 | | ||||
53 | connect(serviceWatcher.get(), &QDBusServiceWatcher::serviceOwnerChanged, | | |||
54 | this, &Private::serviceOwnerChanged); | | |||
55 | | ||||
56 | serviceOwnerChanged(KWIN_SERVICE, QString(), QString()); | | |||
57 | } | | |||
58 | | ||||
59 | void KSMServer::Private::serviceOwnerChanged(const QString &service, | | |||
60 | const QString &oldOwner, | | |||
61 | const QString &newOwner) | | |||
62 | { | | |||
63 | Q_UNUSED(oldOwner); | | |||
64 | Q_UNUSED(newOwner); | | |||
65 | | ||||
66 | if (service == KWIN_SERVICE) { | | |||
67 | // Delete the old object, just in case | | |||
68 | delete kwin; | | |||
69 | kwin = nullptr; | | |||
70 | | ||||
71 | if (KDBusConnectionPool::threadConnection().interface()->isServiceRegistered(KWIN_SERVICE)) { | | |||
72 | // Creating the new dbus interface | | |||
73 | // TODO: in multi-head environment there are multiple kwin instances | | |||
74 | // running and they will export different dbus name on different | | |||
75 | // root window. We have no support for that currently. | | |||
76 | // In future, the session management for Wayland may also need to be | | |||
77 | // reimplemented in some way. | | |||
78 | kwin = new QDBusInterface(KWIN_SERVICE, QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin")); | | |||
79 | | ||||
80 | // If the service is valid, initialize it | | |||
81 | // otherwise delete the object | | |||
82 | if (kwin->isValid()) { | | |||
83 | kwin->setParent(this); | | |||
84 | | ||||
85 | } else { | | |||
86 | delete kwin; | | |||
87 | kwin = nullptr; | | |||
88 | } | | |||
89 | } | | |||
90 | } | | |||
91 | } | 49 | } | ||
92 | 50 | | |||
93 | KSMServer::KSMServer(QObject *parent) | 51 | KSMServer::KSMServer(QObject *parent) | ||
94 | : QObject(parent) | 52 | : QObject(parent) | ||
95 | , d(this) | 53 | , d(this) | ||
96 | { | 54 | { | ||
97 | } | 55 | } | ||
98 | 56 | | |||
99 | KSMServer::~KSMServer() | 57 | KSMServer::~KSMServer() | ||
100 | { | 58 | { | ||
101 | } | 59 | } | ||
102 | 60 | | |||
103 | void KSMServer::startActivitySession(const QString &activity) | 61 | void KSMServer::startActivitySession(const QString &activity) | ||
104 | { | 62 | { | ||
105 | d->processLater(activity, true); | 63 | d->processLater(activity, true); | ||
106 | } | 64 | } | ||
107 | 65 | | |||
108 | void KSMServer::stopActivitySession(const QString &activity) | 66 | void KSMServer::stopActivitySession(const QString &activity) | ||
109 | { | 67 | { | ||
110 | d->processLater(activity, false); | 68 | d->processLater(activity, false); | ||
111 | } | 69 | } | ||
112 | 70 | | |||
113 | void KSMServer::Private::processLater(const QString &activity, bool start) | 71 | void KSMServer::Private::processLater(const QString &activity, bool start) | ||
114 | { | 72 | { | ||
115 | if (kwin) { | 73 | if (kwin->isValid()) { | ||
116 | for (const auto &item: queue) { | 74 | for (const auto &item: queue) { | ||
117 | if (item.first == activity) { | 75 | if (item.first == activity) { | ||
118 | return; | 76 | return; | ||
119 | } | 77 | } | ||
120 | } | 78 | } | ||
121 | 79 | | |||
122 | queue << qMakePair(activity, start); | 80 | queue << qMakePair(activity, start); | ||
123 | 81 | | |||
Show All 22 Lines | 94 | { | |||
146 | makeRunning(item.second); | 104 | makeRunning(item.second); | ||
147 | 105 | | |||
148 | // Calling process again for the rest of the list | 106 | // Calling process again for the rest of the list | ||
149 | QMetaObject::invokeMethod(this, "process", Qt::QueuedConnection); | 107 | QMetaObject::invokeMethod(this, "process", Qt::QueuedConnection); | ||
150 | } | 108 | } | ||
151 | 109 | | |||
152 | void KSMServer::Private::makeRunning(bool value) | 110 | void KSMServer::Private::makeRunning(bool value) | ||
153 | { | 111 | { | ||
154 | if (!kwin) { | 112 | if (!kwin->isValid()) { | ||
155 | qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: No kwin, marking activity as: " << value; | 113 | qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: No kwin, marking activity as: " << value; | ||
156 | subSessionSendEvent(value ? KSMServer::Started : KSMServer::Stopped); | 114 | subSessionSendEvent(value ? KSMServer::Started : KSMServer::Stopped); | ||
157 | return; | 115 | return; | ||
158 | } | 116 | } | ||
159 | 117 | | |||
160 | const auto call = kwin->asyncCall( | 118 | const auto call = kwin->asyncCall( | ||
161 | value ? QLatin1String("startActivity") : QLatin1String("stopActivity"), | 119 | value ? QLatin1String("startActivity") : QLatin1String("stopActivity"), | ||
162 | processingActivity); | 120 | processingActivity); | ||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |
This is also a perfect candidate for dbus xml?