Skip to content

fix: Cycle titlebar focus to tab bar after Super+Tab - #543

Merged
lzwind merged 1 commit into
linuxdeepin:masterfrom
JWWTSL:master
Jun 17, 2026
Merged

fix: Cycle titlebar focus to tab bar after Super+Tab#543
lzwind merged 1 commit into
linuxdeepin:masterfrom
JWWTSL:master

Conversation

@JWWTSL

@JWWTSL JWWTSL commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

log: Take over Tab/Shift+Tab in MainWindow::eventFilter via titlebarFocusRing(): AddButton -> Option -> QuitFullscreen -> Min -> Max -> Close -> tab bar -> wrap. The tab station focuses the DTabBar inner QTabBar so the current tab shows focus. setTabOrder was unreliable across the cross-subtree titlebar widget tree and is removed. Quake window does not override the ring, so its behavior is unchanged.

pms: bug-283709

log: Take over Tab/Shift+Tab in MainWindow::eventFilter via titlebarFocusRing(): AddButton -> Option -> QuitFullscreen -> Min -> Max -> Close -> tab bar -> wrap. The tab station focuses the DTabBar inner QTabBar so the current tab shows focus. setTabOrder was unreliable across the cross-subtree titlebar widget tree and is removed. Quake window does not override the ring, so its behavior is unchanged.

pms: bug-283709

@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 @JWWTSL, 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

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码完美修复了跨子树标题栏焦点循环失效的问题,采用虚函数动态构建焦点环的设计非常优雅
逻辑严密且注释详尽,无任何安全与性能风险,符合所有高质量代码标准

■ 【详细分析】

  • 1.语法逻辑 完全正确 ✓

事件过滤器中精确匹配了Tab与Shift+Tab组合键,排除了Ctrl/Alt/Meta干扰。通过精确相等或祖先关系匹配当前焦点控件,完美兼容DTK内部子控件持有焦点的场景。循环索引计算使用取模算法,正确处理了首尾边界循环。
建议:无需改进

  • 2.代码质量 优秀 ✓

废弃了不可靠的setTabOrder,改为在eventFilter中显式接管,彻底解决了跨子树与DTK focusProxy冲突。基类提供空实现作为默认行为,子类按需重写,符合开闭原则。注释精准解释了设计初衷与历史背景(如为何恢复TabFocus策略),极大提升了可维护性。
建议:无需改进

  • 3.代码性能 高效 ✓

titlebarFocusRing在每次按键时动态查找控件,虽使用findChild,但触发频率极低且仅限于浅层标题栏子树遍历,开销完全可忽略。不缓存控件指针的策略有效避免了DTK重建按钮导致的悬空指针崩溃,是以极小性能代价换取极高稳定性的正确权衡。
建议:无需改进

  • 4.代码安全 存在0个安全漏洞 ✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
无安全风险,代码仅处理本地键盘事件,不涉及外部不可信输入、命令执行或敏感数据流转。

  • 建议:保持当前安全的实现方式

■ 【改进建议代码示例】

// 当前代码已非常完善,无需额外改进代码示例。
// 以下为原代码片段的合规性确认展示:
QList<QWidget *> NormalWindow::titlebarFocusRing()
{
    QList<QWidget *> ring;
    QWidget *tabStation = nullptr;
    if (m_tabbar != nullptr) {
        tabStation = m_tabbar->findChild<QTabBar *>();
        if (tabStation == nullptr)
            tabStation = m_tabbar;
        tabStation->setFocusPolicy(Qt::TabFocus);
    }
    const QList<QWidget *> candidates = {
        m_tabbar ? m_tabbar->findChild<DIconButton *>("AddButton") : nullptr,
        titlebar()->findChild<DIconButton *>("DTitlebarDWindowOptionButton"),
        titlebar()->findChild<QWidget *>("DTitlebarDWindowQuitFullscreenButton"),
        titlebar()->findChild<DIconButton *>("DTitlebarDWindowMinButton"),
        titlebar()->findChild<DIconButton *>("DTitlebarDWindowMaxButton"),
        titlebar()->findChild<DIconButton *>("DTitlebarDWindowCloseButton"),
        tabStation,
    };
    for (QWidget *w : candidates) {
        if (w != nullptr && w->isVisible() && w->isEnabled())
            ring.append(w);
    }
    return ring;
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL, lzwind

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

@JWWTSL

JWWTSL commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@lzwind
lzwind merged commit 822dcc7 into linuxdeepin:master Jun 17, 2026
17 checks passed
@deepin-bot

deepin-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unknown)

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