KDecoration3

decoratedwindow.h
1/*
2 * SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6#pragma once
7
8#include "decoration.h"
9#include "decorationdefines.h"
10#include <kdecoration3/kdecoration3_export.h>
11
12#include <QFont>
13#include <QIcon>
14#include <QObject>
15#include <QPalette>
16#include <QPointer>
17#include <QtGui/qwindowdefs.h>
18
19#include <memory>
20
21namespace KDecoration3
22{
23class DecorationBridge;
24class DecoratedWindowPrivate;
25
26/**
27 * @brief The Client which gets decorated.
28 *
29 * The DecoratedWindow provides access to all the properties relevant for decorating the Client.
30 * Each DecoratedWindow is bound to one Decoration and each Decoration is bound to this one
31 * DecoratedWindow.
32 *
33 * The DecoratedWindow only exports properties, it does not provide any means to change the state.
34 * To change state one needs to call the methods on Decoration. This is as the backend might
35 * disallow state changes. Therefore any changes should be bound to the change signals of the
36 * DecoratedWindow and not be bound to state changes of input elements (such as a button).
37 */
38class KDECORATIONS3_EXPORT DecoratedWindow : public QObject
39{
41 /**
42 * The Decoration of this DecoratedWindow
43 **/
45 /**
46 * Whether the DecoratedWindow is active (has focus) or is inactive.
47 **/
48 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
49 /**
50 * The caption of the DecoratedWindow.
51 **/
52 Q_PROPERTY(QString caption READ caption NOTIFY captionChanged)
53 /**
54 * Whether the DecoratedWindow is on all desktops or on just one.
55 **/
56 Q_PROPERTY(bool onAllDesktops READ isOnAllDesktops NOTIFY onAllDesktopsChanged)
57 /**
58 * Whether the DecoratedWindow is shaded. Shaded means that the actual content is
59 * not visible, only the Decoration is visible.
60 **/
61 Q_PROPERTY(bool shaded READ isShaded NOTIFY shadedChanged)
62 /**
63 * The icon of the DecoratedWindow. This can be used as the icon for the window menu button.
64 **/
65 Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
66 /**
67 * Whether the DecoratedWindow is maximized. A DecoratedWindow is maximized if it is both
68 * maximizedHorizontally and maximizedVertically. The Decoration of a maximized DecoratedWindow
69 * should only consist of the title bar area.
70 **/
71 Q_PROPERTY(bool maximized READ isMaximized NOTIFY maximizedChanged)
72 /**
73 * Whether the DecoratedWindow is maximized horizontally. A horizontally maximized DecoratedWindow
74 * uses the maximal possible width.
75 **/
76 Q_PROPERTY(bool maximizedHorizontally READ isMaximizedHorizontally NOTIFY maximizedHorizontallyChanged)
77 /**
78 * Whether the DecoratedWindow is maximized vertically. A vertically maximized DecoratedWindow
79 * uses the maximal possible height.
80 **/
81 Q_PROPERTY(bool maximizedVertically READ isMaximizedVertically NOTIFY maximizedVerticallyChanged)
82 /**
83 * Whether the DecoratedWindow is set to be kept above other DecoratedWindows. There can be multiple
84 * DecoratedWindows which are set to be kept above.
85 **/
86 Q_PROPERTY(bool keepAbove READ isKeepAbove NOTIFY keepAboveChanged)
87 /**
88 * Whether the DecoratedWindow is set to be kept below other DecoratedWindows. There can be multiple
89 * DecoratedWindows which are set to be kept below.
90 **/
91 Q_PROPERTY(bool keepBelow READ isKeepBelow NOTIFY keepBelowChanged)
92
93 /**
94 * Whether the DecoratedWindow can be closed. If this property is @c false a DecorationButton
95 * for closing the DecoratedWindow should be disabled.
96 **/
97 Q_PROPERTY(bool closeable READ isCloseable NOTIFY closeableChanged)
98 /**
99 * Whether the DecoratedWindow can be maximized. If this property is @c false a DecorationButton
100 * for maximizing the DecoratedWindow should be disabled.
101 **/
102 Q_PROPERTY(bool maximizeable READ isMaximizeable NOTIFY maximizeableChanged)
103 /**
104 * Whether the DecoratedWindow can be minimized. If this property is @c false a DecorationButton
105 * for minimizing the DecoratedWindow should be disabled.
106 **/
107 Q_PROPERTY(bool minimizeable READ isMinimizeable NOTIFY minimizeableChanged)
108 /**
109 * Whether the DecoratedWindow provides context help.
110 * The Decoration should only show a context help button if this property is @c true.
111 **/
112 Q_PROPERTY(bool providesContextHelp READ providesContextHelp NOTIFY providesContextHelpChanged)
113 /**
114 * Whether the DecoratedWindow is a modal dialog.
115 **/
116 Q_PROPERTY(bool modal READ isModal CONSTANT)
117 /**
118 * Whether the DecoratedWindow can be shaded. If this property is @c false a DecorationButton
119 * for shading the DecoratedWindow should be disabled.
120 **/
121 Q_PROPERTY(bool shadeable READ isShadeable NOTIFY shadeableChanged)
122 /**
123 * Whether the DecoratedWindow can be moved.
124 **/
125 Q_PROPERTY(bool moveable READ isMoveable NOTIFY moveableChanged)
126 /**
127 * Whether the DecoratedWindow can be resized.
128 **/
129 Q_PROPERTY(bool resizeable READ isResizeable NOTIFY resizeableChanged)
130
131 /**
132 * The width of the DecoratedWindow.
133 **/
134 Q_PROPERTY(qreal width READ width NOTIFY widthChanged)
135 /**
136 * The height of the DecoratedWindow.
137 **/
138 Q_PROPERTY(qreal height READ height NOTIFY heightChanged)
139 /**
140 * The size of the DecoratedWindow.
141 **/
142 Q_PROPERTY(QSizeF size READ size NOTIFY sizeChanged)
143 /**
144 * The palette this DecoratedWindow uses. The palette might be different for each
145 * DecoratedWindow and the Decoration should honor the palette.
146 **/
147 Q_PROPERTY(QPalette palette READ palette NOTIFY paletteChanged)
148 /**
149 * The Edges which are adjacent to a screen edge. E.g. for a maximized DecoratedWindow this
150 * will include all Edges. The Decoration can use this information to hide borders.
151 **/
152 Q_PROPERTY(Qt::Edges adjacentScreenEdges READ adjacentScreenEdges NOTIFY adjacentScreenEdgesChanged)
153 /**
154 * Whether the DecoratedWindow has an application menu
155 * @since 5.9
156 */
157 Q_PROPERTY(bool hasApplicationMenu READ hasApplicationMenu NOTIFY hasApplicationMenuChanged)
158 /**
159 * Whether the application menu for this DecoratedWindow is currently shown to the user
160 * The Decoration can use this information to highlight the respective button.
161 * @since 5.9
162 */
163 Q_PROPERTY(bool applicationMenuActive READ isApplicationMenuActive NOTIFY applicationMenuActiveChanged)
164
165 /**
166 * The current scale this decorated window is targeting.
167 * @since 6.3
168 */
169 Q_PROPERTY(qreal scale READ scale NOTIFY scaleChanged);
170
171 /**
172 * The next scale this decorated window is going to target.
173 * @since 6.3
174 */
175 Q_PROPERTY(qreal nextScale READ nextScale NOTIFY nextScaleChanged)
176
177public:
178 DecoratedWindow() = delete;
179 ~DecoratedWindow() override;
180 bool isActive() const;
181 QString caption() const;
182 bool isOnAllDesktops() const;
183 bool isShaded() const;
184 QIcon icon() const;
185 bool isMaximized() const;
186 bool isMaximizedHorizontally() const;
187 bool isMaximizedVertically() const;
188 bool isKeepAbove() const;
189 bool isKeepBelow() const;
190
191 bool isCloseable() const;
192 bool isMaximizeable() const;
193 bool isMinimizeable() const;
194 bool providesContextHelp() const;
195 bool isModal() const;
196 bool isShadeable() const;
197 bool isMoveable() const;
198 bool isResizeable() const;
199
200 Qt::Edges adjacentScreenEdges() const;
201
202 QString windowClass() const;
203
204 qreal width() const;
205 qreal height() const;
206 QSizeF size() const;
207
208 Decoration *decoration() const;
209 QPalette palette() const;
210 /**
211 * Used to get colors in QPalette.
212 * @param group The color group
213 * @param role The color role
214 * @return palette().color(group, role)
215 * @since 5.3
216 **/
217 QColor color(QPalette::ColorGroup group, QPalette::ColorRole role) const;
218 /**
219 * Used to get additional colors that are not in QPalette.
220 * @param group The color group
221 * @param role The color role
222 * @return The color if provided for combination of group and role, otherwise invalid QColor.
223 * @since 5.3
224 **/
225 QColor color(ColorGroup group, ColorRole role) const;
226
227 /**
228 * Whether the DecoratedWindow has an application menu
229 * @since 5.9
230 */
231 bool hasApplicationMenu() const;
232 /**
233 * Whether the application menu for this DecoratedWindow is currently shown to the user
234 * The Decoration can use this information to highlight the respective button.
235 * @since 5.9
236 */
237 bool isApplicationMenuActive() const;
238
239 /**
240 * Request the application menu to be shown to the user
241 * @param actionId The DBus menu ID of the action that should be highlighted, 0 for none.
242 */
243 void showApplicationMenu(int actionId);
244
245 /**
246 * Returns the current scale this decorated window is targeting
247 * @since 6.3
248 */
249 qreal scale() const;
250 /**
251 * Returns the next scale this decorated window is going to target.
252 */
253 qreal nextScale() const;
254
256 void activeChanged(bool);
257 void captionChanged(QString);
258 void onAllDesktopsChanged(bool);
259 void shadedChanged(bool);
260 void iconChanged(QIcon);
261 void maximizedChanged(bool);
262 void maximizedHorizontallyChanged(bool);
263 void maximizedVerticallyChanged(bool);
264 void keepAboveChanged(bool);
265 void keepBelowChanged(bool);
266
267 void closeableChanged(bool);
268 void maximizeableChanged(bool);
269 void minimizeableChanged(bool);
270 void providesContextHelpChanged(bool);
271 void shadeableChanged(bool);
272 void moveableChanged(bool);
273 void resizeableChanged(bool);
274
275 void widthChanged(qreal);
276 void heightChanged(qreal);
277 void sizeChanged(const QSizeF &size);
278 void paletteChanged(const QPalette &palette);
279 void adjacentScreenEdgesChanged(Qt::Edges edges);
280
281 void hasApplicationMenuChanged(bool);
282 void applicationMenuActiveChanged(bool);
283 void scaleChanged();
284 void nextScaleChanged();
285
286private:
287 friend class Decoration;
288 DecoratedWindow(Decoration *parent, DecorationBridge *bridge);
289 const std::unique_ptr<DecoratedWindowPrivate> d;
290};
291
292} // namespace
bool onAllDesktops
Whether the DecoratedWindow is on all desktops or on just one.
bool maximizedHorizontally
Whether the DecoratedWindow is maximized horizontally.
bool minimizeable
Whether the DecoratedWindow can be minimized.
bool isApplicationMenuActive() const
Whether the application menu for this DecoratedWindow is currently shown to the user The Decoration c...
bool modal
Whether the DecoratedWindow is a modal dialog.
bool maximizeable
Whether the DecoratedWindow can be maximized.
QIcon icon
The icon of the DecoratedWindow.
bool shaded
Whether the DecoratedWindow is shaded.
bool maximized
Whether the DecoratedWindow is maximized.
bool hasApplicationMenu
Whether the DecoratedWindow has an application menu.
void showApplicationMenu(int actionId)
Request the application menu to be shown to the user.
QColor color(QPalette::ColorGroup group, QPalette::ColorRole role) const
Used to get colors in QPalette.
Qt::Edges adjacentScreenEdges
The Edges which are adjacent to a screen edge.
QString caption
The caption of the DecoratedWindow.
bool applicationMenuActive
Whether the application menu for this DecoratedWindow is currently shown to the user The Decoration c...
qreal nextScale
The next scale this decorated window is going to target.
KDecoration3::Decoration * decoration
The Decoration of this DecoratedWindow.
qreal height
The height of the DecoratedWindow.
QPalette palette
The palette this DecoratedWindow uses.
qreal width
The width of the DecoratedWindow.
bool shadeable
Whether the DecoratedWindow can be shaded.
bool providesContextHelp
Whether the DecoratedWindow provides context help.
bool keepAbove
Whether the DecoratedWindow is set to be kept above other DecoratedWindows.
bool active
Whether the DecoratedWindow is active (has focus) or is inactive.
bool moveable
Whether the DecoratedWindow can be moved.
bool maximizedVertically
Whether the DecoratedWindow is maximized vertically.
qreal scale
The current scale this decorated window is targeting.
bool closeable
Whether the DecoratedWindow can be closed.
QSizeF size
The size of the DecoratedWindow.
bool resizeable
Whether the DecoratedWindow can be resized.
bool keepBelow
Whether the DecoratedWindow is set to be kept below other DecoratedWindows.
Base class for the Decoration.
Definition decoration.h:83
Framework for creating window decorations.
ColorGroup
Color groups are used for DecoratedWindow::color().
ColorRole
Color roles are used for DecoratedWindow::color().
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:56:48 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.