Skip to content
Permalink
Browse files
8233678: [macos 10.15] System menu bar does not work initially on mac…
…OS Catalina

Reviewed-by: jvos, aghaisas
  • Loading branch information
kevinrushforth committed Dec 7, 2020
1 parent ca0d3d0 commit e7dbdfcba095a2416485b1ff41acd1d70efe285d
@@ -217,94 +217,97 @@ public String getDataDirectory() {
return userHome + File.separator + "." + name + File.separator;
}

private void notifyWillFinishLaunching() {
// Subclasses can override the following notify methods.
// Overridden methods need to call super.

protected void notifyWillFinishLaunching() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleWillFinishLaunchingAction(this, System.nanoTime());
}
}

private void notifyDidFinishLaunching() {
protected void notifyDidFinishLaunching() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleDidFinishLaunchingAction(this, System.nanoTime());
}
}

private void notifyWillBecomeActive() {
protected void notifyWillBecomeActive() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleWillBecomeActiveAction(this, System.nanoTime());
}
}

private void notifyDidBecomeActive() {
protected void notifyDidBecomeActive() {
this.initialActiveEventReceived = true;
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleDidBecomeActiveAction(this, System.nanoTime());
}
}

private void notifyWillResignActive() {
protected void notifyWillResignActive() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleWillResignActiveAction(this, System.nanoTime());
}
}

private boolean notifyThemeChanged(String themeName) {
protected boolean notifyThemeChanged(String themeName) {
EventHandler handler = getEventHandler();
if (handler != null) {
return handler.handleThemeChanged(themeName);
}
return false;
}

private void notifyDidResignActive() {
protected void notifyDidResignActive() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleDidResignActiveAction(this, System.nanoTime());
}
}

private void notifyDidReceiveMemoryWarning() {
protected void notifyDidReceiveMemoryWarning() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleDidReceiveMemoryWarning(this, System.nanoTime());
}
}

private void notifyWillHide() {
protected void notifyWillHide() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleWillHideAction(this, System.nanoTime());
}
}

private void notifyDidHide() {
protected void notifyDidHide() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleDidHideAction(this, System.nanoTime());
}
}

private void notifyWillUnhide() {
protected void notifyWillUnhide() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleWillUnhideAction(this, System.nanoTime());
}
}

private void notifyDidUnhide() {
protected void notifyDidUnhide() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleDidUnhideAction(this, System.nanoTime());
}
}

