fix(window): persist maximized state and center window on startup#627
Merged
pengfeixx merged 1 commit intoJun 10, 2026
Merged
Conversation
There was a problem hiding this comment.
Sorry @pengfeixx, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Save window maximized state to config and restore on next launch. Use normalGeometry() when maximized and sync() before _Exit(). Add screen centering and auto-maximize when size exceeds screen. 持久化窗口最大化状态,重启后恢复最大化或居中显示窗口。 最大化时使用 normalGeometry() 保存正常尺寸,添加 sync() 确 保配置在 _Exit() 前写入磁盘。 Log: 修复重启后窗口未恢复最大化状态的问题 PMS: BUG-340035 Influence: 窗口关闭时保存最大化状态,重新打开时恢复最大化;非最大化窗口居中显示;窗口尺寸超过屏幕时自动最大化。
810f136 to
5ad4fb3
Compare
deepin pr auto review这段代码主要实现了窗口状态的保存和恢复功能,包括窗口尺寸和最大化状态。以下是我的审查意见:
具体改进建议:
if (saveMaximized || saveWidth > screenRect.width() - 100 || saveHeight > screenRect.height() - 100) {
// 上次关闭时最大化 或 保存的窗口尺寸接近屏幕可用区域,直接最大化
window->showMaximized();
}
void WebWindow::saveWindowSize()
{
qCDebug(app) << "Saving window size";
QSettings *setting = ConfigManager::getInstance()->getSettings();
if (!setting) {
qCWarning(app) << "Failed to get settings instance";
return;
}
bool isMaximized = windowState() & Qt::WindowMaximized;
setting->beginGroup(QString(kConfigWindowInfo));
try {
if (isMaximized) {
setting->setValue(QString(kConfigWindowWidth), normalGeometry().width());
setting->setValue(QString(kConfigWindowHeight), normalGeometry().height());
} else {
setting->setValue(QString(kConfigWindowWidth), width());
setting->setValue(QString(kConfigWindowHeight), height());
}
setting->setValue(QString(kConfigWindowMaximized), isMaximized);
setting->sync();
} catch (...) {
qCWarning(app) << "Error occurred while saving window size";
}
setting->endGroup();
qCDebug(app) << "Window size saved, maximized:" << isMaximized;
}
// 窗口配置相关常量
extern const char kConfigWindowWidth[]; // 窗口宽度配置键
extern const char kConfigWindowHeight[]; // 窗口高度配置键
extern const char kConfigWindowMaximized[]; // 窗口最大化状态配置键
extern const char kConfigWindowInfo[]; // 窗口信息配置组名
extern const char kConfigAppList[]; // 应用列表配置键
// 获取当前屏幕可用区域(已排除Dock栏占用区域)
QScreen *primaryScreen = QGuiApplication::primaryScreen();
if (!primaryScreen) {
qCWarning(app) << "No primary screen available";
return;
}
QRect screenRect = primaryScreen->availableGeometry();这些改进可以提高代码的健壮性和可维护性,同时保持原有的功能完整性。 |
lzwind
approved these changes
Jun 10, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx 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.
Save window maximized state to config and restore on next launch. Use normalGeometry() when maximized and sync() before _Exit(). Add screen centering and auto-maximize when size exceeds screen.
持久化窗口最大化状态,重启后恢复最大化或居中显示窗口。
最大化时使用 normalGeometry() 保存正常尺寸,添加 sync() 确
保配置在 _Exit() 前写入磁盘。
Log: 修复重启后窗口未恢复最大化状态的问题
PMS: BUG-340035
Influence: 窗口关闭时保存最大化状态,重新打开时恢复最大化;非最大化窗口居中显示;窗口尺寸超过屏幕时自动最大化。