From 3876c89cc1fc3743bedfe2fdfa780f5e46d07928 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Wed, 16 Mar 2022 20:29:03 +0100 Subject: [PATCH] Avoid recreating palette in DecorationPalette::palette KColorScheme::createApplicationPalette is quite expensive and DecorationPalette::palette is called quite a lot Cache the result and only update when needed --- src/decorations/decorationpalette.cpp | 4 +++- src/decorations/decorationpalette.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/decorations/decorationpalette.cpp b/src/decorations/decorationpalette.cpp index 1162691138..a365b1513e 100644 --- a/src/decorations/decorationpalette.cpp +++ b/src/decorations/decorationpalette.cpp @@ -121,13 +121,15 @@ QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::Co QPalette DecorationPalette::palette() const { - return m_legacyPalette ? m_legacyPalette->palette : KColorScheme::createApplicationPalette(m_colorSchemeConfig); + return m_legacyPalette ? m_legacyPalette->palette : m_applicationPalette; } void DecorationPalette::update() { m_colorSchemeConfig->sync(); + m_applicationPalette = KColorScheme::createApplicationPalette(m_colorSchemeConfig); + if (KColorScheme::isColorSetSupported(m_colorSchemeConfig, KColorScheme::Header)) { m_palette.active = KColorScheme(QPalette::Normal, KColorScheme::Header, m_colorSchemeConfig); m_palette.inactive = KColorScheme(QPalette::Inactive, KColorScheme::Header, m_colorSchemeConfig); diff --git a/src/decorations/decorationpalette.h b/src/decorations/decorationpalette.h index 8529c8fe42..a0737cda92 100644 --- a/src/decorations/decorationpalette.h +++ b/src/decorations/decorationpalette.h @@ -68,6 +68,7 @@ private: KSharedConfig::Ptr m_colorSchemeConfig; ModernPalette m_palette; + QPalette m_applicationPalette; }; }