Skip to content

fix: 适配PS鼠标类型的触控板#181

Merged
fly602 merged 1 commit intolinuxdeepin:masterfrom
fly602:master
Mar 10, 2026
Merged

fix: 适配PS鼠标类型的触控板#181
fly602 merged 1 commit intolinuxdeepin:masterfrom
fly602:master

Conversation

@fly602
Copy link
Copy Markdown
Contributor

@fly602 fly602 commented Mar 10, 2026

适配PS鼠标类型的触控板

Log:
PMS: BUG-352421
Influence: 输入设备-触控板

Summary by Sourcery

Extend touchpad handling to support PS-type mouse touchpads and update related dependencies.

New Features:

  • Support initializing touchpads from devices reported as mouse type when they expose libinput touchpad properties.

Bug Fixes:

  • Correctly detect and use libinput for PS-type mouse devices that function as touchpads by checking additional properties.

Enhancements:

  • Update copyright years and bump go-dbus-factory and go-lib module versions while removing an unused image resize dependency from go.mod.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR extends touchpad initialization logic to support PS-type mouse devices that behave like touchpads, refines the libinput usage detection, updates copyright years, and refreshes key module dependencies.

Sequence diagram for NewTouchpadFromDevInfo initialization with PS mouse support

sequenceDiagram
    actor Caller
    participant TouchpadPkg as TouchpadPackage
    participant DevInfo as DeviceInfo
    participant Utils as Utils

    Caller->>TouchpadPkg: NewTouchpadFromDevInfo(dev)
    alt dev is nil or (dev.Type not DevTypeTouchpad and not DevTypeMouse)
        TouchpadPkg-->>Caller: error Not a touchpad device
    else dev.Type is DevTypeTouchpad or DevTypeMouse
        TouchpadPkg->>Utils: IsPropertyExist(dev.Id, libinputPropTapEnabled)
        Utils-->>TouchpadPkg: isLibinputUsed
        alt not isLibinputUsed and dev.Type is DevTypeMouse
            TouchpadPkg->>Utils: IsPropertyExist(dev.Id, libinputPropButtonScrollingButton)
            Utils-->>TouchpadPkg: isLibinputUsedUpdated
        end
        TouchpadPkg-->>Caller: *Touchpad with isLibinputUsed
    end
Loading

Class diagram for Touchpad and DeviceInfo with updated initialization

classDiagram
    class DeviceInfo {
        int32 Id
        string Name
        int Type
    }

    class Touchpad {
        int32 Id
        string Name
        bool isLibinputUsed
        +NewTouchpad(id int32) Touchpad, error
        +NewTouchpadFromDevInfo(dev *DeviceInfo) Touchpad, error
    }

    class Utils {
        +IsPropertyExist(deviceId int32, property string) bool
    }

    class DevType {
        <<enumeration>>
        DevTypeTouchpad
        DevTypeMouse
    }

    class LibinputProperties {
        <<static>>
        libinputPropTapEnabled
        libinputPropButtonScrollingButton
    }

    DeviceInfo --> DevType : has
    Touchpad --> DeviceInfo : constructed_from
    Touchpad --> Utils : uses
    Touchpad --> LibinputProperties : checks_properties
Loading

File-Level Changes

Change Details Files
Extend touchpad construction to accept PS-type mouse devices and improve libinput feature detection.
  • Relax device type validation to accept both touchpad and mouse device types while still rejecting nil or unsupported devices with a more detailed error message including the device type.
  • Introduce intermediate isLibinputUsed logic that first checks libinput tap property and, when the device is a mouse without that property, falls back to checking the button scrolling property.
  • Pass the computed isLibinputUsed flag into the Touchpad struct instead of recomputing the property check inline.
dxinput/touchpad.go
Update project metadata and Go module dependencies.
  • Extend SPDX copyright year range from 2018–2022 to 2018–2026.
  • Bump github.com/linuxdeepin/go-dbus-factory to a newer pseudo-version.
  • Bump github.com/linuxdeepin/go-lib to a newer pseudo-version.
  • Remove the unused github.com/nfnt/resize dependency and refresh go.sum accordingly.
dxinput/touchpad.go
go.mod
go.sum

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In NewTouchpadFromDevInfo, the error branch still dereferences dev even when it may be nil (dev == nil || ...), so split the nil check and return early to avoid a potential panic.
  • Since DevTypeMouse is now accepted, consider adjusting the error message in NewTouchpadFromDevInfo ("Not a touchpad device") to better reflect the broader set of supported device types for easier debugging.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `NewTouchpadFromDevInfo`, the error branch still dereferences `dev` even when it may be nil (`dev == nil || ...`), so split the nil check and return early to avoid a potential panic.
- Since `DevTypeMouse` is now accepted, consider adjusting the error message in `NewTouchpadFromDevInfo` ("Not a touchpad device") to better reflect the broader set of supported device types for easier debugging.

## Individual Comments

