From ca6a8310204f729e9c6ce1274b9f402dfa45fa2f Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Sun, 3 Jan 2016 16:43:31 -0600 Subject: [PATCH] Reset keyboard state when window is deactivated/reactivated --- src/main/java/jace/JaceApplication.java | 2 +- src/main/java/jace/JaceUIController.java | 5 ++++- src/main/java/jace/core/Keyboard.java | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/jace/JaceApplication.java b/src/main/java/jace/JaceApplication.java index a4bc098..576cf79 100644 --- a/src/main/java/jace/JaceApplication.java +++ b/src/main/java/jace/JaceApplication.java @@ -58,7 +58,7 @@ public class JaceApplication extends Application { while (Emulator.computer.getVideo() == null || Emulator.computer.getVideo().getFrameBuffer() == null) { Thread.yield(); } - controller.connectComputer(Emulator.computer); + controller.connectComputer(Emulator.computer, primaryStage); bootWatchdog(); }); primaryStage.setOnCloseRequest(event -> { diff --git a/src/main/java/jace/JaceUIController.java b/src/main/java/jace/JaceUIController.java index 1bbc862..7181bd3 100644 --- a/src/main/java/jace/JaceUIController.java +++ b/src/main/java/jace/JaceUIController.java @@ -10,6 +10,7 @@ import com.sun.glass.ui.Application; import jace.cheat.MetaCheat; import jace.core.Card; import jace.core.Computer; +import jace.core.Keyboard; import jace.library.MediaCache; import jace.library.MediaConsumer; import jace.library.MediaConsumerParent; @@ -43,6 +44,7 @@ import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; +import javafx.stage.Stage; /** * @@ -79,10 +81,11 @@ public class JaceUIController { rootPane.setOnDragExited(this::processDragExitedEvent); } - public void connectComputer(Computer computer) { + public void connectComputer(Computer computer, Stage primaryStage) { this.computer = computer; appleScreen.setImage(computer.getVideo().getFrameBuffer()); EventHandler keyboardHandler = computer.getKeyboard().getListener(); + primaryStage.setOnShowing(evt->computer.getKeyboard().resetState()); rootPane.setFocusTraversable(true); rootPane.setOnKeyPressed(keyboardHandler); rootPane.setOnKeyReleased(keyboardHandler); diff --git a/src/main/java/jace/core/Keyboard.java b/src/main/java/jace/core/Keyboard.java index 5f9ec9d..06eeb15 100644 --- a/src/main/java/jace/core/Keyboard.java +++ b/src/main/java/jace/core/Keyboard.java @@ -39,6 +39,7 @@ import java.util.logging.Logger; import javafx.event.EventHandler; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; +import javafx.stage.WindowEvent; /** * Keyboard manages all keyboard-related activities. For now, all hotkeys are @@ -50,6 +51,12 @@ import javafx.scene.input.KeyEvent; */ public class Keyboard implements Reconfigurable { + public void resetState() { + clearStrobe(); + openApple(false); + solidApple(false); + } + private Computer computer; public Keyboard(Computer computer) {