Skip to content

Fix subwindow size limits (MainWindow::restoreWidgetState)#8204

Open
yohannd1 wants to merge 8 commits intoLMMS:masterfrom
yohannd1:fix/workspace-negative-pos
Open

Fix subwindow size limits (MainWindow::restoreWidgetState)#8204
yohannd1 wants to merge 8 commits intoLMMS:masterfrom
yohannd1:fix/workspace-negative-pos

Conversation

@yohannd1
Copy link
Contributor

@yohannd1 yohannd1 commented Jan 10, 2026

Previously fixed #8202, but that one got fixed first by #3532.
This PR now just corrects the subwindow size on load.

@yohannd1 yohannd1 changed the title Fix negative widget limit Fix negative subwindow limit Jan 11, 2026
@yohannd1 yohannd1 changed the title Fix negative subwindow limit Fix subwindow size & position limits (MainWindow::restoreWidgetState) Feb 16, 2026
@yohannd1
Copy link
Contributor Author

This was previously simply a fix for negative positions, but I've recently realized the minimum size hint code was also wrong. For example, upon loading the project the "Project Notes" window would have its width set to 800 if it was saved as less, even though its actual minimal amount when resizing is around 200 or 300.

Today I pushed a commit that updates the code style and uses w->minimumSizeHint() to decide whether the minimum size is right, and it seems to be working mostly fine.

One potential concern was re-introducing a bug (discussed in comments on the function in question) where in corrupt project files the size would be null, and I manually tried editing a .mmp file and the bug doesn't seem to be there. There seems to be a slight discrepancy between the actual minimum size the window allows and the one reported in the code I wrote.

@yohannd1
Copy link
Contributor Author

There seems to be a slight discrepancy between the actual minimum size the window allows and the one reported in the code I wrote.

It seems that was because I was using the content widget for size hint, not the subwindow itself - I believe I've fixed it now.

@yohannd1 yohannd1 changed the title Fix subwindow size & position limits (MainWindow::restoreWidgetState) Fix subwindow size limits (MainWindow::restoreWidgetState) Feb 27, 2026
Copy link
Member

@messmerd messmerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested it, but the changes are pretty simple and straightforward

Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
@sqrvrt
Copy link
Contributor

sqrvrt commented Mar 1, 2026

any particular reason to use qMax instead of std::max?

@sqrvrt
Copy link
Contributor

sqrvrt commented Mar 1, 2026

On further looking, the max as a whole at least in current state seems redundant, QWidget::setGeometry says it adjust the size implicitly.

If others think that it's better to leave this to be explicit, the .isValid() check would be redundant since size is guaranteed to be valid in prior, and x-y position is not checked. In theory removing the check in upstream would make this behave exactly like this PR.

@sakertooth
Copy link
Contributor

any particular reason to use qMax instead of std::max?

The general rule of thumb is to prefer the STL when possible. It also helps in our effort to move away from Qt (more importantly in the core, i.e., the lmms namespace)

@yohannd1
Copy link
Contributor Author

yohannd1 commented Mar 2, 2026

I believe qMax was being used before in the code - as of the latest commit I've changed it to std::max.

And, as for the explicit check, in previous tests I had the minimum size being loaded incorrectly, but QWidget::setGeometry wasn't being used yet (and indeed it does update correctly).

Nonetheless, the current normalGeometry.isValid() check introduces a specific case where, when the saved width/height is zero (e.g. in "corrupt" projects, as mentioned in an old comment), the window position is being ignored. For that case, I believe just adding just doing std::max(1, value) is alright, as the geometry rect will be valid and the resize method will adjust the size properly. Also implemented that in the latest commit.

@sqrvrt
Copy link
Contributor

sqrvrt commented Mar 2, 2026

Nonetheless, the current normalGeometry.isValid() check introduces a specific case where, when the saved width/height is zero (e.g. in "corrupt" projects, as mentioned in an old comment), the window position is being ignored

Then wouldn't it be better to just remove the check? i.e.

long pile of useless diff

tldr: remove if and deindent block lol

-	if (normalGeometry.isValid())
-	{
-		// first restore the window, as attempting to resize a maximized window causes graphics glitching
-		win->setWindowState(win->windowState() & ~(Qt::WindowMaximized | Qt::WindowMinimized));
-
-		win->setGeometry(normalGeometry);
-
-		// set the window to its correct minimized/maximized/restored state
-		Qt::WindowStates winState = win->windowState();
-		auto winState = win->windowState();
-		winState = de.attribute("maximized").toInt()
-			? (winState | Qt::WindowMaximized)
-			: (winState & ~Qt::WindowMaximized);
-	}
+	// first restore the window, as attempting to resize a maximized window causes graphics glitching
+	win->setWindowState(win->windowState() & ~(Qt::WindowMaximized | Qt::WindowMinimized));
+
+	win->setGeometry(normalGeometry);
+
+	// set the window to its correct minimized/maximized/restored state
+	Qt::WindowStates winState = win->windowState();
+	auto winState = win->windowState();
+	winState = de.attribute("maximized").toInt()
+		? (winState | Qt::WindowMaximized)
+		: (winState & ~Qt::WindowMaximized);

And then again, without the check there's currently nothing that would behave differently compared to the version without explicit minimum heights, so unless you want to keep them for clarity they can be removed as well.

sorry if i'm repeating myself, i just want to be sure that i'm clear

@yohannd1
Copy link
Contributor Author

yohannd1 commented Mar 2, 2026

That does make sense! I've now removed it. Just in case, I've added a comment (not sure if it is of much help either way...):

There used to be validity checks here, but they are not needed anymore.

Also, since win->windowState() returns a Qt::WindowStates, I've noticed the window-maximization logic can be simplified to this:

// Set the window to its correct "maximized?" state.
auto winState = win->windowState();
winState.setFlag(Qt::WindowMaximized, de.attribute("maximized").toInt());
win->setWindowState(winState);

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.

Negative subwindow positions get invalidated when loading project

4 participants