From fb48c9619405a345507ee79dc1d29d262a617a6a Mon Sep 17 00:00:00 2001 From: arlyon Date: Sat, 3 Mar 2018 02:12:33 +0000 Subject: [PATCH 1/2] extract mac-specific functionality into OSXUtil also adds orange-extensions to stub the dependencies jar on other systems pom --- runelite-client/pom.xml | 6 ++ .../java/net/runelite/client/ui/ClientUI.java | 28 +------- .../net/runelite/client/util/OSXUtil.java | 64 +++++++++++++++++++ 3 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/util/OSXUtil.java diff --git a/runelite-client/pom.xml b/runelite-client/pom.xml index bffe89bb2b..1e5c50baab 100644 --- a/runelite-client/pom.xml +++ b/runelite-client/pom.xml @@ -130,6 +130,12 @@ discord 1.0 + + net.runelite + orange-extensions + 1.0 + provided + junit diff --git a/runelite-client/src/main/java/net/runelite/client/ui/ClientUI.java b/runelite-client/src/main/java/net/runelite/client/ui/ClientUI.java index 937eeeb8ce..2c435ad80c 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/ClientUI.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/ClientUI.java @@ -37,14 +37,12 @@ import java.awt.LayoutManager; import java.awt.SystemTray; import java.awt.Toolkit; import java.awt.TrayIcon; -import java.awt.Window; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.util.Enumeration; import javax.imageio.ImageIO; import javax.swing.BoxLayout; @@ -67,7 +65,7 @@ import net.runelite.api.GameState; import net.runelite.api.events.ConfigChanged; import net.runelite.client.RuneLite; import net.runelite.client.RuneLiteProperties; -import net.runelite.client.util.OSType; +import net.runelite.client.util.OSXUtil; import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel; import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities; import org.pushingpixels.substance.internal.utils.SubstanceTitlePaneUtilities; @@ -136,7 +134,7 @@ public class ClientUI extends JFrame setUIFont(new FontUIResource(FontManager.getRunescapeFont())); ClientUI gui = new ClientUI(runelite, properties, client); - tryEnableOSXFullscreen(gui); + OSXUtil.tryEnableFullscreen(gui); return gui; } @@ -459,26 +457,4 @@ public class ClientUI extends JFrame return pluginToolbar; } - /** - * Enables the osx native fullscreen if running on a mac. - * - * @param gui The gui to enable the fullscreen on. - */ - private static void tryEnableOSXFullscreen(ClientUI gui) - { - if (OSType.getOSType() == OSType.MacOS) - { - try - { - Class.forName("com.apple.eawt.FullScreenUtilities") - .getMethod("setWindowCanFullScreen", Window.class, boolean.class) - .invoke(null, gui, true); - log.debug("macOS fullscreen enabled"); - } - catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) - { - // not running macOS, ignore - } - } - } } diff --git a/runelite-client/src/main/java/net/runelite/client/util/OSXUtil.java b/runelite-client/src/main/java/net/runelite/client/util/OSXUtil.java new file mode 100644 index 0000000000..393e57445b --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/util/OSXUtil.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.util; + +import com.apple.eawt.Application; +import com.apple.eawt.FullScreenUtilities; +import lombok.extern.slf4j.Slf4j; +import net.runelite.client.ui.ClientUI; + +/** + * A class with OSX-specific functions to improve integration. + */ +@Slf4j +public class OSXUtil +{ + /** + * Enables the osx native fullscreen if running on a mac. + * + * @param gui The gui to enable the fullscreen on. + */ + public static void tryEnableFullscreen(ClientUI gui) + { + if (OSType.getOSType() == OSType.MacOS) + { + FullScreenUtilities.setWindowCanFullScreen(gui, true); + log.debug("Enabled fullscreen on macOS"); + } + } + + /** + * Requests the foreground in a macOS friendly way. + */ + public static void requestFocus() + { + if (OSType.getOSType() == OSType.MacOS) + { + Application app = Application.getApplication(); + app.requestForeground(true); + log.debug("Requested focus on macOS"); + } + } +} From 1f81a675e0a5aaabeb119a618c19d0c068cae212 Mon Sep 17 00:00:00 2001 From: arlyon Date: Sat, 3 Mar 2018 02:12:44 +0000 Subject: [PATCH 2/2] notifier: fix to request focus on OSX --- .../src/main/java/net/runelite/client/Notifier.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/Notifier.java b/runelite-client/src/main/java/net/runelite/client/Notifier.java index 5fa9ca3516..f2f2006a91 100644 --- a/runelite-client/src/main/java/net/runelite/client/Notifier.java +++ b/runelite-client/src/main/java/net/runelite/client/Notifier.java @@ -43,6 +43,7 @@ import lombok.extern.slf4j.Slf4j; import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.ui.ClientUI; import net.runelite.client.util.OSType; +import net.runelite.client.util.OSXUtil; @Singleton @Slf4j @@ -98,7 +99,14 @@ public class Notifier if (runeLiteConfig.requestFocusOnNotification()) { - clientUI.requestFocus(); + if (OSType.getOSType() == OSType.MacOS) + { + OSXUtil.requestFocus(); + } + else + { + clientUI.requestFocus(); + } } if (runeLiteConfig.enableTrayNotifications())