move ColorManager singleton to Application

This commit is contained in:
Xaver Hugl 2022-07-20 12:27:28 +02:00
parent 9337f145d5
commit f2ad6bcce9
6 changed files with 19 additions and 16 deletions

View file

@ -15,17 +15,14 @@
namespace KWin
{
KWIN_SINGLETON_FACTORY(ColorManager)
class ColorManagerPrivate
{
public:
QVector<ColorDevice *> devices;
};
ColorManager::ColorManager(QObject *parent)
: QObject(parent)
, d(new ColorManagerPrivate)
ColorManager::ColorManager()
: d(std::make_unique<ColorManagerPrivate>())
{
Platform *platform = kwinApp()->platform();
Session *session = platform->session();
@ -40,10 +37,7 @@ ColorManager::ColorManager(QObject *parent)
connect(session, &Session::activeChanged, this, &ColorManager::handleSessionActiveChanged);
}
ColorManager::~ColorManager()
{
s_self = nullptr;
}
ColorManager::~ColorManager() = default;
QVector<ColorDevice *> ColorManager::devices() const
{

View file

@ -9,6 +9,7 @@
#include "kwinglobals.h"
#include <QObject>
#include <memory>
namespace KWin
{
@ -25,6 +26,7 @@ class KWIN_EXPORT ColorManager : public QObject
Q_OBJECT
public:
ColorManager();
~ColorManager() override;
/**
@ -55,8 +57,7 @@ private Q_SLOTS:
void handleSessionActiveChanged(bool active);
private:
QScopedPointer<ColorManagerPrivate> d;
KWIN_SINGLETON(ColorManager)
std::unique_ptr<ColorManagerPrivate> d;
};
} // namespace KWin

View file

@ -271,7 +271,7 @@ void Application::createPlugins()
void Application::createColorManager()
{
ColorManager::create(this);
m_colorManager = std::make_unique<ColorManager>();
}
void Application::createInputMethod()
@ -311,7 +311,7 @@ void Application::destroyPlugins()
void Application::destroyColorManager()
{
delete ColorManager::self();
m_colorManager.reset();
}
void Application::destroyInputMethod()
@ -572,4 +572,9 @@ InputMethod *Application::inputMethod() const
return m_inputMethod.get();
}
ColorManager *Application::colorManager() const
{
return m_colorManager.get();
}
} // namespace

View file

@ -31,6 +31,7 @@ class Platform;
class X11EventFilter;
class PluginManager;
class InputMethod;
class ColorManager;
class XcbEventFilter : public QAbstractNativeEventFilter
{
@ -243,6 +244,7 @@ public:
PluginManager *pluginManager() const;
InputMethod *inputMethod() const;
ColorManager *colorManager() const;
Q_SIGNALS:
void x11ConnectionChanged();
@ -301,6 +303,7 @@ private:
QProcessEnvironment m_processEnvironment;
std::unique_ptr<PluginManager> m_pluginManager;
std::unique_ptr<InputMethod> m_inputMethod;
std::unique_ptr<ColorManager> m_colorManager;
};
inline static Application *kwinApp()

View file

@ -54,7 +54,7 @@ void ColordDevice::updateProfile()
return;
}
ColorDevice *device = ColorManager::self()->findDevice(m_output);
ColorDevice *device = kwinApp()->colorManager()->findDevice(m_output);
if (device) {
device->setProfile(profile.filename());
}

View file

@ -114,7 +114,7 @@ void NightColorManager::init()
KGlobalAccel::setGlobalShortcut(toggleAction, QList<QKeySequence>());
input()->registerShortcut(QKeySequence(), toggleAction, this, &NightColorManager::toggle);
connect(ColorManager::self(), &ColorManager::deviceAdded, this, &NightColorManager::hardReset);
connect(kwinApp()->colorManager(), &ColorManager::deviceAdded, this, &NightColorManager::hardReset);
connect(kwinApp()->platform()->session(), &Session::activeChanged, this, [this](bool active) {
if (active) {
@ -671,7 +671,7 @@ int NightColorManager::currentTargetTemp() const
void NightColorManager::commitGammaRamps(int temperature)
{
const QVector<ColorDevice *> devices = ColorManager::self()->devices();
const QVector<ColorDevice *> devices = kwinApp()->colorManager()->devices();
for (ColorDevice *device : devices) {
device->setTemperature(temperature);
}