kwin/src/session.cpp
Vlad Zahorodnii ade861d6de Refactor session code
At the moment, the session code is far from being extensible. If we
decide to add support for libseatd, it will be a challenging task with
the current design of session management code. The goal of this
refactoring is to fix that.

Another motivation behind this change is to prepare session related code
for upstreaming to kwayland-server where it belongs.
2021-03-23 08:01:19 +00:00

52 lines
1.2 KiB
C++

/*
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "session.h"
#include "session_consolekit.h"
#include "session_direct.h"
#include "session_logind.h"
#include "session_noop.h"
namespace KWin
{
static const struct {
Session::Type type;
std::function<Session *(QObject *)> createFunc;
} s_availableSessions[] = {
{ Session::Type::Logind, &LogindSession::create },
{ Session::Type::ConsoleKit, &ConsoleKitSession::create },
{ Session::Type::Direct, &DirectSession::create },
{ Session::Type::Noop, &NoopSession::create },
};
Session::Session(QObject *parent)
: QObject(parent)
{
}
Session *Session::create(QObject *parent)
{
for (const auto &sessionInfo : s_availableSessions) {
Session *session = sessionInfo.createFunc(parent);
if (session) {
return session;
}
}
return nullptr;
}
Session *Session::create(Type type, QObject *parent)
{
for (const auto &sessionInfo : s_availableSessions) {
if (sessionInfo.type == type) {
return sessionInfo.createFunc(parent);
}
}
return nullptr;
}
} // namespace KWin