2014-08-15 11:30:08 +04:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "logind.h"
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusConnectionInterface>
|
|
|
|
#include <QDBusPendingCallWatcher>
|
|
|
|
#include <QDBusServiceWatcher>
|
|
|
|
#include <QDBusUnixFileDescriptor>
|
2016-04-19 10:33:57 +03:00
|
|
|
#include <QDBusMetaType>
|
2014-08-15 11:30:08 +04:00
|
|
|
|
|
|
|
#include <sys/stat.h>
|
2017-07-30 22:30:33 +03:00
|
|
|
#include <config-kwin.h>
|
|
|
|
#if HAVE_SYS_SYSMACROS_H
|
2017-06-10 18:00:25 +03:00
|
|
|
#include <sys/sysmacros.h>
|
2017-07-30 22:30:33 +03:00
|
|
|
#endif
|
2017-07-30 22:20:36 +03:00
|
|
|
#ifndef major
|
|
|
|
#include <sys/types.h>
|
2017-06-10 18:00:25 +03:00
|
|
|
#endif
|
2017-11-19 01:25:06 +03:00
|
|
|
#include <fcntl.h>
|
2014-08-15 11:30:08 +04:00
|
|
|
#include <unistd.h>
|
2014-12-05 13:42:15 +03:00
|
|
|
#include "utils.h"
|
2014-08-15 11:30:08 +04:00
|
|
|
|
2016-04-19 10:33:57 +03:00
|
|
|
struct DBusLogindSeat {
|
|
|
|
QString name;
|
|
|
|
QDBusObjectPath path;
|
|
|
|
};
|
|
|
|
|
|
|
|
QDBusArgument &operator<<(QDBusArgument &argument, const DBusLogindSeat &seat)
|
|
|
|
{
|
|
|
|
argument.beginStructure();
|
|
|
|
argument << seat.name << seat.path ;
|
|
|
|
argument.endStructure();
|
|
|
|
return argument;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusLogindSeat &seat)
|
|
|
|
{
|
|
|
|
argument.beginStructure();
|
|
|
|
argument >> seat.name >> seat.path;
|
|
|
|
argument.endStructure();
|
|
|
|
return argument;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(DBusLogindSeat)
|
|
|
|
|
2014-08-15 11:30:08 +04:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2017-07-09 18:24:58 +03:00
|
|
|
const static QString s_login1Name = QStringLiteral("logind");
|
2014-08-15 11:30:08 +04:00
|
|
|
const static QString s_login1Service = QStringLiteral("org.freedesktop.login1");
|
|
|
|
const static QString s_login1Path = QStringLiteral("/org/freedesktop/login1");
|
|
|
|
const static QString s_login1ManagerInterface = QStringLiteral("org.freedesktop.login1.Manager");
|
2017-07-09 18:24:58 +03:00
|
|
|
const static QString s_login1SeatInterface = QStringLiteral("org.freedesktop.login1.Seat");
|
2014-08-15 11:30:08 +04:00
|
|
|
const static QString s_login1SessionInterface = QStringLiteral("org.freedesktop.login1.Session");
|
2017-07-14 14:36:48 +03:00
|
|
|
const static QString s_login1ActiveProperty = QStringLiteral("Active");
|
2017-07-09 18:24:58 +03:00
|
|
|
|
|
|
|
const static QString s_ck2Name = QStringLiteral("ConsoleKit");
|
|
|
|
const static QString s_ck2Service = QStringLiteral("org.freedesktop.ConsoleKit");
|
|
|
|
const static QString s_ck2Path = QStringLiteral("/org/freedesktop/ConsoleKit/Manager");
|
|
|
|
const static QString s_ck2ManagerInterface = QStringLiteral("org.freedesktop.ConsoleKit.Manager");
|
|
|
|
const static QString s_ck2SeatInterface = QStringLiteral("org.freedesktop.ConsoleKit.Seat");
|
|
|
|
const static QString s_ck2SessionInterface = QStringLiteral("org.freedesktop.ConsoleKit.Session");
|
2017-07-15 12:01:03 +03:00
|
|
|
const static QString s_ck2ActiveProperty = QStringLiteral("active");
|
2017-07-09 18:24:58 +03:00
|
|
|
|
2014-08-15 14:51:31 +04:00
|
|
|
const static QString s_dbusPropertiesInterface = QStringLiteral("org.freedesktop.DBus.Properties");
|
2014-08-15 11:30:08 +04:00
|
|
|
|
2017-07-09 18:24:58 +03:00
|
|
|
|
|
|
|
|
2014-08-15 11:30:08 +04:00
|
|
|
LogindIntegration *LogindIntegration::s_self = nullptr;
|
|
|
|
|
|
|
|
LogindIntegration *LogindIntegration::create(QObject *parent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!s_self);
|
|
|
|
s_self = new LogindIntegration(parent);
|
|
|
|
return s_self;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogindIntegration::LogindIntegration(const QDBusConnection &connection, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_bus(connection)
|
|
|
|
, m_connected(false)
|
|
|
|
, m_sessionControl(false)
|
2014-08-15 14:51:31 +04:00
|
|
|
, m_sessionActive(false)
|
2014-08-15 11:30:08 +04:00
|
|
|
{
|
|
|
|
// check whether the logind service is registered
|
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.DBus"),
|
|
|
|
QStringLiteral("/"),
|
|
|
|
QStringLiteral("org.freedesktop.DBus"),
|
|
|
|
QStringLiteral("ListNames"));
|
|
|
|
QDBusPendingReply<QStringList> async = m_bus.asyncCall(message);
|
|
|
|
QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(async, this);
|
|
|
|
connect(callWatcher, &QDBusPendingCallWatcher::finished, this,
|
|
|
|
[this](QDBusPendingCallWatcher *self) {
|
|
|
|
QDBusPendingReply<QStringList> reply = *self;
|
|
|
|
self->deleteLater();
|
|
|
|
if (!reply.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (reply.value().contains(s_login1Service)) {
|
2017-07-09 18:24:58 +03:00
|
|
|
setupSessionController(SessionControllerLogind);
|
|
|
|
} else if (reply.value().contains(s_ck2Service)) {
|
|
|
|
setupSessionController(SessionControllerConsoleKit);
|
2014-08-15 11:30:08 +04:00
|
|
|
}
|
2017-07-09 18:24:58 +03:00
|
|
|
|
2014-08-15 11:30:08 +04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
LogindIntegration::LogindIntegration(QObject *parent)
|
|
|
|
: LogindIntegration(QDBusConnection::systemBus(), parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LogindIntegration::~LogindIntegration()
|
|
|
|
{
|
|
|
|
s_self = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-09 18:24:58 +03:00
|
|
|
void LogindIntegration::setupSessionController(SessionController controller)
|
|
|
|
{
|
|
|
|
if (controller == SessionControllerLogind) {
|
|
|
|
// We have the logind serivce, set it up and use it
|
|
|
|
m_sessionControllerName = s_login1Name;
|
|
|
|
m_sessionControllerService = s_login1Service;
|
|
|
|
m_sessionControllerPath = s_login1Path;
|
|
|
|
m_sessionControllerManagerInterface = s_login1ManagerInterface;
|
|
|
|
m_sessionControllerSeatInterface = s_login1SeatInterface;
|
|
|
|
m_sessionControllerSessionInterface = s_login1SessionInterface;
|
2017-07-14 14:36:48 +03:00
|
|
|
m_sessionControllerActiveProperty = s_login1ActiveProperty;
|
2017-07-09 18:24:58 +03:00
|
|
|
m_logindServiceWatcher = new QDBusServiceWatcher(m_sessionControllerService,
|
|
|
|
m_bus,
|
|
|
|
QDBusServiceWatcher::WatchForUnregistration | QDBusServiceWatcher::WatchForRegistration,
|
|
|
|
this);
|
|
|
|
connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &LogindIntegration::logindServiceRegistered);
|
|
|
|
connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceUnregistered, this,
|
|
|
|
[this]() {
|
|
|
|
m_connected = false;
|
|
|
|
emit connectedChanged();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
logindServiceRegistered();
|
|
|
|
} else if (controller == SessionControllerConsoleKit) {
|
|
|
|
// We have the ConsoleKit serivce, set it up and use it
|
|
|
|
m_sessionControllerName = s_ck2Name;
|
|
|
|
m_sessionControllerService = s_ck2Service;
|
|
|
|
m_sessionControllerPath = s_ck2Path;
|
|
|
|
m_sessionControllerManagerInterface = s_ck2ManagerInterface;
|
|
|
|
m_sessionControllerSeatInterface = s_ck2SeatInterface;
|
|
|
|
m_sessionControllerSessionInterface = s_ck2SessionInterface;
|
2017-07-14 14:36:48 +03:00
|
|
|
m_sessionControllerActiveProperty = s_ck2ActiveProperty;
|
2017-07-09 18:24:58 +03:00
|
|
|
m_logindServiceWatcher = new QDBusServiceWatcher(m_sessionControllerService,
|
|
|
|
m_bus,
|
|
|
|
QDBusServiceWatcher::WatchForUnregistration | QDBusServiceWatcher::WatchForRegistration,
|
|
|
|
this);
|
|
|
|
connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &LogindIntegration::logindServiceRegistered);
|
|
|
|
connect(m_logindServiceWatcher, &QDBusServiceWatcher::serviceUnregistered, this,
|
|
|
|
[this]() {
|
|
|
|
m_connected = false;
|
|
|
|
emit connectedChanged();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
logindServiceRegistered();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:30:08 +04:00
|
|
|
void LogindIntegration::logindServiceRegistered()
|
|
|
|
{
|
2016-04-19 11:30:39 +03:00
|
|
|
const QByteArray sessionId = qgetenv("XDG_SESSION_ID");
|
|
|
|
QString methodName;
|
|
|
|
QVariantList args;
|
|
|
|
if (sessionId.isEmpty()) {
|
|
|
|
methodName = QStringLiteral("GetSessionByPID");
|
|
|
|
args << (quint32) QCoreApplication::applicationPid();
|
|
|
|
} else {
|
|
|
|
methodName = QStringLiteral("GetSession");
|
|
|
|
args << QString::fromLocal8Bit(sessionId);
|
|
|
|
}
|
2014-08-15 11:30:08 +04:00
|
|
|
// get the current session
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
|
|
|
m_sessionControllerPath,
|
|
|
|
m_sessionControllerManagerInterface,
|
2016-04-19 11:30:39 +03:00
|
|
|
methodName);
|
|
|
|
message.setArguments(args);
|
2014-08-15 11:30:08 +04:00
|
|
|
QDBusPendingReply<QDBusObjectPath> session = m_bus.asyncCall(message);
|
|
|
|
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(session, this);
|
|
|
|
connect(watcher, &QDBusPendingCallWatcher::finished, this,
|
|
|
|
[this](QDBusPendingCallWatcher *self) {
|
|
|
|
QDBusPendingReply<QDBusObjectPath> reply = *self;
|
|
|
|
self->deleteLater();
|
|
|
|
if (m_connected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!reply.isValid()) {
|
2017-07-09 18:24:58 +03:00
|
|
|
qCDebug(KWIN_CORE) << "The session is not registered with " << m_sessionControllerName << " " << reply.error().message();
|
2014-08-15 11:30:08 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_sessionPath = reply.value().path();
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Session path:" << m_sessionPath;
|
2014-08-15 11:30:08 +04:00
|
|
|
m_connected = true;
|
2014-08-15 14:51:31 +04:00
|
|
|
connectSessionPropertiesChanged();
|
2016-04-19 11:30:39 +03:00
|
|
|
// activate the session, in case we are not on it
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
2016-04-19 11:30:39 +03:00
|
|
|
m_sessionPath,
|
2017-07-09 18:24:58 +03:00
|
|
|
m_sessionControllerSessionInterface,
|
2016-04-19 11:30:39 +03:00
|
|
|
QStringLiteral("Activate"));
|
|
|
|
// blocking on purpose
|
|
|
|
m_bus.call(message);
|
2016-04-19 10:33:57 +03:00
|
|
|
getSeat();
|
2014-08-15 14:51:31 +04:00
|
|
|
getSessionActive();
|
2015-03-31 10:25:47 +03:00
|
|
|
getVirtualTerminal();
|
2014-08-15 14:51:31 +04:00
|
|
|
|
2014-08-15 11:30:08 +04:00
|
|
|
emit connectedChanged();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-08-15 14:51:31 +04:00
|
|
|
void LogindIntegration::connectSessionPropertiesChanged()
|
|
|
|
{
|
2017-07-09 18:24:58 +03:00
|
|
|
m_bus.connect(m_sessionControllerService,
|
2014-08-15 14:51:31 +04:00
|
|
|
m_sessionPath,
|
|
|
|
s_dbusPropertiesInterface,
|
|
|
|
QStringLiteral("PropertiesChanged"),
|
|
|
|
this,
|
|
|
|
SLOT(getSessionActive()));
|
2017-07-09 18:24:58 +03:00
|
|
|
m_bus.connect(m_sessionControllerService,
|
2015-03-31 10:25:47 +03:00
|
|
|
m_sessionPath,
|
|
|
|
s_dbusPropertiesInterface,
|
|
|
|
QStringLiteral("PropertiesChanged"),
|
|
|
|
this,
|
|
|
|
SLOT(getVirtualTerminal()));
|
2014-08-15 14:51:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LogindIntegration::getSessionActive()
|
|
|
|
{
|
|
|
|
if (!m_connected || m_sessionPath.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
2014-08-15 14:51:31 +04:00
|
|
|
m_sessionPath,
|
|
|
|
s_dbusPropertiesInterface,
|
|
|
|
QStringLiteral("Get"));
|
2017-07-14 14:36:48 +03:00
|
|
|
message.setArguments(QVariantList({m_sessionControllerSessionInterface, m_sessionControllerActiveProperty}));
|
2014-08-15 14:51:31 +04:00
|
|
|
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()) {
|
2017-07-09 18:24:58 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Failed to get Active Property of " << m_sessionControllerName << " session:" << reply.error().message();
|
2014-08-15 14:51:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const bool active = reply.value().toBool();
|
|
|
|
if (m_sessionActive != active) {
|
|
|
|
m_sessionActive = active;
|
|
|
|
emit sessionActiveChanged(m_sessionActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-03-31 10:25:47 +03:00
|
|
|
void LogindIntegration::getVirtualTerminal()
|
|
|
|
{
|
|
|
|
if (!m_connected || m_sessionPath.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
2015-03-31 10:25:47 +03:00
|
|
|
m_sessionPath,
|
|
|
|
s_dbusPropertiesInterface,
|
|
|
|
QStringLiteral("Get"));
|
2017-07-09 18:24:58 +03:00
|
|
|
message.setArguments(QVariantList({m_sessionControllerSessionInterface, QStringLiteral("VTNr")}));
|
2015-03-31 10:25:47 +03:00
|
|
|
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()) {
|
2017-07-09 18:24:58 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Failed to get VTNr Property of " << m_sessionControllerName << " session:" << reply.error().message();
|
2015-03-31 10:25:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int vt = reply.value().toUInt();
|
|
|
|
if (m_vt != (int)vt) {
|
|
|
|
m_vt = vt;
|
|
|
|
emit virtualTerminalChanged(m_vt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:30:08 +04:00
|
|
|
void LogindIntegration::takeControl()
|
|
|
|
{
|
|
|
|
if (!m_connected || m_sessionPath.isEmpty() || m_sessionControl) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-27 16:16:55 +03:00
|
|
|
static bool s_recursionCheck = false;
|
|
|
|
if (s_recursionCheck) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s_recursionCheck = true;
|
2014-08-15 11:30:08 +04:00
|
|
|
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
2014-08-15 11:30:08 +04:00
|
|
|
m_sessionPath,
|
2017-07-09 18:24:58 +03:00
|
|
|
m_sessionControllerSessionInterface,
|
2014-08-15 11:30:08 +04:00
|
|
|
QStringLiteral("TakeControl"));
|
|
|
|
message.setArguments(QVariantList({QVariant(false)}));
|
|
|
|
QDBusPendingReply<void> session = m_bus.asyncCall(message);
|
|
|
|
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(session, this);
|
|
|
|
connect(watcher, &QDBusPendingCallWatcher::finished, this,
|
|
|
|
[this](QDBusPendingCallWatcher *self) {
|
2015-03-27 16:16:55 +03:00
|
|
|
s_recursionCheck = false;
|
2014-08-15 11:30:08 +04:00
|
|
|
QDBusPendingReply<void> reply = *self;
|
|
|
|
self->deleteLater();
|
|
|
|
if (!reply.isValid()) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Failed to get session control" << reply.error().message();
|
2014-08-15 11:30:08 +04:00
|
|
|
emit hasSessionControlChanged(false);
|
|
|
|
return;
|
|
|
|
}
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Gained session control";
|
2014-08-15 11:30:08 +04:00
|
|
|
m_sessionControl = true;
|
|
|
|
emit hasSessionControlChanged(true);
|
2017-07-09 18:24:58 +03:00
|
|
|
m_bus.connect(m_sessionControllerService, m_sessionPath,
|
|
|
|
m_sessionControllerSessionInterface, QStringLiteral("PauseDevice"),
|
2015-04-15 18:54:32 +03:00
|
|
|
this, SLOT(pauseDevice(uint,uint,QString)));
|
2014-08-15 11:30:08 +04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogindIntegration::releaseControl()
|
|
|
|
{
|
|
|
|
if (!m_connected || m_sessionPath.isEmpty() || !m_sessionControl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
2014-08-15 11:30:08 +04:00
|
|
|
m_sessionPath,
|
2017-07-09 18:24:58 +03:00
|
|
|
m_sessionControllerSessionInterface,
|
2014-08-15 11:30:08 +04:00
|
|
|
QStringLiteral("ReleaseControl"));
|
|
|
|
m_bus.asyncCall(message);
|
|
|
|
m_sessionControl = false;
|
|
|
|
emit hasSessionControlChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
int LogindIntegration::takeDevice(const char *path)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
if (stat(path, &st) < 0) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Could not stat the path";
|
2014-08-15 11:30:08 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
2014-08-15 11:30:08 +04:00
|
|
|
m_sessionPath,
|
2017-07-09 18:24:58 +03:00
|
|
|
m_sessionControllerSessionInterface,
|
2014-08-15 11:30:08 +04:00
|
|
|
QStringLiteral("TakeDevice"));
|
|
|
|
message.setArguments(QVariantList({QVariant(major(st.st_rdev)), QVariant(minor(st.st_rdev))}));
|
|
|
|
// intended to be a blocking call
|
|
|
|
QDBusMessage reply = m_bus.call(message);
|
|
|
|
if (reply.type() == QDBusMessage::ErrorMessage) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Could not take device" << path << ", cause: " << reply.errorMessage();
|
2014-08-15 11:30:08 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2017-11-19 01:25:06 +03:00
|
|
|
|
|
|
|
// The dup syscall removes the CLOEXEC flag as a side-effect. So use fcntl's F_DUPFD_CLOEXEC cmd.
|
|
|
|
return fcntl(reply.arguments().first().value<QDBusUnixFileDescriptor>().fileDescriptor(), F_DUPFD_CLOEXEC, 0);
|
2014-08-15 11:30:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LogindIntegration::releaseDevice(int fd)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
if (fstat(fd, &st) < 0) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Could not stat the file descriptor";
|
2014-08-15 11:30:08 +04:00
|
|
|
return;
|
|
|
|
}
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
2014-08-15 11:30:08 +04:00
|
|
|
m_sessionPath,
|
2017-07-09 18:24:58 +03:00
|
|
|
m_sessionControllerSessionInterface,
|
2014-08-15 11:30:08 +04:00
|
|
|
QStringLiteral("ReleaseDevice"));
|
|
|
|
message.setArguments(QVariantList({QVariant(major(st.st_rdev)), QVariant(minor(st.st_rdev))}));
|
|
|
|
m_bus.asyncCall(message);
|
|
|
|
}
|
|
|
|
|
2015-04-15 18:54:32 +03:00
|
|
|
void LogindIntegration::pauseDevice(uint devMajor, uint devMinor, const QString &type)
|
|
|
|
{
|
|
|
|
if (QString::compare(type, QStringLiteral("pause"), Qt::CaseInsensitive) == 0) {
|
|
|
|
// unconditionally call complete
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService, m_sessionPath, m_sessionControllerSessionInterface, QStringLiteral("PauseDeviceComplete"));
|
2015-04-15 18:54:32 +03:00
|
|
|
message.setArguments(QVariantList({QVariant(devMajor), QVariant(devMinor)}));
|
|
|
|
m_bus.asyncCall(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-19 10:33:57 +03:00
|
|
|
void LogindIntegration::getSeat()
|
|
|
|
{
|
|
|
|
if (m_sessionPath.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qDBusRegisterMetaType<DBusLogindSeat>();
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
2016-04-19 10:33:57 +03:00
|
|
|
m_sessionPath,
|
|
|
|
s_dbusPropertiesInterface,
|
|
|
|
QStringLiteral("Get"));
|
2017-07-09 18:24:58 +03:00
|
|
|
message.setArguments(QVariantList({m_sessionControllerSessionInterface, QStringLiteral("Seat")}));
|
|
|
|
message.setArguments(QVariantList({m_sessionControllerSessionInterface, QStringLiteral("Seat")}));
|
2016-04-19 10:33:57 +03:00
|
|
|
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()) {
|
2017-07-09 18:24:58 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Failed to get Seat Property of " << m_sessionControllerName << " session:" << reply.error().message();
|
2016-04-19 10:33:57 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
DBusLogindSeat seat = qdbus_cast<DBusLogindSeat>(reply.value().value<QDBusArgument>());
|
|
|
|
const QString seatPath = seat.path.path();
|
2017-07-09 18:24:58 +03:00
|
|
|
qCDebug(KWIN_CORE) << m_sessionControllerName << " seat:" << seat.name << "/" << seatPath;
|
|
|
|
qCDebug(KWIN_CORE) << m_sessionControllerName << " seat:" << seat.name << "/" << seatPath;
|
2016-04-19 10:33:57 +03:00
|
|
|
if (m_seatPath != seatPath) {
|
|
|
|
m_seatPath = seatPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-19 10:36:28 +03:00
|
|
|
void LogindIntegration::switchVirtualTerminal(quint32 vtNr)
|
|
|
|
{
|
|
|
|
if (!m_connected || m_seatPath.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-09 18:24:58 +03:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall(m_sessionControllerService,
|
2016-04-19 10:36:28 +03:00
|
|
|
m_seatPath,
|
2017-07-09 18:24:58 +03:00
|
|
|
m_sessionControllerSeatInterface,
|
2016-04-19 10:36:28 +03:00
|
|
|
QStringLiteral("SwitchTo"));
|
|
|
|
message.setArguments(QVariantList{vtNr});
|
|
|
|
m_bus.asyncCall(message);
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:30:08 +04:00
|
|
|
} // namespace
|