2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-02-15 08:36:59 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2013, 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
|
2016-02-15 08:36:59 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-02-15 08:36:59 +00:00
|
|
|
#include "touch_input.h"
|
2016-05-12 14:33:03 +00:00
|
|
|
#include "abstract_client.h"
|
2018-09-15 00:00:24 +00:00
|
|
|
#include "pointer_input.h"
|
2016-12-27 19:16:50 +00:00
|
|
|
#include "input_event_spy.h"
|
2016-02-15 08:36:59 +00:00
|
|
|
#include "toplevel.h"
|
|
|
|
#include "wayland_server.h"
|
2016-02-15 10:43:36 +00:00
|
|
|
#include "workspace.h"
|
2016-05-12 14:33:03 +00:00
|
|
|
#include "decorations/decoratedclient.h"
|
|
|
|
// KDecoration
|
|
|
|
#include <KDecoration2/Decoration>
|
2016-02-15 08:36:59 +00:00
|
|
|
// KWayland
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/seat_interface.h>
|
2016-02-15 08:36:59 +00:00
|
|
|
// screenlocker
|
|
|
|
#include <KScreenLocker/KsldApp>
|
2016-05-12 14:33:03 +00:00
|
|
|
// Qt
|
|
|
|
#include <QHoverEvent>
|
2016-05-23 15:07:08 +00:00
|
|
|
#include <QWindow>
|
2016-02-15 08:36:59 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
TouchInputRedirection::TouchInputRedirection(InputRedirection *parent)
|
2016-05-12 14:33:03 +00:00
|
|
|
: InputDeviceHandler(parent)
|
2016-02-15 08:36:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TouchInputRedirection::~TouchInputRedirection() = default;
|
|
|
|
|
|
|
|
void TouchInputRedirection::init()
|
|
|
|
{
|
2018-09-15 00:00:24 +00:00
|
|
|
Q_ASSERT(!inited());
|
|
|
|
setInited(true);
|
|
|
|
InputDeviceHandler::init();
|
2016-02-15 08:36:59 +00:00
|
|
|
|
2016-04-25 06:51:33 +00:00
|
|
|
if (waylandServer()->hasScreenLockerIntegration()) {
|
|
|
|
connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this,
|
|
|
|
[this] {
|
|
|
|
cancel();
|
|
|
|
// position doesn't matter
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
connect(workspace(), &QObject::destroyed, this, [this] { setInited(false); });
|
|
|
|
connect(waylandServer(), &QObject::destroyed, this, [this] { setInited(false); });
|
2016-02-15 08:36:59 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 00:00:24 +00:00
|
|
|
bool TouchInputRedirection::focusUpdatesBlocked()
|
2016-02-15 08:36:59 +00:00
|
|
|
{
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!inited()) {
|
|
|
|
return true;
|
2016-02-15 08:36:59 +00:00
|
|
|
}
|
2016-05-23 15:07:08 +00:00
|
|
|
if (m_windowUpdatedInCycle) {
|
2018-09-15 00:00:24 +00:00
|
|
|
return true;
|
2016-05-23 15:07:08 +00:00
|
|
|
}
|
|
|
|
m_windowUpdatedInCycle = true;
|
2018-09-18 14:46:27 +00:00
|
|
|
if (waylandServer()->seat()->isDragTouch()) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-16 11:51:23 +00:00
|
|
|
if (m_activeTouchPoints.count() > 1) {
|
2018-09-15 00:00:24 +00:00
|
|
|
// first touch defines focus
|
|
|
|
return true;
|
2016-05-23 15:07:08 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-13 09:46:21 +00:00
|
|
|
bool TouchInputRedirection::positionValid() const
|
|
|
|
{
|
2019-11-26 17:48:29 +00:00
|
|
|
// we can only determine a position with at least one touch point
|
2021-02-16 11:51:23 +00:00
|
|
|
return !m_activeTouchPoints.isEmpty();
|
2018-12-13 09:46:21 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 00:00:24 +00:00
|
|
|
void TouchInputRedirection::focusUpdate(Toplevel *focusOld, Toplevel *focusNow)
|
|
|
|
{
|
|
|
|
// TODO: handle pointer grab aka popups
|
|
|
|
|
|
|
|
if (AbstractClient *ac = qobject_cast<AbstractClient*>(focusOld)) {
|
|
|
|
ac->leaveEvent();
|
2016-05-12 14:33:03 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
disconnect(m_focusGeometryConnection);
|
|
|
|
m_focusGeometryConnection = QMetaObject::Connection();
|
|
|
|
|
|
|
|
if (AbstractClient *ac = qobject_cast<AbstractClient*>(focusNow)) {
|
|
|
|
ac->enterEvent(m_lastPosition.toPoint());
|
|
|
|
workspace()->updateFocusMousePosition(m_lastPosition.toPoint());
|
2016-02-15 08:36:59 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
|
2016-02-15 08:36:59 +00:00
|
|
|
auto seat = waylandServer()->seat();
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!focusNow || !focusNow->surface() || decoration()) {
|
|
|
|
// no new surface or internal window or on decoration -> cleanup
|
2016-02-15 08:36:59 +00:00
|
|
|
seat->setFocusedTouchSurface(nullptr);
|
|
|
|
return;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
|
|
|
|
// TODO: invalidate pointer focus?
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
// FIXME: add input transformation API to KWaylandServer::SeatInterface for touch input
|
2018-09-15 00:00:24 +00:00
|
|
|
seat->setFocusedTouchSurface(focusNow->surface(), -1 * focusNow->inputTransformation().map(focusNow->pos()) + focusNow->pos());
|
2020-02-05 09:28:50 +00:00
|
|
|
m_focusGeometryConnection = connect(focusNow, &Toplevel::frameGeometryChanged, this,
|
2018-09-15 00:00:24 +00:00
|
|
|
[this] {
|
2020-09-07 08:11:07 +00:00
|
|
|
if (!focus()) {
|
2018-09-15 00:00:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
2020-09-07 08:11:07 +00:00
|
|
|
if (focus()->surface() != seat->focusedTouchSurface()) {
|
2018-09-15 00:00:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
seat->setFocusedTouchSurfacePosition(-1 * focus()->inputTransformation().map(focus()->pos()) + focus()->pos());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchInputRedirection::cleanupInternalWindow(QWindow *old, QWindow *now)
|
|
|
|
{
|
|
|
|
Q_UNUSED(old);
|
|
|
|
Q_UNUSED(now);
|
|
|
|
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchInputRedirection::cleanupDecoration(Decoration::DecoratedClientImpl *old, Decoration::DecoratedClientImpl *now)
|
|
|
|
{
|
2018-12-13 10:06:08 +00:00
|
|
|
Q_UNUSED(old);
|
2018-09-15 00:00:24 +00:00
|
|
|
Q_UNUSED(now);
|
|
|
|
|
2018-12-13 10:06:08 +00:00
|
|
|
// nothing to do
|
2016-02-15 08:36:59 +00:00
|
|
|
}
|
|
|
|
|
2016-05-24 08:57:57 +00:00
|
|
|
void TouchInputRedirection::processDown(qint32 id, const QPointF &pos, quint32 time, LibInput::Device *device)
|
2016-02-15 08:36:59 +00:00
|
|
|
{
|
2016-05-24 08:57:57 +00:00
|
|
|
Q_UNUSED(device)
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!inited()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
m_lastPosition = pos;
|
2016-05-23 15:07:08 +00:00
|
|
|
m_windowUpdatedInCycle = false;
|
2021-02-16 11:51:23 +00:00
|
|
|
m_activeTouchPoints.insert(id);
|
|
|
|
if (m_activeTouchPoints.count() == 1) {
|
2018-09-15 00:00:24 +00:00
|
|
|
update();
|
|
|
|
}
|
2018-09-15 00:37:24 +00:00
|
|
|
input()->processSpies(std::bind(&InputEventSpy::touchDown, std::placeholders::_1, id, pos, time));
|
|
|
|
input()->processFilters(std::bind(&InputEventFilter::touchDown, std::placeholders::_1, id, pos, time));
|
2016-05-23 15:07:08 +00:00
|
|
|
m_windowUpdatedInCycle = false;
|
2016-02-15 08:36:59 +00:00
|
|
|
}
|
|
|
|
|
2016-05-24 08:57:57 +00:00
|
|
|
void TouchInputRedirection::processUp(qint32 id, quint32 time, LibInput::Device *device)
|
2016-02-15 08:36:59 +00:00
|
|
|
{
|
2016-05-24 08:57:57 +00:00
|
|
|
Q_UNUSED(device)
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!inited()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-16 11:51:23 +00:00
|
|
|
if (!m_activeTouchPoints.remove(id)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-23 15:07:08 +00:00
|
|
|
m_windowUpdatedInCycle = false;
|
2018-09-15 00:37:24 +00:00
|
|
|
input()->processSpies(std::bind(&InputEventSpy::touchUp, std::placeholders::_1, id, time));
|
|
|
|
input()->processFilters(std::bind(&InputEventFilter::touchUp, std::placeholders::_1, id, time));
|
2016-05-23 15:07:08 +00:00
|
|
|
m_windowUpdatedInCycle = false;
|
2021-02-16 11:51:23 +00:00
|
|
|
if (m_activeTouchPoints.count() == 0) {
|
2018-09-15 00:00:24 +00:00
|
|
|
update();
|
|
|
|
}
|
2016-02-15 08:36:59 +00:00
|
|
|
}
|
|
|
|
|
2016-05-24 08:57:57 +00:00
|
|
|
void TouchInputRedirection::processMotion(qint32 id, const QPointF &pos, quint32 time, LibInput::Device *device)
|
2016-02-15 08:36:59 +00:00
|
|
|
{
|
2016-05-24 08:57:57 +00:00
|
|
|
Q_UNUSED(device)
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!inited()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-16 11:51:23 +00:00
|
|
|
if (!m_activeTouchPoints.contains(id)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
m_lastPosition = pos;
|
2016-05-23 15:07:08 +00:00
|
|
|
m_windowUpdatedInCycle = false;
|
2018-09-15 00:37:24 +00:00
|
|
|
input()->processSpies(std::bind(&InputEventSpy::touchMotion, std::placeholders::_1, id, pos, time));
|
|
|
|
input()->processFilters(std::bind(&InputEventFilter::touchMotion, std::placeholders::_1, id, pos, time));
|
2016-05-23 15:07:08 +00:00
|
|
|
m_windowUpdatedInCycle = false;
|
2016-02-15 08:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TouchInputRedirection::cancel()
|
|
|
|
{
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!inited()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-16 11:51:23 +00:00
|
|
|
// If the touch sequence is artificially cancelled by the compositor, touch motion and touch
|
|
|
|
// up events will be silently ignored and won't be passed down through the event filter chain.
|
|
|
|
// If the touch sequence is cancelled because we received a TOUCH_CANCEL event from libinput,
|
|
|
|
// the compositor will not receive any TOUCH_MOTION or TOUCH_UP events for that slot.
|
2021-03-11 00:34:03 +00:00
|
|
|
if (!m_activeTouchPoints.isEmpty()) {
|
|
|
|
m_activeTouchPoints.clear();
|
|
|
|
waylandServer()->seat()->cancelTouchSequence();
|
|
|
|
}
|
2016-02-15 08:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TouchInputRedirection::frame()
|
|
|
|
{
|
2021-03-11 00:34:03 +00:00
|
|
|
if (!inited() || !waylandServer()->seat()->hasTouch()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
waylandServer()->seat()->touchFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|