-
Notifications
You must be signed in to change notification settings - Fork 35
fix: resolve touch screen scrolling and clicking issues in bluetooth … #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yixinshark
merged 1 commit into
linuxdeepin:master
from
yixinshark:fix-bluetoothTouchScreen
Mar 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| #include "touchscrollfilter.h" | ||
|
|
||
| #include <QEvent> | ||
| #include <QTouchEvent> | ||
| #include <QMouseEvent> | ||
| #include <QScrollBar> | ||
| #include <QApplication> | ||
|
|
||
| TouchScrollFilter::TouchScrollFilter(QAbstractScrollArea *area) | ||
| : QObject(area) | ||
| , m_area(area) | ||
| , m_isDrag(false) | ||
| { | ||
| if (m_area) { | ||
| m_area->viewport()->setAttribute(Qt::WA_AcceptTouchEvents, true); | ||
| m_area->setAttribute(Qt::WA_AcceptTouchEvents, true); | ||
| m_area->viewport()->installEventFilter(this); | ||
| } | ||
| } | ||
|
|
||
| bool TouchScrollFilter::eventFilter(QObject *watched, QEvent *event) | ||
| { | ||
| if (!m_area) | ||
| return QObject::eventFilter(watched, event); | ||
|
|
||
| const QEvent::Type type = event->type(); | ||
| if (type != QEvent::TouchBegin && type != QEvent::TouchUpdate && | ||
| type != QEvent::TouchEnd && type != QEvent::TouchCancel) { | ||
| return QObject::eventFilter(watched, event); | ||
| } | ||
|
|
||
| QTouchEvent *te = static_cast<QTouchEvent *>(event); | ||
| if (te->points().isEmpty()) { | ||
| event->accept(); | ||
| return true; | ||
| } | ||
|
|
||
| QEventPoint pt = te->points().first(); | ||
|
|
||
| switch (type) { | ||
| case QEvent::TouchBegin: { | ||
| m_lastPos = pt.globalPosition(); | ||
| m_isDrag = false; | ||
| break; | ||
| } | ||
| case QEvent::TouchUpdate: { | ||
| qreal deltaY = pt.globalPosition().y() - m_lastPos.y(); | ||
| qreal deltaX = pt.globalPosition().x() - m_lastPos.x(); | ||
|
|
||
| if (!m_isDrag && (qAbs(deltaY) >= QApplication::startDragDistance() || qAbs(deltaX) >= QApplication::startDragDistance())) { | ||
| m_isDrag = true; | ||
| } | ||
|
|
||
| if (m_isDrag) { | ||
| if (qAbs(deltaY) > 0 && m_area->verticalScrollBar()) { | ||
| m_area->verticalScrollBar()->setValue(m_area->verticalScrollBar()->value() - deltaY); | ||
| } | ||
| if (qAbs(deltaX) > 0 && m_area->horizontalScrollBar()) { | ||
| m_area->horizontalScrollBar()->setValue(m_area->horizontalScrollBar()->value() - deltaX); | ||
| } | ||
| m_lastPos = pt.globalPosition(); | ||
| } | ||
| break; | ||
| } | ||
| case QEvent::TouchEnd: { | ||
|
yixinshark marked this conversation as resolved.
|
||
| if (!m_isDrag) { | ||
| // Determine the correct target widget for the click | ||
| QWidget *target = m_area->viewport(); | ||
| QPoint widgetPos = pt.position().toPoint(); | ||
|
|
||
| // If it's a QScrollArea, the content widget is usually a child of the viewport | ||
| if (QWidget *child = target->childAt(widgetPos)) { | ||
| target = child; | ||
| widgetPos = target->mapFrom(m_area->viewport(), widgetPos); | ||
| } | ||
|
|
||
| QMouseEvent press(QEvent::MouseButtonPress, widgetPos, pt.globalPosition(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); | ||
| QCoreApplication::sendEvent(target, &press); | ||
| QMouseEvent release(QEvent::MouseButtonRelease, widgetPos, pt.globalPosition(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); | ||
| QCoreApplication::sendEvent(target, &release); | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
| break; | ||
| } | ||
|
|
||
| event->accept(); | ||
| return true; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| #ifndef TOUCHSCROLLFILTER_H | ||
| #define TOUCHSCROLLFILTER_H | ||
|
|
||
| #include <QObject> | ||
| #include <QPointF> | ||
| #include <QAbstractScrollArea> | ||
|
|
||
| class TouchScrollFilter : public QObject | ||
| { | ||
| public: | ||
| explicit TouchScrollFilter(QAbstractScrollArea *area); | ||
| ~TouchScrollFilter() override = default; | ||
|
|
||
| protected: | ||
| bool eventFilter(QObject *watched, QEvent *event) override; | ||
|
|
||
| private: | ||
| QAbstractScrollArea *m_area; | ||
| QPointF m_lastPos; | ||
| bool m_isDrag; | ||
| }; | ||
|
|
||
| #endif // TOUCHSCROLLFILTER_H |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.