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"
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "inputmethod.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/output.h"
|
|
|
|
#include "wayland/seat.h"
|
|
|
|
#include "wayland/surface.h"
|
|
|
|
#include "wayland/textinput_v1.h"
|
|
|
|
#include "wayland/textinput_v2.h"
|
|
|
|
#include "wayland/textinput_v3.h"
|
2020-07-11 16:40:28 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
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);
|
2023-03-31 14:07:01 +00:00
|
|
|
connect(surface(), &SurfaceInterface::inputChanged, this, &InputPanelV1Window::reposition);
|
2022-10-14 01:18:05 +00:00
|
|
|
connect(surface(), &SurfaceInterface::mapped, this, &InputPanelV1Window::handleMapped);
|
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);
|
2023-03-23 08:29:24 +00:00
|
|
|
connect(panelSurface, &InputPanelSurfaceV1Interface::aboutToBeDestroyed, this, &InputPanelV1Window::destroyWindow);
|
2021-10-13 16:24:59 +00:00
|
|
|
|
2023-01-04 11:22:31 +00:00
|
|
|
connect(workspace(), &Workspace::outputsChanged, this, &InputPanelV1Window::reposition);
|
|
|
|
|
2022-07-20 10:14:27 +00:00
|
|
|
kwinApp()->inputMethod()->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
|
|
|
{
|
2022-10-14 01:18:05 +00:00
|
|
|
m_mode = Mode::Overlay;
|
|
|
|
maybeShow();
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 17:42:35 +00:00
|
|
|
void InputPanelV1Window::showTopLevel(OutputInterface *output, InputPanelSurfaceV1Interface::Position position)
|
2020-07-11 16:40:28 +00:00
|
|
|
{
|
2022-10-21 19:14:42 +00:00
|
|
|
m_mode = Mode::VirtualKeyboard;
|
2022-10-14 01:18:05 +00:00
|
|
|
maybeShow();
|
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
|
|
|
{
|
2022-09-21 12:17:06 +00:00
|
|
|
m_allowed = true;
|
2022-10-14 01:18:05 +00:00
|
|
|
maybeShow();
|
2022-09-21 12:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputPanelV1Window::show()
|
|
|
|
{
|
2022-10-21 19:14:42 +00:00
|
|
|
m_virtualKeyboardShouldBeShown = true;
|
2022-10-14 01:18:05 +00:00
|
|
|
maybeShow();
|
2022-09-21 12:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputPanelV1Window::hide()
|
|
|
|
{
|
2022-10-21 19:14:42 +00:00
|
|
|
m_virtualKeyboardShouldBeShown = false;
|
|
|
|
if (readyForPainting() && m_mode != Mode::Overlay) {
|
2023-06-01 10:31:04 +00:00
|
|
|
setHidden(true);
|
2022-09-21 12:17:06 +00:00
|
|
|
}
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
void 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-10-14 01:18:05 +00:00
|
|
|
case Mode::None: {
|
|
|
|
// should never happen
|
|
|
|
}; break;
|
2022-10-21 19:14:42 +00:00
|
|
|
case Mode::VirtualKeyboard: {
|
2023-03-31 14:07:01 +00:00
|
|
|
// maliit creates a fullscreen overlay so use the input shape as the window geometry.
|
|
|
|
m_windowGeometry = surface()->input().boundingRect();
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2023-01-04 11:22:31 +00:00
|
|
|
const auto activeOutput = workspace()->activeOutput();
|
2022-05-16 20:13:39 +00:00
|
|
|
QRectF availableArea;
|
2023-01-04 11:22:31 +00:00
|
|
|
if (waylandServer()->isScreenLocked()) {
|
2023-03-31 14:07:01 +00:00
|
|
|
availableArea = workspace()->clientArea(FullScreenArea, this, activeOutput);
|
2022-03-23 10:13:38 +00:00
|
|
|
} else {
|
2023-01-04 11:22:31 +00:00
|
|
|
availableArea = workspace()->clientArea(MaximizeArea, this, activeOutput);
|
2022-03-23 10:13:38 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 14:07:01 +00:00
|
|
|
QRectF geo = m_windowGeometry;
|
|
|
|
geo.moveLeft(availableArea.left() + (availableArea.width() - geo.width()) / 2);
|
|
|
|
geo.moveBottom(availableArea.bottom());
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
moveResize(geo);
|
|
|
|
} break;
|
2022-10-14 01:18:05 +00:00
|
|
|
case Mode::Overlay: {
|
2022-03-23 10:13:38 +00:00
|
|
|
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;
|
2023-01-07 20:56:49 +00:00
|
|
|
auto textInputV1 = waylandServer()->seat()->textInputV1();
|
|
|
|
if (textInputV1 && textInputV1->isEnabled() && textInputV1->surface() == textInputSurface) {
|
|
|
|
cursorRectangle = textInputV1->cursorRectangle();
|
|
|
|
}
|
2022-03-23 10:13:38 +00:00
|
|
|
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) {
|
2022-05-16 20:13:39 +00:00
|
|
|
cursorRectangle.translate(textWindow->bufferGeometry().topLeft().toPoint());
|
|
|
|
const QRectF screen = Workspace::self()->clientArea(PlacementArea, this, cursorRectangle.bottomLeft());
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2023-03-31 14:07:01 +00:00
|
|
|
m_windowGeometry = QRectF(QPointF(0, 0), surface()->size());
|
|
|
|
|
2024-01-26 00:13:56 +00:00
|
|
|
QRectF popupRect(cursorRectangle.left(),
|
|
|
|
cursorRectangle.top() + cursorRectangle.height(),
|
|
|
|
m_windowGeometry.width(),
|
|
|
|
m_windowGeometry.height());
|
2022-03-23 10:13:38 +00:00
|
|
|
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()) {
|
2024-01-26 00:13:56 +00:00
|
|
|
const QRectF flippedPopupRect(cursorRectangle.left(),
|
|
|
|
cursorRectangle.top() - m_windowGeometry.height(),
|
|
|
|
m_windowGeometry.width(),
|
|
|
|
m_windowGeometry.height());
|
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
|
2024-01-11 06:37:51 +00:00
|
|
|
if (flippedPopupRect.top() >= screen.top() && flippedPopupRect.bottom() <= screen.bottom()) {
|
2022-03-23 10:13:38 +00:00
|
|
|
popupRect.moveTop(flippedPopupRect.top());
|
2021-12-13 17:31:08 +00:00
|
|
|
}
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
2024-01-11 06:37:51 +00:00
|
|
|
if (popupRect.top() < screen.top()) {
|
|
|
|
popupRect.moveTop(screen.top());
|
|
|
|
}
|
|
|
|
if (popupRect.bottom() > screen.bottom()) {
|
|
|
|
popupRect.moveBottom(screen.bottom());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
Drop Deleted
Currently, the normal window lifecycle looks as follows: create Window,
wait until it's shown, add it to Workspace, wait until it's closed,
create a Deleted, copy properties from the original window to the
deleted one, destroy the original window, wait until the last deleted
window reference is dropped.
There are a couple of issues with this design: we can't nicely
encapsulate X11 or Wayland specific implementation details if they need
to be accessed for closed windows; manual copying of properties is
cumbersome and error prone and we've had a dozen of cases where effects
worked incorrectly because some properties had not been copied.
The goal of this patch is to drop Deleted and extend the lifetime of the
original window, but with a special state set: Window::isDeleted().
The main danger is that somebody can try to do something with deleted
windows that they should not do, but on the other hand, such code needs
to be guarded with relevant checks too.
2023-03-14 09:45:18 +00:00
|
|
|
m_panelSurface->disconnect(this);
|
|
|
|
m_panelSurface->surface()->disconnect(this);
|
2020-07-11 16:40:28 +00:00
|
|
|
|
Drop Deleted
Currently, the normal window lifecycle looks as follows: create Window,
wait until it's shown, add it to Workspace, wait until it's closed,
create a Deleted, copy properties from the original window to the
deleted one, destroy the original window, wait until the last deleted
window reference is dropped.
There are a couple of issues with this design: we can't nicely
encapsulate X11 or Wayland specific implementation details if they need
to be accessed for closed windows; manual copying of properties is
cumbersome and error prone and we've had a dozen of cases where effects
worked incorrectly because some properties had not been copied.
The goal of this patch is to drop Deleted and extend the lifetime of the
original window, but with a special state set: Window::isDeleted().
The main danger is that somebody can try to do something with deleted
windows that they should not do, but on the other hand, such code needs
to be guarded with relevant checks too.
2023-03-14 09:45:18 +00:00
|
|
|
markAsDeleted();
|
|
|
|
|
|
|
|
Q_EMIT closed();
|
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
|
|
|
|
2023-03-02 20:51:46 +00:00
|
|
|
unref();
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
|
2024-02-20 18:04:06 +00:00
|
|
|
WindowType InputPanelV1Window::windowType() const
|
2020-07-11 16:40:28 +00:00
|
|
|
{
|
2024-02-20 18:04:06 +00:00
|
|
|
return WindowType::Utility;
|
2020-07-11 16:40:28 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 14:07:01 +00:00
|
|
|
QRectF InputPanelV1Window::frameRectToBufferRect(const QRectF &rect) const
|
2020-07-27 19:30:49 +00:00
|
|
|
{
|
2023-03-31 14:07:01 +00:00
|
|
|
return QRectF(rect.topLeft() - m_windowGeometry.topLeft(), surface()->size());
|
2020-07-27 19:30:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
void InputPanelV1Window::moveResizeInternal(const QRectF &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
|
|
|
{
|
|
|
|
updateGeometry(rect);
|
|
|
|
}
|
|
|
|
|
2022-10-14 01:18:05 +00:00
|
|
|
void InputPanelV1Window::handleMapped()
|
|
|
|
{
|
|
|
|
maybeShow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputPanelV1Window::maybeShow()
|
|
|
|
{
|
2022-10-21 19:14:42 +00:00
|
|
|
const bool shouldShow = m_mode == Mode::Overlay || (m_mode == Mode::VirtualKeyboard && m_allowed && m_virtualKeyboardShouldBeShown);
|
Drop Deleted
Currently, the normal window lifecycle looks as follows: create Window,
wait until it's shown, add it to Workspace, wait until it's closed,
create a Deleted, copy properties from the original window to the
deleted one, destroy the original window, wait until the last deleted
window reference is dropped.
There are a couple of issues with this design: we can't nicely
encapsulate X11 or Wayland specific implementation details if they need
to be accessed for closed windows; manual copying of properties is
cumbersome and error prone and we've had a dozen of cases where effects
worked incorrectly because some properties had not been copied.
The goal of this patch is to drop Deleted and extend the lifetime of the
original window, but with a special state set: Window::isDeleted().
The main danger is that somebody can try to do something with deleted
windows that they should not do, but on the other hand, such code needs
to be guarded with relevant checks too.
2023-03-14 09:45:18 +00:00
|
|
|
if (shouldShow && !isDeleted() && surface()->isMapped()) {
|
2023-03-02 15:02:09 +00:00
|
|
|
markAsMapped();
|
2022-10-14 01:18:05 +00:00
|
|
|
reposition();
|
2023-06-01 10:31:04 +00:00
|
|
|
setHidden(false);
|
2022-10-14 01:18:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 10:32:04 +00:00
|
|
|
} // namespace KWin
|
2023-07-05 06:30:14 +00:00
|
|
|
|
|
|
|
#include "moc_inputpanelv1window.cpp"
|