JBR-7524: Workaround for showing window tiling actions when hovering over the maximize button on macOS

This commit is contained in:
Nikita Tsarev
2024-10-01 12:08:43 +02:00
parent 3ede03b58a
commit 1e1115a28e
2 changed files with 73 additions and 0 deletions

View File

@@ -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

View File

@@ -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;
}