From 5a9dec8a916fc9d5e2d61c512904d24b6af0f307 Mon Sep 17 00:00:00 2001 From: endolf Date: Sat, 27 Aug 2005 08:21:42 +0000 Subject: Added shutdown hooks to stop rumblers before quitting. git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@109 e343933a-64c8-49c5-92b1-88f2ce3e89e8 --- .../net/java/games/input/DirectInputRumbler.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/DX8/src/java/net/java/games/input/DirectInputRumbler.java b/plugins/DX8/src/java/net/java/games/input/DirectInputRumbler.java index 5c02b24..d3fd283 100644 --- a/plugins/DX8/src/java/net/java/games/input/DirectInputRumbler.java +++ b/plugins/DX8/src/java/net/java/games/input/DirectInputRumbler.java @@ -54,6 +54,8 @@ public class DirectInputRumbler implements Rumbler { this.effect = effect; this.axisID = axisID; this.axisName = axisName; + + Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook(this))); } /** @@ -98,4 +100,22 @@ public class DirectInputRumbler implements Rumbler { * @param intensity The intensity of the rumble */ private native void setRumble(long effect, float intensity); + + private class ShutdownHook implements Runnable { + private DirectInputRumbler rumbler; + public ShutdownHook(DirectInputRumbler rumbler) { + this.rumbler = rumbler; + } + + public void run() { + if(rumbler!=null) { + rumbler.rumble(0f); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + //Ignore, we are quitting anyway + } + } + } + } } -- cgit v1.2.3