From a4b10d99d84133ff04fbe032c1235d7a8bb1e72c Mon Sep 17 00:00:00 2001 From: testing-ongithub <96100526+testing-ongithub@users.noreply.github.com> Date: Sun, 2 Jan 2022 10:26:06 -0600 Subject: [PATCH] Fix clicking tray icon not bringing client to front on macOS --- .../java/net/runelite/client/util/SwingUtil.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java b/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java index 828adfdadf..08bd9613a4 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java +++ b/runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java @@ -184,6 +184,18 @@ public class SwingUtil @Override public void mouseClicked(MouseEvent e) { + if (OSType.getOSType() == OSType.MacOS) + { + // On macOS, frame.setVisible(true) only restores focus when the visibility was previously false. + // The frame's visibility is not set to false when the window loses focus, so we set it manually. + // Additionally, in order to bring the window to the foreground, + // frame.setVisible(true) calls CPlatformWindow::nativePushNSWindowToFront. + // However, this native method is not called with activateIgnoringOtherApps:YES, + // so any other active window will prevent our window from being brought to the front. + // To work around this, we use our macOS-specific requestForeground(). + frame.setVisible(false); + OSXUtil.requestForeground(); + } frame.setVisible(true); frame.setState(Frame.NORMAL); // Restore }