-
Notifications
You must be signed in to change notification settings - Fork 813
支持通过拖动标题栏退出最大化 #5172
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
base: main
Are you sure you want to change the base?
支持通过拖动标题栏退出最大化 #5172
Conversation
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.
Pull request overview
This PR implements support for exiting the maximized window state by dragging the title bar, addressing feature request #5138. When a maximized window's title bar is dragged, the window should un-maximize and follow the cursor.
Changes:
- Enabled mouse event handling when window is maximized
- Added logic to detect dragging on maximized windows and exit maximized state
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if (primaryStage.isMaximized()) { | ||
| primaryStage.setMaximized(false); | ||
| mouseInitX = primaryStage.getWidth() / 2; |
Copilot
AI
Jan 10, 2026
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.
When exiting maximized state during a drag operation, only mouseInitX is being updated but mouseInitY is not. This will cause incorrect vertical positioning when the user drags the window. Both coordinates should be updated to ensure the window follows the cursor properly. Additionally, stageInitX and stageInitY should be set to the new window position after un-maximizing to ensure proper drag calculations.
| mouseInitX = primaryStage.getWidth() / 2; | |
| // Reinitialize drag reference points after restoring from maximized state | |
| mouseInitX = mouseEvent.getScreenX(); | |
| mouseInitY = mouseEvent.getScreenY(); | |
| stageInitX = primaryStage.getX(); | |
| stageInitY = primaryStage.getY(); | |
| stageInitWidth = primaryStage.getWidth(); | |
| stageInitHeight = primaryStage.getHeight(); |
|
我觉得这个还是有用的。 |
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.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| primaryStage.setY(stageInitY = 0); | ||
| primaryStage.setX(stageInitX = mouseInitX - stageInitWidth / 2); |
Copilot
AI
Jan 15, 2026
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.
The logic doesn't continue dragging after un-maximizing. After setting dragging to true and un-maximizing, the window is positioned but subsequent mouse movement won't move the window until the user releases and starts dragging again. The existing onMouseDragged handler (line 450) expects stageInitX and stageInitY to represent the initial stage position, not 0. Consider setting stageInitX and stageInitY to the calculated position values (mouseInitX - stageInitWidth / 2 and 0 respectively) after setting the stage position, so the subsequent dragging in onMouseDragged continues smoothly.
| primaryStage.setY(stageInitY = 0); | |
| primaryStage.setX(stageInitX = mouseInitX - stageInitWidth / 2); | |
| double newStageY = 0; | |
| double newStageX = mouseInitX - stageInitWidth / 2; | |
| primaryStage.setY(newStageY); | |
| primaryStage.setX(newStageX); | |
| stageInitY = newStageY; | |
| stageInitX = newStageX; |
| } | ||
| if (onTitleBarDoubleClick != null) | ||
| center.setOnMouseClicked(onTitleBarDoubleClick); | ||
| center.setOnMouseDragged(mouseEvent -> { |
Copilot
AI
Jan 15, 2026
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 handler only handles the initial un-maximize action but doesn't consume the event or continue the drag. After un-maximizing, you should either consume the event or delegate to the existing onMouseDragged logic to ensure smooth continuous dragging. Without this, there's a disconnect between the un-maximize action and subsequent drag behavior.
close #5138