-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix the maximize behavior of subwindows on Mac #2798
Conversation
@tresf please test out what happens if more than one window are maximized.
I hope, everything goes right with this PR. |
The behavior is quite bazaar. It seems that Qt on Mac honors the "Only one window can be maximized at a time" behavior. Which can leave the button in a strange situation where it does nothing... 9 out of 10 times the behavior seems correct though although I did get it to lock in the "restore" mode where the maximize pixmap was displayed indefinitely. It seems when the maximized window gains focus, it usually goes back to the proper "maximize" mode with the restore pixmap displayed. I still question if this is the right way. It seems we could bind the maximize and restore buttons to whatever the context menu action is, but I haven't delved into the code that much. |
No, I think there is something with the scroll bar on your first screeny. I guess, the window size is smaller than the MdiArea size and the test fails. 😣 |
@tresf : I have updated this PR. And I edit a explanation in the description above. Please check out the branch. Thank you for testing this. |
I still wonder if the context menu is handled by window manager, since the MDI subwindow is inherited from MainWindow. |
I'm sorry, if I've messed someone up, but this has nothing to do with context menu. It only implements a new function which tests if the subwindow is maximized (see above, first post) regards |
dee95b0 👍 |
#ifdef LMMS_BUILD_APPLE | ||
if( isMaximizedOnMac() ) | ||
{ | ||
m_maximizeBtn->hide(); |
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.
Is the ->hide()
redundant? It seems you do it on every resize regardless, no?
yes. 👍 , and I found another one. Update |
@@ -121,6 +123,23 @@ void SubWindow::elideText( QLabel *label, QString text ) | |||
|
|||
|
|||
|
|||
bool SubWindow::isMaximizedOnMac() | |||
{ | |||
// we check if the subwindow size is identically to the MdiArea size |
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.
This can be simplified.
// check if subwindow size is identical to the MdiArea size, accounting for scrollbars
update |
@@ -220,22 +235,34 @@ void SubWindow::resizeEvent( QResizeEvent * event ) | |||
{ | |||
buttonBarWidth = buttonBarWidth + m_buttonSize.width() + buttonGap; | |||
m_maximizeBtn->move( middleButtonPos ); | |||
// on Mac the isMaximize() function returns always false |
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.
Mentioning an unused function can confuse people when they read this later.
- Should we be using
isMaximize()
instead ofWindowMaximizeButtonHint
? - If so, should we override this on Mac only and leave the logic identical between function calls?
The reason I ask is that the logic is for Mac-only yet we allow some portions to execute every resize event (such as && !isMaximizedOnMac()
. Is that desired?
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.
- I'm unsure if I understand you right here. Qt::WindowMaximizeButtonHint is a Flag which returns true if the window is able to maximize. For example the Fx-Mixer window is not able to be maximized therefore this flag returns false. And if it's false we don't need the maximize button.
- We could implement the isMaximized() function in this form:
bool SubWindow::isMaximized()
{
#ifdef LMMS_BUILD_APPLE
// check if subwindow size is identical to the MdiArea size, accounting for scrollbars
int hScrollBarHeight = mdiArea()->horizontalScrollBar()->isVisible() ? mdiArea()->horizontalScrollBar()->size().height() : 0;
int vScrollBarWidth = mdiArea()->verticalScrollBar()->isVisible() ? mdiArea()->verticalScrollBar()->size().width() : 0;
QSize areaSize( this->mdiArea()->size().width() - vScrollBarWidth, this->mdiArea()->size().height() - hScrollBarHeight );
return areaSize == this->size();
#else
return QMdiSubWindow::isMaximized();
#endif
}
So we have one function for all systems. But for what I see at the first look, we have on Linux & Co. one more redundant function call. I'll look tomorrow into it.
Regards
Testing still passes. I left some more comments about the code approach. 👍 |
Okay, we have now one |
@BaraMGB the code looks good 👍 |
{ | ||
m_minimizeBtn->move( middleButtonPos ); | ||
} | ||
else | ||
{ | ||
m_minimizeBtn->move( leftButtonPos ); | ||
} | ||
m_minimizeBtn->show(); | ||
m_restoreBtn->hide(); | ||
if( isMinimized() ) | ||
{ | ||
if( m_maximizeBtn->isHidden() ) |
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.
This entire if/else can be simplified....
m_restoreBtn->move( m_maximizeBtn->isHidden() ? middleButtonPos : leftButtonPos );
No objections, but I still have yet to test it out on OS X. |
update. |
m_restoreBtn->move( middleButtonPos ); | ||
if( isMaximized() ) | ||
{ | ||
m_restoreBtn->show(); |
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.
Perhaps...
m_restoreBtn->setVisible( isMaximized() );
m_maximizeBtn->setVisible( !isMaximized() );
May also remove the need to hide everything at the top of the function.
Just a side note... I'm not sure how well the optimizers handle this type of logic, but down the road isMaximized()
may benefit from being cached into a variable for the resize event if we ever are in a scenario where we do a bunch of window resizing (such as on project load, etc). Minor point though.... otherwise, the wasted CPU cycles should be relatively benign.
Tested, works fine. Minor note, the restore button can have some strange behavior if restoring two maximized windows one-after the other. The hiding of the scrollbar seems to nudge the min/max/restore buttons to the right when it gains focus and it ignores the click until the scrollbar hides, then it works fine. I'm not sure if this is easy to fix and I don't want to beat it up, so this is ok to merge. I did make a comment on the use of |
AFAIK, Modern compilers can optimize these things quite well, especially when combined with PGO (Profile Guided Optimization) (Note: No luck with LMMS, the optimization changes will crash LMMS). |
Can you provide a screenshot? |
👍 Add some more code optimisations. |
I try to install a build enviroment for this in a VM. I hope it works like expected and I can install OS10.10 for this. Regards |
You do not need to do this. I can continue testing for you. |
@tresf Okay, now the restore button should appears again. |
Just for references, it turned out that #488 (comment) is the reason for the wrong behavior. #4819 should be the correct way. |
fix the maximize behavior of subwindows on Mac
#2450 (comment) @tresf reported an issue on mac. The subwindow don't maximize proper. The button don't change from maximize to restore. This PR fix this.
edit Explanation:
I added a function for testing if the subwindow is maximized. It's quite simple: it checks if the subwindow size is identically to the size of the MdiArea. But we have to care about the Scrollbars of the MdiArea. If an other Subwindow is in Front of the maximized Subwindow, the MdiArea has Scrollbars (sometimes horizontal, sometimes vertical). Our Subwindow becomes smaller than the MdiArea although it is maximized.