// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL #include "ColorSchemeSelector.h" #include "AppPalette.h" #include "koutnet_app_debug.h" #include #include namespace { ColorSchemeSelector *s_instance = nullptr; // Ids, not translated names: matching a name would stop working // the moment the desktop is not in English. QString lightSchemeId() { return QStringLiteral("BreezeLight"); } QString darkSchemeId() { return QStringLiteral("BreezeDark"); } } // namespace ColorSchemeSelector *ColorSchemeSelector::instance() { if (!s_instance) s_instance = new ColorSchemeSelector; return s_instance; } ColorSchemeSelector::ColorSchemeSelector(QObject *parent) : QObject(parent) { const QString active = KColorSchemeManager::instance()->activeSchemeId(); if (active == darkSchemeId()) m_mode = Dark; else if (active == lightSchemeId()) m_mode = Light; // The desktop manager is only used for side effects now (Kirigami reads // the active scheme); the colours themselves come from AppPalette so they // are the same with and without an installed KDE desktop. koutnet::AppPalette::instance()->setMode(static_cast(m_mode)); } void ColorSchemeSelector::setMode(Mode mode) { if (m_mode == mode) return; m_mode = mode; auto *manager = KColorSchemeManager::instance(); const QString id = schemeIdFor(mode); const QModelIndex index = manager->indexForSchemeId(id); if (!id.isEmpty() && !index.isValid()) qCWarning(KOUTNET_LOG_APP) << "colour scheme is not installed, falling back to the system one:" << id; manager->activateScheme(index); koutnet::AppPalette::instance()->setMode(static_cast(mode)); Q_EMIT modeChanged(); } QString ColorSchemeSelector::schemeIdFor(Mode mode) { switch (mode) { case Light: return lightSchemeId(); case Dark: return darkSchemeId(); case FollowSystem: break; } return QString(); }