Commit d2f7f75d authored by Xaver Hugl's avatar Xaver Hugl
Browse files

manage Session with std::unique_ptr

parent 13d079cd
......@@ -82,7 +82,7 @@ DrmBackend::DrmBackend(QObject *parent)
: Platform(parent)
, m_udev(std::make_unique<Udev>())
, m_udevMonitor(m_udev->monitor())
, m_session(Session::create(this))
, m_session(Session::create())
, m_explicitGpus(splitPathList(qEnvironmentVariable("KWIN_DRM_DEVICES"), ':'))
, m_dpmsFilter()
{
......@@ -103,7 +103,7 @@ bool DrmBackend::isActive() const
Session *DrmBackend::session() const
{
return m_session;
return m_session.get();
}
Outputs DrmBackend::outputs() const
......
......@@ -103,7 +103,7 @@ private:
std::unique_ptr<Udev> m_udev;
std::unique_ptr<UdevMonitor> m_udevMonitor;
Session *m_session = nullptr;
std::unique_ptr<Session> m_session;
// all outputs, enabled and disabled
QVector<DrmAbstractOutput *> m_outputs;
// only enabled outputs
......
......@@ -27,7 +27,7 @@ namespace KWin
VirtualBackend::VirtualBackend(QObject *parent)
: Platform(parent)
, m_session(Session::create(Session::Type::Noop, this))
, m_session(Session::create(Session::Type::Noop))
{
if (qEnvironmentVariableIsSet("KWIN_WAYLAND_VIRTUAL_SCREENSHOTS")) {
m_screenshotDir.reset(new QTemporaryDir);
......@@ -53,7 +53,7 @@ VirtualBackend::~VirtualBackend()
Session *VirtualBackend::session() const
{
return m_session;
return m_session.get();
}
bool VirtualBackend::initialize()
......
......@@ -70,7 +70,7 @@ private:
QVector<VirtualOutput *> m_outputs;
QVector<VirtualOutput *> m_outputsEnabled;
std::unique_ptr<QTemporaryDir> m_screenshotDir;
Session *m_session;
std::unique_ptr<Session> m_session;
};
}
......
......@@ -570,7 +570,7 @@ void WaylandSeat::destroyTouchDevice()
WaylandBackend::WaylandBackend(QObject *parent)
: Platform(parent)
, m_session(Session::create(Session::Type::Noop, this))
, m_session(Session::create(Session::Type::Noop))
, m_display(nullptr)
, m_eventQueue(new EventQueue(this))
, m_registry(new Registry(this))
......@@ -714,7 +714,7 @@ bool WaylandBackend::initialize()
Session *WaylandBackend::session() const
{
return m_session;
return m_session.get();
}
void WaylandBackend::initConnection()
......
......@@ -331,7 +331,7 @@ private:
WaylandOutput *createOutput(const QString &name, const QPoint &position, const QSize &size);
Session *m_session;
std::unique_ptr<Session> m_session;
wl_display *m_display;
KWayland::Client::EventQueue *m_eventQueue;
KWayland::Client::Registry *m_registry;
......
......@@ -98,7 +98,7 @@ bool XrandrEventFilter::event(xcb_generic_event_t *event)
X11StandalonePlatform::X11StandalonePlatform(QObject *parent)
: Platform(parent)
, m_session(Session::create(Session::Type::Noop, this))
, m_session(Session::create(Session::Type::Noop))
, m_updateOutputsTimer(new QTimer(this))
, m_x11Display(QX11Info::display())
, m_renderLoop(new RenderLoop(this))
......@@ -154,7 +154,7 @@ bool X11StandalonePlatform::initialize()
Session *X11StandalonePlatform::session() const
{
return m_session;
return m_session.get();
}
OpenGLBackend *X11StandalonePlatform::createOpenGLBackend()
......
......@@ -87,7 +87,7 @@ private:
void updateRefreshRate();
void updateCursor();
Session *m_session;
std::unique_ptr<Session> m_session;
std::unique_ptr<XInputIntegration> m_xinputIntegration;
QThread *m_openGLFreezeProtectionThread = nullptr;
QTimer *m_openGLFreezeProtection = nullptr;
......
......@@ -163,7 +163,7 @@ void X11WindowedInputBackend::initialize()
X11WindowedBackend::X11WindowedBackend(QObject *parent)
: Platform(parent)
, m_session(Session::create(Session::Type::Noop, this))
, m_session(Session::create(Session::Type::Noop))
{
setSupportsPointerWarping(true);
}
......@@ -235,7 +235,7 @@ bool X11WindowedBackend::initialize()
Session *X11WindowedBackend::session() const
{
return m_session;
return m_session.get();
}
void X11WindowedBackend::initXInput()
......
......@@ -153,7 +153,7 @@ private:
void initXInput();
X11WindowedOutput *findOutput(xcb_window_t window) const;
Session *m_session;
std::unique_ptr<Session> m_session;
xcb_connection_t *m_connection = nullptr;
xcb_screen_t *m_screen = nullptr;
xcb_key_symbols_t *m_keySymbols = nullptr;
......
......@@ -15,22 +15,17 @@ namespace KWin
static const struct
{
Session::Type type;
std::function<Session *(QObject *)> createFunc;
std::function<std::unique_ptr<Session>()> createFunc;
} s_availableSessions[] = {
{Session::Type::Logind, &LogindSession::create},
{Session::Type::ConsoleKit, &ConsoleKitSession::create},
{Session::Type::Noop, &NoopSession::create},
};
Session::Session(QObject *parent)
: QObject(parent)
{
}
Session *Session::create(QObject *parent)
std::unique_ptr<Session> Session::create()
{
for (const auto &sessionInfo : s_availableSessions) {
Session *session = sessionInfo.createFunc(parent);
std::unique_ptr<Session> session = sessionInfo.createFunc();
if (session) {
return session;
}
......@@ -38,11 +33,11 @@ Session *Session::create(QObject *parent)
return nullptr;
}
Session *Session::create(Type type, QObject *parent)
std::unique_ptr<Session> Session::create(Type type)
{
for (const auto &sessionInfo : s_availableSessions) {
if (sessionInfo.type == type) {
return sessionInfo.createFunc(parent);
return sessionInfo.createFunc();
}
}
return nullptr;
......
......@@ -11,6 +11,7 @@
#include <QObject>
#include <QString>
#include <memory>
#include <sys/types.h>
namespace KWin
......@@ -45,8 +46,8 @@ public:
};
Q_DECLARE_FLAGS(Capabilities, Capability)
static Session *create(QObject *parent = nullptr);
static Session *create(Type type, QObject *parent = nullptr);
static std::unique_ptr<Session> create();
static std::unique_ptr<Session> create(Type type);
/**
* Returns @c true if the session is active; otherwise returns @c false.
......@@ -110,7 +111,7 @@ Q_SIGNALS:
void devicePaused(dev_t deviceId);
protected:
explicit Session(QObject *parent = nullptr);
explicit Session() = default;
};
} // namespace KWin
......
......@@ -108,7 +108,7 @@ static bool activate(const QString &sessionPath)
return reply.type() != QDBusMessage::ErrorMessage;
}
ConsoleKitSession *ConsoleKitSession::create(QObject *parent)
std::unique_ptr<ConsoleKitSession> ConsoleKitSession::create()
{
if (!QDBusConnection::systemBus().interface()->isServiceRegistered(s_serviceName)) {
return nullptr;
......@@ -132,13 +132,12 @@ ConsoleKitSession *ConsoleKitSession::create(QObject *parent)
return nullptr;
}
ConsoleKitSession *session = new ConsoleKitSession(sessionPath, parent);
std::unique_ptr<ConsoleKitSession> session{new ConsoleKitSession(sessionPath)};
if (session->initialize()) {
return session;
} else {
return nullptr;
}
delete session;
return nullptr;
}
bool ConsoleKitSession::isActive() const
......@@ -218,9 +217,8 @@ void ConsoleKitSession::switchTo(uint terminal)
QDBusConnection::systemBus().asyncCall(message);
}
ConsoleKitSession::ConsoleKitSession(const QString &sessionPath, QObject *parent)
: Session(parent)
, m_sessionPath(sessionPath)
ConsoleKitSession::ConsoleKitSession(const QString &sessionPath)
: m_sessionPath(sessionPath)
{
qDBusRegisterMetaType<DBusConsoleKitSeat>();
}
......
......@@ -18,7 +18,7 @@ class ConsoleKitSession : public Session
Q_OBJECT
public:
static ConsoleKitSession *create(QObject *parent = nullptr);
static std::unique_ptr<ConsoleKitSession> create();
~ConsoleKitSession() override;
bool isActive() const override;
......@@ -36,7 +36,7 @@ private Q_SLOTS:
void handlePrepareForSleep(bool sleep);
private:
explicit ConsoleKitSession(const QString &sessionPath, QObject *parent = nullptr);
explicit ConsoleKitSession(const QString &sessionPath);
bool initialize();
void updateActive(bool active);
......
......@@ -106,7 +106,7 @@ static bool activate(const QString &sessionPath)
return reply.type() != QDBusMessage::ErrorMessage;
}
LogindSession *LogindSession::create(QObject *parent)
std::unique_ptr<LogindSession> LogindSession::create()
{
if (!QDBusConnection::systemBus().interface()->isServiceRegistered(s_serviceName)) {
return nullptr;
......@@ -130,13 +130,12 @@ LogindSession *LogindSession::create(QObject *parent)
return nullptr;
}
LogindSession *session = new LogindSession(sessionPath, parent);
std::unique_ptr<LogindSession> session{new LogindSession(sessionPath)};
if (session->initialize()) {
return session;
} else {
return nullptr;
}
delete session;
return nullptr;
}
bool LogindSession::isActive() const
......@@ -217,9 +216,8 @@ void LogindSession::switchTo(uint terminal)
QDBusConnection::systemBus().asyncCall(message);
}
LogindSession::LogindSession(const QString &sessionPath, QObject *parent)
: Session(parent)
, m_sessionPath(sessionPath)
LogindSession::LogindSession(const QString &sessionPath)
: m_sessionPath(sessionPath)
{
qDBusRegisterMetaType<DBusLogindSeat>();
}
......
......@@ -18,7 +18,7 @@ class LogindSession : public Session
Q_OBJECT
public:
static LogindSession *create(QObject *parent = nullptr);
static std::unique_ptr<LogindSession> create();
~LogindSession() override;
bool isActive() const override;
......@@ -36,7 +36,7 @@ private Q_SLOTS:
void handlePrepareForSleep(bool sleep);
private:
explicit LogindSession(const QString &sessionPath, QObject *parent = nullptr);
explicit LogindSession(const QString &sessionPath);
bool initialize();
void updateActive(bool active);
......
......@@ -9,14 +9,9 @@
namespace KWin
{
NoopSession *NoopSession::create(QObject *parent)
{
return new NoopSession(parent);
}
NoopSession::NoopSession(QObject *parent)
: Session(parent)
std::unique_ptr<NoopSession> NoopSession::create()
{
return std::unique_ptr<NoopSession>{new NoopSession()};
}
NoopSession::~NoopSession()
......
......@@ -16,7 +16,7 @@ class NoopSession : public Session
Q_OBJECT
public:
static NoopSession *create(QObject *parent = nullptr);
static std::unique_ptr<NoopSession> create();
~NoopSession() override;
bool isActive() const override;
......@@ -28,7 +28,7 @@ public:
void switchTo(uint terminal) override;
private:
explicit NoopSession(QObject *parent = nullptr);
explicit NoopSession() = default;
};
} // namespace KWin
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment