[logind] Add support for VTNr property

This commit is contained in:
Martin Gräßlin 2015-03-31 09:25:47 +02:00
parent 61579506e3
commit 3d5899cbfd
2 changed files with 42 additions and 0 deletions

View file

@ -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<QVariant> reply = m_bus.asyncCall(message);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this,
[this](QDBusPendingCallWatcher *self) {
QDBusPendingReply<QVariant> 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) {

View file

@ -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)
};