2020-07-11 16:40:28 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
#include "inputpanelv1window.h"
|
2020-07-11 16:40:28 +00:00
|
|
|
#include "deleted.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "inputmethod.h"
|
2022-04-14 12:33:28 +00:00
|
|
|
#include "output.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "platform.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/output_interface.h"
|
|
|
|
#include "wayland/seat_interface.h"
|
|
|
|
#include "wayland/surface_interface.h"
|
|
|
|
#include "wayland/textinput_v2_interface.h"
|
|
|
|
#include "wayland/textinput_v3_interface.h"
|
2020-07-11 16:40:28 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
using namespace KWaylandServer;
|
|
|
|
|
2020-08-21 10:32:04 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
InputPanelV1Window::InputPanelV1Window(InputPanelSurfaceV1Interface *panelSurface)
|
2022-04-22 17:51:07 +00:00
|
|
|
: WaylandWindow(panelSurface->surface())
|
2020-07-11 16:40:28 +00:00
|
|
|
, m_panelSurface(panelSurface)
|
|
|
|
{
|
2020-09-03 10:23:17 +00:00
|
|
|
setSkipSwitcher(true);
|
2020-07-11 16:40:28 +00:00
|
|
|
setSkipPager(true);
|
|
|
|
setSkipTaskbar(true);
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(surface(), &SurfaceInterface::aboutToBeDestroyed, this, &InputPanelV1Window::destroyWindow);
|
2022-04-22 17:42:35 +00:00
|
|
|
connect(surface(), &SurfaceInterface::sizeChanged, this, &InputPanelV1Window::reposition);
|
|
|
|
connect(surface(), &SurfaceInterface::mapped, this, &InputPanelV1Window::updateDepth);
|
2020-07-11 16:40:28 +00:00
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
connect(panelSurface, &InputPanelSurfaceV1Interface::topLevel, this, &InputPanelV1Window::showTopLevel);
|
|
|
|
connect(panelSurface, &InputPanelSurfaceV1Interface::overlayPanel, this, &InputPanelV1Window::showOverlayPanel);
|
2022-04-23 08:33:23 +00:00
|
|
|
connect(panelSurface, &InputPanelSurfaceV1Interface::destroyed, this, &InputPanelV1Window::destroyWindow);
|
2021-10-13 16:24:59 +00:00
|
|
|
|
|
|
|
InputMethod::self()->setPanel(this);
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
void InputPanelV1Window::showOverlayPanel()
|
2020-07-11 16:40:28 +00:00
|
|
|
{
|
|
|
|
setOutput(nullptr);
|
|
|
|
m_mode = Overlay;
|
|
|
|
reposition();
|
2021-12-22 07:03:31 +00:00
|
|
|
showClient();
|
2020-07-11 16:40:28 +00:00
|
|
|
setReadyForPainting();
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
void InputPanelV1Window::showTopLevel(OutputInterface *output, InputPanelSurfaceV1Interface::Position position)
|
2020-07-11 16:40:28 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(position);
|
|
|
|
m_mode = Toplevel;
|
|
|
|
setOutput(output);
|
2021-12-22 07:03:31 +00:00
|
|
|
showClient();
|
2021-10-13 16:24:59 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
void InputPanelV1Window::allow()
|
2021-10-13 16:24:59 +00:00
|
|
|
{
|
2020-07-11 16:40:28 +00:00
|
|
|
setReadyForPainting();
|
2021-10-13 16:24:59 +00:00
|
|
|
reposition();
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
void KWin::InputPanelV1Window::reposition()
|
2020-07-11 16:40:28 +00:00
|
|
|
{
|
2021-10-13 16:24:59 +00:00
|
|
|
if (!readyForPainting()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-11 16:40:28 +00:00
|
|
|
switch (m_mode) {
|
2022-03-23 10:13:38 +00:00
|
|
|
case Toplevel: {
|
|
|
|
QSize panelSize = surface()->size();
|
|
|
|
if (!panelSize.isValid() || panelSize.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect availableArea;
|
|
|
|
QRect outputArea;
|
|
|
|
if (m_output) {
|
|
|
|
outputArea = m_output->geometry();
|
|
|
|
if (waylandServer()->isScreenLocked()) {
|
|
|
|
availableArea = outputArea;
|
2022-02-14 15:18:14 +00:00
|
|
|
} else {
|
2022-03-23 10:13:38 +00:00
|
|
|
availableArea = workspace()->clientArea(MaximizeArea, this, m_output);
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
} else {
|
|
|
|
availableArea = workspace()->clientArea(MaximizeArea, this);
|
|
|
|
outputArea = workspace()->clientArea(FullScreenArea, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
panelSize = panelSize.boundedTo(availableArea.size());
|
|
|
|
|
|
|
|
QRect geo(availableArea.bottomLeft() - QPoint{0, panelSize.height()}, panelSize);
|
|
|
|
geo.translate((availableArea.width() - panelSize.width()) / 2, availableArea.height() - outputArea.height());
|
|
|
|
moveResize(geo);
|
|
|
|
} break;
|
|
|
|
case Overlay: {
|
|
|
|
auto textInputSurface = waylandServer()->seat()->focusedTextInputSurface();
|
2022-04-23 08:33:23 +00:00
|
|
|
auto textWindow = waylandServer()->findWindow(textInputSurface);
|
2022-03-23 10:13:38 +00:00
|
|
|
QRect cursorRectangle;
|
|
|
|
auto textInputV2 = waylandServer()->seat()->textInputV2();
|
|
|
|
if (textInputV2 && textInputV2->isEnabled() && textInputV2->surface() == textInputSurface) {
|
|
|
|
cursorRectangle = textInputV2->cursorRectangle();
|
|
|
|
}
|
|
|
|
auto textInputV3 = waylandServer()->seat()->textInputV3();
|
|
|
|
if (textInputV3 && textInputV3->isEnabled() && textInputV3->surface() == textInputSurface) {
|
|
|
|
cursorRectangle = textInputV3->cursorRectangle();
|
|
|
|
}
|
2022-04-23 08:33:23 +00:00
|
|
|
if (textWindow) {
|
|
|
|
cursorRectangle.translate(textWindow->bufferGeometry().topLeft());
|
2022-03-29 09:59:02 +00:00
|
|
|
const QRect screen = Workspace::self()->clientArea(PlacementArea, this, cursorRectangle.bottomLeft());
|
2022-03-23 10:13:38 +00:00
|
|
|
|
|
|
|
// Reuse the similar logic like xdg popup
|
|
|
|
QRect popupRect(popupOffset(cursorRectangle, Qt::BottomEdge | Qt::LeftEdge, Qt::RightEdge | Qt::BottomEdge, surface()->size()), surface()->size());
|
|
|
|
|
|
|
|
if (popupRect.left() < screen.left()) {
|
|
|
|
popupRect.moveLeft(screen.left());
|
2021-12-13 17:31:08 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
if (popupRect.right() > screen.right()) {
|
|
|
|
popupRect.moveRight(screen.right());
|
2021-12-13 17:31:08 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
if (popupRect.top() < screen.top() || popupRect.bottom() > screen.bottom()) {
|
|
|
|
auto flippedPopupRect =
|
|
|
|
QRect(popupOffset(cursorRectangle, Qt::TopEdge | Qt::LeftEdge, Qt::RightEdge | Qt::TopEdge, surface()->size()), surface()->size());
|
2021-12-13 17:31:08 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// if it still doesn't fit we should continue with the unflipped version
|
|
|
|
if (flippedPopupRect.top() >= screen.top() || flippedPopupRect.bottom() <= screen.bottom()) {
|
|
|
|
popupRect.moveTop(flippedPopupRect.top());
|
2021-12-13 17:31:08 +00:00
|
|
|
}
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
moveResize(popupRect);
|
|
|
|
}
|
|
|
|
} break;
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
void InputPanelV1Window::destroyWindow()
|
2020-07-11 16:40:28 +00:00
|
|
|
{
|
|
|
|
markAsZombie();
|
|
|
|
|
|
|
|
Deleted *deleted = Deleted::create(this);
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT windowClosed(this, deleted);
|
2020-07-11 16:40:28 +00:00
|
|
|
StackingUpdatesBlocker blocker(workspace());
|
2022-04-23 08:33:23 +00:00
|
|
|
waylandServer()->removeWindow(this);
|
2020-07-11 16:40:28 +00:00
|
|
|
deleted->unrefWindow();
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
NET::WindowType InputPanelV1Window::windowType(bool, int) const
|
2020-07-11 16:40:28 +00:00
|
|
|
{
|
|
|
|
return NET::Utility;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
QRect InputPanelV1Window::inputGeometry() const
|
2020-07-27 19:30:49 +00:00
|
|
|
{
|
2021-10-13 16:24:59 +00:00
|
|
|
return readyForPainting() ? surface()->input().boundingRect().translated(pos()) : QRect();
|
2020-07-27 19:30:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
void InputPanelV1Window::setOutput(OutputInterface *outputIface)
|
2020-07-11 16:40:28 +00:00
|
|
|
{
|
|
|
|
if (m_output) {
|
2022-04-22 17:42:35 +00:00
|
|
|
disconnect(m_output, &Output::geometryChanged, this, &InputPanelV1Window::reposition);
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_output = waylandServer()->findOutput(outputIface);
|
|
|
|
|
|
|
|
if (m_output) {
|
2022-04-22 17:42:35 +00:00
|
|
|
connect(m_output, &Output::geometryChanged, this, &InputPanelV1Window::reposition);
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-21 10:32:04 +00:00
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
void InputPanelV1Window::moveResizeInternal(const QRect &rect, MoveResizeMode mode)
|
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
|
|
|
{
|
|
|
|
Q_UNUSED(mode)
|
|
|
|
updateGeometry(rect);
|
|
|
|
}
|
|
|
|
|
2020-08-21 10:32:04 +00:00
|
|
|
} // namespace KWin
|