Move ownership of Session to Application
The Session can be useful not only to the platform backend but also input backends and for things such as vt switching, etc. Therefore it's better to have the Application own the Session.
This commit is contained in:
parent
5e669aece9
commit
cf3fe003e6
20 changed files with 54 additions and 61 deletions
|
@ -14,6 +14,7 @@
|
|||
#include "inputmethod.h"
|
||||
#include "platform.h"
|
||||
#include "pluginmanager.h"
|
||||
#include "session.h"
|
||||
#include "utils/xcbutils.h"
|
||||
#include "wayland_server.h"
|
||||
#include "workspace.h"
|
||||
|
@ -68,6 +69,7 @@ WaylandTestApplication::WaylandTestApplication(OperationMode mode, int &argc, ch
|
|||
removeLibraryPath(ownPath);
|
||||
addLibraryPath(ownPath);
|
||||
|
||||
setSession(Session::create(Session::Type::Noop));
|
||||
setPlatform(std::make_unique<VirtualBackend>());
|
||||
WaylandServer::create(this);
|
||||
setProcessStartupEnvironment(QProcessEnvironment::systemEnvironment());
|
||||
|
|
|
@ -78,11 +78,11 @@ static QStringList splitPathList(const QString &input, const QChar delimiter)
|
|||
return ret;
|
||||
}
|
||||
|
||||
DrmBackend::DrmBackend(QObject *parent)
|
||||
DrmBackend::DrmBackend(Session *session, QObject *parent)
|
||||
: Platform(parent)
|
||||
, m_udev(std::make_unique<Udev>())
|
||||
, m_udevMonitor(m_udev->monitor())
|
||||
, m_session(Session::create())
|
||||
, m_session(session)
|
||||
, m_explicitGpus(splitPathList(qEnvironmentVariable("KWIN_DRM_DEVICES"), ':'))
|
||||
, m_dpmsFilter()
|
||||
{
|
||||
|
@ -93,16 +93,16 @@ DrmBackend::DrmBackend(QObject *parent)
|
|||
|
||||
DrmBackend::~DrmBackend() = default;
|
||||
|
||||
Session *DrmBackend::session() const
|
||||
{
|
||||
return m_session;
|
||||
}
|
||||
|
||||
bool DrmBackend::isActive() const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
Session *DrmBackend::session() const
|
||||
{
|
||||
return m_session.get();
|
||||
}
|
||||
|
||||
Outputs DrmBackend::outputs() const
|
||||
{
|
||||
return m_outputs;
|
||||
|
@ -196,17 +196,17 @@ void DrmBackend::deactivate()
|
|||
bool DrmBackend::initialize()
|
||||
{
|
||||
// TODO: Pause/Resume individual GPU devices instead.
|
||||
connect(session(), &Session::devicePaused, this, [this](dev_t deviceId) {
|
||||
connect(m_session, &Session::devicePaused, this, [this](dev_t deviceId) {
|
||||
if (primaryGpu()->deviceId() == deviceId) {
|
||||
deactivate();
|
||||
}
|
||||
});
|
||||
connect(session(), &Session::deviceResumed, this, [this](dev_t deviceId) {
|
||||
connect(m_session, &Session::deviceResumed, this, [this](dev_t deviceId) {
|
||||
if (primaryGpu()->deviceId() == deviceId) {
|
||||
reactivate();
|
||||
}
|
||||
});
|
||||
connect(session(), &Session::awoke, this, &DrmBackend::turnOutputsOn);
|
||||
connect(m_session, &Session::awoke, this, &DrmBackend::turnOutputsOn);
|
||||
|
||||
if (!m_explicitGpus.isEmpty()) {
|
||||
for (const QString &fileName : m_explicitGpus) {
|
||||
|
@ -280,7 +280,7 @@ void DrmBackend::handleUdevEvent()
|
|||
|
||||
DrmGpu *DrmBackend::addGpu(const QString &fileName)
|
||||
{
|
||||
int fd = session()->openRestricted(fileName);
|
||||
int fd = m_session->openRestricted(fileName);
|
||||
if (fd < 0) {
|
||||
qCWarning(KWIN_DRM) << "failed to open drm device at" << fileName;
|
||||
return nullptr;
|
||||
|
@ -290,7 +290,7 @@ DrmGpu *DrmBackend::addGpu(const QString &fileName)
|
|||
drmModeRes *resources = drmModeGetResources(fd);
|
||||
if (!resources) {
|
||||
qCDebug(KWIN_DRM) << "Skipping KMS incapable drm device node at" << fileName;
|
||||
session()->closeRestricted(fd);
|
||||
m_session->closeRestricted(fd);
|
||||
return nullptr;
|
||||
}
|
||||
drmModeFreeResources(resources);
|
||||
|
@ -298,7 +298,7 @@ DrmGpu *DrmBackend::addGpu(const QString &fileName)
|
|||
struct stat buf;
|
||||
if (fstat(fd, &buf) == -1) {
|
||||
qCDebug(KWIN_DRM, "Failed to fstat %s: %s", qPrintable(fileName), strerror(errno));
|
||||
session()->closeRestricted(fd);
|
||||
m_session->closeRestricted(fd);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -549,7 +549,7 @@ void DrmBackend::enableOutput(DrmAbstractOutput *output, bool enable)
|
|||
|
||||
std::unique_ptr<InputBackend> DrmBackend::createInputBackend()
|
||||
{
|
||||
return std::make_unique<LibinputBackend>(session());
|
||||
return std::make_unique<LibinputBackend>(m_session);
|
||||
}
|
||||
|
||||
std::unique_ptr<QPainterBackend> DrmBackend::createQPainterBackend()
|
||||
|
|
|
@ -24,6 +24,7 @@ struct gbm_bo;
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
class Session;
|
||||
class Udev;
|
||||
class UdevMonitor;
|
||||
class UdevDevice;
|
||||
|
@ -39,16 +40,17 @@ class KWIN_EXPORT DrmBackend : public Platform
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DrmBackend(QObject *parent = nullptr);
|
||||
explicit DrmBackend(Session *session, QObject *parent = nullptr);
|
||||
~DrmBackend() override;
|
||||
|
||||
Session *session() const;
|
||||
|
||||
std::unique_ptr<InputBackend> createInputBackend() override;
|
||||
std::unique_ptr<QPainterBackend> createQPainterBackend() override;
|
||||
std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
|
||||
|
||||
std::optional<DmaBufParams> testCreateDmaBuf(const QSize &size, quint32 format, const QVector<uint64_t> &modifiers) override;
|
||||
std::shared_ptr<DmaBufTexture> createDmaBufTexture(const QSize &size, quint32 format, const uint64_t modifier) override;
|
||||
Session *session() const override;
|
||||
bool initialize() override;
|
||||
|
||||
Outputs outputs() const override;
|
||||
|
@ -100,7 +102,7 @@ private:
|
|||
|
||||
std::unique_ptr<Udev> m_udev;
|
||||
std::unique_ptr<UdevMonitor> m_udevMonitor;
|
||||
std::unique_ptr<Session> m_session;
|
||||
Session *m_session;
|
||||
// all outputs, enabled and disabled
|
||||
QVector<DrmAbstractOutput *> m_outputs;
|
||||
// only enabled outputs
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include "virtual_backend.h"
|
||||
|
||||
#include "composite.h"
|
||||
#include "session.h"
|
||||
#include "virtual_egl_backend.h"
|
||||
#include "virtual_output.h"
|
||||
#include "virtual_qpainter_backend.h"
|
||||
|
@ -21,7 +20,6 @@ namespace KWin
|
|||
|
||||
VirtualBackend::VirtualBackend(QObject *parent)
|
||||
: Platform(parent)
|
||||
, m_session(Session::create(Session::Type::Noop))
|
||||
{
|
||||
if (qEnvironmentVariableIsSet("KWIN_WAYLAND_VIRTUAL_SCREENSHOTS")) {
|
||||
m_screenshotDir.reset(new QTemporaryDir);
|
||||
|
@ -45,11 +43,6 @@ VirtualBackend::~VirtualBackend()
|
|||
}
|
||||
}
|
||||
|
||||
Session *VirtualBackend::session() const
|
||||
{
|
||||
return m_session.get();
|
||||
}
|
||||
|
||||
bool VirtualBackend::initialize()
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -30,7 +30,6 @@ public:
|
|||
VirtualBackend(QObject *parent = nullptr);
|
||||
~VirtualBackend() override;
|
||||
|
||||
Session *session() const override;
|
||||
bool initialize() override;
|
||||
|
||||
bool saveFrames() const
|
||||
|
@ -67,7 +66,6 @@ private:
|
|||
QVector<VirtualOutput *> m_outputs;
|
||||
QVector<VirtualOutput *> m_outputsEnabled;
|
||||
std::unique_ptr<QTemporaryDir> m_screenshotDir;
|
||||
std::unique_ptr<Session> m_session;
|
||||
};
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <gbm.h>
|
||||
#endif
|
||||
#include "renderloop_p.h"
|
||||
#include "session.h"
|
||||
#include "wayland_logging.h"
|
||||
#include "wayland_output.h"
|
||||
#include "wayland_qpainter_backend.h"
|
||||
|
@ -568,7 +567,6 @@ void WaylandSeat::destroyTouchDevice()
|
|||
|
||||
WaylandBackend::WaylandBackend(QObject *parent)
|
||||
: Platform(parent)
|
||||
, m_session(Session::create(Session::Type::Noop))
|
||||
, m_display(nullptr)
|
||||
, m_eventQueue(new EventQueue(this))
|
||||
, m_registry(new Registry(this))
|
||||
|
@ -710,11 +708,6 @@ bool WaylandBackend::initialize()
|
|||
return true;
|
||||
}
|
||||
|
||||
Session *WaylandBackend::session() const
|
||||
{
|
||||
return m_session.get();
|
||||
}
|
||||
|
||||
void WaylandBackend::initConnection()
|
||||
{
|
||||
connect(
|
||||
|
|
|
@ -252,7 +252,6 @@ public:
|
|||
explicit WaylandBackend(QObject *parent = nullptr);
|
||||
~WaylandBackend() override;
|
||||
bool initialize() override;
|
||||
Session *session() const override;
|
||||
wl_display *display();
|
||||
KWayland::Client::Compositor *compositor();
|
||||
KWayland::Client::SubCompositor *subCompositor();
|
||||
|
@ -330,7 +329,6 @@ private:
|
|||
|
||||
WaylandOutput *createOutput(const QString &name, const QPoint &position, const QSize &size);
|
||||
|
||||
std::unique_ptr<Session> m_session;
|
||||
wl_display *m_display;
|
||||
KWayland::Client::EventQueue *m_eventQueue;
|
||||
KWayland::Client::Registry *m_registry;
|
||||
|
|
|
@ -100,7 +100,6 @@ bool XrandrEventFilter::event(xcb_generic_event_t *event)
|
|||
|
||||
X11StandalonePlatform::X11StandalonePlatform(QObject *parent)
|
||||
: Platform(parent)
|
||||
, m_session(Session::create(Session::Type::Noop))
|
||||
, m_updateOutputsTimer(new QTimer(this))
|
||||
, m_x11Display(QX11Info::display())
|
||||
, m_renderLoop(std::make_unique<RenderLoop>())
|
||||
|
@ -154,11 +153,6 @@ bool X11StandalonePlatform::initialize()
|
|||
return true;
|
||||
}
|
||||
|
||||
Session *X11StandalonePlatform::session() const
|
||||
{
|
||||
return m_session.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<OpenGLBackend> X11StandalonePlatform::createOpenGLBackend()
|
||||
{
|
||||
switch (options->glPlatformInterface()) {
|
||||
|
|
|
@ -35,7 +35,6 @@ public:
|
|||
X11StandalonePlatform(QObject *parent = nullptr);
|
||||
~X11StandalonePlatform() override;
|
||||
bool initialize() override;
|
||||
Session *session() const override;
|
||||
|
||||
std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
|
||||
Edge *createScreenEdge(ScreenEdges *parent) override;
|
||||
|
@ -86,7 +85,6 @@ private:
|
|||
void updateRefreshRate();
|
||||
void updateCursor();
|
||||
|
||||
std::unique_ptr<Session> m_session;
|
||||
std::unique_ptr<XInputIntegration> m_xinputIntegration;
|
||||
QThread *m_openGLFreezeProtectionThread = nullptr;
|
||||
QTimer *m_openGLFreezeProtection = nullptr;
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include <config-kwin.h>
|
||||
|
||||
#include "session.h"
|
||||
#include "utils/xcbutils.h"
|
||||
#include "wayland_server.h"
|
||||
#include "x11_windowed_egl_backend.h"
|
||||
|
@ -164,7 +163,6 @@ void X11WindowedInputBackend::initialize()
|
|||
|
||||
X11WindowedBackend::X11WindowedBackend(QObject *parent)
|
||||
: Platform(parent)
|
||||
, m_session(Session::create(Session::Type::Noop))
|
||||
{
|
||||
setSupportsPointerWarping(true);
|
||||
}
|
||||
|
@ -234,11 +232,6 @@ bool X11WindowedBackend::initialize()
|
|||
}
|
||||
}
|
||||
|
||||
Session *X11WindowedBackend::session() const
|
||||
{
|
||||
return m_session.get();
|
||||
}
|
||||
|
||||
void X11WindowedBackend::initXInput()
|
||||
{
|
||||
#if HAVE_X11_XINPUT
|
||||
|
|
|
@ -88,7 +88,6 @@ public:
|
|||
X11WindowedBackend(QObject *parent = nullptr);
|
||||
~X11WindowedBackend() override;
|
||||
bool initialize() override;
|
||||
Session *session() const override;
|
||||
|
||||
xcb_connection_t *connection() const
|
||||
{
|
||||
|
@ -151,7 +150,6 @@ private:
|
|||
void initXInput();
|
||||
X11WindowedOutput *findOutput(xcb_window_t window) const;
|
||||
|
||||
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;
|
||||
|
|
|
@ -25,7 +25,6 @@ ColorManager::ColorManager()
|
|||
: d(std::make_unique<ColorManagerPrivate>())
|
||||
{
|
||||
Platform *platform = kwinApp()->platform();
|
||||
Session *session = platform->session();
|
||||
|
||||
const QVector<Output *> outputs = platform->enabledOutputs();
|
||||
for (Output *output : outputs) {
|
||||
|
@ -34,7 +33,7 @@ ColorManager::ColorManager()
|
|||
|
||||
connect(platform, &Platform::outputEnabled, this, &ColorManager::handleOutputEnabled);
|
||||
connect(platform, &Platform::outputDisabled, this, &ColorManager::handleOutputDisabled);
|
||||
connect(session, &Session::activeChanged, this, &ColorManager::handleSessionActiveChanged);
|
||||
connect(kwinApp()->session(), &Session::activeChanged, this, &ColorManager::handleSessionActiveChanged);
|
||||
}
|
||||
|
||||
ColorManager::~ColorManager() = default;
|
||||
|
|
|
@ -316,7 +316,7 @@ public:
|
|||
if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) {
|
||||
const xkb_keysym_t keysym = event->nativeVirtualKey();
|
||||
if (keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12) {
|
||||
kwinApp()->platform()->session()->switchTo(keysym - XKB_KEY_XF86Switch_VT_1 + 1);
|
||||
kwinApp()->session()->switchTo(keysym - XKB_KEY_XF86Switch_VT_1 + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2846,7 +2846,7 @@ private:
|
|||
void InputRedirection::setupInputFilters()
|
||||
{
|
||||
const bool hasGlobalShortcutSupport = waylandServer()->hasGlobalShortcutSupport();
|
||||
if ((kwinApp()->platform()->session()->capabilities() & Session::Capability::SwitchTerminal)
|
||||
if ((kwinApp()->session()->capabilities() & Session::Capability::SwitchTerminal)
|
||||
&& hasGlobalShortcutSupport) {
|
||||
installInputEventFilter(new VirtualTerminalFilter);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#if KWIN_BUILD_SCREENLOCKER
|
||||
#include "screenlockerwatcher.h"
|
||||
#endif
|
||||
#include "session.h"
|
||||
#include "sm.h"
|
||||
#include "utils/xcbutils.h"
|
||||
#include "wayland/surface_interface.h"
|
||||
|
@ -125,6 +126,7 @@ Application::~Application()
|
|||
destroyColorManager();
|
||||
destroyAtoms();
|
||||
destroyPlatform();
|
||||
m_session.reset();
|
||||
}
|
||||
|
||||
void Application::notifyStarted()
|
||||
|
@ -553,6 +555,12 @@ void Application::setPlatform(std::unique_ptr<Platform> &&platform)
|
|||
m_platform = std::move(platform);
|
||||
}
|
||||
|
||||
void Application::setSession(std::unique_ptr<Session> &&session)
|
||||
{
|
||||
Q_ASSERT(!m_session);
|
||||
m_session = std::move(session);
|
||||
}
|
||||
|
||||
PluginManager *Application::pluginManager() const
|
||||
{
|
||||
return m_pluginManager.get();
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace KWin
|
|||
{
|
||||
|
||||
class Platform;
|
||||
class Session;
|
||||
class X11EventFilter;
|
||||
class PluginManager;
|
||||
class InputMethod;
|
||||
|
@ -228,6 +229,12 @@ public:
|
|||
}
|
||||
void setPlatform(std::unique_ptr<Platform> &&platform);
|
||||
|
||||
Session *session() const
|
||||
{
|
||||
return m_session.get();
|
||||
}
|
||||
void setSession(std::unique_ptr<Session> &&session);
|
||||
|
||||
bool isTerminating() const
|
||||
{
|
||||
return m_terminating;
|
||||
|
@ -297,6 +304,7 @@ private:
|
|||
#if KWIN_BUILD_ACTIVITIES
|
||||
bool m_useKActivities = true;
|
||||
#endif
|
||||
std::unique_ptr<Session> m_session;
|
||||
std::unique_ptr<Platform> m_platform;
|
||||
bool m_terminating = false;
|
||||
qreal m_xwaylandScale = 1;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "effects.h"
|
||||
#include "inputmethod.h"
|
||||
#include "platform.h"
|
||||
#include "session.h"
|
||||
#include "tabletmodemanager.h"
|
||||
#include "utils/realtime.h"
|
||||
#include "wayland/display.h"
|
||||
|
@ -542,15 +543,23 @@ int main(int argc, char *argv[])
|
|||
|
||||
switch (backendType) {
|
||||
case BackendType::Kms:
|
||||
a.setPlatform(std::make_unique<KWin::DrmBackend>());
|
||||
a.setSession(KWin::Session::create());
|
||||
if (!a.session()) {
|
||||
std::cerr << "FATAl ERROR: could not acquire a session" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
a.setPlatform(std::make_unique<KWin::DrmBackend>(a.session()));
|
||||
break;
|
||||
case BackendType::Virtual:
|
||||
a.setSession(KWin::Session::create(KWin::Session::Type::Noop));
|
||||
a.setPlatform(std::make_unique<KWin::VirtualBackend>());
|
||||
break;
|
||||
case BackendType::X11:
|
||||
a.setSession(KWin::Session::create(KWin::Session::Type::Noop));
|
||||
a.setPlatform(std::make_unique<KWin::X11WindowedBackend>());
|
||||
break;
|
||||
case BackendType::Wayland:
|
||||
a.setSession(KWin::Session::create(KWin::Session::Type::Noop));
|
||||
a.setPlatform(std::make_unique<KWin::Wayland::WaylandBackend>());
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "backends/x11/standalone/x11_standalone_platform.h"
|
||||
#include "platform.h"
|
||||
#include "session.h"
|
||||
#include "sm.h"
|
||||
#include "tabletmodemanager.h"
|
||||
#include "utils/xcbutils.h"
|
||||
|
@ -410,6 +411,7 @@ int main(int argc, char *argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
a.setSession(KWin::Session::create(KWin::Session::Type::Noop));
|
||||
a.setPlatform(std::make_unique<KWin::X11StandalonePlatform>());
|
||||
a.start();
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ class OutlineVisual;
|
|||
class QPainterBackend;
|
||||
class Scene;
|
||||
class ScreenEdges;
|
||||
class Session;
|
||||
class OutputConfiguration;
|
||||
struct DmaBufParams;
|
||||
|
||||
|
@ -64,7 +63,6 @@ class KWIN_EXPORT Platform : public QObject
|
|||
public:
|
||||
~Platform() override;
|
||||
|
||||
virtual Session *session() const = 0;
|
||||
virtual bool initialize() = 0;
|
||||
virtual std::unique_ptr<InputBackend> createInputBackend();
|
||||
virtual std::unique_ptr<OpenGLBackend> createOpenGLBackend();
|
||||
|
|
|
@ -101,7 +101,7 @@ NightColorManager::NightColorManager()
|
|||
|
||||
connect(kwinApp()->colorManager(), &ColorManager::deviceAdded, this, &NightColorManager::hardReset);
|
||||
|
||||
connect(kwinApp()->platform()->session(), &Session::activeChanged, this, [this](bool active) {
|
||||
connect(kwinApp()->session(), &Session::activeChanged, this, [this](bool active) {
|
||||
if (active) {
|
||||
hardReset();
|
||||
} else {
|
||||
|
|
|
@ -115,7 +115,7 @@ std::vector<UdevDevice::Ptr> UdevEnumerate::find()
|
|||
if (deviceSeat.isEmpty()) {
|
||||
deviceSeat = defaultSeat;
|
||||
}
|
||||
if (deviceSeat != kwinApp()->platform()->session()->seat()) {
|
||||
if (deviceSeat != kwinApp()->session()->seat()) {
|
||||
continue;
|
||||
}
|
||||
vect.push_back(std::move(device));
|
||||
|
|
Loading…
Reference in a new issue