Skip to content

feat(lockscreen): add keyboard focus navigation for power buttons#1139

Open
gugullll wants to merge 2 commits into
linuxdeepin:master-backup-20260717from
gugullll:fix/pms-294921-300951
Open

feat(lockscreen): add keyboard focus navigation for power buttons#1139
gugullll wants to merge 2 commits into
linuxdeepin:master-backup-20260717from
gugullll:fix/pms-294921-300951

Conversation

@gugullll

Copy link
Copy Markdown
Contributor

Add circular Tab/BackTab focus chain across lock, switch user, logout and power action buttons. Loop inside PowerList when opened as popup, break out to surrounding buttons when closed.

添加锁屏界面电源操作按钮的键盘焦点循环导航功能。

Log: 添加锁屏界面电源按钮键盘焦点导航
PMS: BUG-300951
Influence: 用户可通过Tab/Shift+Tab在锁屏界面所有电源操作按钮间切换焦点,
焦点按钮显示高亮边框。

Add circular Tab/BackTab focus chain across lock, switch user, logout
and power action buttons. Loop inside PowerList when opened as popup,
break out to surrounding buttons when closed.

添加锁屏界面电源操作按钮的键盘焦点循环导航功能。

Log: 添加锁屏界面电源按钮键盘焦点导航
PMS: BUG-300951
Influence: 用户可通过Tab/Shift+Tab在锁屏界面所有电源操作按钮间切换焦点,
焦点按钮显示高亮边框。

@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.

Sorry @gugullll, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gugullll

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

@deepin-ci-robot

Copy link
Copy Markdown

Hi @gugullll. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

EN: This PR improves lockscreen keyboard accessibility by adding a Tab/Shift+Tab focus chain across the shutdown-related action buttons, and by showing a focus highlight when buttons receive keyboard focus. It primarily wires focus traversal between the outer actions (lock/switch user/logout) and the inner PowerList, and adds looping behavior when PowerList is shown in a popup.

中文: 本 PR 旨在提升锁屏界面的键盘可达性:为锁定/切换用户/注销/电源操作按钮增加 Tab/Shift+Tab 焦点链,并在按钮获得键盘焦点时显示高亮边框;同时在弹出式 PowerList 中实现内部循环导航。

Changes / 变更点:

  • Add initial focus + focus traversal between outer action buttons and PowerList / 增加初始焦点与外部按钮和 PowerList 的焦点跳转
  • Implement PowerList loop/break-out behavior for Tab navigation / 实现 PowerList 的 Tab 循环与跳出行为
  • Show focus border when a shutdown button has keyboard focus / 按钮获得键盘焦点时显示边框高亮

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/plugins/lockscreen/qml/ShutdownView.qml Adds initial focus and Tab/BackTab routing between lock/switch/logout and the power buttons / 增加初始焦点及外部按钮与电源列表间的 Tab/Shift+Tab 路由
src/plugins/lockscreen/qml/ShutdownButton.qml Extends highlight condition to include activeFocus / 将高亮条件扩展为包含键盘焦点态
src/plugins/lockscreen/qml/PowerList.qml Adds focus helpers, loop flag, and edge handling for Tab navigation / 增加聚焦辅助函数、循环标志与 Tab 边界处理
src/plugins/lockscreen/qml/ControlAction.qml Sets focus + enables internal loop when PowerList is opened as a popup / 弹出电源列表时设置初始焦点并启用内部循环

