Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 562535 - [macOS 10.15] Menu is unresponsive after starting application
Summary: [macOS 10.15] Menu is unresponsive after starting application
Status: CLOSED DUPLICATE of bug 552063
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.15   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-27 14:42 EDT by Alexandr Miloslavskiy CLA
Modified: 2020-07-04 17:22 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandr Miloslavskiy CLA 2020-04-27 14:42:20 EDT
This happens even with the simplest snippets such as this:

----------------
public static void main(String[] args) {
	Display display = new Display();
	Shell shell = new Shell(display);

	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
----------------

Steps:
1) Start snippet
2) Try to click menu
3) Switch to some other app and back
4) Menu is now responsive.

I also managed to reproduce it with a simple native snippet:
----------------
#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject<NSApplicationDelegate>
{
}
@end

@implementation AppDelegate : NSObject
-(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)app
{
    return YES;
}
@end

int main ()
{
    NSApplication* app = [NSApplication sharedApplication];
    // Appliaction should close when last window is closed
    AppDelegate* appDelegate = [[AppDelegate alloc] init];
    [app setDelegate:appDelegate];
    // Programs without application bundles and Info.plist files don't get a menubar and can't be brought to the front without this
    [app setActivationPolicy:NSApplicationActivationPolicyRegular];

    NSRect windowRect = NSMakeRect(0, 0, 200, 200);
    id window = [[NSWindow alloc]
        initWithContentRect: windowRect
        styleMask: NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable | NSWindowStyleMaskMiniaturizable
        backing: NSBackingStoreBuffered
        defer:NO
        ];
    [window setTitle:[[NSProcessInfo processInfo] processName]];
    [window makeKeyAndOrderFront:nil];

    [app run];
    return 0;
}
----------------

Compile it with:
clang -framework snippet.m -o snippet

I also found reports in other places:
https://bugs.openjdk.java.net/browse/JDK-8233678
http://www.androwish.org/index.html/info/3583d49f8642eac557517123d6f573ae106e6ce9

The latter uses `[NSApp deactivate]` + `[NSApp activateIgnoringOtherApps: YES]` as workaround.
Comment 1 Alexandr Miloslavskiy CLA 2020-04-27 14:43:33 EDT
I suspect that this may be related to non-bundled applications.
Comment 2 Lakshmi P Shanmugam CLA 2020-04-28 00:48:09 EDT
(In reply to Alexandr Miloslavskiy from comment #0)
> http://www.androwish.org/index.html/info/
> 3583d49f8642eac557517123d6f573ae106e6ce9
> 
> The latter uses `[NSApp deactivate]` + `[NSApp activateIgnoringOtherApps:
> YES]` as workaround.

I'll try if this fixes the problem in SWT.

*** This bug has been marked as a duplicate of bug 552063 ***
Comment 3 Alex Blewitt CLA 2020-07-04 11:17:06 EDT
I've condensed this code into a Git repository:

https://github.com/alblue/Bugger

I've attempted to do the [NSApp deactivate]+[NSApp activateIgnoringOtherApps] combinations, but neither seems to work.

I'll see if I can do something further to get it working with the snippet provided by Alexandr or report it to Apple.
Comment 4 Alex Blewitt CLA 2020-07-04 17:22:50 EDT
What's interesting is that with a 'real' macOS app, if you run the app binary directly it does /not/ bring it to the front and give it focus, so you have to tap on it.

If on the other hand you use 'open' to open the app, then macOS gives it the focus.