Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Scripting: Added MapObject.resolvedClassName() (by MatusGuy, #4529)
* Fixed crash when the selection becomes empty while starting a move (#4536)
* Fixed Properties view update on 'Reset Template Instance' and 'Replace With Template' actions
* Fixed restoring of the layout for maximized windows on startup (#4580)
* Linux: Added file associations for .tmj, .tsj, .tiled-project and .world files (by miffe, #4550)
* Linux: Fixed the window icon on some Wayland compositors (by Ball贸 Gy枚rgy, #4567)
* macOS: Declared UTIs and file associations for all supported Tiled formats (with Jyotish, #4469)
Expand Down
28 changes: 15 additions & 13 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,14 +976,14 @@ void MainWindow::dropEvent(QDropEvent *e)

void MainWindow::resizeEvent(QResizeEvent *e)
{
// When the window is maximized, we need to delay restoring the internal
// layout until after the second resize event (issue #590). This does not
// appear to affect macOS, where only a single resize event is observed.
if (!mHasRestoredLayout)
#ifndef Q_OS_MAC
if (!isMaximized() || e->oldSize().isValid())
#endif
// A maximized window only reaches its final size with the first
// spontaneous resize event, so the layout may need to be restored again
// to avoid it being clamped to the normal geometry (#4580).
if (mReapplyLayoutOnResize && e->spontaneous()) {
mReapplyLayoutOnResize = false;
if (isMaximized())
restoreLayout();
}

if (mPopupWidget)
updatePopupGeometry(e->size());
Expand Down Expand Up @@ -2344,8 +2344,14 @@ void MainWindow::readSettings()
else
resize(Utils::dpiScaled(QSize(1200, 700)));

// Make sure layout is restored eventually (see resizeEvent)
QTimer::singleShot(200, this, &MainWindow::restoreLayout);
restoreLayout();

// A maximized window does not have its final size yet (see resizeEvent).
// Not needed on macOS, where the size is final already, nor on Windows,
// where pending window system events are flushed first (see main.cpp).
#if !defined(Q_OS_MAC) && !defined(Q_OS_WIN)
mReapplyLayoutOnResize = isMaximized();
#endif

updateRecentFilesMenu();
updateRecentProjectsMenu();
Expand All @@ -2355,10 +2361,6 @@ void MainWindow::readSettings()

void MainWindow::restoreLayout()
{
if (mHasRestoredLayout)
return;

mHasRestoredLayout = true;
restoreState(preferences::mainWindowState);
mDocumentManager->restoreState();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tiled/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class TILED_EDITOR_EXPORT MainWindow : public QMainWindow
QPointer<PreferencesDialog> mPreferencesDialog;

QMap<QMainWindow*, QByteArray> mMainWindowStates;
bool mHasRestoredLayout = false;
bool mReapplyLayoutOnResize = false;

SessionOption<QStringList> mLoadedWorlds { "loadedWorlds" };

Expand Down
7 changes: 7 additions & 0 deletions src/tiledapp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformintegration.h>
#include <QtGui/qpa/qwindowsysteminterface.h>

#ifdef ERROR
#undef ERROR
Expand Down Expand Up @@ -594,6 +595,12 @@ int main(int argc, char *argv[])
MainWindow w;
w.show();

#ifdef Q_OS_WIN
// Let a maximized window reach its final size before the layout and
// session are restored (see MainWindow::resizeEvent)
QWindowSystemInterface::flushWindowSystemEvents();
#endif

a.setActivationWindow(&w);
#ifdef Q_OS_WIN
using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
Expand Down
Loading