Skip to content

Commit

Permalink
JBR-7524: Workaround for showing window tiling actions when hovering …
Browse files Browse the repository at this point in the history
…over the maximize button on macOS
  • Loading branch information
tsarn committed Oct 4, 2024
1 parent 3ede03b commit 1e1115a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#import "LWCToolkit.h"

@class AWTView;
@class AWTWindowZoomButtonMouseResponder;

@interface AWTWindow : NSObject <NSWindowDelegate> {
@private
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -128,8 +130,14 @@
NSColor* _color;
}


- (void)configureColors;

@end

@interface AWTWindowZoomButtonMouseResponder : NSResponder
- (id) initWithWindow:(NSWindow*)window;
@end


#endif _AWTWINDOW_H
65 changes: 65 additions & 0 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ - (void)_setHidden:(BOOL)h animated:(BOOL)a;
@interface NSWindow (Private)
- (void)_setTabBarAccessoryViewController:(id)controller;
- (void)setIgnoreMove:(BOOL)value;
- (BOOL)isIgnoreMove;
- (void)_adjustWindowToScreen;
@end

Expand Down Expand Up @@ -403,6 +404,10 @@ - (void)setIgnoreMove:(BOOL)value {
self.movable = !value;
}

- (BOOL)isIgnoreMove {
return _ignoreMove;
}

- (void)_adjustWindowToScreen {
if (_ignoreMove) {
self.movable = YES;
Expand Down Expand Up @@ -808,6 +813,7 @@ - (void) dealloc {
self.customTitleBarConstraints = nil;
self.customTitleBarHeightConstraint = nil;
self.customTitleBarButtonCenterXConstraints = nil;
self.zoomButtonMouseResponder = nil;
[super dealloc];
}

Expand Down Expand Up @@ -1659,6 +1665,9 @@ - (void) setUpCustomTitleBar {
]];

[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];
Expand Down Expand Up @@ -1906,6 +1915,62 @@ - (void) updateCustomTitleBar {

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

0 comments on commit 1e1115a

Please sign in to comment.