[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; m_connected = true;
connectSessionPropertiesChanged(); connectSessionPropertiesChanged();
getSessionActive(); getSessionActive();
getVirtualTerminal();
emit connectedChanged(); emit connectedChanged();
} }
@ -139,6 +140,12 @@ void LogindIntegration::connectSessionPropertiesChanged()
QStringLiteral("PropertiesChanged"), QStringLiteral("PropertiesChanged"),
this, this,
SLOT(getSessionActive())); SLOT(getSessionActive()));
m_bus.connect(s_login1Service,
m_sessionPath,
s_dbusPropertiesInterface,
QStringLiteral("PropertiesChanged"),
this,
SLOT(getVirtualTerminal()));
} }
void LogindIntegration::getSessionActive() 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() void LogindIntegration::takeControl()
{ {
if (!m_connected || m_sessionPath.isEmpty() || m_sessionControl) { if (!m_connected || m_sessionPath.isEmpty() || m_sessionControl) {

View file

@ -45,6 +45,9 @@ public:
bool isActiveSession() const { bool isActiveSession() const {
return m_sessionActive; return m_sessionActive;
} }
int vt() const {
return m_vt;
}
void takeControl(); void takeControl();
void releaseControl(); void releaseControl();
@ -56,9 +59,11 @@ Q_SIGNALS:
void connectedChanged(); void connectedChanged();
void hasSessionControlChanged(bool); void hasSessionControlChanged(bool);
void sessionActiveChanged(bool); void sessionActiveChanged(bool);
void virtualTerminalChanged(int);
private Q_SLOTS: private Q_SLOTS:
void getSessionActive(); void getSessionActive();
void getVirtualTerminal();
private: private:
friend class LogindTest; friend class LogindTest;
@ -77,6 +82,7 @@ private:
QString m_sessionPath; QString m_sessionPath;
bool m_sessionControl; bool m_sessionControl;
bool m_sessionActive; bool m_sessionActive;
int m_vt = -1;
KWIN_SINGLETON(LogindIntegration) KWIN_SINGLETON(LogindIntegration)
}; };