Skip to content

fix: keep dock visible during multitask view#1589

Merged
wjyrich merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-bug-312371
May 7, 2026
Merged

fix: keep dock visible during multitask view#1589
wjyrich merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-bug-312371

Conversation

@wjyrich
Copy link
Copy Markdown
Contributor

@wjyrich wjyrich commented May 7, 2026

  1. Add DBus connection to listen for KWin multitask state changes (org.kde.KWin.MultitaskStateChanged signal)
  2. Track multitask view state with m_inMultitaskView member variable
  3. Override auto-hide behavior to show dock when entering multitask view
  4. Ensure dock remains visible during multitask view and properly checks show/hide state when exiting

Log: Fixed dock auto-hide behavior during multitask view

Influence:

  1. Test entering and exiting multitask view with dock auto-hide enabled
  2. Verify dock remains visible during multitask view
  3. Confirm dock returns to normal auto-hide behavior after exiting multitask view
  4. Test multiple transitions between normal and multitask views
  5. Verify no regression in dock auto-hide under normal conditions

fix: 在多任务视图下保持任务栏可见

  1. 添加 DBus 连接监听 KWin 多任务状态变化 (org.kde.KWin.MultitaskStateChanged 信号)
  2. 使用 m_inMultitaskView 成员变量跟踪多任务视图状态
  3. 重写自动隐藏行为,进入多任务视图时显示任务栏
  4. 确保在多任务视图中任务栏保持可见,退出时正确检查显示/隐藏状态

Log: 修复多任务视图下任务栏自动隐藏问题

Influence:

  1. 测试启用任务栏自动隐藏时进入和退出多任务视图
  2. 验证在多任务视图下任务栏保持可见
  3. 确认退出多任务视图后任务栏恢复正常自动隐藏行为
  4. 测试正常视图和多任务视图之间的多次切换
  5. 验证正常情况下任务栏自动隐藏功能没有回归

PMS: BUG-312371

Summary by Sourcery

Bug Fixes:

  • Prevent the dock from auto-hiding while KWin multitask view is active by tracking multitask state and overriding hide/show decisions accordingly.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 7, 2026

Reviewer's Guide

Adds a KWin DBus listener and a multitask view state flag to override dock auto-hide logic so the dock stays visible during multitask view and resumes normal behavior afterward.

Sequence diagram for dock visibility during KWin multitask view

sequenceDiagram
    actor User
    participant KWin
    participant DBusSessionBus
    participant DockHelper
    participant DockPanel

    User->>KWin: EnterMultitaskView
    KWin->>DBusSessionBus: emit MultitaskStateChanged(true)
    DBusSessionBus->>DockHelper: MultitaskStateChanged(true)
    activate DockHelper
    DockHelper->>DockHelper: onMultitaskStateChanged(true)
    DockHelper->>DockHelper: m_inMultitaskView = true
    DockHelper->>DockHelper: checkNeedShowOrNot()
    DockHelper->>DockPanel: setHideState(Show)
    deactivate DockHelper

    User->>KWin: ExitMultitaskView
    KWin->>DBusSessionBus: emit MultitaskStateChanged(false)
    DBusSessionBus->>DockHelper: MultitaskStateChanged(false)
    activate DockHelper
    DockHelper->>DockHelper: onMultitaskStateChanged(false)
    DockHelper->>DockHelper: m_inMultitaskView = false
    DockHelper->>DockHelper: checkNeedHideOrNot()
    DockHelper->>DockPanel: setHideState(Hide or Show based on conditions)
    deactivate DockHelper
Loading

Updated class diagram for DockHelper multitask state handling

classDiagram
    class DockHelper {
        - bool m_inMultitaskView
        - QHash~QScreen*, DockWakeUpArea*~ m_areas
        - QHash~QWindow*, bool~ m_enters
        - QHash~QWindow*, bool~ m_transientChildShows
        + DockHelper(DockPanel* parent)
        + void checkNeedHideOrNot()
        + void checkNeedShowOrNot()
        + void onMultitaskStateChanged(bool inMultitask)
        - void initAreas()
        + DockPanel* parent()
    }

    class DockPanel {
        + void setHideState(HideState state)
    }

    class QDBusConnection {
        + static QDBusConnection sessionBus()
        + bool connect(QString service, QString path, QString interface, QString name, QObject* receiver, const char* slot)
    }

    DockHelper --> DockPanel : uses
    DockHelper --> QDBusConnection : listens_via
    QDBusConnection <.. DockHelper : sessionBus_connects_to_MultitaskStateChanged
Loading

File-Level Changes

Change Details Files
Listen to KWin multitask state over DBus and track current multitask view state.
  • Create a DBus connection on the session bus to subscribe to org.kde.KWin.MultitaskStateChanged from /KWin
  • Introduce a bool member to cache whether the system is currently in multitask view
  • Add a slot to update the cached state when the multitask signal is received
