mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-7524: Workaround for showing window tiling actions when hovering over the maximize button on macOS
(cherry picked from commit 8fb519bec4)
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#import "LWCToolkit.h"
|
||||
|
||||
@class AWTView;
|
||||
@class AWTWindowZoomButtonMouseResponder;
|
||||
|
||||
@interface AWTWindow : NSObject <NSWindowDelegate> {
|
||||
@private
|
||||
@@ -79,6 +80,7 @@
|
||||
@property (nonatomic, retain) NSLayoutConstraint *customTitleBarHeightConstraint;
|
||||
@property (nonatomic, retain) NSMutableArray *customTitleBarButtonCenterXConstraints;
|
||||
@property (nonatomic) BOOL hideTabController;
|
||||
@property (nonatomic, retain) AWTWindowZoomButtonMouseResponder* zoomButtonMouseResponder;
|
||||
|
||||
- (id) initWithPlatformWindow:(jobject)javaPlatformWindow
|
||||
ownerWindow:owner
|
||||
@@ -128,8 +130,14 @@
|
||||
NSColor* _color;
|
||||
}
|
||||
|
||||
|
||||
- (void)configureColors;
|
||||
|
||||
@end
|
||||
|
||||
@interface AWTWindowZoomButtonMouseResponder : NSResponder
|
||||
- (id) initWithWindow:(NSWindow*)window;
|
||||
@end
|
||||
|
||||
|
||||
#endif _AWTWINDOW_H
|
||||
|
||||
@@ -82,6 +82,7 @@ BOOL isColorMatchingEnabled() {
|
||||
@interface NSWindow (Private)
|
||||
- (void)_setTabBarAccessoryViewController:(id)controller;
|
||||
- (void)setIgnoreMove:(BOOL)value;
|
||||
- (BOOL)isIgnoreMove;
|
||||
- (void)_adjustWindowToScreen;
|
||||
@end
|
||||
|
||||
@@ -403,6 +404,10 @@ AWT_NS_WINDOW_IMPLEMENTATION
|
||||
self.movable = !value;
|
||||
}
|
||||
|
||||
- (BOOL)isIgnoreMove {
|
||||
return _ignoreMove;
|
||||
}
|
||||
|
||||
- (void)_adjustWindowToScreen {
|
||||
if (_ignoreMove) {
|
||||
self.movable = YES;
|
||||
@@ -808,6 +813,7 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
self.customTitleBarConstraints = nil;
|
||||
self.customTitleBarHeightConstraint = nil;
|
||||
self.customTitleBarButtonCenterXConstraints = nil;
|
||||
self.zoomButtonMouseResponder = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -1661,6 +1667,9 @@ static const CGFloat DefaultHorizontalTitleBarButtonOffset = 20.0;
|
||||
]];
|
||||
|
||||
[self.nsWindow setIgnoreMove:YES];
|
||||
|
||||
self.zoomButtonMouseResponder = [[AWTWindowZoomButtonMouseResponder alloc] initWithWindow:self.nsWindow];
|
||||
[self.zoomButtonMouseResponder release]; // property retains the object
|
||||
|
||||
AWTWindowDragView* windowDragView = [[AWTWindowDragView alloc] initWithPlatformWindow:self.javaPlatformWindow];
|
||||
[titlebar addSubview:windowDragView positioned:NSWindowBelow relativeTo:closeButtonView];
|
||||
@@ -1908,6 +1917,62 @@ static const CGFloat DefaultHorizontalTitleBarButtonOffset = 20.0;
|
||||
|
||||
@end // AWTWindow
|
||||
|
||||
@implementation AWTWindowZoomButtonMouseResponder {
|
||||
NSWindow* _window;
|
||||
NSTrackingArea* _trackingArea;
|
||||
}
|
||||
|
||||
- (id) initWithWindow:(NSWindow*)window {
|
||||
self = [super init];
|
||||
if (self == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (![window isKindOfClass: [AWTWindow_Normal class]]) {
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSView* zoomButtonView = [window standardWindowButton:NSWindowZoomButton];
|
||||
if (zoomButtonView == nil) {
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
_window = [window retain];
|
||||
_trackingArea = [[NSTrackingArea alloc]
|
||||
initWithRect:zoomButtonView.bounds
|
||||
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow
|
||||
owner:self
|
||||
userInfo:nil
|
||||
];
|
||||
[zoomButtonView addTrackingArea:_trackingArea];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)mouseEntered:(NSEvent*)event {
|
||||
if ([_window isIgnoreMove]) {
|
||||
// Enable moving the window while we're mousing over the "maximize" button so that
|
||||
// macOS 15 window tiling actions can properly appear
|
||||
_window.movable = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mouseExited:(NSEvent*)event {
|
||||
if ([_window isIgnoreMove]) {
|
||||
_window.movable = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_window release];
|
||||
[_trackingArea release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation AWTWindowDragView {
|
||||
BOOL _dragging;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user