Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
KWin
Commits
fbab964e
Commit
fbab964e
authored
May 27, 2020
by
Jan Blackquill
🌈
Committed by
Jan Blackquill
Sep 28, 2020
Browse files
Use Header color group for decoration colours
parent
02b1e117
Changes
2
Hide whitespace changes
Inline
Side-by-side
decorations/decorationpalette.cpp
View file @
fbab964e
...
...
@@ -5,6 +5,7 @@
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr>
SPDX-FileCopyrightText: 2015 Mika Allan Rauhala <mika.allan.rauhala@gmail.com>
SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
...
...
@@ -26,32 +27,23 @@ namespace Decoration
{
DecorationPalette
::
DecorationPalette
(
const
QString
&
colorScheme
)
:
m_colorScheme
(
QFileInfo
(
colorScheme
).
isAbsolute
()
?
colorScheme
:
QStandardPaths
::
locate
(
QStandardPaths
::
GenericConfigLocation
,
colorScheme
))
:
m_colorScheme
(
colorScheme
!=
QStringLiteral
(
"kdeglobals"
)
?
colorScheme
:
QString
()
)
{
if
(
!
m_colorScheme
.
startsWith
(
QStandardPaths
::
writableLocation
(
QStandardPaths
::
GenericConfigLocation
))
&&
colorScheme
==
QStringLiteral
(
"kdeglobals"
))
{
// kdeglobals doesn't exist so create it. This is needed to monitor it using QFileSystemWatcher.
auto
config
=
KSharedConfig
::
openConfig
(
colorScheme
,
KConfig
::
SimpleConfig
);
KConfigGroup
wmConfig
(
config
,
QStringLiteral
(
"WM"
));
wmConfig
.
writeEntry
(
"FakeEntryToKeepThisGroup"
,
true
);
config
->
sync
();
m_colorScheme
=
QStandardPaths
::
locate
(
QStandardPaths
::
GenericConfigLocation
,
colorScheme
);
if
(
m_colorScheme
.
isEmpty
())
{
m_colorSchemeConfig
=
KSharedConfig
::
openConfig
(
m_colorScheme
,
KConfig
::
FullConfig
);
}
else
{
m_colorSchemeConfig
=
KSharedConfig
::
openConfig
(
m_colorScheme
,
KConfig
::
SimpleConfig
);
}
m_watcher
.
addPath
(
m_colorScheme
);
connect
(
&
m_watcher
,
&
QFileSystemWatcher
::
fileChanged
,
[
this
]()
{
m_watcher
.
addPath
(
m_colorScheme
);
update
();
emit
changed
();
});
m_watcher
=
KConfigWatcher
::
create
(
m_colorSchemeConfig
);
connect
(
m_watcher
.
data
(),
&
KConfigWatcher
::
configChanged
,
this
,
&
DecorationPalette
::
update
);
update
();
}
bool
DecorationPalette
::
isValid
()
const
{
return
m_activeTitleBarColor
.
isValid
()
;
return
true
;
}
QColor
DecorationPalette
::
color
(
KDecoration2
::
ColorGroup
group
,
KDecoration2
::
ColorRole
role
)
const
...
...
@@ -59,33 +51,69 @@ QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::Co
using
KDecoration2
::
ColorRole
;
using
KDecoration2
::
ColorGroup
;
if
(
m_legacyPalette
.
has_value
())
{
switch
(
role
)
{
case
ColorRole
::
Frame
:
switch
(
group
)
{
case
ColorGroup
::
Active
:
return
m_legacyPalette
->
activeFrameColor
;
case
ColorGroup
::
Inactive
:
return
m_legacyPalette
->
inactiveFrameColor
;
default:
return
QColor
();
}
case
ColorRole
::
TitleBar
:
switch
(
group
)
{
case
ColorGroup
::
Active
:
return
m_legacyPalette
->
activeTitleBarColor
;
case
ColorGroup
::
Inactive
:
return
m_legacyPalette
->
inactiveTitleBarColor
;
default:
return
QColor
();
}
case
ColorRole
::
Foreground
:
switch
(
group
)
{
case
ColorGroup
::
Active
:
return
m_legacyPalette
->
activeForegroundColor
;
case
ColorGroup
::
Inactive
:
return
m_legacyPalette
->
inactiveForegroundColor
;
case
ColorGroup
::
Warning
:
return
m_legacyPalette
->
warningForegroundColor
;
default:
return
QColor
();
}
default:
return
QColor
();
}
}
switch
(
role
)
{
case
ColorRole
::
Frame
:
switch
(
group
)
{
case
ColorGroup
::
Active
:
return
m_
activeFrameC
olor
;
return
m_
palette
.
active
.
background
().
c
olor
()
;
case
ColorGroup
::
Inactive
:
return
m_
inactiveFrameC
olor
;
return
m_
palette
.
inactive
.
background
().
c
olor
()
;
default:
return
QColor
();
}
case
ColorRole
::
TitleBar
:
switch
(
group
)
{
case
ColorGroup
::
Active
:
return
m_
activeTitleBarC
olor
;
return
m_
palette
.
active
.
background
().
c
olor
()
;
case
ColorGroup
::
Inactive
:
return
m_
inactiveTitleBarC
olor
;
return
m_
palette
.
inactive
.
background
().
c
olor
()
;
default:
return
QColor
();
}
case
ColorRole
::
Foreground
:
switch
(
group
)
{
case
ColorGroup
::
Active
:
return
m_active
F
oreground
C
olor
;
return
m_
palette
.
active
.
f
oreground
().
c
olor
()
;
case
ColorGroup
::
Inactive
:
return
m_inactive
F
oreground
C
olor
;
return
m_
palette
.
inactive
.
f
oreground
().
c
olor
()
;
case
ColorGroup
::
Warning
:
return
m_
warningForegroundC
olor
;
return
m_
palette
.
inactive
.
foreground
(
KColorScheme
::
ForegroundRole
::
NegativeText
).
c
olor
()
;
default:
return
QColor
();
}
...
...
@@ -96,31 +124,41 @@ QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::Co
QPalette
DecorationPalette
::
palette
()
const
{
return
m_
palette
;
return
m_
legacyPalette
?
m_legacyPalette
->
palette
:
KColorScheme
::
createApplicationPalette
(
m_colorSchemeConfig
)
;
}
void
DecorationPalette
::
update
()
{
auto
config
=
KSharedConfig
::
openConfig
(
m_colorScheme
,
KConfig
::
SimpleConfig
);
KConfigGroup
wmConfig
(
config
,
QStringLiteral
(
"WM"
));
if
(
!
wmConfig
.
exists
()
&&
!
m_colorScheme
.
endsWith
(
QStringLiteral
(
"/kdeglobals"
)))
{
qCWarning
(
KWIN_DECORATIONS
)
<<
"Invalid color scheme"
<<
m_colorScheme
<<
"lacks WM group"
;
return
;
m_colorSchemeConfig
->
sync
();
if
(
!
KColorScheme
::
isColorSetSupported
(
m_colorSchemeConfig
,
KColorScheme
::
Header
))
{
KConfigGroup
wmConfig
(
m_colorSchemeConfig
,
QStringLiteral
(
"WM"
));
if
(
!
wmConfig
.
exists
())
{
m_palette
.
active
=
KColorScheme
(
QPalette
::
Normal
,
KColorScheme
::
Header
,
m_colorSchemeConfig
);
m_palette
.
inactive
=
KColorScheme
(
QPalette
::
Inactive
,
KColorScheme
::
Header
,
m_colorSchemeConfig
);
m_legacyPalette
.
reset
();
return
;
}
m_legacyPalette
=
LegacyPalette
{};
m_legacyPalette
->
palette
=
KColorScheme
::
createApplicationPalette
(
m_colorSchemeConfig
);
m_legacyPalette
->
activeFrameColor
=
wmConfig
.
readEntry
(
"frame"
,
m_legacyPalette
->
palette
.
color
(
QPalette
::
Active
,
QPalette
::
Window
));
m_legacyPalette
->
inactiveFrameColor
=
wmConfig
.
readEntry
(
"inactiveFrame"
,
m_legacyPalette
->
activeFrameColor
);
m_legacyPalette
->
activeTitleBarColor
=
wmConfig
.
readEntry
(
"activeBackground"
,
m_legacyPalette
->
palette
.
color
(
QPalette
::
Active
,
QPalette
::
Highlight
));
m_legacyPalette
->
inactiveTitleBarColor
=
wmConfig
.
readEntry
(
"inactiveBackground"
,
m_legacyPalette
->
inactiveTitleBarColor
);
m_legacyPalette
->
activeForegroundColor
=
wmConfig
.
readEntry
(
"activeForeground"
,
m_legacyPalette
->
palette
.
color
(
QPalette
::
Active
,
QPalette
::
HighlightedText
));
m_legacyPalette
->
inactiveForegroundColor
=
wmConfig
.
readEntry
(
"inactiveForeground"
,
m_legacyPalette
->
activeForegroundColor
.
darker
());
KConfigGroup
windowColorsConfig
(
m_colorSchemeConfig
,
QStringLiteral
(
"Colors:Window"
));
m_legacyPalette
->
warningForegroundColor
=
windowColorsConfig
.
readEntry
(
"ForegroundNegative"
,
QColor
(
237
,
21
,
2
));
}
else
{
m_palette
.
active
=
KColorScheme
(
QPalette
::
Normal
,
KColorScheme
::
Header
,
m_colorSchemeConfig
);
m_palette
.
inactive
=
KColorScheme
(
QPalette
::
Inactive
,
KColorScheme
::
Header
,
m_colorSchemeConfig
);
m_legacyPalette
.
reset
();
}
m_palette
=
KColorScheme
::
createApplicationPalette
(
config
);
m_activeFrameColor
=
wmConfig
.
readEntry
(
"frame"
,
m_palette
.
color
(
QPalette
::
Active
,
QPalette
::
Window
));
m_inactiveFrameColor
=
wmConfig
.
readEntry
(
"inactiveFrame"
,
m_activeFrameColor
);
m_activeTitleBarColor
=
wmConfig
.
readEntry
(
"activeBackground"
,
m_palette
.
color
(
QPalette
::
Active
,
QPalette
::
Highlight
));
m_inactiveTitleBarColor
=
wmConfig
.
readEntry
(
"inactiveBackground"
,
m_inactiveFrameColor
);
m_activeForegroundColor
=
wmConfig
.
readEntry
(
"activeForeground"
,
m_palette
.
color
(
QPalette
::
Active
,
QPalette
::
HighlightedText
));
m_inactiveForegroundColor
=
wmConfig
.
readEntry
(
"inactiveForeground"
,
m_activeForegroundColor
.
darker
());
KConfigGroup
windowColorsConfig
(
config
,
QStringLiteral
(
"Colors:Window"
));
m_warningForegroundColor
=
windowColorsConfig
.
readEntry
(
"ForegroundNegative"
,
QColor
(
237
,
21
,
2
));
Q_EMIT
changed
();
}
}
...
...
decorations/decorationpalette.h
View file @
fbab964e
...
...
@@ -15,6 +15,11 @@
#include
<KDecoration2/DecorationSettings>
#include
<QFileSystemWatcher>
#include
<QPalette>
#include
<KSharedConfig>
#include
<KColorScheme>
#include
<KConfigWatcher>
#include
<optional>
namespace
KWin
{
...
...
@@ -38,19 +43,31 @@ private:
void
update
();
QString
m_colorScheme
;
QFileSystemWatcher
m_watcher
;
KConfigWatcher
::
Ptr
m_watcher
;
struct
LegacyPalette
{
QPalette
palette
;
QColor
activeTitleBarColor
;
QColor
inactiveTitleBarColor
;
QColor
activeFrameColor
;
QColor
inactiveFrameColor
;
QPalette
m_palette
;
QColor
activeForegroundColor
;
QColor
inactiveForegroundColor
;
QColor
warningForegroundColor
;
};
QColor
m_activeTitleBarColor
;
QColor
m_inactiveTitleBarColor
;
struct
ModernPalette
{
KColorScheme
active
;
KColorScheme
inactive
;
};
QColor
m_activeFrameColor
;
QColor
m_inactiveFrameColor
;
std
::
optional
<
LegacyPalette
>
m_legacyPalette
;
KSharedConfig
::
Ptr
m_colorSchemeConfig
;
QColor
m_activeForegroundColor
;
QColor
m_inactiveForegroundColor
;
QColor
m_warningForegroundColor
;
ModernPalette
m_palette
;
};
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment