Skip to content

fix(desktop): Windows 触屏设备上标签页无法关闭(全应用 hover 样式失效) - #778

Open
jenken827 wants to merge 2 commits into
codedogQBY:mainfrom
jenken827:fix/windows-touchscreen-hover
Open

jenken827 wants to merge 2 commits into
codedogQBY:mainfrom
jenken827:fix/windows-touchscreen-hover

Conversation

@jenken827

Copy link
Copy Markdown

问题

Windows 触屏设备(如 Surface)上,打开多本书后顶部标签页没有关闭按钮,无法关闭指定的标签页。

tab 关闭按钮原实现为 hidden group-hover:flex(悬停显示),但在这类设备上它永远不会出现。进一步排查发现影响不止于此——全应用的 hover 交互(按钮悬停变色、悬停显现的控件等)在这类设备上全部失效,tab 关闭按钮只是唯一造成功能损失的入口。

根因

  1. Tailwind v4 将所有 hover: / group-hover: 工具类编译进 @media (hover: hover)(已在构建产物 CSS 中确认)。

  2. Chromium/WebView2 在带触摸屏的 Windows 设备上,指针设备枚举只上报触屏数字化仪。实测本应用 WebView 的媒体查询矩阵:

    查询 结果
    (hover: hover) / (any-hover: hover) false / false
    (pointer: fine) / (any-pointer: fine) false / false
    (pointer: coarse) / maxTouchPoints true / 10

    any-hover / any-pointer: fine 都是 false——鼠标在 WebView 的设备能力报告里完全不存在(即使正在使用鼠标),因此换用任何 CSS 写法(包括 any-* 查询)都无法恢复。鼠标事件本身(JS mousemove、:hover 状态)是正常的,坏的只是能力上报这一层。

修复

  1. 根因修复src-tauri,仅 Windows,无新增依赖,commit 1):启动时通过 Win32 Raw Input API 枚举指针设备,检测到鼠标或精确触摸板时,通过 WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS 追加 --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4,修正 WebView 的指针能力上报。
    • 不修改任何 CSS;
    • 无鼠标的纯触屏设备保持原行为;
    • 触屏能力保留(实测 maxTouchPoints 仍为 10,不影响双指手势)。
  2. 交互补强TabBar.tsx,commit 2):激活 tab 的关闭按钮常显(不再依赖 hover),非激活 tab 保留悬停显示;按钮补充多语言 tooltip(tabs.close,en/zh/zh-TW/ja/ko/fr/es 七种语言)。

验证

  • 修复前实测媒体查询:hover:hover=false, any-hover:hover=false, pointer:fine=false, any-pointer:fine=false;修复后全部正确翻转。
  • 通过 CDP 向页面注入与 TabItem 结构相同的探针并派发鼠标事件:修复前悬停时按钮 display 仍为 none;修复后正确翻转为 flex(CSS 一行未改)。
  • 真机(Surface + 鼠标)验证:多本书打开时关闭按钮悬停可见、激活 tab 常显、可正常关闭指定 tab。
  • cargo checktsc 通过;改动的 lint 告警均为存量问题(HEAD 上即存在)。
image image

注:本次代码修复和PR信息的提交由AI生成

…ouchscreen devices

On Windows machines with a touchscreen (e.g. Surface), Chromium's device
enumeration registers only the touch digitizer, so CSS media queries report
(hover: none) / (pointer: coarse) even while a mouse is in use — and
(any-hover: hover) / (any-pointer: fine) are false as well, so no CSS-side
query can recover. Tailwind v4 compiles every hover/group-hover utility into
@media (hover: hover), which left all hover styling in the app dead on such
devices, including the reader tab close button.

At startup, enumerate pointer devices via the Raw Input API; when a mouse or
precision touchpad is present, append blink-settings overrides through
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS so the WebView reports a fine,
hover-capable pointer. Touch capability is untouched (maxTouchPoints stays
intact) and touch-only devices keep the current behavior.
The tab close button only appeared on hover, and hover-only UI is unusable
when the webview reports no hover capability (see previous commit) — with
several books open there was no way to close a specific tab. Show the close
button permanently on the active tab, keep the hover-reveal behavior for
inactive tabs, and label the button with a localized tooltip (tabs.close)
in all supported languages.
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