fix: resolve popup cursor display incorrect as arrow when hovering links#444
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts the global event filter’s cursor handling so that popup cursors are derived from the native window handle’s effective cursor shape rather than the forwarding QWidget, preventing Wayland popups from incorrectly resetting to Arrow when hovering links. Sequence diagram for updated cursor handling on popup hoversequenceDiagram
actor User
participant WaylandCompositor
participant QWidgetWindow
participant RootQWidget as RootQWidget
participant EventFilter
participant QWindowHandle as QWindowHandle
participant PluginPopup
User->>WaylandCompositor: Move pointer over hyperlink in popup
WaylandCompositor->>QWidgetWindow: Pointer move
QWidgetWindow->>RootQWidget: CursorChange event (forwarded)
RootQWidget->>EventFilter: eventFilter(widget, CursorChange)
EventFilter->>RootQWidget: widget->window()
EventFilter->>QWindowHandle: window()->windowHandle()
EventFilter->>QWindowHandle: cursor().shape()
QWindowHandle-->>EventFilter: effective cursorShape (PointingHandCursor)
EventFilter->>PluginPopup: requestSetCursor(cursorShape)
PluginPopup->>WaylandCompositor: Update popup cursor
WaylandCompositor-->>User: Pointer shown as PointingHandCursor
Class diagram for updated EventFilter cursor handlingclassDiagram
class EventFilter {
+bool eventFilter(QObject* watched, QEvent* event)
-void handleCursorChange(QWidget* widget)
}
class QWidget {
+QWidget* window()
+QCursor cursor()
}
class QWindow {
+QCursor cursor()
+QWindow* windowHandle()
}
class PluginPopup {
+static PluginPopup* getWithoutCreating(QWindow* windowHandle)
+void requestSetCursor(int cursorShape)
}
EventFilter ..> QWidget : observes
QWidget ..> QWindow : window
QWindow <.. PluginPopup : lookup_by_windowHandle
EventFilter ..> PluginPopup : emits_requestSetCursor
EventFilter ..> QWindow : reads_cursor_via_windowHandle
QWidget ..> QWindow : windowHandle (via window()->windowHandle())
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
EventFilter::handleCursorChange,windowHandleis dereferenced without a null check; consider guarding againstwidget->window()->windowHandle()returningnullptrto avoid a potential crash in cases where the widget has not yet been backed by a native window.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `EventFilter::handleCursorChange`, `windowHandle` is dereferenced without a null check; consider guarding against `widget->window()->windowHandle()` returning `nullptr` to avoid a potential crash in cases where the widget has not yet been backed by a native window.
## Individual Comments
### Comment 1
<location path="src/loader/widgetplugin.cpp" line_range="82" />
<code_context>
auto windowHandle = widget->window()->windowHandle();
if (auto pluginPopup = Plugin::PluginPopup::getWithoutCreating(windowHandle)) {
- Qt::CursorShape cursorShape = widget->cursor().shape();
+ Qt::CursorShape cursorShape = windowHandle->cursor().shape();
Q_EMIT pluginPopup->requestSetCursor(static_cast<int>(cursorShape));
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Potential null dereference when accessing windowHandle->cursor().
Switching from `widget->cursor()` (safe for a non-null widget) to `windowHandle->cursor()` introduces a crash risk if `widget->window()->windowHandle()` returns `nullptr` (e.g., before the native window exists). Please add a null check before using `windowHandle->cursor().shape()`, and either fall back to `widget->cursor()` or return early when no handle is available.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
By default, Qt's QWidgetWindow forwards unhandled events (like CursorChange) to its top-level QWidget. If the global EventFilter monitors all widgets indiscriminately, it will intercept the forwarded event on the root widget and wrongly capture its ArrowCursor fallback value, thereby overwriting the correct PointingHand cursor globally. Instead of evaluating the widget's personal cursor state when a CursorChange happens, we now read the globally computed cursor shape straight from the target native windowHandle, ensuring Wayland popups consistently reflect the correct pointer shape. 修复悬浮超链接时气泡游标异常显示为箭头的问题 Qt 内部窗口事件回传机制会导致系统原生的 QWindow 将自身游标变化转发给底下的 最顶层 QWidget 容器。因为原事件监听器无差别捕获所有由于转发而受到的游标改变 信号,而顶层容器并未独立设过游标(呈现默认箭头),导致在捕获后向 Wayland 误传 了箭头重置。 通过将取值对象从转发目标(Widget小组件自身)改为实际的载体原生窗口(WindowHandle), 彻底绕过组件树转发污染,使得弹窗在 Wayland 环境下可以随时反馈准确的游标状态。 Log: resolve popup cursor display incorrect as arrow when hovering links
0b3d1de to
fb2c311
Compare
deepin pr auto review这段代码的 diff 主要是修改了版权年份和一行获取光标形状的逻辑。下面我将从语法逻辑、代码质量、代码性能和代码安全四个方面进行审查: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
总结与改进建议这次修改主要是逻辑上的调整,语法没有问题。主要关注点在于光标获取对象的变更。 改进建议:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
By default, Qt's QWidgetWindow forwards unhandled events (like CursorChange) to its top-level QWidget. If the global EventFilter monitors all widgets indiscriminately, it will intercept the forwarded event on the root widget and wrongly capture its ArrowCursor fallback value, thereby overwriting the correct PointingHand cursor globally.
Instead of evaluating the widget's personal cursor state when a CursorChange happens, we now read the globally computed cursor shape straight from the target native windowHandle, ensuring Wayland popups consistently reflect the correct pointer shape.
修复悬浮超链接时气泡游标异常显示为箭头的问题
Qt 内部窗口事件回传机制会导致系统原生的 QWindow 将自身游标变化转发给底下的
最顶层 QWidget 容器。因为原事件监听器无差别捕获所有由于转发而受到的游标改变
信号,而顶层容器并未独立设过游标(呈现默认箭头),导致在捕获后向 Wayland 误传
了箭头重置。
通过将取值对象从转发目标(Widget小组件自身)改为实际的载体原生窗口(WindowHandle), 彻底绕过组件树转发污染,使得弹窗在 Wayland 环境下可以随时反馈准确的游标状态。
Log: resolve popup cursor display incorrect as arrow when hovering links
Summary by Sourcery
Bug Fixes: