Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.3] Prevent preferences dialog from going out of screen #4613

Merged
merged 4 commits into from
May 31, 2022
Merged
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
41 changes: 32 additions & 9 deletions src/preferences/dialog/dlgpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,20 +363,43 @@ void DlgPreferences::onShow() {
}
int newX = m_geometry[0].toInt();
int newY = m_geometry[1].toInt();
int newWidth = m_geometry[2].toInt();
int newHeight = m_geometry[3].toInt();

const QScreen* const pScreen = mixxx::widgethelper::getScreen(*this);
QSize screenSpace;
QRect screenAvailableGeometry;
VERIFY_OR_DEBUG_ASSERT(pScreen) {
qWarning() << "Assuming screen size of 800x600px.";
screenSpace = QSize(800, 600);
screenAvailableGeometry = QRect(0, 0, 800, 600);
}
else {
screenSpace = pScreen->size();
screenAvailableGeometry = pScreen->availableGeometry();
}
newX = std::max(0, std::min(newX, screenSpace.width() - m_geometry[2].toInt()));
newY = std::max(0, std::min(newY, screenSpace.height() - m_geometry[3].toInt()));

// Make sure the entire window is visible on screen and is not occluded by taskbar
// Note: Window geometry excludes window decoration
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Note: Window geometry excludes window decoration
// The window's frameGeometry() includes window decoration, geometry() does not

Copy link
Member

Choose a reason for hiding this comment

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

Do you mind updating the comments in resizeEvent() and moveEvent()?

int windowDecorationWidth = frameGeometry().width() - geometry().width();
int windowDecorationHeight = frameGeometry().height() - geometry().height();
if (windowDecorationWidth <= 0) {
windowDecorationWidth = 2;
}
if (windowDecorationHeight <= 0) {
windowDecorationHeight = 30;
}
Comment on lines +383 to +388
Copy link
Member

Choose a reason for hiding this comment

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

this does not make sense to me. Would you mind giving some explanation?

Copy link
Member

@ronso0 ronso0 Jan 9, 2022

Choose a reason for hiding this comment

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

I'm currently debugging a similiar issue with DlgDevTools¹ and I ended up here, too:

Those magic numbers are used as default window decoration dimensions in QRect DlgPreferences::getDefaultGeometry() in case they cannot be retireved from the OS. !?

¹when I open it the initial window it's like 10.000 pixels wide

int availableWidth = screenAvailableGeometry.width() - windowDecorationWidth;
int availableHeight = screenAvailableGeometry.height() - windowDecorationHeight;
newWidth = std::min(newWidth, availableWidth);
newHeight = std::min(newHeight, availableHeight);
int minX = screenAvailableGeometry.x();
int minY = screenAvailableGeometry.y();
int maxX = screenAvailableGeometry.x() + availableWidth - newWidth;
int maxY = screenAvailableGeometry.y() + availableHeight - newHeight;
newX = std::clamp(newX, minX, maxX);
newY = std::clamp(newY, minY, maxY);
m_geometry[0] = QString::number(newX);
m_geometry[1] = QString::number(newY);
m_geometry[2] = QString::number(newWidth);
m_geometry[3] = QString::number(newHeight);

// Update geometry with last values
#ifdef __WINDOWS__
Expand All @@ -391,10 +414,10 @@ void DlgPreferences::onShow() {
int offsetY = geometry().top() - frameGeometry().top();
newX += offsetX;
newY += offsetY;
setGeometry(newX, // x position
newY, // y position
m_geometry[2].toInt(), // width
m_geometry[3].toInt()); // height
setGeometry(newX, // x position
newY, // y position
newWidth, // width
newHeight); // height
#endif // __LINUX__ / __MACOS__
// Move is also needed on linux.
move(newX, newY);
Expand Down