Skip to content

feat: support touchpad expand switch - #1267

Open
fly602 wants to merge 1 commit into
linuxdeepin:release/2500from
fly602:codex/feat-touchpad-expand-enable-release-2500
Open

fly602 wants to merge 1 commit into
linuxdeepin:release/2500from
fly602:codex/feat-touchpad-expand-enable-release-2500

Conversation

@fly602

@fly602 fly602 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

变更内容

  • 新增 SetTouchpadExpandEnable 方法及 ExpandIsExist、ExpandEnable 属性。
  • 全局触控板开关继续使用 udev 规则,防误触开关通过 /proc/uos/touchpad_expand_switch 控制。
  • 根据全局触控板状态和用户配置同步防误触内核节点。
  • 当前版本未引入 security-loader、Polkit 权限接口等安全启动相关改动。

验证

  • GOCACHE=/tmp/gocache-dde-daemon-release GOTMPDIR=/tmp go test ./system/inputdevices1
  • git diff --cached --check

PMS: TASK-395683

Summary by Sourcery

Support the touchpad anti-mistouch expansion switch while preserving global touchpad control through udev rules.

New Features:

  • Add D-Bus support for enabling or disabling the touchpad anti-mistouch expansion switch.
  • Expose touchpad expansion availability and enabled state through properties and persistent configuration.

Bug Fixes:

  • Synchronize the anti-mistouch kernel switch with the global touchpad state and user preference during startup and configuration changes.

Enhancements:

  • Improve touchpad configuration handling with validation and safe access to the touchpad instance.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602

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

@sourcery-ai

sourcery-ai Bot commented Sep 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds D-Bus and DConfig support for a touchpad anti-misclick preference, then synchronizes the /proc/uos/touchpad_expand_switch kernel node with that preference and the global touchpad state across startup and runtime changes, without introducing security-loader or Polkit changes.

Sequence diagram for touchpad expand synchronization

sequenceDiagram
    participant Client
    participant Touchpad
    participant DConfig
    participant Proc as KernelProcNode

    Client->>Touchpad: SetTouchpadExpandEnable(enabled)
    Touchpad->>DConfig: SetValue(touchpadExpandEnabled, enabled)
    Touchpad->>Proc: WriteFile(enable or disable)
    Proc-->>Touchpad: Updated switch state
    Touchpad-->>Client: ExpandEnable property changed

    DConfig->>Touchpad: ValueChanged(touchpadEnabled or touchpadExpandEnabled)
    Touchpad->>DConfig: Value(touchpadExpandEnabled)
    Touchpad->>Proc: WriteFile(globalEnabled && preference)
    Touchpad-->>Client: ExpandEnable or ExpandIsExist changed
Loading

Flow diagram for startup touchpad expand state restoration

flowchart TD
    A[Touchpad initialization] --> B{Expand switch exists?}
    B -- No --> C[Set ExpandIsExist false]
    B -- Yes --> D[Read touchpadEnabled and touchpadExpandEnabled]
    D --> E[Compute globalEnabled && preference]
    E --> F[Write enable or disable to /proc/uos/touchpad_expand_switch]
    F --> G[Publish ExpandIsExist and ExpandEnable]
Loading

File-Level Changes

Change Details Files
Expose and persist the touchpad anti-misclick preference through D-Bus and DConfig.
  • Add the SetTouchpadExpandEnable D-Bus method.
  • Add ExpandIsExist and ExpandEnable properties with change notifications.
  • Generalize DConfig reads and writes to support both touchpad settings, including type validation.
misc/dsg-configs/org.deepin.dde.daemon.inputdevices.json
system/inputdevices1/exported_methods_auto.go
system/inputdevices1/inputdevices.go
system/inputdevices1/inputdevices_dbusutil.go
system/inputdevices1/touchpad.go
Synchronize the kernel anti-misclick switch with global touchpad state and user preference.
  • Detect the /proc/uos/touchpad_expand_switch node and expose its availability.
  • Write enable/disable commands to the proc node while preserving the user preference when the global touchpad is disabled.
  • Apply synchronization during startup, global touchpad changes, preference changes, and explicit D-Bus updates.
system/inputdevices1/inputdevices.go
system/inputdevices1/touchpad.go
Harden touchpad initialization and configuration handling for the new synchronization flow.
  • Safely retrieve the touchpad instance before initialization work.
  • Validate DConfig value types and handle configuration read failures with warnings and defaults.
system/inputdevices1/inputdevices.go
system/inputdevices1/touchpad.go

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="system/inputdevices1/touchpad.go" line_range="96-98" />
<code_context>
+		return dbusutil.ToError(err)
+	}
+	if err := t.syncTouchpadExpand(enabled); err != nil {
+		logger.Warning("failed to sync touchpad expand:", err)
+	}
+	return nil
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** SetTouchpadEnable returns success after the global udev operation succeeds even when syncTouchpadExpand fails, so callers receive no error while the anti-mistouch kernel node remains in the wrong state.

