From 6fb8eac89071cb2193b20279aa3c5dde83000a2e Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 8 Feb 2024 22:35:52 +0200 Subject: [PATCH] plugins/{nightcolor -> nightlight} --- src/plugins/CMakeLists.txt | 2 +- src/plugins/nightcolor/CMakeLists.txt | 31 ---- .../nightcolor/nightcolorsettings.kcfgc | 8 - src/plugins/nightlight/CMakeLists.txt | 31 ++++ .../clockskewnotifier.cpp | 0 .../clockskewnotifier.h | 0 .../clockskewnotifierengine.cpp | 0 .../clockskewnotifierengine_linux.cpp | 0 .../clockskewnotifierengine_linux.h | 0 .../clockskewnotifierengine_p.h | 0 .../{nightcolor => nightlight}/constants.h | 0 .../{nightcolor => nightlight}/main.cpp | 10 +- .../{nightcolor => nightlight}/metadata.json | 0 .../nightlightdbusinterface.cpp} | 68 ++++---- .../nightlightdbusinterface.h} | 12 +- .../nightlightmanager.cpp} | 148 +++++++++--------- .../nightlightmanager.h} | 56 +++---- .../nightlightsettings.kcfg} | 4 +- .../nightlight/nightlightsettings.kcfgc | 8 + .../org.kde.KWin.NightLight.xml | 0 .../{nightcolor => nightlight}/suncalc.cpp | 0 .../{nightcolor => nightlight}/suncalc.h | 0 22 files changed, 189 insertions(+), 189 deletions(-) delete mode 100644 src/plugins/nightcolor/CMakeLists.txt delete mode 100644 src/plugins/nightcolor/nightcolorsettings.kcfgc create mode 100644 src/plugins/nightlight/CMakeLists.txt rename src/plugins/{nightcolor => nightlight}/clockskewnotifier.cpp (100%) rename src/plugins/{nightcolor => nightlight}/clockskewnotifier.h (100%) rename src/plugins/{nightcolor => nightlight}/clockskewnotifierengine.cpp (100%) rename src/plugins/{nightcolor => nightlight}/clockskewnotifierengine_linux.cpp (100%) rename src/plugins/{nightcolor => nightlight}/clockskewnotifierengine_linux.h (100%) rename src/plugins/{nightcolor => nightlight}/clockskewnotifierengine_p.h (100%) rename src/plugins/{nightcolor => nightlight}/constants.h (100%) rename src/plugins/{nightcolor => nightlight}/main.cpp (60%) rename src/plugins/{nightcolor => nightlight}/metadata.json (100%) rename src/plugins/{nightcolor/nightcolordbusinterface.cpp => nightlight/nightlightdbusinterface.cpp} (82%) rename src/plugins/{nightcolor/nightcolordbusinterface.h => nightlight/nightlightdbusinterface.h} (89%) rename src/plugins/{nightcolor/nightcolormanager.cpp => nightlight/nightlightmanager.cpp} (83%) rename src/plugins/{nightcolor/nightcolormanager.h => nightlight/nightlightmanager.h} (83%) rename src/plugins/{nightcolor/nightcolorsettings.kcfg => nightlight/nightlightsettings.kcfg} (93%) create mode 100644 src/plugins/nightlight/nightlightsettings.kcfgc rename src/plugins/{nightcolor => nightlight}/org.kde.KWin.NightLight.xml (100%) rename src/plugins/{nightcolor => nightlight}/suncalc.cpp (100%) rename src/plugins/{nightcolor => nightlight}/suncalc.h (100%) diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 8b2faeaada..05e0ad3a6c 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -80,7 +80,7 @@ add_subdirectory(minimizeall) add_subdirectory(morphingpopups) add_subdirectory(mouseclick) add_subdirectory(mousemark) -add_subdirectory(nightcolor) +add_subdirectory(nightlight) add_subdirectory(outputlocator) add_subdirectory(overview) add_subdirectory(qpa) diff --git a/src/plugins/nightcolor/CMakeLists.txt b/src/plugins/nightcolor/CMakeLists.txt deleted file mode 100644 index 995609af4f..0000000000 --- a/src/plugins/nightcolor/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -kcoreaddons_add_plugin(nightcolor INSTALL_NAMESPACE "kwin/plugins") -target_sources(nightcolor PRIVATE - clockskewnotifier.cpp - clockskewnotifierengine.cpp - nightcolordbusinterface.cpp - nightcolormanager.cpp - main.cpp - suncalc.cpp -) - -ecm_qt_declare_logging_category(nightcolor - HEADER nightcolorlogging.h - IDENTIFIER KWIN_NIGHTCOLOR - CATEGORY_NAME kwin_nightcolor - DEFAULT_SEVERITY Critical -) - -kconfig_add_kcfg_files(nightcolor nightcolorsettings.kcfgc) - -set(nightcolor_xml_SOURCES) -qt_add_dbus_adaptor(nightcolor_xml_SOURCES org.kde.KWin.NightLight.xml nightcolordbusinterface.h KWin::NightColorDBusInterface) -target_sources(nightcolor PRIVATE ${nightcolor_xml_SOURCES}) - -if (CMAKE_SYSTEM_NAME MATCHES "Linux") - target_sources(nightcolor PRIVATE clockskewnotifierengine_linux.cpp) -endif() - -target_link_libraries(nightcolor kwin KF6::ConfigGui KF6::GlobalAccel KF6::I18n) - -install(FILES nightcolorsettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) -install(FILES org.kde.KWin.NightLight.xml DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR}) diff --git a/src/plugins/nightcolor/nightcolorsettings.kcfgc b/src/plugins/nightcolor/nightcolorsettings.kcfgc deleted file mode 100644 index 0ca271243d..0000000000 --- a/src/plugins/nightcolor/nightcolorsettings.kcfgc +++ /dev/null @@ -1,8 +0,0 @@ -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/src/plugins/nightlight/CMakeLists.txt b/src/plugins/nightlight/CMakeLists.txt new file mode 100644 index 0000000000..583a3e8340 --- /dev/null +++ b/src/plugins/nightlight/CMakeLists.txt @@ -0,0 +1,31 @@ +kcoreaddons_add_plugin(nightlight INSTALL_NAMESPACE "kwin/plugins") +target_sources(nightlight PRIVATE + clockskewnotifier.cpp + clockskewnotifierengine.cpp + nightlightdbusinterface.cpp + nightlightmanager.cpp + main.cpp + suncalc.cpp +) + +ecm_qt_declare_logging_category(nightlight + HEADER nightlightlogging.h + IDENTIFIER KWIN_NIGHTLIGHT + CATEGORY_NAME kwin_nightlight + DEFAULT_SEVERITY Critical +) + +kconfig_add_kcfg_files(nightlight nightlightsettings.kcfgc) + +set(nightlight_xml_SOURCES) +qt_add_dbus_adaptor(nightlight_xml_SOURCES org.kde.KWin.NightLight.xml nightlightdbusinterface.h KWin::NightLightDBusInterface) +target_sources(nightlight PRIVATE ${nightlight_xml_SOURCES}) + +if (CMAKE_SYSTEM_NAME MATCHES "Linux") + target_sources(nightlight PRIVATE clockskewnotifierengine_linux.cpp) +endif() + +target_link_libraries(nightlight kwin KF6::ConfigGui KF6::GlobalAccel KF6::I18n) + +install(FILES nightlightsettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) +install(FILES org.kde.KWin.NightLight.xml DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR}) diff --git a/src/plugins/nightcolor/clockskewnotifier.cpp b/src/plugins/nightlight/clockskewnotifier.cpp similarity index 100% rename from src/plugins/nightcolor/clockskewnotifier.cpp rename to src/plugins/nightlight/clockskewnotifier.cpp diff --git a/src/plugins/nightcolor/clockskewnotifier.h b/src/plugins/nightlight/clockskewnotifier.h similarity index 100% rename from src/plugins/nightcolor/clockskewnotifier.h rename to src/plugins/nightlight/clockskewnotifier.h diff --git a/src/plugins/nightcolor/clockskewnotifierengine.cpp b/src/plugins/nightlight/clockskewnotifierengine.cpp similarity index 100% rename from src/plugins/nightcolor/clockskewnotifierengine.cpp rename to src/plugins/nightlight/clockskewnotifierengine.cpp diff --git a/src/plugins/nightcolor/clockskewnotifierengine_linux.cpp b/src/plugins/nightlight/clockskewnotifierengine_linux.cpp similarity index 100% rename from src/plugins/nightcolor/clockskewnotifierengine_linux.cpp rename to src/plugins/nightlight/clockskewnotifierengine_linux.cpp diff --git a/src/plugins/nightcolor/clockskewnotifierengine_linux.h b/src/plugins/nightlight/clockskewnotifierengine_linux.h similarity index 100% rename from src/plugins/nightcolor/clockskewnotifierengine_linux.h rename to src/plugins/nightlight/clockskewnotifierengine_linux.h diff --git a/src/plugins/nightcolor/clockskewnotifierengine_p.h b/src/plugins/nightlight/clockskewnotifierengine_p.h similarity index 100% rename from src/plugins/nightcolor/clockskewnotifierengine_p.h rename to src/plugins/nightlight/clockskewnotifierengine_p.h diff --git a/src/plugins/nightcolor/constants.h b/src/plugins/nightlight/constants.h similarity index 100% rename from src/plugins/nightcolor/constants.h rename to src/plugins/nightlight/constants.h diff --git a/src/plugins/nightcolor/main.cpp b/src/plugins/nightlight/main.cpp similarity index 60% rename from src/plugins/nightcolor/main.cpp rename to src/plugins/nightlight/main.cpp index 4a2209c279..9b3c293bde 100644 --- a/src/plugins/nightcolor/main.cpp +++ b/src/plugins/nightlight/main.cpp @@ -4,27 +4,27 @@ SPDX-License-Identifier: LGPL-2.0-or-later */ -#include "nightcolormanager.h" +#include "nightlightmanager.h" #include using namespace KWin; -class KWIN_EXPORT NightColorManagerFactory : public PluginFactory +class KWIN_EXPORT NightLightManagerFactory : public PluginFactory { Q_OBJECT Q_PLUGIN_METADATA(IID PluginFactory_iid FILE "metadata.json") Q_INTERFACES(KWin::PluginFactory) public: - explicit NightColorManagerFactory() = default; + explicit NightLightManagerFactory() = default; std::unique_ptr create() const override; }; -std::unique_ptr NightColorManagerFactory::create() const +std::unique_ptr NightLightManagerFactory::create() const { - return std::make_unique(); + return std::make_unique(); } #include "main.moc" diff --git a/src/plugins/nightcolor/metadata.json b/src/plugins/nightlight/metadata.json similarity index 100% rename from src/plugins/nightcolor/metadata.json rename to src/plugins/nightlight/metadata.json diff --git a/src/plugins/nightcolor/nightcolordbusinterface.cpp b/src/plugins/nightlight/nightlightdbusinterface.cpp similarity index 82% rename from src/plugins/nightcolor/nightcolordbusinterface.cpp rename to src/plugins/nightlight/nightlightdbusinterface.cpp index d3cf84666d..f1091c47c0 100644 --- a/src/plugins/nightcolor/nightcolordbusinterface.cpp +++ b/src/plugins/nightlight/nightlightdbusinterface.cpp @@ -7,16 +7,16 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -#include "nightcolordbusinterface.h" -#include "nightcolormanager.h" +#include "nightlightdbusinterface.h" #include "nightlightadaptor.h" +#include "nightlightmanager.h" #include namespace KWin { -NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) +NightLightDBusInterface::NightLightDBusInterface(NightLightManager *parent) : QObject(parent) , m_manager(parent) , m_inhibitorWatcher(new QDBusServiceWatcher(this)) @@ -24,9 +24,9 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) m_inhibitorWatcher->setConnection(QDBusConnection::sessionBus()); m_inhibitorWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); connect(m_inhibitorWatcher, &QDBusServiceWatcher::serviceUnregistered, - this, &NightColorDBusInterface::removeInhibitorService); + this, &NightLightDBusInterface::removeInhibitorService); - connect(m_manager, &NightColorManager::inhibitedChanged, this, [this] { + connect(m_manager, &NightLightManager::inhibitedChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("inhibited"), m_manager->isInhibited()); @@ -44,7 +44,7 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &NightColorManager::enabledChanged, this, [this] { + connect(m_manager, &NightLightManager::enabledChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("enabled"), m_manager->isEnabled()); @@ -62,7 +62,7 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &NightColorManager::runningChanged, this, [this] { + connect(m_manager, &NightLightManager::runningChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("running"), m_manager->isRunning()); @@ -80,7 +80,7 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &NightColorManager::currentTemperatureChanged, this, [this] { + connect(m_manager, &NightLightManager::currentTemperatureChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("currentTemperature"), m_manager->currentTemperature()); @@ -98,7 +98,7 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &NightColorManager::targetTemperatureChanged, this, [this] { + connect(m_manager, &NightLightManager::targetTemperatureChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("targetTemperature"), m_manager->targetTemperature()); @@ -116,7 +116,7 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &NightColorManager::modeChanged, this, [this] { + connect(m_manager, &NightLightManager::modeChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("mode"), uint(m_manager->mode())); @@ -134,7 +134,7 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &NightColorManager::daylightChanged, this, [this] { + connect(m_manager, &NightLightManager::daylightChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("daylight"), uint(m_manager->daylight())); @@ -152,7 +152,7 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &NightColorManager::previousTransitionTimingsChanged, this, [this] { + connect(m_manager, &NightLightManager::previousTransitionTimingsChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("previousTransitionDateTime"), previousTransitionDateTime()); changedProperties.insert(QStringLiteral("previousTransitionDuration"), previousTransitionDuration()); @@ -171,7 +171,7 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().send(message); }); - connect(m_manager, &NightColorManager::scheduledTransitionTimingsChanged, this, [this] { + connect(m_manager, &NightLightManager::scheduledTransitionTimingsChanged, this, [this] { QVariantMap changedProperties; changedProperties.insert(QStringLiteral("scheduledTransitionDateTime"), scheduledTransitionDateTime()); changedProperties.insert(QStringLiteral("scheduledTransitionDuration"), scheduledTransitionDuration()); @@ -195,52 +195,52 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent) QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.KWin.NightLight")); } -NightColorDBusInterface::~NightColorDBusInterface() +NightLightDBusInterface::~NightLightDBusInterface() { QDBusConnection::sessionBus().unregisterService(QStringLiteral("org.kde.KWin.NightLight")); } -bool NightColorDBusInterface::isInhibited() const +bool NightLightDBusInterface::isInhibited() const { return m_manager->isInhibited(); } -bool NightColorDBusInterface::isEnabled() const +bool NightLightDBusInterface::isEnabled() const { return m_manager->isEnabled(); } -bool NightColorDBusInterface::isRunning() const +bool NightLightDBusInterface::isRunning() const { return m_manager->isRunning(); } -bool NightColorDBusInterface::isAvailable() const +bool NightLightDBusInterface::isAvailable() const { return true; // TODO: Night color should register its own dbus service instead. } -int NightColorDBusInterface::currentTemperature() const +int NightLightDBusInterface::currentTemperature() const { return m_manager->currentTemperature(); } -int NightColorDBusInterface::targetTemperature() const +int NightLightDBusInterface::targetTemperature() const { return m_manager->targetTemperature(); } -int NightColorDBusInterface::mode() const +int NightLightDBusInterface::mode() const { return m_manager->mode(); } -bool NightColorDBusInterface::daylight() const +bool NightLightDBusInterface::daylight() const { return m_manager->daylight(); } -quint64 NightColorDBusInterface::previousTransitionDateTime() const +quint64 NightLightDBusInterface::previousTransitionDateTime() const { const QDateTime dateTime = m_manager->previousTransitionDateTime(); if (dateTime.isValid()) { @@ -249,12 +249,12 @@ quint64 NightColorDBusInterface::previousTransitionDateTime() const return 0; } -quint32 NightColorDBusInterface::previousTransitionDuration() const +quint32 NightLightDBusInterface::previousTransitionDuration() const { return quint32(m_manager->previousTransitionDuration()); } -quint64 NightColorDBusInterface::scheduledTransitionDateTime() const +quint64 NightLightDBusInterface::scheduledTransitionDateTime() const { const QDateTime dateTime = m_manager->scheduledTransitionDateTime(); if (dateTime.isValid()) { @@ -263,17 +263,17 @@ quint64 NightColorDBusInterface::scheduledTransitionDateTime() const return 0; } -quint32 NightColorDBusInterface::scheduledTransitionDuration() const +quint32 NightLightDBusInterface::scheduledTransitionDuration() const { return quint32(m_manager->scheduledTransitionDuration()); } -void NightColorDBusInterface::setLocation(double latitude, double longitude) +void NightLightDBusInterface::setLocation(double latitude, double longitude) { m_manager->autoLocationUpdate(latitude, longitude); } -uint NightColorDBusInterface::inhibit() +uint NightLightDBusInterface::inhibit() { const QString serviceName = QDBusContext::message().service(); @@ -288,14 +288,14 @@ uint NightColorDBusInterface::inhibit() return m_lastInhibitionCookie; } -void NightColorDBusInterface::uninhibit(uint cookie) +void NightLightDBusInterface::uninhibit(uint cookie) { const QString serviceName = QDBusContext::message().service(); uninhibit(serviceName, cookie); } -void NightColorDBusInterface::uninhibit(const QString &serviceName, uint cookie) +void NightLightDBusInterface::uninhibit(const QString &serviceName, uint cookie) { const int removedCount = m_inhibitors.remove(serviceName, cookie); if (!removedCount) { @@ -309,7 +309,7 @@ void NightColorDBusInterface::uninhibit(const QString &serviceName, uint cookie) m_manager->uninhibit(); } -void NightColorDBusInterface::removeInhibitorService(const QString &serviceName) +void NightLightDBusInterface::removeInhibitorService(const QString &serviceName) { const auto cookies = m_inhibitors.values(serviceName); for (const uint &cookie : cookies) { @@ -317,16 +317,16 @@ void NightColorDBusInterface::removeInhibitorService(const QString &serviceName) } } -void NightColorDBusInterface::preview(uint previewTemp) +void NightLightDBusInterface::preview(uint previewTemp) { m_manager->preview(previewTemp); } -void NightColorDBusInterface::stopPreview() +void NightLightDBusInterface::stopPreview() { m_manager->stopPreview(); } } -#include "moc_nightcolordbusinterface.cpp" +#include "moc_nightlightdbusinterface.cpp" diff --git a/src/plugins/nightcolor/nightcolordbusinterface.h b/src/plugins/nightlight/nightlightdbusinterface.h similarity index 89% rename from src/plugins/nightcolor/nightcolordbusinterface.h rename to src/plugins/nightlight/nightlightdbusinterface.h index 3c9d86420b..3af79be80c 100644 --- a/src/plugins/nightcolor/nightcolordbusinterface.h +++ b/src/plugins/nightlight/nightlightdbusinterface.h @@ -16,9 +16,9 @@ namespace KWin { -class NightColorManager; +class NightLightManager; -class NightColorDBusInterface : public QObject, public QDBusContext +class NightLightDBusInterface : public QObject, public QDBusContext { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.NightLight") @@ -36,8 +36,8 @@ class NightColorDBusInterface : public QObject, public QDBusContext Q_PROPERTY(quint32 scheduledTransitionDuration READ scheduledTransitionDuration) public: - explicit NightColorDBusInterface(NightColorManager *parent); - ~NightColorDBusInterface() override; + explicit NightLightDBusInterface(NightLightManager *parent); + ~NightLightDBusInterface() override; bool isInhibited() const; bool isEnabled() const; @@ -61,7 +61,7 @@ public Q_SLOTS: void setLocation(double latitude, double longitude); /** - * @brief Temporarily blocks Night Color. + * @brief Temporarily blocks Night Light. * @since 5.18 */ uint inhibit(); @@ -87,7 +87,7 @@ private Q_SLOTS: private: void uninhibit(const QString &serviceName, uint cookie); - NightColorManager *m_manager; + NightLightManager *m_manager; QDBusServiceWatcher *m_inhibitorWatcher; QMultiHash m_inhibitors; uint m_lastInhibitionCookie = 0; diff --git a/src/plugins/nightcolor/nightcolormanager.cpp b/src/plugins/nightlight/nightlightmanager.cpp similarity index 83% rename from src/plugins/nightcolor/nightcolormanager.cpp rename to src/plugins/nightlight/nightlightmanager.cpp index 3c1e9b6a93..afcf4f9185 100644 --- a/src/plugins/nightcolor/nightcolormanager.cpp +++ b/src/plugins/nightlight/nightlightmanager.cpp @@ -6,13 +6,13 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -#include "nightcolormanager.h" +#include "nightlightmanager.h" #include "clockskewnotifier.h" #include "colors/colordevice.h" #include "colors/colormanager.h" -#include "nightcolordbusinterface.h" -#include "nightcolorlogging.h" -#include "nightcolorsettings.h" +#include "nightlightdbusinterface.h" +#include "nightlightlogging.h" +#include "nightlightsettings.h" #include "suncalc.h" #include @@ -36,28 +36,28 @@ namespace KWin static const int QUICK_ADJUST_DURATION = 2000; static const int TEMPERATURE_STEP = 50; -static NightColorManager *s_instance = nullptr; +static NightLightManager *s_instance = nullptr; static bool checkLocation(double lat, double lng) { return -90 <= lat && lat <= 90 && -180 <= lng && lng <= 180; } -NightColorManager *NightColorManager::self() +NightLightManager *NightLightManager::self() { return s_instance; } -NightColorManager::NightColorManager() +NightLightManager::NightLightManager() { - NightColorSettings::instance(kwinApp()->config()); + NightLightSettings::instance(kwinApp()->config()); s_instance = this; - m_iface = new NightColorDBusInterface(this); + m_iface = new NightLightDBusInterface(this); m_skewNotifier = new ClockSkewNotifier(this); - // Display a message when Night Color is (un)inhibited. - connect(this, &NightColorManager::inhibitedChanged, this, [this] { + // Display a message when Night Light is (un)inhibited. + connect(this, &NightLightManager::inhibitedChanged, this, [this] { const QString iconName = isInhibited() ? QStringLiteral("redshift-status-off") : m_daylight && m_targetTemperature != DEFAULT_DAY_TEMPERATURE ? QStringLiteral("redshift-status-day") @@ -78,7 +78,7 @@ NightColorManager::NightColorManager() }); m_configWatcher = KConfigWatcher::create(kwinApp()->config()); - connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, &NightColorManager::reconfigure); + connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, &NightLightManager::reconfigure); // we may always read in the current config readConfig(); @@ -88,9 +88,9 @@ NightColorManager::NightColorManager() toggleAction->setObjectName(QStringLiteral("Toggle Night Color")); toggleAction->setText(i18n("Toggle Night Light")); KGlobalAccel::setGlobalShortcut(toggleAction, QList()); - connect(toggleAction, &QAction::triggered, this, &NightColorManager::toggle); + connect(toggleAction, &QAction::triggered, this, &NightLightManager::toggle); - connect(kwinApp()->colorManager(), &ColorManager::deviceAdded, this, &NightColorManager::hardReset); + connect(kwinApp()->colorManager(), &ColorManager::deviceAdded, this, &NightLightManager::hardReset); connect(kwinApp()->session(), &Session::activeChanged, this, [this](bool active) { if (active) { @@ -114,7 +114,7 @@ NightColorManager::NightColorManager() if (reply.isValid()) { comingFromSuspend = reply.value().toBool(); } else { - qCDebug(KWIN_NIGHTCOLOR) << "Failed to get PreparingForSleep Property of logind session:" << reply.error().message(); + qCDebug(KWIN_NIGHTLIGHT) << "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; } @@ -129,12 +129,12 @@ NightColorManager::NightColorManager() hardReset(); } -NightColorManager::~NightColorManager() +NightLightManager::~NightLightManager() { s_instance = nullptr; } -void NightColorManager::hardReset() +void NightLightManager::hardReset() { cancelAllTimers(); @@ -148,25 +148,25 @@ void NightColorManager::hardReset() resetAllTimers(); } -void NightColorManager::reconfigure() +void NightLightManager::reconfigure() { cancelAllTimers(); readConfig(); resetAllTimers(); } -void NightColorManager::toggle() +void NightLightManager::toggle() { m_isGloballyInhibited = !m_isGloballyInhibited; m_isGloballyInhibited ? inhibit() : uninhibit(); } -bool NightColorManager::isInhibited() const +bool NightLightManager::isInhibited() const { return m_inhibitReferenceCount; } -void NightColorManager::inhibit() +void NightLightManager::inhibit() { m_inhibitReferenceCount++; @@ -176,7 +176,7 @@ void NightColorManager::inhibit() } } -void NightColorManager::uninhibit() +void NightLightManager::uninhibit() { m_inhibitReferenceCount--; @@ -186,69 +186,69 @@ void NightColorManager::uninhibit() } } -bool NightColorManager::isEnabled() const +bool NightLightManager::isEnabled() const { return m_active; } -bool NightColorManager::isRunning() const +bool NightLightManager::isRunning() const { return m_running; } -int NightColorManager::currentTemperature() const +int NightLightManager::currentTemperature() const { return m_currentTemp; } -int NightColorManager::targetTemperature() const +int NightLightManager::targetTemperature() const { return m_targetTemperature; } -NightColorMode NightColorManager::mode() const +NightLightMode NightLightManager::mode() const { return m_mode; } -QDateTime NightColorManager::previousTransitionDateTime() const +QDateTime NightLightManager::previousTransitionDateTime() const { return m_prev.first; } -qint64 NightColorManager::previousTransitionDuration() const +qint64 NightLightManager::previousTransitionDuration() const { return m_prev.first.msecsTo(m_prev.second); } -QDateTime NightColorManager::scheduledTransitionDateTime() const +QDateTime NightLightManager::scheduledTransitionDateTime() const { return m_next.first; } -qint64 NightColorManager::scheduledTransitionDuration() const +qint64 NightLightManager::scheduledTransitionDuration() const { return m_next.first.msecsTo(m_next.second); } -void NightColorManager::readConfig() +void NightLightManager::readConfig() { - NightColorSettings *s = NightColorSettings::self(); + NightLightSettings *s = NightLightSettings::self(); s->load(); setEnabled(s->active()); - const NightColorMode mode = s->mode(); + const NightLightMode mode = s->mode(); switch (s->mode()) { - case NightColorMode::Automatic: - case NightColorMode::Location: - case NightColorMode::Timings: - case NightColorMode::Constant: + case NightLightMode::Automatic: + case NightLightMode::Location: + case NightLightMode::Timings: + case NightLightMode::Constant: setMode(mode); break; default: // Fallback for invalid setting values. - setMode(NightColorMode::Automatic); + setMode(NightLightMode::Automatic); break; } @@ -295,7 +295,7 @@ void NightColorManager::readConfig() m_trTime = std::max(trTime / 1000 / 60, 1); } -void NightColorManager::resetAllTimers() +void NightLightManager::resetAllTimers() { cancelAllTimers(); setRunning(isEnabled() && !isInhibited()); @@ -305,14 +305,14 @@ void NightColorManager::resetAllTimers() resetQuickAdjustTimer(currentTargetTemp()); } -void NightColorManager::cancelAllTimers() +void NightLightManager::cancelAllTimers() { m_slowUpdateStartTimer.reset(); m_slowUpdateTimer.reset(); m_quickAdjustTimer.reset(); } -void NightColorManager::resetQuickAdjustTimer(int targetTemp) +void NightLightManager::resetQuickAdjustTimer(int targetTemp) { int tempDiff = std::abs(targetTemp - m_currentTemp); // allow tolerance of one TEMPERATURE_STEP to compensate if a slow update is coincidental @@ -334,7 +334,7 @@ void NightColorManager::resetQuickAdjustTimer(int targetTemp) } } -void NightColorManager::quickAdjust(int targetTemp) +void NightLightManager::quickAdjust(int targetTemp) { if (!m_quickAdjustTimer) { return; @@ -356,7 +356,7 @@ void NightColorManager::quickAdjust(int targetTemp) } } -void NightColorManager::resetSlowUpdateStartTimer() +void NightLightManager::resetSlowUpdateStartTimer() { m_slowUpdateStartTimer.reset(); @@ -367,21 +367,21 @@ void NightColorManager::resetSlowUpdateStartTimer() // There is no need for starting the slow update timer. Screen color temperature // will be constant all the time now. - if (m_mode == NightColorMode::Constant) { + if (m_mode == NightLightMode::Constant) { return; } // set up the next slow update m_slowUpdateStartTimer = std::make_unique(); m_slowUpdateStartTimer->setSingleShot(true); - connect(m_slowUpdateStartTimer.get(), &QTimer::timeout, this, &NightColorManager::resetSlowUpdateStartTimer); + connect(m_slowUpdateStartTimer.get(), &QTimer::timeout, this, &NightLightManager::resetSlowUpdateStartTimer); updateTransitionTimings(false); updateTargetTemperature(); const int diff = QDateTime::currentDateTime().msecsTo(m_next.first); if (diff <= 0) { - qCCritical(KWIN_NIGHTCOLOR) << "Error in time calculation. Deactivating Night Color."; + qCCritical(KWIN_NIGHTLIGHT) << "Error in time calculation. Deactivating Night Light."; return; } m_slowUpdateStartTimer->start(diff); @@ -390,7 +390,7 @@ void NightColorManager::resetSlowUpdateStartTimer() resetSlowUpdateTimer(); } -void NightColorManager::resetSlowUpdateTimer() +void NightLightManager::resetSlowUpdateTimer() { m_slowUpdateTimer.reset(); @@ -427,7 +427,7 @@ void NightColorManager::resetSlowUpdateTimer() } } -void NightColorManager::slowUpdate(int targetTemp) +void NightLightManager::slowUpdate(int targetTemp) { if (!m_slowUpdateTimer) { return; @@ -445,7 +445,7 @@ void NightColorManager::slowUpdate(int targetTemp) } } -void NightColorManager::preview(uint previewTemp) +void NightLightManager::preview(uint previewTemp) { previewTemp = std::clamp(previewTemp, MIN_TEMPERATURE, DEFAULT_DAY_TEMPERATURE); resetQuickAdjustTimer((int)previewTemp); @@ -454,7 +454,7 @@ void NightColorManager::preview(uint previewTemp) } m_previewTimer = std::make_unique(); m_previewTimer->setSingleShot(true); - connect(m_previewTimer.get(), &QTimer::timeout, this, &NightColorManager::stopPreview); + connect(m_previewTimer.get(), &QTimer::timeout, this, &NightLightManager::stopPreview); m_previewTimer->start(15000); QDBusMessage message = QDBusMessage::createMethodCall( @@ -468,7 +468,7 @@ void NightColorManager::preview(uint previewTemp) QDBusConnection::sessionBus().asyncCall(message); } -void NightColorManager::stopPreview() +void NightLightManager::stopPreview() { if (m_previewTimer && m_previewTimer->isActive()) { updateTransitionTimings(false); @@ -477,9 +477,9 @@ void NightColorManager::stopPreview() } } -void NightColorManager::updateTargetTemperature() +void NightLightManager::updateTargetTemperature() { - const int targetTemperature = mode() != NightColorMode::Constant && daylight() ? m_dayTargetTemp : m_nightTargetTemp; + const int targetTemperature = mode() != NightLightMode::Constant && daylight() ? m_dayTargetTemp : m_nightTargetTemp; if (m_targetTemperature == targetTemperature) { return; @@ -490,16 +490,16 @@ void NightColorManager::updateTargetTemperature() Q_EMIT targetTemperatureChanged(); } -void NightColorManager::updateTransitionTimings(bool force) +void NightLightManager::updateTransitionTimings(bool force) { const auto oldPrev = m_prev; const auto oldNext = m_next; - if (m_mode == NightColorMode::Constant) { + if (m_mode == NightLightMode::Constant) { setDaylight(false); m_next = DateTimes(); m_prev = DateTimes(); - } else if (m_mode == NightColorMode::Timings) { + } else if (m_mode == NightLightMode::Timings) { const QDateTime todayNow = QDateTime::currentDateTime(); const QDateTime nextMorB = QDateTime(todayNow.date().addDays(m_morning < todayNow.time()), m_morning); @@ -520,7 +520,7 @@ void NightColorManager::updateTransitionTimings(bool force) const QDateTime todayNow = QDateTime::currentDateTime(); double lat, lng; - if (m_mode == NightColorMode::Automatic) { + if (m_mode == NightLightMode::Automatic) { lat = m_latAuto; lng = m_lngAuto; } else { @@ -573,7 +573,7 @@ void NightColorManager::updateTransitionTimings(bool force) } } -DateTimes NightColorManager::getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const +DateTimes NightLightManager::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 @@ -588,7 +588,7 @@ DateTimes NightColorManager::getSunTimings(const QDateTime &dateTime, double lat dateTimes.first = dateTimes.second.addMSecs(-FALLBACK_SLOW_UPDATE_TIME); } else { // Just use default values for morning and evening, but the user - // will probably deactivate Night Color anyway if he is living + // will probably deactivate Night Light anyway if he is living // in a region without clear sun rise and set. const QTime referenceTime = morning ? QTime(6, 0) : QTime(18, 0); dateTimes.first = QDateTime(dateTime.date(), referenceTime); @@ -598,7 +598,7 @@ DateTimes NightColorManager::getSunTimings(const QDateTime &dateTime, double lat return dateTimes; } -bool NightColorManager::checkAutomaticSunTimings() const +bool NightLightManager::checkAutomaticSunTimings() const { if (m_prev.first.isValid() && m_prev.second.isValid() && m_next.first.isValid() && m_next.second.isValid()) { const QDateTime todayNow = QDateTime::currentDateTime(); @@ -607,18 +607,18 @@ bool NightColorManager::checkAutomaticSunTimings() const return false; } -bool NightColorManager::daylight() const +bool NightLightManager::daylight() const { return m_daylight; } -int NightColorManager::currentTargetTemp() const +int NightLightManager::currentTargetTemp() const { if (!m_running) { return DEFAULT_DAY_TEMPERATURE; } - if (m_mode == NightColorMode::Constant) { + if (m_mode == NightLightMode::Constant) { return m_nightTargetTemp; } @@ -644,7 +644,7 @@ int NightColorManager::currentTargetTemp() const } } -void NightColorManager::commitGammaRamps(int temperature) +void NightLightManager::commitGammaRamps(int temperature) { const QList devices = kwinApp()->colorManager()->devices(); for (ColorDevice *device : devices) { @@ -654,9 +654,9 @@ void NightColorManager::commitGammaRamps(int temperature) setCurrentTemperature(temperature); } -void NightColorManager::autoLocationUpdate(double latitude, double longitude) +void NightLightManager::autoLocationUpdate(double latitude, double longitude) { - qCDebug(KWIN_NIGHTCOLOR, "Received new location (lat: %f, lng: %f)", latitude, longitude); + qCDebug(KWIN_NIGHTLIGHT, "Received new location (lat: %f, lng: %f)", latitude, longitude); if (!checkLocation(latitude, longitude)) { return; @@ -670,7 +670,7 @@ void NightColorManager::autoLocationUpdate(double latitude, double longitude) m_latAuto = latitude; m_lngAuto = longitude; - NightColorSettings *s = NightColorSettings::self(); + NightLightSettings *s = NightLightSettings::self(); s->setLatitudeAuto(latitude); s->setLongitudeAuto(longitude); s->save(); @@ -678,7 +678,7 @@ void NightColorManager::autoLocationUpdate(double latitude, double longitude) resetAllTimers(); } -void NightColorManager::setEnabled(bool enabled) +void NightLightManager::setEnabled(bool enabled) { if (m_active == enabled) { return; @@ -688,7 +688,7 @@ void NightColorManager::setEnabled(bool enabled) Q_EMIT enabledChanged(); } -void NightColorManager::setRunning(bool running) +void NightLightManager::setRunning(bool running) { if (m_running == running) { return; @@ -697,7 +697,7 @@ void NightColorManager::setRunning(bool running) Q_EMIT runningChanged(); } -void NightColorManager::setCurrentTemperature(int temperature) +void NightLightManager::setCurrentTemperature(int temperature) { if (m_currentTemp == temperature) { return; @@ -706,7 +706,7 @@ void NightColorManager::setCurrentTemperature(int temperature) Q_EMIT currentTemperatureChanged(); } -void NightColorManager::setMode(NightColorMode mode) +void NightLightManager::setMode(NightLightMode mode) { if (m_mode == mode) { return; @@ -715,7 +715,7 @@ void NightColorManager::setMode(NightColorMode mode) Q_EMIT modeChanged(); } -void NightColorManager::setDaylight(bool daylight) +void NightLightManager::setDaylight(bool daylight) { if (m_daylight == daylight) { return; @@ -726,4 +726,4 @@ void NightColorManager::setDaylight(bool daylight) } // namespace KWin -#include "moc_nightcolormanager.cpp" +#include "moc_nightlightmanager.cpp" diff --git a/src/plugins/nightcolor/nightcolormanager.h b/src/plugins/nightlight/nightlightmanager.h similarity index 83% rename from src/plugins/nightcolor/nightcolormanager.h rename to src/plugins/nightlight/nightlightmanager.h index e942fcf729..d3ccb00d67 100644 --- a/src/plugins/nightcolor/nightcolormanager.h +++ b/src/plugins/nightlight/nightlightmanager.h @@ -24,15 +24,15 @@ namespace KWin { class ClockSkewNotifier; -class NightColorDBusInterface; +class NightLightDBusInterface; typedef QPair DateTimes; typedef QPair Times; /** - * This enum type is used to specify operation mode of the night color manager. + * This enum type is used to specify operation mode of the night light manager. */ -enum NightColorMode { +enum NightLightMode { /** * Color temperature is computed based on the current position of the Sun. * @@ -58,7 +58,7 @@ enum NightColorMode { }; /** - * The night color manager is a blue light filter similar to Redshift. + * The night light manager is a blue light filter similar to Redshift. * * There are four modes this manager can operate in: Automatic, Location, Timings, * and Constant. Both Automatic and Location modes derive screen color temperature @@ -73,13 +73,13 @@ enum NightColorMode { * * With the Constant mode, screen color temperature is always constant. */ -class KWIN_EXPORT NightColorManager : public Plugin +class KWIN_EXPORT NightLightManager : public Plugin { Q_OBJECT public: - explicit NightColorManager(); - ~NightColorManager() override; + explicit NightLightManager(); + ~NightLightManager() override; void autoLocationUpdate(double latitude, double longitude); @@ -102,12 +102,12 @@ public: void toggle(); /** - * Returns @c true if the night color manager is blocked; otherwise @c false. + * Returns @c true if the night light manager is blocked; otherwise @c false. */ bool isInhibited() const; /** - * Temporarily blocks the night color manager. + * Temporarily blocks the night light manager. * * After calling this method, the screen color temperature will be reverted * back to 6500C. When you're done, call uninhibit() method. @@ -115,17 +115,17 @@ public: void inhibit(); /** - * Attempts to unblock the night color manager. + * Attempts to unblock the night light manager. */ void uninhibit(); /** - * Returns @c true if Night Color is enabled; otherwise @c false. + * Returns @c true if Night Light is enabled; otherwise @c false. */ bool isEnabled() const; /** - * Returns @c true if Night Color is currently running; otherwise @c false. + * Returns @c true if Night Light is currently running; otherwise @c false. */ bool isRunning() const; @@ -140,18 +140,18 @@ public: int targetTemperature() const; /** - * Returns the mode in which Night Color is operating. + * Returns the mode in which Night Light is operating. */ - NightColorMode mode() const; + NightLightMode mode() const; /** - * Returns whether Night Color is currently on day time. + * Returns whether Night Light is currently on day time. */ bool daylight() const; /** * Returns the datetime that specifies when the previous screen color temperature transition - * had started. Notice that when Night Color operates in the Constant mode, the returned date + * had started. Notice that when Night Light operates in the Constant mode, the returned date * time object is not valid. */ QDateTime previousTransitionDateTime() const; @@ -163,7 +163,7 @@ public: /** * Returns the datetime that specifies when the next screen color temperature transition will - * start. Notice that when Night Color operates in the Constant mode, the returned date time + * start. Notice that when Night Light operates in the Constant mode, the returned date time * object is not valid. */ QDateTime scheduledTransitionDateTime() const; @@ -175,7 +175,7 @@ public: // for auto tests void reconfigure(); - static NightColorManager *self(); + static NightLightManager *self(); /** * Previews a given temperature for a short time (15s). @@ -194,17 +194,17 @@ public Q_SLOTS: Q_SIGNALS: /** - * Emitted whenever the night color manager is blocked or unblocked. + * Emitted whenever the night light manager is blocked or unblocked. */ void inhibitedChanged(); /** - * Emitted whenever the night color manager is enabled or disabled. + * Emitted whenever the night light manager is enabled or disabled. */ void enabledChanged(); /** - * Emitted whenever the night color manager starts or stops running. + * Emitted whenever the night light manager starts or stops running. */ void runningChanged(); @@ -224,7 +224,7 @@ Q_SIGNALS: void modeChanged(); /** - * Emitted whenver night color has switched between day and night time. + * Emitted whenver night light has switched between day and night time. */ void daylightChanged(); @@ -264,22 +264,22 @@ private: void setEnabled(bool enabled); void setRunning(bool running); void setCurrentTemperature(int temperature); - void setMode(NightColorMode mode); + void setMode(NightLightMode mode); void setDaylight(bool daylight); - NightColorDBusInterface *m_iface; + NightLightDBusInterface *m_iface; ClockSkewNotifier *m_skewNotifier; - // Specifies whether Night Color is enabled. + // Specifies whether Night Light is enabled. bool m_active = false; - // Specifies whether Night Color is currently running. + // Specifies whether Night Light is currently running. bool m_running = false; - // Specifies whether Night Color is inhibited globally. + // Specifies whether Night Light is inhibited globally. bool m_isGloballyInhibited = false; - NightColorMode m_mode = NightColorMode::Automatic; + NightLightMode m_mode = NightLightMode::Automatic; // the previous and next sunrise/sunset intervals - in UTC time DateTimes m_prev = DateTimes(); diff --git a/src/plugins/nightcolor/nightcolorsettings.kcfg b/src/plugins/nightlight/nightlightsettings.kcfg similarity index 93% rename from src/plugins/nightcolor/nightcolorsettings.kcfg rename to src/plugins/nightlight/nightlightsettings.kcfg index 0b7b7ba0bf..aa7e5fce1c 100644 --- a/src/plugins/nightcolor/nightcolorsettings.kcfg +++ b/src/plugins/nightlight/nightlightsettings.kcfg @@ -9,13 +9,13 @@ false - + - NightColorMode::Automatic + NightLightMode::Automatic 6500 diff --git a/src/plugins/nightlight/nightlightsettings.kcfgc b/src/plugins/nightlight/nightlightsettings.kcfgc new file mode 100644 index 0000000000..92f06d89fe --- /dev/null +++ b/src/plugins/nightlight/nightlightsettings.kcfgc @@ -0,0 +1,8 @@ +File=nightlightsettings.kcfg +NameSpace=KWin +ClassName=NightLightSettings +Singleton=true +Mutators=true +# nightlightmanager.h is needed for NightLightMode +IncludeFiles=nightlightmanager.h +UseEnumTypes=true diff --git a/src/plugins/nightcolor/org.kde.KWin.NightLight.xml b/src/plugins/nightlight/org.kde.KWin.NightLight.xml similarity index 100% rename from src/plugins/nightcolor/org.kde.KWin.NightLight.xml rename to src/plugins/nightlight/org.kde.KWin.NightLight.xml diff --git a/src/plugins/nightcolor/suncalc.cpp b/src/plugins/nightlight/suncalc.cpp similarity index 100% rename from src/plugins/nightcolor/suncalc.cpp rename to src/plugins/nightlight/suncalc.cpp diff --git a/src/plugins/nightcolor/suncalc.h b/src/plugins/nightlight/suncalc.h similarity index 100% rename from src/plugins/nightcolor/suncalc.h rename to src/plugins/nightlight/suncalc.h