Skip to content

perf: avoid touch-scroll guard work for unrelated UI events - #693

Open
AliceJump wants to merge 1 commit into
masterfrom
codex/okef-touch-event-startup
Open

AliceJump wants to merge 1 commit into
masterfrom
codex/okef-touch-event-startup

Conversation

@AliceJump

@AliceJump AliceJump commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Why

The pinned framework's global touch-scroll click guard walks widget ancestry and queries its scroller before checking the event type. During startup it receives large numbers of paint, layout, style and other events that its handler always returns unchanged.

Changes

  • Add an early return for events other than MouseButtonPress and MouseButtonRelease.
  • Delegate both handled mouse events to the original framework function with the original objects.
  • Keep the patch idempotent and install it before the application constructs its widgets.

The original drag detection, synthetic-release handling, pressed-state reset and QObject lifetime checks remain authoritative. This small compatibility patch follows the contract in locked ok-script 2.0.22.

Validation

  • Standalone Windows checkout of base 2379d139 with only this patch: gui-overlays 186/186 passed, including all 12 new tests.
  • Real Qt tests compare the wrapper against the original handler for dragging, scrolling, ordinary/fake releases, double clicks, external targets, destruction and subsequent normal clicks through the application's event filter.
  • Non-mouse events are verified not to invoke the old handler or widget ancestry checks.
  • Linux locked Qt focused tests: 12/12 passed.
  • Test inventory: 179 files across 18 groups; Ruff check/format and git diff --check pass.

This PR can be reviewed independently of #691 (language loading) and #692 (unvisited task pages). Application startup measurements are performed separately from instrumented profiling.

Summary by CodeRabbit

  • 问题修复
    • 改善触摸滚动时的点击处理,减少滚动期间误触;滚动结束后仍可正常点击。
    • 改善拖动、双击及界面滚动区域关闭等情况下的交互表现。

Return immediately for events the pinned guard does not handle, and delegate
mouse press/release handling unchanged. Verify native drag, release,
pressed-state and QObject lifetime behavior with real Qt objects.
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

新增触摸滚动事件过滤补丁,并在启动时安装。补丁将鼠标按下和释放事件交给原处理器,跳过其他事件。新增 Qt 测试,并将测试加入 gui-overlays 测试组。

Changes: 触摸滚动点击保护

层 / 文件 摘要
补丁安装与事件过滤
src/patches/touch_scroll_event_filter_patch.py, src/patches/startup_patches.py
启动补丁安装器现在调用新补丁。补丁只将鼠标按下和释放事件交给原事件处理器,并通过标记避免重复包装。
事件过滤测试与测试组登记
tests/TestTouchScrollEventFilterPatch.py, scripts/testing/run_ci_test_group.py
新增 Qt 测试,覆盖事件委派、拖动与滚动状态、伪造释放、双击、对象生命周期及全局过滤器交互。测试运行器将该测试加入 gui-overlays 组。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Suggested reviewers: eeeeeeeedison, luqing233

Merge Risk: Minimal · up to 2106c

This change skips touch-scroll guard work for unrelated UI events and keeps the existing press and release handling. No merge-blocking risk was identified, and new tests compare the patched behavior with the original.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“perf: avoid touch-scroll guard work for unrelated UI events”准确描述了本 PR 的主要变更。变更在 touch_scroll_event_filter_patch.py 中为 _TouchScrollClickGuard.eventFilter 增加早期返回:非鼠标按下或释放事件直接返回 False,不再执行控件祖先和滚动区域检查。…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Pr 范围一致性 Passed PR #693(作者 AliceJump)的标题和描述声明的是性能优化:对非鼠标事件提前返回,并把鼠标按下和释放事件委托给原始 _TouchScrollClickGuard.eventFilter。实际 diff 与该声明一致。 已核对的变更: - src/patches/touch_scroll_event_filter_patch.py(新增):包装器对 MouseButtonPres…
Full details: Title check

Explanation

标题“perf: avoid touch-scroll guard work for unrelated UI events”准确描述了本 PR 的主要变更。变更在 touch_scroll_event_filter_patch.py 中为 _TouchScrollClickGuard.eventFilter 增加早期返回:非鼠标按下或释放事件直接返回 False,不再执行控件祖先和滚动区域检查。PR 目标也明确说明了这一点,且标题与性能优化意图一致。

Full details: Pr 范围一致性

Explanation

PR #693(作者 AliceJump)的标题和描述声明的是性能优化:对非鼠标事件提前返回,并把鼠标按下和释放事件委托给原始 _TouchScrollClickGuard.eventFilter。实际 diff 与该声明一致。 已核对的变更: - src/patches/touch_scroll_event_filter_patch.py(新增):包装器对 MouseButtonPress 和 MouseButtonRelease 之外的事件直接返回 False,其他事件调用原函数并传入原始对象。幂等标记 _okef_mouse_events_only 已存在。 - src/patches/startup_patches.py:在启动补丁中调用安装函数。描述中“在应用构造控件前安装”已披露。 - scripts/testing/run_ci_test_group.py:把 TestTouchScrollEventFilterPatch.py 加入 gui-overlays 测试组。这是测试清单变更,描述中的测试清单已覆盖。 - tests/TestTouchScrollEventFilterPatch.py(新增):与描述中的测试说明一致。 行为对照(linked repo AliceJump/ok-script,HEAD 428bcd56,ok/ui/qt/util/touch_scroll.py 第 9–85 行):原始 eventFilter 对非鼠标事件的所有路径都返回 False,包括 _active、isValid、_is_content_widget 的检查分支。因此提前返回不改变判定结果,只省去祖先遍历和 scroller 查询。鼠标事件的分支(拖动判定、伪造释放、pressed 状态重置、QObject 生命周期检查)仍由原函数处理,未被修改。 失败条件要求“PR 声称仅增加诊断、日志或可视化,但实际修改核心判定规则等,且未披露”。本 PR 声称的是性能优化,不是诊断类变更,因此该失败条件不适用。实际的行为变化(事件分派顺序和启动时的全局补丁安装)均已在描述中披露。 说明:我未核对 PR 描述中提到的 locked ok-script 2.0.22 版本,仅核对了 linked repo 的 HEAD。该差异不影响本范围一致性判断。

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2379d13 and 2106c81.

Files selected for processing: 4

  • scripts/testing/run_ci_test_group.py
  • src/patches/startup_patches.py
  • src/patches/touch_scroll_event_filter_patch.py
  • tests/TestTouchScrollEventFilterPatch.py
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant