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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "inputpanelv1client.h"
|
|
|
|
#include "deleted.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include "abstract_wayland_output.h"
|
|
|
|
#include "platform.h"
|
2021-10-13 16:24:59 +00:00
|
|
|
#include "inputmethod.h"
|
2020-07-11 16:40:28 +00:00
|
|
|
#include <KWaylandServer/output_interface.h>
|
|
|
|
#include <KWaylandServer/seat_interface.h>
|
|
|
|
#include <KWaylandServer/surface_interface.h>
|
2020-09-21 07:35:34 +00:00
|
|
|
#include <KWaylandServer/textinput_v2_interface.h>
|
2021-12-13 17:31:08 +00:00
|
|
|
#include <KWaylandServer/textinput_v3_interface.h>
|
2020-07-11 16:40:28 +00:00
|
|
|
|
|
|
|
using namespace KWaylandServer;
|
|
|
|
|
2020-08-21 10:32:04 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2020-07-11 16:40:28 +00:00
|
|
|
InputPanelV1Client::InputPanelV1Client(InputPanelSurfaceV1Interface *panelSurface)
|
|
|
|
: WaylandClient(panelSurface->surface())
|
|
|
|
, 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);
|
|
|
|
|
|
|
|
connect(surface(), &SurfaceInterface::aboutToBeDestroyed, this, &InputPanelV1Client::destroyClient);
|
|
|
|
connect(surface(), &SurfaceInterface::sizeChanged, this, &InputPanelV1Client::reposition);
|
|
|
|
connect(surface(), &SurfaceInterface::mapped, this, &InputPanelV1Client::updateDepth);
|
|
|
|
|
|
|
|
connect(panelSurface, &InputPanelSurfaceV1Interface::topLevel, this, &InputPanelV1Client::showTopLevel);
|
|
|
|
connect(panelSurface, &InputPanelSurfaceV1Interface::overlayPanel, this, &InputPanelV1Client::showOverlayPanel);
|
|
|
|
connect(panelSurface, &InputPanelSurfaceV1Interface::destroyed, this, &InputPanelV1Client::destroyClient);
|
2021-10-13 16:24:59 +00:00
|
|
|
|
|
|
|
InputMethod::self()->setPanel(this);
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputPanelV1Client::showOverlayPanel()
|
|
|
|
{
|
|
|
|
setOutput(nullptr);
|
|
|
|
m_mode = Overlay;
|
|
|
|
reposition();
|
|
|
|
setReadyForPainting();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputPanelV1Client::showTopLevel(OutputInterface *output, InputPanelSurfaceV1Interface::Position position)
|
|
|
|
{
|
|
|
|
Q_UNUSED(position);
|
|
|
|
m_mode = Toplevel;
|
|
|
|
setOutput(output);
|
2021-10-13 16:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputPanelV1Client::allow()
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void KWin::InputPanelV1Client::reposition()
|
|
|
|
{
|
2021-10-13 16:24:59 +00:00
|
|
|
if (!readyForPainting()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-11 16:40:28 +00:00
|
|
|
switch (m_mode) {
|
|
|
|
case Toplevel: {
|
|
|
|
if (m_output) {
|
|
|
|
const QSize panelSize = surface()->size();
|
|
|
|
if (!panelSize.isValid() || panelSize.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-07 03:44:55 +00:00
|
|
|
QRect availableArea;
|
|
|
|
if (waylandServer()->isScreenLocked()) {
|
|
|
|
availableArea = m_output->geometry();
|
|
|
|
} else {
|
2021-08-17 11:55:34 +00:00
|
|
|
availableArea = workspace()->clientArea(MaximizeArea, this, m_output);
|
2021-05-07 03:44:55 +00:00
|
|
|
}
|
2021-02-19 13:59:01 +00:00
|
|
|
QRect geo(availableArea.topLeft(), panelSize);
|
|
|
|
geo.translate((availableArea.width() - panelSize.width())/2, availableArea.height() - panelSize.height());
|
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
|
|
|
moveResize(geo);
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Overlay: {
|
2021-12-13 17:31:08 +00:00
|
|
|
auto textInputSurface = waylandServer()->seat()->focusedTextInputSurface();
|
|
|
|
auto textClient = waylandServer()->findClient(textInputSurface);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
if (textClient) {
|
2021-12-20 11:26:47 +00:00
|
|
|
cursorRectangle.translate(textClient->bufferGeometry().topLeft());
|
2021-12-13 17:31:08 +00:00
|
|
|
const QRect screen = Workspace::self()->clientArea(PlacementArea, cursorRectangle.bottomLeft(), 0);
|
|
|
|
|
|
|
|
// Reuse the similar logic like xdg popup
|
2021-12-19 05:06:14 +00:00
|
|
|
QRect popupRect(popupOffset(cursorRectangle, Qt::BottomEdge | Qt::LeftEdge, Qt::RightEdge | Qt::BottomEdge, surface()->size()), surface()->size());
|
2021-12-13 17:31:08 +00:00
|
|
|
|
|
|
|
if (popupRect.left() < screen.left()) {
|
|
|
|
popupRect.moveLeft(screen.left());
|
|
|
|
}
|
|
|
|
if (popupRect.right() > screen.right()) {
|
|
|
|
popupRect.moveRight(screen.right());
|
|
|
|
}
|
|
|
|
if (popupRect.top() < screen.top() || popupRect.bottom() > screen.bottom()) {
|
|
|
|
auto flippedPopupRect =
|
2021-12-19 08:10:56 +00:00
|
|
|
QRect(popupOffset(cursorRectangle, Qt::TopEdge | Qt::LeftEdge, Qt::RightEdge | Qt::TopEdge, surface()->size()), surface()->size());
|
2021-12-13 17:31:08 +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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moveResize(popupRect);
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputPanelV1Client::destroyClient()
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
waylandServer()->removeClient(this);
|
|
|
|
deleted->unrefWindow();
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
NET::WindowType InputPanelV1Client::windowType(bool, int) const
|
|
|
|
{
|
|
|
|
return NET::Utility;
|
|
|
|
}
|
|
|
|
|
2020-07-27 19:30:49 +00:00
|
|
|
QRect InputPanelV1Client::inputGeometry() const
|
|
|
|
{
|
2021-10-13 16:24:59 +00:00
|
|
|
return readyForPainting() ? surface()->input().boundingRect().translated(pos()) : QRect();
|
2020-07-27 19:30:49 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 16:40:28 +00:00
|
|
|
void InputPanelV1Client::setOutput(OutputInterface *outputIface)
|
|
|
|
{
|
|
|
|
if (m_output) {
|
|
|
|
disconnect(m_output, &AbstractWaylandOutput::geometryChanged, this, &InputPanelV1Client::reposition);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_output = waylandServer()->findOutput(outputIface);
|
|
|
|
|
|
|
|
if (m_output) {
|
|
|
|
connect(m_output, &AbstractWaylandOutput::geometryChanged, this, &InputPanelV1Client::reposition);
|
|
|
|
}
|
|
|
|
}
|
2020-08-21 10:32:04 +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
|
|
|
void InputPanelV1Client::moveResizeInternal(const QRect &rect, MoveResizeMode mode)
|
|
|
|
{
|
|
|
|
Q_UNUSED(mode)
|
|
|
|
updateGeometry(rect);
|
|
|
|
}
|
|
|
|
|
2020-08-21 10:32:04 +00:00
|
|
|
} // namespace KWin
|