KWin
Loading...
Searching...
No Matches
layershellv1window.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
8#include "core/output.h"
10#include "screenedge.h"
12#include "wayland/output.h"
14#include "wayland/surface.h"
15#include "wayland_server.h"
16#include "workspace.h"
17
18namespace KWin
19{
20
21static NET::WindowType scopeToType(const QString &scope)
22{
23 static const QHash<QString, NET::WindowType> scopeToType{
24 {QStringLiteral("desktop"), NET::Desktop},
25 {QStringLiteral("dock"), NET::Dock},
26 {QStringLiteral("crititical-notification"), NET::CriticalNotification},
27 {QStringLiteral("notification"), NET::Notification},
28 {QStringLiteral("tooltip"), NET::Tooltip},
29 {QStringLiteral("on-screen-display"), NET::OnScreenDisplay},
30 {QStringLiteral("dialog"), NET::Dialog},
31 {QStringLiteral("splash"), NET::Splash},
32 {QStringLiteral("utility"), NET::Utility},
33 };
34 return scopeToType.value(scope.toLower(), NET::Normal);
35}
36
38 Output *output,
39 LayerShellV1Integration *integration)
40 : WaylandWindow(shellSurface->surface())
41 , m_desiredOutput(output)
42 , m_integration(integration)
43 , m_shellSurface(shellSurface)
44 , m_windowType(scopeToType(shellSurface->scope()))
45{
47 setSkipPager(true);
48 setSkipTaskbar(true);
49
54
56 this, &LayerShellV1Window::scheduleRearrange);
58 this, &LayerShellV1Window::handleOutputEnabledChanged);
59
61 this, &LayerShellV1Window::handleSizeChanged);
63 this, &LayerShellV1Window::handleUnmapped);
65 this, &LayerShellV1Window::handleCommitted);
66
68 this, &LayerShellV1Window::scheduleRearrange);
70 this, &LayerShellV1Window::scheduleRearrange);
72 this, &LayerShellV1Window::scheduleRearrange);
74 this, &LayerShellV1Window::scheduleRearrange);
76 this, &LayerShellV1Window::scheduleRearrange);
78 this, &LayerShellV1Window::handleAcceptsFocusChanged);
79}
80
82{
83 return m_shellSurface;
84}
85
87{
88 return m_desiredOutput;
89}
90
91void LayerShellV1Window::scheduleRearrange()
92{
93 m_integration->scheduleRearrange();
94}
95
96NET::WindowType LayerShellV1Window::windowType() const
97{
98 return m_windowType;
99}
100
102{
103 return false;
104}
105
107{
108 return true;
109}
110
112{
113 return false;
114}
115
117{
118 return false;
119}
120
122{
123 return false;
124}
125
127{
128 if (acceptsFocus()) {
129 setActive(true);
130 }
131 return true;
132}
133
135{
136 return acceptsFocus() && readyForPainting();
137}
138
140{
141 return wantsInput();
142}
143
145{
146 switch (area) {
147 case StrutAreaLeft:
148 if (m_shellSurface->exclusiveEdge() == Qt::LeftEdge) {
149 return StrutRect(x(), y(), m_shellSurface->exclusiveZone(), height(), StrutAreaLeft);
150 }
151 return StrutRect();
152 case StrutAreaRight:
153 if (m_shellSurface->exclusiveEdge() == Qt::RightEdge) {
154 return StrutRect(x() + width() - m_shellSurface->exclusiveZone(), y(),
155 m_shellSurface->exclusiveZone(), height(), StrutAreaRight);
156 }
157 return StrutRect();
158 case StrutAreaTop:
159 if (m_shellSurface->exclusiveEdge() == Qt::TopEdge) {
160 return StrutRect(x(), y(), width(), m_shellSurface->exclusiveZone(), StrutAreaTop);
161 }
162 return StrutRect();
163 case StrutAreaBottom:
164 if (m_shellSurface->exclusiveEdge() == Qt::BottomEdge) {
165 return StrutRect(x(), y() + height() - m_shellSurface->exclusiveZone(),
166 width(), m_shellSurface->exclusiveZone(), StrutAreaBottom);
167 }
168 return StrutRect();
169 default:
170 return StrutRect();
171 }
172}
173
175{
176 return m_shellSurface->exclusiveZone() > 0;
177}
178
180{
181 if (m_screenEdge) {
182 m_screenEdge->disconnect(this);
183 }
184 m_shellSurface->disconnect(this);
185 m_shellSurface->surface()->disconnect(this);
186 m_desiredOutput->disconnect(this);
187
189 cleanTabBox();
190 Q_EMIT closed();
194 scheduleRearrange();
195 unref();
196}
197
199{
200 m_shellSurface->sendClosed();
201}
202
204{
205 switch (m_shellSurface->layer()) {
207 return DesktopLayer;
209 return BelowLayer;
211 return AboveLayer;
213 return OverlayLayer;
214 default:
215 Q_UNREACHABLE();
216 }
217}
218
220{
221 return !isDeleted() && m_shellSurface->acceptsFocus();
222}
223
225{
228 return;
229 }
230
231 const QSizeF requestedClientSize = frameSizeToClientSize(rect.size());
232 if (requestedClientSize != clientSize()) {
233 m_shellSurface->sendConfigure(rect.size().toSize());
234 } else {
236 return;
237 }
238
239 // The surface position is updated synchronously.
240 QRectF updateRect = m_frameGeometry;
241 updateRect.moveTopLeft(rect.topLeft());
242 updateGeometry(updateRect);
243}
244
245void LayerShellV1Window::handleSizeChanged()
246{
248 scheduleRearrange();
249}
250
251void LayerShellV1Window::handleUnmapped()
252{
253 m_integration->recreateWindow(shellSurface());
254}
255
256void LayerShellV1Window::handleCommitted()
257{
258 if (surface()->buffer()) {
259 markAsMapped();
260 }
261}
262
263void LayerShellV1Window::handleAcceptsFocusChanged()
264{
265 switch (m_shellSurface->layer()) {
268 if (wantsInput()) {
269 workspace()->activateWindow(this);
270 }
271 break;
274 break;
275 }
276}
277
278void LayerShellV1Window::handleOutputEnabledChanged()
279{
280 if (!m_desiredOutput->isEnabled()) {
281 closeWindow();
283 }
284}
285
287{
288 if (m_virtualKeyboardGeometry == geo) {
289 return;
290 }
291
293 scheduleRearrange();
294}
295
297{
298 // ShowOnScreenEdge can be called by an Edge, and setHidden could destroy the Edge
299 // Use the singleshot to avoid use-after-free
300 QTimer::singleShot(0, this, &LayerShellV1Window::deactivateScreenEdge);
301}
302
304{
305 m_screenEdge = edge;
306
307 connect(edge, &AutoHideScreenEdgeV1Interface::destroyed,
308 this, &LayerShellV1Window::deactivateScreenEdge);
310 this, &LayerShellV1Window::activateScreenEdge);
312 this, &LayerShellV1Window::deactivateScreenEdge);
313
314 connect(this, &LayerShellV1Window::frameGeometryChanged, edge, [this]() {
315 if (m_screenEdgeActive) {
316 reserveScreenEdge();
317 }
318 });
319}
320
321void LayerShellV1Window::reserveScreenEdge()
322{
323 if (workspace()->screenEdges()->reserve(this, m_screenEdge->border())) {
324 setHidden(true);
325 } else {
326 setHidden(false);
327 }
328}
329
330void LayerShellV1Window::unreserveScreenEdge()
331{
332 setHidden(false);
334}
335
336void LayerShellV1Window::activateScreenEdge()
337{
338 m_screenEdgeActive = true;
339 reserveScreenEdge();
340}
341
342void LayerShellV1Window::deactivateScreenEdge()
343{
344 m_screenEdgeActive = false;
345 unreserveScreenEdge();
346}
347
348} // namespace KWin
349
350#include "moc_layershellv1window.cpp"
void recreateWindow(LayerSurfaceV1Interface *shellSurface)
bool acceptsFocus() const override
bool wantsInput() const override
void installAutoHideScreenEdgeV1(AutoHideScreenEdgeV1Interface *edge)
LayerShellV1Window(LayerSurfaceV1Interface *shellSurface, Output *output, LayerShellV1Integration *integration)
bool dockWantsInput() const override
bool isPlaceable() const override
void setVirtualKeyboardGeometry(const QRectF &geo) override
bool isCloseable() const override
LayerSurfaceV1Interface * shellSurface() const
StrutRect strutRect(StrutArea area) const override
bool isResizable() const override
Layer belongsToLayer() const override
void moveResizeInternal(const QRectF &rect, MoveResizeMode mode) override
bool isMovableAcrossScreens() const override
bool isMovable() const override
NET::WindowType windowType() const override
bool hasStrut() const override
SurfaceInterface * surface() const
quint32 sendConfigure(const QSize &size)
void enabledChanged()
void geometryChanged()
bool isEnabled() const
Definition output.cpp:536
void reserve(ElectricBorder border, QObject *object, const char *callback)
void removeWindow(Window *c)
void updateGeometry(const QRectF &rect)
virtual QSizeF clientSizeToFrameSize(const QSizeF &size) const
Definition window.cpp:3265
QPointF pos
Definition window.h:79
qreal width
Definition window.h:99
QSizeF size
Definition window.h:84
SurfaceInterface * surface() const
Definition window.cpp:342
void setSkipTaskbar(bool set)
Definition window.cpp:464
bool readyForPainting() const
Definition window.h:1917
void unref()
Definition window.cpp:118
QRectF m_frameGeometry
Definition window.h:1725
void setActive(bool)
Definition window.cpp:499
QSizeF clientSize() const
Definition window.h:1872
void setHidden(bool hidden)
Definition window.cpp:4242
qreal y
Definition window.h:94
bool isDesktop() const
Definition window.h:1922
qreal x
Definition window.h:89
void cleanTabBox()
Definition window.cpp:4054
QRectF m_virtualKeyboardGeometry
Definition window.h:1798
QRectF rect
Definition window.h:113
qreal height
Definition window.h:104
void setSkipPager(bool set)
Definition window.cpp:448
void frameGeometryChanged(const QRectF &oldGeometry)
bool areGeometryUpdatesBlocked() const
Definition window.h:2093
void setPendingMoveResizeMode(MoveResizeMode mode)
Definition window.h:2113
KWin::Output * output
Definition window.h:111
virtual QSizeF frameSizeToClientSize(const QSizeF &size) const
Definition window.cpp:3258
void setSkipSwitcher(bool set)
Definition window.cpp:436
bool isDeleted() const
Definition window.cpp:540
void markAsDeleted()
Definition window.cpp:545
ScreenEdges * screenEdges() const
void activateWindow(Window *window, bool force=false)
StrutArea
Definition common.h:35
@ StrutAreaRight
Definition common.h:38
@ StrutAreaBottom
Definition common.h:39
@ StrutAreaTop
Definition common.h:37
@ StrutAreaLeft
Definition common.h:40
@ ElectricNone
Definition globals.h:70
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830
Layer
Definition globals.h:162
@ BelowLayer
Definition globals.h:166
@ DesktopLayer
Definition globals.h:165
@ AboveLayer
Definition globals.h:168
@ OverlayLayer
Definition globals.h:174