aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Flöser <[email protected]>2018-12-01 14:52:47 +0100
committerMartin Flöser <[email protected]>2018-12-13 18:55:46 +0100
commit070b46f455667d0f9ddbccffc1a43f6a44a25f6d (patch)
treedcef5d27efb5f6b7376de92828f892f0c047c65f
parentdd55a59d8144a158941bdffb6be8b755bb712c54 (diff)
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
-rw-r--r--CMakeLists.txt1
-rw-r--r--autotests/integration/touch_input_test.cpp25
-rw-r--r--input.cpp2
-rw-r--r--touch_hide_cursor_spy.cpp65
-rw-r--r--touch_hide_cursor_spy.h40
5 files changed, 133 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 63b5157..fd5246e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -483,6 +483,7 @@ set(kwin_KDEINIT_SRCS
libinput/events.cpp
libinput/libinput_logging.cpp
udev.cpp
+ touch_hide_cursor_spy.cpp
)
include(ECMQtDeclareLoggingCategory)
diff --git a/autotests/integration/touch_input_test.cpp b/autotests/integration/touch_input_test.cpp
index aee34c3..89aef84 100644
--- a/autotests/integration/touch_input_test.cpp
+++ b/autotests/integration/touch_input_test.cpp
@@ -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");
diff --git a/input.cpp b/input.cpp
index 6f53343..d35333f 100644
--- a/input.cpp
+++ b/input.cpp
@@ -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);
diff --git a/touch_hide_cursor_spy.cpp b/touch_hide_cursor_spy.cpp
new file mode 100644
index 0000000..0cc13ab
--- /dev/null
+++ b/touch_hide_cursor_spy.cpp
@@ -0,0 +1,65 @@
+/********************************************************************
+ KWin - the KDE window manager
+ This file is part of the KDE project.
+
+Copyright (C) 2018 Martin Flöser <[email protected]>
+
+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();
+}
+
+}
diff --git a/touch_hide_cursor_spy.h b/touch_hide_cursor_spy.h
new file mode 100644
index 0000000..08029dd
--- /dev/null
+++ b/touch_hide_cursor_spy.h
@@ -0,0 +1,40 @@
+/********************************************************************
+ KWin - the KDE window manager
+ This file is part of the KDE project.
+
+Copyright (C) 2018 Martin Flöser <[email protected]>
+
+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;
+};
+
+}