quicksettings/nightcolor: Fix night color

This commit is contained in:
Devin Lin 2022-01-04 12:12:46 -05:00
parent db8ab82778
commit 1f0db0efc6
14 changed files with 424 additions and 15 deletions

View file

@ -58,16 +58,14 @@ include(CheckIncludeFiles)
plasma_install_package(look-and-feel org.kde.plasma.phone look-and-feel)
plasma_install_package(shell org.kde.plasma.phoneshell shells)
plasma_install_package(quicksettings/nightcolor org.kde.plasma.nightcolor quicksettings)
plasma_install_package(quicksettings/airplanemode org.kde.plasma.airplanemode quicksettings)
install(FILES plasma_phone_components.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR})
add_subdirectory(bin)
add_subdirectory(applets)
add_subdirectory(containments)
add_subdirectory(components)
add_subdirectory(quicksettings)
find_program(PlasmaOpenSettings plasma-open-settings)
set_package_properties(PlasmaOpenSettings PROPERTIES

View file

@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later
plasma_install_package(airplanemode org.kde.plasma.airplanemode quicksettings)
add_subdirectory(nightcolor)

View file

@ -0,0 +1,49 @@
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later
set_source_files_properties(dbus/org.kde.kwin.ColorCorrect.xml PROPERTIES NO_NAMESPACE TRUE)
qt_add_dbus_interfaces(DBUS_SRCS dbus/org.kde.kwin.ColorCorrect.xml)
set(nightcolorplugin_SRCS
nightcolorplugin.cpp
nightcolorutil.cpp
enum.h
${DBUS_SRCS}
)
kconfig_add_kcfg_files(nightcolorplugin_SRCS nightcolorsettings.kcfgc GENERATE_MOC)
add_library(nightcolorplugin ${nightcolorplugin_SRCS})
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Config
Declarative
)
target_link_libraries(nightcolorplugin
PUBLIC
Qt::Core
PRIVATE
Qt::DBus
Qt::Qml
Qt::Gui
Qt::Quick
KF5::Plasma
KF5::I18n
KF5::Notifications
KF5::PlasmaQuick
KF5::WaylandClient
KF5::Service
KF5::CoreAddons
KF5::QuickAddons
KF5::ConfigCore
KF5::ConfigGui
)
set_property(TARGET nightcolorplugin PROPERTY LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/quicksetting/nightcolor)
file(COPY qmldir DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/quicksetting/nightcolor)
install(TARGETS nightcolorplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/quicksetting/nightcolor)
install(FILES qmldir ${qml_SRC} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/quicksetting/nightcolor)
plasma_install_package(package org.kde.plasma.nightcolor quicksettings)

View file

@ -0,0 +1,109 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!--
- SPDX-FileCopyrightText: 2017 Roman Gilg
- SPDX-FileCopyrightText: 2020 Vlad Zahorodnii
- SPDX-License-Identifier: GPL-2.0-or-later
-->
<node>
<interface name="org.kde.kwin.ColorCorrect">
<method name="nightColorAutoLocationUpdate">
<arg type="d" direction="in"/>
<arg type="d" direction="in"/>
</method>
<!--
Creates an inhibition lock for Night Color.
You can use this method to temporarily disable Night Color feature.
After calling this method, the screen color temperature will be set
back to the neutral temperature (6500K).
This method returns a cookie that uniquely identifies the inhibition
request. You must pass the cookie to uninhibit() when you're done.
Note that the inhibition lock will be released automatically when
the service, which requested it, is unregistered.
A client is allowed to hold more than just one inhibition lock.
-->
<method name="inhibit">
<arg name="cookie" type="u" direction="out"/>
</method>
<!--
Releases an inhibition lock identified by the given cookie.
Note that the inhibition lock will be released automatically when
the service, which requested it, is unregistered.
-->
<method name="uninhibit">
<arg name="cookie" type="u" direction="in"/>
</method>
<!--
This property holds a value to indicate whether Night Color is inhibited.
-->
<property name="inhibited" type="b" access="read"/>
<!--
This property holds a value to indicate whether Night Color is enabled.
-->
<property name="enabled" type="b" access="read"/>
<!--
This property holds a value to indicate whether Night Color is running.
-->
<property name="running" type="b" access="read"/>
<!--
This property holds a value to indicate whether Night Color is available.
-->
<property name="available" type="b" access="read"/>
<!--
This property holds a value to indicate the current screen color temperature.
-->
<property name="currentTemperature" type="u" access="read"/>
<!--
This property holds a value to indicate the target screen color temperature.
-->
<property name="targetTemperature" type="u" access="read"/>
<!--
This property holds a value to indicate the operating mode.
Valid modes: 0 - automatic, 1 - location, 2 - timings, 3 - constant.
-->
<property name="mode" type="u" access="read"/>
<!--
This property holds a Unix timestamp that specifies when the previous color
temperature transition had started. Note that when Night Color operates in
the constant mode, this property holds a value of 0.
-->
<property name="previousTransitionDateTime" type="t" access="read"/>
<!--
This property holds a value that specifies the duration of the previous color
temperature transition, in milliseconds. Note that when Night Color operates
in the constant mode, this property holds a value of 0.
-->
<property name="previousTransitionDuration" type="u" access="read"/>
<!--
This property holds a Unix timestamp that specifies when the next scheduled
color temperature transition will start. Note that when Night Color operates
in the constant mode, this property holds a value of 0.
-->
<property name="scheduledTransitionDateTime" type="t" access="read"/>
<!--
This property holds a value that specifies the duration of next scheduled
color transition, in milliseconds. Note that when Night Color operates in
the constant mode, this property holds a value of 0.
-->
<property name="scheduledTransitionDuration" type="u" access="read"/>
</interface>
</node>

View file

@ -0,0 +1,40 @@
/*
SPDX-FileCopyrightText: 2021 Benjamin Port <benjamin.port@enioka.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <qobjectdefs.h>
namespace ColorCorrect
{
Q_NAMESPACE
enum NightColorMode {
/**
* Color temperature is computed based on the current position of the Sun.
*
* Location of the user is provided by Plasma.
*/
Automatic,
/**
* Color temperature is computed based on the current position of the Sun.
*
* Location of the user is provided by themselves.
*/
Location,
/**
* Color temperature is computed based on the current time.
*
* Sunrise and sunset times have to be specified by the user.
*/
Timings,
/**
* Color temperature is constant thoughout the day.
*/
Constant,
};
Q_ENUM_NS(NightColorMode)
}

View file

@ -0,0 +1,23 @@
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "nightcolorplugin.h"
#include <QQmlContext>
#include <QQuickItem>
#include "nightcolorutil.h"
void NightColorPlugin::registerTypes(const char *uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.quicksetting.nightcolor"));
qmlRegisterSingletonType<NightColorUtil>(uri, 1, 0, "NightColorUtil", [](QQmlEngine *, QJSEngine *) {
return new NightColorUtil;
});
}
//#include "moc_nightcolorplugin.cpp"

View file

@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QUrl>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
class NightColorPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char *uri) override;
};

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
- SPDX-FileCopyrightText: 2020 Vlad Zahorodnii
- SPDX-License-Identifier: GPL-2.0-or-later
-->
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kwinrc"/>
<group name="NightColor">
<entry name="ActiveEnabled" type="Bool">
<default>true</default>
</entry>
<entry name="Active" type="Bool">
<default>false</default>
</entry>
<entry name="ModeEnabled" type="Bool">
<default>true</default>
</entry>
<entry name="Mode" type="Enum">
<choices name="ColorCorrect::NightColorMode">
<choice name="Automatic"/>
<choice name="Location"/>
<choice name="Times"/>
<choice name="Constant"/>
</choices>
<default>Automatic</default>
</entry>
<entry name="NightTemperatureEnabled" type="Bool">
<default>true</default>
</entry>
<entry name="NightTemperature" type="Int">
<default>4500</default>
<min>1000</min>
<max>6500</max>
</entry>
<entry name="LatitudeAuto" type="Double">
<default>0.</default>
</entry>
<entry name="LongitudeAuto" type="Double">
<default>0.</default>
</entry>
<entry name="LocationEnabled" type="Bool">
<default>true</default>
</entry>
<entry name="LatitudeFixed" type="Double">
<default>0.</default>
</entry>
<entry name="LongitudeFixed" type="Double">
<default>0.</default>
</entry>
<entry name="MorningBeginFixed" type="String">
<default>0600</default>
</entry>
<entry name="EveningBeginFixed" type="String">
<default>1800</default>
</entry>
<entry name="TransitionTime" type="Int">
<default>30</default>
</entry>
</group>
</kcfg>

