支持通过拖动标题栏退出最大化#5172
Conversation
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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 -> { |
There was a problem hiding this comment.
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