// notificiation when user drag and drops files onto app icon
private void notifyOpenFiles(String files[]) {
protected void notifyOpenFiles(String files[]) {
if ((this.initialActiveEventReceived == false) && (this.initialOpenedFiles == null)) {
// rememeber the initial opened files
this.initialOpenedFiles = files;
@@ -315,7 +318,7 @@ private void notifyOpenFiles(String files[]) {
}
}

private void notifyWillQuit() {
protected void notifyWillQuit() {
EventHandler handler = getEventHandler();
if (handler != null) {
handler.handleQuitAction(this, System.nanoTime());
@@ -28,13 +28,16 @@
import com.sun.glass.ui.*;
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
import com.sun.javafx.util.Logging;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

final class MacApplication extends Application implements InvokeLaterDispatcher.InvokeLaterSubmitter {

@@ -73,14 +76,49 @@ native void _runLoop(ClassLoader classLoader, Runnable launchable,
boolean isTaskbarApplication);
@Override
protected void runLoop(final Runnable launchable) {
// For normal (not embedded) taskbar applications the masOS activation
// init code will deactivate and then reactivate the application to
// allow the system menubar to work properly.
// We need to spin up a nested event loop and wait for the reactivation
// to finish prior to allowing the rest of the initialization to run.
final Runnable wrappedRunnable = () -> {
if (isNormalTaskbarApp()) {
waitForReactivation();
}
launchable.run();
};

isTaskbarApplication =
AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
String taskbarAppProp = System.getProperty("glass.taskbarApplication");
return !"false".equalsIgnoreCase(taskbarAppProp);
});

ClassLoader classLoader = MacApplication.class.getClassLoader();
_runLoop(classLoader, launchable, isTaskbarApplication);
_runLoop(classLoader, wrappedRunnable, isTaskbarApplication);
}

private final CountDownLatch reactivationLatch = new CountDownLatch(1);

// Spin up a nested event loop waiting for the app reactivation event
void waitForReactivation() {
final EventLoop eventLoop = createEventLoop();
Thread thr = new Thread(() -> {
try {
if (!reactivationLatch.await(5, TimeUnit.SECONDS)) {
Logging.getJavaFXLogger().warning("Timeout while waiting for app reactivation");
}
} catch (InterruptedException ex) {
Logging.getJavaFXLogger().warning("Exception while waiting for app reactivation: " + ex);
}
Application.invokeLater(() -> {
eventLoop.leave(null);
});
});
thr.setDaemon(true);
thr.start();

eventLoop.enter();
}

native private void _finishTerminating();
@@ -95,6 +133,22 @@ private void notifyApplicationDidTerminate() {
setEventThread(null);
}

private boolean firstDidResignActive = false;

@Override
protected void notifyDidResignActive() {
firstDidResignActive = true;
super.notifyDidResignActive();
}

@Override
protected void notifyDidBecomeActive() {
if (firstDidResignActive) {
reactivationLatch.countDown();
}
super.notifyDidBecomeActive();
}

// Called from the native code
private void setEventThread() {
setEventThread(Thread.currentThread());
@@ -313,6 +367,13 @@ protected boolean _supportsTransparentWindows() {

@Override native protected boolean _supportsSystemMenu();

// NOTE: this will not return a valid result until the native _runloop
// method has been executed and called the Runnable passed to that method.
native private boolean _isNormalTaskbarApp();
boolean isNormalTaskbarApp() {
return _isNormalTaskbarApp();
}

native protected String _getRemoteLayerServerName();
public String getRemoteLayerServerName() {
return _getRemoteLayerServerName();
@@ -54,7 +54,10 @@
static BOOL isFullScreenExitingLoop = NO;
static NSMutableDictionary * keyCodeForCharMap = nil;
static BOOL isEmbedded = NO;
static BOOL isNormalTaskbarApp = NO;
static BOOL disableSyncRendering = NO;
static BOOL firstActivation = YES;
static BOOL shouldReactivate = NO;

#ifdef STATIC_BUILD
jint JNICALL JNI_OnLoad_glass(JavaVM *vm, void *reserved)
@@ -271,6 +274,13 @@ - (void)applicationDidBecomeActive:(NSNotification *)aNotification
}
[pool drain];
GLASS_CHECK_EXCEPTION(env);

if (isNormalTaskbarApp && firstActivation) {
LOG("-> deactivate (hide) app");
firstActivation = NO;
shouldReactivate = YES;
[NSApp hide:NSApp];
}
}

- (void)applicationWillResignActive:(NSNotification *)aNotification
@@ -297,6 +307,12 @@ - (void)applicationDidResignActive:(NSNotification *)aNotification
}
[pool drain];
GLASS_CHECK_EXCEPTION(env);

if (isNormalTaskbarApp && shouldReactivate) {
LOG("-> reactivate app");
shouldReactivate = NO;
[NSApp activateIgnoringOtherApps:YES];
}
}

- (void)applicationWillHide:(NSNotification *)aNotification
@@ -517,6 +533,7 @@ - (void)runLoop:(id)selector
{
if (self->jTaskBarApp == JNI_TRUE)
{
isNormalTaskbarApp = YES;
// move process from background only to full on app with visible Dock icon
ProcessSerialNumber psn;
if (GetCurrentProcess(&psn) == noErr)
@@ -1050,6 +1067,18 @@ + (BOOL)syncRenderingDisabled {
return !isEmbedded;
}

/*
* Class: com_sun_glass_ui_mac_MacApplication
* Method: _isNormalTaskbarApp
* Signature: ()Z;
*/
JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_mac_MacApplication__1isNormalTaskbarApp
(JNIEnv *env, jobject japplication)
{
LOG("Java_com_sun_glass_ui_mac_MacApplication__1isNormalTaskbarApp");
return isNormalTaskbarApp;
}

/*
* Class: com_sun_glass_ui_mac_MacApplication
* Method: _hide
@@ -324,6 +324,7 @@ - (void)_setPixels:(jobject)pixels

if ([[glassmenu->item title] compare:@"Apple"] == NSOrderedSame)
{
LOG("calling setAppleMenu");
[NSApp performSelector:@selector(setAppleMenu:) withObject:glassmenu->item];
}

0 comments on commit e7dbdfc

Please sign in to comment.