KWin
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
decorationoptions.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6#include "decorationoptions.h"
7#include <KConfigGroup>
8#include <KDecoration2/DecoratedClient>
9#include <KDecoration2/DecorationSettings>
10#include <KSharedConfig>
11#include <QGuiApplication>
12#include <QStyleHints>
13
14namespace KWin
15{
16
17ColorSettings::ColorSettings(const QPalette &pal)
18{
19 init(pal);
20}
21
22void ColorSettings::update(const QPalette &pal)
23{
24 init(pal);
25}
26
27void ColorSettings::init(const QPalette &pal)
28{
29 m_palette = pal;
30 KConfigGroup wmConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("WM"));
31 m_activeFrameColor = wmConfig.readEntry("frame", pal.color(QPalette::Active, QPalette::Window));
32 m_inactiveFrameColor = wmConfig.readEntry("inactiveFrame", m_activeFrameColor);
33 m_activeTitleBarColor = wmConfig.readEntry("activeBackground", pal.color(QPalette::Active, QPalette::Highlight));
34 m_inactiveTitleBarColor = wmConfig.readEntry("inactiveBackground", m_inactiveFrameColor);
35 m_activeTitleBarBlendColor = wmConfig.readEntry("activeBlend", m_activeTitleBarColor.darker(110));
36 m_inactiveTitleBarBlendColor = wmConfig.readEntry("inactiveBlend", m_inactiveTitleBarColor.darker(110));
37 m_activeFontColor = wmConfig.readEntry("activeForeground", pal.color(QPalette::Active, QPalette::HighlightedText));
38 m_inactiveFontColor = wmConfig.readEntry("inactiveForeground", m_activeFontColor.darker());
39 m_activeButtonColor = wmConfig.readEntry("activeTitleBtnBg", m_activeFrameColor.lighter(130));
40 m_inactiveButtonColor = wmConfig.readEntry("inactiveTitleBtnBg", m_inactiveFrameColor.lighter(130));
41 m_activeHandle = wmConfig.readEntry("handle", m_activeFrameColor);
42 m_inactiveHandle = wmConfig.readEntry("inactiveHandle", m_activeHandle);
43}
44
46 : QObject(parent)
47 , m_active(true)
48 , m_decoration(nullptr)
49 , m_colors(ColorSettings(QPalette()))
50{
51 connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::slotActiveChanged);
55}
56
60
62{
63 return m_active ? m_colors.activeFrame() : m_colors.inactiveFrame();
64}
65
67{
68 return m_active ? m_colors.activeButtonColor() : m_colors.inactiveButtonColor();
69}
70
72{
73 return m_active ? m_colors.activeFont() : m_colors.inactiveFont();
74}
75
77{
78 return m_active ? m_colors.activeHandle() : m_colors.inactiveHandle();
79}
80
82{
83 return m_active ? m_colors.activeTitleBarBlendColor() : m_colors.inactiveTitleBarBlendColor();
84}
85
87{
88 return m_active ? m_colors.activeTitleBarColor() : m_colors.inactiveTitleBarColor();
89}
90
92{
93 return m_decoration ? m_decoration->settings()->font() : QFont();
94}
95
96static int decorationButton(KDecoration2::DecorationButtonType type)
97{
98 switch (type) {
99 case KDecoration2::DecorationButtonType::Menu:
101 case KDecoration2::DecorationButtonType::ApplicationMenu:
103 case KDecoration2::DecorationButtonType::OnAllDesktops:
105 case KDecoration2::DecorationButtonType::Minimize:
107 case KDecoration2::DecorationButtonType::Maximize:
109 case KDecoration2::DecorationButtonType::Close:
111 case KDecoration2::DecorationButtonType::ContextHelp:
113 case KDecoration2::DecorationButtonType::Shade:
115 case KDecoration2::DecorationButtonType::KeepBelow:
117 case KDecoration2::DecorationButtonType::KeepAbove:
119 default:
121 }
122}
123
125{
126 QList<int> ret;
127 if (m_decoration) {
128 for (auto it : m_decoration->settings()->decorationButtonsLeft()) {
129 ret << decorationButton(it);
130 }
131 }
132 return ret;
133}
134
136{
137 QList<int> ret;
138 if (m_decoration) {
139 for (auto it : m_decoration->settings()->decorationButtonsRight()) {
140 ret << decorationButton(it);
141 }
142 }
143 return ret;
144}
145
146KDecoration2::Decoration *DecorationOptions::decoration() const
147{
148 return m_decoration;
149}
150
151void DecorationOptions::setDecoration(KDecoration2::Decoration *decoration)
152{
153 if (m_decoration == decoration) {
154 return;
155 }
156 if (m_decoration) {
157 // disconnect from existing decoration
158 disconnect(m_decoration->client(), &KDecoration2::DecoratedClient::activeChanged, this, &DecorationOptions::slotActiveChanged);
159 auto s = m_decoration->settings();
160 disconnect(s.get(), &KDecoration2::DecorationSettings::fontChanged, this, &DecorationOptions::fontChanged);
161 disconnect(s.get(), &KDecoration2::DecorationSettings::decorationButtonsLeftChanged, this, &DecorationOptions::titleButtonsChanged);
162 disconnect(s.get(), &KDecoration2::DecorationSettings::decorationButtonsRightChanged, this, &DecorationOptions::titleButtonsChanged);
163 disconnect(m_paletteConnection);
164 }
165 m_decoration = decoration;
166 connect(m_decoration->client(), &KDecoration2::DecoratedClient::activeChanged, this, &DecorationOptions::slotActiveChanged);
167 m_paletteConnection = connect(m_decoration->client(), &KDecoration2::DecoratedClient::paletteChanged, this, [this](const QPalette &pal) {
168 m_colors.update(pal);
169 Q_EMIT colorsChanged();
170 });
171 auto s = m_decoration->settings();
172 connect(s.get(), &KDecoration2::DecorationSettings::fontChanged, this, &DecorationOptions::fontChanged);
173 connect(s.get(), &KDecoration2::DecorationSettings::decorationButtonsLeftChanged, this, &DecorationOptions::titleButtonsChanged);
174 connect(s.get(), &KDecoration2::DecorationSettings::decorationButtonsRightChanged, this, &DecorationOptions::titleButtonsChanged);
175 Q_EMIT decorationChanged();
176}
177
178void DecorationOptions::slotActiveChanged()
179{
180 if (!m_decoration) {
181 return;
182 }
183 if (m_active == m_decoration->client()->isActive()) {
184 return;
185 }
186 m_active = m_decoration->client()->isActive();
187 Q_EMIT colorsChanged();
188 Q_EMIT fontChanged();
189}
190
192{
193 return QGuiApplication::styleHints()->mousePressAndHoldInterval();
194}
195
196Borders::Borders(QObject *parent)
197 : QObject(parent)
198 , m_left(0)
199 , m_right(0)
200 , m_top(0)
201 , m_bottom(0)
202{
203}
204
208
209void Borders::setLeft(int left)
210{
211 if (m_left != left) {
212 m_left = left;
213 Q_EMIT leftChanged();
214 }
215}
216void Borders::setRight(int right)
217{
218 if (m_right != right) {
219 m_right = right;
220 Q_EMIT rightChanged();
221 }
222}
223void Borders::setTop(int top)
224{
225 if (m_top != top) {
226 m_top = top;
227 Q_EMIT topChanged();
228 }
229}
230void Borders::setBottom(int bottom)
231{
232 if (m_bottom != bottom) {
233 m_bottom = bottom;
234 Q_EMIT bottomChanged();
235 }
236}
237
239{
240 setBorders(border);
241 setTitle(border);
242}
243
244void Borders::setBorders(int border)
245{
246 setSideBorders(border);
247 setBottom(border);
248}
249
251{
252 setLeft(border);
253 setRight(border);
254}
255
256void Borders::setTitle(int value)
257{
258 setTop(value);
259}
260
261Borders::operator QMargins() const
262{
263 return QMargins(m_left, m_top, m_right, m_bottom);
264}
265
266} // namespace
267
268#include "moc_decorationoptions.cpp"
void setBorders(int value)
void setRight(int right)
void rightChanged()
void setBottom(int bottom)
void setLeft(int left)
void topChanged()
void leftChanged()
void setTop(int top)
void bottomChanged()
Borders(QObject *parent=nullptr)
void setSideBorders(int value)
void setTitle(int value)
void setAllBorders(int value)
const QColor & activeButtonColor() const
const QColor & activeTitleBarBlendColor() const
const QColor & activeFrame() const
const QColor & inactiveTitleBarBlendColor() const
const QColor & inactiveFrame() const
const QColor & inactiveTitleBarColor() const
const QColor & activeTitleBarColor() const
const QColor & inactiveHandle() const
const QColor & activeHandle() const
const QColor & activeFont() const
void update(const QPalette &pal)
const QColor & inactiveButtonColor() const
ColorSettings(const QPalette &pal)
const QColor & inactiveFont() const
KDecoration2::Decoration * decoration() const
void setDecoration(KDecoration2::Decoration *decoration)
DecorationOptions(QObject *parent=nullptr)
Session::Type type
Definition session.cpp:17