diff --git a/src/plugins/colorblindnesscorrection/CMakeLists.txt b/src/plugins/colorblindnesscorrection/CMakeLists.txt index 49b860cb47..e63a34fc24 100644 --- a/src/plugins/colorblindnesscorrection/CMakeLists.txt +++ b/src/plugins/colorblindnesscorrection/CMakeLists.txt @@ -6,7 +6,13 @@ kwin_add_builtin_effect(colorblindnesscorrection colorblindnesscorrection.qrc main.cpp ) -kconfig_add_kcfg_files(colorblindnesscorrection colorblindnesscorrection_settings.kcfgc GENERATE_MOC) +set(SETTINGS_HEADER "colorblindnesscorrection_settings_singleton") +set(GENERATE_MOC "false") +set(USE_SINGLETON "true") +set(KCFGFILE_ARGS "arg=\"true\"") +configure_file(colorblindnesscorrection_settings.kcfgc.in ${CMAKE_CURRENT_BINARY_DIR}/${SETTINGS_HEADER}.kcfgc @ONLY) +configure_file(colorblindnesscorrection_settings.kcfg.in ${CMAKE_CURRENT_BINARY_DIR}/${SETTINGS_HEADER}.kcfg @ONLY) +kconfig_add_kcfg_files(colorblindnesscorrection ${CMAKE_CURRENT_BINARY_DIR}/${SETTINGS_HEADER}.kcfgc) target_link_libraries(colorblindnesscorrection PRIVATE kwin @@ -19,14 +25,20 @@ if (NOT KWIN_BUILD_KCMS) return() endif() +set(SETTINGS_HEADER "colorblindnesscorrection_settings") kcmutils_add_qml_kcm(kwin_colorblindnesscorrection_config SOURCES colorblindnesscorrection_config.cpp INSTALL_NAMESPACE "kwin/effects/configs" DISABLE_DESKTOP_FILE_GENERATION) kcmutils_generate_module_data(kwin_colorblindnesscorrection_config MODULE_DATA_HEADER colorblindnesscorrection_settingsdata.h MODULE_DATA_CLASS_NAME ColorBlindnessCorrectionSettingsData - SETTINGS_HEADERS colorblindnesscorrection_settings.h + SETTINGS_HEADERS ${SETTINGS_HEADER}.h SETTINGS_CLASSES ColorBlindnessCorrectionSettings ) -kconfig_add_kcfg_files(kwin_colorblindnesscorrection_config colorblindnesscorrection_settings.kcfgc GENERATE_MOC) +set(GENERATE_MOC "true") +set(USE_SINGLETON "false") +set(KCFGFILE_ARGS "name=\"kwinrc\"") +configure_file(colorblindnesscorrection_settings.kcfgc.in ${CMAKE_CURRENT_BINARY_DIR}/${SETTINGS_HEADER}.kcfgc @ONLY) +configure_file(colorblindnesscorrection_settings.kcfg.in ${CMAKE_CURRENT_BINARY_DIR}/${SETTINGS_HEADER}.kcfg @ONLY) +kconfig_add_kcfg_files(kwin_colorblindnesscorrection_config ${CMAKE_CURRENT_BINARY_DIR}/colorblindnesscorrection_settings.kcfgc GENERATE_MOC) target_link_libraries(kwin_colorblindnesscorrection_config KF6::ConfigCore KF6::KCMUtils diff --git a/src/plugins/colorblindnesscorrection/colorblindnesscorrection.cpp b/src/plugins/colorblindnesscorrection/colorblindnesscorrection.cpp index 00a3961c38..370336ce37 100644 --- a/src/plugins/colorblindnesscorrection/colorblindnesscorrection.cpp +++ b/src/plugins/colorblindnesscorrection/colorblindnesscorrection.cpp @@ -6,12 +6,10 @@ #include "colorblindnesscorrection.h" -#include - #include "effect/effecthandler.h" #include "opengl/glshader.h" -#include "colorblindnesscorrection_settings.h" +#include "colorblindnesscorrection_settings_singleton.h" Q_LOGGING_CATEGORY(KWIN_COLORBLINDNESS_CORRECTION, "kwin_effect_colorblindnesscorrection", QtWarningMsg) @@ -26,8 +24,11 @@ namespace KWin ColorBlindnessCorrectionEffect::ColorBlindnessCorrectionEffect() : OffscreenEffect() - , m_mode(static_cast(ColorBlindnessCorrectionSettings().mode())) { + ColorBlindnessCorrectionSettings::instance(effects->config()); + m_mode = static_cast(ColorBlindnessCorrectionSettings::mode()); + m_intensity = std::clamp(ColorBlindnessCorrectionSettings::intensity(), 0.0f, 1.0f); + loadData(); } @@ -65,6 +66,10 @@ void ColorBlindnessCorrectionEffect::loadData() return; } + if (ShaderBinder binder{m_shader.get()}; !m_shader->setUniform("intensity", m_intensity)) { + qCWarning(KWIN_COLORBLINDNESS_CORRECTION) << "Failed to set intensity"; + } + for (const auto windows = effects->stackingOrder(); EffectWindow * w : windows) { correctColor(w); } @@ -108,12 +113,15 @@ void ColorBlindnessCorrectionEffect::reconfigure(ReconfigureFlags flags) return; } - auto newMode = static_cast(ColorBlindnessCorrectionSettings().mode()); - if (m_mode == newMode) { + ColorBlindnessCorrectionSettings::self()->read(); + const auto newMode = static_cast(ColorBlindnessCorrectionSettings::mode()); + const auto newIntensity = std::clamp(ColorBlindnessCorrectionSettings::intensity(), 0.0f, 1.0f); + if (m_mode == newMode && qFuzzyCompare(m_intensity, newIntensity)) { return; } m_mode = newMode; + m_intensity = newIntensity; disconnect(effects, &EffectsHandler::windowDeleted, this, &ColorBlindnessCorrectionEffect::slotWindowDeleted); disconnect(effects, &EffectsHandler::windowAdded, this, &ColorBlindnessCorrectionEffect::correctColor); diff --git a/src/plugins/colorblindnesscorrection/colorblindnesscorrection.h b/src/plugins/colorblindnesscorrection/colorblindnesscorrection.h index 4ad7854a89..8ef48eaba8 100644 --- a/src/plugins/colorblindnesscorrection/colorblindnesscorrection.h +++ b/src/plugins/colorblindnesscorrection/colorblindnesscorrection.h @@ -48,6 +48,7 @@ private: void loadData(); Mode m_mode = Protanopia; + float m_intensity = 1.0f; std::unordered_set m_windows; std::unique_ptr m_shader; diff --git a/src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfg b/src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfg.in similarity index 81% rename from src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfg rename to src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfg.in index 98e3cd43f6..5b0492abc8 100644 --- a/src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfg +++ b/src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfg.in @@ -7,10 +7,13 @@ 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" > - + 0 + + 1.0 + diff --git a/src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfgc b/src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfgc.in similarity index 51% rename from src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfgc rename to src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfgc.in index b084975d1a..288b747f80 100644 --- a/src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfgc +++ b/src/plugins/colorblindnesscorrection/colorblindnesscorrection_settings.kcfgc.in @@ -1,9 +1,10 @@ # SPDX-FileCopyrightText: 2023 Fushan Wen # SPDX-License-Identifier: GPL-2.0-or-later -File=colorblindnesscorrection_settings.kcfg +File=@SETTINGS_HEADERS@.kcfg ClassName=ColorBlindnessCorrectionSettings +DefaultValueGetters=@GENERATE_MOC@ +GenerateProperties=@GENERATE_MOC@ +ParentInConstructor=@GENERATE_MOC@ +Singleton=@USE_SINGLETON@ Mutators=true -DefaultValueGetters=true -GenerateProperties=true -ParentInConstructor=true diff --git a/src/plugins/colorblindnesscorrection/shaders/Deutranopia.frag b/src/plugins/colorblindnesscorrection/shaders/Deutranopia.frag index ee39169ea4..6b0ef267e8 100644 --- a/src/plugins/colorblindnesscorrection/shaders/Deutranopia.frag +++ b/src/plugins/colorblindnesscorrection/shaders/Deutranopia.frag @@ -3,6 +3,7 @@ uniform sampler2D sampler; uniform vec4 modulation; uniform float saturation; +uniform float intensity; varying vec2 texcoord0; void main() @@ -27,7 +28,7 @@ void main() vec3 error = vec3((0.0809444479 * l) + (-0.130504409 * m) + (0.116721066 * s), (-0.0102485335 * l) + (0.0540193266 * m) + (-0.113614708 * s), (-0.000365296938 * l) + (-0.00412161469 * m) + (0.693511405 * s)); - vec3 diff = tex.rgb - error; + vec3 diff = (tex.rgb - error) * vec3(intensity); vec3 correction = vec3(0.0, (diff.r * 0.7) + (diff.g * 1.0), (diff.r * 0.7) + (diff.b * 1.0)); diff --git a/src/plugins/colorblindnesscorrection/shaders/Deutranopia_core.frag b/src/plugins/colorblindnesscorrection/shaders/Deutranopia_core.frag index 16c9c76bc4..3ba483c0f9 100644 --- a/src/plugins/colorblindnesscorrection/shaders/Deutranopia_core.frag +++ b/src/plugins/colorblindnesscorrection/shaders/Deutranopia_core.frag @@ -4,7 +4,7 @@ uniform sampler2D sampler; uniform vec4 modulation; uniform float saturation; - +uniform float intensity; in vec2 texcoord0; out vec4 fragColor; @@ -30,7 +30,7 @@ void main() vec3 error = vec3((0.0809444479 * l) + (-0.130504409 * m) + (0.116721066 * s), (-0.0102485335 * l) + (0.0540193266 * m) + (-0.113614708 * s), (-0.000365296938 * l) + (-0.00412161469 * m) + (0.693511405 * s)); - vec3 diff = tex.rgb - error; + vec3 diff = (tex.rgb - error) * vec3(intensity); vec3 correction = vec3(0.0, (diff.r * 0.7) + (diff.g * 1.0), (diff.r * 0.7) + (diff.b * 1.0)); diff --git a/src/plugins/colorblindnesscorrection/shaders/Protanopia.frag b/src/plugins/colorblindnesscorrection/shaders/Protanopia.frag index 0aae250862..04a5c33e43 100644 --- a/src/plugins/colorblindnesscorrection/shaders/Protanopia.frag +++ b/src/plugins/colorblindnesscorrection/shaders/Protanopia.frag @@ -3,6 +3,7 @@ uniform sampler2D sampler; uniform vec4 modulation; uniform float saturation; +uniform float intensity; varying vec2 texcoord0; void main() @@ -27,7 +28,7 @@ void main() vec3 error = vec3((0.0809444479 * l) + (-0.130504409 * m) + (0.116721066 * s), (-0.0102485335 * l) + (0.0540193266 * m) + (-0.113614708 * s), (-0.000365296938 * l) + (-0.00412161469 * m) + (0.693511405 * s)); - vec3 diff = tex.rgb - error; + vec3 diff = (tex.rgb - error) * vec3(intensity); vec3 correction = vec3(0.0, (diff.r * 0.7) + (diff.g * 1.0), (diff.r * 0.7) + (diff.b * 1.0)); diff --git a/src/plugins/colorblindnesscorrection/shaders/Protanopia_core.frag b/src/plugins/colorblindnesscorrection/shaders/Protanopia_core.frag index 46cbff9590..6cb7d2808f 100644 --- a/src/plugins/colorblindnesscorrection/shaders/Protanopia_core.frag +++ b/src/plugins/colorblindnesscorrection/shaders/Protanopia_core.frag @@ -4,7 +4,7 @@ uniform sampler2D sampler; uniform vec4 modulation; uniform float saturation; - +uniform float intensity; in vec2 texcoord0; out vec4 fragColor; @@ -30,7 +30,7 @@ void main() vec3 error = vec3((0.0809444479 * l) + (-0.130504409 * m) + (0.116721066 * s), (-0.0102485335 * l) + (0.0540193266 * m) + (-0.113614708 * s), (-0.000365296938 * l) + (-0.00412161469 * m) + (0.693511405 * s)); - vec3 diff = tex.rgb - error; + vec3 diff = (tex.rgb - error) * vec3(intensity); vec3 correction = vec3(0.0, (diff.r * 0.7) + (diff.g * 1.0), (diff.r * 0.7) + (diff.b * 1.0)); diff --git a/src/plugins/colorblindnesscorrection/shaders/Tritanopia.frag b/src/plugins/colorblindnesscorrection/shaders/Tritanopia.frag index 635f269c73..f94a83567e 100644 --- a/src/plugins/colorblindnesscorrection/shaders/Tritanopia.frag +++ b/src/plugins/colorblindnesscorrection/shaders/Tritanopia.frag @@ -3,6 +3,7 @@ uniform sampler2D sampler; uniform vec4 modulation; uniform float saturation; +uniform float intensity; varying vec2 texcoord0; void main() @@ -27,7 +28,7 @@ void main() vec3 error = vec3((0.0809444479 * l) + (-0.130504409 * m) + (0.116721066 * s), (-0.0102485335 * l) + (0.0540193266 * m) + (-0.113614708 * s), (-0.000365296938 * l) + (-0.00412161469 * m) + (0.693511405 * s)); - vec3 diff = tex.rgb - error; + vec3 diff = (tex.rgb - error) * vec3(intensity); vec3 correction = vec3(0.0, (diff.r * 0.7) + (diff.g * 1.0), (diff.r * 0.7) + (diff.b * 1.0)); diff --git a/src/plugins/colorblindnesscorrection/shaders/Tritanopia_core.frag b/src/plugins/colorblindnesscorrection/shaders/Tritanopia_core.frag index 4e9276290a..db09c4e415 100644 --- a/src/plugins/colorblindnesscorrection/shaders/Tritanopia_core.frag +++ b/src/plugins/colorblindnesscorrection/shaders/Tritanopia_core.frag @@ -4,7 +4,7 @@ uniform sampler2D sampler; uniform vec4 modulation; uniform float saturation; - +uniform float intensity; in vec2 texcoord0; out vec4 fragColor; @@ -30,7 +30,7 @@ void main() vec3 error = vec3((0.0809444479 * l) + (-0.130504409 * m) + (0.116721066 * s), (-0.0102485335 * l) + (0.0540193266 * m) + (-0.113614708 * s), (-0.000365296938 * l) + (-0.00412161469 * m) + (0.693511405 * s)); - vec3 diff = tex.rgb - error; + vec3 diff = (tex.rgb - error) * vec3(intensity); vec3 correction = vec3(0.0, (diff.r * 0.7) + (diff.g * 1.0), (diff.r * 0.7) + (diff.b * 1.0)); diff --git a/src/plugins/colorblindnesscorrection/ui/main.qml b/src/plugins/colorblindnesscorrection/ui/main.qml index e27ea4d5de..f574fa5398 100644 --- a/src/plugins/colorblindnesscorrection/ui/main.qml +++ b/src/plugins/colorblindnesscorrection/ui/main.qml @@ -16,7 +16,7 @@ KCM.SimpleKCM { id: root implicitWidth: Kirigami.Units.gridUnit * 30 - implicitHeight: Kirigami.Units.gridUnit * 22 + implicitHeight: Kirigami.Units.gridUnit * 24 RowLayout { id: previewArea @@ -67,6 +67,7 @@ KCM.SimpleKCM { } QQC.ComboBox { + id: colorComboBox Kirigami.FormData.label: i18nc("@label", "Mode:") currentIndex: kcm.settings.mode textRole: "text" @@ -79,5 +80,15 @@ KCM.SimpleKCM { onActivated: kcm.settings.mode = currentValue } + + QQC.Slider { + Kirigami.FormData.label: i18nc("@label", "Intensity:") + Layout.preferredWidth: colorComboBox.implicitWidth + from: 0.0 + to: 1.0 + value: kcm.settings.intensity + + onMoved: kcm.settings.intensity = value + } } }