Visitar URL original
fix(inputdevices): skip touchpad settings apply when dconfig is temporarily unreadable by hualet · Pull Request #1271 · linuxdeepin/dde-daemon · GitHub
Skip to content

fix(inputdevices): skip touchpad settings apply when dconfig is temporarily unreadable - #1271

Open
hualet wants to merge 1 commit into
linuxdeepin:masterfrom
hualet:fix/touchpad-dconfig-unreadable
Open

hualet wants to merge 1 commit into
linuxdeepin:masterfrom
hualet:fix/touchpad-dconfig-unreadable

Conversation

@hualet

@hualet hualet commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1270

问题

common/dconfig/dcprop.go 的 Bool.Get() 在 dconfig 后端暂时不可读(dde-dconfig-daemon 开机激活竞态、服务重启、总线拥塞)时静默返回 false,inputdevices1/touchpad.go 的 apply 函数又把这个值无条件写入 X 设备属性。一次读失败窗口内的重应用会把触摸板设置整体清零:

libinput Tapping Enabled: 0
libinput Natural Scrolling Enabled: 0
libinput Disable While Typing Enabled: 0
libinput Scroll Method Enabled: 0, 0, 0

而此时 dconfig 中对应键值实际全部为 true,表现为轻点点击与双指滚动失效,且 apply 失败只有 Debugf 日志,生产环境不可见。

修改

  1. common/dconfig/dcprop.go:Bool 保留最近一次成功读取值(lastKnown),新增 GetWithError() (bool, error)——读失败返回缓存值及错误,调用方可区分"配置就是 false"与"值读不到";Get() 基于其实现;
  2. inputdevices1/touchpad.go:enableTapToClick / enableNaturalScroll / enableEdgeScroll / enableTwoFingerScroll / disableWhileTyping / enablePalmDetect 改用 GetWithError,读失败时跳过本次应用(设备属性保持现状)并记 Warning;apply 失败日志 Debugf → Warningf。

不改变任何正常路径的行为:dconfig 可读时应用逻辑与之前完全一致。

验证

  • 基于 6.1.107 构建并安装到受影响的真实机器(AMD 平台 + ELAN0662 i2c-hid,Deepin 25 / X11),重启后触摸板属性保持正确,此前反复出现的"轻点/双指滚动被清零"不再复现;
  • dconfig 可读路径行为验证:通过 dde-dconfig 切换 tapToClick(false→true),X 属性正确跟随。

Summary by Sourcery

Preserve touchpad state during transient dconfig read failures while maintaining existing behavior when configuration is available.

Bug Fixes:

  • Prevent touchpad settings from being reset when dconfig is temporarily unreadable by skipping the affected device-property updates until configuration reads succeed.

Enhancements:

  • Retain the last successfully read boolean configuration value and expose read errors so callers can distinguish unavailable settings from valid false values.
  • Promote touchpad configuration and device-application failures from debug to warning logs for better production visibility.

…rarily unreadable

common/dconfig Bool.Get() silently returned false when the dconfig
backend was temporarily unreadable (daemon startup race, service
restart, bus congestion), and the touchpad apply functions wrote that
value unconditionally. A single re-apply inside such a window reset
Tapping/NaturalScroll/DisableWhileTyping to 0 and collapsed the
mutually-exclusive scroll method bits to 0,0,0, breaking tap-to-click
and two-finger scrolling while dconfig still held true.

- common/dconfig: Bool keeps a last-known-good value, adds
  GetWithError() so callers can tell 'configured false' from unreadable
- inputdevices1: touchpad apply functions skip the apply and log a
  warning when the config read fails, leaving device properties intact

Log: dconfig 暂时不可读时触摸板设置被整体写为 false/零值,轻点与双指滚动失效

Fixes: linuxdeepin#1270
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hualet

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 Oct 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR prevents transient dconfig read failures from clearing touchpad settings by caching the last known boolean values, skipping affected applies when reads fail, and surfacing both configuration and device-application failures through warnings while preserving normal readable-path behavior.

Sequence diagram for safe touchpad settings application

sequenceDiagram
    participant Touchpad
    participant Bool
    participant DConfig
    participant XDevice
    participant Logger

    Touchpad->>Bool: GetWithError()
    Bool->>DConfig: GetValueBool(key)
    alt dconfig readable
        DConfig-->>Bool: value, nil
        Bool-->>Touchpad: value, nil
        Touchpad->>XDevice: EnableTapToClick(value)
        XDevice-->>Touchpad: success or error
        opt device apply error
            Touchpad->>Logger: Warningf(...)
        end
    else dconfig temporarily unreadable
        DConfig-->>Bool: lastKnown, error
        Bool-->>Touchpad: lastKnown, error
        Touchpad->>Logger: Warningf(...)
    end