**Triggers:** When /proc/uos/touchpad_expand_switch exists but cannot be written.

**Suggested fix:** Return the synchronization error from SetTouchpadEnable, or explicitly document and expose the operation as best-effort rather than reporting success.

```suggestion
	if err := t.syncTouchpadExpand(enabled); err != nil {
		return dbusutil.ToError(err)
	}
```
</issue_to_address>

### Comment 2
<location path="system/inputdevices1/touchpad.go" line_range="153-154" />
<code_context>
+// syncTouchpadExpand 根据全局触控板状态和 DConfig 偏好同步防误触开关。
+// 该函数只写 proc 节点,不更新 DConfig。
+func (t *Touchpad) syncTouchpadExpand(globalEnabled bool) error {
+	if err := touchpadExpandExist(touchpadExpandSwitchFile); err != nil {
+		t.setPropExpandIsExist(false)
+		logger.Info("/proc/uos/touchpad_expand_switch not exist.")
+		return nil
+	}
+	t.setPropExpandIsExist(true)
+
+	expandEnabled, err := getDsgConf(_dsettingsTouchpadExpandEnabledKey)
+	if err != nil {
+		logger.Warning(err)
+		// DConfig 默认值为 true,读取失败时按默认值恢复实际状态。
+		expandEnabled = true
+	}
+	return t.setTouchpadExpandEnable(globalEnabled && expandEnabled, false)
+}
+
+func (t *Touchpad) setTouchpadExpandEnable(enabled bool, updateDsg bool) error {
+	logger.Infof("setTouchpadExpandEnable: %v", enabled)
+	if err := touchpadExpandExist(touchpadExpandSwitchFile); err != nil {
+		return err
+	}
+	t.setPropExpandIsExist(true)
</code_context>
<issue_to_address>
**issue (bug_risk):** setTouchpadExpandEnable returns before clearing ExpandIsExist when the proc node disappears after initialization, leaving the exported property permanently true even though the node no longer exists.

**Triggers:** When the proc node is removed or becomes inaccessible after a previous successful existence check.

**Suggested fix:** Set ExpandIsExist to false before returning the existence error, or centralize existence-state updates in the caller.

```suggestion
	if err := touchpadExpandExist(touchpadExpandSwitchFile); err != nil {
		t.setPropExpandIsExist(false)
		return err
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread system/inputdevices1/touchpad.go
Comment thread system/inputdevices1/touchpad.go
1. Add SetTouchpadExpandEnable and expand state properties.
2. Keep the global touchpad switch controlled by udev rules.
3. Sync the expand proc node with the global and user settings.

Log: Add support for the touchpad anti-mistouch switch

Influence:
1. Verify SetTouchpadExpandEnable writes /proc/uos/touchpad_expand_switch.
2. Disable the global touchpad and verify expand is disabled.
3. Re-enable the global touchpad and verify expand preference is restored.

feat: 支持触控板防误触开关

1. 新增 SetTouchpadExpandEnable 方法及防误触状态属性。
2. 全局触控板开关继续保持 udev 规则控制方案。
3. 根据全局开关和用户配置同步防误触内核节点。

Log: 支持触控板防误触功能开关

Influence:
1. 验证 SetTouchpadExpandEnable 能正确写入防误触节点。
2. 关闭全局触控板,验证防误触开关联动关闭。
3. 重新开启全局触控板,验证用户防误触配置恢复。

PMS: TASK-395683
@fly602
fly602 force-pushed the codex/feat-touchpad-expand-enable-release-2500 branch from 67f8eed to c75b01c Compare September 24, 2026 01:18
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 97 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 代码实现与 commit 目的一致,新增触控板防误触开关功能逻辑清晰,错误处理完善,无安全漏洞。存在少量代码结构优化空间。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. system/inputdevices1/touchpad.go:182 - touchpadExpandExist 函数接收 filePath 参数但仅与常量 touchpadExpandSwitchFile 比较验证,参数化设计冗余,所有调用方均传入相同常量。建议简化为无参函数或直接内联检查。
  2. system/inputdevices1/inputdevices.go:286 - 在 _dsettingsTouchpadExpandEnabledKey case 中,代码读取 DConfig 值仅用于类型校验,未使用实际值。随后 syncTouchpadExpand 内部再次读取相同 DConfig 值,存在冗余读取。
  3. misc/dsg-configs/org.deepin.dde.daemon.inputdevices.json:13 - dconfig JSON 中 name 字段 "touchpad_Expand Enabled" 大小写不一致(Expand 首字母大写),建议统一命名风格。

建议: ['dconfig JSON 中 name 字段 "touchpad_Expand Enabled" 大小写不一致(Expand 首字母大写),建议统一为 "touchpad Expand Enabled" 或 "touchpad_expand_enabled"。']


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 暂无代码示例

本报告由 AI 代码审查工具自动生成

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.

2 participants