View file

@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2020 Vlad Zahorodnii
# SPDX-License-Identifier: GPL-2.0-or-later
File=nightcolorsettings.kcfg
Namespace=ColorCorrect
ClassName=NightColorSettings
Mutators=true
# nightcolormanager.h is needed for NightColorMode
IncludeFiles=enum.h
UseEnumTypes=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
Notifiers=true

View file

@ -0,0 +1,53 @@
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "nightcolorutil.h"
NightColorUtil::NightColorUtil(QObject *parent)
: QObject{parent}
, m_ccInterface{new OrgKdeKwinColorCorrectInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/ColorCorrect"), QDBusConnection::sessionBus(), this)}
, m_settings{new NightColorSettings(this)}
{
if (!m_ccInterface->isValid()) {
qWarning() << "Can't connect to nightcolor over DBus!";
} else {
m_enabled = m_ccInterface->running();
// subscribe to property updates
QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.KWin"),
QStringLiteral("/ColorCorrect"),
QStringLiteral("org.freedesktop.DBus.Properties"),
QStringLiteral("PropertiesChanged"),
this,
SLOT(enabledUpdated(QString, QVariantMap, QStringList)));
}
}
bool NightColorUtil::enabled()
{
return m_enabled;
}
void NightColorUtil::setEnabled(bool enabled)
{
m_settings->setModeEnabled(true);
m_settings->setMode(ColorCorrect::NightColorMode::Constant);
m_settings->setActiveEnabled(true);
m_settings->setActive(enabled);
m_settings->save();
}
void NightColorUtil::enabledUpdated(QString name, QVariantMap map, QStringList list)
{
Q_UNUSED(name);
Q_UNUSED(map);
Q_UNUSED(list);
bool running = m_ccInterface->running();
if (running != m_enabled) {
m_enabled = running;
Q_EMIT enabledChanged();
}
}

View file

@ -0,0 +1,35 @@
/*
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QObject>
#include "colorcorrectinterface.h"
#include "nightcolorsettings.h"
class NightColorUtil : public QObject
{
Q_OBJECT
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
public:
NightColorUtil(QObject *parent = nullptr);
bool enabled();
void setEnabled(bool enabled);
Q_SIGNALS:
void enabledChanged();
public Q_SLOTS:
void enabledUpdated(QString name, QVariantMap map, QStringList list);
private:
bool m_enabled;
OrgKdeKwinColorCorrectInterface *m_ccInterface;
NightColorSettings *m_settings;
};

View file

@ -8,25 +8,16 @@
import org.kde.colorcorrect 0.1 as CC
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import org.kde.plasma.quicksetting.nightcolor 1.0 as NightColor
MobileShell.QuickSetting {
text: i18n("Night Color")
icon: "redshift-status-on"
enabled: compositorAdaptor.active
enabled: NightColor.NightColorUtil.enabled
status: ""
settingsCommand: "plasma-open-settings kcm_nightcolor"
CC.CompositorAdaptor {
id: compositorAdaptor
}
function toggle() {
if (compositorAdaptor.active) {
compositorAdaptor.activeStaged = false;
} else {
compositorAdaptor.activeStaged = true;
compositorAdaptor.modeStaged = 3; // always on
}
compositorAdaptor.sendConfigurationAll();
enabled = compositorAdaptor.active;
NightColor.NightColorUtil.enabled = !enabled;
}
}

View file

@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
# SPDX-License-Identifier: GPL-2.0-or-later
module org.kde.plasma.quicksetting.nightcolor
plugin nightcolorplugin
classname NightColorPlugin