panels/dock/dockhelper.cpp
panels/dock/dockhelper.h
Override dock auto-hide/show decisions while in multitask view so the dock remains visible.
  • Guard the hide decision logic to prevent hiding when multitask view is active
  • Force the show decision logic to show the dock when multitask view is active
  • Trigger re-evaluation of show/hide state when entering or exiting multitask view
panels/dock/dockhelper.cpp

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 left some high level feedback:

  • The DBus connection to org.kde.KWin.MultitaskStateChanged ignores the return value and any potential errors; consider checking the success of QDBusConnection::connect and at least logging failures so issues with the signal wiring are observable.
  • Right now m_inMultitaskView is only updated on the signal; if the dock starts while KWin is already in multitask view, the initial state may be wrong—consider querying the current multitask state on initialization to keep the dock in sync from startup.
  • The new DBus connect uses the old SLOT() syntax; switching to the functor-based syntax (e.g. &DockHelper::onMultitaskStateChanged) would give compile‑time checking of the slot signature and be consistent with newer Qt style.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The DBus connection to `org.kde.KWin.MultitaskStateChanged` ignores the return value and any potential errors; consider checking the success of `QDBusConnection::connect` and at least logging failures so issues with the signal wiring are observable.
- Right now `m_inMultitaskView` is only updated on the signal; if the dock starts while KWin is already in multitask view, the initial state may be wrong—consider querying the current multitask state on initialization to keep the dock in sync from startup.
- The new DBus connect uses the old `SLOT()` syntax; switching to the functor-based syntax (e.g. `&DockHelper::onMultitaskStateChanged`) would give compile‑time checking of the slot signature and be consistent with newer Qt style.

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.

1. Add DBus connection to listen for KWin multitask state changes
(org.kde.KWin.MultitaskStateChanged signal)
2. Track multitask view state with m_inMultitaskView member variable
3. Override auto-hide behavior to show dock when entering multitask view
4. Ensure dock remains visible during multitask view and properly checks
show/hide state when exiting

Log: Fixed dock auto-hide behavior during multitask view

Influence:
1. Test entering and exiting multitask view with dock auto-hide enabled
2. Verify dock remains visible during multitask view
3. Confirm dock returns to normal auto-hide behavior after exiting
multitask view
4. Test multiple transitions between normal and multitask views
5. Verify no regression in dock auto-hide under normal conditions

fix: 在多任务视图下保持任务栏可见

1. 添加 DBus 连接监听 KWin 多任务状态变化
(org.kde.KWin.MultitaskStateChanged 信号)
2. 使用 m_inMultitaskView 成员变量跟踪多任务视图状态
3. 重写自动隐藏行为,进入多任务视图时显示任务栏
4. 确保在多任务视图中任务栏保持可见,退出时正确检查显示/隐藏状态

Log: 修复多任务视图下任务栏自动隐藏问题

Influence:
1. 测试启用任务栏自动隐藏时进入和退出多任务视图
2. 验证在多任务视图下任务栏保持可见
3. 确认退出多任务视图后任务栏恢复正常自动隐藏行为
4. 测试正常视图和多任务视图之间的多次切换
5. 验证正常情况下任务栏自动隐藏功能没有回归

PMS: BUG-312371
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码实现了在多任务视图开启时强制显示 Dock 面板,并在多任务视图关闭时恢复原有的隐藏/显示逻辑的功能。整体逻辑是通顺的,但在代码规范、健壮性和安全性方面还有提升空间。

以下是详细的审查意见和改进建议:

1. 语法与逻辑

  • 版权年份更新
    • 问题dockhelper.h 中将版权年份从 2024 修改为了 2024 - 2026
    • 建议:通常版权年份应覆盖代码实际存在和使用的年份。如果是今年的代码,建议写 20242024 - 2025。写 2026 可能是笔误,建议核实。
  • DBUS 连接错误处理
    • 问题QDBusConnection::sessionBus().connect(...) 返回一个 bool 值表示连接是否成功。当前代码没有检查返回值。
    • 建议:如果 DBus 服务未运行或连接失败,信号将无法触发。建议添加判断逻辑,打印警告日志,便于调试。
  • 槽函数声明
    • 问题onMultitaskStateChanged 被声明在 public Q_SLOTS 下。
    • 建议:该槽函数仅用于内部响应 DBUS 信号,建议将其移至 private Q_SLOTSprivate 区域(如果使用 Qt5 的连接语法),以封装实现细节。

2. 代码质量

  • 魔法字符串
    • 问题:DBus 连接中使用了硬编码的字符串路径 "/KWin" 和接口名 "org.kde.KWin"
    • 建议:虽然这些通常是 KWin 的标准接口,但为了代码的可维护性,建议在类中定义静态常量字符串。
  • 代码风格
    • 问题onMultitaskStateChanged 中的 if 判断体只有一行代码,使用了大括号。
    • 建议:保持与项目中其他代码风格一致。如果项目中单行 if 不加括号,这里也可以去掉;如果强制加括号,则保持现状即可。
  • 命名规范
    • 评价:变量名 m_inMultitaskView 和函数名 onMultitaskStateChanged 清晰易懂,符合 Qt 命名规范。

