diff --git a/logind.cpp b/logind.cpp index 9596c739c1..0a2c356ac0 100644 --- a/logind.cpp +++ b/logind.cpp @@ -125,6 +125,7 @@ void LogindIntegration::logindServiceRegistered() m_connected = true; connectSessionPropertiesChanged(); getSessionActive(); + getVirtualTerminal(); emit connectedChanged(); } @@ -139,6 +140,12 @@ void LogindIntegration::connectSessionPropertiesChanged() QStringLiteral("PropertiesChanged"), this, SLOT(getSessionActive())); + m_bus.connect(s_login1Service, + m_sessionPath, + s_dbusPropertiesInterface, + QStringLiteral("PropertiesChanged"), + this, + SLOT(getVirtualTerminal())); } void LogindIntegration::getSessionActive() @@ -170,6 +177,35 @@ void LogindIntegration::getSessionActive() ); } +void LogindIntegration::getVirtualTerminal() +{ + if (!m_connected || m_sessionPath.isEmpty()) { + return; + } + QDBusMessage message = QDBusMessage::createMethodCall(s_login1Service, + m_sessionPath, + s_dbusPropertiesInterface, + QStringLiteral("Get")); + message.setArguments(QVariantList({s_login1SessionInterface, QStringLiteral("VTNr")})); + QDBusPendingReply reply = m_bus.asyncCall(message); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, &QDBusPendingCallWatcher::finished, this, + [this](QDBusPendingCallWatcher *self) { + QDBusPendingReply reply = *self; + self->deleteLater(); + if (!reply.isValid()) { + qCDebug(KWIN_CORE) << "Failed to get VTNr Property of logind session:" << reply.error().message(); + return; + } + const int vt = reply.value().toUInt(); + if (m_vt != (int)vt) { + m_vt = vt; + emit virtualTerminalChanged(m_vt); + } + } + ); +} + void LogindIntegration::takeControl() { if (!m_connected || m_sessionPath.isEmpty() || m_sessionControl) { diff --git a/logind.h b/logind.h index bc6478af67..7165990938 100644 --- a/logind.h +++ b/logind.h @@ -45,6 +45,9 @@ public: bool isActiveSession() const { return m_sessionActive; } + int vt() const { + return m_vt; + } void takeControl(); void releaseControl(); @@ -56,9 +59,11 @@ Q_SIGNALS: void connectedChanged(); void hasSessionControlChanged(bool); void sessionActiveChanged(bool); + void virtualTerminalChanged(int); private Q_SLOTS: void getSessionActive(); + void getVirtualTerminal(); private: friend class LogindTest; @@ -77,6 +82,7 @@ private: QString m_sessionPath; bool m_sessionControl; bool m_sessionActive; + int m_vt = -1; KWIN_SINGLETON(LogindIntegration) };