diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h index be4edfa521fb..ab33c7d8adef 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h @@ -32,6 +32,7 @@ #import "LWCToolkit.h" @class AWTView; +@class AWTWindowZoomButtonMouseResponder; @interface AWTWindow : NSObject { @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 diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m index 326e8272bb33..3590eb996b5e 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m @@ -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]; } @@ -1659,6 +1665,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]; @@ -1906,6 +1915,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; }