feat(wm-helper): support system window menu on treeland/wayland#380
Merged
Conversation
1. Add Wayland-specific path for popupSystemWindowMenu 2. Show window menu via QWaylandShellSurface for treeland compositor 3. Include necessary Qt Wayland private headers Log: Add Wayland window menu support for treeland compositor feat(wm-helper): 支持 treeland/wayland 系统窗口菜单 1. 为 popupSystemWindowMenu 添加 Wayland 专用路径 2. 通过 QWaylandShellSurface 为 treeland 合成器显示窗口菜单 3. 引入必要的 Qt Wayland 私有头文件 Log: 为 treeland 合成器添加 Wayland 窗口菜单支持 PMS: TASK-389419
Contributor
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的 Git Diff。本次修改主要是在 以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的审查意见和改进建议: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进后的代码建议综合以上分析,我为你重构了这部分代码,主要改进点包括:减少嵌套、增加空指针保护、修复原有代码的潜在崩溃。 #ifndef DTK_DISABLE_TREELAND
#include "plugins/platform/treeland/dtreelandwindowmanagerhelper.h"
#include <private/qguiapplication_p.h>
#include <private/qwaylandwindow_p.h>
#include <private/qwaylandshellsurface_p.h>
#include <private/qwaylandintegration_p.h>
#endif
DGUI_BEGIN_NAMESPACE
// ... 省略其他代码 ...
void DWindowManagerHelper::popupSystemWindowMenu(const QWindow *window)
{
#ifndef DTK_DISABLE_TREELAND
if (DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsWaylandPlatform)) {
// 1. 提前返回 空指针检查
if (!window || !window->handle()) {
return;
}
// 2. 使用 dynamic_cast 安全转换,并检查结果
auto *wlWindow = dynamic_cast<QtWaylandClient::QWaylandWindow*>(window->handle());
if (!wlWindow) {
return;
}
auto *shellSurface = wlWindow->shellSurface();
if (!shellSurface) {
return;
}
// 3. 使用 dynamic_cast 替代 static_cast 防御未定义行为,或者确信 IsWaylandPlatform 已保证安全
// 如果 IsWaylandPlatform 绝对可靠,static_cast 也可以,但 dynamic_cast 更防御性
auto *wlIntegration = dynamic_cast<QtWaylandClient::QWaylandIntegration*>(
QGuiApplicationPrivate::platformIntegration());
if (!wlIntegration) {
return;
}
auto *defaultDevice = wlIntegration->display() ? wlIntegration->display()->defaultInputDevice() : nullptr;
if (defaultDevice) {
shellSurface->showWindowMenu(defaultDevice);
}
return;
}
#endif
// 修复原有代码的潜在空指针解引用崩溃
if (!window || !window->handle()) {
return;
}
return callPlatformFunction<void, void(*)(quint32)>(_popupSystemWindowMenu, quint32(window->handle()->winId()));
}总结本次修改的方向是正确的,填补了 Wayland 平台下系统窗口菜单的功能缺失。主要需要关注的是私有 API 的长期维护成本以及代码的防御性编程(空指针检查)。建议在合并前确认对 Qt 私有 API 的依赖是否符合项目的长期维护策略。 |
18202781743
approved these changes
May 11, 2026
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, mhduiy The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Log: Add Wayland window menu support for treeland compositor
feat(wm-helper): 支持 treeland/wayland 系统窗口菜单
Log: 为 treeland 合成器添加 Wayland 窗口菜单支持
PMS: TASK-389419