2020-08-07 19:01:42 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
#include "layershellv1window.h"
|
2020-08-07 19:01:42 +00:00
|
|
|
#include "deleted.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "layershellv1integration.h"
|
2022-04-14 12:33:28 +00:00
|
|
|
#include "output.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/layershell_v1_interface.h"
|
|
|
|
#include "wayland/output_interface.h"
|
|
|
|
#include "wayland/surface_interface.h"
|
2020-08-07 19:01:42 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
using namespace KWaylandServer;
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static NET::WindowType scopeToType(const QString &scope)
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
static const QHash<QString, NET::WindowType> scopeToType{
|
|
|
|
{QStringLiteral("desktop"), NET::Desktop},
|
|
|
|
{QStringLiteral("dock"), NET::Dock},
|
|
|
|
{QStringLiteral("crititical-notification"), NET::CriticalNotification},
|
|
|
|
{QStringLiteral("notification"), NET::Notification},
|
|
|
|
{QStringLiteral("tooltip"), NET::Tooltip},
|
|
|
|
{QStringLiteral("on-screen-display"), NET::OnScreenDisplay},
|
|
|
|
{QStringLiteral("dialog"), NET::Dialog},
|
|
|
|
{QStringLiteral("splash"), NET::Splash},
|
|
|
|
{QStringLiteral("utility"), NET::Utility},
|
2020-08-07 19:01:42 +00:00
|
|
|
};
|
|
|
|
return scopeToType.value(scope.toLower(), NET::Normal);
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
LayerShellV1Window::LayerShellV1Window(LayerSurfaceV1Interface *shellSurface,
|
2022-04-14 12:33:28 +00:00
|
|
|
Output *output,
|
2020-08-07 19:01:42 +00:00
|
|
|
LayerShellV1Integration *integration)
|
2022-04-22 17:51:07 +00:00
|
|
|
: WaylandWindow(shellSurface->surface())
|
2021-08-25 10:47:44 +00:00
|
|
|
, m_desiredOutput(output)
|
2020-08-07 19:01:42 +00:00
|
|
|
, m_integration(integration)
|
|
|
|
, m_shellSurface(shellSurface)
|
|
|
|
, m_windowType(scopeToType(shellSurface->scope()))
|
|
|
|
{
|
|
|
|
setSkipSwitcher(!isDesktop());
|
|
|
|
setSkipPager(true);
|
|
|
|
setSkipTaskbar(true);
|
|
|
|
|
|
|
|
connect(shellSurface, &LayerSurfaceV1Interface::aboutToBeDestroyed,
|
2022-04-23 08:33:23 +00:00
|
|
|
this, &LayerShellV1Window::destroyWindow);
|
2020-08-07 19:01:42 +00:00
|
|
|
connect(shellSurface->surface(), &SurfaceInterface::aboutToBeDestroyed,
|
2022-04-23 08:33:23 +00:00
|
|
|
this, &LayerShellV1Window::destroyWindow);
|
2020-08-07 19:01:42 +00:00
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::geometryChanged,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::scheduleRearrange);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::enabledChanged,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::handleOutputEnabledChanged);
|
2022-04-14 12:33:28 +00:00
|
|
|
connect(output, &Output::destroyed,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::handleOutputDestroyed);
|
2020-08-07 19:01:42 +00:00
|
|
|
|
|
|
|
connect(shellSurface->surface(), &SurfaceInterface::sizeChanged,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::handleSizeChanged);
|
2020-08-07 19:01:42 +00:00
|
|
|
connect(shellSurface->surface(), &SurfaceInterface::unmapped,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::handleUnmapped);
|
2020-08-07 19:01:42 +00:00
|
|
|
connect(shellSurface->surface(), &SurfaceInterface::committed,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::handleCommitted);
|
2020-08-07 19:01:42 +00:00
|
|
|
|
|
|
|
connect(shellSurface, &LayerSurfaceV1Interface::desiredSizeChanged,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::scheduleRearrange);
|
2020-08-07 19:01:42 +00:00
|
|
|
connect(shellSurface, &LayerSurfaceV1Interface::layerChanged,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::scheduleRearrange);
|
2020-08-07 19:01:42 +00:00
|
|
|
connect(shellSurface, &LayerSurfaceV1Interface::marginsChanged,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::scheduleRearrange);
|
2020-08-07 19:01:42 +00:00
|
|
|
connect(shellSurface, &LayerSurfaceV1Interface::anchorChanged,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::scheduleRearrange);
|
2020-08-07 19:01:42 +00:00
|
|
|
connect(shellSurface, &LayerSurfaceV1Interface::exclusiveZoneChanged,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::scheduleRearrange);
|
2020-08-07 19:01:42 +00:00
|
|
|
connect(shellSurface, &LayerSurfaceV1Interface::acceptsFocusChanged,
|
2022-04-22 17:46:41 +00:00
|
|
|
this, &LayerShellV1Window::handleAcceptsFocusChanged);
|
2020-08-07 19:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
LayerSurfaceV1Interface *LayerShellV1Window::shellSurface() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return m_shellSurface;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
Output *LayerShellV1Window::desiredOutput() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
2021-08-25 10:47:44 +00:00
|
|
|
return m_desiredOutput;
|
2020-08-07 19:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::scheduleRearrange()
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
m_integration->scheduleRearrange();
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
NET::WindowType LayerShellV1Window::windowType(bool, int) const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return m_windowType;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
bool LayerShellV1Window::isPlaceable() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
bool LayerShellV1Window::isCloseable() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
bool LayerShellV1Window::isMovable() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
bool LayerShellV1Window::isMovableAcrossScreens() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
bool LayerShellV1Window::isResizable() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
bool LayerShellV1Window::takeFocus()
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
setActive(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
bool LayerShellV1Window::wantsInput() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return acceptsFocus() && readyForPainting();
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
StrutRect LayerShellV1Window::strutRect(StrutArea area) const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
switch (area) {
|
|
|
|
case StrutAreaLeft:
|
|
|
|
if (m_shellSurface->exclusiveEdge() == Qt::LeftEdge) {
|
|
|
|
return StrutRect(x(), y(), m_shellSurface->exclusiveZone(), height(), StrutAreaLeft);
|
|
|
|
}
|
|
|
|
return StrutRect();
|
|
|
|
case StrutAreaRight:
|
|
|
|
if (m_shellSurface->exclusiveEdge() == Qt::RightEdge) {
|
|
|
|
return StrutRect(x() + width() - m_shellSurface->exclusiveZone(), y(),
|
|
|
|
m_shellSurface->exclusiveZone(), height(), StrutAreaRight);
|
|
|
|
}
|
|
|
|
return StrutRect();
|
|
|
|
case StrutAreaTop:
|
|
|
|
if (m_shellSurface->exclusiveEdge() == Qt::TopEdge) {
|
|
|
|
return StrutRect(x(), y(), width(), m_shellSurface->exclusiveZone(), StrutAreaTop);
|
|
|
|
}
|
|
|
|
return StrutRect();
|
|
|
|
case StrutAreaBottom:
|
|
|
|
if (m_shellSurface->exclusiveEdge() == Qt::BottomEdge) {
|
|
|
|
return StrutRect(x(), y() + height() - m_shellSurface->exclusiveZone(),
|
|
|
|
width(), m_shellSurface->exclusiveZone(), StrutAreaBottom);
|
|
|
|
}
|
|
|
|
return StrutRect();
|
|
|
|
default:
|
|
|
|
return StrutRect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
bool LayerShellV1Window::hasStrut() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return m_shellSurface->exclusiveZone() > 0;
|
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void LayerShellV1Window::destroyWindow()
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
markAsZombie();
|
|
|
|
cleanTabBox();
|
|
|
|
Deleted *deleted = Deleted::create(this);
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT windowClosed(this, deleted);
|
2020-08-07 19:01:42 +00:00
|
|
|
StackingUpdatesBlocker blocker(workspace());
|
|
|
|
cleanGrouping();
|
2022-04-23 08:33:23 +00:00
|
|
|
waylandServer()->removeWindow(this);
|
2020-08-07 19:01:42 +00:00
|
|
|
deleted->unrefWindow();
|
|
|
|
scheduleRearrange();
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::closeWindow()
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
m_shellSurface->sendClosed();
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
Layer LayerShellV1Window::belongsToLayer() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
if (!isNormalWindow()) {
|
2022-04-22 17:51:07 +00:00
|
|
|
return WaylandWindow::belongsToLayer();
|
2020-08-07 19:01:42 +00:00
|
|
|
}
|
|
|
|
switch (m_shellSurface->layer()) {
|
|
|
|
case LayerSurfaceV1Interface::BackgroundLayer:
|
|
|
|
return DesktopLayer;
|
|
|
|
case LayerSurfaceV1Interface::BottomLayer:
|
|
|
|
return BelowLayer;
|
|
|
|
case LayerSurfaceV1Interface::TopLayer:
|
|
|
|
return AboveLayer;
|
|
|
|
case LayerSurfaceV1Interface::OverlayLayer:
|
|
|
|
return UnmanagedLayer;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
bool LayerShellV1Window::acceptsFocus() const
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
return m_shellSurface->acceptsFocus();
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::moveResizeInternal(const QRect &rect, MoveResizeMode mode)
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
Rework async geometry updates
Window management features were written with synchronous geometry
updates in mind. Currently, this poses a big problem on Wayland because
geometry updates are done in asynchronous fashion there.
At the moment, geometry is updated in a so called pseudo-asynchronous
fashion, meaning that the frame geometry will be reset to the old value
once geometry updates are unblocked. The main drawback of this approach
is that it is too error prone, the data flow is hard to comprehend, etc.
It is worth noting that there is already a machinery to perform async
geometry which is used during interactive move/resize operations.
This change extends the move/resize geometry usage beyond interactive
move/resize to make asynchronous geometry updates less error prone and
easier to comprehend.
With the proposed solution, all geometry updates must be done on the
move/resize geometry first. After that, the new geometry is passed on to
the Client-specific implementation of moveResizeInternal().
To be more specific, the frameGeometry() returns the current frame
geometry, it is primarily useful only to the scene. If you want to move
or resize a window, you need to use moveResizeGeometry() because it
corresponds to the last requested frame geometry.
It is worth noting that the moveResizeGeometry() returns the desired
bounding geometry. The client may commit the xdg_toplevel surface with a
slightly smaller window geometry, for example to enforce a specific
aspect ratio. The client is not allowed to resize beyond the size as
indicated in moveResizeGeometry().
The data flow is very simple: moveResize() updates the move/resize
geometry and calls the client-specific implementation of the
moveResizeInternal() method. Based on whether a configure event is
needed, moveResizeInternal() will update the frameGeometry() either
immediately or after the client commits a new buffer.
Unfortunately, both the compositor and xdg-shell clients try to update
the window geometry. It means that it's possible to have conflicts
between the two. With this change, the compositor's move resize geometry
will be synced only if there are no pending configure events, meaning
that the user doesn't try to resize the window.
2021-04-30 18:26:09 +00:00
|
|
|
if (areGeometryUpdatesBlocked()) {
|
|
|
|
setPendingMoveResizeMode(mode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QSize requestedClientSize = frameSizeToClientSize(rect.size());
|
|
|
|
if (requestedClientSize != clientSize()) {
|
|
|
|
m_shellSurface->sendConfigure(rect.size());
|
|
|
|
} else {
|
|
|
|
updateGeometry(rect);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The surface position is updated synchronously.
|
|
|
|
QRect updateRect = m_frameGeometry;
|
|
|
|
updateRect.moveTopLeft(rect.topLeft());
|
|
|
|
updateGeometry(updateRect);
|
2020-08-07 19:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::handleSizeChanged()
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
updateGeometry(QRect(pos(), clientSizeToFrameSize(surface()->size())));
|
|
|
|
scheduleRearrange();
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::handleUnmapped()
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
m_integration->recreateWindow(shellSurface());
|
2020-08-07 19:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::handleCommitted()
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
if (surface()->buffer()) {
|
|
|
|
updateDepth();
|
|
|
|
setReadyForPainting();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::handleAcceptsFocusChanged()
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
switch (m_shellSurface->layer()) {
|
|
|
|
case LayerSurfaceV1Interface::TopLayer:
|
|
|
|
case LayerSurfaceV1Interface::OverlayLayer:
|
|
|
|
if (wantsInput()) {
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(this);
|
2020-08-07 19:01:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LayerSurfaceV1Interface::BackgroundLayer:
|
|
|
|
case LayerSurfaceV1Interface::BottomLayer:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::handleOutputEnabledChanged()
|
2021-01-22 08:22:24 +00:00
|
|
|
{
|
2021-08-25 10:47:44 +00:00
|
|
|
if (!m_desiredOutput->isEnabled()) {
|
2021-01-22 08:22:24 +00:00
|
|
|
closeWindow();
|
2022-04-23 08:33:23 +00:00
|
|
|
destroyWindow();
|
2021-01-22 08:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::handleOutputDestroyed()
|
2020-08-07 19:01:42 +00:00
|
|
|
{
|
|
|
|
closeWindow();
|
2022-04-23 08:33:23 +00:00
|
|
|
destroyWindow();
|
2020-08-07 19:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:46:41 +00:00
|
|
|
void LayerShellV1Window::setVirtualKeyboardGeometry(const QRect &geo)
|
2021-04-09 14:44:44 +00:00
|
|
|
{
|
|
|
|
if (m_virtualKeyboardGeometry == geo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_virtualKeyboardGeometry = geo;
|
|
|
|
scheduleRearrange();
|
|
|
|
}
|
|
|
|
|
2020-08-07 19:01:42 +00:00
|
|
|
} // namespace KWin
|