Skip to content
Permalink
Browse files

Fix dialog focus on macOS (#408)

Prevent additional QZ Tray instances being launched when in CLI or IDE and clicking on "About", etc.
  • Loading branch information...
Vzor- authored and tresf committed Jan 31, 2019
1 parent ec2f876 commit fecdce382e682b31a5831afbfd3b0c5512283faf
Showing with 15 additions and 1 deletion.
  1. +4 −1 src/qz/ui/BasicDialog.java
  2. +11 −0 src/qz/utils/MacUtilities.java
@@ -1,6 +1,7 @@
package qz.ui;

import qz.common.Constants;
import qz.utils.MacUtilities;
import qz.utils.ShellUtilities;
import qz.utils.SystemUtilities;

@@ -159,7 +160,9 @@ public ImageIcon getIcon(IconCache.Icon icon) {
public void setVisible(boolean b) {
// fix window focus on macOS
if (SystemUtilities.isMac() && !GraphicsEnvironment.isHeadless()) {
ShellUtilities.executeAppleScript("tell application \"" + Constants.ABOUT_TITLE + "\" to activate");
ShellUtilities.executeAppleScript("tell application \"System Events\" " +
"set frontmost of every process whose unix id is " + MacUtilities.getProcessID() + " to true " +
"end tell");
}
super.setVisible(b);
}
@@ -11,6 +11,8 @@
package qz.utils;

import com.apple.OSXAdapter;
import com.sun.jna.Library;
import com.sun.jna.Native;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import qz.common.TrayManager;
@@ -106,4 +108,13 @@ public static int getScaleFactor() {
return 1;
}

public static int getProcessID() {
return CLibrary.INSTANCE.getpid();
}

private interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary) Native.loadLibrary("c", CLibrary.class);
int getpid ();
}

}

0 comments on commit fecdce3

Please sign in to comment.
You can’t perform that action at this time.