Loading

File-Level Changes

Change Details Files
Preserve the last successfully read boolean value and expose backend read errors so callers no longer interpret transient dconfig failures as false.
  • Add cached last-known state to boolean properties.
  • Add GetWithError returning the cached value plus an error on unreadable backends.
  • Keep Get as a compatibility wrapper over the new behavior.
common/dconfig/dcprop.go
Make touchpad property application fail-safe during transient dconfig outages and improve failure visibility.
  • Use error-aware reads for tap-to-click, scrolling, disable-while-typing, and palm-detection settings.
  • Skip each affected device-property update when its configuration cannot be read, preserving the current device state.
  • Promote device-property application failures from debug to warning logs.
inputdevices1/touchpad.go

Assessment against linked issues

Issue Objective Addressed Explanation
#1270 Distinguish temporary dconfig read failures from legitimate false values by retaining the last successfully read boolean value and exposing read errors. ✅
#1270 Prevent touchpad settings from being written to X/libinput when any relevant dconfig value cannot be read, preserving the device's current attributes during temporary backend failures. ✅
#1270 Make skipped applications and touchpad property-application failures visible through warning-level logging rather than only debug logging. ✅

Possibly linked issues


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 reviewed your changes and they look great!


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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 79 分,大于 70 分通过阈值。本次变更修复了 dconfig 暂时不可读时触控板设置被错误写入设备的问题,方案合理,无安全漏洞。但存在一处逻辑遗漏(enableLeftHanded 未同步修改)和一处轻微的缓存一致性问题。

🔍 详细分析

1. 语法逻辑 ❌

评价: 一般 ❌ 不通过

潜在问题:

  1. inputdevices1/touchpad.go:335 - enableLeftHanded() 未同步使用 GetWithError(),与本次修改的其他 6 个函数不一致,导致左手习惯设置在 dconfig 不可读时仍被错误以 false 写入设备
  2. common/dconfig/dcprop.go:101 - Set() 方法成功写入后未更新 lastKnown,存在短暂的缓存不一致窗口

建议: 1.将 enableLeftHanded() 也改为使用 GetWithError() 并在错误时跳过应用
2.在 Set() 成功写入后更新 b.lastKnown = val,或接受该轻微不一致(因下次成功读取时会自动修正)


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. inputdevices1/touchpad.go:346 - GetWithError()+错误检查+日志+return 模式在 7 个函数中重复,可提取辅助函数

建议: 可考虑提取一个 applyBoolSetting(val *dconfig.Bool, applyFn func(bool) error, settingName string) 辅助函数来统一处理错误检查和应用逻辑,减少重复代码


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 性能良好,互斥锁使用正确,lastKnown 缓存避免了 dconfig 不可读时的冗余读取


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 本次变更无安全风险,变更内容仅涉及配置读取错误处理逻辑,不涉及用户输入处理、命令执行或权限操作


💡 改进建议代码示例

// 修复 enableLeftHanded 遗漏
func (tpad *Touchpad) enableLeftHanded() {
    enabled, err := tpad.LeftHanded.GetWithError()
    if err != nil {
        logger.Warningf("skip left-handed apply, dconfig unreadable: %v", err)
        return
    }
    for _, v := range tpad.devInfos {
        err := v.EnableLeftHanded(enabled)
        if err != nil {
            logger.Warningf("Enable left handed '%v - %v' failed: %v",
                v.Id, v.Name, err)
        }
    }
}

// 修复 Set() 中 lastKnown 缓存一致性(可选)
func (b *Bool) Set(val bool) bool {
    if b.Get() != val {
        b.mu.Lock()
        defer b.mu.Unlock()
        err := b.dc.SetValue(b.key, val)
        if err == nil {
            b.lastKnown = val
        }
        return err == nil
    }
    return true
}

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

@deepin-bot

deepin-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.1.108
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1274

@deepin-bot

deepin-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.1.109
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1281

@deepin-bot

deepin-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.1.110
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1283

@deepin-bot

deepin-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.1.111
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1286

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.

inputdevices 触摸板设置在 dconfig 暂时不可读时被整体应用为 false/零值(轻点/双指滚动失效)

2 participants