3. 代码性能

  • 逻辑冗余检查
    • 问题:在 onMultitaskStateChanged 中,先检查了 m_inMultitaskView != inMultitask,然后根据状态调用 checkNeedShowOrNotcheckNeedHideOrNot
    • 分析:这是一个很好的优化,避免了状态未改变时的无效计算。
    • 潜在优化:在 checkNeedHideOrNotcheckNeedShowOrNot 中,对 m_inMultitaskView 的判断是在计算完 needHideneedShow 之后进行的。
      • checkNeedHideOrNot 中,如果 m_inMultitaskViewtrue,直接将 needHide 设为 false
      • checkNeedShowOrNot 中,如果 m_inMultitaskViewtrue,直接将 needShow 设为 true
    • 建议:虽然当前逻辑不影响正确性,但为了性能(微优化),可以将 m_inMultitaskView 的判断提前到函数开头。如果处于多任务视图,checkNeedHideOrNot 可以直接返回,无需计算鼠标位置等逻辑;checkNeedShowOrNot 也可以直接设置状态并返回。这能减少不必要的计算。

4. 代码安全

  • DBus 安全性
    • 问题:代码监听了系统级的 KWin 信号。
    • 建议:确保 KWin 发送的信号是可信的。虽然通常系统总线上的服务是可信的,但在处理接收到的参数 bool inMultitask 时,逻辑是安全的(仅作为布尔值判断)。
  • 状态一致性
    • 问题m_inMultitaskView 是一个成员变量,其状态依赖于外部 DBus 信号。
    • 风险:如果 KWin 意外崩溃重启,或者 DBus 连接断开,m_inMultitaskView 可能会卡在 true 状态,导致 Dock 无法自动隐藏。
    • 建议:考虑添加 NameOwnerChanged 信号监听,或者定期检查 KWin 服务状态,或者在 Dock 获得焦点/激活时重置该状态(视具体业务逻辑而定)。当前代码在构造函数中连接一次,如果服务重启,连接可能失效。

改进后的代码示例

// dockhelper.h
class DockHelper : public QObject
{
    // ...
private Q_SLOTS:
    void onMultitaskStateChanged(bool inMultitask);
    // ...

private:
    static constexpr const char* KWIN_SERVICE = "org.kde.KWin";
    static constexpr const char* KWIN_PATH = "/KWin";
    static constexpr const char* KWIN_INTERFACE = "org.kde.KWin";
    
    bool m_inMultitaskView = false;
    // ...
};

// dockhelper.cpp
DockHelper::DockHelper(DockPanel *parent)
    : QObject(parent)
{
    // ... 初始化代码 ...

    // 检查 DBus 连接是否成功
    if (!QDBusConnection::sessionBus().connect(QString(),
                                              QStringLiteral(KWIN_PATH),
                                              QStringLiteral(KWIN_INTERFACE),
                                              QStringLiteral("MultitaskStateChanged"),
                                              this,
                                              SLOT(onMultitaskStateChanged(bool)))) {
        qWarning() << "Failed to connect to KWin MultitaskStateChanged signal";
    }

    // ...
}

void DockHelper::checkNeedHideOrNot()
{
    // 性能优化:如果处于多任务视图,强制不隐藏,直接返回
    if (m_inMultitaskView) {
        return; 
    }

    // 原有的计算 needHide 的逻辑
    // ...
    
    if (needHide)
        parent()->setHideState(Hide);
}

void DockHelper::checkNeedShowOrNot()
{
    // 性能优化:如果处于多任务视图,强制显示
    if (m_inMultitaskView) {
        parent()->setHideState(Show);
        return;
    }

    // 原有的计算 needShow 的逻辑
    // ...

    if (needShow)
        parent()->setHideState(Show);
}

void DockHelper::onMultitaskStateChanged(bool inMultitask)
{
    // 状态未改变则不做处理
    if (m_inMultitaskView == inMultitask) {
        return;
    }

    m_inMultitaskView = inMultitask;
    
    // 根据新状态触发检查
    if (m_inMultitaskView) {
        checkNeedShowOrNot();
    } else {
        checkNeedHideOrNot();
    }
}

总结

这段代码主要的功能实现是正确的。主要的改进点在于:

  1. 增加 DBus 连接的错误处理,防止静默失败。
  2. 优化逻辑判断顺序,将多任务视图的判断提前,避免不必要的计算。
  3. 修正版权年份调整槽函数访问权限,提升代码规范性。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: robertkill, wjyrich

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

@wjyrich wjyrich merged commit f149806 into linuxdeepin:master May 7, 2026
11 of 12 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