From 37e997acdbf0b79dec2b06a8647e75bbb24bd82e Mon Sep 17 00:00:00 2001 From: Robbie McLeod <31489752+rbbi@users.noreply.github.com> Date: Sat, 18 Aug 2018 12:44:10 +0100 Subject: [PATCH] Fix sidebar hotkey leaking into game client --- .../java/net/runelite/client/ui/ClientUI.java | 18 +++++- .../net/runelite/client/ui/UiKeyListener.java | 58 ------------------- 2 files changed, 15 insertions(+), 61 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/ui/UiKeyListener.java 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 64e54158ba..755f71a245 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,6 +37,8 @@ import java.awt.GraphicsConfiguration; import java.awt.LayoutManager; import java.awt.Rectangle; import java.awt.TrayIcon; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import javax.annotation.Nullable; import javax.inject.Inject; @@ -62,12 +64,14 @@ import net.runelite.client.RuneLite; import net.runelite.client.RuneLiteProperties; import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ExpandResizeType; +import net.runelite.client.config.Keybind; import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.config.WarningOnExit; import net.runelite.client.events.NavigationButtonAdded; import net.runelite.client.events.NavigationButtonRemoved; import net.runelite.client.input.KeyManager; import net.runelite.client.ui.skin.SubstanceRuneLiteLookAndFeel; +import net.runelite.client.util.HotkeyListener; import net.runelite.client.util.ImageUtil; import net.runelite.client.util.OSType; import net.runelite.client.util.OSXUtil; @@ -290,9 +294,17 @@ public class ClientUI frame.add(container); // Add key listener - final UiKeyListener uiKeyListener = new UiKeyListener(this); - frame.addKeyListener(uiKeyListener); - keyManager.registerKeyListener(uiKeyListener); + final HotkeyListener sidebarListener = new HotkeyListener(() -> + new Keybind(KeyEvent.VK_F11, InputEvent.CTRL_DOWN_MASK)) + { + @Override + public void hotkeyPressed() + { + toggleSidebar(); + } + }; + + keyManager.registerKeyListener(sidebarListener); // Decorate window with custom chrome and titlebar if needed final boolean withTitleBar = config.enableCustomChrome(); diff --git a/runelite-client/src/main/java/net/runelite/client/ui/UiKeyListener.java b/runelite-client/src/main/java/net/runelite/client/ui/UiKeyListener.java deleted file mode 100644 index 494acc94e9..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/ui/UiKeyListener.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.ui; - -import java.awt.event.KeyEvent; -import javax.swing.SwingUtilities; -import net.runelite.client.input.KeyListener; - -class UiKeyListener implements KeyListener -{ - private final ClientUI clientUi; - - UiKeyListener(ClientUI clientUi) - { - this.clientUi = clientUi; - } - - @Override - public void keyTyped(KeyEvent e) - { - } - - @Override - public void keyPressed(KeyEvent e) - { - if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_F11) - { - SwingUtilities.invokeLater(clientUi::toggleSidebar); - } - } - - @Override - public void keyReleased(KeyEvent e) - { - } -}