### Comment 1
<location path="dxinput/touchpad.go" line_range="56-57" />
<code_context>
 func NewTouchpadFromDevInfo(dev *DeviceInfo) (*Touchpad, error) {
-	if dev == nil || dev.Type != DevTypeTouchpad {
-		return nil, fmt.Errorf("Not a touchpad device(%d - %s)", dev.Id, dev.Name)
+	if dev == nil || (dev.Type != DevTypeTouchpad && dev.Type != DevTypeMouse) {
+		return nil, fmt.Errorf("Not a touchpad device(%d - %s), type: %v", dev.Id, dev.Name, dev.Type)
+	}
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard clause dereferences dev when it may be nil, leading to a potential panic.

Because `dev` can be nil in this branch, formatting the error string still dereferences `dev.Id`, `dev.Name`, and `dev.Type`, which will panic. Please handle the `dev == nil` case separately (e.g., with a simpler error) or only build the detailed error when `dev != nil`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

适配PS鼠标类型的触控板

Log:
PMS: BUG-352421
Influence: 输入设备-触控板
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码主要是对触摸板(touchpad)输入处理逻辑的更新,同时更新了依赖库版本。以下是对该 diff 的详细审查意见:

1. 代码逻辑审查

变更点:NewTouchpadFromDevInfo 函数

  • 设备类型检查放宽

    • 原逻辑:只接受 DevTypeTouchpad 类型的设备。
    • 新逻辑:接受 DevTypeTouchpadDevTypeMouse 类型的设备。
    • 意见:这是一个较大的逻辑变更。通常鼠标和触摸板的处理逻辑不同(例如触摸板支持手势、轻触点击等,而鼠标主要支持按键和滚轮)。将鼠标纳入 Touchpad 结构体处理可能会导致语义上的混淆。
    • 建议:确认是否真的需要将鼠标逻辑复用触摸板的代码结构。如果是为了支持某些特定的触摸板模拟鼠标的场景,或者某些特定硬件上报类型错误,建议添加详细的注释说明为什么鼠标会被当作 Touchpad 处理。如果是为了统一输入设备管理,建议考虑重构,使用一个更通用的 InputDevice 接口或基类,而不是让 Touchpad 兼容鼠标。
  • Libinput 检测逻辑优化

    • 原逻辑:无条件检查 libinputPropTapEnabled 属性是否存在。
    • 新逻辑:如果是鼠标类型,则检查 libinputPropButtonScrollingButton 属性;否则检查 libinputPropTapEnabled
    • 意见:这个修改是为了适配上述放宽的设备类型检查,逻辑上是自洽的。它针对不同设备类型检查了其特有的 libinput 属性,这是合理的。

2. 代码质量与规范

  • 错误处理改进

    • 原逻辑if dev == nil || dev.Type != ...,如果 dev 为 nil,后续 dev.Id 等操作会导致 panic(尽管短路逻辑可能避免,但在格式化字符串中引用是不安全的)。
    • 新逻辑:将 dev == nil 的检查单独列出,并返回明确的错误信息 "device info is nil"
    • 意见非常好。这提高了代码的健壮性,避免了潜在的空指针 panic 风险,符合 Go 语言的错误处理最佳实践。
  • 错误信息格式化

    • 新的错误信息 unsupported device type: %v (device: %d - %s) 更加详细,包含了设备类型、ID 和名称,有助于调试。
    • 意见良好

3. 代码性能

  • 属性检查
    • utils.IsPropertyExist 通常涉及系统调用(如 D-Bus 或读取文件)。虽然这里只是增加了一个条件分支,但整体性能影响可忽略不计。
    • 意见:无需优化。

4. 代码安全

  • 空指针解引用

    • 如前所述,通过提前检查 dev == nil,修复了潜在的空指针解引用风险。
    • 意见安全
  • 版权年份更新

    • SPDX-FileCopyrightText: 2018 - 2026
    • 意见:这通常是为了维护代码的版权有效期,属于常规维护,不影响代码逻辑安全性。

5. 依赖管理

  • 依赖更新
    • github.com/linuxdeepin/go-dbus-factory
    • github.com/linuxdeepin/go-lib
    • 移除了 github.com/nfnt/resize
    • 意见
      • 移除未使用的依赖是好的实践,减少了潜在的攻击面和编译后的二进制体积。
      • 更新内部依赖(deepin 相关库)通常是为了配合新功能的开发或修复上游 bug。需要确保这些新版本的库是经过测试且稳定的。

总结与建议

  1. 核心建议:最需要关注的是将鼠标(DevTypeMouse)纳入触摸板(Touchpad)处理逻辑这一变更。

    • 风险:如果后续代码中有针对触摸板特有功能(如禁用触摸板、调整灵敏度、手势操作)的逻辑,当设备是鼠标时,这些逻辑可能会产生意外行为(例如尝试给鼠标设置灵敏度参数失败,或者错误地禁用了鼠标)。
    • 改进建议:建议在 Touchpad 结构体中增加一个字段(如 DeviceType),明确记录当前实例是基于触摸板还是鼠标创建的。在后续的方法实现中,根据这个类型字段进行区分处理,避免对鼠标执行不适用于它的操作。
  2. 代码细节

    • 代码的健壮性(空指针检查)和可读性(错误信息)都有所提升,值得肯定。
  3. 测试建议

    • 必须针对鼠标设备进行充分测试,确保在新逻辑下鼠标的各项功能(移动、点击、滚动)正常工作,且不会触发触摸板的特定设置逻辑。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fly602 fly602 merged commit 7f0ab8f into linuxdeepin:master Mar 10, 2026
17 of 18 checks passed
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.

3 participants