From bdfb946267eac7a87fe009a2b04f425a854db7b2 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 25 Nov 2020 21:11:48 +0200 Subject: [PATCH] Convert Night Color into a plugin Night Color adjusts the color temperature based on the current time in your location. It's not a generic color correction module per se. We need a central component that can be used by both night color and colord integration to tweak gamma ramps and which will be able to resolve conflicts between the two. The Night Color manager cannot be such a thing because of its very specific usecase. This change converts Night Color into a plugin to prepare some space for such a component. The tricky part is that the dbus api of Night Color has "ColorCorrect" in its name. I'm afraid we cannot do that much about it without breaking API compatibility. --- CMakeLists.txt | 28 --- Messages.sh | 2 +- autotests/integration/CMakeLists.txt | 2 +- ...ightcolor_test.cpp => nightcolor_test.cpp} | 43 +++-- colorcorrection/colorcorrect_settings.kcfgc | 8 - platform.cpp | 2 - platform.h | 8 - plugins/CMakeLists.txt | 1 + plugins/nightcolor/CMakeLists.txt | 31 +++ .../nightcolor}/clockskewnotifier.cpp | 0 .../nightcolor}/clockskewnotifier.h | 0 .../nightcolor}/clockskewnotifierengine.cpp | 0 .../clockskewnotifierengine_linux.cpp | 0 .../clockskewnotifierengine_linux.h | 0 .../nightcolor}/clockskewnotifierengine_p.h | 0 .../nightcolor}/constants.h | 3 - plugins/nightcolor/main.cpp | 37 ++++ plugins/nightcolor/metadata.json | 6 + .../nightcolor/nightcolordbusinterface.cpp | 65 +++---- .../nightcolor/nightcolordbusinterface.h | 20 +- .../nightcolor/nightcolormanager.cpp | 177 ++++++++++-------- .../nightcolor/nightcolormanager.h | 31 ++- .../nightcolor/nightcolorsettings.kcfg | 2 +- plugins/nightcolor/nightcolorsettings.kcfgc | 8 + .../nightcolor/org.kde.kwin.ColorCorrect.xml | 0 .../nightcolor}/suncalc.cpp | 2 - .../nightcolor}/suncalc.h | 5 - useractions.cpp | 2 - 28 files changed, 251 insertions(+), 232 deletions(-) rename autotests/integration/{colorcorrect_nightcolor_test.cpp => nightcolor_test.cpp} (92%) delete mode 100644 colorcorrection/colorcorrect_settings.kcfgc create mode 100644 plugins/nightcolor/CMakeLists.txt rename {colorcorrection => plugins/nightcolor}/clockskewnotifier.cpp (100%) rename {colorcorrection => plugins/nightcolor}/clockskewnotifier.h (100%) rename {colorcorrection => plugins/nightcolor}/clockskewnotifierengine.cpp (100%) rename {colorcorrection => plugins/nightcolor}/clockskewnotifierengine_linux.cpp (100%) rename {colorcorrection => plugins/nightcolor}/clockskewnotifierengine_linux.h (100%) rename {colorcorrection => plugins/nightcolor}/clockskewnotifierengine_p.h (100%) rename {colorcorrection => plugins/nightcolor}/constants.h (99%) create mode 100644 plugins/nightcolor/main.cpp create mode 100644 plugins/nightcolor/metadata.json rename colorcorrection/colorcorrectdbusinterface.cpp => plugins/nightcolor/nightcolordbusinterface.cpp (78%) rename colorcorrection/colorcorrectdbusinterface.h => plugins/nightcolor/nightcolordbusinterface.h (91%) rename colorcorrection/manager.cpp => plugins/nightcolor/nightcolormanager.cpp (86%) rename colorcorrection/manager.h => plugins/nightcolor/nightcolormanager.h (94%) rename colorcorrection/colorcorrect_settings.kcfg => plugins/nightcolor/nightcolorsettings.kcfg (96%) create mode 100644 plugins/nightcolor/nightcolorsettings.kcfgc rename org.kde.kwin.ColorCorrect.xml => plugins/nightcolor/org.kde.kwin.ColorCorrect.xml (100%) rename {colorcorrection => plugins/nightcolor}/suncalc.cpp (99%) rename {colorcorrection => plugins/nightcolor}/suncalc.h (96%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 961ae76ab8..03f33f57b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -452,11 +452,6 @@ set(kwin_SRCS appmenu.cpp atoms.cpp client_machine.cpp - colorcorrection/clockskewnotifier.cpp - colorcorrection/clockskewnotifierengine.cpp - colorcorrection/colorcorrectdbusinterface.cpp - colorcorrection/manager.cpp - colorcorrection/suncalc.cpp composite.cpp cursor.cpp dbusinterface.cpp @@ -567,25 +562,6 @@ set(kwin_SRCS xwl/xwayland_interface.cpp ) -if (CMAKE_SYSTEM_NAME MATCHES "Linux") - set(kwin_SRCS - ${kwin_SRCS} - colorcorrection/clockskewnotifierengine_linux.cpp - ) -endif() - -include(ECMQtDeclareLoggingCategory) -ecm_qt_declare_logging_category(kwin_SRCS - HEADER - colorcorrect_logging.h - IDENTIFIER - KWIN_COLORCORRECTION - CATEGORY_NAME - kwin_colorcorrection - DEFAULT_SEVERITY - Critical -) - if (KWIN_BUILD_TABBOX) include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) set(kwin_SRCS ${kwin_SRCS} @@ -626,13 +602,11 @@ if(KWIN_TTY_PREFIX) endif() kconfig_add_kcfg_files(kwin_SRCS settings.kcfgc) -kconfig_add_kcfg_files(kwin_SRCS colorcorrection/colorcorrect_settings.kcfgc) kconfig_add_kcfg_files(kwin_SRCS rulesettings.kcfgc) kconfig_add_kcfg_files(kwin_SRCS rulebooksettingsbase.kcfgc) qt5_add_dbus_adaptor(kwin_SRCS org.kde.KWin.xml dbusinterface.h KWin::DBusInterface) qt5_add_dbus_adaptor(kwin_SRCS org.kde.kwin.Compositing.xml dbusinterface.h KWin::CompositorDBusInterface) -qt5_add_dbus_adaptor(kwin_SRCS org.kde.kwin.ColorCorrect.xml colorcorrection/colorcorrectdbusinterface.h KWin::ColorCorrect::ColorCorrectDBusInterface) qt5_add_dbus_adaptor(kwin_SRCS ${kwin_effects_dbus_xml} effects.h KWin::EffectsHandlerImpl) qt5_add_dbus_adaptor(kwin_SRCS org.kde.KWin.VirtualDesktopManager.xml dbusinterface.h KWin::VirtualDesktopManagerDBusInterface) qt5_add_dbus_adaptor(kwin_SRCS org.kde.KWin.Session.xml sm.h KWin::SessionManager) @@ -816,13 +790,11 @@ endif() ########### install files ############### install(FILES kwin.kcfg DESTINATION ${KCFG_INSTALL_DIR} RENAME ${KWIN_NAME}.kcfg) -install(FILES colorcorrection/colorcorrect_settings.kcfg DESTINATION ${KCFG_INSTALL_DIR} RENAME ${KWIN_NAME}_colorcorrect.kcfg) install(FILES kwin.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR} RENAME ${KWIN_NAME}.notifyrc) install( FILES org.kde.KWin.VirtualDesktopManager.xml org.kde.KWin.xml - org.kde.kwin.ColorCorrect.xml org.kde.kwin.Compositing.xml org.kde.kwin.Effects.xml org.kde.KWin.Plugins.xml diff --git a/Messages.sh b/Messages.sh index fb452e1b57..88fa9ed818 100644 --- a/Messages.sh +++ b/Messages.sh @@ -1,3 +1,3 @@ #! /usr/bin/env bash $EXTRACTRC *.kcfg *.ui >> rc.cpp -$XGETTEXT *.h *.cpp colorcorrection/*.cpp helpers/killer/*.cpp plugins/scenes/opengl/*.cpp tabbox/*.cpp scripting/*.cpp plugins/krunner-integration/*.cpp -o $podir/kwin.pot +$XGETTEXT *.h *.cpp plugins/nightcolor/*.cpp helpers/killer/*.cpp plugins/scenes/opengl/*.cpp tabbox/*.cpp scripting/*.cpp plugins/krunner-integration/*.cpp -o $podir/kwin.pot diff --git a/autotests/integration/CMakeLists.txt b/autotests/integration/CMakeLists.txt index 3fa74aad72..88c34af6d2 100644 --- a/autotests/integration/CMakeLists.txt +++ b/autotests/integration/CMakeLists.txt @@ -89,7 +89,7 @@ integrationTest(WAYLAND_ONLY NAME testLayerShellV1Client SRCS layershellv1client integrationTest(WAYLAND_ONLY NAME testVirtualDesktop SRCS virtual_desktop_test.cpp) integrationTest(WAYLAND_ONLY NAME testXdgShellClientRules SRCS xdgshellclient_rules_test.cpp) integrationTest(WAYLAND_ONLY NAME testIdleInhibition SRCS idle_inhibition_test.cpp) -integrationTest(WAYLAND_ONLY NAME testColorCorrectNightColor SRCS colorcorrect_nightcolor_test.cpp) +integrationTest(WAYLAND_ONLY NAME testNightColor SRCS nightcolor_test.cpp LIBS KWinNightColorPlugin) integrationTest(WAYLAND_ONLY NAME testDontCrashCursorPhysicalSizeEmpty SRCS dont_crash_cursor_physical_size_empty.cpp) integrationTest(WAYLAND_ONLY NAME testDontCrashReinitializeCompositor SRCS dont_crash_reinitialize_compositor.cpp) integrationTest(WAYLAND_ONLY NAME testNoGlobalShortcuts SRCS no_global_shortcuts_test.cpp) diff --git a/autotests/integration/colorcorrect_nightcolor_test.cpp b/autotests/integration/nightcolor_test.cpp similarity index 92% rename from autotests/integration/colorcorrect_nightcolor_test.cpp rename to autotests/integration/nightcolor_test.cpp index d5920ca53a..51e267156c 100644 --- a/autotests/integration/colorcorrect_nightcolor_test.cpp +++ b/autotests/integration/nightcolor_test.cpp @@ -7,19 +7,19 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "kwin_wayland_test.h" - #include "platform.h" #include "wayland_server.h" -#include "colorcorrection/manager.h" -#include "colorcorrection/constants.h" + +#include "plugins/nightcolor/nightcolormanager.h" +#include "plugins/nightcolor/constants.h" #include using namespace KWin; -static const QString s_socketName = QStringLiteral("wayland_test_kwin_colorcorrect_nightcolor-0"); +static const QString s_socketName = QStringLiteral("wayland_test_kwin_nightcolor-0"); -class ColorCorrectNightColorTest : public QObject +class NightColorTest : public QObject { Q_OBJECT private Q_SLOTS: @@ -34,7 +34,7 @@ private Q_SLOTS: void testAutoLocationUpdate(); }; -void ColorCorrectNightColorTest::initTestCase() +void NightColorTest::initTestCase() { QSignalSpy applicationStartedSpy(kwinApp(), &Application::started); QVERIFY(applicationStartedSpy.isValid()); @@ -47,19 +47,22 @@ void ColorCorrectNightColorTest::initTestCase() kwinApp()->start(); QVERIFY(applicationStartedSpy.wait()); waylandServer()->initWorkspace(); + + NightColorManager *manager = NightColorManager::self(); + QVERIFY(manager); } -void ColorCorrectNightColorTest::init() +void NightColorTest::init() { QVERIFY(Test::setupWaylandConnection()); } -void ColorCorrectNightColorTest::cleanup() +void NightColorTest::cleanup() { Test::destroyWaylandConnection(); } -void ColorCorrectNightColorTest::testConfigRead_data() +void NightColorTest::testConfigRead_data() { QTest::addColumn("active"); QTest::addColumn("mode"); @@ -79,7 +82,7 @@ void ColorCorrectNightColorTest::testConfigRead_data() QTest::newRow("wrongData2") << "fa" << 4 << 7000 << 91. << -181. << "060" << "800" << -2 << false; } -void ColorCorrectNightColorTest::testConfigRead() +void NightColorTest::testConfigRead() { QFETCH(QString, active); QFETCH(int, mode); @@ -93,7 +96,7 @@ void ColorCorrectNightColorTest::testConfigRead() const bool activeDefault = true; const int modeDefault = 0; - const int nightTemperatureUpperEnd = ColorCorrect::NEUTRAL_TEMPERATURE; + const int nightTemperatureUpperEnd = NEUTRAL_TEMPERATURE; const double latitudeFixedDefault = 0; const double longitudeFixedDefault = 0; const QTime morningBeginFixedDefault = QTime(6,0,0); @@ -111,7 +114,7 @@ void ColorCorrectNightColorTest::testConfigRead() cfgGroup.writeEntry("EveningBeginFixed", eveningBeginFixedDefault.toString("hhmm")); cfgGroup.writeEntry("TransitionTime", transitionTimeDefault); - ColorCorrect::Manager *manager = kwinApp()->platform()->colorCorrectManager(); + NightColorManager *manager = NightColorManager::self(); manager->reparseConfigAndReset(); auto info = manager->info(); QVERIFY(!info.isEmpty()); @@ -159,7 +162,7 @@ void ColorCorrectNightColorTest::testConfigRead() } } -void ColorCorrectNightColorTest::testChangeConfiguration_data() +void NightColorTest::testChangeConfiguration_data() { QTest::addColumn("activeReadIn"); QTest::addColumn("modeReadIn"); @@ -186,7 +189,7 @@ void ColorCorrectNightColorTest::testChangeConfiguration_data() QTest::newRow("wrongData8") << true << 0 << 4500 << 0. << 0. << QTime(1,0,0) << QTime(23,30,0) << 90 << false; } -void ColorCorrectNightColorTest::testChangeConfiguration() +void NightColorTest::testChangeConfiguration() { QFETCH(bool, activeReadIn); QFETCH(int, modeReadIn); @@ -200,7 +203,7 @@ void ColorCorrectNightColorTest::testChangeConfiguration() const bool activeDefault = true; const int modeDefault = 0; - const int nightTemperatureDefault = ColorCorrect::DEFAULT_NIGHT_TEMPERATURE; + const int nightTemperatureDefault = DEFAULT_NIGHT_TEMPERATURE; const double latitudeFixedDefault = 0; const double longitudeFixedDefault = 0; const QTime morningBeginFixedDefault = QTime(6,0,0); @@ -258,7 +261,7 @@ void ColorCorrectNightColorTest::testChangeConfiguration() QCOMPARE(info.value("TransitionTime").toInt(), transitionTimeExpect); }; - ColorCorrect::Manager *manager = kwinApp()->platform()->colorCorrectManager(); + NightColorManager *manager = NightColorManager::self(); // test with default values setData(); @@ -292,9 +295,9 @@ void ColorCorrectNightColorTest::testChangeConfiguration() compareValues(manager->info()); } -void ColorCorrectNightColorTest::testAutoLocationUpdate() +void NightColorTest::testAutoLocationUpdate() { - ColorCorrect::Manager *manager = kwinApp()->platform()->colorCorrectManager(); + NightColorManager *manager = NightColorManager::self(); auto info = manager->info(); QCOMPARE(info.value("LatitudeAuto").toDouble(), 0.); QCOMPARE(info.value("LongitudeAuto").toDouble(), 0.); @@ -324,5 +327,5 @@ void ColorCorrectNightColorTest::testAutoLocationUpdate() QCOMPARE(info.value("LatitudeAuto").toDouble(), 50.); } -WAYLANDTEST_MAIN(ColorCorrectNightColorTest) -#include "colorcorrect_nightcolor_test.moc" +WAYLANDTEST_MAIN(NightColorTest) +#include "nightcolor_test.moc" diff --git a/colorcorrection/colorcorrect_settings.kcfgc b/colorcorrection/colorcorrect_settings.kcfgc deleted file mode 100644 index 4c178d6840..0000000000 --- a/colorcorrection/colorcorrect_settings.kcfgc +++ /dev/null @@ -1,8 +0,0 @@ -File=colorcorrect_settings.kcfg -NameSpace=KWin::ColorCorrect -ClassName=Settings -Singleton=true -Mutators=true -# manager.h is needed for NightColorMode -IncludeFiles=colorcorrection/manager.h -UseEnumTypes=true diff --git a/platform.cpp b/platform.cpp index 7660913bb7..9064463fa2 100644 --- a/platform.cpp +++ b/platform.cpp @@ -21,7 +21,6 @@ #include "screens.h" #include "screenedge.h" #include "wayland_server.h" -#include "colorcorrection/manager.h" #include #include @@ -38,7 +37,6 @@ Platform::Platform(QObject *parent) , m_eglDisplay(EGL_NO_DISPLAY) { setSoftwareCursorForced(false); - m_colorCorrect = new ColorCorrect::Manager(this); connect(Cursors::self(), &Cursors::currentCursorRendered, this, &Platform::cursorRendered); } diff --git a/platform.h b/platform.h index a2d110114f..0947fb1943 100644 --- a/platform.h +++ b/platform.h @@ -28,9 +28,6 @@ class OutputConfigurationInterface; namespace KWin { -namespace ColorCorrect { -class Manager; -} class AbstractOutput; class Edge; @@ -418,10 +415,6 @@ public: return m_supportsGammaControl; } - ColorCorrect::Manager *colorCorrectManager() { - return m_colorCorrect; - } - // outputs with connections (org_kde_kwin_outputdevice) virtual Outputs outputs() const { return Outputs(); @@ -571,7 +564,6 @@ private: EGLContext m_context = EGL_NO_CONTEXT; EGLContext m_globalShareContext = EGL_NO_CONTEXT; int m_hideCursorCounter = 0; - ColorCorrect::Manager *m_colorCorrect = nullptr; bool m_supportsGammaControl = false; bool m_supportsOutputChanges = false; CompositingType m_selectedCompositor = NoCompositing; diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index cb3c44b2c0..49e3e3f70e 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(platforms) add_subdirectory(scenes) add_subdirectory(windowsystem) add_subdirectory(kpackage) +add_subdirectory(nightcolor) if (KWIN_BUILD_DECORATIONS) add_subdirectory(kdecorations) diff --git a/plugins/nightcolor/CMakeLists.txt b/plugins/nightcolor/CMakeLists.txt new file mode 100644 index 0000000000..c517f8d5e5 --- /dev/null +++ b/plugins/nightcolor/CMakeLists.txt @@ -0,0 +1,31 @@ +set(nightcolor_SOURCES + clockskewnotifier.cpp + clockskewnotifierengine.cpp + nightcolordbusinterface.cpp + nightcolormanager.cpp + main.cpp + suncalc.cpp +) + +ecm_qt_declare_logging_category(nightcolor_SOURCES + HEADER nightcolorlogging.h + IDENTIFIER KWIN_NIGHTCOLOR + CATEGORY_NAME kwin_nightcolor + DEFAULT_SEVERITY Critical +) + +kconfig_add_kcfg_files(nightcolor_SOURCES nightcolorsettings.kcfgc) +qt5_add_dbus_adaptor(nightcolor_SOURCES org.kde.kwin.ColorCorrect.xml + nightcolordbusinterface.h KWin::NightColorDBusInterface) + +add_library(KWinNightColorPlugin SHARED ${nightcolor_SOURCES}) + +if (CMAKE_SYSTEM_NAME MATCHES "Linux") + target_sources(KWinNightColorPlugin PRIVATE clockskewnotifierengine_linux.cpp) +endif() + +target_link_libraries(KWinNightColorPlugin kwin) + +install(FILES nightcolorsettings.kcfg DESTINATION ${KCFG_INSTALL_DIR} RENAME ${KWIN_NAME}_colorcorrect.kcfg) +install(FILES org.kde.kwin.ColorCorrect.xml DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR}) +install(TARGETS KWinNightColorPlugin DESTINATION ${PLUGIN_INSTALL_DIR}/kwin/plugins/) diff --git a/colorcorrection/clockskewnotifier.cpp b/plugins/nightcolor/clockskewnotifier.cpp similarity index 100% rename from colorcorrection/clockskewnotifier.cpp rename to plugins/nightcolor/clockskewnotifier.cpp diff --git a/colorcorrection/clockskewnotifier.h b/plugins/nightcolor/clockskewnotifier.h similarity index 100% rename from colorcorrection/clockskewnotifier.h rename to plugins/nightcolor/clockskewnotifier.h diff --git a/colorcorrection/clockskewnotifierengine.cpp b/plugins/nightcolor/clockskewnotifierengine.cpp similarity index 100% rename from colorcorrection/clockskewnotifierengine.cpp rename to plugins/nightcolor/clockskewnotifierengine.cpp diff --git a/colorcorrection/clockskewnotifierengine_linux.cpp b/plugins/nightcolor/clockskewnotifierengine_linux.cpp similarity index 100% rename from colorcorrection/clockskewnotifierengine_linux.cpp rename to plugins/nightcolor/clockskewnotifierengine_linux.cpp diff --git a/colorcorrection/clockskewnotifierengine_linux.h b/plugins/nightcolor/clockskewnotifierengine_linux.h similarity index 100% rename from colorcorrection/clockskewnotifierengine_linux.h rename to plugins/nightcolor/clockskewnotifierengine_linux.h diff --git a/colorcorrection/clockskewnotifierengine_p.h b/plugins/nightcolor/clockskewnotifierengine_p.h similarity index 100% rename from colorcorrection/clockskewnotifierengine_p.h rename to plugins/nightcolor/clockskewnotifierengine_p.h diff --git a/colorcorrection/constants.h b/plugins/nightcolor/constants.h similarity index 99% rename from colorcorrection/constants.h rename to plugins/nightcolor/constants.h index eb76f9c175..0210bb4269 100644 --- a/colorcorrection/constants.h +++ b/plugins/nightcolor/constants.h @@ -11,8 +11,6 @@ namespace KWin { -namespace ColorCorrect -{ static const int MSC_DAY = 86400000; static const int MIN_TEMPERATURE = 1000; @@ -272,7 +270,6 @@ static const float blackbodyColor[] = { 0.62740336, 0.75282962, 1.00000000 }; -} } #endif // KWIN_NIGHTCOLOR_CONSTANTS_H diff --git a/plugins/nightcolor/main.cpp b/plugins/nightcolor/main.cpp new file mode 100644 index 0000000000..0e69b3bac6 --- /dev/null +++ b/plugins/nightcolor/main.cpp @@ -0,0 +1,37 @@ +/* + SPDX-FileCopyrightText: 2020 Vlad Zahorodnii + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +#include "nightcolormanager.h" + +#include + +using namespace KWin; + +class KWIN_EXPORT NightColorManagerFactory : public PluginFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID PluginFactory_iid FILE "metadata.json") + Q_INTERFACES(KWin::PluginFactory) + +public: + explicit NightColorManagerFactory(QObject *parent = nullptr); + + Plugin *create() const override; +}; + +NightColorManagerFactory::NightColorManagerFactory(QObject *parent) + : PluginFactory(parent) +{ +} + +Plugin *NightColorManagerFactory::create() const +{ + return new NightColorManager(); +} + +K_EXPORT_PLUGIN_VERSION(KWIN_PLUGIN_API_VERSION) + +#include "main.moc" diff --git a/plugins/nightcolor/metadata.json b/plugins/nightcolor/metadata.json new file mode 100644 index 0000000000..e88aaad209 --- /dev/null +++ b/plugins/nightcolor/metadata.json @@ -0,0 +1,6 @@ +{ + "KPlugin": { + "EnabledByDefault": true, + "Id": "kwin5_plugin_nightcolor" + } +} diff --git a/colorcorrection/colorcorrectdbusinterface.cpp b/plugins/nightcolor/nightcolordbusinterface.cpp similarity index 78% rename from colorcorrection/colorcorrectdbusinterface.cpp rename to plugins/nightcolor/nightcolordbusinterface.cpp index f1d80d9524..cc01a4f4ba 100644 --- a/colorcorrection/colorcorrectdbusinterface.cpp +++ b/plugins/nightcolor/nightcolordbusinterface.cpp @@ -7,17 +7,15 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -#include "colorcorrectdbusinterface.h" +#include "nightcolordbusinterface.h" +#include "nightcolormanager.h" #include "colorcorrectadaptor.h" -#include "manager.h" - #include namespace KWin { -namespace ColorCorrect { -ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) +NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) : QObject(parent) , m_manager(parent) , m_inhibitorWatcher(new QDBusServiceWatcher(this)) @@ -25,9 +23,9 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) m_inhibitorWatcher->setConnection(QDBusConnection::sessionBus()); m_inhibitorWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); connect(m_inhibitorWatcher, &QDBusServiceWatcher::serviceUnregistered, - this, &ColorCorrectDBusInterface::removeInhibitorService); + this, &NightColorDBusInterface::removeInhibitorService); - connect(m_manager, &Manager::inhibitedChanged, this, [this] { + connect(m_manager, &NightColorManager::inhibitedChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("inhibited"), m_manager->isInhibited()); @@ -46,7 +44,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &Manager::enabledChanged, this, [this] { + connect(m_manager, &NightColorManager::enabledChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("enabled"), m_manager->isEnabled()); @@ -65,7 +63,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &Manager::runningChanged, this, [this] { + connect(m_manager, &NightColorManager::runningChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("running"), m_manager->isRunning()); @@ -84,7 +82,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &Manager::currentTemperatureChanged, this, [this] { + connect(m_manager, &NightColorManager::currentTemperatureChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("currentTemperature"), m_manager->currentTemperature()); @@ -103,7 +101,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &Manager::targetTemperatureChanged, this, [this] { + connect(m_manager, &NightColorManager::targetTemperatureChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("targetTemperature"), m_manager->targetTemperature()); @@ -122,7 +120,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &Manager::modeChanged, this, [this] { + connect(m_manager, &NightColorManager::modeChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("mode"), uint(m_manager->mode())); @@ -141,7 +139,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &Manager::previousTransitionTimingsChanged, this, [this] { + connect(m_manager, &NightColorManager::previousTransitionTimingsChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("previousTransitionDateTime"), previousTransitionDateTime()); changedProperties.insert(QStringLiteral("previousTransitionDuration"), previousTransitionDuration()); @@ -161,7 +159,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &Manager::scheduledTransitionTimingsChanged, this, [this] { + connect(m_manager, &NightColorManager::scheduledTransitionTimingsChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("scheduledTransitionDateTime"), scheduledTransitionDateTime()); changedProperties.insert(QStringLiteral("scheduledTransitionDuration"), scheduledTransitionDuration()); @@ -181,47 +179,47 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &Manager::configChange, this, &ColorCorrectDBusInterface::nightColorConfigChanged); + connect(m_manager, &NightColorManager::configChange, this, &NightColorDBusInterface::nightColorConfigChanged); new ColorCorrectAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/ColorCorrect"), this); } -bool ColorCorrectDBusInterface::isInhibited() const +bool NightColorDBusInterface::isInhibited() const { return m_manager->isInhibited(); } -bool ColorCorrectDBusInterface::isEnabled() const +bool NightColorDBusInterface::isEnabled() const { return m_manager->isEnabled(); } -bool ColorCorrectDBusInterface::isRunning() const +bool NightColorDBusInterface::isRunning() const { return m_manager->isRunning(); } -bool ColorCorrectDBusInterface::isAvailable() const +bool NightColorDBusInterface::isAvailable() const { return m_manager->isAvailable(); } -int ColorCorrectDBusInterface::currentTemperature() const +int NightColorDBusInterface::currentTemperature() const { return m_manager->currentTemperature(); } -int ColorCorrectDBusInterface::targetTemperature() const +int NightColorDBusInterface::targetTemperature() const { return m_manager->targetTemperature(); } -int ColorCorrectDBusInterface::mode() const +int NightColorDBusInterface::mode() const { return m_manager->mode(); } -quint64 ColorCorrectDBusInterface::previousTransitionDateTime() const +quint64 NightColorDBusInterface::previousTransitionDateTime() const { const QDateTime dateTime = m_manager->previousTransitionDateTime(); if (dateTime.isValid()) { @@ -230,12 +228,12 @@ quint64 ColorCorrectDBusInterface::previousTransitionDateTime() const return 0; } -quint32 ColorCorrectDBusInterface::previousTransitionDuration() const +quint32 NightColorDBusInterface::previousTransitionDuration() const { return quint32(m_manager->previousTransitionDuration()); } -quint64 ColorCorrectDBusInterface::scheduledTransitionDateTime() const +quint64 NightColorDBusInterface::scheduledTransitionDateTime() const { const QDateTime dateTime = m_manager->scheduledTransitionDateTime(); if (dateTime.isValid()) { @@ -244,27 +242,27 @@ quint64 ColorCorrectDBusInterface::scheduledTransitionDateTime() const return 0; } -quint32 ColorCorrectDBusInterface::scheduledTransitionDuration() const +quint32 NightColorDBusInterface::scheduledTransitionDuration() const { return quint32(m_manager->scheduledTransitionDuration()); } -QHash ColorCorrectDBusInterface::nightColorInfo() +QHash NightColorDBusInterface::nightColorInfo() { return m_manager->info(); } -bool ColorCorrectDBusInterface::setNightColorConfig(QHash data) +bool NightColorDBusInterface::setNightColorConfig(QHash data) { return m_manager->changeConfiguration(data); } -void ColorCorrectDBusInterface::nightColorAutoLocationUpdate(double latitude, double longitude) +void NightColorDBusInterface::nightColorAutoLocationUpdate(double latitude, double longitude) { m_manager->autoLocationUpdate(latitude, longitude); } -uint ColorCorrectDBusInterface::inhibit() +uint NightColorDBusInterface::inhibit() { const QString serviceName = QDBusContext::message().service(); @@ -279,14 +277,14 @@ uint ColorCorrectDBusInterface::inhibit() return m_lastInhibitionCookie; } -void ColorCorrectDBusInterface::uninhibit(uint cookie) +void NightColorDBusInterface::uninhibit(uint cookie) { const QString serviceName = QDBusContext::message().service(); uninhibit(serviceName, cookie); } -void ColorCorrectDBusInterface::uninhibit(const QString &serviceName, uint cookie) +void NightColorDBusInterface::uninhibit(const QString &serviceName, uint cookie) { const int removedCount = m_inhibitors.remove(serviceName, cookie); if (!removedCount) { @@ -300,7 +298,7 @@ void ColorCorrectDBusInterface::uninhibit(const QString &serviceName, uint cooki m_manager->uninhibit(); } -void ColorCorrectDBusInterface::removeInhibitorService(const QString &serviceName) +void NightColorDBusInterface::removeInhibitorService(const QString &serviceName) { const auto cookies = m_inhibitors.values(serviceName); for (const uint &cookie : cookies) { @@ -309,4 +307,3 @@ void ColorCorrectDBusInterface::removeInhibitorService(const QString &serviceNam } } -} diff --git a/colorcorrection/colorcorrectdbusinterface.h b/plugins/nightcolor/nightcolordbusinterface.h similarity index 91% rename from colorcorrection/colorcorrectdbusinterface.h rename to plugins/nightcolor/nightcolordbusinterface.h index b10ef79bf6..a54885af44 100644 --- a/colorcorrection/colorcorrectdbusinterface.h +++ b/plugins/nightcolor/nightcolordbusinterface.h @@ -7,8 +7,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef KWIN_NIGHTCOLOR_DBUS_INTERFACE_H -#define KWIN_NIGHTCOLOR_DBUS_INTERFACE_H +#pragma once #include #include @@ -16,12 +15,9 @@ namespace KWin { -namespace ColorCorrect -{ +class NightColorManager; -class Manager; - -class ColorCorrectDBusInterface : public QObject, public QDBusContext +class NightColorDBusInterface : public QObject, public QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.ColorCorrect") @@ -38,8 +34,8 @@ class ColorCorrectDBusInterface : public QObject, public QDBusContext Q_PROPERTY(quint32 scheduledTransitionDuration READ scheduledTransitionDuration) public: - explicit ColorCorrectDBusInterface(Manager *parent); - ~ColorCorrectDBusInterface() override = default; + explicit NightColorDBusInterface(NightColorManager *parent); + ~NightColorDBusInterface() override = default; bool isInhibited() const; bool isEnabled() const; @@ -143,14 +139,10 @@ private Q_SLOTS: private: void uninhibit(const QString &serviceName, uint cookie); - Manager *m_manager; + NightColorManager *m_manager; QDBusServiceWatcher *m_inhibitorWatcher; QMultiHash m_inhibitors; uint m_lastInhibitionCookie = 0; }; } - -} - -#endif // KWIN_NIGHTCOLOR_DBUS_INTERFACE_H diff --git a/colorcorrection/manager.cpp b/plugins/nightcolor/nightcolormanager.cpp similarity index 86% rename from colorcorrection/manager.cpp rename to plugins/nightcolor/nightcolormanager.cpp index d2c968fd16..4a83d4a52a 100644 --- a/colorcorrection/manager.cpp +++ b/plugins/nightcolor/nightcolormanager.cpp @@ -6,11 +6,12 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -#include "manager.h" +#include "nightcolormanager.h" #include "clockskewnotifier.h" -#include "colorcorrectdbusinterface.h" +#include "nightcolordbusinterface.h" +#include "nightcolorlogging.h" +#include "nightcolorsettings.h" #include "suncalc.h" -#include #include #include @@ -19,8 +20,6 @@ #include #include -#include - #include #include @@ -29,26 +28,31 @@ #include namespace KWin { -namespace ColorCorrect { static const int QUICK_ADJUST_DURATION = 2000; static const int TEMPERATURE_STEP = 50; +static NightColorManager *s_instance = nullptr; static bool checkLocation(double lat, double lng) { return -90 <= lat && lat <= 90 && -180 <= lng && lng <= 180; } -Manager::Manager(QObject *parent) - : QObject(parent) +NightColorManager *NightColorManager::self() { - m_iface = new ColorCorrectDBusInterface(this); + return s_instance; +} + +NightColorManager::NightColorManager(QObject *parent) + : Plugin(parent) +{ + s_instance = this; + + m_iface = new NightColorDBusInterface(this); m_skewNotifier = new ClockSkewNotifier(this); - connect(kwinApp(), &Application::workspaceCreated, this, &Manager::init); - // Display a message when Night Color is (un)inhibited. - connect(this, &Manager::inhibitedChanged, this, [this] { + connect(this, &NightColorManager::inhibitedChanged, this, [this] { // TODO: Maybe use different icons? const QString iconName = isInhibited() ? QStringLiteral("preferences-desktop-display-nightcolor-off") @@ -67,11 +71,22 @@ Manager::Manager(QObject *parent) QDBusConnection::sessionBus().asyncCall(message); }); + + if (workspace()) { + init(); + } else { + connect(kwinApp(), &Application::workspaceCreated, this, &NightColorManager::init); + } } -void Manager::init() +NightColorManager::~NightColorManager() { - Settings::instance(kwinApp()->config()); + s_instance = nullptr; +} + +void NightColorManager::init() +{ + NightColorSettings::instance(kwinApp()->config()); // we may always read in the current config readConfig(); @@ -79,7 +94,22 @@ void Manager::init() return; } - connect(Screens::self(), &Screens::countChanged, this, &Manager::hardReset); + // legacy shortcut with localized key (to avoid breaking existing config) + if (i18n("Toggle Night Color") != QStringLiteral("Toggle Night Color")) { + QAction toggleActionLegacy; + toggleActionLegacy.setProperty("componentName", QStringLiteral(KWIN_NAME)); + toggleActionLegacy.setObjectName(i18n("Toggle Night Color")); + KGlobalAccel::self()->removeAllShortcuts(&toggleActionLegacy); + } + + QAction *toggleAction = new QAction(this); + toggleAction->setProperty("componentName", QStringLiteral(KWIN_NAME)); + toggleAction->setObjectName(QStringLiteral("Toggle Night Color")); + toggleAction->setText(i18n("Toggle Night Color")); + KGlobalAccel::setGlobalShortcut(toggleAction, QList()); + input()->registerShortcut(QKeySequence(), toggleAction, this, &NightColorManager::toggle); + + connect(Screens::self(), &Screens::countChanged, this, &NightColorManager::hardReset); connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged, this, [this](bool active) { @@ -105,7 +135,7 @@ void Manager::init() if (reply.isValid()) { comingFromSuspend = reply.value().toBool(); } else { - qCDebug(KWIN_COLORCORRECTION) << "Failed to get PreparingForSleep Property of logind session:" << reply.error().message(); + qCDebug(KWIN_NIGHTCOLOR) << "Failed to get PreparingForSleep Property of logind session:" << reply.error().message(); // Always do a hard reset in case we have no further information. comingFromSuspend = true; } @@ -120,7 +150,7 @@ void Manager::init() hardReset(); } -void Manager::hardReset() +void NightColorManager::hardReset() { cancelAllTimers(); @@ -134,25 +164,25 @@ void Manager::hardReset() resetAllTimers(); } -void Manager::reparseConfigAndReset() +void NightColorManager::reparseConfigAndReset() { cancelAllTimers(); readConfig(); hardReset(); } -void Manager::toggle() +void NightColorManager::toggle() { m_isGloballyInhibited = !m_isGloballyInhibited; m_isGloballyInhibited ? inhibit() : uninhibit(); } -bool Manager::isInhibited() const +bool NightColorManager::isInhibited() const { return m_inhibitReferenceCount; } -void Manager::inhibit() +void NightColorManager::inhibit() { m_inhibitReferenceCount++; @@ -162,7 +192,7 @@ void Manager::inhibit() } } -void Manager::uninhibit() +void NightColorManager::uninhibit() { m_inhibitReferenceCount--; @@ -172,77 +202,59 @@ void Manager::uninhibit() } } -bool Manager::isEnabled() const +bool NightColorManager::isEnabled() const { return m_active; } -bool Manager::isRunning() const +bool NightColorManager::isRunning() const { return m_running; } -bool Manager::isAvailable() const +bool NightColorManager::isAvailable() const { return kwinApp()->platform()->supportsGammaControl(); } -int Manager::currentTemperature() const +int NightColorManager::currentTemperature() const { return m_currentTemp; } -int Manager::targetTemperature() const +int NightColorManager::targetTemperature() const { return m_targetTemperature; } -NightColorMode Manager::mode() const +NightColorMode NightColorManager::mode() const { return m_mode; } -QDateTime Manager::previousTransitionDateTime() const +QDateTime NightColorManager::previousTransitionDateTime() const { return m_prev.first; } -qint64 Manager::previousTransitionDuration() const +qint64 NightColorManager::previousTransitionDuration() const { return m_prev.first.msecsTo(m_prev.second); } -QDateTime Manager::scheduledTransitionDateTime() const +QDateTime NightColorManager::scheduledTransitionDateTime() const { return m_next.first; } -qint64 Manager::scheduledTransitionDuration() const +qint64 NightColorManager::scheduledTransitionDuration() const { return m_next.first.msecsTo(m_next.second); } -void Manager::initShortcuts() +void NightColorManager::readConfig() { - // legacy shortcut with localized key (to avoid breaking existing config) - if (i18n("Toggle Night Color") != QStringLiteral("Toggle Night Color")) { - QAction toggleActionLegacy; - toggleActionLegacy.setProperty("componentName", QStringLiteral(KWIN_NAME)); - toggleActionLegacy.setObjectName(i18n("Toggle Night Color")); - KGlobalAccel::self()->removeAllShortcuts(&toggleActionLegacy); - } - - QAction *toggleAction = new QAction(this); - toggleAction->setProperty("componentName", QStringLiteral(KWIN_NAME)); - toggleAction->setObjectName(QStringLiteral("Toggle Night Color")); - toggleAction->setText(i18n("Toggle Night Color")); - KGlobalAccel::setGlobalShortcut(toggleAction, QList()); - input()->registerShortcut(QKeySequence(), toggleAction, this, &Manager::toggle); -} - -void Manager::readConfig() -{ - Settings *s = Settings::self(); + NightColorSettings *s = NightColorSettings::self(); s->load(); setEnabled(s->active()); @@ -309,7 +321,7 @@ void Manager::readConfig() m_trTime = qMax(trTime / 1000 / 60, 1); } -void Manager::resetAllTimers() +void NightColorManager::resetAllTimers() { cancelAllTimers(); if (isAvailable()) { @@ -321,7 +333,7 @@ void Manager::resetAllTimers() } } -void Manager::cancelAllTimers() +void NightColorManager::cancelAllTimers() { delete m_slowUpdateStartTimer; delete m_slowUpdateTimer; @@ -332,7 +344,7 @@ void Manager::cancelAllTimers() m_quickAdjustTimer = nullptr; } -void Manager::resetQuickAdjustTimer() +void NightColorManager::resetQuickAdjustTimer() { updateTransitionTimings(false); updateTargetTemperature(); @@ -343,7 +355,7 @@ void Manager::resetQuickAdjustTimer() cancelAllTimers(); m_quickAdjustTimer = new QTimer(this); m_quickAdjustTimer->setSingleShot(false); - connect(m_quickAdjustTimer, &QTimer::timeout, this, &Manager::quickAdjust); + connect(m_quickAdjustTimer, &QTimer::timeout, this, &NightColorManager::quickAdjust); int interval = QUICK_ADJUST_DURATION / (tempDiff / TEMPERATURE_STEP); if (interval == 0) { @@ -355,7 +367,7 @@ void Manager::resetQuickAdjustTimer() } } -void Manager::quickAdjust() +void NightColorManager::quickAdjust() { if (!m_quickAdjustTimer) { return; @@ -379,7 +391,7 @@ void Manager::quickAdjust() } } -void Manager::resetSlowUpdateStartTimer() +void NightColorManager::resetSlowUpdateStartTimer() { delete m_slowUpdateStartTimer; m_slowUpdateStartTimer = nullptr; @@ -398,14 +410,14 @@ void Manager::resetSlowUpdateStartTimer() // set up the next slow update m_slowUpdateStartTimer = new QTimer(this); m_slowUpdateStartTimer->setSingleShot(true); - connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &Manager::resetSlowUpdateStartTimer); + connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &NightColorManager::resetSlowUpdateStartTimer); updateTransitionTimings(false); updateTargetTemperature(); const int diff = QDateTime::currentDateTime().msecsTo(m_next.first); if (diff <= 0) { - qCCritical(KWIN_COLORCORRECTION) << "Error in time calculation. Deactivating Night Color."; + qCCritical(KWIN_NIGHTCOLOR) << "Error in time calculation. Deactivating Night Color."; return; } m_slowUpdateStartTimer->start(diff); @@ -414,7 +426,7 @@ void Manager::resetSlowUpdateStartTimer() resetSlowUpdateTimer(); } -void Manager::resetSlowUpdateTimer() +void NightColorManager::resetSlowUpdateTimer() { delete m_slowUpdateTimer; m_slowUpdateTimer = nullptr; @@ -448,7 +460,7 @@ void Manager::resetSlowUpdateTimer() } } -void Manager::slowUpdate(int targetTemp) +void NightColorManager::slowUpdate(int targetTemp) { if (!m_slowUpdateTimer) { return; @@ -467,7 +479,7 @@ void Manager::slowUpdate(int targetTemp) } } -void Manager::updateTargetTemperature() +void NightColorManager::updateTargetTemperature() { const int targetTemperature = mode() != NightColorMode::Constant && daylight() ? m_dayTargetTemp : m_nightTargetTemp; @@ -480,7 +492,7 @@ void Manager::updateTargetTemperature() emit targetTemperatureChanged(); } -void Manager::updateTransitionTimings(bool force) +void NightColorManager::updateTransitionTimings(bool force) { if (m_mode == NightColorMode::Constant) { m_next = DateTimes(); @@ -557,7 +569,7 @@ void Manager::updateTransitionTimings(bool force) emit scheduledTransitionTimingsChanged(); } -DateTimes Manager::getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const +DateTimes NightColorManager::getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const { DateTimes dateTimes = calculateSunTimings(dateTime, latitude, longitude, morning); // At locations near the poles it is possible, that we can't @@ -582,7 +594,7 @@ DateTimes Manager::getSunTimings(const QDateTime &dateTime, double latitude, dou return dateTimes; } -bool Manager::checkAutomaticSunTimings() const +bool NightColorManager::checkAutomaticSunTimings() const { if (m_prev.first.isValid() && m_prev.second.isValid() && m_next.first.isValid() && m_next.second.isValid()) { @@ -593,12 +605,12 @@ bool Manager::checkAutomaticSunTimings() const return false; } -bool Manager::daylight() const +bool NightColorManager::daylight() const { return m_prev.first.date() == m_next.first.date(); } -int Manager::currentTargetTemp() const +int NightColorManager::currentTargetTemp() const { if (!m_running) { return NEUTRAL_TEMPERATURE; @@ -630,7 +642,7 @@ int Manager::currentTargetTemp() const } } -void Manager::commitGammaRamps(int temperature) +void NightColorManager::commitGammaRamps(int temperature) { const auto outs = kwinApp()->platform()->outputs(); @@ -674,11 +686,11 @@ void Manager::commitGammaRamps(int temperature) } else { m_failedCommitAttempts++; if (m_failedCommitAttempts < 10) { - qCWarning(KWIN_COLORCORRECTION).nospace() << "Committing Gamma Ramp failed for output " << o->name() << + qCWarning(KWIN_NIGHTCOLOR).nospace() << "Committing Gamma Ramp failed for output " << o->name() << ". Trying " << (10 - m_failedCommitAttempts) << " times more."; } else { // TODO: On multi monitor setups we could try to rollback earlier changes for already committed outputs - qCWarning(KWIN_COLORCORRECTION) << "Gamma Ramp commit failed too often. Deactivating color correction for now."; + qCWarning(KWIN_NIGHTCOLOR) << "Gamma Ramp commit failed too often. Deactivating Night Color for now."; m_failedCommitAttempts = 0; // reset so we can try again later (i.e. after suspend phase or config change) setRunning(false); cancelAllTimers(); @@ -687,7 +699,7 @@ void Manager::commitGammaRamps(int temperature) } } -QHash Manager::info() const +QHash NightColorManager::info() const { return QHash { { QStringLiteral("Available"), isAvailable() }, @@ -718,7 +730,7 @@ QHash Manager::info() const }; } -bool Manager::changeConfiguration(QHash data) +bool NightColorManager::changeConfiguration(QHash data) { bool activeUpdate, modeUpdate, tempUpdate, locUpdate, timeUpdate; activeUpdate = modeUpdate = tempUpdate = locUpdate = timeUpdate = false; @@ -841,7 +853,7 @@ bool Manager::changeConfiguration(QHash data) cancelAllTimers(); } - Settings *s = Settings::self(); + NightColorSettings *s = NightColorSettings::self(); if (activeUpdate) { setEnabled(active); s->setActive(active); @@ -881,9 +893,9 @@ bool Manager::changeConfiguration(QHash data) return true; } -void Manager::autoLocationUpdate(double latitude, double longitude) +void NightColorManager::autoLocationUpdate(double latitude, double longitude) { - qCDebug(KWIN_COLORCORRECTION, "Received new location (lat: %f, lng: %f)", latitude, longitude); + qCDebug(KWIN_NIGHTCOLOR, "Received new location (lat: %f, lng: %f)", latitude, longitude); if (!checkLocation(latitude, longitude)) { return; @@ -897,7 +909,7 @@ void Manager::autoLocationUpdate(double latitude, double longitude) m_latAuto = latitude; m_lngAuto = longitude; - Settings *s = Settings::self(); + NightColorSettings *s = NightColorSettings::self(); s->setLatitudeAuto(latitude); s->setLongitudeAuto(longitude); s->save(); @@ -906,7 +918,7 @@ void Manager::autoLocationUpdate(double latitude, double longitude) emit configChange(info()); } -void Manager::setEnabled(bool enabled) +void NightColorManager::setEnabled(bool enabled) { if (m_active == enabled) { return; @@ -916,7 +928,7 @@ void Manager::setEnabled(bool enabled) emit enabledChanged(); } -void Manager::setRunning(bool running) +void NightColorManager::setRunning(bool running) { if (m_running == running) { return; @@ -925,7 +937,7 @@ void Manager::setRunning(bool running) emit runningChanged(); } -void Manager::setCurrentTemperature(int temperature) +void NightColorManager::setCurrentTemperature(int temperature) { if (m_currentTemp == temperature) { return; @@ -934,7 +946,7 @@ void Manager::setCurrentTemperature(int temperature) emit currentTemperatureChanged(); } -void Manager::setMode(NightColorMode mode) +void NightColorManager::setMode(NightColorMode mode) { if (m_mode == mode) { return; @@ -943,5 +955,4 @@ void Manager::setMode(NightColorMode mode) emit modeChanged(); } -} -} +} // namespace KWin diff --git a/colorcorrection/manager.h b/plugins/nightcolor/nightcolormanager.h similarity index 94% rename from colorcorrection/manager.h rename to plugins/nightcolor/nightcolormanager.h index e892a2e3a4..120ad44513 100644 --- a/colorcorrection/manager.h +++ b/plugins/nightcolor/nightcolormanager.h @@ -6,11 +6,11 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef KWIN_COLORCORRECT_MANAGER_H -#define KWIN_COLORCORRECT_MANAGER_H + +#pragma once #include "constants.h" -#include +#include "plugin.h" #include #include @@ -22,16 +22,11 @@ namespace KWin { class ClockSkewNotifier; -class Workspace; - -namespace ColorCorrect -{ +class NightColorDBusInterface; typedef QPair DateTimes; typedef QPair Times; -class ColorCorrectDBusInterface; - /** * This enum type is used to specify operation mode of the night color manager. */ @@ -76,12 +71,14 @@ enum NightColorMode { * * With the Constant mode, screen color temperature is always constant. */ -class KWIN_EXPORT Manager : public QObject +class KWIN_EXPORT NightColorManager : public Plugin { Q_OBJECT public: - Manager(QObject *parent); + explicit NightColorManager(QObject *parent = nullptr); + ~NightColorManager() override; + void init(); /** @@ -190,6 +187,7 @@ public: // for auto tests void reparseConfigAndReset(); + static NightColorManager *self(); public Q_SLOTS: void resetSlowUpdateStartTimer(); @@ -239,7 +237,6 @@ Q_SIGNALS: void scheduledTransitionTimingsChanged(); private: - void initShortcuts(); void readConfig(); void hardReset(); void slowUpdate(int targetTemp); @@ -268,7 +265,7 @@ private: void setCurrentTemperature(int temperature); void setMode(NightColorMode mode); - ColorCorrectDBusInterface *m_iface; + NightColorDBusInterface *m_iface; ClockSkewNotifier *m_skewNotifier; // Specifies whether Night Color is enabled. @@ -309,12 +306,6 @@ private: int m_failedCommitAttempts = 0; int m_inhibitReferenceCount = 0; - - // The Workspace class needs to call initShortcuts during initialization. - friend class KWin::Workspace; }; -} -} - -#endif // KWIN_COLORCORRECT_MANAGER_H +} // namespace KWin diff --git a/colorcorrection/colorcorrect_settings.kcfg b/plugins/nightcolor/nightcolorsettings.kcfg similarity index 96% rename from colorcorrection/colorcorrect_settings.kcfg rename to plugins/nightcolor/nightcolorsettings.kcfg index 375caf766b..d235fba1f9 100644 --- a/colorcorrection/colorcorrect_settings.kcfg +++ b/plugins/nightcolor/nightcolorsettings.kcfg @@ -15,7 +15,7 @@ true - + diff --git a/plugins/nightcolor/nightcolorsettings.kcfgc b/plugins/nightcolor/nightcolorsettings.kcfgc new file mode 100644 index 0000000000..0ca271243d --- /dev/null +++ b/plugins/nightcolor/nightcolorsettings.kcfgc @@ -0,0 +1,8 @@ +File=nightcolorsettings.kcfg +NameSpace=KWin +ClassName=NightColorSettings +Singleton=true +Mutators=true +# nightcolormanager.h is needed for NightColorMode +IncludeFiles=nightcolormanager.h +UseEnumTypes=true diff --git a/org.kde.kwin.ColorCorrect.xml b/plugins/nightcolor/org.kde.kwin.ColorCorrect.xml similarity index 100% rename from org.kde.kwin.ColorCorrect.xml rename to plugins/nightcolor/org.kde.kwin.ColorCorrect.xml diff --git a/colorcorrection/suncalc.cpp b/plugins/nightcolor/suncalc.cpp similarity index 99% rename from colorcorrection/suncalc.cpp rename to plugins/nightcolor/suncalc.cpp index 20b0ae92ed..6d32e481a4 100644 --- a/colorcorrection/suncalc.cpp +++ b/plugins/nightcolor/suncalc.cpp @@ -14,7 +14,6 @@ #include namespace KWin { -namespace ColorCorrect { #define TWILIGHT_NAUT -12.0 #define TWILIGHT_CIVIL -6.0 @@ -160,4 +159,3 @@ QPair calculateSunTimings(const QDateTime &dateTime, doubl } } -} diff --git a/colorcorrection/suncalc.h b/plugins/nightcolor/suncalc.h similarity index 96% rename from colorcorrection/suncalc.h rename to plugins/nightcolor/suncalc.h index 73fa94c85d..45c8c4c604 100644 --- a/colorcorrection/suncalc.h +++ b/plugins/nightcolor/suncalc.h @@ -16,9 +16,6 @@ namespace KWin { -namespace ColorCorrect -{ - /** * Calculates for a given location and date two of the * following sun timings in their temporal order: @@ -29,8 +26,6 @@ namespace ColorCorrect QPair calculateSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning); - -} } #endif // KWIN_SUNCALCULATOR_H diff --git a/useractions.cpp b/useractions.cpp index e22ac02a06..6954cce728 100644 --- a/useractions.cpp +++ b/useractions.cpp @@ -25,7 +25,6 @@ #include "useractions.h" #include "cursor.h" #include "x11client.h" -#include "colorcorrection/manager.h" #include "composite.h" #include "input.h" #include "workspace.h" @@ -967,7 +966,6 @@ void Workspace::initShortcuts() TabBox::TabBox::self()->initShortcuts(); #endif VirtualDesktopManager::self()->initShortcuts(); - kwinApp()->platform()->colorCorrectManager()->initShortcuts(); m_userActionsMenu->discard(); // so that it's recreated next time }