2016-02-15 08:36:59 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2013, 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2018-09-15 00:00:24 +00:00
|
|
|
Copyright (C) 2018 Roman Gilg <subdiff@gmail.com>
|
2016-02-15 08:36:59 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "touch_input.h"
|
2016-05-12 14:33:03 +00:00
|
|
|
#include "abstract_client.h"
|
2016-02-15 08:36:59 +00:00
|
|
|
#include "input.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
|
|
|
|
#include <KWayland/Server/seat_interface.h>
|
|
|
|
// 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;
|
|
|
|
}
|
2018-12-13 09:46:21 +00:00
|
|
|
if (m_touches > 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
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_touches >= 0);
|
2019-11-26 17:48:29 +00:00
|
|
|
// we can only determine a position with at least one touch point
|
2018-12-13 09:46:21 +00:00
|
|
|
return m_touches == 0;
|
|
|
|
}
|
|
|
|
|
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?
|
|
|
|
|
|
|
|
// FIXME: add input transformation API to KWayland::Server::SeatInterface for touch input
|
|
|
|
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] {
|
|
|
|
if (focus().isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (focus().data()->surface() != seat->focusedTouchSurface()) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
void TouchInputRedirection::insertId(qint32 internalId, qint32 kwaylandId)
|
2016-02-15 08:36:59 +00:00
|
|
|
{
|
|
|
|
m_idMapper.insert(internalId, kwaylandId);
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
qint32 TouchInputRedirection::mappedId(qint32 internalId)
|
2016-02-15 08:36:59 +00:00
|
|
|
{
|
|
|
|
auto it = m_idMapper.constFind(internalId);
|
|
|
|
if (it != m_idMapper.constEnd()) {
|
|
|
|
return it.value();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
void TouchInputRedirection::removeId(qint32 internalId)
|
2016-02-15 08:36:59 +00:00
|
|
|
{
|
|
|
|
m_idMapper.remove(internalId);
|
|
|
|
}
|
|
|
|
|
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;
|
2018-12-13 09:46:21 +00:00
|
|
|
m_touches++;
|
|
|
|
if (m_touches == 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;
|
|
|
|
}
|
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;
|
2018-09-15 00:00:24 +00:00
|
|
|
m_touches--;
|
|
|
|
if (m_touches == 0) {
|
|
|
|
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;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
waylandServer()->seat()->cancelTouchSequence();
|
|
|
|
m_idMapper.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TouchInputRedirection::frame()
|
|
|
|
{
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!inited()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
waylandServer()->seat()->touchFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|