Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2020-05-14 17:43:53 +02:00
30 changed files with 709 additions and 429 deletions

View File

@@ -157,9 +157,14 @@ public class Notifier
return;
}
if (runeLiteConfig.requestFocusOnNotification())
switch (runeLiteConfig.notificationRequestFocus())
{
clientUI.requestFocus();
case REQUEST:
clientUI.requestFocus();
break;
case FORCE:
clientUI.forceFocus();
break;
}
if (runeLiteConfig.enableTrayNotifications())

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2020, Adam <Adam@sigterm.info>
* 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.config;
public enum RequestFocusType
{
OFF,
REQUEST,
FORCE;
}

View File

@@ -221,13 +221,13 @@ public interface RuneLiteConfig extends Config
@ConfigItem(
keyName = "notificationRequestFocus",
name = "Request focus on notification",
description = "Toggles window focus request",
description = "Configures the window focus request type on notification",
position = 16,
titleSection = "notificationsTitle"
)
default boolean requestFocusOnNotification()
default RequestFocusType notificationRequestFocus()
{
return true;
return RequestFocusType.OFF;
}
@ConfigItem(

View File

@@ -95,6 +95,7 @@ import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.OSType;
import net.runelite.client.util.OSXUtil;
import net.runelite.client.util.SwingUtil;
import net.runelite.client.util.WinUtil;
import org.pushingpixels.substance.internal.SubstanceSynapse;
import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities;
import org.pushingpixels.substance.internal.utils.SubstanceTitlePaneUtilities;
@@ -680,41 +681,38 @@ public class ClientUI
*/
public void requestFocus()
{
if (OSType.getOSType() == OSType.MacOS)
switch (OSType.getOSType())
{
OSXUtil.requestFocus();
case MacOS:
// On OSX Component::requestFocus has no visible effect, so we use our OSX-specific
// requestUserAttention()
OSXUtil.requestUserAttention();
break;
default:
frame.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.
// See https://stackoverflow.com/questions/309023/how-to-bring-a-window-to-the-front/7435722#7435722
else if (OSType.getOSType() == OSType.Windows && !frame.isFocused())
giveClientFocus();
}
/**
* Attempt to forcibly bring the client frame to front
*/
public void forceFocus()
{
switch (OSType.getOSType())
{
SwingUtilities.invokeLater(() ->
{
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 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);
}
});
case MacOS:
OSXUtil.requestForeground();
break;
case Windows:
WinUtil.requestForeground(frame);
break;
default:
frame.requestFocus();
break;
}
frame.requestFocus();
giveClientFocus();
}

View File

@@ -49,16 +49,23 @@ public class OSXUtil
}
}
/**
* Request user attention on macOS
*/
public static void requestUserAttention()
{
Application app = Application.getApplication();
app.requestUserAttention(true);
log.debug("Requested user attention on macOS");
}
/**
* Requests the foreground in a macOS friendly way.
*/
public static void requestFocus()
public static void requestForeground()
{
if (OSType.getOSType() == OSType.MacOS)
{
Application app = Application.getApplication();
app.requestForeground(true);
log.debug("Requested focus on macOS");
}
Application app = Application.getApplication();
app.requestForeground(true);
log.debug("Forced focus on macOS");
}
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2020, Adam <Adam@sigterm.info>
* 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.sun.jna.Native;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinUser;
import java.awt.Frame;
public class WinUtil
{
/**
* Forcibly set focus to the given component
*
*/
public static void requestForeground(Frame frame)
{
// SetForegroundWindow can't set iconified windows to foreground, so set the
// frame state to normal first
frame.setState(Frame.NORMAL);
User32 user32 = User32.INSTANCE;
// Windows does not allow any process to set the foreground window, but it will if
// the process received the last input event. So we send a F22 key event to the process.
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow
WinUser.INPUT input = new WinUser.INPUT();
input.type = new WinDef.DWORD(WinUser.INPUT.INPUT_KEYBOARD);
input.input.ki.wVk = new WinDef.WORD(0x85); // VK_F22
user32.SendInput(new WinDef.DWORD(1), (WinUser.INPUT[]) input.toArray(1), input.size());
// Now we may set the foreground window
WinDef.HWND hwnd = new WinDef.HWND(Native.getComponentPointer(frame));
user32.SetForegroundWindow(hwnd);
}
}