Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 070b46f4 authored by Martin Flöser's avatar Martin Flöser

Hide mouse cursor when interacting with touch screen

Summary:
On touch events the mouse cursor gets hidden, on next mouse event the
mouse cursor is shown again. This IMHO significantly improves the system
interaction if touch is the primary user interface.

Test Plan: Test case added and ctest passes

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D17280
parent dd55a59d
......@@ -483,6 +483,7 @@ set(kwin_KDEINIT_SRCS
libinput/events.cpp
libinput/libinput_logging.cpp
udev.cpp
touch_hide_cursor_spy.cpp
)
include(ECMQtDeclareLoggingCategory)
......
......@@ -45,6 +45,7 @@ private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void testTouchHidesCursor();
void testMultipleTouchPoints_data();
void testMultipleTouchPoints();
void testCancel();
......@@ -128,6 +129,30 @@ AbstractClient *TouchInputTest::showWindow(bool decorated)
return c;
}
void TouchInputTest::testTouchHidesCursor()
{
QCOMPARE(kwinApp()->platform()->isCursorHidden(), false);
quint32 timestamp = 1;
kwinApp()->platform()->touchDown(1, QPointF(125, 125), timestamp++);
QCOMPARE(kwinApp()->platform()->isCursorHidden(), true);
kwinApp()->platform()->touchDown(2, QPointF(130, 125), timestamp++);
kwinApp()->platform()->touchUp(2, timestamp++);
kwinApp()->platform()->touchUp(1, timestamp++);
// now a mouse event should show the cursor again
kwinApp()->platform()->pointerMotion(QPointF(0, 0), timestamp++);
QCOMPARE(kwinApp()->platform()->isCursorHidden(), false);
// touch should hide again
kwinApp()->platform()->touchDown(1, QPointF(125, 125), timestamp++);
kwinApp()->platform()->touchUp(1, timestamp++);
QCOMPARE(kwinApp()->platform()->isCursorHidden(), true);
// wheel should also show
kwinApp()->platform()->pointerAxisVertical(1.0, timestamp++);
QCOMPARE(kwinApp()->platform()->isCursorHidden(), false);
}
void TouchInputTest::testMultipleTouchPoints_data()
{
QTest::addColumn<bool>("decorated");
......
......@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "keyboard_input.h"
#include "pointer_input.h"
#include "touch_input.h"
#include "touch_hide_cursor_spy.h"
#include "client.h"
#include "effects.h"
#include "gestures.h"
......@@ -1754,6 +1755,7 @@ void InputRedirection::setupInputFilters()
installInputEventFilter(new VirtualTerminalFilter);
}
if (waylandServer()) {
installInputEventSpy(new TouchHideCursorSpy);
installInputEventFilter(new TerminateServerFilter);
installInputEventFilter(new DragAndDropInputFilter);
installInputEventFilter(new LockScreenFilter);
......
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2018 Martin Flöser <mgraesslin@kde.org>
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_hide_cursor_spy.h"
#include "main.h"
#include "platform.h"
namespace KWin
{
void TouchHideCursorSpy::pointerEvent(MouseEvent *event)
{
Q_UNUSED(event)
showCursor();
}
void TouchHideCursorSpy::wheelEvent(KWin::WheelEvent *event)
{
Q_UNUSED(event)
showCursor();
}
void TouchHideCursorSpy::touchDown(quint32 id, const QPointF &pos, quint32 time)
{
Q_UNUSED(id)
Q_UNUSED(pos)
Q_UNUSED(time)
hideCursor();
}
void TouchHideCursorSpy::showCursor()
{
if (!m_cursorHidden) {
return;
}
m_cursorHidden = false;
kwinApp()->platform()->showCursor();
}
void TouchHideCursorSpy::hideCursor()
{
if (m_cursorHidden) {
return;
}
m_cursorHidden = true;
kwinApp()->platform()->hideCursor();
}
}
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2018 Martin Flöser <mgraesslin@kde.org>
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/>.
*********************************************************************/
#pragma once
#include "input_event_spy.h"
namespace KWin
{
class TouchHideCursorSpy : public InputEventSpy
{
public:
void pointerEvent(KWin::MouseEvent *event) override;
void wheelEvent(KWin::WheelEvent *event) override;
void touchDown(quint32 id, const QPointF &pos, quint32 time) override;
private:
void showCursor();
void hideCursor();
bool m_cursorHidden = false;
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment