Changeset View
Changeset View
Standalone View
Standalone View
logind.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 49 | { | |||
---|---|---|---|---|---|
53 | return argument; | 53 | return argument; | ||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | Q_DECLARE_METATYPE(DBusLogindSeat) | 56 | Q_DECLARE_METATYPE(DBusLogindSeat) | ||
57 | 57 | | |||
58 | namespace KWin | 58 | namespace KWin | ||
59 | { | 59 | { | ||
60 | 60 | | |||
61 | const static QString s_login1Name = QStringLiteral("logind"); | ||||
61 | const static QString s_login1Service = QStringLiteral("org.freedesktop.login1"); | 62 | const static QString s_login1Service = QStringLiteral("org.freedesktop.login1"); | ||
62 | const static QString s_login1Path = QStringLiteral("/org/freedesktop/login1"); | 63 | const static QString s_login1Path = QStringLiteral("/org/freedesktop/login1"); | ||
63 | const static QString s_login1ManagerInterface = QStringLiteral("org.freedesktop.login1.Manager"); | 64 | const static QString s_login1ManagerInterface = QStringLiteral("org.freedesktop.login1.Manager"); | ||
65 | const static QString s_login1SeatInterface = QStringLiteral("org.freedesktop.login1.Seat"); | ||||
64 | const static QString s_login1SessionInterface = QStringLiteral("org.freedesktop.login1.Session"); | 66 | const static QString s_login1SessionInterface = QStringLiteral("org.freedesktop.login1.Session"); | ||
67 | const static QString s_login1ActivateProperty = QStringLiteral("Activate"); | ||||
68 | | ||||
69 | const static QString s_ck2Name = QStringLiteral("ConsoleKit"); | ||||
70 | const static QString s_ck2Service = QStringLiteral("org.freedesktop.ConsoleKit"); | ||||
71 | const static QString s_ck2Path = QStringLiteral("/org/freedesktop/ConsoleKit/Manager"); | ||||
72 | const static QString s_ck2ManagerInterface = QStringLiteral("org.freedesktop.ConsoleKit.Manager"); | ||||
73 | const static QString s_ck2SeatInterface = QStringLiteral("org.freedesktop.ConsoleKit.Seat"); | ||||
74 | const static QString s_ck2SessionInterface = QStringLiteral("org.freedesktop.ConsoleKit.Session"); | ||||
75 | const static QString s_ck2ActivateProperty = QStringLiteral("activate"); | ||||
76 | | ||||
65 | const static QString s_dbusPropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); | 77 | const static QString s_dbusPropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties"); | ||
66 | 78 | | |||
79 | | ||||
80 | | ||||
67 | LogindIntegration *LogindIntegration::s_self = nullptr; | 81 | LogindIntegration *LogindIntegration::s_self = nullptr; | ||
68 | 82 | | |||
69 | LogindIntegration *LogindIntegration::create(QObject *parent) | 83 | LogindIntegration *LogindIntegration::create(QObject *parent) | ||
70 | { | 84 | { | ||
71 | Q_ASSERT(!s_self); | 85 | Q_ASSERT(!s_self); | ||
72 | s_self = new LogindIntegration(parent); | 86 | s_self = new LogindIntegration(parent); | ||
73 | return s_self; | 87 | return s_self; | ||
74 | } | 88 | } | ||
75 | 89 | | |||
76 | LogindIntegration::LogindIntegration(const QDBusConnection &connection, QObject *parent) | 90 | LogindIntegration::LogindIntegration(const QDBusConnection &connection, QObject *parent) | ||
77 | : QObject(parent) | 91 | : QObject(parent) | ||
78 | , m_bus(connection) | 92 | , m_bus(connection) | ||
79 | , m_logindServiceWatcher(new QDBusServiceWatcher(s_login1Service, | | |||
80 | m_bus, | | |||
81 | QDBusServiceWatcher::WatchForUnregistration | QDBusServiceWatcher::WatchForRegistration, | | |||
82 | this)) | | |||
83 | , m_connected(false) | 93 | , m_connected(false) | ||
84 | , m_sessionControl(false) | 94 | , m_sessionControl(false) | ||
85 | , m_sessionActive(false) | 95 | , m_sessionActive(false) | ||
86 | { | 96 | { | ||
87 | connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &LogindIntegration::logindServiceRegistered); | | |||
88 | connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, | | |||
89 | [this]() { | | |||
90 | m_connected = false; | | |||
91 | emit connectedChanged(); | | |||
92 | } | | |||
93 | ); | | |||
94 | | ||||
95 | // check whether the logind service is registered | 97 | // check whether the logind service is registered | ||
96 | QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.DBus"), | 98 | QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.DBus"), | ||
97 | QStringLiteral("/"), | 99 | QStringLiteral("/"), | ||
98 | QStringLiteral("org.freedesktop.DBus"), | 100 | QStringLiteral("org.freedesktop.DBus"), | ||
99 | QStringLiteral("ListNames")); | 101 | QStringLiteral("ListNames")); | ||
100 | QDBusPendingReply<QStringList> async = m_bus.asyncCall(message); | 102 | QDBusPendingReply<QStringList> async = m_bus.asyncCall(message); | ||
101 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(async, this); | 103 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(async, this); | ||
102 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, | 104 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, | ||
103 | [this](QDBusPendingCallWatcher *self) { | 105 | [this](QDBusPendingCallWatcher *self) { | ||
104 | QDBusPendingReply<QStringList> reply = *self; | 106 | QDBusPendingReply<QStringList> reply = *self; | ||
105 | self->deleteLater(); | 107 | self->deleteLater(); | ||
106 | if (!reply.isValid()) { | 108 | if (!reply.isValid()) { | ||
107 | return; | 109 | return; | ||
108 | } | 110 | } | ||
109 | if (reply.value().contains(s_login1Service)) { | 111 | if (reply.value().contains(s_login1Service)) { | ||
110 | logindServiceRegistered(); | 112 | setupSessionController(SessionControllerLogind); | ||
113 | } else if (reply.value().contains(s_ck2Service)) { | ||||
114 | setupSessionController(SessionControllerConsoleKit); | ||||
111 | } | 115 | } | ||
116 | | ||||
112 | } | 117 | } | ||
113 | ); | 118 | ); | ||
114 | } | 119 | } | ||
115 | 120 | | |||
116 | LogindIntegration::LogindIntegration(QObject *parent) | 121 | LogindIntegration::LogindIntegration(QObject *parent) | ||
117 | : LogindIntegration(QDBusConnection::systemBus(), parent) | 122 | : LogindIntegration(QDBusConnection::systemBus(), parent) | ||
118 | { | 123 | { | ||
119 | } | 124 | } | ||
120 | 125 | | |||
121 | LogindIntegration::~LogindIntegration() | 126 | LogindIntegration::~LogindIntegration() | ||
122 | { | 127 | { | ||
123 | s_self = nullptr; | 128 | s_self = nullptr; | ||
graesslin: As this part is now basically copied I suggest to turn it into a private method and pass e.g. | |||||
124 | } | 129 | } | ||
125 | 130 | | |||
131 | void LogindIntegration::setupSessionController(SessionController controller) | ||||
132 | { | ||||
133 | if (controller == SessionControllerLogind) { | ||||
134 | // We have the logind serivce, set it up and use it | ||||
135 | m_sessionControllerName = s_login1Name; | ||||
136 | m_sessionControllerService = s_login1Service; | ||||
137 | m_sessionControllerPath = s_login1Path; | ||||
138 | m_sessionControllerManagerInterface = s_login1ManagerInterface; | ||||
139 | m_sessionControllerSeatInterface = s_login1SeatInterface; | ||||
140 | m_sessionControllerSessionInterface = s_login1SessionInterface; | ||||
141 | m_sessionControllerActivateProperty = s_login1ActivateProperty; | ||||
142 | m_logindServiceWatcher = new QDBusServiceWatcher(m_sessionControllerService, | ||||
143 | m_bus, | ||||
144 | QDBusServiceWatcher::WatchForUnregistration | QDBusServiceWatcher::WatchForRegistration, | ||||
145 | this); | ||||
146 | connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &LogindIntegration::logindServiceRegistered); | ||||
147 | connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, | ||||
148 | [this]() { | ||||
149 | m_connected = false; | ||||
150 | emit connectedChanged(); | ||||
151 | } | ||||
152 | ); | ||||
153 | logindServiceRegistered(); | ||||
154 | } else if (controller == SessionControllerConsoleKit) { | ||||
155 | // We have the ConsoleKit serivce, set it up and use it | ||||
156 | m_sessionControllerName = s_ck2Name; | ||||
157 | m_sessionControllerService = s_ck2Service; | ||||
158 | m_sessionControllerPath = s_ck2Path; | ||||
159 | m_sessionControllerManagerInterface = s_ck2ManagerInterface; | ||||
160 | m_sessionControllerSeatInterface = s_ck2SeatInterface; | ||||
161 | m_sessionControllerSessionInterface = s_ck2SessionInterface; | ||||
162 | m_sessionControllerActivateProperty = s_ck2ActivateProperty; | ||||
163 | m_logindServiceWatcher = new QDBusServiceWatcher(m_sessionControllerService, | ||||
164 | m_bus, | ||||
165 | QDBusServiceWatcher::WatchForUnregistration | QDBusServiceWatcher::WatchForRegistration, | ||||
166 | this); | ||||
167 | connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &LogindIntegration::logindServiceRegistered); | ||||
168 | connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, | ||||
169 | [this]() { | ||||
170 | m_connected = false; | ||||
171 | emit connectedChanged(); | ||||
172 | } | ||||
173 | ); | ||||
174 | logindServiceRegistered(); | ||||
175 | } | ||||
176 | } | ||||
177 | | ||||
126 | void LogindIntegration::logindServiceRegistered() | 178 | void LogindIntegration::logindServiceRegistered() | ||
127 | { | 179 | { | ||
128 | const QByteArray sessionId = qgetenv("XDG_SESSION_ID"); | 180 | const QByteArray sessionId = qgetenv("XDG_SESSION_ID"); | ||
129 | QString methodName; | 181 | QString methodName; | ||
130 | QVariantList args; | 182 | QVariantList args; | ||
131 | if (sessionId.isEmpty()) { | 183 | if (sessionId.isEmpty()) { | ||
132 | methodName = QStringLiteral("GetSessionByPID"); | 184 | methodName = QStringLiteral("GetSessionByPID"); | ||
133 | args << (quint32) QCoreApplication::applicationPid(); | 185 | args << (quint32) QCoreApplication::applicationPid(); | ||
134 | } else { | 186 | } else { | ||
135 | methodName = QStringLiteral("GetSession"); | 187 | methodName = QStringLiteral("GetSession"); | ||
136 | args << QString::fromLocal8Bit(sessionId); | 188 | args << QString::fromLocal8Bit(sessionId); | ||
137 | } | 189 | } | ||
138 | // get the current session | 190 | // get the current session | ||
139 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 191 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
140 | s_login1Path, | 192 | m_sessionControllerPath, | ||
141 | s_login1ManagerInterface, | 193 | m_sessionControllerManagerInterface, | ||
142 | methodName); | 194 | methodName); | ||
143 | message.setArguments(args); | 195 | message.setArguments(args); | ||
144 | QDBusPendingReply<QDBusObjectPath> session = m_bus.asyncCall(message); | 196 | QDBusPendingReply<QDBusObjectPath> session = m_bus.asyncCall(message); | ||
145 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(session, this); | 197 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(session, this); | ||
146 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | 198 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | ||
147 | [this](QDBusPendingCallWatcher *self) { | 199 | [this](QDBusPendingCallWatcher *self) { | ||
148 | QDBusPendingReply<QDBusObjectPath> reply = *self; | 200 | QDBusPendingReply<QDBusObjectPath> reply = *self; | ||
149 | self->deleteLater(); | 201 | self->deleteLater(); | ||
150 | if (m_connected) { | 202 | if (m_connected) { | ||
151 | return; | 203 | return; | ||
152 | } | 204 | } | ||
153 | if (!reply.isValid()) { | 205 | if (!reply.isValid()) { | ||
154 | qCDebug(KWIN_CORE) << "The session is not registered with logind" << reply.error().message(); | 206 | qCDebug(KWIN_CORE) << "The session is not registered with " << m_sessionControllerName << " " << reply.error().message(); | ||
155 | return; | 207 | return; | ||
156 | } | 208 | } | ||
157 | m_sessionPath = reply.value().path(); | 209 | m_sessionPath = reply.value().path(); | ||
158 | qCDebug(KWIN_CORE) << "Session path:" << m_sessionPath; | 210 | qCDebug(KWIN_CORE) << "Session path:" << m_sessionPath; | ||
159 | m_connected = true; | 211 | m_connected = true; | ||
160 | connectSessionPropertiesChanged(); | 212 | connectSessionPropertiesChanged(); | ||
161 | // activate the session, in case we are not on it | 213 | // activate the session, in case we are not on it | ||
162 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 214 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
163 | m_sessionPath, | 215 | m_sessionPath, | ||
164 | s_login1SessionInterface, | 216 | m_sessionControllerSessionInterface, | ||
165 | QStringLiteral("Activate")); | 217 | QStringLiteral("Activate")); | ||
166 | // blocking on purpose | 218 | // blocking on purpose | ||
167 | m_bus.call(message); | 219 | m_bus.call(message); | ||
168 | getSeat(); | 220 | getSeat(); | ||
169 | getSessionActive(); | 221 | getSessionActive(); | ||
170 | getVirtualTerminal(); | 222 | getVirtualTerminal(); | ||
171 | 223 | | |||
172 | emit connectedChanged(); | 224 | emit connectedChanged(); | ||
173 | } | 225 | } | ||
174 | ); | 226 | ); | ||
175 | } | 227 | } | ||
176 | 228 | | |||
177 | void LogindIntegration::connectSessionPropertiesChanged() | 229 | void LogindIntegration::connectSessionPropertiesChanged() | ||
178 | { | 230 | { | ||
179 | m_bus.connect(s_login1Service, | 231 | m_bus.connect(m_sessionControllerService, | ||
180 | m_sessionPath, | 232 | m_sessionPath, | ||
181 | s_dbusPropertiesInterface, | 233 | s_dbusPropertiesInterface, | ||
182 | QStringLiteral("PropertiesChanged"), | 234 | QStringLiteral("PropertiesChanged"), | ||
183 | this, | 235 | this, | ||
184 | SLOT(getSessionActive())); | 236 | SLOT(getSessionActive())); | ||
185 | m_bus.connect(s_login1Service, | 237 | m_bus.connect(m_sessionControllerService, | ||
186 | m_sessionPath, | 238 | m_sessionPath, | ||
187 | s_dbusPropertiesInterface, | 239 | s_dbusPropertiesInterface, | ||
188 | QStringLiteral("PropertiesChanged"), | 240 | QStringLiteral("PropertiesChanged"), | ||
189 | this, | 241 | this, | ||
190 | SLOT(getVirtualTerminal())); | 242 | SLOT(getVirtualTerminal())); | ||
191 | } | 243 | } | ||
192 | 244 | | |||
193 | void LogindIntegration::getSessionActive() | 245 | void LogindIntegration::getSessionActive() | ||
194 | { | 246 | { | ||
195 | if (!m_connected || m_sessionPath.isEmpty()) { | 247 | if (!m_connected || m_sessionPath.isEmpty()) { | ||
196 | return; | 248 | return; | ||
197 | } | 249 | } | ||
198 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 250 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
199 | m_sessionPath, | 251 | m_sessionPath, | ||
200 | s_dbusPropertiesInterface, | 252 | s_dbusPropertiesInterface, | ||
201 | QStringLiteral("Get")); | 253 | QStringLiteral("Get")); | ||
202 | message.setArguments(QVariantList({s_login1SessionInterface, QStringLiteral("Active")})); | 254 | message.setArguments(QVariantList({m_sessionControllerSessionInterface, m_sessionControllerActivateProperty})); | ||
203 | QDBusPendingReply<QVariant> reply = m_bus.asyncCall(message); | 255 | QDBusPendingReply<QVariant> reply = m_bus.asyncCall(message); | ||
204 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | 256 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | ||
205 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | 257 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | ||
206 | [this](QDBusPendingCallWatcher *self) { | 258 | [this](QDBusPendingCallWatcher *self) { | ||
207 | QDBusPendingReply<QVariant> reply = *self; | 259 | QDBusPendingReply<QVariant> reply = *self; | ||
208 | self->deleteLater(); | 260 | self->deleteLater(); | ||
209 | if (!reply.isValid()) { | 261 | if (!reply.isValid()) { | ||
210 | qCDebug(KWIN_CORE) << "Failed to get Active Property of logind session:" << reply.error().message(); | 262 | qCDebug(KWIN_CORE) << "Failed to get Active Property of " << m_sessionControllerName << " session:" << reply.error().message(); | ||
211 | return; | 263 | return; | ||
212 | } | 264 | } | ||
213 | const bool active = reply.value().toBool(); | 265 | const bool active = reply.value().toBool(); | ||
214 | if (m_sessionActive != active) { | 266 | if (m_sessionActive != active) { | ||
215 | m_sessionActive = active; | 267 | m_sessionActive = active; | ||
216 | emit sessionActiveChanged(m_sessionActive); | 268 | emit sessionActiveChanged(m_sessionActive); | ||
217 | } | 269 | } | ||
218 | } | 270 | } | ||
219 | ); | 271 | ); | ||
220 | } | 272 | } | ||
221 | 273 | | |||
222 | void LogindIntegration::getVirtualTerminal() | 274 | void LogindIntegration::getVirtualTerminal() | ||
223 | { | 275 | { | ||
224 | if (!m_connected || m_sessionPath.isEmpty()) { | 276 | if (!m_connected || m_sessionPath.isEmpty()) { | ||
225 | return; | 277 | return; | ||
226 | } | 278 | } | ||
227 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 279 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
228 | m_sessionPath, | 280 | m_sessionPath, | ||
229 | s_dbusPropertiesInterface, | 281 | s_dbusPropertiesInterface, | ||
230 | QStringLiteral("Get")); | 282 | QStringLiteral("Get")); | ||
231 | message.setArguments(QVariantList({s_login1SessionInterface, QStringLiteral("VTNr")})); | 283 | message.setArguments(QVariantList({m_sessionControllerSessionInterface, QStringLiteral("VTNr")})); | ||
232 | QDBusPendingReply<QVariant> reply = m_bus.asyncCall(message); | 284 | QDBusPendingReply<QVariant> reply = m_bus.asyncCall(message); | ||
233 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | 285 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | ||
234 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | 286 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | ||
235 | [this](QDBusPendingCallWatcher *self) { | 287 | [this](QDBusPendingCallWatcher *self) { | ||
236 | QDBusPendingReply<QVariant> reply = *self; | 288 | QDBusPendingReply<QVariant> reply = *self; | ||
237 | self->deleteLater(); | 289 | self->deleteLater(); | ||
238 | if (!reply.isValid()) { | 290 | if (!reply.isValid()) { | ||
239 | qCDebug(KWIN_CORE) << "Failed to get VTNr Property of logind session:" << reply.error().message(); | 291 | qCDebug(KWIN_CORE) << "Failed to get VTNr Property of " << m_sessionControllerName << " session:" << reply.error().message(); | ||
240 | return; | 292 | return; | ||
241 | } | 293 | } | ||
242 | const int vt = reply.value().toUInt(); | 294 | const int vt = reply.value().toUInt(); | ||
243 | if (m_vt != (int)vt) { | 295 | if (m_vt != (int)vt) { | ||
244 | m_vt = vt; | 296 | m_vt = vt; | ||
245 | emit virtualTerminalChanged(m_vt); | 297 | emit virtualTerminalChanged(m_vt); | ||
246 | } | 298 | } | ||
247 | } | 299 | } | ||
248 | ); | 300 | ); | ||
249 | } | 301 | } | ||
250 | 302 | | |||
251 | void LogindIntegration::takeControl() | 303 | void LogindIntegration::takeControl() | ||
252 | { | 304 | { | ||
253 | if (!m_connected || m_sessionPath.isEmpty() || m_sessionControl) { | 305 | if (!m_connected || m_sessionPath.isEmpty() || m_sessionControl) { | ||
254 | return; | 306 | return; | ||
255 | } | 307 | } | ||
256 | static bool s_recursionCheck = false; | 308 | static bool s_recursionCheck = false; | ||
257 | if (s_recursionCheck) { | 309 | if (s_recursionCheck) { | ||
258 | return; | 310 | return; | ||
259 | } | 311 | } | ||
260 | s_recursionCheck = true; | 312 | s_recursionCheck = true; | ||
261 | 313 | | |||
262 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 314 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
263 | m_sessionPath, | 315 | m_sessionPath, | ||
264 | s_login1SessionInterface, | 316 | m_sessionControllerSessionInterface, | ||
265 | QStringLiteral("TakeControl")); | 317 | QStringLiteral("TakeControl")); | ||
266 | message.setArguments(QVariantList({QVariant(false)})); | 318 | message.setArguments(QVariantList({QVariant(false)})); | ||
267 | QDBusPendingReply<void> session = m_bus.asyncCall(message); | 319 | QDBusPendingReply<void> session = m_bus.asyncCall(message); | ||
268 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(session, this); | 320 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(session, this); | ||
269 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | 321 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | ||
270 | [this](QDBusPendingCallWatcher *self) { | 322 | [this](QDBusPendingCallWatcher *self) { | ||
271 | s_recursionCheck = false; | 323 | s_recursionCheck = false; | ||
272 | QDBusPendingReply<void> reply = *self; | 324 | QDBusPendingReply<void> reply = *self; | ||
273 | self->deleteLater(); | 325 | self->deleteLater(); | ||
274 | if (!reply.isValid()) { | 326 | if (!reply.isValid()) { | ||
275 | qCDebug(KWIN_CORE) << "Failed to get session control" << reply.error().message(); | 327 | qCDebug(KWIN_CORE) << "Failed to get session control" << reply.error().message(); | ||
276 | emit hasSessionControlChanged(false); | 328 | emit hasSessionControlChanged(false); | ||
277 | return; | 329 | return; | ||
278 | } | 330 | } | ||
279 | qCDebug(KWIN_CORE) << "Gained session control"; | 331 | qCDebug(KWIN_CORE) << "Gained session control"; | ||
280 | m_sessionControl = true; | 332 | m_sessionControl = true; | ||
281 | emit hasSessionControlChanged(true); | 333 | emit hasSessionControlChanged(true); | ||
282 | m_bus.connect(s_login1Service, m_sessionPath, | 334 | m_bus.connect(m_sessionControllerService, m_sessionPath, | ||
283 | s_login1SessionInterface, QStringLiteral("PauseDevice"), | 335 | m_sessionControllerSessionInterface, QStringLiteral("PauseDevice"), | ||
284 | this, SLOT(pauseDevice(uint,uint,QString))); | 336 | this, SLOT(pauseDevice(uint,uint,QString))); | ||
285 | } | 337 | } | ||
286 | ); | 338 | ); | ||
287 | } | 339 | } | ||
288 | 340 | | |||
289 | void LogindIntegration::releaseControl() | 341 | void LogindIntegration::releaseControl() | ||
290 | { | 342 | { | ||
291 | if (!m_connected || m_sessionPath.isEmpty() || !m_sessionControl) { | 343 | if (!m_connected || m_sessionPath.isEmpty() || !m_sessionControl) { | ||
292 | return; | 344 | return; | ||
293 | } | 345 | } | ||
294 | 346 | | |||
295 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 347 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
296 | m_sessionPath, | 348 | m_sessionPath, | ||
297 | s_login1SessionInterface, | 349 | m_sessionControllerSessionInterface, | ||
298 | QStringLiteral("ReleaseControl")); | 350 | QStringLiteral("ReleaseControl")); | ||
299 | m_bus.asyncCall(message); | 351 | m_bus.asyncCall(message); | ||
300 | m_sessionControl = false; | 352 | m_sessionControl = false; | ||
301 | emit hasSessionControlChanged(false); | 353 | emit hasSessionControlChanged(false); | ||
302 | } | 354 | } | ||
303 | 355 | | |||
304 | int LogindIntegration::takeDevice(const char *path) | 356 | int LogindIntegration::takeDevice(const char *path) | ||
305 | { | 357 | { | ||
306 | struct stat st; | 358 | struct stat st; | ||
307 | if (stat(path, &st) < 0) { | 359 | if (stat(path, &st) < 0) { | ||
308 | qCDebug(KWIN_CORE) << "Could not stat the path"; | 360 | qCDebug(KWIN_CORE) << "Could not stat the path"; | ||
309 | return -1; | 361 | return -1; | ||
310 | } | 362 | } | ||
311 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 363 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
312 | m_sessionPath, | 364 | m_sessionPath, | ||
313 | s_login1SessionInterface, | 365 | m_sessionControllerSessionInterface, | ||
314 | QStringLiteral("TakeDevice")); | 366 | QStringLiteral("TakeDevice")); | ||
315 | message.setArguments(QVariantList({QVariant(major(st.st_rdev)), QVariant(minor(st.st_rdev))})); | 367 | message.setArguments(QVariantList({QVariant(major(st.st_rdev)), QVariant(minor(st.st_rdev))})); | ||
316 | // intended to be a blocking call | 368 | // intended to be a blocking call | ||
317 | QDBusMessage reply = m_bus.call(message); | 369 | QDBusMessage reply = m_bus.call(message); | ||
318 | if (reply.type() == QDBusMessage::ErrorMessage) { | 370 | if (reply.type() == QDBusMessage::ErrorMessage) { | ||
319 | qCDebug(KWIN_CORE) << "Could not take device" << path << ", cause: " << reply.errorMessage(); | 371 | qCDebug(KWIN_CORE) << "Could not take device" << path << ", cause: " << reply.errorMessage(); | ||
320 | return -1; | 372 | return -1; | ||
321 | } | 373 | } | ||
322 | return dup(reply.arguments().first().value<QDBusUnixFileDescriptor>().fileDescriptor()); | 374 | return dup(reply.arguments().first().value<QDBusUnixFileDescriptor>().fileDescriptor()); | ||
323 | } | 375 | } | ||
324 | 376 | | |||
325 | void LogindIntegration::releaseDevice(int fd) | 377 | void LogindIntegration::releaseDevice(int fd) | ||
326 | { | 378 | { | ||
327 | struct stat st; | 379 | struct stat st; | ||
328 | if (fstat(fd, &st) < 0) { | 380 | if (fstat(fd, &st) < 0) { | ||
329 | qCDebug(KWIN_CORE) << "Could not stat the file descriptor"; | 381 | qCDebug(KWIN_CORE) << "Could not stat the file descriptor"; | ||
330 | return; | 382 | return; | ||
331 | } | 383 | } | ||
332 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 384 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
333 | m_sessionPath, | 385 | m_sessionPath, | ||
334 | s_login1SessionInterface, | 386 | m_sessionControllerSessionInterface, | ||
335 | QStringLiteral("ReleaseDevice")); | 387 | QStringLiteral("ReleaseDevice")); | ||
336 | message.setArguments(QVariantList({QVariant(major(st.st_rdev)), QVariant(minor(st.st_rdev))})); | 388 | message.setArguments(QVariantList({QVariant(major(st.st_rdev)), QVariant(minor(st.st_rdev))})); | ||
337 | m_bus.asyncCall(message); | 389 | m_bus.asyncCall(message); | ||
338 | } | 390 | } | ||
339 | 391 | | |||
340 | void LogindIntegration::pauseDevice(uint devMajor, uint devMinor, const QString &type) | 392 | void LogindIntegration::pauseDevice(uint devMajor, uint devMinor, const QString &type) | ||
341 | { | 393 | { | ||
342 | if (QString::compare(type, QStringLiteral("pause"), Qt::CaseInsensitive) == 0) { | 394 | if (QString::compare(type, QStringLiteral("pause"), Qt::CaseInsensitive) == 0) { | ||
343 | // unconditionally call complete | 395 | // unconditionally call complete | ||
344 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, m_sessionPath, s_login1SessionInterface, QStringLiteral("PauseDeviceComplete")); | 396 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, m_sessionPath, m_sessionControllerSessionInterface, QStringLiteral("PauseDeviceComplete")); | ||
345 | message.setArguments(QVariantList({QVariant(devMajor), QVariant(devMinor)})); | 397 | message.setArguments(QVariantList({QVariant(devMajor), QVariant(devMinor)})); | ||
346 | m_bus.asyncCall(message); | 398 | m_bus.asyncCall(message); | ||
347 | } | 399 | } | ||
348 | } | 400 | } | ||
349 | 401 | | |||
350 | void LogindIntegration::getSeat() | 402 | void LogindIntegration::getSeat() | ||
351 | { | 403 | { | ||
352 | if (m_sessionPath.isEmpty()) { | 404 | if (m_sessionPath.isEmpty()) { | ||
353 | return; | 405 | return; | ||
354 | } | 406 | } | ||
355 | qDBusRegisterMetaType<DBusLogindSeat>(); | 407 | qDBusRegisterMetaType<DBusLogindSeat>(); | ||
356 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 408 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
357 | m_sessionPath, | 409 | m_sessionPath, | ||
358 | s_dbusPropertiesInterface, | 410 | s_dbusPropertiesInterface, | ||
359 | QStringLiteral("Get")); | 411 | QStringLiteral("Get")); | ||
360 | message.setArguments(QVariantList({s_login1SessionInterface, QStringLiteral("Seat")})); | 412 | message.setArguments(QVariantList({m_sessionControllerSessionInterface, QStringLiteral("Seat")})); | ||
413 | message.setArguments(QVariantList({m_sessionControllerSessionInterface, QStringLiteral("Seat")})); | ||||
361 | QDBusPendingReply<QVariant> reply = m_bus.asyncCall(message); | 414 | QDBusPendingReply<QVariant> reply = m_bus.asyncCall(message); | ||
362 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | 415 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | ||
363 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | 416 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | ||
364 | [this](QDBusPendingCallWatcher *self) { | 417 | [this](QDBusPendingCallWatcher *self) { | ||
365 | QDBusPendingReply<QVariant> reply = *self; | 418 | QDBusPendingReply<QVariant> reply = *self; | ||
366 | self->deleteLater(); | 419 | self->deleteLater(); | ||
367 | if (!reply.isValid()) { | 420 | if (!reply.isValid()) { | ||
368 | qCDebug(KWIN_CORE) << "Failed to get Seat Property of logind session:" << reply.error().message(); | 421 | qCDebug(KWIN_CORE) << "Failed to get Seat Property of " << m_sessionControllerName << " session:" << reply.error().message(); | ||
369 | return; | 422 | return; | ||
370 | } | 423 | } | ||
371 | DBusLogindSeat seat = qdbus_cast<DBusLogindSeat>(reply.value().value<QDBusArgument>()); | 424 | DBusLogindSeat seat = qdbus_cast<DBusLogindSeat>(reply.value().value<QDBusArgument>()); | ||
372 | const QString seatPath = seat.path.path(); | 425 | const QString seatPath = seat.path.path(); | ||
373 | qCDebug(KWIN_CORE) << "Logind seat:" << seat.name << "/" << seatPath; | 426 | qCDebug(KWIN_CORE) << m_sessionControllerName << " seat:" << seat.name << "/" << seatPath; | ||
427 | qCDebug(KWIN_CORE) << m_sessionControllerName << " seat:" << seat.name << "/" << seatPath; | ||||
374 | if (m_seatPath != seatPath) { | 428 | if (m_seatPath != seatPath) { | ||
375 | m_seatPath = seatPath; | 429 | m_seatPath = seatPath; | ||
376 | } | 430 | } | ||
377 | } | 431 | } | ||
378 | ); | 432 | ); | ||
379 | } | 433 | } | ||
380 | 434 | | |||
381 | void LogindIntegration::switchVirtualTerminal(quint32 vtNr) | 435 | void LogindIntegration::switchVirtualTerminal(quint32 vtNr) | ||
382 | { | 436 | { | ||
383 | if (!m_connected || m_seatPath.isEmpty()) { | 437 | if (!m_connected || m_seatPath.isEmpty()) { | ||
384 | return; | 438 | return; | ||
385 | } | 439 | } | ||
386 | QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, | 440 | QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, | ||
387 | m_seatPath, | 441 | m_seatPath, | ||
388 | QStringLiteral("org.freedesktop.login1.Seat"), | 442 | m_sessionControllerSeatInterface, | ||
389 | QStringLiteral("SwitchTo")); | 443 | QStringLiteral("SwitchTo")); | ||
390 | message.setArguments(QVariantList{vtNr}); | 444 | message.setArguments(QVariantList{vtNr}); | ||
391 | m_bus.asyncCall(message); | 445 | m_bus.asyncCall(message); | ||
392 | } | 446 | } | ||
393 | 447 | | |||
394 | } // namespace | 448 | } // namespace |
As this part is now basically copied I suggest to turn it into a private method and pass e.g. an enum to indicate whether it's logind or consolekit.