Skip to content

Conversation

@fly602
Copy link
Contributor

@fly602 fly602 commented Dec 23, 2025

Changed the D-Bus GetNameOwner call to store the result and check if kglobalaccel is available
Updated warning message to info when kglobalaccel becomes ready This ensures proper initialization of KWin shortcuts only when kglobalaccel service is actually available

Log: Fixed kglobalaccel service detection for KWin shortcuts

Influence:

  1. Test KWin shortcut functionality with and without kglobalaccel service running
  2. Verify that shortcuts work correctly when kglobalaccel starts after the window manager
  3. Check that no errors occur when kglobalaccel is not available
  4. Test D-Bus signal handling for service availability changes

fix: 正确处理 kglobalaccel D-Bus 名称所有者

修改 D-Bus GetNameOwner 调用以存储结果并检查 kglobalaccel 是否可用 当 kglobalaccel 准备就绪时将警告消息更新为信息级别
这确保仅在 kglobalaccel 服务实际可用时正确初始化 KWin 快捷键

Log: 修复了 KWin 快捷键的 kglobalaccel 服务检测
PMS: BUG-344071
Influence:

  1. 测试在有和没有运行 kglobalaccel 服务时的 KWin 快捷键功能
  2. 验证当 kglobalaccel 在窗口管理器之后启动时快捷键是否正常工作
  3. 检查当 kglobalaccel 不可用时不会出现错误
  4. 测试服务可用性变化的 D-Bus 信号处理

Summary by Sourcery

Improve kglobalaccel service detection to initialize KWin shortcuts only when the D-Bus name owner is actually available and adjust logging accordingly.

Bug Fixes:

  • Ensure kglobalaccel availability is correctly determined by storing and validating the D-Bus GetNameOwner result before initializing KWin shortcuts.

Enhancements:

  • Downgrade the "kglobalaccel ready" message from warning to info to reduce noisy logging when the service becomes available.

Changed the D-Bus GetNameOwner call to store the result and check if
kglobalaccel is available
Updated warning message to info when kglobalaccel becomes ready
This ensures proper initialization of KWin shortcuts only when
kglobalaccel service is actually available

Log: Fixed kglobalaccel service detection for KWin shortcuts

Influence:
1. Test KWin shortcut functionality with and without kglobalaccel
service running
2. Verify that shortcuts work correctly when kglobalaccel starts after
the window manager
3. Check that no errors occur when kglobalaccel is not available
4. Test D-Bus signal handling for service availability changes

fix: 正确处理 kglobalaccel D-Bus 名称所有者

修改 D-Bus GetNameOwner 调用以存储结果并检查 kglobalaccel 是否可用
当 kglobalaccel 准备就绪时将警告消息更新为信息级别
这确保仅在 kglobalaccel 服务实际可用时正确初始化 KWin 快捷键

Log: 修复了 KWin 快捷键的 kglobalaccel 服务检测
PMS: BUG-344071
Influence:
1. 测试在有和没有运行 kglobalaccel 服务时的 KWin 快捷键功能
2. 验证当 kglobalaccel 在窗口管理器之后启动时快捷键是否正常工作
3. 检查当 kglobalaccel 不可用时不会出现错误
4. 测试服务可用性变化的 D-Bus 信号处理
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 23, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts kglobalaccel D-Bus name-owner detection and logging to only initialize KWin shortcuts when the kglobalaccel service is actually available and to log readiness at info level instead of warning.

Sequence diagram for Manager.init D-Bus kglobalaccel detection

sequenceDiagram
    participant Manager
    participant ShortcutManager
    participant SessionBus
    participant DBusDaemon
    participant KGlobalAccelService

    Manager->>ShortcutManager: AddSystem(wm)
    Manager->>ShortcutManager: AddMedia(wm)

    Manager->>SessionBus: Call GetNameOwner(org.kde.kglobalaccel)
    SessionBus-->>Manager: owner or error

    alt kglobalaccel not ready (error from GetNameOwner)
        Manager->>Manager: log Warning("kglobalaccel not ready", err)
        Manager->>DBusDaemon: NewDBus(SessionBus)
        Manager->>DBusDaemon: InitSignalExt(sessionSigLoop, true)
        DBusDaemon-->>Manager: ready to emit NameOwnerChanged

        DBusDaemon->>Manager: NameOwnerChanged(name, oldOwner, newOwner)
        alt name == org.kde.kglobalaccel and newOwner != ""
            Manager->>Manager: log Info("kglobalaccel ready")
            Manager->>ShortcutManager: AddKWin(wm)
            Manager->>DBusDaemon: RemoveAllHandlers()
        else other services or kglobalaccel lost
            Manager->>Manager: ignore
        end
    else kglobalaccel already has owner (no error)
        Manager->>Manager: owner string is set
        Manager->>ShortcutManager: AddKWin(wm) (existing behavior outside diff)
    end
Loading

Class diagram for Manager and related D-Bus shortcut initialization

classDiagram
    class Manager {
        - shortcutManager ShortcutManager
        - wm WindowManager
        - sessionBus SessionBus
        - sessionSigLoop SessionSignalLoop
        - logger Logger
        - owner string
        + init()
    }

    class ShortcutManager {
        + AddSystem(wm WindowManager)
        + AddMedia(wm WindowManager)
        + AddKWin(wm WindowManager)
    }

    class SessionBus {
        + BusObject() DBusObject
    }

    class DBusObject {
        + Call(method string, flags int, name string) DBusCall
    }

    class DBusCall {
        + Store(owner *string) error
    }

    class DBusDaemon {
        + InitSignalExt(loop SessionSignalLoop, matchAll bool)
        + ConnectNameOwnerChanged(handler func(name string, oldOwner string, newOwner string))
        + RemoveAllHandlers()
    }

    class Logger {
        + Warning(args)
        + Info(args)
    }

    Manager --> ShortcutManager : uses
    Manager --> SessionBus : uses
    Manager --> DBusDaemon : configures
    Manager --> Logger : logs
    SessionBus --> DBusObject : creates
    DBusObject --> DBusCall : returns
    DBusCall --> Manager : sets owner
    DBusDaemon --> Manager : NameOwnerChanged callback
    Manager --> ShortcutManager : AddKWin on kglobalaccel ready
    Logger <.. Manager : Warning/Info level change
Loading

File-Level Changes

Change Details Files
Fix D-Bus GetNameOwner usage to correctly detect kglobalaccel availability and adjust readiness logging.
  • Store the result of org.freedesktop.DBus.GetNameOwner into a local owner string to validate presence of the org.kde.kglobalaccel service instead of ignoring the return value.
  • Keep the fallback path that initializes D-Bus NameOwnerChanged signal handling when GetNameOwner fails, ensuring KWin shortcuts are added when kglobalaccel eventually appears.
  • Downgrade the log level from warning to info when kglobalaccel becomes ready to reduce noisy warnings for normal startup behavior.
keybinding1/manager.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

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行审查:

  1. 语法逻辑:
  • 代码逻辑基本正确,主要是修复了一个DBUS调用的问题
  • 将原来的 Store() 改为 Store(&owner) 是正确的,因为需要存储获取到的所有者信息
  1. 代码质量:
  • 建议在声明 owner 变量时添加注释说明其用途
  • logger.Warning 改为 logger.Info 是合理的,因为"kglobalaccel ready"是一个正常状态信息,不是警告信息
  1. 代码性能:
  • 当前实现没有明显的性能问题
  • DBUS调用是异步的,不会阻塞主线程
  1. 代码安全:
  • 建议添加对 owner 变量的空值检查
  • 可以考虑添加超时机制,防止DBUS调用无限等待

改进建议:

// owner 用于存储 kglobalaccel 服务的所有者信息
var owner string
err := sessionBus.BusObject().Call("org.freedesktop.DBus.GetNameOwner",
    0, "org.kde.kglobalaccel").Store(&owner)
if err != nil {
    logger.Warning("kglobalaccel not ready:", err)
    dbusDaemon := ofdbus.NewDBus(sessionBus)
    dbusDaemon.InitSignalExt(m.sessionSigLoop, true)
    dbusDaemon.ConnectNameOwnerChanged(func(name string, oldOwner string, newOwner string) {
        if name == "org.kde.kglobalaccel" {
            if newOwner != "" {
                logger.Info("kglobalaccel ready, owner:", newOwner)
                m.shortcutManager.AddKWin(m.wm)
                dbusDaemon.RemoveAllHandlers()
            } else {
                logger.Warning("kglobalaccel lost owner")
            }
        }
    })
} else {
    // 直接添加,因为服务已经就绪
    logger.Info("kglobalaccel ready, owner:", owner)
    m.shortcutManager.AddKWin(m.wm)
}

主要改进点:

  1. 添加了变量注释
  2. 添加了对服务失去所有者的处理
  3. 在服务已经就绪的情况下直接添加,避免等待信号
  4. 在日志中添加了所有者信息,便于调试
  5. 优化了条件判断结构,使逻辑更清晰

Copy link

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

  • You now store the owner string from GetNameOwner but never use it; either remove the variable and Store argument or add a check that uses owner to decide whether kglobalaccel is available.
  • Consider aligning the log level for the initial kglobalaccel not ready message with the later kglobalaccel ready info log to avoid treating normal startup ordering as a warning.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You now store the `owner` string from `GetNameOwner` but never use it; either remove the variable and `Store` argument or add a check that uses `owner` to decide whether kglobalaccel is available.
- Consider aligning the log level for the initial `kglobalaccel not ready` message with the later `kglobalaccel ready` info log to avoid treating normal startup ordering as a warning.

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.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@fly602 fly602 merged commit 0cd3127 into linuxdeepin:master Dec 23, 2025
15 of 17 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