Comment on lines +12 to +14
Component.onCompleted: {
lockBtn.forceActiveFocus()
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

锁屏状态打开关机界面时,只会创建PowerList,不会创建ShutdownView(ShutdownView包含一个PowerList和三个单独的按钮),不会被抢焦点,见ControlAction.qml中修改部分

Comment on lines +24 to +26
id:powerList
onTabOutForward: lockBtn.forceActiveFocus()
onTabOutBackward: logoutBtn.forceActiveFocus()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

跟上面哪个一样,已锁定状态下不会加载ShutdownView这个界面,不会出现焦点推送到不可见对象的情况。

Comment thread src/plugins/lockscreen/qml/PowerList.qml
Comment on lines +55 to +59
KeyNavigation.tab: rebootBtn
KeyNavigation.backtab: hibernateBtn
Keys.onBacktabPressed :function(event) {
if(root.loopInside)
{
Adjust keyboard focus visual for ShutdownButton to align with X11
button focus appearance, using white border and tinted background.

调整关机按钮键盘焦点视觉效果,与X11按钮焦点样式保持一致。

Log: 更新关机按钮焦点样式
PMS: BUG-300951
Influence: 关机按钮获得键盘焦点时显示白色边框和半透明背景,与X11样式一致。
wineee

This comment was marked as duplicate.

@wineee

wineee commented Jul 17, 2026

Copy link
Copy Markdown
Member

Code Review

整体评价

整体实现思路清晰,为锁屏电源按钮添加了键盘 Tab/BackTab 焦点循环导航,同时为 ShutdownButton 增加了聚焦视觉反馈。loopInside 设计使 PowerList 在弹窗模式和内嵌模式(ShutdownView)下表现不同,是一个合理的架构选择。

值得肯定:

  • 焦点链的两种模式(弹窗内循环 vs. 跨按钮循环)通过 loopInside 属性控制,设计清晰
  • ShutdownButton 聚焦视觉反馈使用 activeFocus && !hovered && !pressed 条件,避免状态叠加时的视觉混乱
  • PR 描述中英文双语,关联了 PMS 编号

问题列表

🔴 [必须修复] ControlAction 弹窗关闭后焦点丢失

ControlAction.qml 中弹窗关闭时(点击背景或 Escape),onClosed 只设置了 expand = falseloopInside = false,但没有将焦点恢复到 powerItem 按钮。如果焦点停留在弹窗内的 PowerList 按钮上,关闭后焦点可能悬空。

建议onClosed 中恢复焦点:

onClosed: {
    innerPowerList.loopInside = false
    powerItem.forceActiveFocus()
    powerItem.expand = false
}

🔴 [必须修复] 禁用按钮打断焦点链

PowerList.qml 中按钮都有 enabled: GreeterProxy.canXxx 条件。Qt Quick 的 KeyNavigation 不会自动跳过 disabled 的 item——Tab 到禁用按钮后焦点会被"卡住"。

建议 为每个使用 KeyNavigation 的按钮处理禁用跳过逻辑,或在 Keys 处理器中查找下一个 enabled 的按钮跳转。此问题同样存在于 ShutdownView.qmlvisible: !GreeterProxy.isLocked 按钮上。

🟡 [建议修改] QML 代码格式不一致

多处 id: 后缺少空格,部分地方有多余空格:

// 当前
id:lockBtn           id:powerList
Keys.onBacktabPressed :function(event)  // 冒号前多余空格

// 建议
id: lockBtn           id: powerList
Keys.onBacktabPressed: function(event)

diff 中也存在多处行尾空白字符,建议清理。

🟡 [建议修改] enableLoopInside() 函数冗余

该函数仅设置 loopInside = true,无额外逻辑。建议直接在调用处赋值以减少间接层:

onOpened: {
    innerPowerList.focusPowerOff()
    innerPowerList.loopInside = true
}

🟡 [建议修改] Component.onCompleted 对不可见按钮强制获取焦点

GreeterProxy.isLocked 为 true 时,lockBtn 的 visible 为 false,对其 forceActiveFocus() 可能导致焦点行为异常。建议增加可见性判断。

🔵 [仅供参考] Pressed + Focus 叠加时边框样式变化

按钮同时 activeFocus + pressed 时,边框从 3px→2px,颜色变为纯白,操作中可能有短暂视觉跳动。取决于设计要求。


总结

优先级 数量
必须修复 2
建议修改 3
仅供参考 1

建议先修复焦点丢失和禁用按钮跳过两个关键问题,格式问题可一并清理。

@deepin-bot

deepin-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.8.15
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1163

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants