fix: rebuild desktop root native windows on topology change#3704
fix: rebuild desktop root native windows on topology change#3704Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ivy233 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 |
|
TAG Bot New tag: 6.5.133 |
a6fc9ee to
6c5b6e8
Compare
deepin pr auto review这份代码的 diff 主要涉及桌面环境在多显示器环境下的窗口重建逻辑、显示更新机制以及信号处理。以下是对语法逻辑、代码质量、代码性能和代码安全的详细审查和改进意见: 1. 语法与逻辑审查审查点: inline QString getScreenName(QWidget *win)
{
- Q_ASSERT(win);
+ if (!win)
+ return QString();
return win->property(DesktopFrameProperty::kPropScreenName).toString();
}
审查点: void BaseWindow::recreateNativeWindow(const QRect &geometry)
{
hide();
setGeometry(geometry);
destroy(true, false);
create();
setGeometry(geometry);
}
审查点: bool WindowFrame::needRecreateNativeWindows(const QList<ScreenPointer> &screens) const
{
// ... 省略部分代码 ...
for (auto it = currentGeometries.cbegin(); it != currentGeometries.cend(); ++it) {
const QRect previous = d->screenGeometries.value(it.key());
const QRect current = it.value();
if (previous.topLeft() != current.topLeft()) {
return true;
}
}
// ...
}
2. 代码质量审查审查点: void BackgroundManager::onWindowShowed()
{
for (auto it = d->backgroundWidgets.begin(); it != d->backgroundWidgets.end(); ++it) {
const BackgroundWidgetPointer &bwp = it.value();
bwp->show();
bwp->update();
}
}
审查点: QWriteLocker lk(&d->locker);
+ const bool recreateNativeWindows = d->recreateNativeWindows;
+ d->recreateNativeWindows = false;
3. 代码性能审查审查点:频繁的屏幕拓扑缓存更新 void WindowFrame::cacheScreenTopology(const QList<ScreenPointer> &screens)
{
d->screenOrder.clear();
d->screenGeometries.clear();
// ... 填充数据 ...
}
审查点: void WindowFrame::onGeometryChanged()
{
bool changed = false;
+ const auto screens = ddplugin_desktop_util::screenProxyLogicScreens();
+ if (needRecreateNativeWindows(screens)) {
+ d->recreateNativeWindows = true;
+ buildBaseWindow();
+ return;
+ }
// ...
}
4. 代码安全审查审查点:空指针检查 void WindowFramePrivate::recreateNativeWindow(BaseWindowPointer win, ScreenPointer screen)
{
if (!win || !screen)
return;
// ...
}
审查点:窗口句柄的有效性 if (QWindow *handle = win->windowHandle()) {
handle->setOpacity(0.99);
traceWindow(handle);
}
总结与改进建议
// 示例改进:定义常量
static constexpr qreal kWindowRefreshOpacity = 0.99;
// 使用
handle->setOpacity(kWindowRefreshOpacity);总体而言,这段代码在处理多显示器动态切换和窗口重建方面逻辑清晰,安全性考虑周全(空指针检查、锁机制)。主要的改进空间在于减少代码重复、明确魔法数字的含义以及微调重绘逻辑。 |
https://bbs.deepin.org/post/297315
该反馈的代码提交,是带调试log的,如果需要合并还需要处理,仅用作一个提示。
如果直接用该pr,需要删掉fmWarning;也可以基于该pr重新做一些修改后重新提。