From b0195f12f0c2ad5a63d376ba2af9dc31d1e1a66e Mon Sep 17 00:00:00 2001 From: Twiglet1022 <29353990+Twiglet1022@users.noreply.github.com> Date: Tue, 16 Apr 2019 20:28:35 +0100 Subject: [PATCH 1/2] Bring client to front on windows if "Request focus on notification" on --- .../java/net/runelite/client/ui/ClientUI.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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 96ba6c31e6..a8577becad 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 @@ -596,6 +596,27 @@ public class ClientUI { OSXUtil.requestFocus(); } + // The workaround for Windows is to minimise and then un-minimise the client to bring + // it to the front because java.awt.Window#toFront doesn't work reliably. + else if (OSType.getOSType() == OSType.Windows && !frame.isFocused()) + { + if ((frame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) + { + frame.setExtendedState(JFrame.ICONIFIED); + frame.setExtendedState(JFrame.MAXIMIZED_BOTH); + } + else + { + // If the client is snapped to the edges of the screen, setExtendedState(JFrame.NORMAL) + // will undo the snap-to-edge so setSize() is required to prevent the client from + // changing size. Unfortunately Windows does not support JFrame.MAXIMIZED_VERT + int width = frame.getWidth(); + int height = frame.getHeight(); + frame.setExtendedState(JFrame.ICONIFIED); + frame.setExtendedState(JFrame.NORMAL); + frame.setSize(width, height); + } + } frame.requestFocus(); giveClientFocus(); From 223057a13659986c26074127af0a2851106cf717 Mon Sep 17 00:00:00 2001 From: Twiglet1022 <29353990+Twiglet1022@users.noreply.github.com> Date: Thu, 25 Apr 2019 23:42:37 +0100 Subject: [PATCH 2/2] Use SwingUtilities#invokeLater This ensures that the calls to setExtendedState are thread safe as that is probably what was causing the occasional game crash before. --- .../java/net/runelite/client/ui/ClientUI.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) 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 a8577becad..0556873806 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 @@ -602,19 +602,28 @@ public class ClientUI { if ((frame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) { - frame.setExtendedState(JFrame.ICONIFIED); - frame.setExtendedState(JFrame.MAXIMIZED_BOTH); + SwingUtilities.invokeLater(() -> + { + frame.setExtendedState(JFrame.ICONIFIED); + frame.setExtendedState(JFrame.MAXIMIZED_BOTH); + }); } else { - // If the client is snapped to the edges of the screen, setExtendedState(JFrame.NORMAL) - // will undo the snap-to-edge so setSize() is required to prevent the client from - // changing size. Unfortunately Windows does not support JFrame.MAXIMIZED_VERT - int width = frame.getWidth(); - int height = frame.getHeight(); - frame.setExtendedState(JFrame.ICONIFIED); - frame.setExtendedState(JFrame.NORMAL); - frame.setSize(width, height); + SwingUtilities.invokeLater(() -> + { + // If the client is snapped to the top and bottom edges of the screen, setExtendedState will + // will reset it so setSize and setLocation ensure that the client doesn't move or resize. + // It is done this way because Windows does not support JFrame.MAXIMIZED_VERT + int x = frame.getLocation().x; + int y = frame.getLocation().y; + int width = frame.getWidth(); + int height = frame.getHeight(); + frame.setExtendedState(JFrame.ICONIFIED); + frame.setExtendedState(JFrame.NORMAL); + frame.setLocation(x, y); + frame.setSize(width, height); + }); } }