-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from 1 commit
cc86bf3
6f8f8dc
cc0b7bb
3f7fc18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -363,6 +363,8 @@ 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; | ||||||||||
|
@@ -371,12 +373,29 @@ void DlgPreferences::onShow() { | |||||||||
screenSpace = QSize(800, 600); | ||||||||||
} | ||||||||||
else { | ||||||||||
screenSpace = pScreen->size(); | ||||||||||
screenSpace = pScreen->availableSize(); | ||||||||||
} | ||||||||||
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 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = screenSpace.width() - windowDecorationWidth; | ||||||||||
int availableHeight = screenSpace.height() - windowDecorationHeight; | ||||||||||
newWidth = std::min(newWidth, availableWidth); | ||||||||||
newHeight = std::min(newHeight, availableHeight); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does not make sense to me either. |
||||||||||
newX = std::max(0, std::min(newX, availableWidth - newWidth)); | ||||||||||
newY = std::max(0, std::min(newY, availableHeight - newHeight)); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://en.cppreference.com/w/cpp/algorithm/clamp
Suggested change
|
||||||||||
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__ | ||||||||||
|
@@ -393,8 +412,8 @@ void DlgPreferences::onShow() { | |||||||||
newY += offsetY; | ||||||||||
setGeometry(newX, // x position | ||||||||||
newY, // y position | ||||||||||
m_geometry[2].toInt(), // width | ||||||||||
m_geometry[3].toInt()); // height | ||||||||||
newWidth, // width | ||||||||||
newHeight); // height | ||||||||||
#endif // __LINUX__ / __MACOS__ | ||||||||||
// Move is also needed on linux. | ||||||||||
move(newX, newY); | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
availableSize
returns QSize(width, height)Did you consider pScreen->
availableGeometry()
here? It returns QRect(int x, int y, int width, int height)