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.
This commit is contained in:
parent
2bac328cc8
commit
bdfb946267
28 changed files with 251 additions and 232 deletions
|
@ -452,11 +452,6 @@ set(kwin_SRCS
|
||||||
appmenu.cpp
|
appmenu.cpp
|
||||||
atoms.cpp
|
atoms.cpp
|
||||||
client_machine.cpp
|
client_machine.cpp
|
||||||
colorcorrection/clockskewnotifier.cpp
|
|
||||||
colorcorrection/clockskewnotifierengine.cpp
|
|
||||||
colorcorrection/colorcorrectdbusinterface.cpp
|
|
||||||
colorcorrection/manager.cpp
|
|
||||||
colorcorrection/suncalc.cpp
|
|
||||||
composite.cpp
|
composite.cpp
|
||||||
cursor.cpp
|
cursor.cpp
|
||||||
dbusinterface.cpp
|
dbusinterface.cpp
|
||||||
|
@ -567,25 +562,6 @@ set(kwin_SRCS
|
||||||
xwl/xwayland_interface.cpp
|
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)
|
if (KWIN_BUILD_TABBOX)
|
||||||
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
|
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
|
||||||
set(kwin_SRCS ${kwin_SRCS}
|
set(kwin_SRCS ${kwin_SRCS}
|
||||||
|
@ -626,13 +602,11 @@ if(KWIN_TTY_PREFIX)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
kconfig_add_kcfg_files(kwin_SRCS settings.kcfgc)
|
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 rulesettings.kcfgc)
|
||||||
kconfig_add_kcfg_files(kwin_SRCS rulebooksettingsbase.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.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.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 ${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.VirtualDesktopManager.xml dbusinterface.h KWin::VirtualDesktopManagerDBusInterface)
|
||||||
qt5_add_dbus_adaptor(kwin_SRCS org.kde.KWin.Session.xml sm.h KWin::SessionManager)
|
qt5_add_dbus_adaptor(kwin_SRCS org.kde.KWin.Session.xml sm.h KWin::SessionManager)
|
||||||
|
@ -816,13 +790,11 @@ endif()
|
||||||
########### install files ###############
|
########### install files ###############
|
||||||
|
|
||||||
install(FILES kwin.kcfg DESTINATION ${KCFG_INSTALL_DIR} RENAME ${KWIN_NAME}.kcfg)
|
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 kwin.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR} RENAME ${KWIN_NAME}.notifyrc)
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
org.kde.KWin.VirtualDesktopManager.xml
|
org.kde.KWin.VirtualDesktopManager.xml
|
||||||
org.kde.KWin.xml
|
org.kde.KWin.xml
|
||||||
org.kde.kwin.ColorCorrect.xml
|
|
||||||
org.kde.kwin.Compositing.xml
|
org.kde.kwin.Compositing.xml
|
||||||
org.kde.kwin.Effects.xml
|
org.kde.kwin.Effects.xml
|
||||||
org.kde.KWin.Plugins.xml
|
org.kde.KWin.Plugins.xml
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
$EXTRACTRC *.kcfg *.ui >> rc.cpp
|
$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
|
||||||
|
|
|
@ -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 testVirtualDesktop SRCS virtual_desktop_test.cpp)
|
||||||
integrationTest(WAYLAND_ONLY NAME testXdgShellClientRules SRCS xdgshellclient_rules_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 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 testDontCrashCursorPhysicalSizeEmpty SRCS dont_crash_cursor_physical_size_empty.cpp)
|
||||||
integrationTest(WAYLAND_ONLY NAME testDontCrashReinitializeCompositor SRCS dont_crash_reinitialize_compositor.cpp)
|
integrationTest(WAYLAND_ONLY NAME testDontCrashReinitializeCompositor SRCS dont_crash_reinitialize_compositor.cpp)
|
||||||
integrationTest(WAYLAND_ONLY NAME testNoGlobalShortcuts SRCS no_global_shortcuts_test.cpp)
|
integrationTest(WAYLAND_ONLY NAME testNoGlobalShortcuts SRCS no_global_shortcuts_test.cpp)
|
||||||
|
|
|
@ -7,19 +7,19 @@
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
#include "kwin_wayland_test.h"
|
#include "kwin_wayland_test.h"
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "wayland_server.h"
|
#include "wayland_server.h"
|
||||||
#include "colorcorrection/manager.h"
|
|
||||||
#include "colorcorrection/constants.h"
|
#include "plugins/nightcolor/nightcolormanager.h"
|
||||||
|
#include "plugins/nightcolor/constants.h"
|
||||||
|
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
|
|
||||||
using namespace KWin;
|
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
|
Q_OBJECT
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
@ -34,7 +34,7 @@ private Q_SLOTS:
|
||||||
void testAutoLocationUpdate();
|
void testAutoLocationUpdate();
|
||||||
};
|
};
|
||||||
|
|
||||||
void ColorCorrectNightColorTest::initTestCase()
|
void NightColorTest::initTestCase()
|
||||||
{
|
{
|
||||||
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
||||||
QVERIFY(applicationStartedSpy.isValid());
|
QVERIFY(applicationStartedSpy.isValid());
|
||||||
|
@ -47,19 +47,22 @@ void ColorCorrectNightColorTest::initTestCase()
|
||||||
kwinApp()->start();
|
kwinApp()->start();
|
||||||
QVERIFY(applicationStartedSpy.wait());
|
QVERIFY(applicationStartedSpy.wait());
|
||||||
waylandServer()->initWorkspace();
|
waylandServer()->initWorkspace();
|
||||||
|
|
||||||
|
NightColorManager *manager = NightColorManager::self();
|
||||||
|
QVERIFY(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorCorrectNightColorTest::init()
|
void NightColorTest::init()
|
||||||
{
|
{
|
||||||
QVERIFY(Test::setupWaylandConnection());
|
QVERIFY(Test::setupWaylandConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorCorrectNightColorTest::cleanup()
|
void NightColorTest::cleanup()
|
||||||
{
|
{
|
||||||
Test::destroyWaylandConnection();
|
Test::destroyWaylandConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorCorrectNightColorTest::testConfigRead_data()
|
void NightColorTest::testConfigRead_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("active");
|
QTest::addColumn<QString>("active");
|
||||||
QTest::addColumn<int>("mode");
|
QTest::addColumn<int>("mode");
|
||||||
|
@ -79,7 +82,7 @@ void ColorCorrectNightColorTest::testConfigRead_data()
|
||||||
QTest::newRow("wrongData2") << "fa" << 4 << 7000 << 91. << -181. << "060" << "800" << -2 << false;
|
QTest::newRow("wrongData2") << "fa" << 4 << 7000 << 91. << -181. << "060" << "800" << -2 << false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorCorrectNightColorTest::testConfigRead()
|
void NightColorTest::testConfigRead()
|
||||||
{
|
{
|
||||||
QFETCH(QString, active);
|
QFETCH(QString, active);
|
||||||
QFETCH(int, mode);
|
QFETCH(int, mode);
|
||||||
|
@ -93,7 +96,7 @@ void ColorCorrectNightColorTest::testConfigRead()
|
||||||
|
|
||||||
const bool activeDefault = true;
|
const bool activeDefault = true;
|
||||||
const int modeDefault = 0;
|
const int modeDefault = 0;
|
||||||
const int nightTemperatureUpperEnd = ColorCorrect::NEUTRAL_TEMPERATURE;
|
const int nightTemperatureUpperEnd = NEUTRAL_TEMPERATURE;
|
||||||
const double latitudeFixedDefault = 0;
|
const double latitudeFixedDefault = 0;
|
||||||
const double longitudeFixedDefault = 0;
|
const double longitudeFixedDefault = 0;
|
||||||
const QTime morningBeginFixedDefault = QTime(6,0,0);
|
const QTime morningBeginFixedDefault = QTime(6,0,0);
|
||||||
|
@ -111,7 +114,7 @@ void ColorCorrectNightColorTest::testConfigRead()
|
||||||
cfgGroup.writeEntry("EveningBeginFixed", eveningBeginFixedDefault.toString("hhmm"));
|
cfgGroup.writeEntry("EveningBeginFixed", eveningBeginFixedDefault.toString("hhmm"));
|
||||||
cfgGroup.writeEntry("TransitionTime", transitionTimeDefault);
|
cfgGroup.writeEntry("TransitionTime", transitionTimeDefault);
|
||||||
|
|
||||||
ColorCorrect::Manager *manager = kwinApp()->platform()->colorCorrectManager();
|
NightColorManager *manager = NightColorManager::self();
|
||||||
manager->reparseConfigAndReset();
|
manager->reparseConfigAndReset();
|
||||||
auto info = manager->info();
|
auto info = manager->info();
|
||||||
QVERIFY(!info.isEmpty());
|
QVERIFY(!info.isEmpty());
|
||||||
|
@ -159,7 +162,7 @@ void ColorCorrectNightColorTest::testConfigRead()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorCorrectNightColorTest::testChangeConfiguration_data()
|
void NightColorTest::testChangeConfiguration_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<bool>("activeReadIn");
|
QTest::addColumn<bool>("activeReadIn");
|
||||||
QTest::addColumn<int>("modeReadIn");
|
QTest::addColumn<int>("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;
|
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(bool, activeReadIn);
|
||||||
QFETCH(int, modeReadIn);
|
QFETCH(int, modeReadIn);
|
||||||
|
@ -200,7 +203,7 @@ void ColorCorrectNightColorTest::testChangeConfiguration()
|
||||||
|
|
||||||
const bool activeDefault = true;
|
const bool activeDefault = true;
|
||||||
const int modeDefault = 0;
|
const int modeDefault = 0;
|
||||||
const int nightTemperatureDefault = ColorCorrect::DEFAULT_NIGHT_TEMPERATURE;
|
const int nightTemperatureDefault = DEFAULT_NIGHT_TEMPERATURE;
|
||||||
const double latitudeFixedDefault = 0;
|
const double latitudeFixedDefault = 0;
|
||||||
const double longitudeFixedDefault = 0;
|
const double longitudeFixedDefault = 0;
|
||||||
const QTime morningBeginFixedDefault = QTime(6,0,0);
|
const QTime morningBeginFixedDefault = QTime(6,0,0);
|
||||||
|
@ -258,7 +261,7 @@ void ColorCorrectNightColorTest::testChangeConfiguration()
|
||||||
QCOMPARE(info.value("TransitionTime").toInt(), transitionTimeExpect);
|
QCOMPARE(info.value("TransitionTime").toInt(), transitionTimeExpect);
|
||||||
};
|
};
|
||||||
|
|
||||||
ColorCorrect::Manager *manager = kwinApp()->platform()->colorCorrectManager();
|
NightColorManager *manager = NightColorManager::self();
|
||||||
|
|
||||||
// test with default values
|
// test with default values
|
||||||
setData();
|
setData();
|
||||||
|
@ -292,9 +295,9 @@ void ColorCorrectNightColorTest::testChangeConfiguration()
|
||||||
compareValues(manager->info());
|
compareValues(manager->info());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorCorrectNightColorTest::testAutoLocationUpdate()
|
void NightColorTest::testAutoLocationUpdate()
|
||||||
{
|
{
|
||||||
ColorCorrect::Manager *manager = kwinApp()->platform()->colorCorrectManager();
|
NightColorManager *manager = NightColorManager::self();
|
||||||
auto info = manager->info();
|
auto info = manager->info();
|
||||||
QCOMPARE(info.value("LatitudeAuto").toDouble(), 0.);
|
QCOMPARE(info.value("LatitudeAuto").toDouble(), 0.);
|
||||||
QCOMPARE(info.value("LongitudeAuto").toDouble(), 0.);
|
QCOMPARE(info.value("LongitudeAuto").toDouble(), 0.);
|
||||||
|
@ -324,5 +327,5 @@ void ColorCorrectNightColorTest::testAutoLocationUpdate()
|
||||||
QCOMPARE(info.value("LatitudeAuto").toDouble(), 50.);
|
QCOMPARE(info.value("LatitudeAuto").toDouble(), 50.);
|
||||||
}
|
}
|
||||||
|
|
||||||
WAYLANDTEST_MAIN(ColorCorrectNightColorTest)
|
WAYLANDTEST_MAIN(NightColorTest)
|
||||||
#include "colorcorrect_nightcolor_test.moc"
|
#include "nightcolor_test.moc"
|
|
@ -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
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "screens.h"
|
#include "screens.h"
|
||||||
#include "screenedge.h"
|
#include "screenedge.h"
|
||||||
#include "wayland_server.h"
|
#include "wayland_server.h"
|
||||||
#include "colorcorrection/manager.h"
|
|
||||||
|
|
||||||
#include <KWaylandServer/outputconfiguration_interface.h>
|
#include <KWaylandServer/outputconfiguration_interface.h>
|
||||||
#include <KWaylandServer/outputchangeset.h>
|
#include <KWaylandServer/outputchangeset.h>
|
||||||
|
@ -38,7 +37,6 @@ Platform::Platform(QObject *parent)
|
||||||
, m_eglDisplay(EGL_NO_DISPLAY)
|
, m_eglDisplay(EGL_NO_DISPLAY)
|
||||||
{
|
{
|
||||||
setSoftwareCursorForced(false);
|
setSoftwareCursorForced(false);
|
||||||
m_colorCorrect = new ColorCorrect::Manager(this);
|
|
||||||
connect(Cursors::self(), &Cursors::currentCursorRendered, this, &Platform::cursorRendered);
|
connect(Cursors::self(), &Cursors::currentCursorRendered, this, &Platform::cursorRendered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,6 @@ class OutputConfigurationInterface;
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
namespace ColorCorrect {
|
|
||||||
class Manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AbstractOutput;
|
class AbstractOutput;
|
||||||
class Edge;
|
class Edge;
|
||||||
|
@ -418,10 +415,6 @@ public:
|
||||||
return m_supportsGammaControl;
|
return m_supportsGammaControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorCorrect::Manager *colorCorrectManager() {
|
|
||||||
return m_colorCorrect;
|
|
||||||
}
|
|
||||||
|
|
||||||
// outputs with connections (org_kde_kwin_outputdevice)
|
// outputs with connections (org_kde_kwin_outputdevice)
|
||||||
virtual Outputs outputs() const {
|
virtual Outputs outputs() const {
|
||||||
return Outputs();
|
return Outputs();
|
||||||
|
@ -571,7 +564,6 @@ private:
|
||||||
EGLContext m_context = EGL_NO_CONTEXT;
|
EGLContext m_context = EGL_NO_CONTEXT;
|
||||||
EGLContext m_globalShareContext = EGL_NO_CONTEXT;
|
EGLContext m_globalShareContext = EGL_NO_CONTEXT;
|
||||||
int m_hideCursorCounter = 0;
|
int m_hideCursorCounter = 0;
|
||||||
ColorCorrect::Manager *m_colorCorrect = nullptr;
|
|
||||||
bool m_supportsGammaControl = false;
|
bool m_supportsGammaControl = false;
|
||||||
bool m_supportsOutputChanges = false;
|
bool m_supportsOutputChanges = false;
|
||||||
CompositingType m_selectedCompositor = NoCompositing;
|
CompositingType m_selectedCompositor = NoCompositing;
|
||||||
|
|
|
@ -5,6 +5,7 @@ add_subdirectory(platforms)
|
||||||
add_subdirectory(scenes)
|
add_subdirectory(scenes)
|
||||||
add_subdirectory(windowsystem)
|
add_subdirectory(windowsystem)
|
||||||
add_subdirectory(kpackage)
|
add_subdirectory(kpackage)
|
||||||
|
add_subdirectory(nightcolor)
|
||||||
|
|
||||||
if (KWIN_BUILD_DECORATIONS)
|
if (KWIN_BUILD_DECORATIONS)
|
||||||
add_subdirectory(kdecorations)
|
add_subdirectory(kdecorations)
|
||||||
|
|
31
plugins/nightcolor/CMakeLists.txt
Normal file
31
plugins/nightcolor/CMakeLists.txt
Normal file
|
@ -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/)
|
|
@ -11,8 +11,6 @@
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
namespace ColorCorrect
|
|
||||||
{
|
|
||||||
|
|
||||||
static const int MSC_DAY = 86400000;
|
static const int MSC_DAY = 86400000;
|
||||||
static const int MIN_TEMPERATURE = 1000;
|
static const int MIN_TEMPERATURE = 1000;
|
||||||
|
@ -272,7 +270,6 @@ static const float blackbodyColor[] = {
|
||||||
0.62740336, 0.75282962, 1.00000000
|
0.62740336, 0.75282962, 1.00000000
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // KWIN_NIGHTCOLOR_CONSTANTS_H
|
#endif // KWIN_NIGHTCOLOR_CONSTANTS_H
|
37
plugins/nightcolor/main.cpp
Normal file
37
plugins/nightcolor/main.cpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nightcolormanager.h"
|
||||||
|
|
||||||
|
#include <KPluginFactory>
|
||||||
|
|
||||||
|
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"
|
6
plugins/nightcolor/metadata.json
Normal file
6
plugins/nightcolor/metadata.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"KPlugin": {
|
||||||
|
"EnabledByDefault": true,
|
||||||
|
"Id": "kwin5_plugin_nightcolor"
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,17 +7,15 @@
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "colorcorrectdbusinterface.h"
|
#include "nightcolordbusinterface.h"
|
||||||
|
#include "nightcolormanager.h"
|
||||||
#include "colorcorrectadaptor.h"
|
#include "colorcorrectadaptor.h"
|
||||||
|
|
||||||
#include "manager.h"
|
|
||||||
|
|
||||||
#include <QDBusMessage>
|
#include <QDBusMessage>
|
||||||
|
|
||||||
namespace KWin {
|
namespace KWin {
|
||||||
namespace ColorCorrect {
|
|
||||||
|
|
||||||
ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_manager(parent)
|
, m_manager(parent)
|
||||||
, m_inhibitorWatcher(new QDBusServiceWatcher(this))
|
, m_inhibitorWatcher(new QDBusServiceWatcher(this))
|
||||||
|
@ -25,9 +23,9 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
m_inhibitorWatcher->setConnection(QDBusConnection::sessionBus());
|
m_inhibitorWatcher->setConnection(QDBusConnection::sessionBus());
|
||||||
m_inhibitorWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
|
m_inhibitorWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
|
||||||
connect(m_inhibitorWatcher, &QDBusServiceWatcher::serviceUnregistered,
|
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;
|
QVariantMap changedProperties;
|
||||||
changedProperties.insert(QStringLiteral("inhibited"), m_manager->isInhibited());
|
changedProperties.insert(QStringLiteral("inhibited"), m_manager->isInhibited());
|
||||||
|
|
||||||
|
@ -46,7 +44,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_manager, &Manager::enabledChanged, this, [this] {
|
connect(m_manager, &NightColorManager::enabledChanged, this, [this] {
|
||||||
QVariantMap changedProperties;
|
QVariantMap changedProperties;
|
||||||
changedProperties.insert(QStringLiteral("enabled"), m_manager->isEnabled());
|
changedProperties.insert(QStringLiteral("enabled"), m_manager->isEnabled());
|
||||||
|
|
||||||
|
@ -65,7 +63,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_manager, &Manager::runningChanged, this, [this] {
|
connect(m_manager, &NightColorManager::runningChanged, this, [this] {
|
||||||
QVariantMap changedProperties;
|
QVariantMap changedProperties;
|
||||||
changedProperties.insert(QStringLiteral("running"), m_manager->isRunning());
|
changedProperties.insert(QStringLiteral("running"), m_manager->isRunning());
|
||||||
|
|
||||||
|
@ -84,7 +82,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_manager, &Manager::currentTemperatureChanged, this, [this] {
|
connect(m_manager, &NightColorManager::currentTemperatureChanged, this, [this] {
|
||||||
QVariantMap changedProperties;
|
QVariantMap changedProperties;
|
||||||
changedProperties.insert(QStringLiteral("currentTemperature"), m_manager->currentTemperature());
|
changedProperties.insert(QStringLiteral("currentTemperature"), m_manager->currentTemperature());
|
||||||
|
|
||||||
|
@ -103,7 +101,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_manager, &Manager::targetTemperatureChanged, this, [this] {
|
connect(m_manager, &NightColorManager::targetTemperatureChanged, this, [this] {
|
||||||
QVariantMap changedProperties;
|
QVariantMap changedProperties;
|
||||||
changedProperties.insert(QStringLiteral("targetTemperature"), m_manager->targetTemperature());
|
changedProperties.insert(QStringLiteral("targetTemperature"), m_manager->targetTemperature());
|
||||||
|
|
||||||
|
@ -122,7 +120,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_manager, &Manager::modeChanged, this, [this] {
|
connect(m_manager, &NightColorManager::modeChanged, this, [this] {
|
||||||
QVariantMap changedProperties;
|
QVariantMap changedProperties;
|
||||||
changedProperties.insert(QStringLiteral("mode"), uint(m_manager->mode()));
|
changedProperties.insert(QStringLiteral("mode"), uint(m_manager->mode()));
|
||||||
|
|
||||||
|
@ -141,7 +139,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_manager, &Manager::previousTransitionTimingsChanged, this, [this] {
|
connect(m_manager, &NightColorManager::previousTransitionTimingsChanged, this, [this] {
|
||||||
QVariantMap changedProperties;
|
QVariantMap changedProperties;
|
||||||
changedProperties.insert(QStringLiteral("previousTransitionDateTime"), previousTransitionDateTime());
|
changedProperties.insert(QStringLiteral("previousTransitionDateTime"), previousTransitionDateTime());
|
||||||
changedProperties.insert(QStringLiteral("previousTransitionDuration"), previousTransitionDuration());
|
changedProperties.insert(QStringLiteral("previousTransitionDuration"), previousTransitionDuration());
|
||||||
|
@ -161,7 +159,7 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_manager, &Manager::scheduledTransitionTimingsChanged, this, [this] {
|
connect(m_manager, &NightColorManager::scheduledTransitionTimingsChanged, this, [this] {
|
||||||
QVariantMap changedProperties;
|
QVariantMap changedProperties;
|
||||||
changedProperties.insert(QStringLiteral("scheduledTransitionDateTime"), scheduledTransitionDateTime());
|
changedProperties.insert(QStringLiteral("scheduledTransitionDateTime"), scheduledTransitionDateTime());
|
||||||
changedProperties.insert(QStringLiteral("scheduledTransitionDuration"), scheduledTransitionDuration());
|
changedProperties.insert(QStringLiteral("scheduledTransitionDuration"), scheduledTransitionDuration());
|
||||||
|
@ -181,47 +179,47 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_manager, &Manager::configChange, this, &ColorCorrectDBusInterface::nightColorConfigChanged);
|
connect(m_manager, &NightColorManager::configChange, this, &NightColorDBusInterface::nightColorConfigChanged);
|
||||||
new ColorCorrectAdaptor(this);
|
new ColorCorrectAdaptor(this);
|
||||||
QDBusConnection::sessionBus().registerObject(QStringLiteral("/ColorCorrect"), this);
|
QDBusConnection::sessionBus().registerObject(QStringLiteral("/ColorCorrect"), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColorCorrectDBusInterface::isInhibited() const
|
bool NightColorDBusInterface::isInhibited() const
|
||||||
{
|
{
|
||||||
return m_manager->isInhibited();
|
return m_manager->isInhibited();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColorCorrectDBusInterface::isEnabled() const
|
bool NightColorDBusInterface::isEnabled() const
|
||||||
{
|
{
|
||||||
return m_manager->isEnabled();
|
return m_manager->isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColorCorrectDBusInterface::isRunning() const
|
bool NightColorDBusInterface::isRunning() const
|
||||||
{
|
{
|
||||||
return m_manager->isRunning();
|
return m_manager->isRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColorCorrectDBusInterface::isAvailable() const
|
bool NightColorDBusInterface::isAvailable() const
|
||||||
{
|
{
|
||||||
return m_manager->isAvailable();
|
return m_manager->isAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ColorCorrectDBusInterface::currentTemperature() const
|
int NightColorDBusInterface::currentTemperature() const
|
||||||
{
|
{
|
||||||
return m_manager->currentTemperature();
|
return m_manager->currentTemperature();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ColorCorrectDBusInterface::targetTemperature() const
|
int NightColorDBusInterface::targetTemperature() const
|
||||||
{
|
{
|
||||||
return m_manager->targetTemperature();
|
return m_manager->targetTemperature();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ColorCorrectDBusInterface::mode() const
|
int NightColorDBusInterface::mode() const
|
||||||
{
|
{
|
||||||
return m_manager->mode();
|
return m_manager->mode();
|
||||||
}
|
}
|
||||||
|
|
||||||
quint64 ColorCorrectDBusInterface::previousTransitionDateTime() const
|
quint64 NightColorDBusInterface::previousTransitionDateTime() const
|
||||||
{
|
{
|
||||||
const QDateTime dateTime = m_manager->previousTransitionDateTime();
|
const QDateTime dateTime = m_manager->previousTransitionDateTime();
|
||||||
if (dateTime.isValid()) {
|
if (dateTime.isValid()) {
|
||||||
|
@ -230,12 +228,12 @@ quint64 ColorCorrectDBusInterface::previousTransitionDateTime() const
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 ColorCorrectDBusInterface::previousTransitionDuration() const
|
quint32 NightColorDBusInterface::previousTransitionDuration() const
|
||||||
{
|
{
|
||||||
return quint32(m_manager->previousTransitionDuration());
|
return quint32(m_manager->previousTransitionDuration());
|
||||||
}
|
}
|
||||||
|
|
||||||
quint64 ColorCorrectDBusInterface::scheduledTransitionDateTime() const
|
quint64 NightColorDBusInterface::scheduledTransitionDateTime() const
|
||||||
{
|
{
|
||||||
const QDateTime dateTime = m_manager->scheduledTransitionDateTime();
|
const QDateTime dateTime = m_manager->scheduledTransitionDateTime();
|
||||||
if (dateTime.isValid()) {
|
if (dateTime.isValid()) {
|
||||||
|
@ -244,27 +242,27 @@ quint64 ColorCorrectDBusInterface::scheduledTransitionDateTime() const
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 ColorCorrectDBusInterface::scheduledTransitionDuration() const
|
quint32 NightColorDBusInterface::scheduledTransitionDuration() const
|
||||||
{
|
{
|
||||||
return quint32(m_manager->scheduledTransitionDuration());
|
return quint32(m_manager->scheduledTransitionDuration());
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, QVariant> ColorCorrectDBusInterface::nightColorInfo()
|
QHash<QString, QVariant> NightColorDBusInterface::nightColorInfo()
|
||||||
{
|
{
|
||||||
return m_manager->info();
|
return m_manager->info();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColorCorrectDBusInterface::setNightColorConfig(QHash<QString, QVariant> data)
|
bool NightColorDBusInterface::setNightColorConfig(QHash<QString, QVariant> data)
|
||||||
{
|
{
|
||||||
return m_manager->changeConfiguration(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);
|
m_manager->autoLocationUpdate(latitude, longitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint ColorCorrectDBusInterface::inhibit()
|
uint NightColorDBusInterface::inhibit()
|
||||||
{
|
{
|
||||||
const QString serviceName = QDBusContext::message().service();
|
const QString serviceName = QDBusContext::message().service();
|
||||||
|
|
||||||
|
@ -279,14 +277,14 @@ uint ColorCorrectDBusInterface::inhibit()
|
||||||
return m_lastInhibitionCookie;
|
return m_lastInhibitionCookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorCorrectDBusInterface::uninhibit(uint cookie)
|
void NightColorDBusInterface::uninhibit(uint cookie)
|
||||||
{
|
{
|
||||||
const QString serviceName = QDBusContext::message().service();
|
const QString serviceName = QDBusContext::message().service();
|
||||||
|
|
||||||
uninhibit(serviceName, cookie);
|
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);
|
const int removedCount = m_inhibitors.remove(serviceName, cookie);
|
||||||
if (!removedCount) {
|
if (!removedCount) {
|
||||||
|
@ -300,7 +298,7 @@ void ColorCorrectDBusInterface::uninhibit(const QString &serviceName, uint cooki
|
||||||
m_manager->uninhibit();
|
m_manager->uninhibit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorCorrectDBusInterface::removeInhibitorService(const QString &serviceName)
|
void NightColorDBusInterface::removeInhibitorService(const QString &serviceName)
|
||||||
{
|
{
|
||||||
const auto cookies = m_inhibitors.values(serviceName);
|
const auto cookies = m_inhibitors.values(serviceName);
|
||||||
for (const uint &cookie : cookies) {
|
for (const uint &cookie : cookies) {
|
||||||
|
@ -309,4 +307,3 @@ void ColorCorrectDBusInterface::removeInhibitorService(const QString &serviceNam
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -7,8 +7,7 @@
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef KWIN_NIGHTCOLOR_DBUS_INTERFACE_H
|
#pragma once
|
||||||
#define KWIN_NIGHTCOLOR_DBUS_INTERFACE_H
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtDBus>
|
#include <QtDBus>
|
||||||
|
@ -16,12 +15,9 @@
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace ColorCorrect
|
class NightColorManager;
|
||||||
{
|
|
||||||
|
|
||||||
class Manager;
|
class NightColorDBusInterface : public QObject, public QDBusContext
|
||||||
|
|
||||||
class ColorCorrectDBusInterface : public QObject, public QDBusContext
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.ColorCorrect")
|
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)
|
Q_PROPERTY(quint32 scheduledTransitionDuration READ scheduledTransitionDuration)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ColorCorrectDBusInterface(Manager *parent);
|
explicit NightColorDBusInterface(NightColorManager *parent);
|
||||||
~ColorCorrectDBusInterface() override = default;
|
~NightColorDBusInterface() override = default;
|
||||||
|
|
||||||
bool isInhibited() const;
|
bool isInhibited() const;
|
||||||
bool isEnabled() const;
|
bool isEnabled() const;
|
||||||
|
@ -143,14 +139,10 @@ private Q_SLOTS:
|
||||||
private:
|
private:
|
||||||
void uninhibit(const QString &serviceName, uint cookie);
|
void uninhibit(const QString &serviceName, uint cookie);
|
||||||
|
|
||||||
Manager *m_manager;
|
NightColorManager *m_manager;
|
||||||
QDBusServiceWatcher *m_inhibitorWatcher;
|
QDBusServiceWatcher *m_inhibitorWatcher;
|
||||||
QMultiHash<QString, uint> m_inhibitors;
|
QMultiHash<QString, uint> m_inhibitors;
|
||||||
uint m_lastInhibitionCookie = 0;
|
uint m_lastInhibitionCookie = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // KWIN_NIGHTCOLOR_DBUS_INTERFACE_H
|
|
|
@ -6,11 +6,12 @@
|
||||||
|
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
#include "manager.h"
|
#include "nightcolormanager.h"
|
||||||
#include "clockskewnotifier.h"
|
#include "clockskewnotifier.h"
|
||||||
#include "colorcorrectdbusinterface.h"
|
#include "nightcolordbusinterface.h"
|
||||||
|
#include "nightcolorlogging.h"
|
||||||
|
#include "nightcolorsettings.h"
|
||||||
#include "suncalc.h"
|
#include "suncalc.h"
|
||||||
#include <colorcorrect_logging.h>
|
|
||||||
|
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
|
@ -19,8 +20,6 @@
|
||||||
#include <workspace.h>
|
#include <workspace.h>
|
||||||
#include <logind.h>
|
#include <logind.h>
|
||||||
|
|
||||||
#include <colorcorrect_settings.h>
|
|
||||||
|
|
||||||
#include <KGlobalAccel>
|
#include <KGlobalAccel>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
|
@ -29,26 +28,31 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
namespace KWin {
|
namespace KWin {
|
||||||
namespace ColorCorrect {
|
|
||||||
|
|
||||||
static const int QUICK_ADJUST_DURATION = 2000;
|
static const int QUICK_ADJUST_DURATION = 2000;
|
||||||
static const int TEMPERATURE_STEP = 50;
|
static const int TEMPERATURE_STEP = 50;
|
||||||
|
static NightColorManager *s_instance = nullptr;
|
||||||
|
|
||||||
static bool checkLocation(double lat, double lng)
|
static bool checkLocation(double lat, double lng)
|
||||||
{
|
{
|
||||||
return -90 <= lat && lat <= 90 && -180 <= lng && lng <= 180;
|
return -90 <= lat && lat <= 90 && -180 <= lng && lng <= 180;
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager::Manager(QObject *parent)
|
NightColorManager *NightColorManager::self()
|
||||||
: QObject(parent)
|
|
||||||
{
|
{
|
||||||
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);
|
m_skewNotifier = new ClockSkewNotifier(this);
|
||||||
|
|
||||||
connect(kwinApp(), &Application::workspaceCreated, this, &Manager::init);
|
|
||||||
|
|
||||||
// Display a message when Night Color is (un)inhibited.
|
// 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?
|
// TODO: Maybe use different icons?
|
||||||
const QString iconName = isInhibited()
|
const QString iconName = isInhibited()
|
||||||
? QStringLiteral("preferences-desktop-display-nightcolor-off")
|
? QStringLiteral("preferences-desktop-display-nightcolor-off")
|
||||||
|
@ -67,11 +71,22 @@ Manager::Manager(QObject *parent)
|
||||||
|
|
||||||
QDBusConnection::sessionBus().asyncCall(message);
|
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
|
// we may always read in the current config
|
||||||
readConfig();
|
readConfig();
|
||||||
|
|
||||||
|
@ -79,7 +94,22 @@ void Manager::init()
|
||||||
return;
|
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<QKeySequence>());
|
||||||
|
input()->registerShortcut(QKeySequence(), toggleAction, this, &NightColorManager::toggle);
|
||||||
|
|
||||||
|
connect(Screens::self(), &Screens::countChanged, this, &NightColorManager::hardReset);
|
||||||
|
|
||||||
connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged, this,
|
connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged, this,
|
||||||
[this](bool active) {
|
[this](bool active) {
|
||||||
|
@ -105,7 +135,7 @@ void Manager::init()
|
||||||
if (reply.isValid()) {
|
if (reply.isValid()) {
|
||||||
comingFromSuspend = reply.value().toBool();
|
comingFromSuspend = reply.value().toBool();
|
||||||
} else {
|
} 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.
|
// Always do a hard reset in case we have no further information.
|
||||||
comingFromSuspend = true;
|
comingFromSuspend = true;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +150,7 @@ void Manager::init()
|
||||||
hardReset();
|
hardReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::hardReset()
|
void NightColorManager::hardReset()
|
||||||
{
|
{
|
||||||
cancelAllTimers();
|
cancelAllTimers();
|
||||||
|
|
||||||
|
@ -134,25 +164,25 @@ void Manager::hardReset()
|
||||||
resetAllTimers();
|
resetAllTimers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::reparseConfigAndReset()
|
void NightColorManager::reparseConfigAndReset()
|
||||||
{
|
{
|
||||||
cancelAllTimers();
|
cancelAllTimers();
|
||||||
readConfig();
|
readConfig();
|
||||||
hardReset();
|
hardReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::toggle()
|
void NightColorManager::toggle()
|
||||||
{
|
{
|
||||||
m_isGloballyInhibited = !m_isGloballyInhibited;
|
m_isGloballyInhibited = !m_isGloballyInhibited;
|
||||||
m_isGloballyInhibited ? inhibit() : uninhibit();
|
m_isGloballyInhibited ? inhibit() : uninhibit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::isInhibited() const
|
bool NightColorManager::isInhibited() const
|
||||||
{
|
{
|
||||||
return m_inhibitReferenceCount;
|
return m_inhibitReferenceCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::inhibit()
|
void NightColorManager::inhibit()
|
||||||
{
|
{
|
||||||
m_inhibitReferenceCount++;
|
m_inhibitReferenceCount++;
|
||||||
|
|
||||||
|
@ -162,7 +192,7 @@ void Manager::inhibit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::uninhibit()
|
void NightColorManager::uninhibit()
|
||||||
{
|
{
|
||||||
m_inhibitReferenceCount--;
|
m_inhibitReferenceCount--;
|
||||||
|
|
||||||
|
@ -172,77 +202,59 @@ void Manager::uninhibit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::isEnabled() const
|
bool NightColorManager::isEnabled() const
|
||||||
{
|
{
|
||||||
return m_active;
|
return m_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::isRunning() const
|
bool NightColorManager::isRunning() const
|
||||||
{
|
{
|
||||||
return m_running;
|
return m_running;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::isAvailable() const
|
bool NightColorManager::isAvailable() const
|
||||||
{
|
{
|
||||||
return kwinApp()->platform()->supportsGammaControl();
|
return kwinApp()->platform()->supportsGammaControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Manager::currentTemperature() const
|
int NightColorManager::currentTemperature() const
|
||||||
{
|
{
|
||||||
return m_currentTemp;
|
return m_currentTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Manager::targetTemperature() const
|
int NightColorManager::targetTemperature() const
|
||||||
{
|
{
|
||||||
return m_targetTemperature;
|
return m_targetTemperature;
|
||||||
}
|
}
|
||||||
|
|
||||||
NightColorMode Manager::mode() const
|
NightColorMode NightColorManager::mode() const
|
||||||
{
|
{
|
||||||
return m_mode;
|
return m_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime Manager::previousTransitionDateTime() const
|
QDateTime NightColorManager::previousTransitionDateTime() const
|
||||||
{
|
{
|
||||||
return m_prev.first;
|
return m_prev.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 Manager::previousTransitionDuration() const
|
qint64 NightColorManager::previousTransitionDuration() const
|
||||||
{
|
{
|
||||||
return m_prev.first.msecsTo(m_prev.second);
|
return m_prev.first.msecsTo(m_prev.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime Manager::scheduledTransitionDateTime() const
|
QDateTime NightColorManager::scheduledTransitionDateTime() const
|
||||||
{
|
{
|
||||||
return m_next.first;
|
return m_next.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 Manager::scheduledTransitionDuration() const
|
qint64 NightColorManager::scheduledTransitionDuration() const
|
||||||
{
|
{
|
||||||
return m_next.first.msecsTo(m_next.second);
|
return m_next.first.msecsTo(m_next.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::initShortcuts()
|
void NightColorManager::readConfig()
|
||||||
{
|
{
|
||||||
// legacy shortcut with localized key (to avoid breaking existing config)
|
NightColorSettings *s = NightColorSettings::self();
|
||||||
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<QKeySequence>());
|
|
||||||
input()->registerShortcut(QKeySequence(), toggleAction, this, &Manager::toggle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Manager::readConfig()
|
|
||||||
{
|
|
||||||
Settings *s = Settings::self();
|
|
||||||
s->load();
|
s->load();
|
||||||
|
|
||||||
setEnabled(s->active());
|
setEnabled(s->active());
|
||||||
|
@ -309,7 +321,7 @@ void Manager::readConfig()
|
||||||
m_trTime = qMax(trTime / 1000 / 60, 1);
|
m_trTime = qMax(trTime / 1000 / 60, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::resetAllTimers()
|
void NightColorManager::resetAllTimers()
|
||||||
{
|
{
|
||||||
cancelAllTimers();
|
cancelAllTimers();
|
||||||
if (isAvailable()) {
|
if (isAvailable()) {
|
||||||
|
@ -321,7 +333,7 @@ void Manager::resetAllTimers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::cancelAllTimers()
|
void NightColorManager::cancelAllTimers()
|
||||||
{
|
{
|
||||||
delete m_slowUpdateStartTimer;
|
delete m_slowUpdateStartTimer;
|
||||||
delete m_slowUpdateTimer;
|
delete m_slowUpdateTimer;
|
||||||
|
@ -332,7 +344,7 @@ void Manager::cancelAllTimers()
|
||||||
m_quickAdjustTimer = nullptr;
|
m_quickAdjustTimer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::resetQuickAdjustTimer()
|
void NightColorManager::resetQuickAdjustTimer()
|
||||||
{
|
{
|
||||||
updateTransitionTimings(false);
|
updateTransitionTimings(false);
|
||||||
updateTargetTemperature();
|
updateTargetTemperature();
|
||||||
|
@ -343,7 +355,7 @@ void Manager::resetQuickAdjustTimer()
|
||||||
cancelAllTimers();
|
cancelAllTimers();
|
||||||
m_quickAdjustTimer = new QTimer(this);
|
m_quickAdjustTimer = new QTimer(this);
|
||||||
m_quickAdjustTimer->setSingleShot(false);
|
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);
|
int interval = QUICK_ADJUST_DURATION / (tempDiff / TEMPERATURE_STEP);
|
||||||
if (interval == 0) {
|
if (interval == 0) {
|
||||||
|
@ -355,7 +367,7 @@ void Manager::resetQuickAdjustTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::quickAdjust()
|
void NightColorManager::quickAdjust()
|
||||||
{
|
{
|
||||||
if (!m_quickAdjustTimer) {
|
if (!m_quickAdjustTimer) {
|
||||||
return;
|
return;
|
||||||
|
@ -379,7 +391,7 @@ void Manager::quickAdjust()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::resetSlowUpdateStartTimer()
|
void NightColorManager::resetSlowUpdateStartTimer()
|
||||||
{
|
{
|
||||||
delete m_slowUpdateStartTimer;
|
delete m_slowUpdateStartTimer;
|
||||||
m_slowUpdateStartTimer = nullptr;
|
m_slowUpdateStartTimer = nullptr;
|
||||||
|
@ -398,14 +410,14 @@ void Manager::resetSlowUpdateStartTimer()
|
||||||
// set up the next slow update
|
// set up the next slow update
|
||||||
m_slowUpdateStartTimer = new QTimer(this);
|
m_slowUpdateStartTimer = new QTimer(this);
|
||||||
m_slowUpdateStartTimer->setSingleShot(true);
|
m_slowUpdateStartTimer->setSingleShot(true);
|
||||||
connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &Manager::resetSlowUpdateStartTimer);
|
connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &NightColorManager::resetSlowUpdateStartTimer);
|
||||||
|
|
||||||
updateTransitionTimings(false);
|
updateTransitionTimings(false);
|
||||||
updateTargetTemperature();
|
updateTargetTemperature();
|
||||||
|
|
||||||
const int diff = QDateTime::currentDateTime().msecsTo(m_next.first);
|
const int diff = QDateTime::currentDateTime().msecsTo(m_next.first);
|
||||||
if (diff <= 0) {
|
if (diff <= 0) {
|
||||||
qCCritical(KWIN_COLORCORRECTION) << "Error in time calculation. Deactivating Night Color.";
|
qCCritical(KWIN_NIGHTCOLOR) << "Error in time calculation. Deactivating Night Color.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_slowUpdateStartTimer->start(diff);
|
m_slowUpdateStartTimer->start(diff);
|
||||||
|
@ -414,7 +426,7 @@ void Manager::resetSlowUpdateStartTimer()
|
||||||
resetSlowUpdateTimer();
|
resetSlowUpdateTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::resetSlowUpdateTimer()
|
void NightColorManager::resetSlowUpdateTimer()
|
||||||
{
|
{
|
||||||
delete m_slowUpdateTimer;
|
delete m_slowUpdateTimer;
|
||||||
m_slowUpdateTimer = nullptr;
|
m_slowUpdateTimer = nullptr;
|
||||||
|
@ -448,7 +460,7 @@ void Manager::resetSlowUpdateTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::slowUpdate(int targetTemp)
|
void NightColorManager::slowUpdate(int targetTemp)
|
||||||
{
|
{
|
||||||
if (!m_slowUpdateTimer) {
|
if (!m_slowUpdateTimer) {
|
||||||
return;
|
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;
|
const int targetTemperature = mode() != NightColorMode::Constant && daylight() ? m_dayTargetTemp : m_nightTargetTemp;
|
||||||
|
|
||||||
|
@ -480,7 +492,7 @@ void Manager::updateTargetTemperature()
|
||||||
emit targetTemperatureChanged();
|
emit targetTemperatureChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::updateTransitionTimings(bool force)
|
void NightColorManager::updateTransitionTimings(bool force)
|
||||||
{
|
{
|
||||||
if (m_mode == NightColorMode::Constant) {
|
if (m_mode == NightColorMode::Constant) {
|
||||||
m_next = DateTimes();
|
m_next = DateTimes();
|
||||||
|
@ -557,7 +569,7 @@ void Manager::updateTransitionTimings(bool force)
|
||||||
emit scheduledTransitionTimingsChanged();
|
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);
|
DateTimes dateTimes = calculateSunTimings(dateTime, latitude, longitude, morning);
|
||||||
// At locations near the poles it is possible, that we can't
|
// 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;
|
return dateTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::checkAutomaticSunTimings() const
|
bool NightColorManager::checkAutomaticSunTimings() const
|
||||||
{
|
{
|
||||||
if (m_prev.first.isValid() && m_prev.second.isValid() &&
|
if (m_prev.first.isValid() && m_prev.second.isValid() &&
|
||||||
m_next.first.isValid() && m_next.second.isValid()) {
|
m_next.first.isValid() && m_next.second.isValid()) {
|
||||||
|
@ -593,12 +605,12 @@ bool Manager::checkAutomaticSunTimings() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::daylight() const
|
bool NightColorManager::daylight() const
|
||||||
{
|
{
|
||||||
return m_prev.first.date() == m_next.first.date();
|
return m_prev.first.date() == m_next.first.date();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Manager::currentTargetTemp() const
|
int NightColorManager::currentTargetTemp() const
|
||||||
{
|
{
|
||||||
if (!m_running) {
|
if (!m_running) {
|
||||||
return NEUTRAL_TEMPERATURE;
|
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();
|
const auto outs = kwinApp()->platform()->outputs();
|
||||||
|
|
||||||
|
@ -674,11 +686,11 @@ void Manager::commitGammaRamps(int temperature)
|
||||||
} else {
|
} else {
|
||||||
m_failedCommitAttempts++;
|
m_failedCommitAttempts++;
|
||||||
if (m_failedCommitAttempts < 10) {
|
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.";
|
". Trying " << (10 - m_failedCommitAttempts) << " times more.";
|
||||||
} else {
|
} else {
|
||||||
// TODO: On multi monitor setups we could try to rollback earlier changes for already committed outputs
|
// 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)
|
m_failedCommitAttempts = 0; // reset so we can try again later (i.e. after suspend phase or config change)
|
||||||
setRunning(false);
|
setRunning(false);
|
||||||
cancelAllTimers();
|
cancelAllTimers();
|
||||||
|
@ -687,7 +699,7 @@ void Manager::commitGammaRamps(int temperature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, QVariant> Manager::info() const
|
QHash<QString, QVariant> NightColorManager::info() const
|
||||||
{
|
{
|
||||||
return QHash<QString, QVariant> {
|
return QHash<QString, QVariant> {
|
||||||
{ QStringLiteral("Available"), isAvailable() },
|
{ QStringLiteral("Available"), isAvailable() },
|
||||||
|
@ -718,7 +730,7 @@ QHash<QString, QVariant> Manager::info() const
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::changeConfiguration(QHash<QString, QVariant> data)
|
bool NightColorManager::changeConfiguration(QHash<QString, QVariant> data)
|
||||||
{
|
{
|
||||||
bool activeUpdate, modeUpdate, tempUpdate, locUpdate, timeUpdate;
|
bool activeUpdate, modeUpdate, tempUpdate, locUpdate, timeUpdate;
|
||||||
activeUpdate = modeUpdate = tempUpdate = locUpdate = timeUpdate = false;
|
activeUpdate = modeUpdate = tempUpdate = locUpdate = timeUpdate = false;
|
||||||
|
@ -841,7 +853,7 @@ bool Manager::changeConfiguration(QHash<QString, QVariant> data)
|
||||||
cancelAllTimers();
|
cancelAllTimers();
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings *s = Settings::self();
|
NightColorSettings *s = NightColorSettings::self();
|
||||||
if (activeUpdate) {
|
if (activeUpdate) {
|
||||||
setEnabled(active);
|
setEnabled(active);
|
||||||
s->setActive(active);
|
s->setActive(active);
|
||||||
|
@ -881,9 +893,9 @@ bool Manager::changeConfiguration(QHash<QString, QVariant> data)
|
||||||
return true;
|
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)) {
|
if (!checkLocation(latitude, longitude)) {
|
||||||
return;
|
return;
|
||||||
|
@ -897,7 +909,7 @@ void Manager::autoLocationUpdate(double latitude, double longitude)
|
||||||
m_latAuto = latitude;
|
m_latAuto = latitude;
|
||||||
m_lngAuto = longitude;
|
m_lngAuto = longitude;
|
||||||
|
|
||||||
Settings *s = Settings::self();
|
NightColorSettings *s = NightColorSettings::self();
|
||||||
s->setLatitudeAuto(latitude);
|
s->setLatitudeAuto(latitude);
|
||||||
s->setLongitudeAuto(longitude);
|
s->setLongitudeAuto(longitude);
|
||||||
s->save();
|
s->save();
|
||||||
|
@ -906,7 +918,7 @@ void Manager::autoLocationUpdate(double latitude, double longitude)
|
||||||
emit configChange(info());
|
emit configChange(info());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::setEnabled(bool enabled)
|
void NightColorManager::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (m_active == enabled) {
|
if (m_active == enabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -916,7 +928,7 @@ void Manager::setEnabled(bool enabled)
|
||||||
emit enabledChanged();
|
emit enabledChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::setRunning(bool running)
|
void NightColorManager::setRunning(bool running)
|
||||||
{
|
{
|
||||||
if (m_running == running) {
|
if (m_running == running) {
|
||||||
return;
|
return;
|
||||||
|
@ -925,7 +937,7 @@ void Manager::setRunning(bool running)
|
||||||
emit runningChanged();
|
emit runningChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::setCurrentTemperature(int temperature)
|
void NightColorManager::setCurrentTemperature(int temperature)
|
||||||
{
|
{
|
||||||
if (m_currentTemp == temperature) {
|
if (m_currentTemp == temperature) {
|
||||||
return;
|
return;
|
||||||
|
@ -934,7 +946,7 @@ void Manager::setCurrentTemperature(int temperature)
|
||||||
emit currentTemperatureChanged();
|
emit currentTemperatureChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::setMode(NightColorMode mode)
|
void NightColorManager::setMode(NightColorMode mode)
|
||||||
{
|
{
|
||||||
if (m_mode == mode) {
|
if (m_mode == mode) {
|
||||||
return;
|
return;
|
||||||
|
@ -943,5 +955,4 @@ void Manager::setMode(NightColorMode mode)
|
||||||
emit modeChanged();
|
emit modeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace KWin
|
||||||
}
|
|
|
@ -6,11 +6,11 @@
|
||||||
|
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
#ifndef KWIN_COLORCORRECT_MANAGER_H
|
|
||||||
#define KWIN_COLORCORRECT_MANAGER_H
|
#pragma once
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include <kwin_export.h>
|
#include "plugin.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
|
@ -22,16 +22,11 @@ namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
class ClockSkewNotifier;
|
class ClockSkewNotifier;
|
||||||
class Workspace;
|
class NightColorDBusInterface;
|
||||||
|
|
||||||
namespace ColorCorrect
|
|
||||||
{
|
|
||||||
|
|
||||||
typedef QPair<QDateTime,QDateTime> DateTimes;
|
typedef QPair<QDateTime,QDateTime> DateTimes;
|
||||||
typedef QPair<QTime,QTime> Times;
|
typedef QPair<QTime,QTime> Times;
|
||||||
|
|
||||||
class ColorCorrectDBusInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 color manager.
|
||||||
*/
|
*/
|
||||||
|
@ -76,12 +71,14 @@ enum NightColorMode {
|
||||||
*
|
*
|
||||||
* With the Constant mode, screen color temperature is always constant.
|
* With the Constant mode, screen color temperature is always constant.
|
||||||
*/
|
*/
|
||||||
class KWIN_EXPORT Manager : public QObject
|
class KWIN_EXPORT NightColorManager : public Plugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Manager(QObject *parent);
|
explicit NightColorManager(QObject *parent = nullptr);
|
||||||
|
~NightColorManager() override;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -190,6 +187,7 @@ public:
|
||||||
|
|
||||||
// for auto tests
|
// for auto tests
|
||||||
void reparseConfigAndReset();
|
void reparseConfigAndReset();
|
||||||
|
static NightColorManager *self();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void resetSlowUpdateStartTimer();
|
void resetSlowUpdateStartTimer();
|
||||||
|
@ -239,7 +237,6 @@ Q_SIGNALS:
|
||||||
void scheduledTransitionTimingsChanged();
|
void scheduledTransitionTimingsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initShortcuts();
|
|
||||||
void readConfig();
|
void readConfig();
|
||||||
void hardReset();
|
void hardReset();
|
||||||
void slowUpdate(int targetTemp);
|
void slowUpdate(int targetTemp);
|
||||||
|
@ -268,7 +265,7 @@ private:
|
||||||
void setCurrentTemperature(int temperature);
|
void setCurrentTemperature(int temperature);
|
||||||
void setMode(NightColorMode mode);
|
void setMode(NightColorMode mode);
|
||||||
|
|
||||||
ColorCorrectDBusInterface *m_iface;
|
NightColorDBusInterface *m_iface;
|
||||||
ClockSkewNotifier *m_skewNotifier;
|
ClockSkewNotifier *m_skewNotifier;
|
||||||
|
|
||||||
// Specifies whether Night Color is enabled.
|
// Specifies whether Night Color is enabled.
|
||||||
|
@ -309,12 +306,6 @@ private:
|
||||||
|
|
||||||
int m_failedCommitAttempts = 0;
|
int m_failedCommitAttempts = 0;
|
||||||
int m_inhibitReferenceCount = 0;
|
int m_inhibitReferenceCount = 0;
|
||||||
|
|
||||||
// The Workspace class needs to call initShortcuts during initialization.
|
|
||||||
friend class KWin::Workspace;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace KWin
|
||||||
}
|
|
||||||
|
|
||||||
#endif // KWIN_COLORCORRECT_MANAGER_H
|
|
|
@ -15,7 +15,7 @@
|
||||||
<default>true</default>
|
<default>true</default>
|
||||||
</entry>
|
</entry>
|
||||||
<entry name="Mode" type="Enum">
|
<entry name="Mode" type="Enum">
|
||||||
<choices name="KWin::ColorCorrect::NightColorMode">
|
<choices name="KWin::NightColorMode">
|
||||||
<choice name="Automatic"/>
|
<choice name="Automatic"/>
|
||||||
<choice name="Location"/>
|
<choice name="Location"/>
|
||||||
<choice name="Times"/>
|
<choice name="Times"/>
|
8
plugins/nightcolor/nightcolorsettings.kcfgc
Normal file
8
plugins/nightcolor/nightcolorsettings.kcfgc
Normal file
|
@ -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
|
|
@ -14,7 +14,6 @@
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
|
|
||||||
namespace KWin {
|
namespace KWin {
|
||||||
namespace ColorCorrect {
|
|
||||||
|
|
||||||
#define TWILIGHT_NAUT -12.0
|
#define TWILIGHT_NAUT -12.0
|
||||||
#define TWILIGHT_CIVIL -6.0
|
#define TWILIGHT_CIVIL -6.0
|
||||||
|
@ -160,4 +159,3 @@ QPair<QDateTime, QDateTime> calculateSunTimings(const QDateTime &dateTime, doubl
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -16,9 +16,6 @@
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace ColorCorrect
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates for a given location and date two of the
|
* Calculates for a given location and date two of the
|
||||||
* following sun timings in their temporal order:
|
* following sun timings in their temporal order:
|
||||||
|
@ -29,8 +26,6 @@ namespace ColorCorrect
|
||||||
|
|
||||||
QPair<QDateTime, QDateTime> calculateSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning);
|
QPair<QDateTime, QDateTime> calculateSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // KWIN_SUNCALCULATOR_H
|
#endif // KWIN_SUNCALCULATOR_H
|
|
@ -25,7 +25,6 @@
|
||||||
#include "useractions.h"
|
#include "useractions.h"
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
#include "x11client.h"
|
#include "x11client.h"
|
||||||
#include "colorcorrection/manager.h"
|
|
||||||
#include "composite.h"
|
#include "composite.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "workspace.h"
|
#include "workspace.h"
|
||||||
|
@ -967,7 +966,6 @@ void Workspace::initShortcuts()
|
||||||
TabBox::TabBox::self()->initShortcuts();
|
TabBox::TabBox::self()->initShortcuts();
|
||||||
#endif
|
#endif
|
||||||
VirtualDesktopManager::self()->initShortcuts();
|
VirtualDesktopManager::self()->initShortcuts();
|
||||||
kwinApp()->platform()->colorCorrectManager()->initShortcuts();
|
|
||||||
m_userActionsMenu->discard(); // so that it's recreated next time
|
m_userActionsMenu->discard(); // so that it's recreated next time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue