KWin
Loading...
Searching...
No Matches
decoratedclient.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "decoratedclient.h"
10#include "cursor.h"
11#include "decorationbridge.h"
12#include "decorationpalette.h"
13#include "window.h"
14#include "workspace.h"
15#include "x11window.h"
16
17#include <KDecoration2/DecoratedClient>
18#include <KDecoration2/Decoration>
19
20#include <QDebug>
21#include <QStyle>
22#include <QToolTip>
23
24namespace KWin
25{
26namespace Decoration
27{
28
29DecoratedClientImpl::DecoratedClientImpl(Window *window, KDecoration2::DecoratedClient *decoratedClient, KDecoration2::Decoration *decoration)
30 : QObject()
31 , ApplicationMenuEnabledDecoratedClientPrivate(decoratedClient, decoration)
32 , m_window(window)
33 , m_clientSize(window->clientSize().toSize())
34{
38 });
39 connect(window, &Window::clientGeometryChanged, this, [decoratedClient, this]() {
40 if (m_window->clientSize() == m_clientSize) {
41 return;
42 }
43 const auto oldSize = m_clientSize;
44 m_clientSize = m_window->clientSize().toSize();
45 if (oldSize.width() != m_clientSize.width()) {
46 Q_EMIT decoratedClient->widthChanged(m_clientSize.width());
47 }
48 if (oldSize.height() != m_clientSize.height()) {
49 Q_EMIT decoratedClient->heightChanged(m_clientSize.height());
50 }
51 Q_EMIT decoratedClient->sizeChanged(m_clientSize);
52 });
54 Q_EMIT decoratedClient->onAllDesktopsChanged(window->isOnAllDesktops());
55 });
58 });
59 connect(window, &Window::iconChanged, this, [decoratedClient, window]() {
61 });
63 connect(window, &Window::keepAboveChanged, decoratedClient, &KDecoration2::DecoratedClient::keepAboveChanged);
64 connect(window, &Window::keepBelowChanged, decoratedClient, &KDecoration2::DecoratedClient::keepBelowChanged);
66 Q_EMIT decoratedClient->adjacentScreenEdgesChanged(adjacentScreenEdges());
67 });
68 connect(window, &Window::closeableChanged, decoratedClient, &KDecoration2::DecoratedClient::closeableChanged);
69 connect(window, &Window::shadeableChanged, decoratedClient, &KDecoration2::DecoratedClient::shadeableChanged);
70 connect(window, &Window::minimizeableChanged, decoratedClient, &KDecoration2::DecoratedClient::minimizeableChanged);
71 connect(window, &Window::maximizeableChanged, decoratedClient, &KDecoration2::DecoratedClient::maximizeableChanged);
72
73 connect(window, &Window::paletteChanged, decoratedClient, &KDecoration2::DecoratedClient::paletteChanged);
74
75 connect(window, &Window::hasApplicationMenuChanged, decoratedClient, &KDecoration2::DecoratedClient::hasApplicationMenuChanged);
76 connect(window, &Window::applicationMenuActiveChanged, decoratedClient, &KDecoration2::DecoratedClient::applicationMenuActiveChanged);
77
78 m_toolTipWakeUp.setSingleShot(true);
79 connect(&m_toolTipWakeUp, &QTimer::timeout, this, [this]() {
80 int fallAsleepDelay = QApplication::style()->styleHint(QStyle::SH_ToolTip_FallAsleepDelay);
81 this->m_toolTipFallAsleep.setRemainingTime(fallAsleepDelay);
82
83 QToolTip::showText(Cursors::self()->mouse()->pos().toPoint(), this->m_toolTipText);
84 m_toolTipShowing = true;
85 });
86}
87
89{
90 if (m_toolTipShowing) {
92 }
93}
94
96{
97 Q_EMIT decoratedClient()->shadedChanged(m_window->isShade());
98}
99
100#define DELEGATE(type, name, clientName) \
101 type DecoratedClientImpl::name() const \
102 { \
103 return m_window->clientName(); \
104 }
105
106#define DELEGATE2(type, name) DELEGATE(type, name, name)
107
108DELEGATE2(QString, caption)
109DELEGATE2(bool, isActive)
110DELEGATE2(bool, isCloseable)
111DELEGATE(bool, isMaximizeable, isMaximizable)
112DELEGATE(bool, isMinimizeable, isMinimizable)
113DELEGATE2(bool, isModal)
114DELEGATE(bool, isMoveable, isMovable)
115DELEGATE(bool, isResizeable, isResizable)
116DELEGATE2(bool, isShadeable)
117DELEGATE2(bool, providesContextHelp)
118DELEGATE2(bool, isOnAllDesktops)
119DELEGATE2(QPalette, palette)
120DELEGATE2(QIcon, icon)
121
122#undef DELEGATE2
123#undef DELEGATE
124
125#define DELEGATE(type, name, clientName) \
126 type DecoratedClientImpl::name() const \
127 { \
128 return m_window->clientName(); \
129 }
130
131DELEGATE(bool, isKeepAbove, keepAbove)
132DELEGATE(bool, isKeepBelow, keepBelow)
133DELEGATE(bool, isShaded, isShade)
134
135#undef DELEGATE
136
138{
139 if (X11Window *x11Window = qobject_cast<X11Window *>(m_window)) {
140 return x11Window->window();
141 }
142 return 0;
143}
144
146{
147 if (X11Window *x11Window = qobject_cast<X11Window *>(m_window)) {
148 return x11Window->frameId();
149 }
150 return 0;
151}
152
153#define DELEGATE(name, op) \
154 void DecoratedClientImpl::name() \
155 { \
156 if (m_window->isDeleted()) { \
157 return; \
158 } \
159 Workspace::self()->performWindowOperation(m_window, Options::op); \
160 }
161
162DELEGATE(requestToggleShade, ShadeOp)
163DELEGATE(requestToggleOnAllDesktops, OnAllDesktopsOp)
164DELEGATE(requestToggleKeepAbove, KeepAboveOp)
165DELEGATE(requestToggleKeepBelow, KeepBelowOp)
166
167#undef DELEGATE
168
169#define DELEGATE(name, clientName) \
170 void DecoratedClientImpl::name() \
171 { \
172 if (m_window->isDeleted()) { \
173 return; \
174 } \
175 m_window->clientName(); \
176 }
177
178DELEGATE(requestContextHelp, showContextHelp)
179
180#undef DELEGATE
181
183{
184 m_window->setMinimized(true);
185}
186
188{
189 if (m_window->isDeleted()) {
190 return;
191 }
192 QMetaObject::invokeMethod(m_window, &Window::closeWindow, Qt::QueuedConnection);
193}
194
195QColor DecoratedClientImpl::color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const
196{
197 auto dp = m_window->decorationPalette();
198 if (dp) {
199 return dp->color(group, role);
200 }
201
202 return QColor();
203}
204
206{
207 if (m_window->isDeleted()) {
208 return;
209 }
210 if (!workspace()->decorationBridge()->showToolTips()) {
211 return;
212 }
213
214 m_toolTipText = text;
215
216 int wakeUpDelay = QApplication::style()->styleHint(QStyle::SH_ToolTip_WakeUpDelay);
217 m_toolTipWakeUp.start(m_toolTipFallAsleep.hasExpired() ? wakeUpDelay : 20);
218}
219
221{
222 m_toolTipWakeUp.stop();
223 QToolTip::hideText();
224 m_toolTipShowing = false;
225}
226
228{
229 if (m_window->isDeleted()) {
230 return;
231 }
232 Workspace::self()->showWindowMenu(QRectF(m_window->pos() + rect.topLeft(), m_window->pos() + rect.bottomRight()).toRect(), m_window);
233}
234
235void DecoratedClientImpl::requestShowApplicationMenu(const QRect &rect, int actionId)
236{
237 if (m_window->isDeleted()) {
238 return;
239 }
240 Workspace::self()->showApplicationMenu(rect, m_window, actionId);
241}
242
244{
245 if (m_window->isDeleted()) {
246 return;
247 }
248 decoration()->showApplicationMenu(actionId);
249}
250
252{
253 if (m_window->isDeleted()) {
254 return;
255 }
256 auto operation = options->operationMaxButtonClick(buttons);
257 QMetaObject::invokeMethod(
258 this, [this, operation] {
259 delayedRequestToggleMaximization(operation);
260 },
261 Qt::QueuedConnection);
262}
263
264void DecoratedClientImpl::delayedRequestToggleMaximization(Options::WindowOperation operation)
265{
266 if (m_window->isDeleted()) {
267 return;
268 }
269 Workspace::self()->performWindowOperation(m_window, operation);
270}
271
273{
274 return m_clientSize.width();
275}
276
278{
279 return m_clientSize.height();
280}
281
283{
284 return m_clientSize;
285}
286
291
296
301
303{
304 Qt::Edges edges;
305 const QuickTileMode mode = m_window->quickTileMode();
306 if (mode.testFlag(QuickTileFlag::Left)) {
307 edges |= Qt::LeftEdge;
308 if (!mode.testFlag(QuickTileFlag::Top) && !mode.testFlag(QuickTileFlag::Bottom)) {
309 // using complete side
310 edges |= Qt::TopEdge | Qt::BottomEdge;
311 }
312 }
313 if (mode.testFlag(QuickTileFlag::Top)) {
314 edges |= Qt::TopEdge;
315 }
316 if (mode.testFlag(QuickTileFlag::Right)) {
317 edges |= Qt::RightEdge;
318 if (!mode.testFlag(QuickTileFlag::Top) && !mode.testFlag(QuickTileFlag::Bottom)) {
319 // using complete side
320 edges |= Qt::TopEdge | Qt::BottomEdge;
321 }
322 }
323 if (mode.testFlag(QuickTileFlag::Bottom)) {
324 edges |= Qt::BottomEdge;
325 }
326 return edges;
327}
328
330{
331 return m_window->hasApplicationMenu();
332}
333
335{
336 return m_window->applicationMenuActive();
337}
338
340{
341 return m_window->resourceName() + QLatin1Char(' ') + m_window->resourceClass();
342}
343
344}
345}
346
347#include "moc_decoratedclient.cpp"
static Cursors * self()
Definition cursor.cpp:35
void showApplicationMenu(int actionId) override
QColor color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const override
KDecoration2::DecoratedClient * decoratedClient()
void requestToggleMaximization(Qt::MouseButtons buttons) override
DecoratedClientImpl(Window *window, KDecoration2::DecoratedClient *decoratedClient, KDecoration2::Decoration *decoration)
Qt::Edges adjacentScreenEdges() const override
void requestShowToolTip(const QString &text) override
void requestShowWindowMenu(const QRect &rect) override
void requestShowApplicationMenu(const QRect &rect, int actionId) override
QColor color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const
WindowOperation operationMaxButtonClick(Qt::MouseButtons button) const
Definition options.cpp:1014
void maximizeableChanged(bool)
QPointF pos
Definition window.h:79
void setMinimized(bool set)
Definition window.cpp:984
void iconChanged()
void shadeableChanged(bool)
bool isShade() const
Definition window.h:1034
const Decoration::DecorationPalette * decorationPalette()
Definition window.cpp:1012
void clientGeometryChanged(const QRectF &oldGeometry)
bool applicationMenuActive
Definition window.h:511
bool isOnAllDesktops() const
Definition window.h:2032
void shadeChanged()
QSizeF clientSize() const
Definition window.h:1872
void hasApplicationMenuChanged(bool)
virtual MaximizeMode requestedMaximizeMode() const
Definition window.cpp:3999
QuickTileMode quickTileMode() const
Definition window.h:1096
void keepAboveChanged(bool)
QIcon icon
Definition window.h:327
virtual void closeWindow()=0
void minimizeableChanged(bool)
void applicationMenuActiveChanged(bool)
void desktopsChanged()
QString resourceClass
Definition window.h:115
bool isActive() const
Definition window.h:882
void quickTileModeChanged()
QString resourceName
Definition window.h:114
void paletteChanged(const QPalette &p)
QString caption
Definition window.h:392
void closeableChanged(bool)
void activeChanged()
void keepBelowChanged(bool)
bool hasApplicationMenu
Definition window.h:506
void captionChanged()
void setDecoratedClient(Decoration::DecoratedClientImpl *client)
Definition window.cpp:2816
bool isDeleted() const
Definition window.cpp:540
void showApplicationMenu(const QRect &pos, Window *window, int actionId)
void showWindowMenu(const QRect &pos, Window *cl)
void performWindowOperation(KWin::Window *window, Options::WindowOperation op)
static Workspace * self()
Definition workspace.h:91
#define DELEGATE(type, name, clientName)
#define DELEGATE2(type, name)
@ MaximizeVertical
The window is maximized vertically.
Definition common.h:76
@ MaximizeHorizontal
Definition common.h:77
Workspace * workspace()
Definition workspace.h:830
Options * options
Definition main.cpp:73